Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:35

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #if !defined(BOOST_SPIRIT_X3_EXPECT_MARCH_16_2012_1024PM)
0008 #define BOOST_SPIRIT_X3_EXPECT_MARCH_16_2012_1024PM
0009 
0010 #include <boost/spirit/home/x3/support/context.hpp>
0011 #include <boost/spirit/home/x3/core/parser.hpp>
0012 #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp>
0013 
0014 #include <boost/config.hpp> // for BOOST_SYMBOL_VISIBLE
0015 #include <boost/throw_exception.hpp>
0016 #include <stdexcept>
0017 
0018 namespace boost { namespace spirit { namespace x3
0019 {
0020     template <typename Iterator>
0021     struct BOOST_SYMBOL_VISIBLE expectation_failure : std::runtime_error
0022     {
0023     public:
0024 
0025         expectation_failure(Iterator where, std::string const& which)
0026           : std::runtime_error("boost::spirit::x3::expectation_failure")
0027           , where_(where), which_(which)
0028         {}
0029         ~expectation_failure() {}
0030 
0031         std::string which() const { return which_; }
0032         Iterator const& where() const { return where_; }
0033 
0034     private:
0035 
0036         Iterator where_;
0037         std::string which_;
0038     };
0039 
0040     template <typename Subject>
0041     struct expect_directive : unary_parser<Subject, expect_directive<Subject>>
0042     {
0043         typedef unary_parser<Subject, expect_directive<Subject> > base_type;
0044         static bool const is_pass_through_unary = true;
0045 
0046         constexpr expect_directive(Subject const& subject)
0047           : base_type(subject) {}
0048 
0049         template <typename Iterator, typename Context
0050           , typename RContext, typename Attribute>
0051         bool parse(Iterator& first, Iterator const& last
0052           , Context const& context, RContext& rcontext, Attribute& attr) const
0053         {
0054             bool r = this->subject.parse(first, last, context, rcontext, attr);
0055 
0056             if (!r)
0057             {
0058                 boost::throw_exception(
0059                     expectation_failure<Iterator>(
0060                         first, what(this->subject)));
0061             }
0062             return r;
0063         }
0064     };
0065 
0066     struct expect_gen
0067     {
0068         template <typename Subject>
0069         constexpr expect_directive<typename extension::as_parser<Subject>::value_type>
0070         operator[](Subject const& subject) const
0071         {
0072             return { as_parser(subject) };
0073         }
0074     };
0075 
0076     constexpr auto expect = expect_gen{};
0077 }}}
0078 
0079 namespace boost { namespace spirit { namespace x3 { namespace detail
0080 {
0081     // Special case handling for expect expressions.
0082     template <typename Subject, typename Context, typename RContext>
0083     struct parse_into_container_impl<expect_directive<Subject>, Context, RContext>
0084     {
0085         template <typename Iterator, typename Attribute>
0086         static bool call(
0087             expect_directive<Subject> const& parser
0088           , Iterator& first, Iterator const& last
0089           , Context const& context, RContext& rcontext, Attribute& attr)
0090         {
0091             bool r = parse_into_container(
0092                 parser.subject, first, last, context, rcontext, attr);
0093 
0094             if (!r)
0095             {
0096                 boost::throw_exception(
0097                     expectation_failure<Iterator>(
0098                         first, what(parser.subject)));
0099             }
0100             return r;
0101         }
0102     };
0103 }}}}
0104 
0105 #endif