1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2009 Francois Barel
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(BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM)
9 #define BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM
15 #include <boost/ref.hpp>
17 #include <boost/spirit/home/support/handles_container.hpp>
18 #include <boost/spirit/home/qi/parser.hpp>
20 namespace boost { namespace spirit { namespace qi
22 ///////////////////////////////////////////////////////////////////////////
23 // parameterized_nonterminal: parser representing the invocation of a
24 // nonterminal, passing inherited attributes
25 ///////////////////////////////////////////////////////////////////////////
26 template <typename Subject, typename Params>
27 struct parameterized_nonterminal
28 : parser<parameterized_nonterminal<Subject, Params> >
30 parameterized_nonterminal(Subject const& subject, Params const& params_)
31 : ref(subject), params(params_)
35 template <typename Context, typename Iterator>
37 // Forward to subject.
38 : Subject::template attribute<Context, Iterator> {};
40 template <typename Iterator, typename Context
41 , typename Skipper, typename Attribute>
42 bool parse(Iterator& first, Iterator const& last
43 , Context& context, Skipper const& skipper
44 , Attribute& attr_) const
46 // Forward to subject, passing the additional
47 // params argument to parse.
48 return ref.get().parse(first, last, context, skipper, attr_, params);
51 template <typename Context>
52 info what(Context& context) const
54 // Forward to subject.
55 return ref.get().what(context);
58 boost::reference_wrapper<Subject const> ref;
63 namespace boost { namespace spirit { namespace traits
65 ///////////////////////////////////////////////////////////////////////////
66 template <typename Subject, typename Params, typename Attribute
67 , typename Context, typename Iterator>
68 struct handles_container<qi::parameterized_nonterminal<Subject, Params>
69 , Attribute, Context, Iterator>
70 : handles_container<typename remove_const<Subject>::type
71 , Attribute, Context, Iterator>