1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_GUARD_FERBRUARY_02_2013_0649PM)
8 #define BOOST_SPIRIT_X3_GUARD_FERBRUARY_02_2013_0649PM
10 #include <boost/spirit/home/x3/support/context.hpp>
11 #include <boost/spirit/home/x3/directive/expect.hpp>
13 namespace boost { namespace spirit { namespace x3
15 enum class error_handler_result
23 template <typename Subject, typename Handler>
24 struct guard : unary_parser<Subject, guard<Subject, Handler>>
26 typedef unary_parser<Subject, guard<Subject, Handler>> base_type;
27 static bool const is_pass_through_unary = true;
29 guard(Subject const& subject, Handler handler)
30 : base_type(subject), handler(handler) {}
32 template <typename Iterator, typename Context
33 , typename RuleContext, typename Attribute>
34 bool parse(Iterator& first, Iterator const& last
35 , Context const& context, RuleContext& rcontext, Attribute& attr) const
42 bool r = this->subject.parse(i, last, context, rcontext, attr);
47 catch (expectation_failure<Iterator> const& x)
49 switch (handler(first, last, x, context))
51 case error_handler_result::fail:
53 case error_handler_result::retry:
55 case error_handler_result::accept:
57 case error_handler_result::rethrow: