File indexing completed on 2025-09-15 08:52:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_SPIRIT_X3_EXPECT_MARCH_16_2012_1024PM)
0010 #define BOOST_SPIRIT_X3_EXPECT_MARCH_16_2012_1024PM
0011
0012 #include <boost/spirit/home/x3/support/context.hpp>
0013 #include <boost/spirit/home/x3/support/expectation.hpp>
0014 #include <boost/spirit/home/x3/core/parser.hpp>
0015 #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
0016
0017 namespace boost { namespace spirit { namespace x3
0018 {
0019 template <typename Subject>
0020 struct expect_directive : unary_parser<Subject, expect_directive<Subject>>
0021 {
0022 typedef unary_parser<Subject, expect_directive<Subject> > base_type;
0023 static bool const is_pass_through_unary = true;
0024
0025 constexpr expect_directive(Subject const& subject)
0026 : base_type(subject) {}
0027
0028 template <typename Iterator, typename Context
0029 , typename RContext, typename Attribute>
0030 bool parse(Iterator& first, Iterator const& last
0031 , Context const& context, RContext& rcontext, Attribute& attr) const
0032 {
0033 bool const r = this->subject.parse(first, last, context, rcontext, attr);
0034
0035 if (!r)
0036 {
0037 #if BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE
0038 boost::throw_exception(
0039 expectation_failure<Iterator>(
0040 first, what(this->subject)));
0041 #else
0042 if (!has_expectation_failure(context))
0043 {
0044 set_expectation_failure(first, this->subject, context);
0045 }
0046 #endif
0047 }
0048 return r;
0049 }
0050 };
0051
0052 struct expect_gen
0053 {
0054 template <typename Subject>
0055 constexpr expect_directive<typename extension::as_parser<Subject>::value_type>
0056 operator[](Subject const& subject) const
0057 {
0058 return { as_parser(subject) };
0059 }
0060 };
0061
0062 constexpr auto expect = expect_gen{};
0063 }}}
0064
0065 namespace boost { namespace spirit { namespace x3 { namespace detail
0066 {
0067
0068 template <typename Subject, typename Context, typename RContext>
0069 struct parse_into_container_impl<expect_directive<Subject>, Context, RContext>
0070 {
0071 template <typename Iterator, typename Attribute>
0072 static bool call(
0073 expect_directive<Subject> const& parser
0074 , Iterator& first, Iterator const& last
0075 , Context const& context, RContext& rcontext, Attribute& attr)
0076 {
0077 bool const r = parse_into_container(
0078 parser.subject, first, last, context, rcontext, attr);
0079
0080 if (!r)
0081 {
0082 #if BOOST_SPIRIT_X3_THROW_EXPECTATION_FAILURE
0083 boost::throw_exception(
0084 expectation_failure<Iterator>(
0085 first, what(parser.subject)));
0086 #else
0087 if (!has_expectation_failure(context))
0088 {
0089 set_expectation_failure(first, parser.subject, context);
0090 }
0091 #endif
0092 }
0093 return r;
0094 }
0095 };
0096 }}}}
0097
0098 #endif