/*============================================================================= Copyright (c) 2001-2007 Joel de Guzman Copyright (c) 2001-2008 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_FEB_05_2007_1153AM) #define SPIRIT_ALTERNATIVE_FEB_05_2007_1153AM #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace spirit { namespace qi { struct alternative { template struct transform_child : mpl::identity {}; template struct build_container { // if the original attribute list does not contain any unused // attributes it is used, otherwise a single unused_type is // pushed to the front the list. This is to make sure that if // there is an unused in the list it is the first one. typedef typename mpl::find_if >::type unused_; typedef typename mpl::eval_if< is_same::type>, mpl::identity, fusion::result_of::push_front >::type attribute_sequence; // Ok, now make a variant over the attribute_sequence. It's // a pity that make_variant_over does not support forward MPL // sequences. We use our own conversion metaprogram (as_variant). typedef typename as_variant::type type; }; template struct attribute : build_fusion_sequence { }; template < typename Component , typename Iterator, typename Context , typename Skipper, typename Attribute> static bool parse( Component const& component , Iterator& first, Iterator const& last , Context& context, Skipper const& skipper , Attribute& attr) { detail::alternative_function f(first, last, context, skipper, attr); // return true if *any* of the parsers succeed return fusion::any(component.elements, f); } template static std::string what(Component const& component, Context const& ctx) { std::string result = "alternatives["; fusion::for_each(component.elements, spirit::detail::what_function(result, ctx)); result += "]"; return result; } }; }}} #endif