Chris@16
|
1 // Copyright (c) 2001-2011 Hartmut Kaiser
|
Chris@16
|
2 // Copyright (c) 2011 Thomas Heller
|
Chris@16
|
3 //
|
Chris@16
|
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM)
|
Chris@16
|
8 #define BOOST_SPIRIT_LEX_ARGUMENT_PHEONIX_MARCH_25_2011_1841PM
|
Chris@16
|
9
|
Chris@16
|
10 #if defined(_MSC_VER)
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/spirit/include/phoenix_core.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost { namespace spirit { namespace lex
|
Chris@16
|
17 {
|
Chris@16
|
18 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
19 // The value_context is used as a noop Phoenix actor to create the
|
Chris@16
|
20 // placeholder '_val' (see below). It is a noop actor because it is used
|
Chris@16
|
21 // as a placeholder only, while it is being converted either to a
|
Chris@16
|
22 // value_getter (if used as a rvalue) or to a value_setter (if used as a
|
Chris@16
|
23 // lvalue). The conversion is achieved by specializing and overloading a
|
Chris@16
|
24 // couple of the Phoenix templates from the Phoenix expression composition
|
Chris@16
|
25 // engine (see the end of this file).
|
Chris@16
|
26 struct value_context
|
Chris@16
|
27 {
|
Chris@16
|
28 typedef mpl::true_ no_nullary;
|
Chris@16
|
29
|
Chris@16
|
30 typedef unused_type result_type;
|
Chris@16
|
31
|
Chris@16
|
32 template <typename Env>
|
Chris@16
|
33 struct result
|
Chris@16
|
34 {
|
Chris@16
|
35 typedef unused_type type;
|
Chris@16
|
36 };
|
Chris@16
|
37
|
Chris@16
|
38 template <typename Env>
|
Chris@16
|
39 unused_type
|
Chris@16
|
40 eval(Env const& env) const
|
Chris@16
|
41 {
|
Chris@16
|
42 return unused;
|
Chris@16
|
43 }
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 // forward declarations
|
Chris@16
|
47 struct value_getter;
|
Chris@16
|
48 template <typename> struct value_setter;
|
Chris@16
|
49
|
Chris@16
|
50 ///////////////////////////////////////////////////////////////////////////
|
Chris@16
|
51 // The state_context is used as a noop Phoenix actor to create the
|
Chris@16
|
52 // placeholder '_state' (see below). It is a noop actor because it is used
|
Chris@16
|
53 // as a placeholder only, while it is being converted either to a
|
Chris@16
|
54 // state_getter (if used as a rvalue) or to a state_setter (if used as a
|
Chris@16
|
55 // lvalue). The conversion is achieved by specializing and overloading a
|
Chris@16
|
56 // couple of the Phoenix templates from the Phoenix expression composition
|
Chris@16
|
57 // engine (see the end of this file).
|
Chris@16
|
58 struct state_context
|
Chris@16
|
59 {
|
Chris@16
|
60 typedef mpl::true_ no_nullary;
|
Chris@16
|
61
|
Chris@16
|
62 typedef unused_type result_type;
|
Chris@16
|
63
|
Chris@16
|
64 template <typename Env>
|
Chris@16
|
65 struct result
|
Chris@16
|
66 {
|
Chris@16
|
67 typedef unused_type type;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 template <typename Env>
|
Chris@16
|
71 unused_type
|
Chris@16
|
72 eval(Env const& env) const
|
Chris@16
|
73 {
|
Chris@16
|
74 return unused;
|
Chris@16
|
75 }
|
Chris@16
|
76 };
|
Chris@16
|
77
|
Chris@16
|
78 // forward declarations
|
Chris@16
|
79 struct state_getter;
|
Chris@16
|
80 template <typename> struct state_setter;
|
Chris@16
|
81 struct eoi_getter;
|
Chris@16
|
82 }}}
|
Chris@16
|
83
|
Chris@16
|
84 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
85 #ifdef BOOST_SPIRIT_USE_PHOENIX_V3
|
Chris@16
|
86
|
Chris@16
|
87 BOOST_PHOENIX_DEFINE_EXPRESSION(
|
Chris@16
|
88 (boost)(spirit)(lex)(value_setter)
|
Chris@16
|
89 , (boost::phoenix::meta_grammar)
|
Chris@16
|
90 )
|
Chris@16
|
91
|
Chris@16
|
92 BOOST_PHOENIX_DEFINE_EXPRESSION(
|
Chris@16
|
93 (boost)(spirit)(lex)(state_setter)
|
Chris@16
|
94 , (boost::phoenix::meta_grammar)
|
Chris@16
|
95 )
|
Chris@16
|
96
|
Chris@16
|
97 namespace boost { namespace phoenix
|
Chris@16
|
98 {
|
Chris@16
|
99 namespace result_of
|
Chris@16
|
100 {
|
Chris@16
|
101 template <>
|
Chris@16
|
102 struct is_nullary<custom_terminal<boost::spirit::lex::value_context> >
|
Chris@16
|
103 : mpl::false_
|
Chris@16
|
104 {};
|
Chris@16
|
105 }
|
Chris@16
|
106
|
Chris@16
|
107 template <typename Dummy>
|
Chris@16
|
108 struct is_custom_terminal<boost::spirit::lex::value_context, Dummy>: mpl::true_ {};
|
Chris@16
|
109
|
Chris@16
|
110 template <typename Dummy>
|
Chris@16
|
111 struct custom_terminal<boost::spirit::lex::value_context, Dummy>
|
Chris@16
|
112 : proto::call<
|
Chris@16
|
113 v2_eval(
|
Chris@16
|
114 proto::make<boost::spirit::lex::value_getter()>
|
Chris@16
|
115 , proto::call<functional::env(proto::_state)>
|
Chris@16
|
116 )
|
Chris@16
|
117 >
|
Chris@16
|
118 {};
|
Chris@16
|
119
|
Chris@16
|
120 template <typename Dummy>
|
Chris@16
|
121 struct is_nullary::when<spirit::lex::rule::value_setter, Dummy>
|
Chris@16
|
122 : proto::make<mpl::false_()>
|
Chris@16
|
123 {};
|
Chris@16
|
124
|
Chris@16
|
125 template <typename Dummy>
|
Chris@16
|
126 struct default_actions::when<spirit::lex::rule::value_setter, Dummy>
|
Chris@16
|
127 : proto::call<
|
Chris@16
|
128 v2_eval(
|
Chris@16
|
129 proto::make<
|
Chris@16
|
130 spirit::lex::value_setter<proto::_child0>(
|
Chris@16
|
131 proto::_child0
|
Chris@16
|
132 )
|
Chris@16
|
133 >
|
Chris@16
|
134 , _env
|
Chris@16
|
135 )
|
Chris@16
|
136 >
|
Chris@16
|
137 {};
|
Chris@16
|
138
|
Chris@16
|
139 template <>
|
Chris@16
|
140 struct actor<spirit::lex::value_context>
|
Chris@16
|
141 : boost::phoenix::actor<proto::terminal<spirit::lex::value_context>::type>
|
Chris@16
|
142 {
|
Chris@16
|
143 typedef boost::phoenix::actor<
|
Chris@16
|
144 proto::terminal<spirit::lex::value_context>::type
|
Chris@16
|
145 > base_type;
|
Chris@16
|
146
|
Chris@16
|
147 actor(base_type const & base = base_type())
|
Chris@16
|
148 : base_type(base)
|
Chris@16
|
149 {}
|
Chris@16
|
150
|
Chris@16
|
151 template <typename Expr>
|
Chris@16
|
152 typename spirit::lex::expression::value_setter<
|
Chris@16
|
153 typename phoenix::as_actor<Expr>::type>::type const
|
Chris@16
|
154 operator=(Expr const & expr) const
|
Chris@16
|
155 {
|
Chris@16
|
156 return
|
Chris@16
|
157 spirit::lex::expression::value_setter<
|
Chris@16
|
158 typename phoenix::as_actor<Expr>::type
|
Chris@16
|
159 >::make(phoenix::as_actor<Expr>::convert(expr));
|
Chris@16
|
160 }
|
Chris@16
|
161 };
|
Chris@16
|
162
|
Chris@16
|
163 namespace result_of
|
Chris@16
|
164 {
|
Chris@16
|
165 template <>
|
Chris@16
|
166 struct is_nullary<custom_terminal<boost::spirit::lex::state_context> >
|
Chris@16
|
167 : mpl::false_
|
Chris@16
|
168 {};
|
Chris@16
|
169 }
|
Chris@16
|
170
|
Chris@16
|
171 template <typename Dummy>
|
Chris@16
|
172 struct is_custom_terminal<boost::spirit::lex::state_context, Dummy>: mpl::true_ {};
|
Chris@16
|
173
|
Chris@16
|
174 template <typename Dummy>
|
Chris@16
|
175 struct custom_terminal<boost::spirit::lex::state_context, Dummy>
|
Chris@16
|
176 : proto::call<
|
Chris@16
|
177 v2_eval(
|
Chris@16
|
178 proto::make<boost::spirit::lex::state_getter()>
|
Chris@16
|
179 , proto::call<functional::env(proto::_state)>
|
Chris@16
|
180 )
|
Chris@16
|
181 >
|
Chris@16
|
182 {};
|
Chris@16
|
183
|
Chris@16
|
184 template <typename Dummy>
|
Chris@16
|
185 struct is_nullary::when<spirit::lex::rule::state_setter, Dummy>
|
Chris@16
|
186 : proto::make<mpl::false_()>
|
Chris@16
|
187 {};
|
Chris@16
|
188
|
Chris@16
|
189 template <typename Dummy>
|
Chris@16
|
190 struct default_actions::when<spirit::lex::rule::state_setter, Dummy>
|
Chris@16
|
191 : proto::call<
|
Chris@16
|
192 v2_eval(
|
Chris@16
|
193 proto::make<
|
Chris@16
|
194 spirit::lex::state_setter<proto::_child0>(
|
Chris@16
|
195 proto::_child0
|
Chris@16
|
196 )
|
Chris@16
|
197 >
|
Chris@16
|
198 , _env
|
Chris@16
|
199 )
|
Chris@16
|
200 >
|
Chris@16
|
201 {};
|
Chris@16
|
202
|
Chris@16
|
203 template <>
|
Chris@16
|
204 struct actor<spirit::lex::state_context>
|
Chris@16
|
205 : boost::phoenix::actor<proto::terminal<spirit::lex::state_context>::type>
|
Chris@16
|
206 {
|
Chris@16
|
207 typedef boost::phoenix::actor<
|
Chris@16
|
208 proto::terminal<spirit::lex::state_context>::type
|
Chris@16
|
209 > base_type;
|
Chris@16
|
210
|
Chris@16
|
211 actor(base_type const & base = base_type())
|
Chris@16
|
212 : base_type(base)
|
Chris@16
|
213 {}
|
Chris@16
|
214
|
Chris@16
|
215 template <typename Expr>
|
Chris@16
|
216 typename spirit::lex::expression::state_setter<
|
Chris@16
|
217 typename phoenix::as_actor<Expr>::type>::type const
|
Chris@16
|
218 operator=(Expr const & expr) const
|
Chris@16
|
219 {
|
Chris@16
|
220 return
|
Chris@16
|
221 spirit::lex::expression::state_setter<
|
Chris@16
|
222 typename phoenix::as_actor<Expr>::type
|
Chris@16
|
223 >::make(phoenix::as_actor<Expr>::convert(expr));
|
Chris@16
|
224 }
|
Chris@16
|
225 };
|
Chris@16
|
226
|
Chris@16
|
227 namespace result_of
|
Chris@16
|
228 {
|
Chris@16
|
229 template <>
|
Chris@16
|
230 struct is_nullary<custom_terminal<boost::spirit::lex::eoi_getter> >
|
Chris@16
|
231 : mpl::false_
|
Chris@16
|
232 {};
|
Chris@16
|
233 }
|
Chris@16
|
234
|
Chris@16
|
235 template <typename Dummy>
|
Chris@16
|
236 struct is_custom_terminal<boost::spirit::lex::eoi_getter, Dummy>: mpl::true_ {};
|
Chris@16
|
237
|
Chris@16
|
238 template <typename Dummy>
|
Chris@16
|
239 struct custom_terminal<boost::spirit::lex::eoi_getter, Dummy>
|
Chris@16
|
240 : proto::call<
|
Chris@16
|
241 v2_eval(
|
Chris@16
|
242 proto::make<boost::spirit::lex::eoi_getter()>
|
Chris@16
|
243 , proto::call<functional::env(proto::_state)>
|
Chris@16
|
244 )
|
Chris@16
|
245 >
|
Chris@16
|
246 {};
|
Chris@16
|
247 }}
|
Chris@16
|
248
|
Chris@16
|
249 #endif // BOOST_SPIRIT_USE_PHOENIX_V3
|
Chris@16
|
250
|
Chris@16
|
251 #endif
|