1 [/==============================================================================
2 Copyright (C) 2001-2011 Joel de Guzman
3 Copyright (C) 2001-2011 Hartmut Kaiser
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 ===============================================================================/]
9 [section:auxiliary Auxiliary Parsers]
11 This module includes different auxiliary parsers not fitting into any of the
12 other categories. This module includes the `attr`, `attr_cast`, `eoi`, `eol`,
13 `eps`, and `lazy` parsers.
15 [heading Module Header]
17 // forwards to <boost/spirit/home/qi/auxiliary.hpp>
18 #include <boost/spirit/include/qi_auxiliary.hpp>
20 Also, see __include_structure__.
22 [/------------------------------------------------------------------------------]
23 [section:attr Attribute Parser (`attr`)]
27 The Attribute parser does not consume any input, for this reason it
28 always matches an empty string and always succeeds. It's purpose is to
29 expose its specified parameter as an attribute.
33 // forwards to <boost/spirit/home/qi/auxiliary/attr.hpp>
34 #include <boost/spirit/include/qi_attr.hpp>
36 Also, see __include_structure__.
42 [[`boost::spirit::attr // alias: boost::spirit::qi::attr`]]
47 [:__primitive_parser_concept__]
49 [variablelist Notation
50 [[`a`] [A arbitrary typed constant value, e.g. 0.0, "Hello", or a
51 variable of arbitrary type or a __qi_lazy_argument__ that evaluates
52 to an arbitrary type.]]
53 [[`A`] [The type of `a` or if it is a __qi_lazy_argument__, its
57 [heading Expression Semantics]
59 Semantics of an expression is defined only where it differs from, or is
60 not defined in __primitive_parser_concept__.
63 [[Expression] [Semantics]]
64 [[`attr(a)`] [Create a pseudo parser exposing the current value of
65 `a` as its attribute without consuming any input
72 [[Expression] [Attribute]]
81 The complexity is constant as no input is consumed and no matching is done.
85 [note The test harness for the example(s) below is presented in the
86 __qi_basics_examples__ section.]
88 Some using declarations:
90 [reference_using_declarations_attr]
92 Using `attr` with literals:
96 Using `attr` with __phoenix__ function objects:
98 [reference_attr_phoenix]
102 [/------------------------------------------------------------------------------]
103 [section:attr_cast Attribute Transformation Pseudo Parser (`attr_cast`)]
105 [heading Description]
107 The `attr_cast<Exposed, Transformed>()` component invokes the embedded parser
108 while supplying an attribute of type `Transformed`. The supplied attribute gets created
109 from the original attribute (of type `Exposed`) passed to this component using the
110 customization point __customize_transform_attribute__.
114 // forwards to <boost/spirit/home/qi/auxiliary/attr_cast.hpp>
115 #include <boost/spirit/include/qi_attr_cast.hpp>
117 Also, see __include_structure__.
123 [[`boost::spirit::attr_cast // alias: boost::spirit::qi::attr_cast`]]
128 template <Exposed, Transformed>
129 <unspecified> attr_cast(<unspecified>);
131 [heading Template parameters]
134 [[Parameter] [Description] [Default]]
135 [[`Exposed`] [The type of the attribute supplied to the `attr_cast`.] [__unused_type__]]
136 [[`Transformed`][The type of the attribute expected by the embedded
137 parser `p`.] [__unused_type__]]
140 The `attr_cast` is a function template. It is possible to invoke it using the
144 attr_cast<Exposed>(p)
145 attr_cast<Exposed, Transformed>(p)
147 depending on which of the attribute types can be deduced properly if not
148 explicitly specified.
152 [:__unary_parser_concept__]
154 [variablelist Notation
155 [[`p`] [A parser object.]]
158 [heading Expression Semantics]
160 Semantics of an expression is defined only where it differs from, or is
161 not defined in __unary_parser_concept__.
164 [[Expression] [Semantics]]
165 [[`attr_cast(p)`] [Create a component invoking the
166 parser `p` while passing an attribute of the type
167 as normally expected by `p`. The type of the supplied
168 attribute will be transformed to the type
169 `p` exposes as its attribute type (by using the
170 attribute customization point __customize_transform_attribute__).]]
171 [[`attr_cast<Exposed>(p)`] [Create a component invoking the
172 parser `p` while passing an attribute of the type
173 as normally expected by `p`. The supplied attribute
174 is expected to be of the type `Exposed`, it will be
175 transformed to the type `p` exposes as its attribute type
176 (using the attribute customization point
177 __customize_transform_attribute__).]]
178 [[`attr_cast<Exposed, Transformed>(p)`] [Create a component invoking the
179 parser `p` while passing an attribute of type
180 `Transformed`. The supplied attribute is expected
181 to be of the type `Exposed`, it will be transformed
182 to the type `Transformed` (using the attribute
183 customization point __customize_transform_attribute__).]]
189 [[Expression] [Attribute]]
190 [[`attr_cast(p)`] [`p: A --> attr_cast(p): A`]]
191 [[`attr_cast<Exposed>(p)`] [`p: A --> attr_cast<Exposed>(p): Exposed`]]
192 [[`attr_cast<Exposed, Transformed>(p)`]
193 [`p: A --> attr_cast<Exposed, Transformed>(p): Exposed`]]
198 [:The complexity of this component is fully defined by the complexity of the
199 embedded parser `p`.]
203 [note The test harness for the example(s) below is presented in the
204 __qi_basics_examples__ section.]
206 Some using declarations:
208 [reference_qi_using_declarations_attr_cast]
210 The example references data structure `int_data` which needs a specialization of
211 the customization point __customize_transform_attribute__:
213 [reference_qi_auxiliary_attr_cast_data1]
215 Now we use the `attr_cast` pseudo parser to invoke the attribute
218 [reference_qi_attr_cast1]
223 [/------------------------------------------------------------------------------]
224 [section:eol End of Line Parser (`eol`)]
226 [heading Description]
228 The `eol` parser matches the end of line (CR/LF and combinations
233 // forwards to <boost/spirit/home/qi/auxiliary/eol.hpp>
234 #include <boost/spirit/include/qi_eol.hpp>
236 Also, see __include_structure__.
242 [[`boost::spirit::eol // alias: boost::spirit::qi::eol`]]
247 [:__primitive_parser_concept__]
249 [heading Expression Semantics]
251 Semantics of an expression is defined only where it differs from, or is
252 not defined in __primitive_parser_concept__.
255 [[Expression] [Semantics]]
256 [[`eol`] [Create a parser that matches the end of line.]]
262 [[Expression] [Attribute]]
263 [[`eol`] [__unused__]]
272 [note The test harness for the example(s) below is presented in the
273 __qi_basics_examples__ section.]
275 Some using declarations:
277 [reference_using_declarations_eol]
283 [endsect] [/ End of Line]
285 [/------------------------------------------------------------------------------]
286 [section:eoi End of Input Parser (`eoi`)]
288 [heading Description]
290 The `eoi` parser matches the end of input (returns a successful match
291 with 0 length when the input is exhausted)
295 // forwards to <boost/spirit/home/qi/auxiliary/eoi.hpp>
296 #include <boost/spirit/include/qi_eoi.hpp>
298 Also, see __include_structure__.
304 [[`boost::spirit::eoi // alias: boost::spirit::qi::eoi`]]
309 [:__primitive_parser_concept__]
311 [heading Expression Semantics]
313 Semantics of an expression is defined only where it differs from, or is
314 not defined in __primitive_parser_concept__.
317 [[Expression] [Semantics]]
318 [[`eoi`] [Create a parser that matches the end of input.]]
324 [[Expression] [Attribute]]
325 [[`eoi`] [__unused__]]
334 [note The test harness for the example(s) below is presented in the
335 __qi_basics_examples__ section.]
337 Some using declarations:
339 [reference_using_declarations_eoi]
345 [endsect] [/ End of Input]
347 [/------------------------------------------------------------------------------]
348 [section:eps Epsilon Parser (`eps`)]
350 [heading Description]
352 The Epsilon (`eps`) is a multi-purpose parser that returns a zero length
355 [heading Simple Form]
357 In its simplest form, `eps` matches the null string and always returns a
358 match of zero length:
360 eps // always returns a zero-length match
362 This form is usually used to trigger a semantic action unconditionally.
363 For example, it is useful in triggering error messages when a set of
366 r = a | b | c | eps[error()]; // Call error if a, b, and c fail to match
368 [heading Semantic Predicate]
370 Semantic predicates allow you to attach a conditional function anywhere
371 in the grammar. In this role, the epsilon takes a __qi_lazy_argument__ that
372 returns `true` or `false`. The __qi_lazy_argument__ is typically a test
373 that is called to resolve ambiguity in the grammar. A parse failure will
374 be reported when the __qi_lazy_argument__ result evaluates to `false`.
375 Otherwise an empty match will be reported. The general form is:
379 The __qi_lazy_argument__ `f` is called to do a semantic test (say, checking
380 if a symbol is in the symbol table). If test returns true, `rest` will
381 be evaluated. Otherwise, the production will return early with a
382 no-match without ever touching rest.
386 // forwards to <boost/spirit/home/qi/auxiliary/eps.hpp>
387 #include <boost/spirit/include/qi_eps.hpp>
389 Also, see __include_structure__.
395 [[`boost::spirit::eps // alias: boost::spirit::qi::eps`]]
400 [:__primitive_parser_concept__]
402 [variablelist Notation
403 [[`f`] [A __qi_lazy_argument__ that evaluates `bool`.]]
406 [heading Expression Semantics]
408 Semantics of an expression is defined only where it differs from, or is
409 not defined in __primitive_parser_concept__.
412 [[Expression] [Semantics]]
413 [[`eps`] [Match an empty string (always matches).]]
414 [[`eps(f)`] [If `f` evaluates to `true`, return a zero length match.]]
420 [[Expression] [Attribute]]
421 [[`eps`] [__unused__]]
426 [:For plain (`eps`) the complexity is O(1). For Semantic predicates
427 (`eps(f)`) the complexity is defined by the function `f`.]
431 [note The test harness for the example(s) below is presented in the
432 __qi_basics_examples__ section.]
434 Some using declarations:
436 [reference_using_declarations_eps]
442 [reference_eps_while]
446 [/------------------------------------------------------------------------------]
447 [section:lazy Lazy Parser (`lazy`)]
449 [heading Description]
451 The `lazy` parser, as its name suggests, invokes a lazy __phoenix__
452 function that returns a parser at parse time. This parser will be
453 used once it is created to continue the parse.
457 // forwards to <boost/spirit/home/qi/auxiliary/lazy.hpp>
458 #include <boost/spirit/include/qi_lazy.hpp>
460 Also, see __include_structure__.
466 [[`boost::spirit::lazy // alias: boost::spirit::qi::lazy`]]
471 [:__parser_concept__]
473 [variablelist Notation
474 [[`fp`] [A __qi_lazy_argument__ that evaluates to a
475 __parser_concept__.]]
478 [heading Expression Semantics]
480 Semantics of an expression is defined only where it differs from, or is
481 not defined in __parser_concept__.
484 [[Expression] [Semantics]]
485 [[`fp`] [Create a lazy-parser from a __qi_lazy_argument__, `fp`.
486 `fp` will be invoked at parse time. `fp` is expected to
487 return a __parser_concept__ object. This parser is then
488 invoked in order to parse the input.]]
489 [[`lazy(fp)`] [Create a lazy-parser from a __qi_lazy_argument__, `fp`.
490 `fp` will be invoked at parse time. `fp` is expected to
491 return a __parser_concept__ object. This parser is then
492 invoked in order to parse the input.]]
498 [[Expression] [Attribute]]
499 [[`fp`] [The attribute type of the return type of `fp`.]]
500 [[`lazy(fp)`] [The attribute type of the return type of `fp`.]]
505 The complexity of the `lazy` parser is determined by the complexity of
506 the parser returned from `fp`.
510 [note The test harness for the example(s) below is presented in the
511 __qi_basics_examples__ section.]
513 Some using declarations:
515 [reference_using_declarations_lazy]
523 [endsect] [/ Auxiliary]