1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2001-2011 Hartmut Kaiser
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #if !defined(SPIRIT_PLUS_MARCH_13_2007_0127PM)
9 #define SPIRIT_PLUS_MARCH_13_2007_0127PM
15 #include <boost/spirit/home/qi/meta_compiler.hpp>
16 #include <boost/spirit/home/qi/parser.hpp>
17 #include <boost/spirit/home/support/container.hpp>
18 #include <boost/spirit/home/qi/detail/attributes.hpp>
19 #include <boost/spirit/home/qi/detail/fail_function.hpp>
20 #include <boost/spirit/home/qi/detail/pass_container.hpp>
21 #include <boost/spirit/home/support/has_semantic_action.hpp>
22 #include <boost/spirit/home/support/handles_container.hpp>
23 #include <boost/spirit/home/support/info.hpp>
25 namespace boost { namespace spirit
27 ///////////////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////////////////
31 struct use_operator<qi::domain, proto::tag::unary_plus> // enables +p
35 namespace boost { namespace spirit { namespace qi
37 template <typename Subject>
38 struct plus : unary_parser<plus<Subject> >
40 typedef Subject subject_type;
42 template <typename Context, typename Iterator>
45 // Build a std::vector from the subject's attribute. Note
46 // that build_std_vector may return unused_type if the
47 // subject's attribute is an unused_type.
49 traits::build_std_vector<
50 typename traits::attribute_of<
51 Subject, Context, Iterator>::type
56 plus(Subject const& subject)
60 bool parse_container(F f) const
62 // in order to succeed we need to match at least one element
71 template <typename Iterator, typename Context
72 , typename Skipper, typename Attribute>
73 bool parse(Iterator& first, Iterator const& last
74 , Context& context, Skipper const& skipper
75 , Attribute& attr) const
77 typedef detail::fail_function<Iterator, Context, Skipper>
80 // ensure the attribute is actually a container type
81 traits::make_container(attr);
83 Iterator iter = first;
84 fail_function f(iter, last, context, skipper);
85 if (!parse_container(detail::make_pass_container(f, attr)))
92 template <typename Context>
93 info what(Context& context) const
95 return info("plus", subject.what(context));
101 ///////////////////////////////////////////////////////////////////////////
102 // Parser generators: make_xxx function (objects)
103 ///////////////////////////////////////////////////////////////////////////
104 template <typename Elements, typename Modifiers>
105 struct make_composite<proto::tag::unary_plus, Elements, Modifiers>
106 : make_unary_composite<Elements, plus>
110 namespace boost { namespace spirit { namespace traits
112 ///////////////////////////////////////////////////////////////////////////
113 template <typename Subject>
114 struct has_semantic_action<qi::plus<Subject> >
115 : unary_has_semantic_action<Subject> {};
117 ///////////////////////////////////////////////////////////////////////////
118 template <typename Subject, typename Attribute, typename Context
120 struct handles_container<qi::plus<Subject>, Attribute, Context