File indexing completed on 2025-01-19 09:47:46
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_SPIRIT_QI_OPERATOR_SEQUENCE_BASE_HPP
0009 #define BOOST_SPIRIT_QI_OPERATOR_SEQUENCE_BASE_HPP
0010
0011 #if defined(_MSC_VER)
0012 #pragma once
0013 #endif
0014
0015 #include <boost/spirit/home/qi/domain.hpp>
0016 #include <boost/spirit/home/qi/detail/pass_container.hpp>
0017 #include <boost/spirit/home/qi/detail/attributes.hpp>
0018 #include <boost/spirit/home/support/algorithm/any_if.hpp>
0019 #include <boost/spirit/home/support/detail/what_function.hpp>
0020 #include <boost/spirit/home/support/unused.hpp>
0021 #include <boost/spirit/home/support/info.hpp>
0022 #include <boost/spirit/home/support/sequence_base_id.hpp>
0023 #include <boost/spirit/home/support/has_semantic_action.hpp>
0024 #include <boost/spirit/home/qi/parser.hpp>
0025 #include <boost/fusion/include/as_vector.hpp>
0026 #include <boost/fusion/include/vector.hpp>
0027 #include <boost/fusion/include/for_each.hpp>
0028 #include <boost/mpl/identity.hpp>
0029
0030 namespace boost { namespace spirit { namespace qi
0031 {
0032 template <typename Derived, typename Elements>
0033 struct sequence_base
0034 : nary_parser<Derived>
0035 {
0036 typedef Elements elements_type;
0037 struct sequence_base_id;
0038
0039 template <typename Context, typename Iterator>
0040 struct attribute
0041 {
0042
0043 typedef typename traits::build_attribute_sequence<
0044 Elements, Context, traits::sequence_attribute_transform
0045 , Iterator, qi::domain
0046 >::type all_attributes;
0047
0048
0049
0050
0051
0052 typedef typename
0053 traits::build_fusion_vector<all_attributes>::type
0054 type_;
0055
0056
0057
0058 typedef typename
0059 traits::strip_single_element_vector<type_>::type
0060 type;
0061 };
0062
0063 sequence_base(Elements const& elements_)
0064 : elements(elements_) {}
0065
0066
0067 template <typename Iterator, typename Context
0068 , typename Skipper, typename Attribute>
0069 bool parse_impl(Iterator& first, Iterator const& last
0070 , Context& context, Skipper const& skipper
0071 , Attribute& attr_, mpl::false_) const
0072 {
0073 Iterator iter = first;
0074 typedef traits::attribute_not_unused<Context, Iterator> predicate;
0075
0076
0077
0078 typedef typename attribute<Context, Iterator>::type_ attr_type_;
0079 typename traits::wrap_if_not_tuple<Attribute
0080 , typename mpl::and_<
0081 traits::one_element_sequence<attr_type_>
0082 , mpl::not_<traits::one_element_sequence<Attribute> >
0083 >::type
0084 >::type attr_local(attr_);
0085
0086
0087 if (spirit::any_if(elements, attr_local
0088 , Derived::fail_function(iter, last, context, skipper), predicate()))
0089 return false;
0090 first = iter;
0091 return true;
0092 }
0093
0094
0095 template <typename Iterator, typename Context
0096 , typename Skipper, typename Attribute>
0097 bool parse_impl(Iterator& first, Iterator const& last
0098 , Context& context, Skipper const& skipper
0099 , Attribute& attr_, mpl::true_) const
0100 {
0101
0102 traits::make_container(attr_);
0103
0104 Iterator iter = first;
0105
0106 if (fusion::any(elements
0107 , detail::make_sequence_pass_container(
0108 Derived::fail_function(iter, last, context, skipper), attr_))
0109 )
0110 return false;
0111 first = iter;
0112 return true;
0113 }
0114
0115
0116
0117 template <typename Iterator, typename Context
0118 , typename Skipper, typename Attribute>
0119 bool parse(Iterator& first, Iterator const& last
0120 , Context& context, Skipper const& skipper
0121 , Attribute& attr_) const
0122 {
0123 return parse_impl(first, last, context, skipper, attr_
0124 , traits::is_container<Attribute>());
0125 }
0126
0127 template <typename Context>
0128 info what(Context& context) const
0129 {
0130 info result(this->derived().id());
0131 fusion::for_each(elements,
0132 spirit::detail::what_function<Context>(result, context));
0133 return result;
0134 }
0135
0136 Elements elements;
0137 };
0138 }}}
0139
0140 #endif