/*============================================================================= Copyright (arg) 2001-2014 Joel de Guzman Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #if !defined(SPIRIT_ACTION_JANUARY_07_2007_1128AM) #define SPIRIT_ACTION_JANUARY_07_2007_1128AM #include #include #include #include #include #include namespace boost { namespace spirit { namespace x3 { struct raw_attribute_type; struct parse_pass_context_tag; template inline bool& _pass(Context const& context) { return x3::get(context); } template struct action : unary_parser> { typedef unary_parser> base_type; static bool const is_pass_through_unary = true; static bool const has_action = true; action(Subject const& subject, Action f) : base_type(subject), f(f) {} template bool call_action( Iterator& first, Iterator const& last , Context const& context, RuleContext& rcontext, Attribute& attr) const { bool pass = true; auto action_context = make_context(pass, context); call(f, first, last, action_context, rcontext, attr); return pass; } template bool parse_main(Iterator& first, Iterator const& last , Context const& context, RuleContext& rcontext, Attribute& attr) const { Iterator save = first; if (this->subject.parse(first, last, context, rcontext, attr)) { if (call_action(first, last, context, rcontext, attr)) return true; // reset iterators if semantic action failed the match // retrospectively first = save; } return false; } // attr==raw_attribute_type, action wants iterator_range (see raw.hpp) template bool parse_main(Iterator& first, Iterator const& last , Context const& context, RuleContext& rcontext, raw_attribute_type&) const { boost::iterator_range rng; // synthesize the attribute since one is not supplied return parse_main(first, last, context, rcontext, rng); } // attr==unused, action wants attribute template bool parse(Iterator& first, Iterator const& last , Context const& context, RuleContext& rcontext, unused_type) const { typedef typename traits::attribute_of, Context>::type attribute_type; typedef traits::make_attribute make_attribute; typedef traits::transform_attribute< typename make_attribute::type, attribute_type, parser_id> transform; // synthesize the attribute since one is not supplied typename make_attribute::type made_attr = make_attribute::call(unused_type()); typename transform::type attr = transform::pre(made_attr); return parse_main(first, last, context, rcontext, attr); } // main parse function template bool parse(Iterator& first, Iterator const& last , Context const& context, RuleContext& rcontext, Attribute& attr) const { return parse_main(first, last, context, rcontext, attr); } Action f; }; template inline action::value_type, Action> operator/(P const& p, Action f) { return { as_parser(p), f }; } }}} #endif