Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:31:50

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003     Copyright (c) 2001-2011 Hartmut Kaiser
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #ifndef BOOST_SPIRIT_QI_OPERATOR_PLUS_HPP
0009 #define BOOST_SPIRIT_QI_OPERATOR_PLUS_HPP
0010 
0011 #if defined(_MSC_VER)
0012 #pragma once
0013 #endif
0014 
0015 #include <boost/spirit/home/qi/meta_compiler.hpp>
0016 #include <boost/spirit/home/qi/parser.hpp>
0017 #include <boost/spirit/home/support/container.hpp>
0018 #include <boost/spirit/home/qi/detail/attributes.hpp>
0019 #include <boost/spirit/home/qi/detail/fail_function.hpp>
0020 #include <boost/spirit/home/qi/detail/pass_container.hpp>
0021 #include <boost/spirit/home/support/has_semantic_action.hpp>
0022 #include <boost/spirit/home/support/handles_container.hpp>
0023 #include <boost/spirit/home/support/info.hpp>
0024 #include <boost/proto/operators.hpp>
0025 #include <boost/proto/tags.hpp>
0026 
0027 namespace boost { namespace spirit
0028 {
0029     ///////////////////////////////////////////////////////////////////////////
0030     // Enablers
0031     ///////////////////////////////////////////////////////////////////////////
0032     template <>
0033     struct use_operator<qi::domain, proto::tag::unary_plus> // enables +p
0034       : mpl::true_ {};
0035 }}
0036 
0037 namespace boost { namespace spirit { namespace qi
0038 {
0039     template <typename Subject>
0040     struct plus : unary_parser<plus<Subject> >
0041     {
0042         typedef Subject subject_type;
0043 
0044         template <typename Context, typename Iterator>
0045         struct attribute
0046         {
0047             // Build a std::vector from the subject's attribute. Note
0048             // that build_std_vector may return unused_type if the
0049             // subject's attribute is an unused_type.
0050             typedef typename
0051                 traits::build_std_vector<
0052                     typename traits::attribute_of<
0053                         Subject, Context, Iterator>::type
0054                 >::type
0055             type;
0056         };
0057 
0058         plus(Subject const& subject_)
0059           : subject(subject_) {}
0060 
0061         template <typename F>
0062         bool parse_container(F f) const
0063         {
0064             // in order to succeed we need to match at least one element 
0065             if (f (subject))
0066                 return false;
0067 
0068             while (!f (subject))
0069                 ;
0070             return true;
0071         }
0072 
0073         template <typename Iterator, typename Context
0074           , typename Skipper, typename Attribute>
0075         bool parse(Iterator& first, Iterator const& last
0076           , Context& context, Skipper const& skipper
0077           , Attribute& attr_) const
0078         {
0079             typedef detail::fail_function<Iterator, Context, Skipper>
0080                 fail_function;
0081 
0082             // ensure the attribute is actually a container type
0083             traits::make_container(attr_);
0084 
0085             Iterator iter = first;
0086             fail_function f(iter, last, context, skipper);
0087             if (!parse_container(detail::make_pass_container(f, attr_)))
0088                 return false;
0089 
0090             first = f.first;
0091             return true;
0092         }
0093 
0094         template <typename Context>
0095         info what(Context& context) const
0096         {
0097             return info("plus", subject.what(context));
0098         }
0099 
0100         Subject subject;
0101     };
0102 
0103     ///////////////////////////////////////////////////////////////////////////
0104     // Parser generators: make_xxx function (objects)
0105     ///////////////////////////////////////////////////////////////////////////
0106     template <typename Elements, typename Modifiers>
0107     struct make_composite<proto::tag::unary_plus, Elements, Modifiers>
0108       : make_unary_composite<Elements, plus>
0109     {};
0110 }}}
0111 
0112 namespace boost { namespace spirit { namespace traits
0113 {
0114     ///////////////////////////////////////////////////////////////////////////
0115     template <typename Subject>
0116     struct has_semantic_action<qi::plus<Subject> >
0117       : unary_has_semantic_action<Subject> {};
0118 
0119     ///////////////////////////////////////////////////////////////////////////
0120     template <typename Subject, typename Attribute, typename Context
0121       , typename Iterator>
0122     struct handles_container<qi::plus<Subject>, Attribute, Context
0123           , Iterator>
0124       : mpl::true_ {}; 
0125 }}}
0126 
0127 #endif