Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/spirit/home/lex/argument.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Copyright (c) 2001-2011 Hartmut Kaiser | |
2 // Copyright (c) 2001-2011 Joel de Guzman | |
3 // Copyright (c) 2010 Bryce Lelbach | |
4 // Copyright (c) 2011 Thomas Heller | |
5 // | |
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | |
9 #if !defined(BOOST_SPIRIT_LEX_ARGUMENT_JUNE_07_2009_1106AM) | |
10 #define BOOST_SPIRIT_LEX_ARGUMENT_JUNE_07_2009_1106AM | |
11 | |
12 #if defined(_MSC_VER) | |
13 #pragma once | |
14 #endif | |
15 | |
16 #include <boost/spirit/include/phoenix_core.hpp> | |
17 #include <boost/spirit/include/phoenix_operator.hpp> | |
18 #include <boost/spirit/home/support/string_traits.hpp> | |
19 #include <boost/spirit/home/lex/argument_phoenix.hpp> | |
20 #include <boost/fusion/include/at.hpp> | |
21 #include <boost/mpl/at.hpp> | |
22 #include <boost/mpl/bool.hpp> | |
23 #include <boost/type_traits/is_same.hpp> | |
24 #include <boost/type_traits/remove_const.hpp> | |
25 #include <boost/type_traits/remove_reference.hpp> | |
26 | |
27 /////////////////////////////////////////////////////////////////////////////// | |
28 namespace boost { namespace spirit { namespace lex | |
29 { | |
30 /////////////////////////////////////////////////////////////////////////// | |
31 // The state_getter is a Phoenix actor used to access the name of the | |
32 // current lexer state by calling get_state_name() on the context (which | |
33 // is the 5th parameter to any lexer semantic actions). | |
34 // | |
35 // This Phoenix actor is invoked whenever the placeholder '_state' is used | |
36 // as a rvalue inside a lexer semantic action: | |
37 // | |
38 // lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
39 // this->self = identifier [ std::cout << _state ]; | |
40 // | |
41 // The example shows how to print the lexer state after matching a token | |
42 // 'identifier'. | |
43 struct state_getter | |
44 { | |
45 typedef mpl::true_ no_nullary; | |
46 | |
47 template <typename Env> | |
48 struct result | |
49 { | |
50 typedef | |
51 typename remove_reference< | |
52 typename remove_const< | |
53 typename mpl::at_c<typename Env::args_type, 4>::type | |
54 >::type | |
55 >::type | |
56 context_type; | |
57 | |
58 typedef typename context_type::state_name_type type; | |
59 }; | |
60 | |
61 template <typename Env> | |
62 typename result<Env>::type | |
63 eval(Env const& env) const | |
64 { | |
65 return fusion::at_c<4>(env.args()).get_state_name(); | |
66 } | |
67 }; | |
68 | |
69 /////////////////////////////////////////////////////////////////////////// | |
70 // The state_setter is a Phoenix actor used to change the name of the | |
71 // current lexer state by calling set_state_name() on the context (which | |
72 // is the 5th parameter to any lexer semantic actions). | |
73 // | |
74 // This Phoenix actor is invoked whenever the placeholder '_state' is used | |
75 // as a lvalue inside a lexer semantic action: | |
76 // | |
77 // lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
78 // this->self = identifier [ _state = "SOME_LEXER_STATE" ]; | |
79 // | |
80 // The example shows how to change the lexer state after matching a token | |
81 // 'identifier'. | |
82 template <typename Actor> | |
83 struct state_setter | |
84 { | |
85 typedef mpl::true_ no_nullary; | |
86 | |
87 template <typename Env> | |
88 struct result | |
89 { | |
90 typedef void type; | |
91 }; | |
92 | |
93 template <typename Env> | |
94 void eval(Env const& env) const | |
95 { | |
96 typedef | |
97 typename remove_reference< | |
98 typename remove_const< | |
99 typename mpl::at_c<typename Env::args_type, 4>::type | |
100 >::type | |
101 >::type | |
102 context_type; | |
103 | |
104 typedef typename context_type::state_name_type string; | |
105 | |
106 fusion::at_c<4>(env.args()).set_state_name( | |
107 traits::get_c_string(actor_.eval(env))); | |
108 } | |
109 | |
110 state_setter(Actor const& actor) | |
111 : actor_(actor) {} | |
112 | |
113 // see explanation for this constructor at the end of this file | |
114 #ifndef BOOST_SPIRIT_USE_PHOENIX_V3 | |
115 state_setter(phoenix::actor<state_getter>, Actor const& actor) | |
116 : actor_(actor) {} | |
117 #endif | |
118 | |
119 Actor actor_; | |
120 }; | |
121 | |
122 /////////////////////////////////////////////////////////////////////////// | |
123 // The value_getter is used to create the _val placeholder, which is a | |
124 // Phoenix actor used to access the value of the current token. | |
125 // | |
126 // This Phoenix actor is invoked whenever the placeholder '_val' is used | |
127 // as a rvalue inside a lexer semantic action: | |
128 // | |
129 // lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
130 // this->self = identifier [ std::cout << _val ]; | |
131 // | |
132 // The example shows how to use _val to print the identifier name (which | |
133 // is the initial token value). | |
134 struct value_getter | |
135 { | |
136 typedef mpl::true_ no_nullary; | |
137 | |
138 template <typename Env> | |
139 struct result | |
140 { | |
141 typedef | |
142 typename remove_reference< | |
143 typename remove_const< | |
144 typename mpl::at_c<typename Env::args_type, 4>::type | |
145 >::type | |
146 >::type | |
147 context_type; | |
148 | |
149 typedef typename context_type::get_value_type type; | |
150 }; | |
151 | |
152 template <typename Env> | |
153 typename result<Env>::type | |
154 eval(Env const& env) const | |
155 { | |
156 return fusion::at_c<4>(env.args()).get_value(); | |
157 } | |
158 }; | |
159 | |
160 /////////////////////////////////////////////////////////////////////////// | |
161 // The value_setter is a Phoenix actor used to change the name of the | |
162 // current lexer state by calling set_state_name() on the context (which | |
163 // is the 5th parameter to any lexer semantic actions). | |
164 // | |
165 // This Phoenix actor is invoked whenever the placeholder '_val' is used | |
166 // as a lvalue inside a lexer semantic action: | |
167 // | |
168 // lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
169 // this->self = identifier [ _val = "identifier" ]; | |
170 // | |
171 // The example shows how to change the token value after matching a token | |
172 // 'identifier'. | |
173 template <typename Actor> | |
174 struct value_setter | |
175 { | |
176 typedef mpl::true_ no_nullary; | |
177 | |
178 template <typename Env> | |
179 struct result | |
180 { | |
181 typedef void type; | |
182 }; | |
183 | |
184 template <typename Env> | |
185 void eval(Env const& env) const | |
186 { | |
187 fusion::at_c<4>(env.args()).set_value(actor_.eval(env)); | |
188 } | |
189 | |
190 value_setter(Actor const& actor) | |
191 : actor_(actor) {} | |
192 | |
193 #ifndef BOOST_SPIRIT_USE_PHOENIX_V3 | |
194 // see explanation for this constructor at the end of this file | |
195 value_setter(phoenix::actor<value_getter>, Actor const& actor) | |
196 : actor_(actor) {} | |
197 #endif | |
198 | |
199 Actor actor_; | |
200 }; | |
201 | |
202 /////////////////////////////////////////////////////////////////////////// | |
203 // The eoi_getter is used to create the _eoi placeholder, which is a | |
204 // Phoenix actor used to access the end of input iterator pointing to the | |
205 // end of the underlying input sequence. | |
206 // | |
207 // This actor is invoked whenever the placeholder '_eoi' is used in a | |
208 // lexer semantic action: | |
209 // | |
210 // lex::token_def<> identifier = "[a-zA-Z_][a-zA-Z0-9_]*"; | |
211 // this->self = identifier | |
212 // [ std::cout << construct_<std::string>(_end, _eoi) ]; | |
213 // | |
214 // The example shows how to use _eoi to print all remaining input after | |
215 // matching a token 'identifier'. | |
216 struct eoi_getter | |
217 { | |
218 typedef mpl::true_ no_nullary; | |
219 | |
220 template <typename Env> | |
221 struct result | |
222 { | |
223 typedef | |
224 typename remove_reference< | |
225 typename remove_const< | |
226 typename mpl::at_c<typename Env::args_type, 4>::type | |
227 >::type | |
228 >::type | |
229 context_type; | |
230 | |
231 typedef typename context_type::base_iterator_type const& type; | |
232 }; | |
233 | |
234 template <typename Env> | |
235 typename result<Env>::type | |
236 eval(Env const& env) const | |
237 { | |
238 return fusion::at_c<4>(env.args()).get_eoi(); | |
239 } | |
240 }; | |
241 | |
242 /////////////////////////////////////////////////////////////////////////// | |
243 // '_start' and '_end' may be used to access the start and the end of | |
244 // the matched sequence of the current token | |
245 typedef phoenix::arg_names::_1_type _start_type; | |
246 typedef phoenix::arg_names::_2_type _end_type; | |
247 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
248 _start_type const _start = _start_type(); | |
249 _end_type const _end = _end_type(); | |
250 #endif | |
251 | |
252 // We are reusing the placeholder '_pass' to access and change the pass | |
253 // status of the current match (see support/argument.hpp for its | |
254 // definition). | |
255 // typedef phoenix::arg_names::_3_type _pass_type; | |
256 using boost::spirit::_pass_type; | |
257 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
258 using boost::spirit::_pass; | |
259 #endif | |
260 | |
261 // '_tokenid' may be used to access and change the tokenid of the current | |
262 // token | |
263 typedef phoenix::arg_names::_4_type _tokenid_type; | |
264 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
265 _tokenid_type const _tokenid = _tokenid_type(); | |
266 #endif | |
267 | |
268 typedef phoenix::actor<value_context> _val_type; | |
269 typedef phoenix::actor<state_context> _state_type; | |
270 typedef phoenix::actor<eoi_getter> _eoi_type; | |
271 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS | |
272 // '_val' may be used to access and change the token value of the current | |
273 // token | |
274 _val_type const _val = _val_type(); | |
275 // _state may be used to access and change the name of the current lexer | |
276 // state | |
277 _state_type const _state = _state_type(); | |
278 // '_eoi' may be used to access the end of input iterator of the input | |
279 // stream used by the lexer to match tokens from | |
280 _eoi_type const _eoi = _eoi_type(); | |
281 #endif | |
282 }}} | |
283 | |
284 /////////////////////////////////////////////////////////////////////////////// | |
285 #ifndef BOOST_SPIRIT_USE_PHOENIX_V3 | |
286 namespace boost { namespace phoenix | |
287 { | |
288 /////////////////////////////////////////////////////////////////////////// | |
289 // The specialization of as_actor_base<> below is needed to convert all | |
290 // occurrences of _state in places where it's used as a rvalue into the | |
291 // proper Phoenix actor (spirit::state_getter) accessing the lexer state. | |
292 template<> | |
293 struct as_actor_base<actor<spirit::lex::state_context> > | |
294 { | |
295 typedef spirit::lex::state_getter type; | |
296 | |
297 static spirit::lex::state_getter | |
298 convert(actor<spirit::lex::state_context>) | |
299 { | |
300 return spirit::lex::state_getter(); | |
301 } | |
302 }; | |
303 | |
304 /////////////////////////////////////////////////////////////////////////// | |
305 // The specialization of as_composite<> below is needed to convert all | |
306 // assignments to _state (places where it's used as a lvalue) into the | |
307 // proper Phoenix actor (spirit::state_setter) allowing to change the | |
308 // lexer state. | |
309 template <typename RHS> | |
310 struct as_composite<assign_eval, actor<spirit::lex::state_context>, RHS> | |
311 { | |
312 // For an assignment to _state (a spirit::state_context actor), this | |
313 // specialization makes Phoenix's compose() function construct a | |
314 // spirit::state_setter actor from 1. the LHS, a spirit::state_getter | |
315 // actor (due to the specialization of as_actor_base<> above), | |
316 // and 2. the RHS actor. | |
317 // This is why spirit::state_setter needs a constructor which takes | |
318 // a dummy spirit::state_getter as its first argument in addition | |
319 // to its real, second argument (the RHS actor). | |
320 typedef spirit::lex::state_setter<typename as_actor<RHS>::type> type; | |
321 }; | |
322 | |
323 /////////////////////////////////////////////////////////////////////////// | |
324 // The specialization of as_actor_base<> below is needed to convert all | |
325 // occurrences of _val in places where it's used as a rvalue into the | |
326 // proper Phoenix actor (spirit::value_getter) accessing the token value. | |
327 template<> | |
328 struct as_actor_base<actor<spirit::lex::value_context> > | |
329 { | |
330 typedef spirit::lex::value_getter type; | |
331 | |
332 static spirit::lex::value_getter | |
333 convert(actor<spirit::lex::value_context>) | |
334 { | |
335 return spirit::lex::value_getter(); | |
336 } | |
337 }; | |
338 | |
339 /////////////////////////////////////////////////////////////////////////// | |
340 // The specialization of as_composite<> below is needed to convert all | |
341 // assignments to _val (places where it's used as a lvalue) into the | |
342 // proper Phoenix actor (spirit::value_setter) allowing to change the | |
343 // token value. | |
344 template <typename RHS> | |
345 struct as_composite<assign_eval, actor<spirit::lex::value_context>, RHS> | |
346 { | |
347 // For an assignment to _val (a spirit::value_context actor), this | |
348 // specialization makes Phoenix's compose() function construct a | |
349 // spirit::value_setter actor from 1. the LHS, a spirit::value_getter | |
350 // actor (due to the specialization of as_actor_base<> above), | |
351 // and 2. the RHS actor. | |
352 // This is why spirit::value_setter needs a constructor which takes | |
353 // a dummy spirit::value_getter as its first argument in addition | |
354 // to its real, second argument (the RHS actor). | |
355 typedef spirit::lex::value_setter<typename as_actor<RHS>::type> type; | |
356 }; | |
357 }} | |
358 #endif | |
359 | |
360 #undef SPIRIT_DECLARE_ARG | |
361 #endif | |
362 |