Chris@16
|
1 /*==============================================================================
|
Chris@16
|
2 Copyright (c) 2006 Tobias Schwinger
|
Chris@16
|
3 http://spirit.sourceforge.net/
|
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 // The comment below contains a unnamed 'namespace {', which is flagged by the
|
Chris@16
|
9 // Boost inspect tool as a violation of common C++ programming rules. Since it's
|
Chris@16
|
10 // in a comment, well, we switch it off :-P
|
Chris@16
|
11 // boostinspect:nounnamed
|
Chris@16
|
12
|
Chris@16
|
13 //
|
Chris@16
|
14 // About:
|
Chris@16
|
15 // =====
|
Chris@16
|
16 //
|
Chris@16
|
17 // Using a typeof operator or Boost.Typeof to automatically set the type of
|
Chris@16
|
18 // variables (as done in the Spirit example demonstrating typeof) is by far not
|
Chris@101
|
19 // all we can do to tighten up our grammars as there are some significant
|
Chris@16
|
20 // drawbacks of this approach:
|
Chris@16
|
21 // - the types complexity scales with the complexity of the grammar (sooner or
|
Chris@16
|
22 // later hitting the limits of the compiler),
|
Chris@16
|
23 // - recursive grammars are not possible, and
|
Chris@16
|
24 // - all parser objects are embedded by value.
|
Chris@16
|
25 //
|
Chris@16
|
26 // The Spirit documentation therefore recommends creating custom parser classes
|
Chris@16
|
27 // (derived from the a sub_grammar template):
|
Chris@16
|
28 //
|
Chris@16
|
29 // http://www.boost.org/libs/spirit/doc/techniques.html#no_rules
|
Chris@16
|
30 // http://www.boost.org/libs/spirit/doc/techniques.html#typeof
|
Chris@16
|
31 //
|
Chris@16
|
32 // In practice manually applying this technique leads to rather lengthy code and
|
Chris@16
|
33 // overthis requires the user to have a solid understanding of Spirit details.
|
Chris@16
|
34 //
|
Chris@101
|
35 // Here is a generalized, macro-based approach to easily create typeof-based
|
Chris@16
|
36 // grammars that can be recursive and arbitrarily complex.
|
Chris@16
|
37 //
|
Chris@16
|
38 //
|
Chris@16
|
39 // Quick manual:
|
Chris@16
|
40 // ============
|
Chris@101
|
41 //
|
Chris@16
|
42 // 1. Setup
|
Chris@101
|
43 //
|
Chris@101
|
44 // Before the rule parser macro (the protagonist of the facility) can be used
|
Chris@101
|
45 // the user must define the macro BOOST_SPIRIT__NAMESPACE (note the double
|
Chris@16
|
46 // underscore characeter) and setup a registration group for Boost.Typeof.
|
Chris@101
|
47 //
|
Chris@16
|
48 // Examples:
|
Chris@101
|
49 //
|
Chris@16
|
50 // // should come after regular #includeS
|
Chris@16
|
51 // #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
Chris@101
|
52 //
|
Chris@16
|
53 // // [...]
|
Chris@101
|
54 //
|
Chris@16
|
55 // #define BOOST_SPIRIT__NAMESPACE (2,(my_project, my_module))
|
Chris@16
|
56 // // | | +- outer +- inner
|
Chris@16
|
57 // // ! space ! -+ | namespace namespace
|
Chris@16
|
58 // // |
|
Chris@16
|
59 // // +--- number of nested namespaces
|
Chris@101
|
60 //
|
Chris@16
|
61 // namespace my_project { namespace my_module {
|
Chris@101
|
62 //
|
Chris@16
|
63 // // [...]
|
Chris@101
|
64 //
|
Chris@16
|
65 // ---
|
Chris@101
|
66 //
|
Chris@16
|
67 // // should come after regular #includeS
|
Chris@16
|
68 // #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
Chris@101
|
69 //
|
Chris@16
|
70 // // [...]
|
Chris@101
|
71 //
|
Chris@16
|
72 // #define BOOST_SPIRIT__NAMESPACE (2,(my_project, (anonymous) ))
|
Chris@101
|
73 //
|
Chris@16
|
74 // namespace my_project { namespace {
|
Chris@101
|
75 //
|
Chris@16
|
76 // // [...]
|
Chris@101
|
77 //
|
Chris@16
|
78 // ---
|
Chris@101
|
79 //
|
Chris@16
|
80 // // should come after regular #includeS
|
Chris@16
|
81 // #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
Chris@101
|
82 //
|
Chris@16
|
83 // // [...]
|
Chris@101
|
84 //
|
Chris@101
|
85 //
|
Chris@16
|
86 // #define BOOST_SPIRIT__NAMESPACE -
|
Chris@16
|
87 // // we're working at root namespace
|
Chris@101
|
88 //
|
Chris@101
|
89 //
|
Chris@16
|
90 // Why do I have to do this?
|
Chris@101
|
91 //
|
Chris@16
|
92 // Boost.Typeof needs to assign a unique ID for each registration. This ID is
|
Chris@101
|
93 // created composed of the line number and the registration group. The
|
Chris@16
|
94 // facility performs Typeof registration and thus requires the source file to
|
Chris@16
|
95 // have its own registration group. Further Boost.Typeof requires registration
|
Chris@16
|
96 // to happen at root namespace so we have to close and reopen the namespace
|
Chris@16
|
97 // we're in.
|
Chris@16
|
98 //
|
Chris@101
|
99 //
|
Chris@16
|
100 // 2. The rule parser macro
|
Chris@101
|
101 //
|
Chris@16
|
102 // A simple rule parser definition looks like that:
|
Chris@101
|
103 //
|
Chris@16
|
104 // // we're at namespace scope here
|
Chris@101
|
105 //
|
Chris@16
|
106 // // Skip parser for C/C++ comments and whitespace
|
Chris@101
|
107 // BOOST_SPIRIT_RULE_PARSER(skipper,
|
Chris@101
|
108 // -,-,-,
|
Chris@101
|
109 //
|
Chris@101
|
110 // +( confix_p("//",*anychar_p,eol_p)
|
Chris@16
|
111 // | confix_p("/*",*anychar_p,"*/")
|
Chris@101
|
112 // | space_p
|
Chris@16
|
113 // )
|
Chris@16
|
114 // )
|
Chris@101
|
115 //
|
Chris@16
|
116 // Now we can use 'skipper' in other Spirit expressions.
|
Chris@101
|
117 //
|
Chris@101
|
118 // The code above creates a parser (template) class 'skpper_t' and (in this
|
Chris@101
|
119 // case, because there are no parameters) a static const instance 'skipper' of
|
Chris@16
|
120 // that class. The class is automatically registered with Boost.Typeof. The type
|
Chris@16
|
121 // name our parser is skipper_t here.
|
Chris@101
|
122 //
|
Chris@101
|
123 //
|
Chris@16
|
124 // 2.1. Parametrized rule parsers
|
Chris@101
|
125 //
|
Chris@16
|
126 // Rule parser definitions can have parameters.
|
Chris@101
|
127 //
|
Chris@16
|
128 // Parameters are passed to the BOOST_SPIRIT_RULE_PARSER macro as its second
|
Chris@101
|
129 // argument (just pass '-' if there are no parameters) with the following
|
Chris@16
|
130 // format:
|
Chris@101
|
131 //
|
Chris@16
|
132 // (N,( param1,param2, / ... / paramN ))
|
Chris@16
|
133 // +-- number of parameters
|
Chris@101
|
134 //
|
Chris@16
|
135 // Example of a whole rule parser:
|
Chris@101
|
136 //
|
Chris@16
|
137 // BOOST_SPIRIT_RULE_PARSER(new_name,
|
Chris@16
|
138 // (1,( symbol_table )),-,-,
|
Chris@101
|
139 //
|
Chris@16
|
140 // lexeme_d[ (alpha_p >> *alnum_p)[ symbol_table.add ] ]
|
Chris@16
|
141 // )
|
Chris@101
|
142 //
|
Chris@16
|
143 // The expression 'new_name(my_symbols)' parses a string literal and adds it to
|
Chris@16
|
144 // the symbol table 'my_symbols'.
|
Chris@101
|
145 //
|
Chris@16
|
146 // The rule parser macro creates a function template as called 'new_name' that
|
Chris@16
|
147 // takes one parameter of deduced reference type and returns a specialization of
|
Chris@16
|
148 // 'new_name_t' in this case.
|
Chris@101
|
149 //
|
Chris@101
|
150 // Since parsers that require to be fast and lightweight often also require to
|
Chris@101
|
151 // be reentrant, it's quite common to pass in some semantic controller (the
|
Chris@16
|
152 // symbol table in the example above).
|
Chris@101
|
153 // However, parameters are templated so they can be anything (including parsers
|
Chris@16
|
154 // of course) so refactoring tasks can be abstracted with rule parsers as well.
|
Chris@101
|
155 //
|
Chris@16
|
156 // BOOST_SPIRIT_RULE_PARSER(enumeration_parser,
|
Chris@16
|
157 // (2,( element_parser, delimiter_parser )),-,-,
|
Chris@101
|
158 //
|
Chris@16
|
159 // element_parser >> *(delimiter_parser >> element_parser)
|
Chris@101
|
160 // )
|
Chris@101
|
161 //
|
Chris@101
|
162 // The expression 'enumeration_parser(int_p[ some_action ], ',')' creates a
|
Chris@16
|
163 // parser for a comma-separated list of integers.
|
Chris@101
|
164 //
|
Chris@101
|
165 //
|
Chris@16
|
166 // 2.2. Rule parsrs and semantic actions
|
Chris@101
|
167 //
|
Chris@16
|
168 // While semantic actions can be globally attached to a rule parser or passed
|
Chris@101
|
169 // to a parametrized rule parser as (part of) an argument, even more control is
|
Chris@16
|
170 // possible by using action placeholders. E.g:
|
Chris@101
|
171 //
|
Chris@16
|
172 // BOOST_SPIRIT_ACTION_PLACEHOLDER(int_action)
|
Chris@101
|
173 //
|
Chris@16
|
174 // BOOST_SPIRIT_RULE_PARSER(int_list,
|
Chris@16
|
175 // -,(1,( int_action )),-,
|
Chris@101
|
176 //
|
Chris@16
|
177 // int_p[ int_action ] >> *(',' >> int_p[ int_action ])
|
Chris@16
|
178 // )
|
Chris@101
|
179 //
|
Chris@101
|
180 // The expression 'int_list[ my_action ]' parses a comma separated list of
|
Chris@16
|
181 // integers and calls 'my_action' for every integer parsed therein.
|
Chris@101
|
182 //
|
Chris@101
|
183 // Of course multiple actions can be attached to one placeholder as usual (in
|
Chris@16
|
184 // this case 'int_list[ my_action1 ][ my_action2 ] would call two actions).
|
Chris@101
|
185 //
|
Chris@16
|
186 // Further there can be multiple action placeholders for a single rule parser:
|
Chris@101
|
187 //
|
Chris@16
|
188 // BOOST_SPIRIT_ACTION_PLACEHOLDER(feed_int)
|
Chris@16
|
189 // BOOST_SPIRIT_ACTION_PLACEHOLDER(next_int)
|
Chris@101
|
190 //
|
Chris@16
|
191 // BOOST_SPIRIT_RULE_PARSER(int_list,
|
Chris@16
|
192 // -,(2,( feed_int, next_int )),-,
|
Chris@101
|
193 //
|
Chris@16
|
194 // int_p[ feed_int ] >> *(',' >> int_p[ next_int ][ feed_int ])
|
Chris@16
|
195 // )
|
Chris@101
|
196 //
|
Chris@16
|
197 // The expression 'int_list[ (feed_int = my_action1), (next_int = my_action2) ]'
|
Chris@101
|
198 // creates a parser for a comma separated list of integers with the actions
|
Chris@16
|
199 // attached appropriately.
|
Chris@101
|
200 //
|
Chris@16
|
201 // int_list[ feed_int = my_action1,my_action2, next_int = my_action3 ]
|
Chris@101
|
202 //
|
Chris@101
|
203 // works too (in this case the action placeholder 'feed_int' has two actions
|
Chris@16
|
204 // attached to it).
|
Chris@101
|
205 //
|
Chris@101
|
206 // You can both override and append actions associated with an action
|
Chris@16
|
207 // placeholder:
|
Chris@101
|
208 //
|
Chris@16
|
209 // var = int_list[ feed_int = my_action1, next_int = my_action2 ]
|
Chris@101
|
210 //
|
Chris@16
|
211 // // [...]
|
Chris@101
|
212 //
|
Chris@101
|
213 // ... var[ feed_int = another_action ]
|
Chris@16
|
214 // // 'another_action' overrides the actions previously attached to 'feed_int'
|
Chris@101
|
215 //
|
Chris@16
|
216 // ... var[ next_int += another_action ]
|
Chris@101
|
217 // // 'another_action' is appended to the list of actions attached to
|
Chris@16
|
218 // // 'next_int'
|
Chris@101
|
219 //
|
Chris@16
|
220 // Action placeholders are not entirely for free -- they add to the size and the
|
Chris@101
|
221 // initialization time of the rule parser. However, the impact on an already
|
Chris@16
|
222 // initialized rule parser instance should be quite small.
|
Chris@101
|
223 //
|
Chris@101
|
224 //
|
Chris@16
|
225 // 2.3. Member variables
|
Chris@101
|
226 //
|
Chris@101
|
227 // You can add member variables to the rule parser class using the third
|
Chris@16
|
228 // parameter of the rule parser macro:
|
Chris@101
|
229 //
|
Chris@16
|
230 // BOOST_SPIRIT_RULE_PARSER( calc,
|
Chris@16
|
231 // -,
|
Chris@16
|
232 // -,
|
Chris@16
|
233 // (3,( ((subrule<0>),expression,()),
|
Chris@16
|
234 // ((subrule<1>),term,()),
|
Chris@16
|
235 // ((subrule<2>),factor,() )) ),
|
Chris@101
|
236 //
|
Chris@16
|
237 // // [...]
|
Chris@101
|
238 //
|
Chris@16
|
239 // adds three subrules to the rule parser.
|
Chris@16
|
240 // Each parameter must have the following type to allow commas to be handled
|
Chris@16
|
241 // safely from within the preprocessing code:
|
Chris@101
|
242 //
|
Chris@16
|
243 // ((type)),name,(constructor argument(s)))
|
Chris@101
|
244 //
|
Chris@16
|
245 //
|
Chris@16
|
246 // 2.4. The opaque rule parser
|
Chris@16
|
247 //
|
Chris@101
|
248 // Rule parsers usually are templates. Building large grammars pushes the
|
Chris@101
|
249 // compiler really hard (and eventually to its limits) because of the
|
Chris@16
|
250 // metafunction complexity involved.
|
Chris@101
|
251 // If a rule parser without parameters and action placeholders is defined, a
|
Chris@16
|
252 // non-template class is created. Non-templated rule parsers can also be created
|
Chris@101
|
253 // explicitly by using BOOST_SPIRIT_OPAQUE_RULE_PARSER.
|
Chris@16
|
254 // Opaque rule parsers can have parameters and member variables (note: no action
|
Chris@101
|
255 // placeholders are possible). The parameters of an opaque rule parsers are
|
Chris@16
|
256 // strictly typed, e.g:
|
Chris@16
|
257 //
|
Chris@16
|
258 // BOOST_SPIRIT_OPAQUE_RULE_PARSER(new_identifier,
|
Chris@16
|
259 // (1,( ((my_symbol_table_t &),symbol_table) ))
|
Chris@16
|
260 // ,-,
|
Chris@16
|
261 // (alpha_p >> *alnum_p) [ symbol_table.add ]
|
Chris@101
|
262 // )
|
Chris@16
|
263 //
|
Chris@101
|
264 // Note it's also possible to have opaque rule parsers accept parameters of
|
Chris@16
|
265 // non-const reference types which is not possible with regular rule parsers.
|
Chris@16
|
266 //
|
Chris@16
|
267 //
|
Chris@16
|
268 // 3. Utilities for by-reference embedding
|
Chris@101
|
269 //
|
Chris@101
|
270 // When using parsers mutiple times or recursively it can be helpful to embed
|
Chris@16
|
271 // them by-reference into the final parser expression.
|
Chris@16
|
272 // For this purpose the library provides a wrapper template 'parser_reference'.
|
Chris@16
|
273 // There is also a function template to create a wrapped parser which can deduce
|
Chris@16
|
274 // the parser's type from its argument.
|
Chris@16
|
275 //
|
Chris@16
|
276 // --- --- - - --- - - --- - - - - --- - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
277 #if !defined(BOOST_SPIRIT_UTILITY_RULE_PARSER_HPP_INCLUDED)
|
Chris@16
|
278 # define BOOST_SPIRIT_UTILITY_RULE_PARSER_HPP_INCLUDED
|
Chris@16
|
279 //==============================================================================
|
Chris@16
|
280 // Dependencies
|
Chris@16
|
281 //==============================================================================
|
Chris@16
|
282 # include <boost/config.hpp>
|
Chris@16
|
283 # include <boost/detail/workaround.hpp>
|
Chris@16
|
284 # include <boost/call_traits.hpp>
|
Chris@16
|
285 # include <boost/typeof/typeof.hpp>
|
Chris@16
|
286 # include <boost/spirit/home/classic/namespace.hpp>
|
Chris@16
|
287 # include <boost/spirit/home/classic/core/parser.hpp>
|
Chris@16
|
288 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
289 # include <boost/preprocessor/cat.hpp>
|
Chris@16
|
290 # include <boost/preprocessor/seq/seq.hpp>
|
Chris@16
|
291 # include <boost/preprocessor/seq/for_each_i.hpp>
|
Chris@16
|
292 # include <boost/preprocessor/tuple/eat.hpp>
|
Chris@16
|
293 # include <boost/preprocessor/tuple/to_seq.hpp>
|
Chris@16
|
294 # include <boost/preprocessor/array/size.hpp>
|
Chris@16
|
295 # include <boost/preprocessor/control/if.hpp>
|
Chris@16
|
296 # include <boost/preprocessor/control/iif.hpp>
|
Chris@16
|
297 # include <boost/preprocessor/control/expr_iif.hpp>
|
Chris@16
|
298 # include <boost/preprocessor/logical/or.hpp>
|
Chris@16
|
299 # include <boost/preprocessor/logical/nor.hpp>
|
Chris@16
|
300 # include <boost/preprocessor/logical/not.hpp>
|
Chris@16
|
301 # include <boost/preprocessor/logical/compl.hpp>
|
Chris@16
|
302 # include <boost/preprocessor/arithmetic/inc.hpp>
|
Chris@16
|
303 # include <boost/preprocessor/arithmetic/dec.hpp>
|
Chris@16
|
304 # include <boost/preprocessor/arithmetic/add.hpp>
|
Chris@16
|
305 # include <boost/preprocessor/detail/is_unary.hpp>
|
Chris@16
|
306 # include <boost/preprocessor/detail/is_binary.hpp>
|
Chris@16
|
307 # include <boost/preprocessor/repetition/repeat.hpp>
|
Chris@16
|
308 # include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@16
|
309 # include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
Chris@16
|
310 # include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
Chris@16
|
311 # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
Chris@16
|
312 # include <boost/preprocessor/punctuation/comma.hpp>
|
Chris@16
|
313 # include <boost/preprocessor/punctuation/comma_if.hpp>
|
Chris@16
|
314 # include <boost/preprocessor/facilities/empty.hpp>
|
Chris@16
|
315 # include <boost/preprocessor/facilities/identity.hpp>
|
Chris@16
|
316 # include <boost/preprocessor/facilities/intercept.hpp>
|
Chris@16
|
317 //==============================================================================
|
Chris@16
|
318 // Interface
|
Chris@16
|
319 //==============================================================================
|
Chris@16
|
320 // Creates a rule parser. Use at namespace scope.
|
Chris@16
|
321 # define BOOST_SPIRIT_RULE_PARSER(name,params,actions,members,rule) \
|
Chris@16
|
322 BOOST_SPIRIT_RP_IMPL_I(name,params,actions,members,rule)
|
Chris@16
|
323 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
324 // Creates a non-templated rule parser. Use at namespace scope.
|
Chris@16
|
325 # define BOOST_SPIRIT_OPAQUE_RULE_PARSER(name,params,members,rule) \
|
Chris@16
|
326 BOOST_SPIRIT_RP_OPAQUE_IMPL_I(name,params,members,rule)
|
Chris@16
|
327 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
328 // Defines an action placeholder. Use at namespace scope.
|
Chris@16
|
329 # define BOOST_SPIRIT_ACTION_PLACEHOLDER(name) \
|
Chris@16
|
330 BOOST_SPIRIT_RP_AP_IMPL(name,::BOOST_SPIRIT_CLASSIC_NS::type_of)
|
Chris@16
|
331 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
332 // Utilities to embed parsers by reference.
|
Chris@16
|
333 namespace boost
|
Chris@16
|
334 {
|
Chris@16
|
335 namespace spirit
|
Chris@16
|
336 {
|
Chris@16
|
337 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
338
|
Chris@16
|
339 template<class P> class parser_reference;
|
Chris@16
|
340 template<class P> parser_reference<P> embed_by_reference(parser<P> const &);
|
Chris@16
|
341
|
Chris@16
|
342 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
343 }
|
Chris@16
|
344 }
|
Chris@16
|
345 //==============================================================================
|
Chris@16
|
346 // Implementation
|
Chris@16
|
347 //==============================================================================
|
Chris@16
|
348 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
Chris@16
|
349 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
350 // RP_REGISTER_TEMPLATE
|
Chris@16
|
351 //
|
Chris@101
|
352 // Boost.Typeof registration from within BOOST_SPIRIT__NAMESPACE
|
Chris@16
|
353 # define BOOST_SPIRIT_RP_REGISTER_TEMPLATE(name,params) \
|
Chris@16
|
354 BOOST_SPIRIT_RP_EMIT(NS_CLOSE,BOOST_SPIRIT__NAMESPACE,-) \
|
Chris@16
|
355 BOOST_TYPEOF_REGISTER_TEMPLATE( \
|
Chris@16
|
356 BOOST_SPIRIT_RP_EMIT(NS_QUALIFY,BOOST_SPIRIT__NAMESPACE,-) name, \
|
Chris@16
|
357 params) \
|
Chris@101
|
358 BOOST_SPIRIT_RP_EMIT(NS_OPEN,BOOST_SPIRIT__NAMESPACE,-)
|
Chris@16
|
359 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
360 // RP_REGISTER_TYPE
|
Chris@16
|
361 //
|
Chris@101
|
362 // Boost.Typeof registration from within BOOST_SPIRIT__NAMESPACE
|
Chris@16
|
363 # define BOOST_SPIRIT_RP_REGISTER_TYPE(name) \
|
Chris@16
|
364 BOOST_SPIRIT_RP_EMIT(NS_CLOSE,BOOST_SPIRIT__NAMESPACE,-) \
|
Chris@16
|
365 BOOST_TYPEOF_REGISTER_TYPE( \
|
Chris@16
|
366 BOOST_SPIRIT_RP_EMIT(NS_QUALIFY,BOOST_SPIRIT__NAMESPACE,-) name ) \
|
Chris@101
|
367 BOOST_SPIRIT_RP_EMIT(NS_OPEN,BOOST_SPIRIT__NAMESPACE,-)
|
Chris@16
|
368 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
369 // RP_AP_IMPL
|
Chris@16
|
370 //
|
Chris@16
|
371 // The action placeholder definition
|
Chris@16
|
372 # define BOOST_SPIRIT_RP_AP_IMPL(name,ns) \
|
Chris@16
|
373 namespace __action_placeholder \
|
Chris@16
|
374 { \
|
Chris@16
|
375 struct name \
|
Chris@16
|
376 { \
|
Chris@16
|
377 template<typename Action> \
|
Chris@16
|
378 ns :: action_chain< name, ns :: replace, Action> \
|
Chris@16
|
379 operator=(Action const & __a) const \
|
Chris@16
|
380 { return ns :: action_chain< name, ns :: replace, Action>(__a); } \
|
Chris@16
|
381 \
|
Chris@16
|
382 template<typename Action> \
|
Chris@16
|
383 ns :: action_chain< name, ns :: append, Action> \
|
Chris@16
|
384 operator+=(Action const & __a) const \
|
Chris@16
|
385 { return ns :: action_chain< name, ns :: append, Action> (__a); } \
|
Chris@16
|
386 }; \
|
Chris@16
|
387 } \
|
Chris@101
|
388 __action_placeholder:: name const name = __action_placeholder:: name ();
|
Chris@16
|
389 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
390 // RP_IMPL_I
|
Chris@16
|
391 //
|
Chris@16
|
392 // Does some precalculation so RP_IMPL_II can look cleaner
|
Chris@16
|
393 # define BOOST_SPIRIT_RP_IMPL_I(name,pars,acts,mbrs,expr) \
|
Chris@16
|
394 BOOST_SPIRIT_RP_IMPL_II(name, name ## _t , \
|
Chris@16
|
395 pars, BOOST_SPIRIT_RP_ARRAY_SIZE(pars), \
|
Chris@16
|
396 acts, BOOST_SPIRIT_RP_ARRAY_SIZE(acts), \
|
Chris@16
|
397 mbrs, BOOST_SPIRIT_RP_ARRAY_SIZE(mbrs), expr)
|
Chris@16
|
398 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
399 // RP_IMPL_II
|
Chris@16
|
400 # define BOOST_SPIRIT_RP_IMPL_II(name,name_t,pars,np,acts,na,mbrs,nm,x) \
|
Chris@16
|
401 BOOST_PP_IIF(BOOST_PP_OR(np,na),BOOST_SPIRIT_RP_IMPL_III, \
|
Chris@16
|
402 BOOST_SPIRIT_RP_OPAQUE_IMPL_II) \
|
Chris@16
|
403 (name,name_t,pars,np,acts,na,mbrs,nm,x)
|
Chris@16
|
404 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
405 // RP_IMPL_III
|
Chris@16
|
406 //
|
Chris@16
|
407 // The rule parser definition
|
Chris@16
|
408 # define BOOST_SPIRIT_RP_IMPL_III(name,name_t,pars,np,acts,na,mbrs,nm,x) \
|
Chris@16
|
409 \
|
Chris@16
|
410 template< BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,typename __,1) > \
|
Chris@16
|
411 class name_t \
|
Chris@101
|
412 : public ::BOOST_SPIRIT_CLASSIC_NS::parser< name_t \
|
Chris@16
|
413 < BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,__,0) > > \
|
Chris@16
|
414 { \
|
Chris@16
|
415 class __rule \
|
Chris@16
|
416 { \
|
Chris@16
|
417 BOOST_SPIRIT_RP_EMIT(PM_STATIC,pars,__T) \
|
Chris@16
|
418 BOOST_SPIRIT_RP_EMIT(AP_STATIC,acts,-) \
|
Chris@16
|
419 BOOST_SPIRIT_RP_EMIT(MV_STATIC,mbrs,BOOST_PP_IDENTITY(typename)) \
|
Chris@16
|
420 public: \
|
Chris@16
|
421 BOOST_TYPEOF_NESTED_TYPEDEF_TPL(__expr, \
|
Chris@101
|
422 ::BOOST_SPIRIT_CLASSIC_NS::type_of::depend_on_type<__Dummy>(x) ) \
|
Chris@16
|
423 }; \
|
Chris@16
|
424 \
|
Chris@16
|
425 public: \
|
Chris@16
|
426 \
|
Chris@16
|
427 typedef name_t self_t; \
|
Chris@16
|
428 typedef typename __rule::__expr::type::parser_category_t \
|
Chris@16
|
429 parser_category_t; \
|
Chris@16
|
430 \
|
Chris@16
|
431 BOOST_PP_EXPR_IIF(BOOST_PP_NOR(np,na),typedef self_t const & embed_t;) \
|
Chris@16
|
432 \
|
Chris@16
|
433 protected: \
|
Chris@16
|
434 \
|
Chris@16
|
435 BOOST_SPIRIT_RP_EMIT(MV_NONSTATIC,mbrs,BOOST_PP_IDENTITY(typename)) \
|
Chris@16
|
436 BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_AP_EXTRA_MBRS,2)(np,na) \
|
Chris@16
|
437 \
|
Chris@16
|
438 typename __rule::__expr::type::embed_t __parser; \
|
Chris@16
|
439 \
|
Chris@16
|
440 public: \
|
Chris@16
|
441 \
|
Chris@16
|
442 explicit name_t ( BOOST_SPIRIT_RP_CTOR(PARAMS,pars,np,acts) ) \
|
Chris@16
|
443 : BOOST_SPIRIT_RP_EMIT(MV_CTOR_INIT_LIST,mbrs,-) \
|
Chris@16
|
444 BOOST_PP_COMMA_IF(nm) \
|
Chris@16
|
445 BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_CTOR_COMMA,4)(INIT_LIST,pars,np,acts)\
|
Chris@16
|
446 __parser(x) \
|
Chris@16
|
447 { } \
|
Chris@16
|
448 \
|
Chris@16
|
449 name_t( name_t const & that) \
|
Chris@16
|
450 : BOOST_SPIRIT_RP_EMIT(MV_CTOR_COPY_INIT_LIST,mbrs,that) \
|
Chris@16
|
451 BOOST_PP_COMMA_IF(nm) \
|
Chris@16
|
452 BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_CTOR_COMMA,4) \
|
Chris@16
|
453 (COPY_INIT_LIST,pars,np,acts) \
|
Chris@16
|
454 __parser(that.__parser) \
|
Chris@16
|
455 { } \
|
Chris@16
|
456 \
|
Chris@16
|
457 template<typename Scanner> struct result \
|
Chris@16
|
458 { \
|
Chris@16
|
459 typedef typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result< \
|
Chris@16
|
460 typename __rule::__expr::type, Scanner>::type type; \
|
Chris@16
|
461 }; \
|
Chris@16
|
462 \
|
Chris@16
|
463 template<typename Scanner> \
|
Chris@16
|
464 typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<self_t, Scanner>::type \
|
Chris@16
|
465 parse(Scanner const & s) const { return __parser.parse(s); } \
|
Chris@16
|
466 \
|
Chris@16
|
467 BOOST_SPIRIT_RP_IF(na,SPIRIT_RP_AP_HANDLER,5) \
|
Chris@16
|
468 (name_t,np,acts,na,::BOOST_SPIRIT_CLASSIC_NS::type_of) \
|
Chris@16
|
469 }; \
|
Chris@16
|
470 \
|
Chris@16
|
471 BOOST_PP_IF(np,BOOST_SPIRIT_RP_GEN_FUNC,BOOST_SPIRIT_RP_GLOB_VAR) \
|
Chris@16
|
472 (name,name_t,np,na) \
|
Chris@16
|
473 BOOST_SPIRIT_RP_REGISTER_TEMPLATE \
|
Chris@101
|
474 (name_t,BOOST_PP_INC(BOOST_PP_ADD(np,na)))
|
Chris@16
|
475 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
476 // RP_OPAQUE_IMPL_I
|
Chris@16
|
477 //
|
Chris@16
|
478 # define BOOST_SPIRIT_RP_OPAQUE_IMPL_I(name,pars,mbrs,expr) \
|
Chris@16
|
479 BOOST_SPIRIT_RP_OPAQUE_IMPL_II(name, name ## _t, \
|
Chris@16
|
480 pars,BOOST_SPIRIT_RP_ARRAY_SIZE(pars),-,-,\
|
Chris@16
|
481 mbrs,BOOST_SPIRIT_RP_ARRAY_SIZE(mbrs),expr)
|
Chris@16
|
482 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
483 // RP_OPAQUE_IMPL_II
|
Chris@16
|
484 //
|
Chris@16
|
485 # define BOOST_SPIRIT_RP_OPAQUE_IMPL_II(name,name_t,pars,np,_1,_2,mbrs,nm,x) \
|
Chris@16
|
486 class name_t; \
|
Chris@16
|
487 \
|
Chris@16
|
488 BOOST_SPIRIT_RP_REGISTER_TYPE(name_t) \
|
Chris@16
|
489 \
|
Chris@16
|
490 class name_t \
|
Chris@16
|
491 : public ::BOOST_SPIRIT_CLASSIC_NS::parser< name_t > \
|
Chris@16
|
492 { \
|
Chris@16
|
493 class __rule \
|
Chris@16
|
494 { \
|
Chris@16
|
495 BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_STATIC,pars,-) \
|
Chris@16
|
496 BOOST_SPIRIT_RP_EMIT(MV_STATIC,mbrs,BOOST_PP_EMPTY) \
|
Chris@16
|
497 public: \
|
Chris@16
|
498 BOOST_TYPEOF_NESTED_TYPEDEF(__expr,x) \
|
Chris@16
|
499 }; \
|
Chris@16
|
500 \
|
Chris@16
|
501 public: \
|
Chris@16
|
502 \
|
Chris@16
|
503 typedef name_t self_t; \
|
Chris@16
|
504 typedef __rule::__expr::type::parser_category_t parser_category_t; \
|
Chris@16
|
505 BOOST_PP_EXPR_IIF(BOOST_PP_NOT(np),typedef self_t const & embed_t;) \
|
Chris@16
|
506 \
|
Chris@16
|
507 protected: \
|
Chris@16
|
508 \
|
Chris@16
|
509 BOOST_SPIRIT_RP_EMIT(MV_NONSTATIC,mbrs,BOOST_PP_EMPTY) \
|
Chris@16
|
510 \
|
Chris@16
|
511 __rule::__expr::type::embed_t __parser; \
|
Chris@16
|
512 \
|
Chris@16
|
513 public: \
|
Chris@16
|
514 \
|
Chris@16
|
515 explicit name_t (BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_CTOR_PARAMS,pars,-)) \
|
Chris@16
|
516 : BOOST_SPIRIT_RP_EMIT(MV_CTOR_INIT_LIST,mbrs,-) \
|
Chris@16
|
517 BOOST_PP_COMMA_IF(nm) __parser(x) \
|
Chris@16
|
518 { } \
|
Chris@16
|
519 \
|
Chris@16
|
520 name_t(name_t const & that) \
|
Chris@16
|
521 : BOOST_SPIRIT_RP_EMIT(MV_CTOR_COPY_INIT_LIST,mbrs,that) \
|
Chris@16
|
522 BOOST_PP_COMMA_IF(nm) __parser(that.__parser) \
|
Chris@16
|
523 { } \
|
Chris@16
|
524 \
|
Chris@16
|
525 template<typename Scanner> struct result \
|
Chris@16
|
526 { \
|
Chris@16
|
527 typedef typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result< \
|
Chris@16
|
528 __rule::__expr::type, Scanner>::type type; \
|
Chris@16
|
529 }; \
|
Chris@16
|
530 \
|
Chris@16
|
531 template<typename Scanner> \
|
Chris@16
|
532 typename ::BOOST_SPIRIT_CLASSIC_NS::parser_result<self_t, Scanner>::type \
|
Chris@16
|
533 parse(Scanner const & s) const { return __parser.parse(s); } \
|
Chris@16
|
534 }; \
|
Chris@16
|
535 \
|
Chris@16
|
536 BOOST_PP_IF(np,BOOST_SPIRIT_RP_GEN_OPAQUE,BOOST_SPIRIT_RP_GLOB_OPAQUE) \
|
Chris@16
|
537 (name,name_t,np,pars)
|
Chris@16
|
538 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@101
|
539 // RP_AP_HANDLER
|
Chris@16
|
540 //
|
Chris@16
|
541 // Part of the rule parser definition for handling action placeholders
|
Chris@16
|
542 # define BOOST_SPIRIT_RP_AP_HANDLER(name_t,np,acts,na,ns) \
|
Chris@16
|
543 private: \
|
Chris@16
|
544 template<typename A> struct __rebound_1st \
|
Chris@16
|
545 { \
|
Chris@16
|
546 typedef name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,__T) , \
|
Chris@16
|
547 typename ns ::action_concatenator<__A0,A>::type \
|
Chris@16
|
548 BOOST_PP_COMMA_IF(BOOST_PP_DEC(na)) \
|
Chris@16
|
549 BOOST_PP_ENUM_SHIFTED_PARAMS(na,__A) \
|
Chris@16
|
550 > type; \
|
Chris@16
|
551 }; \
|
Chris@16
|
552 \
|
Chris@16
|
553 template<typename X> struct __rebound \
|
Chris@16
|
554 { \
|
Chris@16
|
555 typedef name_t < \
|
Chris@16
|
556 void BOOST_PP_ENUM_TRAILING_PARAMS(np,__T) \
|
Chris@16
|
557 BOOST_SPIRIT_RP_EMIT(AP_REBOUND_TPL_ARGS,acts,X) \
|
Chris@16
|
558 > type; \
|
Chris@16
|
559 }; \
|
Chris@16
|
560 public: \
|
Chris@16
|
561 template<typename A> \
|
Chris@16
|
562 typename __rebound_1st<A>::type const operator[](A const & a) const \
|
Chris@16
|
563 { \
|
Chris@16
|
564 return typename __rebound_1st<A>::type ( \
|
Chris@16
|
565 BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np) \
|
Chris@16
|
566 ns ::concatenate_actions(__a0,a) \
|
Chris@16
|
567 BOOST_PP_COMMA_IF(BOOST_PP_DEC(na)) \
|
Chris@16
|
568 BOOST_PP_ENUM_SHIFTED_PARAMS(na,__a) ); \
|
Chris@16
|
569 } \
|
Chris@16
|
570 template<class PH, ns ::action_chain_mode M, typename A> \
|
Chris@16
|
571 typename __rebound< ns ::action_chain<PH,M,A> >::type const \
|
Chris@16
|
572 operator[]( ns ::action_chain<PH,M,A> const & x) const \
|
Chris@16
|
573 { \
|
Chris@16
|
574 return typename __rebound< ns ::action_chain<PH,M,A> >::type ( \
|
Chris@16
|
575 BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np) \
|
Chris@16
|
576 BOOST_SPIRIT_RP_EMIT(AP_REBOUND_ARGS,acts,x) ); \
|
Chris@16
|
577 } \
|
Chris@16
|
578 template<class Head, class Tail> \
|
Chris@16
|
579 typename __rebound< ns ::action_chains<Head,Tail> >::type const \
|
Chris@16
|
580 operator[]( ns ::action_chains<Head,Tail> const & x) const \
|
Chris@16
|
581 { \
|
Chris@16
|
582 return typename __rebound< ns ::action_chains<Head,Tail> >::type ( \
|
Chris@16
|
583 BOOST_PP_ENUM_PARAMS(np,__p) BOOST_PP_COMMA_IF(np) \
|
Chris@16
|
584 BOOST_SPIRIT_RP_EMIT(AP_REBOUND_ARGS,acts,x) ); \
|
Chris@16
|
585 }
|
Chris@16
|
586 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
587 // RP_AP_EXTRA_MBRS
|
Chris@16
|
588 //
|
Chris@16
|
589 // Extra members we need for rebinding if there are action placeholders
|
Chris@16
|
590 # define BOOST_SPIRIT_RP_AP_EXTRA_MBRS(np,na) \
|
Chris@16
|
591 private: \
|
Chris@16
|
592 BOOST_PP_REPEAT(np,BOOST_SPIRIT_RP_PM_MBRS,-) \
|
Chris@101
|
593 BOOST_PP_REPEAT(na,BOOST_SPIRIT_RP_AP_MBRS,-)
|
Chris@16
|
594 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
595 // RP_PM_MBRS
|
Chris@16
|
596 //
|
Chris@16
|
597 // Member variables to remember parameters if there are action placeholder
|
Chris@16
|
598 # define BOOST_SPIRIT_RP_PM_MBRS(z,i,d) __T ## i __p ## i ;
|
Chris@16
|
599 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
600 // RP_AP_MBRS
|
Chris@16
|
601 //
|
Chris@16
|
602 // Member variables to remember action placeholder substitutes
|
Chris@16
|
603 # define BOOST_SPIRIT_RP_AP_MBRS(z,i,d) __A ## i __a ## i ;
|
Chris@16
|
604 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
605 // RP_CTOR
|
Chris@16
|
606 //
|
Chris@16
|
607 // Expands to a fragment of a constructor (parameters or init-list)
|
Chris@16
|
608 # define BOOST_SPIRIT_RP_CTOR(what,pars,np,acts) \
|
Chris@16
|
609 BOOST_SPIRIT_RP_EMIT(PM_CTOR_ ## what,pars,__T) \
|
Chris@16
|
610 BOOST_SPIRIT_RP_EMIT(AP_CTOR_ ## what,acts,np)
|
Chris@16
|
611 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
612 // RP_CTOR_COMMA
|
Chris@16
|
613 //
|
Chris@16
|
614 // RP_CTOR with a trailing comma
|
Chris@16
|
615 # define BOOST_SPIRIT_RP_CTOR_COMMA(what,pars,np,acts) \
|
Chris@16
|
616 BOOST_SPIRIT_RP_CTOR(what,pars,np,acts) ,
|
Chris@16
|
617 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
618 // RP_TPL_PARAMS
|
Chris@16
|
619 //
|
Chris@101
|
620 // Expands to the template parameters or arguments of the rule parser template
|
Chris@16
|
621 # define BOOST_SPIRIT_RP_TPL_PARAMS(pars,acts,prefix,defaults) \
|
Chris@16
|
622 prefix ## Dummy \
|
Chris@16
|
623 BOOST_SPIRIT_RP_EMIT(PM_TEMPLATE_PARAMS,pars,prefix ## T) \
|
Chris@16
|
624 BOOST_SPIRIT_RP_EMIT(AP_TEMPLATE_PARAMS,acts,(prefix ## A,defaults))
|
Chris@16
|
625 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
626 // RP_GEN_FUNC
|
Chris@16
|
627 //
|
Chris@16
|
628 // Generator function
|
Chris@16
|
629 # define BOOST_SPIRIT_RP_GEN_FUNC(name,name_t,np,na) \
|
Chris@16
|
630 template< BOOST_PP_ENUM_PARAMS(np,typename T) > \
|
Chris@16
|
631 inline name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,T) > \
|
Chris@16
|
632 name( BOOST_PP_ENUM_BINARY_PARAMS(np,T, const & p) ) \
|
Chris@16
|
633 { return name_t < void BOOST_PP_ENUM_TRAILING_PARAMS(np,T) > \
|
Chris@16
|
634 (BOOST_PP_ENUM_PARAMS(np,p) BOOST_PP_ENUM_TRAILING_PARAMS(na, \
|
Chris@16
|
635 ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor() BOOST_PP_INTERCEPT) ); \
|
Chris@16
|
636 }
|
Chris@16
|
637 // RP_GEN_OPAQUE
|
Chris@16
|
638 //
|
Chris@16
|
639 // non-templated version for opaque rule parsers.
|
Chris@16
|
640 # define BOOST_SPIRIT_RP_GEN_OPAQUE(name,name_t,np,pars) \
|
Chris@16
|
641 inline name_t name( BOOST_SPIRIT_RP_EMIT(PM_OPAQUE_GEN_PARAMS,pars,p)) \
|
Chris@16
|
642 { return name_t (BOOST_PP_ENUM_PARAMS(np,p)); }
|
Chris@16
|
643 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
644 // RP_GLOB_VAR
|
Chris@16
|
645 //
|
Chris@16
|
646 // Global variable -- used instead of the generator function if there are no
|
Chris@16
|
647 // parameters
|
Chris@16
|
648 # define BOOST_SPIRIT_RP_GLOB_VAR(name,name_t,np,na) \
|
Chris@16
|
649 static name_t <void> const name = name_t <void>(BOOST_PP_ENUM_PARAMS(na, \
|
Chris@16
|
650 ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor() BOOST_PP_INTERCEPT) );
|
Chris@16
|
651
|
Chris@16
|
652 // RP_GLOB_OPAQUE
|
Chris@16
|
653 //
|
Chris@16
|
654 // non-templated version for opaque rule parsers.
|
Chris@16
|
655 # define BOOST_SPIRIT_RP_GLOB_OPAQUE(name,name_t,np,pars) \
|
Chris@16
|
656 static name_t const name = name_t () ;
|
Chris@16
|
657 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
658 // PP_EMIT operations (fragment emittion based on array input)
|
Chris@16
|
659
|
Chris@16
|
660 // - - Namespace handling
|
Chris@16
|
661
|
Chris@16
|
662 // NS_OPEN
|
Chris@16
|
663 # define BOOST_SPIRIT_RP__NS_OPEN(r,data,i,elem) \
|
Chris@16
|
664 namespace BOOST_SPIRIT_RP_OPTIONAL(elem) {
|
Chris@16
|
665
|
Chris@16
|
666 // NS_QUALIFY
|
Chris@16
|
667 # define BOOST_SPIRIT_RP__NS_QUALIFY(r,data,i,elem) \
|
Chris@16
|
668 BOOST_SPIRIT_RP_OPTIONAL(elem ::)
|
Chris@16
|
669
|
Chris@16
|
670 // NS_CLOSE
|
Chris@16
|
671 # define BOOST_SPIRIT_RP__NS_CLOSE(r,data,i,elem) }
|
Chris@16
|
672
|
Chris@16
|
673 // - - Parameter handling
|
Chris@16
|
674
|
Chris@16
|
675 // PM_STATIC
|
Chris@16
|
676 # define BOOST_SPIRIT_RP__PM_STATIC(r,data,i,elem) \
|
Chris@16
|
677 static typename ::boost::call_traits< data ## i >::reference elem ;
|
Chris@16
|
678
|
Chris@16
|
679 // PM_CTOR_PARAMS
|
Chris@16
|
680 # define BOOST_SPIRIT_RP__PM_CTOR_PARAMS(r,data,i,elem) \
|
Chris@16
|
681 BOOST_PP_COMMA_IF(i) \
|
Chris@101
|
682 typename ::boost::call_traits< data ## i >::param_type elem
|
Chris@16
|
683
|
Chris@16
|
684 // PM_CTOR_ARGS
|
Chris@16
|
685 # define BOOST_SPIRIT_RP__PM_CTOR_ARGS(r,data,i,elem) \
|
Chris@16
|
686 BOOST_PP_COMMA_IF(i) elem
|
Chris@16
|
687
|
Chris@16
|
688 // PM_CTOR_INIT_LIST
|
Chris@16
|
689 # define BOOST_SPIRIT_RP__PM_CTOR_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
690 BOOST_PP_COMMA_IF(i) __p ## i ( elem )
|
Chris@16
|
691
|
Chris@16
|
692 // PM_CTOR_COPY_INIT_LIST
|
Chris@16
|
693 # define BOOST_SPIRIT_RP__PM_CTOR_COPY_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
694 BOOST_PP_COMMA_IF(i) __p ## i ( that. __p ## i )
|
Chris@16
|
695
|
Chris@16
|
696
|
Chris@16
|
697 // PM_TEMPLATE_PARAMS
|
Chris@16
|
698 # define BOOST_SPIRIT_RP__PM_TEMPLATE_PARAMS(r,data,i,elem) , data ## i
|
Chris@16
|
699
|
Chris@16
|
700 // - strictly typed parameters of the opaque rule_parser
|
Chris@16
|
701
|
Chris@16
|
702 // PM_OPAQUE_STATIC
|
Chris@16
|
703 # define BOOST_SPIRIT_RP__PM_OPAQUE_STATIC(r,data,i,elem) \
|
Chris@16
|
704 static ::boost::call_traits< \
|
Chris@16
|
705 BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem)) \
|
Chris@16
|
706 >::reference BOOST_PP_TUPLE_ELEM(2,1,elem) ;
|
Chris@16
|
707
|
Chris@16
|
708 // PM_OPAQUE_CTOR_PARAMS
|
Chris@16
|
709 # define BOOST_SPIRIT_RP__PM_OPAQUE_CTOR_PARAMS(r,data,i,elem) \
|
Chris@16
|
710 BOOST_PP_COMMA_IF(i) ::boost::call_traits< \
|
Chris@16
|
711 BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem)) \
|
Chris@16
|
712 >::param_type BOOST_PP_TUPLE_ELEM(2,1,elem)
|
Chris@16
|
713
|
Chris@16
|
714 // PM_OPAQUE_GEN_PARAMS
|
Chris@16
|
715 # define BOOST_SPIRIT_RP__PM_OPAQUE_GEN_PARAMS(r,data,i,elem) \
|
Chris@16
|
716 BOOST_PP_COMMA_IF(i) ::boost::call_traits< \
|
Chris@16
|
717 BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(2,0,elem)) \
|
Chris@16
|
718 >::param_type data ## i
|
Chris@16
|
719
|
Chris@16
|
720 // - - Member variable handling
|
Chris@16
|
721
|
Chris@16
|
722 // MV_NONSTATIC
|
Chris@16
|
723 # define BOOST_SPIRIT_RP__MV_NONSTATIC(r,data,i,elem) \
|
Chris@16
|
724 data() BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(3,0,elem)) \
|
Chris@16
|
725 BOOST_PP_TUPLE_ELEM(3,1,elem) ;
|
Chris@16
|
726
|
Chris@16
|
727 // MV_STATIC
|
Chris@16
|
728 # define BOOST_SPIRIT_RP__MV_STATIC(r,data,i,elem) \
|
Chris@16
|
729 static data() ::boost::call_traits< \
|
Chris@16
|
730 data() BOOST_SPIRIT_RP_TYPE(BOOST_PP_TUPLE_ELEM(3,0,elem)) \
|
Chris@16
|
731 >::reference BOOST_PP_TUPLE_ELEM(3,1,elem) ;
|
Chris@16
|
732
|
Chris@16
|
733 // MV_CTOR_INIT_LIST
|
Chris@16
|
734 # define BOOST_SPIRIT_RP__MV_CTOR_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
735 BOOST_PP_COMMA_IF(i) \
|
Chris@16
|
736 BOOST_PP_TUPLE_ELEM(3,1,elem) BOOST_PP_TUPLE_ELEM(3,2,elem)
|
Chris@16
|
737
|
Chris@16
|
738 // MV_CTOR_COPY_INIT_LIST
|
Chris@16
|
739 # define BOOST_SPIRIT_RP__MV_CTOR_COPY_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
740 BOOST_PP_COMMA_IF(i) \
|
Chris@16
|
741 BOOST_PP_TUPLE_ELEM(3,1,elem) (data . BOOST_PP_TUPLE_ELEM(3,1,elem))
|
Chris@16
|
742
|
Chris@16
|
743 // - - Action placeholder handling
|
Chris@16
|
744
|
Chris@16
|
745 // AP_STATIC
|
Chris@16
|
746 # define BOOST_SPIRIT_RP__AP_STATIC(r,data,i,elem) static __A ## i & elem ;
|
Chris@16
|
747
|
Chris@16
|
748 // AP_CTOR_PARAMS
|
Chris@16
|
749 # define BOOST_SPIRIT_RP__AP_CTOR_PARAMS(r,data,i,elem) \
|
Chris@16
|
750 BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) \
|
Chris@16
|
751 typename ::boost::call_traits< __A ## i >::param_type elem
|
Chris@16
|
752
|
Chris@16
|
753 // AP_CTOR_ARGS
|
Chris@16
|
754 # define BOOST_SPIRIT_RP__AP_CTOR_ARGS(r,data,i,elem) \
|
Chris@16
|
755 BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) elem
|
Chris@16
|
756
|
Chris@16
|
757 // AP_CTOR_INIT_LIST
|
Chris@16
|
758 # define BOOST_SPIRIT_RP__AP_CTOR_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
759 BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) __a ## i ( elem )
|
Chris@16
|
760
|
Chris@16
|
761 // AP_CTOR_COPY_INIT_LIST
|
Chris@16
|
762 # define BOOST_SPIRIT_RP__AP_CTOR_COPY_INIT_LIST(r,data,i,elem) \
|
Chris@16
|
763 BOOST_SPIRIT_RP_COMMA_IF_OR(data,i) __a ## i ( that. __a ## i )
|
Chris@16
|
764
|
Chris@16
|
765 // AP_TEMPLATE_PARAMS
|
Chris@16
|
766 # define BOOST_SPIRIT_RP__AP_TEMPLATE_PARAMS(r,data,i,elem) \
|
Chris@16
|
767 , BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2,0,data),i) \
|
Chris@16
|
768 BOOST_PP_EXPR_IIF(BOOST_PP_TUPLE_ELEM(2,1,data), \
|
Chris@16
|
769 = ::BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor)
|
Chris@16
|
770
|
Chris@16
|
771 // AP_REBOUND_ARGS
|
Chris@16
|
772 # define BOOST_SPIRIT_RP__AP_REBOUND_ARGS(r,data,i,elem) \
|
Chris@16
|
773 BOOST_PP_COMMA_IF(i) \
|
Chris@16
|
774 ::BOOST_SPIRIT_CLASSIC_NS::type_of::get_placeholdee< __action_placeholder:: elem > \
|
Chris@16
|
775 ( __a ## i , data )
|
Chris@16
|
776
|
Chris@16
|
777 // AP_REBOUND_TPL_ARGS
|
Chris@16
|
778 # define BOOST_SPIRIT_RP__AP_REBOUND_TPL_ARGS(r,data,i,elem) \
|
Chris@16
|
779 , typename ::BOOST_SPIRIT_CLASSIC_NS::type_of::placeholdee< \
|
Chris@101
|
780 __action_placeholder:: elem , __A ## i, data >::type
|
Chris@16
|
781
|
Chris@16
|
782 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
783 // PP_EMIT
|
Chris@16
|
784 //
|
Chris@16
|
785 // Performs one of the operations in the above section on an optional array.
|
Chris@16
|
786 //
|
Chris@16
|
787 # define BOOST_SPIRIT_RP_EMIT(op, array, data) \
|
Chris@16
|
788 BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I(BOOST_SPIRIT_RP__ ## op,data,array)
|
Chris@16
|
789 // --- --- - - --- - - --- - - - - --- - - - - - - - - - - - - - - - - - - - - -
|
Chris@101
|
790 // RP_ARRAY_FOR_EACH_I
|
Chris@16
|
791 //
|
Chris@16
|
792 // Iterates an optional array. That is you can pass e.g.'-' or 'none' to denote
|
Chris@16
|
793 // emptiness.
|
Chris@16
|
794 # define BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I(macro,data,optional_array) \
|
Chris@16
|
795 BOOST_PP_IIF(BOOST_PP_IS_BINARY(optional_array), \
|
Chris@16
|
796 BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I_IMPL, \
|
Chris@16
|
797 BOOST_PP_TUPLE_EAT(3))(macro,data,optional_array)
|
Chris@16
|
798
|
Chris@101
|
799 // RP_ARRAY_FOR_EACH_I_IMPL
|
Chris@16
|
800 # define BOOST_SPIRIT_RP_ARRAY_FOR_EACH_I_IMPL(macro,data,array) \
|
Chris@16
|
801 BOOST_SPIRIT_RP_IF(BOOST_PP_ARRAY_SIZE(array),PP_SEQ_FOR_EACH_I,3) \
|
Chris@16
|
802 (macro,data, BOOST_SPIRIT_RP_IF(BOOST_PP_ARRAY_SIZE(array), \
|
Chris@16
|
803 PP_TUPLE_TO_SEQ,2) array)
|
Chris@16
|
804 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@101
|
805 // RP_ARRAY_SIZE
|
Chris@16
|
806 //
|
Chris@16
|
807 // Expands to the size of an "optional array".
|
Chris@16
|
808 //
|
Chris@16
|
809 // Examples:
|
Chris@16
|
810 //
|
Chris@16
|
811 // BOOST_SPIRIT_RP_ARRAY_SIZE( (2,(a,b)) ) // 2
|
Chris@16
|
812 // BOOST_SPIRIT_RP_ARRAY_SIZE( (0,()) ) // 0
|
Chris@16
|
813 // BOOST_SPIRIT_RP_ARRAY_SIZE( none ) // 0
|
Chris@16
|
814 // BOOST_SPIRIT_RP_ARRAY_SIZE( - ) // 0
|
Chris@16
|
815 //
|
Chris@16
|
816 # define BOOST_SPIRIT_RP_ARRAY_SIZE(optional_array) \
|
Chris@16
|
817 BOOST_PP_IIF(BOOST_PP_IS_BINARY(optional_array), \
|
Chris@16
|
818 BOOST_PP_ARRAY_SIZE, 0 BOOST_PP_TUPLE_EAT(1))(optional_array)
|
Chris@16
|
819 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
820 // RP_OPTIONAL
|
Chris@101
|
821 //
|
Chris@16
|
822 // Expands to nothing if the argument is parenthesized.
|
Chris@16
|
823 //
|
Chris@16
|
824 // Examples:
|
Chris@16
|
825 //
|
Chris@16
|
826 // BOOST_SPIRIT_RP_OPTIONAL( foobar ) // foobar
|
Chris@16
|
827 // BOOST_SPIRIT_RP_OPTIONAL( (none) ) // evaluates to nothing
|
Chris@16
|
828 //
|
Chris@16
|
829 # define BOOST_SPIRIT_RP_OPTIONAL(elem) \
|
Chris@101
|
830 BOOST_PP_EXPR_IIF(BOOST_PP_COMPL(BOOST_PP_IS_UNARY(elem)),elem)
|
Chris@16
|
831 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
832 // RP_COMMA_IF_OR
|
Chris@16
|
833 //
|
Chris@16
|
834 // Expands to nothing if both arguments are zero, otherwise expands to a comma.
|
Chris@16
|
835 //
|
Chris@16
|
836 # define BOOST_SPIRIT_RP_COMMA_IF_OR(a,b) \
|
Chris@16
|
837 BOOST_PP_IIF(BOOST_PP_OR(a,b),BOOST_PP_COMMA,BOOST_PP_EMPTY)()
|
Chris@16
|
838 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
Chris@16
|
839 // RP_IF
|
Chris@16
|
840 //
|
Chris@16
|
841 // BOOST_SPIRIT_RP_IF(cond,name,arity)
|
Chris@16
|
842 //
|
Chris@16
|
843 // is equivalent to:
|
Chris@16
|
844 //
|
Chris@16
|
845 // BOOST_PP_IF(cond,BOOST_name,BOOST_PP_TUPLE_EAT(arity))
|
Chris@16
|
846 //
|
Chris@16
|
847 # define BOOST_SPIRIT_RP_IF(cond,name,arity) \
|
Chris@16
|
848 BOOST_PP_IF(cond,BOOST_ ## name,BOOST_PP_TUPLE_EAT(arity))
|
Chris@16
|
849
|
Chris@16
|
850 //------------------------------------------------------------------------------
|
Chris@16
|
851 // Wrapper and gernator function to embed a parser by reference
|
Chris@16
|
852 //------------------------------------------------------------------------------
|
Chris@16
|
853
|
Chris@101
|
854 namespace boost { namespace spirit {
|
Chris@16
|
855
|
Chris@16
|
856 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
857
|
Chris@16
|
858 // Wrapper to embed a parser by reference
|
Chris@16
|
859
|
Chris@101
|
860 template<class P> class parser_reference
|
Chris@16
|
861 : public parser< parser_reference<P> >
|
Chris@16
|
862 {
|
Chris@16
|
863 P const & ref_that;
|
Chris@16
|
864 public:
|
Chris@16
|
865 parser_reference(P & that)
|
Chris@16
|
866 // we allow implicit conversion but forbid temporaries.
|
Chris@16
|
867 : ref_that(that)
|
Chris@16
|
868 { }
|
Chris@16
|
869
|
Chris@16
|
870 typedef parser_reference<P> self_t;
|
Chris@101
|
871 typedef self_t const & embed_t;
|
Chris@16
|
872 typedef typename P::parser_category_t parser_category_t;
|
Chris@16
|
873
|
Chris@101
|
874 template<typename ScannerT> struct result
|
Chris@16
|
875 { typedef typename P::BOOST_NESTED_TEMPLATE result<ScannerT>::type type; };
|
Chris@16
|
876
|
Chris@101
|
877 template<typename ScannerT>
|
Chris@16
|
878 typename result<ScannerT>::type
|
Chris@16
|
879 parse(ScannerT const & scan) const
|
Chris@16
|
880 { return this->ref_that.parse(scan); }
|
Chris@16
|
881 };
|
Chris@16
|
882
|
Chris@101
|
883 template<class P> parser_reference<P>
|
Chris@16
|
884 embed_by_reference(::BOOST_SPIRIT_CLASSIC_NS::parser<P> & p)
|
Chris@16
|
885 { return p; }
|
Chris@16
|
886
|
Chris@16
|
887 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
888
|
Chris@16
|
889 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS
|
Chris@16
|
890
|
Chris@16
|
891 BOOST_TYPEOF_REGISTER_TEMPLATE(BOOST_SPIRIT_CLASSIC_NS::parser_reference, 1)
|
Chris@16
|
892
|
Chris@16
|
893 //------------------------------------------------------------------------------
|
Chris@16
|
894 // Expression templates for action placeholders.
|
Chris@16
|
895 //------------------------------------------------------------------------------
|
Chris@16
|
896
|
Chris@101
|
897 namespace boost { namespace spirit {
|
Chris@16
|
898
|
Chris@16
|
899 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
900
|
Chris@101
|
901 namespace type_of {
|
Chris@16
|
902
|
Chris@16
|
903 // No-operation functor
|
Chris@16
|
904
|
Chris@101
|
905 struct nop_functor
|
Chris@16
|
906 {
|
Chris@16
|
907 template<typename T>
|
Chris@101
|
908 bool operator()(T const &) const
|
Chris@16
|
909 { return false; }
|
Chris@16
|
910 template<typename T, typename U>
|
Chris@16
|
911 bool operator()(T const &, U const &) const
|
Chris@16
|
912 { return false; }
|
Chris@16
|
913
|
Chris@16
|
914 typedef bool result_type;
|
Chris@16
|
915 };
|
Chris@16
|
916
|
Chris@16
|
917 // Composite action
|
Chris@16
|
918
|
Chris@16
|
919 template<typename Action1, typename Action2>
|
Chris@16
|
920 class composite_action
|
Chris@16
|
921 {
|
Chris@16
|
922 Action1 fnc_a1;
|
Chris@16
|
923 Action2 fnc_a2;
|
Chris@16
|
924 public:
|
Chris@16
|
925 composite_action(Action1 const & a1, Action2 const & a2)
|
Chris@16
|
926 : fnc_a1(a1), fnc_a2(a2)
|
Chris@16
|
927 { }
|
Chris@16
|
928
|
Chris@16
|
929 template<typename T>
|
Chris@16
|
930 void operator()(T const & inp) const
|
Chris@16
|
931 { fnc_a1(inp); fnc_a2(inp); }
|
Chris@16
|
932
|
Chris@16
|
933 template<typename T, typename U>
|
Chris@16
|
934 void operator()(T const & inp1, U const inp2) const
|
Chris@16
|
935 { fnc_a1(inp1, inp2); fnc_a2(inp1, inp2); }
|
Chris@16
|
936 };
|
Chris@16
|
937
|
Chris@16
|
938 // Action concatenation (and optimize away nop_functorS)
|
Chris@16
|
939
|
Chris@16
|
940 template<typename Action1, typename Action2>
|
Chris@16
|
941 struct action_concatenator
|
Chris@16
|
942 {
|
Chris@16
|
943 typedef composite_action<Action1,Action2> type;
|
Chris@16
|
944
|
Chris@16
|
945 static type concatenate(Action1 const & a1, Action2 const & a2)
|
Chris@16
|
946 { return composite_action<Action1,Action2>(a1,a2); }
|
Chris@16
|
947 };
|
Chris@16
|
948 template<typename Action> struct action_concatenator<nop_functor, Action>
|
Chris@16
|
949 {
|
Chris@16
|
950 typedef Action type;
|
Chris@16
|
951
|
Chris@101
|
952 static type concatenate(nop_functor const &, Action const & a)
|
Chris@16
|
953 { return a; }
|
Chris@16
|
954 };
|
Chris@16
|
955 template<typename Action> struct action_concatenator<Action, nop_functor>
|
Chris@16
|
956 {
|
Chris@16
|
957 typedef Action type;
|
Chris@16
|
958
|
Chris@101
|
959 static type concatenate(Action const & a, nop_functor const &)
|
Chris@16
|
960 { return a; }
|
Chris@16
|
961 };
|
Chris@16
|
962 template<> struct action_concatenator<nop_functor, nop_functor>
|
Chris@16
|
963 {
|
Chris@16
|
964 typedef nop_functor type;
|
Chris@16
|
965
|
Chris@101
|
966 static type concatenate(nop_functor const &, nop_functor const &)
|
Chris@16
|
967 { return nop_functor(); }
|
Chris@16
|
968 };
|
Chris@16
|
969
|
Chris@16
|
970 template<typename Action1, typename Action2>
|
Chris@101
|
971 typename action_concatenator<Action1,Action2>::type
|
Chris@16
|
972 concatenate_actions(Action1 const & a1, Action2 const & a2)
|
Chris@16
|
973 {
|
Chris@16
|
974 return action_concatenator<Action1,Action2>::concatenate(a1,a2);
|
Chris@16
|
975 }
|
Chris@16
|
976
|
Chris@16
|
977 // Action chains
|
Chris@16
|
978
|
Chris@16
|
979 enum action_chain_mode { replace, append };
|
Chris@16
|
980
|
Chris@16
|
981 template<class Placeholder, action_chain_mode Mode, typename Action>
|
Chris@16
|
982 class action_chain
|
Chris@16
|
983 {
|
Chris@16
|
984 Action fnc_action;
|
Chris@16
|
985 public:
|
Chris@16
|
986 action_chain(Action const & a)
|
Chris@16
|
987 : fnc_action(a)
|
Chris@16
|
988 { }
|
Chris@16
|
989
|
Chris@16
|
990 typedef Action action_type;
|
Chris@16
|
991
|
Chris@16
|
992 Action const & action() const { return fnc_action; }
|
Chris@16
|
993 };
|
Chris@16
|
994
|
Chris@16
|
995 // This operator adds actions to an action chain definition
|
Chris@16
|
996 template<class PH, action_chain_mode M, typename A1, typename A2>
|
Chris@16
|
997 action_chain<PH, M, typename action_concatenator<A1,A2>::type>
|
Chris@16
|
998 operator, (action_chain<PH,M,A1> const & chain, A2 const & a)
|
Chris@16
|
999 {
|
Chris@16
|
1000 return action_chain<PH,M,typename action_concatenator<A1,A2>::type>
|
Chris@16
|
1001 ( concatenate_actions(chain.action(), a) );
|
Chris@16
|
1002 }
|
Chris@16
|
1003
|
Chris@16
|
1004 // Expression template for mutiple action chain assignments
|
Chris@16
|
1005 template<class ChainOrChains, class LastChain>
|
Chris@16
|
1006 class action_chains
|
Chris@16
|
1007 {
|
Chris@16
|
1008 ChainOrChains obj_head;
|
Chris@16
|
1009 LastChain obj_tail;
|
Chris@16
|
1010 public:
|
Chris@16
|
1011 action_chains(ChainOrChains const & head, LastChain const & tail)
|
Chris@16
|
1012 : obj_head(head), obj_tail(tail)
|
Chris@16
|
1013 { }
|
Chris@16
|
1014
|
Chris@16
|
1015 typedef ChainOrChains head_type;
|
Chris@16
|
1016 typedef LastChain tail_type;
|
Chris@16
|
1017
|
Chris@16
|
1018 head_type const & head() const { return obj_head; }
|
Chris@16
|
1019 tail_type const & tail() const { return obj_tail; }
|
Chris@101
|
1020 };
|
Chris@16
|
1021
|
Chris@16
|
1022 // Action chain concatenation
|
Chris@16
|
1023 template<class Head, class Tail>
|
Chris@16
|
1024 action_chains<Head,Tail> make_chain(Head const & h, Tail const & t)
|
Chris@16
|
1025 { return action_chains<Head,Tail>(h,t); }
|
Chris@16
|
1026
|
Chris@101
|
1027 template<class PH1, action_chain_mode M1, typename A1,
|
Chris@16
|
1028 class PH2, action_chain_mode M2, typename A2>
|
Chris@16
|
1029 action_chains< action_chain<PH1,M1,A1>, action_chain<PH2,M2,A2> >
|
Chris@101
|
1030 operator, (action_chain<PH1,M1,A1> const & h,
|
Chris@16
|
1031 action_chain<PH2,M2,A2> const & t)
|
Chris@16
|
1032 { return make_chain(h,t); }
|
Chris@16
|
1033
|
Chris@16
|
1034 template<class Head, class Tail,class PH, action_chain_mode M, typename A>
|
Chris@16
|
1035 action_chains< action_chains<Head,Tail>, action_chain<PH,M,A> >
|
Chris@16
|
1036 operator, (action_chains<Head,Tail> const & h, action_chain<PH,M,A> const & t)
|
Chris@16
|
1037 { return make_chain(h,t); }
|
Chris@16
|
1038
|
Chris@16
|
1039
|
Chris@101
|
1040 // Extract the (maybe composite) action associated with an action
|
Chris@16
|
1041 // placeholders from the chains with a fold algorithm.
|
Chris@16
|
1042 template<class Placeholder, typename StartAction, class NewChainOrChains>
|
Chris@16
|
1043 struct placeholdee
|
Chris@16
|
1044 {
|
Chris@101
|
1045 typedef StartAction type;
|
Chris@16
|
1046
|
Chris@16
|
1047 static type get(StartAction const & a, NewChainOrChains const &)
|
Chris@16
|
1048 { return a; }
|
Chris@16
|
1049 };
|
Chris@16
|
1050
|
Chris@16
|
1051 template<class Placeholder, // <-- non-deduced
|
Chris@16
|
1052 typename StartAction, class NewChainOrChains>
|
Chris@16
|
1053 typename placeholdee<Placeholder,StartAction,NewChainOrChains>::type
|
Chris@16
|
1054 get_placeholdee(StartAction const & a, NewChainOrChains const & c)
|
Chris@16
|
1055 { return placeholdee<Placeholder,StartAction,NewChainOrChains>::get(a,c); }
|
Chris@16
|
1056
|
Chris@101
|
1057 template<class Placeholder, typename StartAction, class Head, class Tail>
|
Chris@16
|
1058 struct placeholdee
|
Chris@16
|
1059 < Placeholder, StartAction, action_chains<Head,Tail> >
|
Chris@16
|
1060 {
|
Chris@16
|
1061 typedef typename placeholdee<Placeholder,
|
Chris@16
|
1062 typename placeholdee<Placeholder,StartAction,Head>::type, Tail >::type
|
Chris@16
|
1063 type;
|
Chris@16
|
1064
|
Chris@16
|
1065 static type get(StartAction const & a, action_chains<Head,Tail> const & c)
|
Chris@16
|
1066 {
|
Chris@16
|
1067 return get_placeholdee<Placeholder>(
|
Chris@16
|
1068 get_placeholdee<Placeholder>(a,c.head()), c.tail() );
|
Chris@16
|
1069 }
|
Chris@16
|
1070 };
|
Chris@16
|
1071
|
Chris@16
|
1072 template<class Placeholder, typename StartAction, typename A>
|
Chris@16
|
1073 struct placeholdee
|
Chris@16
|
1074 < Placeholder, StartAction, action_chain<Placeholder,replace,A> >
|
Chris@16
|
1075 {
|
Chris@16
|
1076 typedef A type;
|
Chris@16
|
1077
|
Chris@101
|
1078 static type get(StartAction const &,
|
Chris@16
|
1079 action_chain<Placeholder,replace,A> const & c)
|
Chris@16
|
1080 { return c.action(); }
|
Chris@16
|
1081 };
|
Chris@16
|
1082
|
Chris@16
|
1083 template<class Placeholder, typename StartAction, typename A>
|
Chris@16
|
1084 struct placeholdee
|
Chris@16
|
1085 < Placeholder, StartAction, action_chain<Placeholder,append,A> >
|
Chris@16
|
1086 {
|
Chris@16
|
1087 typedef typename action_concatenator<StartAction,A>::type type;
|
Chris@16
|
1088
|
Chris@101
|
1089 static type get(StartAction const & a,
|
Chris@16
|
1090 action_chain<Placeholder,append,A> const & c)
|
Chris@16
|
1091 { return concatenate_actions(a,c.action()); }
|
Chris@16
|
1092 };
|
Chris@16
|
1093
|
Chris@101
|
1094 }
|
Chris@16
|
1095
|
Chris@16
|
1096 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
1097
|
Chris@16
|
1098 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS::type_of
|
Chris@16
|
1099
|
Chris@16
|
1100 BOOST_TYPEOF_REGISTER_TYPE(BOOST_SPIRIT_CLASSIC_NS::type_of::nop_functor)
|
Chris@16
|
1101 BOOST_TYPEOF_REGISTER_TEMPLATE(BOOST_SPIRIT_CLASSIC_NS::type_of::composite_action,2)
|
Chris@16
|
1102
|
Chris@16
|
1103 //------------------------------------------------------------------------------
|
Chris@16
|
1104 // Misc.utilities
|
Chris@16
|
1105 //------------------------------------------------------------------------------
|
Chris@16
|
1106
|
Chris@101
|
1107 namespace boost { namespace spirit {
|
Chris@16
|
1108
|
Chris@16
|
1109 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
|
Chris@16
|
1110
|
Chris@16
|
1111 namespace type_of {
|
Chris@16
|
1112
|
Chris@16
|
1113 // Utility function to create a dependency to a template argument.
|
Chris@16
|
1114
|
Chris@16
|
1115 template<typename T, typename X>
|
Chris@101
|
1116 X const & depend_on_type(X const & x)
|
Chris@16
|
1117 { return x; }
|
Chris@16
|
1118
|
Chris@16
|
1119 // Utility to allow use parenthesized type expressions with commas inside
|
Chris@16
|
1120 // as a type within macros. Thanks to Dave Abrahams for telling me this nice
|
Chris@16
|
1121 // trick.
|
Chris@16
|
1122
|
Chris@16
|
1123 #define BOOST_SPIRIT_RP_TYPE(x) \
|
Chris@16
|
1124 ::BOOST_SPIRIT_CLASSIC_NS::type_of::remove_special_fptr \
|
Chris@16
|
1125 < ::BOOST_SPIRIT_CLASSIC_NS::type_of::special_result & (*) x >::type
|
Chris@16
|
1126
|
Chris@16
|
1127 struct special_result;
|
Chris@16
|
1128
|
Chris@16
|
1129 template<typename T> struct remove_special_fptr { };
|
Chris@16
|
1130 template<typename T> struct remove_special_fptr< special_result & (*)(T) >
|
Chris@16
|
1131 { typedef T type; };
|
Chris@16
|
1132
|
Chris@101
|
1133 }
|
Chris@16
|
1134
|
Chris@16
|
1135 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
|
Chris@16
|
1136
|
Chris@16
|
1137 } } // namespace ::BOOST_SPIRIT_CLASSIC_NS::type_of
|
Chris@16
|
1138
|
Chris@16
|
1139 //------------------------------------------------------------------------------
|
Chris@101
|
1140 #endif
|
Chris@16
|
1141 //------------------------------------------------------------------------------
|
Chris@16
|
1142
|