]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/x3/directive/expect.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / spirit / home / x3 / directive / expect.hpp
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 #include <boost/spirit/home/x3/support/context.hpp>
11 #include <boost/spirit/home/x3/core/parser.hpp>
12 #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
13
14 #include <boost/throw_exception.hpp>
15 #include <stdexcept>
16
17 namespace boost { namespace spirit { namespace x3
18 {
19 template <typename Iterator>
20 struct expectation_failure : std::runtime_error
21 {
22 public:
23
24 expectation_failure(Iterator where, std::string const& which)
25 : std::runtime_error("boost::spirit::x3::expectation_failure")
26 , where_(where), which_(which)
27 {}
28 ~expectation_failure() throw() {}
29
30 std::string which() const { return which_; }
31 Iterator const& where() const { return where_; }
32
33 private:
34
35 Iterator where_;
36 std::string which_;
37 };
38
39 template <typename Subject>
40 struct expect_directive : unary_parser<Subject, expect_directive<Subject>>
41 {
42 typedef unary_parser<Subject, expect_directive<Subject> > base_type;
43 static bool const is_pass_through_unary = true;
44
45 expect_directive(Subject const& subject)
46 : base_type(subject) {}
47
48 template <typename Iterator, typename Context
49 , typename RContext, typename Attribute>
50 bool parse(Iterator& first, Iterator const& last
51 , Context const& context, RContext& rcontext, Attribute& attr) const
52 {
53 bool r = this->subject.parse(first, last, context, rcontext, attr);
54
55 if (!r)
56 {
57 boost::throw_exception(
58 expectation_failure<Iterator>(
59 first, what(this->subject)));
60 }
61 return r;
62 }
63 };
64
65 struct expect_gen
66 {
67 template <typename Subject>
68 expect_directive<typename extension::as_parser<Subject>::value_type>
69 operator[](Subject const& subject) const
70 {
71 return { as_parser(subject) };
72 }
73 };
74
75 auto const expect = expect_gen{};
76 }}}
77
78 namespace boost { namespace spirit { namespace x3 { namespace detail
79 {
80 // Special case handling for expect expressions.
81 template <typename Subject, typename Context, typename RContext>
82 struct parse_into_container_impl<expect_directive<Subject>, Context, RContext>
83 {
84 template <typename Iterator, typename Attribute>
85 static bool call(
86 expect_directive<Subject> const& parser
87 , Iterator& first, Iterator const& last
88 , Context const& context, RContext& rcontext, Attribute& attr)
89 {
90 bool r = parse_into_container(
91 parser.subject, first, last, context, rcontext, attr);
92
93 if (!r)
94 {
95 boost::throw_exception(
96 expectation_failure<Iterator>(
97 first, what(parser.subject)));
98 }
99 return r;
100 }
101 };
102 }}}}
103
104 #endif