Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/spirit/home/qi/operator/kleene.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_KLEENE_HPP
0009 #define BOOST_SPIRIT_QI_OPERATOR_KLEENE_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     //[composite_parsers_kleene_enable_
0033     template <>
0034     struct use_operator<qi::domain, proto::tag::dereference> // enables *p
0035       : mpl::true_ {};
0036     //]
0037 }}
0038 
0039 namespace boost { namespace spirit { namespace qi
0040 {
0041     //[composite_parsers_kleene
0042     template <typename Subject>
0043     struct kleene : unary_parser<kleene<Subject> >
0044     {
0045         typedef Subject subject_type;
0046 
0047         template <typename Context, typename Iterator>
0048         struct attribute
0049         {
0050             // Build a std::vector from the subject's attribute. Note
0051             // that build_std_vector may return unused_type if the
0052             // subject's attribute is an unused_type.
0053             typedef typename
0054                 traits::build_std_vector<
0055                     typename traits::
0056                         attribute_of<Subject, Context, Iterator>::type
0057                 >::type
0058             type;
0059         };
0060 
0061         kleene(Subject const& subject_)
0062           : subject(subject_) {}
0063 
0064         template <typename F>
0065         bool parse_container(F f) const
0066         {
0067             while (!f (subject))
0068                 ;
0069             return true;
0070         }
0071 
0072         template <typename Iterator, typename Context
0073           , typename Skipper, typename Attribute>
0074         bool parse(Iterator& first, Iterator const& last
0075           , Context& context, Skipper const& skipper
0076           , Attribute& attr_) const
0077         {
0078             // ensure the attribute is actually a container type
0079             traits::make_container(attr_);
0080 
0081             typedef detail::fail_function<Iterator, Context, Skipper>
0082                 fail_function;
0083 
0084             Iterator iter = first;
0085             fail_function f(iter, last, context, skipper);
0086             parse_container(detail::make_pass_container(f, attr_));
0087 
0088             first = f.first;
0089             return true;
0090         }
0091 
0092         template <typename Context>
0093         info what(Context& context) const
0094         {
0095             return info("kleene", subject.what(context));
0096         }
0097 
0098         Subject subject;
0099     };
0100     //]
0101 
0102     ///////////////////////////////////////////////////////////////////////////
0103     // Parser generators: make_xxx function (objects)
0104     ///////////////////////////////////////////////////////////////////////////
0105     //[composite_parsers_kleene_generator
0106     template <typename Elements, typename Modifiers>
0107     struct make_composite<proto::tag::dereference, Elements, Modifiers>
0108       : make_unary_composite<Elements, kleene>
0109     {};
0110     //]
0111 
0112 //     ///////////////////////////////////////////////////////////////////////////
0113 //     // Define what attributes are compatible with a kleene
0114 //     template <typename Attribute, typename Subject, typename Context, typename Iterator>
0115 //     struct is_attribute_compatible<Attribute, kleene<Subject>, Context, Iterator>
0116 //       : traits::is_container_compatible<qi::domain, Attribute
0117 //               , kleene<Subject>, Context, Iterator>
0118 //     {};
0119 }}}
0120 
0121 namespace boost { namespace spirit { namespace traits
0122 {
0123     ///////////////////////////////////////////////////////////////////////////
0124     template <typename Subject>
0125     struct has_semantic_action<qi::kleene<Subject> >
0126       : unary_has_semantic_action<Subject> {};
0127 
0128     ///////////////////////////////////////////////////////////////////////////
0129     template <typename Subject, typename Attribute, typename Context
0130       , typename Iterator>
0131     struct handles_container<qi::kleene<Subject>, Attribute
0132           , Context, Iterator>
0133       : mpl::true_ {}; 
0134 }}}
0135 
0136 #endif