1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #if !defined(SPIRIT_EXPECT_APRIL_29_2007_0445PM)
9 #define SPIRIT_EXPECT_APRIL_29_2007_0445PM
15 #include <boost/spirit/home/qi/operator/sequence_base.hpp>
16 #include <boost/spirit/home/qi/detail/expect_function.hpp>
17 #include <boost/spirit/home/qi/meta_compiler.hpp>
18 #include <boost/spirit/home/support/has_semantic_action.hpp>
19 #include <boost/spirit/home/support/handles_container.hpp>
20 #include <boost/spirit/home/support/info.hpp>
23 namespace boost { namespace spirit
25 ///////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////
29 struct use_operator<qi::domain, proto::tag::greater> // enables >
33 struct flatten_tree<qi::domain, proto::tag::greater> // flattens >
37 namespace boost { namespace spirit { namespace qi
39 template <typename Iterator>
40 struct expectation_failure : std::runtime_error
42 expectation_failure(Iterator first_, Iterator last_, info const& what)
43 : std::runtime_error("boost::spirit::qi::expectation_failure")
44 , first(first_), last(last_), what_(what)
46 ~expectation_failure() throw() {}
53 template <typename Elements>
54 struct expect : sequence_base<expect<Elements>, Elements>
56 friend struct sequence_base<expect<Elements>, Elements>;
58 expect(Elements const& elements)
59 : sequence_base<expect<Elements>, Elements>(elements) {}
63 template <typename Iterator, typename Context, typename Skipper>
64 static detail::expect_function<
65 Iterator, Context, Skipper
66 , expectation_failure<Iterator> >
68 Iterator& first, Iterator const& last
69 , Context& context, Skipper const& skipper)
71 return detail::expect_function<
72 Iterator, Context, Skipper, expectation_failure<Iterator> >
73 (first, last, context, skipper);
76 std::string id() const { return "expect"; }
79 ///////////////////////////////////////////////////////////////////////////
80 // Parser generators: make_xxx function (objects)
81 ///////////////////////////////////////////////////////////////////////////
82 template <typename Elements, typename Modifiers>
83 struct make_composite<proto::tag::greater, Elements, Modifiers>
84 : make_nary_composite<Elements, expect>
88 namespace boost { namespace spirit { namespace traits
90 ///////////////////////////////////////////////////////////////////////////
91 template <typename Elements>
92 struct has_semantic_action<qi::expect<Elements> >
93 : nary_has_semantic_action<Elements> {};
95 ///////////////////////////////////////////////////////////////////////////
96 template <typename Elements, typename Attribute, typename Context
98 struct handles_container<qi::expect<Elements>, Attribute, Context