/*============================================================================= Copyright (c) 2001-2010 Joel de Guzman Copyright (c) 2001-2010 Hartmut Kaiser 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_ALTERNATIVE_FEBRUARY_05_2007_1153AM) #define SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Enablers /////////////////////////////////////////////////////////////////////////// template <> struct use_operator // enables | : mpl::true_ {}; template <> struct flatten_tree // flattens | : mpl::true_ {}; }} namespace boost { namespace spirit { namespace qi { template struct alternative : nary_parser > { template struct attribute { // Put all the element attributes in a tuple typedef typename traits::build_attribute_sequence< Elements, Context, mpl::identity, Iterator>::type all_attributes; // Ok, now make a variant over the attribute sequence. Note that // build_variant makes sure that 1) all attributes in the variant // are unique 2) puts the unused attribute, if there is any, to // the front and 3) collapses single element variants, variant // to T. typedef typename traits::build_variant::type type; }; alternative(Elements const& elements) : elements(elements) {} template bool parse(Iterator& first, Iterator const& last , Context& context, Skipper const& skipper , Attribute& attr) const { detail::alternative_function f(first, last, context, skipper, attr); // return true if *any* of the parsers succeed return fusion::any(elements, f); } template info what(Context& context) const { info result("alternative"); fusion::for_each(elements, spirit::detail::what_function(result, context)); return result; } Elements elements; }; /////////////////////////////////////////////////////////////////////////// // Parser generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// template struct make_composite : make_nary_composite {}; }}} namespace boost { namespace spirit { namespace traits { template struct has_semantic_action > : nary_has_semantic_action {}; }}} #endif