File indexing completed on 2025-01-19 09:47:44
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_SPIRIT_QI_DIRECTIVE_EXPECT_HPP
0008 #define BOOST_SPIRIT_QI_DIRECTIVE_EXPECT_HPP
0009
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013
0014 #include <boost/spirit/home/qi/meta_compiler.hpp>
0015 #include <boost/spirit/home/support/has_semantic_action.hpp>
0016 #include <boost/spirit/home/qi/detail/attributes.hpp>
0017 #include <boost/spirit/home/qi/detail/expectation_failure.hpp>
0018 #include <boost/spirit/home/support/common_terminals.hpp>
0019 #include <boost/spirit/home/support/handles_container.hpp>
0020 #include <boost/spirit/home/support/unused.hpp>
0021 #include <boost/spirit/home/support/info.hpp>
0022
0023 namespace boost { namespace spirit {
0024
0025
0026
0027 template <>
0028 struct use_directive<qi::domain, tag::expect>
0029 : mpl::true_ {};
0030 }}
0031
0032 namespace boost { namespace spirit { namespace qi {
0033
0034 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0035 using spirit::expect;
0036 #endif
0037 using spirit::expect_type;
0038
0039 template <typename Subject>
0040 struct expect_directive : unary_parser<expect_directive<Subject> >
0041 {
0042 typedef result_of::compile<domain, Subject> subject_type;
0043
0044 template <typename Context, typename Iterator>
0045 struct attribute
0046 {
0047 typedef traits::attribute_of<subject_type, Context, Iterator>
0048 type;
0049 };
0050
0051 expect_directive(Subject const& subject_) : subject(subject_) {}
0052
0053 template <typename Iterator, typename Context
0054 , typename Skipper, typename Attribute>
0055 bool parse(Iterator& first, Iterator const& last
0056 , Context& context, Skipper const& skipper
0057 , Attribute& attr_) const
0058 {
0059 typedef expectation_failure<Iterator> exception;
0060
0061 if (!subject.parse(first, last, context, skipper, attr_))
0062 {
0063 boost::throw_exception(
0064 exception(first, last, subject.what(context)));
0065 #if defined(BOOST_NO_EXCEPTIONS)
0066 return false;
0067 #endif
0068 }
0069 return true;
0070 }
0071
0072 template <typename Context>
0073 info what(Context& context) const
0074 {
0075 return info("expect", subject.what(context));
0076 }
0077
0078 Subject subject;
0079 };
0080
0081
0082
0083
0084 template <typename Subject, typename Modifiers>
0085 struct make_directive<tag::expect, Subject, Modifiers>
0086 {
0087 typedef expect_directive<Subject> result_type;
0088
0089 result_type operator()
0090 (unused_type, Subject const& subject, unused_type) const
0091 {
0092 return result_type(subject);
0093 }
0094 };
0095
0096 }}}
0097
0098 namespace boost { namespace spirit { namespace traits {
0099
0100 template <typename Subject>
0101 struct has_semantic_action<qi::expect_directive<Subject> >
0102 : unary_has_semantic_action<Subject> {};
0103
0104
0105 template <typename Subject, typename Attribute
0106 , typename Context, typename Iterator>
0107 struct handles_container<
0108 qi::expect_directive<Subject>, Attribute, Context, Iterator
0109 >
0110 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
0111 }}}
0112
0113 #endif