File indexing completed on 2025-01-31 10:02:34
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_X3_GUARD_FERBRUARY_02_2013_0649PM)
0008 #define BOOST_SPIRIT_X3_GUARD_FERBRUARY_02_2013_0649PM
0009
0010 #include <boost/spirit/home/x3/support/context.hpp>
0011 #include <boost/spirit/home/x3/directive/expect.hpp>
0012
0013 namespace boost { namespace spirit { namespace x3
0014 {
0015 enum class error_handler_result
0016 {
0017 fail
0018 , retry
0019 , accept
0020 , rethrow
0021 };
0022
0023 template <typename Subject, typename Handler>
0024 struct guard : unary_parser<Subject, guard<Subject, Handler>>
0025 {
0026 typedef unary_parser<Subject, guard<Subject, Handler>> base_type;
0027 static bool const is_pass_through_unary = true;
0028
0029 constexpr guard(Subject const& subject, Handler handler)
0030 : base_type(subject), handler(handler) {}
0031
0032 template <typename Iterator, typename Context
0033 , typename RuleContext, typename Attribute>
0034 bool parse(Iterator& first, Iterator const& last
0035 , Context const& context, RuleContext& rcontext, Attribute& attr) const
0036 {
0037 for (;;)
0038 {
0039 try
0040 {
0041 Iterator i = first;
0042 bool r = this->subject.parse(i, last, context, rcontext, attr);
0043 if (r)
0044 first = i;
0045 return r;
0046 }
0047 catch (expectation_failure<Iterator> const& x)
0048 {
0049 switch (handler(first, last, x, context))
0050 {
0051 case error_handler_result::fail:
0052 return false;
0053 case error_handler_result::retry:
0054 continue;
0055 case error_handler_result::accept:
0056 return true;
0057 case error_handler_result::rethrow:
0058 throw;
0059 }
0060 }
0061 }
0062 return false;
0063 }
0064
0065 Handler handler;
0066 };
0067 }}}
0068
0069 #endif