1
/*=============================================================================
3
Copyright (c) 2001-2003 Joel de Guzman
4
http://spirit.sourceforge.net/
6
Permission to copy, use, modify, sell and distribute this software is
7
granted provided this copyright notice appears in all copies. This
8
software is provided "as is" without express or implied warranty, and
9
with no claim as to its suitability for any purpose.
10
=============================================================================*/
11
#ifndef BOOST_SPIRIT_EXCEPTIONS_IPP
12
#define BOOST_SPIRIT_EXCEPTIONS_IPP
14
namespace boost { namespace spirit { namespace impl {
17
template <typename ParserT, typename ScannerT>
18
typename parser_result<ParserT, ScannerT>::type
19
fallback_parser_helper(ParserT const& subject, ScannerT const& scan);
22
template <typename RT, typename ParserT, typename ScannerT>
23
RT fallback_parser_parse(ParserT const& p, ScannerT const& scan)
25
typedef typename ScannerT::iterator_t iterator_t;
26
typedef typename RT::attr_t attr_t;
27
typedef error_status<attr_t> error_status_t;
28
typedef typename ParserT::error_descr_t error_descr_t;
30
iterator_t save = scan.first;
31
error_status_t hr(error_status_t::retry);
33
while (hr.result == error_status_t::retry)
38
return p.subject().parse(scan);
40
return impl::fallback_parser_helper(p, scan);
44
catch (parser_error<error_descr_t, iterator_t> error)
47
hr = p.handler(scan, error);
50
case error_status_t::fail:
51
return scan.no_match();
52
case error_status_t::accept:
53
return scan.create_match
54
(hr.length, hr.value, save, scan.first);
55
case error_status_t::rethrow:
56
boost::throw_exception(error);
62
return scan.no_match();
65
///////////////////////////////////////////////////////////////////////////
67
// Borland does not like calling the subject directly in the try block.
68
// Removing the #ifdef __BORLANDC__ code makes Borland complain that
69
// some variables and types cannot be found in the catch block. Weird!
71
///////////////////////////////////////////////////////////////////////////
74
template <typename ParserT, typename ScannerT>
75
typename parser_result<ParserT, ScannerT>::type
76
fallback_parser_helper(ParserT const& p, ScannerT const& scan)
77
{ return p.subject().parse(scan); }
81
}}} // namespace boost::spirit::impl
83
///////////////////////////////////////////////////////////////////////////////