1 /*=============================================================================
2 Copyright (c) 2016 Frank Hein, maxence business consulting gmbh
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_JULY_13_2016)
8 #define SPIRIT_EXPECT_JULY_13_2016
14 #include <boost/spirit/home/qi/meta_compiler.hpp>
15 #include <boost/spirit/home/support/has_semantic_action.hpp>
16 #include <boost/spirit/home/qi/detail/attributes.hpp>
17 #include <boost/spirit/home/qi/detail/expectation_failure.hpp>
18 #include <boost/spirit/home/support/common_terminals.hpp>
19 #include <boost/spirit/home/support/handles_container.hpp>
20 #include <boost/spirit/home/support/unused.hpp>
21 #include <boost/spirit/home/support/info.hpp>
23 namespace boost { namespace spirit {
24 ///////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////
28 struct use_directive<qi::domain, tag::expect> // enables expect[p]
32 namespace boost { namespace spirit { namespace qi {
34 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
37 using spirit::expect_type;
39 template <typename Subject>
40 struct expect_directive : unary_parser<expect_directive<Subject> >
42 typedef result_of::compile<domain, Subject> subject_type;
44 template <typename Context, typename Iterator>
47 typedef traits::attribute_of<subject_type, Context, Iterator>
51 expect_directive(Subject const& subject_) : subject(subject_) {}
53 template <typename Iterator, typename Context
54 , typename Skipper, typename Attribute>
55 bool parse(Iterator& first, Iterator const& last
56 , Context& context, Skipper const& skipper
57 , Attribute& attr_) const
59 typedef expectation_failure<Iterator> exception;
61 if (!subject.parse(first, last, context, skipper, attr_))
63 boost::throw_exception(
64 exception(first, last, subject.what(context)));
65 #if defined(BOOST_NO_EXCEPTIONS)
66 return false; // for systems not supporting exceptions
72 template <typename Context>
73 info what(Context& context) const
75 return info("expect", subject.what(context));
81 ///////////////////////////////////////////////////////////////////////////
82 // Parser generators: make_xxx function (objects)
83 ///////////////////////////////////////////////////////////////////////////
84 template <typename Subject, typename Modifiers>
85 struct make_directive<tag::expect, Subject, Modifiers>
87 typedef expect_directive<Subject> result_type;
89 result_type operator()
90 (unused_type, Subject const& subject, unused_type) const
92 return result_type(subject);
98 namespace boost { namespace spirit { namespace traits {
99 ///////////////////////////////////////////////////////////////////////////
100 template <typename Subject>
101 struct has_semantic_action<qi::expect_directive<Subject> >
102 : unary_has_semantic_action<Subject> {};
104 ///////////////////////////////////////////////////////////////////////////
105 template <typename Subject, typename Attribute
106 , typename Context, typename Iterator>
107 struct handles_container<
108 qi::expect_directive<Subject>, Attribute, Context, Iterator
110 : unary_handles_container<Subject, Attribute, Context, Iterator> {};