comparison DEPENDENCIES/generic/include/boost/spirit/home/x3/auxiliary/guard.hpp @ 102:f46d142149f5

Whoops, finish that update
author Chris Cannam
date Mon, 07 Sep 2015 11:13:41 +0100
parents
children
comparison
equal deleted inserted replaced
101:c530137014c0 102:f46d142149f5
1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
3
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
9
10 #if defined(_MSC_VER)
11 #pragma once
12 #endif
13
14 #include <boost/spirit/home/x3/support/context.hpp>
15 #include <boost/spirit/home/x3/directive/expect.hpp>
16
17 namespace boost { namespace spirit { namespace x3
18 {
19 enum class error_handler_result
20 {
21 fail
22 , retry
23 , accept
24 , rethrow
25 };
26
27 template <typename Subject, typename Handler>
28 struct guard : unary_parser<Subject, guard<Subject, Handler>>
29 {
30 typedef unary_parser<Subject, guard<Subject, Handler>> base_type;
31 static bool const is_pass_through_unary = true;
32
33 guard(Subject const& subject, Handler handler)
34 : base_type(subject), handler(handler) {}
35
36 template <typename Iterator, typename Context
37 , typename RuleContext, typename Attribute>
38 bool parse(Iterator& first, Iterator const& last
39 , Context const& context, RuleContext& rcontext, Attribute& attr) const
40 {
41 for (;;)
42 {
43 try
44 {
45 Iterator i = first;
46 bool r = this->subject.parse(i, last, context, rcontext, attr);
47 if (r)
48 first = i;
49 return r;
50 }
51 catch (expectation_failure<Iterator> const& x)
52 {
53 switch (handler(first, last, x, context))
54 {
55 case error_handler_result::fail:
56 return false;
57 case error_handler_result::retry:
58 continue;
59 case error_handler_result::accept:
60 return true;
61 case error_handler_result::rethrow:
62 throw;
63 }
64 }
65 }
66 return false;
67 }
68
69 Handler handler;
70 };
71 }}}
72
73 #endif