annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/operator/alternative.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Joel de Guzman
Chris@16 3 Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 4
Chris@16 5 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 =============================================================================*/
Chris@16 8 #if !defined(SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM)
Chris@16 9 #define SPIRIT_ALTERNATIVE_FEBRUARY_05_2007_1153AM
Chris@16 10
Chris@16 11 #if defined(_MSC_VER)
Chris@16 12 #pragma once
Chris@16 13 #endif
Chris@16 14
Chris@16 15 #include <boost/spirit/home/qi/detail/alternative_function.hpp>
Chris@16 16 #include <boost/spirit/home/qi/meta_compiler.hpp>
Chris@16 17 #include <boost/spirit/home/qi/parser.hpp>
Chris@16 18 #include <boost/spirit/home/qi/detail/attributes.hpp>
Chris@16 19 #include <boost/spirit/home/support/has_semantic_action.hpp>
Chris@16 20 #include <boost/spirit/home/support/handles_container.hpp>
Chris@16 21 #include <boost/spirit/home/support/detail/what_function.hpp>
Chris@16 22 #include <boost/spirit/home/support/unused.hpp>
Chris@16 23 #include <boost/spirit/home/support/info.hpp>
Chris@16 24 #include <boost/fusion/include/any.hpp>
Chris@16 25 #include <boost/fusion/include/mpl.hpp>
Chris@16 26 #include <boost/fusion/include/for_each.hpp>
Chris@16 27
Chris@16 28 namespace boost { namespace spirit
Chris@16 29 {
Chris@16 30 ///////////////////////////////////////////////////////////////////////////
Chris@16 31 // Enablers
Chris@16 32 ///////////////////////////////////////////////////////////////////////////
Chris@16 33 template <>
Chris@16 34 struct use_operator<qi::domain, proto::tag::bitwise_or> // enables |
Chris@16 35 : mpl::true_ {};
Chris@16 36
Chris@16 37 template <>
Chris@16 38 struct flatten_tree<qi::domain, proto::tag::bitwise_or> // flattens |
Chris@16 39 : mpl::true_ {};
Chris@16 40 }}
Chris@16 41
Chris@16 42 namespace boost { namespace spirit { namespace qi
Chris@16 43 {
Chris@16 44 template <typename Elements>
Chris@16 45 struct alternative : nary_parser<alternative<Elements> >
Chris@16 46 {
Chris@16 47 template <typename Context, typename Iterator>
Chris@16 48 struct attribute
Chris@16 49 {
Chris@16 50 // Put all the element attributes in a tuple
Chris@16 51 typedef typename traits::build_attribute_sequence<
Chris@16 52 Elements, Context, traits::alternative_attribute_transform
Chris@16 53 , Iterator, qi::domain
Chris@16 54 >::type all_attributes;
Chris@16 55
Chris@16 56 // Ok, now make a variant over the attribute sequence. Note that
Chris@16 57 // build_variant makes sure that 1) all attributes in the variant
Chris@16 58 // are unique 2) puts the unused attribute, if there is any, to
Chris@16 59 // the front and 3) collapses single element variants, variant<T>
Chris@16 60 // to T.
Chris@16 61 typedef typename
Chris@16 62 traits::build_variant<all_attributes>::type
Chris@16 63 type;
Chris@16 64 };
Chris@16 65
Chris@16 66 alternative(Elements const& elements_)
Chris@16 67 : elements(elements_) {}
Chris@16 68
Chris@16 69 template <typename Iterator, typename Context
Chris@16 70 , typename Skipper, typename Attribute>
Chris@16 71 bool parse(Iterator& first, Iterator const& last
Chris@16 72 , Context& context, Skipper const& skipper
Chris@16 73 , Attribute& attr_) const
Chris@16 74 {
Chris@16 75 detail::alternative_function<Iterator, Context, Skipper, Attribute>
Chris@16 76 f(first, last, context, skipper, attr_);
Chris@16 77
Chris@16 78 // return true if *any* of the parsers succeed
Chris@16 79 return fusion::any(elements, f);
Chris@16 80 }
Chris@16 81
Chris@16 82 template <typename Context>
Chris@16 83 info what(Context& context) const
Chris@16 84 {
Chris@16 85 info result("alternative");
Chris@16 86 fusion::for_each(elements,
Chris@16 87 spirit::detail::what_function<Context>(result, context));
Chris@16 88 return result;
Chris@16 89 }
Chris@16 90
Chris@16 91 Elements elements;
Chris@16 92 };
Chris@16 93
Chris@16 94 ///////////////////////////////////////////////////////////////////////////
Chris@16 95 // Parser generators: make_xxx function (objects)
Chris@16 96 ///////////////////////////////////////////////////////////////////////////
Chris@16 97 template <typename Elements, typename Modifiers>
Chris@16 98 struct make_composite<proto::tag::bitwise_or, Elements, Modifiers>
Chris@16 99 : make_nary_composite<Elements, alternative>
Chris@16 100 {};
Chris@16 101 }}}
Chris@16 102
Chris@16 103 namespace boost { namespace spirit { namespace traits
Chris@16 104 {
Chris@16 105 ///////////////////////////////////////////////////////////////////////////
Chris@16 106 template <typename Elements>
Chris@16 107 struct has_semantic_action<qi::alternative<Elements> >
Chris@16 108 : nary_has_semantic_action<Elements> {};
Chris@16 109
Chris@16 110 ///////////////////////////////////////////////////////////////////////////
Chris@16 111 template <typename Elements, typename Attribute, typename Context
Chris@16 112 , typename Iterator>
Chris@16 113 struct handles_container<qi::alternative<Elements>, Attribute, Context
Chris@16 114 , Iterator>
Chris@16 115 : nary_handles_container<Elements, Attribute, Context, Iterator> {};
Chris@16 116 }}}
Chris@16 117
Chris@16 118 #endif