comparison DEPENDENCIES/generic/include/boost/spirit/home/x3/directive/expect.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(SPIRIT_EXPECT_MARCH_16_2012_1024PM)
8 #define SPIRIT_EXPECT_MARCH_16_2012_1024PM
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/core/parser.hpp>
16 #include <boost/throw_exception.hpp>
17 #include <stdexcept>
18
19 namespace boost { namespace spirit { namespace x3
20 {
21 template <typename Iterator>
22 struct expectation_failure : std::runtime_error
23 {
24 public:
25
26 expectation_failure(Iterator where, std::string const& which)
27 : std::runtime_error("boost::spirit::x3::expectation_failure")
28 , where_(where), which_(which)
29 {}
30 ~expectation_failure() throw() {}
31
32 std::string which() const { return which_; }
33 Iterator const& where() const { return where_; }
34
35 private:
36
37 Iterator where_;
38 std::string which_;
39 };
40
41 template <typename Subject>
42 struct expect_directive : unary_parser<Subject, expect_directive<Subject>>
43 {
44 typedef unary_parser<Subject, expect_directive<Subject> > base_type;
45 static bool const is_pass_through_unary = true;
46
47 expect_directive(Subject const& subject)
48 : base_type(subject) {}
49
50 template <typename Iterator, typename Context
51 , typename RContext, typename Attribute>
52 bool parse(Iterator& first, Iterator const& last
53 , Context const& context, RContext& rcontext, Attribute& attr) const
54 {
55 bool r = this->subject.parse(first, last, context, rcontext, attr);
56
57 if (!r)
58 {
59 boost::throw_exception(
60 expectation_failure<Iterator>(
61 first, what(this->subject)));
62 }
63 return r;
64 }
65 };
66
67 struct expect_gen
68 {
69 template <typename Subject>
70 expect_directive<typename extension::as_parser<Subject>::value_type>
71 operator[](Subject const& subject) const
72 {
73 return {as_parser(subject)};
74 }
75 };
76
77 expect_gen const expect = expect_gen();
78 }}}
79
80 #endif