source: NonGTP/Boost/boost/spirit/error_handling/impl/exceptions.ipp @ 857

Revision 857, 3.0 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2001-2003 Joel de Guzman
3    http://spirit.sourceforge.net/
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9#ifndef BOOST_SPIRIT_EXCEPTIONS_IPP
10#define BOOST_SPIRIT_EXCEPTIONS_IPP
11
12namespace boost { namespace spirit { namespace impl {
13
14#ifdef __BORLANDC__
15    template <typename ParserT, typename ScannerT>
16    typename parser_result<ParserT, ScannerT>::type
17    fallback_parser_helper(ParserT const& subject, ScannerT const& scan);
18#endif
19
20    template <typename RT, typename ParserT, typename ScannerT>
21    RT fallback_parser_parse(ParserT const& p, ScannerT const& scan)
22    {
23        typedef typename ScannerT::iterator_t iterator_t;
24        typedef typename RT::attr_t attr_t;
25        typedef error_status<attr_t> error_status_t;
26        typedef typename ParserT::error_descr_t error_descr_t;
27
28        iterator_t save = scan.first;
29        error_status_t hr(error_status_t::retry);
30
31        while (hr.result == error_status_t::retry)
32        {
33            try
34            {
35            #ifndef __BORLANDC__
36                return p.subject().parse(scan);
37            #else
38                return impl::fallback_parser_helper(p, scan);
39            #endif
40            }
41
42            catch (parser_error<error_descr_t, iterator_t>& error)
43            {
44                scan.first = save;
45                hr = p.handler(scan, error);
46                switch (hr.result)
47                {
48                    case error_status_t::fail:
49                        return scan.no_match();
50                    case error_status_t::accept:
51                        return scan.create_match
52                            (std::size_t(hr.length), hr.value, save, scan.first);
53                    case error_status_t::rethrow:
54                         boost::throw_exception(error);
55                    default:
56                        continue;
57                }
58            }
59        }
60        return scan.no_match();
61    }
62
63///////////////////////////////////////////////////////////////////////////
64//
65//  Borland does not like calling the subject directly in the try block.
66//  Removing the #ifdef __BORLANDC__ code makes Borland complain that
67//  some variables and types cannot be found in the catch block. Weird!
68//
69///////////////////////////////////////////////////////////////////////////
70#ifdef __BORLANDC__
71
72    template <typename ParserT, typename ScannerT>
73    typename parser_result<ParserT, ScannerT>::type
74    fallback_parser_helper(ParserT const& p, ScannerT const& scan)
75    {
76        return p.subject().parse(scan);
77    }
78
79#endif
80
81}}} // namespace boost::spirit::impl
82
83///////////////////////////////////////////////////////////////////////////////
84#endif
85
Note: See TracBrowser for help on using the repository browser.