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_ACTION_JANUARY_07_2007_1128AM)
0008 #define BOOST_SPIRIT_X3_ACTION_JANUARY_07_2007_1128AM
0009 
0010 #include <boost/spirit/home/x3/support/context.hpp>
0011 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
0012 #include <boost/spirit/home/x3/core/call.hpp>
0013 #include <boost/spirit/home/x3/nonterminal/detail/transform_attribute.hpp>
0014 #include <boost/range/iterator_range_core.hpp>
0015 
0016 namespace boost { namespace spirit { namespace x3
0017 {
0018     struct raw_attribute_type;
0019     struct parse_pass_context_tag;
0020 
0021     template <typename Context>
0022     inline bool& _pass(Context const& context)
0023     {
0024         return x3::get<parse_pass_context_tag>(context);
0025     }
0026 
0027     template <typename Subject, typename Action>
0028     struct action : unary_parser<Subject, action<Subject, Action>>
0029     {
0030         typedef unary_parser<Subject, action<Subject, Action>> base_type;
0031         static bool const is_pass_through_unary = true;
0032         static bool const has_action = true;
0033 
0034         constexpr action(Subject const& subject, Action f)
0035           : base_type(subject), f(f) {}
0036 
0037         template <typename Iterator, typename Context, typename RuleContext, typename Attribute>
0038         bool call_action(
0039             Iterator& first, Iterator const& last
0040           , Context const& context, RuleContext& rcontext, Attribute& attr) const
0041         {
0042             bool pass = true;
0043             auto action_context = make_context<parse_pass_context_tag>(pass, context);
0044             call(f, first, last, action_context, rcontext, attr);
0045             return pass;
0046         }
0047 
0048         template <typename Iterator, typename Context
0049           , typename RuleContext, typename Attribute>
0050         bool parse_main(Iterator& first, Iterator const& last
0051           , Context const& context, RuleContext& rcontext, Attribute& attr) const
0052         {
0053             Iterator save = first;
0054             if (this->subject.parse(first, last, context, rcontext, attr))
0055             {
0056                 if (call_action(first, last, context, rcontext, attr))
0057                     return true;
0058 
0059                 // reset iterators if semantic action failed the match
0060                 // retrospectively
0061                 first = save;
0062             }
0063             return false;
0064         }
0065         
0066         // attr==raw_attribute_type, action wants iterator_range (see raw.hpp)
0067         template <typename Iterator, typename Context, typename RuleContext>
0068         bool parse_main(Iterator& first, Iterator const& last
0069           , Context const& context, RuleContext& rcontext, raw_attribute_type&) const
0070         {
0071             boost::iterator_range<Iterator> rng;
0072             // synthesize the attribute since one is not supplied
0073             return parse_main(first, last, context, rcontext, rng);
0074         }
0075 
0076         // attr==unused, action wants attribute
0077         template <typename Iterator, typename Context, typename RuleContext>
0078         bool parse(Iterator& first, Iterator const& last
0079           , Context const& context, RuleContext& rcontext, unused_type) const
0080         {
0081             typedef typename
0082                 traits::attribute_of<action<Subject, Action>, Context>::type
0083             attribute_type;
0084 
0085             // synthesize the attribute since one is not supplied
0086             attribute_type attribute{};
0087             return parse_main(first, last, context, rcontext, attribute);
0088         }
0089         
0090         // main parse function
0091         template <typename Iterator, typename Context
0092             , typename RuleContext, typename Attribute>
0093         bool parse(Iterator& first, Iterator const& last
0094           , Context const& context, RuleContext& rcontext, Attribute& attr) const
0095         {
0096             return parse_main(first, last, context, rcontext, attr);
0097         }
0098 
0099         Action f;
0100     };
0101 
0102     template <typename P, typename Action>
0103     constexpr action<typename extension::as_parser<P>::value_type, Action>
0104     operator/(P const& p, Action f)
0105     {
0106         return { as_parser(p), f };
0107     }
0108 }}}
0109 
0110 #endif