Chris@16: /*============================================================================= Chris@16: Copyright (c) 2001-2011 Joel de Guzman Chris@16: Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: #if !defined(SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM) Chris@16: #define SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Enablers Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template <> Chris@16: struct use_operator // enables | Chris@16: : mpl::true_ {}; Chris@16: Chris@16: template <> Chris@16: struct flatten_tree // flattens | Chris@16: : mpl::true_ {}; Chris@16: }} Chris@16: Chris@16: namespace boost { namespace spirit { namespace qi Chris@16: { Chris@16: template Chris@16: struct alternative : nary_parser > Chris@16: { Chris@16: template Chris@16: struct attribute Chris@16: { Chris@16: // Put all the element attributes in a tuple Chris@16: typedef typename traits::build_attribute_sequence< Chris@16: Elements, Context, traits::alternative_attribute_transform Chris@16: , Iterator, qi::domain Chris@16: >::type all_attributes; Chris@16: Chris@16: // Ok, now make a variant over the attribute sequence. Note that Chris@16: // build_variant makes sure that 1) all attributes in the variant Chris@16: // are unique 2) puts the unused attribute, if there is any, to Chris@16: // the front and 3) collapses single element variants, variant Chris@16: // to T. Chris@16: typedef typename Chris@16: traits::build_variant::type Chris@16: type; Chris@16: }; Chris@16: Chris@16: alternative(Elements const& elements_) Chris@16: : elements(elements_) {} Chris@16: Chris@16: template Chris@16: bool parse(Iterator& first, Iterator const& last Chris@16: , Context& context, Skipper const& skipper Chris@16: , Attribute& attr_) const Chris@16: { Chris@16: detail::alternative_function Chris@16: f(first, last, context, skipper, attr_); Chris@16: Chris@16: // return true if *any* of the parsers succeed Chris@16: return fusion::any(elements, f); Chris@16: } Chris@16: Chris@16: template Chris@16: info what(Context& context) const Chris@16: { Chris@16: info result("alternative"); Chris@16: fusion::for_each(elements, Chris@16: spirit::detail::what_function(result, context)); Chris@16: return result; Chris@16: } Chris@16: Chris@16: Elements elements; Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Parser generators: make_xxx function (objects) Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct make_composite Chris@16: : make_nary_composite Chris@16: {}; Chris@16: }}} Chris@16: Chris@16: namespace boost { namespace spirit { namespace traits Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct has_semantic_action > Chris@16: : nary_has_semantic_action {}; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct handles_container, Attribute, Context Chris@16: , Iterator> Chris@16: : nary_handles_container {}; Chris@16: }}} Chris@16: Chris@16: #endif