Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2009 Francois Barel
|
Chris@16
|
4
|
Chris@16
|
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 ==============================================================================*/
|
Chris@16
|
8 #if !defined(BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM)
|
Chris@16
|
9 #define BOOST_SPIRIT_PARAMETERIZED_AUGUST_09_2009_0539AM
|
Chris@16
|
10
|
Chris@16
|
11 #if defined(_MSC_VER)
|
Chris@16
|
12 #pragma once
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/ref.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/spirit/home/support/handles_container.hpp>
|
Chris@16
|
18 #include <boost/spirit/home/qi/parser.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace spirit { namespace qi
|
Chris@16
|
21 {
|
Chris@16
|
22 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
23 // parameterized_nonterminal: parser representing the invocation of a
|
Chris@16
|
24 // nonterminal, passing inherited attributes
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 template <typename Subject, typename Params>
|
Chris@16
|
27 struct parameterized_nonterminal
|
Chris@16
|
28 : parser<parameterized_nonterminal<Subject, Params> >
|
Chris@16
|
29 {
|
Chris@16
|
30 parameterized_nonterminal(Subject const& subject, Params const& params_)
|
Chris@16
|
31 : ref(subject), params(params_)
|
Chris@16
|
32 {
|
Chris@16
|
33 }
|
Chris@16
|
34
|
Chris@16
|
35 template <typename Context, typename Iterator>
|
Chris@16
|
36 struct attribute
|
Chris@16
|
37 // Forward to subject.
|
Chris@16
|
38 : Subject::template attribute<Context, Iterator> {};
|
Chris@16
|
39
|
Chris@16
|
40 template <typename Iterator, typename Context
|
Chris@16
|
41 , typename Skipper, typename Attribute>
|
Chris@16
|
42 bool parse(Iterator& first, Iterator const& last
|
Chris@16
|
43 , Context& context, Skipper const& skipper
|
Chris@16
|
44 , Attribute& attr_) const
|
Chris@16
|
45 {
|
Chris@16
|
46 // Forward to subject, passing the additional
|
Chris@16
|
47 // params argument to parse.
|
Chris@16
|
48 return ref.get().parse(first, last, context, skipper, attr_, params);
|
Chris@16
|
49 }
|
Chris@16
|
50
|
Chris@16
|
51 template <typename Context>
|
Chris@16
|
52 info what(Context& context) const
|
Chris@16
|
53 {
|
Chris@16
|
54 // Forward to subject.
|
Chris@16
|
55 return ref.get().what(context);
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 boost::reference_wrapper<Subject const> ref;
|
Chris@16
|
59 Params params;
|
Chris@16
|
60 };
|
Chris@16
|
61 }}}
|
Chris@16
|
62
|
Chris@16
|
63 namespace boost { namespace spirit { namespace traits
|
Chris@16
|
64 {
|
Chris@16
|
65 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
66 template <typename Subject, typename Params, typename Attribute
|
Chris@16
|
67 , typename Context, typename Iterator>
|
Chris@16
|
68 struct handles_container<qi::parameterized_nonterminal<Subject, Params>
|
Chris@16
|
69 , Attribute, Context, Iterator>
|
Chris@16
|
70 : handles_container<typename remove_const<Subject>::type
|
Chris@16
|
71 , Attribute, Context, Iterator>
|
Chris@16
|
72 {};
|
Chris@16
|
73 }}}
|
Chris@16
|
74
|
Chris@16
|
75 #endif
|