1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(SPIRIT_HOLD_FEBRUARY_6_2010_0917AM)
8 #define SPIRIT_HOLD_FEBRUARY_6_2010_0917AM
14 #include <boost/spirit/home/qi/meta_compiler.hpp>
15 #include <boost/spirit/home/qi/skip_over.hpp>
16 #include <boost/spirit/home/qi/parser.hpp>
17 #include <boost/spirit/home/support/attributes.hpp>
18 #include <boost/spirit/home/support/info.hpp>
19 #include <boost/spirit/home/support/common_terminals.hpp>
20 #include <boost/spirit/home/support/unused.hpp>
21 #include <boost/spirit/home/support/has_semantic_action.hpp>
22 #include <boost/spirit/home/support/handles_container.hpp>
24 namespace boost { namespace spirit
26 ///////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////
30 struct use_directive<qi::domain, tag::hold> // enables hold
34 namespace boost { namespace spirit { namespace qi
36 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
39 using spirit::hold_type;
41 template <typename Subject>
42 struct hold_directive : unary_parser<hold_directive<Subject> >
44 typedef Subject subject_type;
45 hold_directive(Subject const& subject_)
46 : subject(subject_) {}
48 template <typename Context, typename Iterator>
52 traits::attribute_of<subject_type, Context, Iterator>::type
56 template <typename Iterator, typename Context
57 , typename Skipper, typename Attribute>
58 bool parse(Iterator& first, Iterator const& last
59 , Context& context, Skipper const& skipper, Attribute& attr_) const
61 Attribute copy(attr_);
62 if (subject.parse(first, last, context, skipper, copy))
64 traits::swap_impl(copy, attr_);
70 template <typename Context>
71 info what(Context& context) const
73 return info("hold", subject.what(context));
80 ///////////////////////////////////////////////////////////////////////////
81 // Parser generators: make_xxx function (objects)
82 ///////////////////////////////////////////////////////////////////////////
83 template <typename Subject, typename Modifiers>
84 struct make_directive<tag::hold, Subject, Modifiers>
86 typedef hold_directive<Subject> result_type;
87 result_type operator()(unused_type, Subject const& subject, unused_type) const
89 return result_type(subject);
94 namespace boost { namespace spirit { namespace traits
96 ///////////////////////////////////////////////////////////////////////////
97 template <typename Subject>
98 struct has_semantic_action<qi::hold_directive<Subject> >
99 : unary_has_semantic_action<Subject> {};
101 ///////////////////////////////////////////////////////////////////////////
102 template <typename Subject, typename Attribute, typename Context
104 struct handles_container<qi::hold_directive<Subject>, Attribute
106 : unary_handles_container<Subject, Attribute, Context, Iterator> {};