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 ===============================================================================/]
8 [section:parse_api Parser API]
10 [//////////////////////////////////////////////////////////////////////////////]
11 [section:iterator_api Iterator Based Parser API]
15 The library provides a couple of free functions to make parsing a snap.
16 These parser functions have two forms. The first form `parse` works on
17 the character level. The second `phrase_parse` works on the phrase level
18 and requires skip parser. Both versions can take in attributes by
19 reference that will hold the parsed values on a successful parse.
23 // forwards to <boost/spirit/home/qi/parse.hpp>
24 #include <boost/spirit/include/qi_parse.hpp>
26 For variadic attributes:
28 // forwards to <boost/spirit/home/qi/parse_attr.hpp>
29 #include <boost/spirit/include/qi_parse_attr.hpp>
31 The variadic attributes version of the API allows one or more
32 attributes to be passed into the parse functions. The functions taking two
33 or more are usable when the parser expression is a __qi_sequence__ only.
34 In this case each of the attributes passed have to match the corresponding
37 For the API functions deducing the correct (matching) parser type from the
38 supplied attribute type:
40 // forwards to <boost/spirit/home/qi/detail/parse_auto.hpp>
41 #include <boost/spirit/include/qi_parse_auto.hpp>
43 Also, see __include_structure__.
49 [[`boost::spirit::qi::parse` ]]
50 [[`boost::spirit::qi::phrase_parse` ]]
51 [[`boost::spirit::qi::skip_flag::postskip` ]]
52 [[`boost::spirit::qi::skip_flag::dont_postskip` ]]
57 namespace boost { namespace spirit { namespace qi
59 template <typename Iterator, typename Expr>
66 template <typename Iterator, typename Expr
67 , typename Attr1, typename Attr2, ..., typename AttrN>
73 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
75 template <typename Iterator, typename Expr, typename Skipper>
81 , Skipper const& skipper
82 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);
84 template <typename Iterator, typename Expr, typename Skipper
85 , typename Attr1, typename Attr2, ..., typename AttrN>
91 , Skipper const& skipper
92 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
94 template <typename Iterator, typename Expr, typename Skipper
95 , typename Attr1, typename Attr2, ..., typename AttrN>
101 , Skipper const& skipper
102 , BOOST_SCOPED_ENUM(skip_flag) post_skip
103 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
106 [note Starting with __spirit__ V2.5 (distributed with Boost V1.47) the
107 placeholder `_val` can be used in semantic actions attached to top level
108 parser components. In this case `_val` refers to the supplied attribute
109 as a whole. For API functions taking more than one attribute argument
110 `_val` will refer to a Fusion vector or references to the attributes.]
112 __qi__ parser API functions based on the automatic creation of the matching
115 namespace boost { namespace spirit { namespace qi
117 template <typename Iterator, typename Attr>
125 template <typename Iterator, typename Attr, typename Skipper>
131 , Skipper const& skipper
132 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);
135 All functions above return `true` if none of the involved parser components
136 failed, and `false` otherwise.
138 The maximum number of supported arguments is limited by the preprocessor
139 constant `SPIRIT_ARGUMENTS_LIMIT`. This constant defaults to the value defined
140 by the preprocessor constant `PHOENIX_LIMIT` (which in turn defaults to `10`).
142 [note The variadic functions with two or more attributes internally combine
143 references to all passed attributes into a `fusion::vector` and forward
144 this as a combined attribute to the corresponding one attribute function.]
146 The `phrase_parse` functions not taking an explicit `skip_flag` as one of their
147 arguments invoke the passed skipper after a successful match of the parser
148 expression. This can be inhibited by using the other versions of that function
149 while passing `skip_flag::dont_postskip` to the corresponding argument.
152 [[Parameter] [Description]]
153 [[`Iterator`] [__fwditer__ pointing to the source to parse.]]
154 [[`Expr`] [An expression that can be converted to a Qi parser.]]
155 [[`Skipper`] [Parser used to skip white spaces.]]
156 [[`Attr`] [An attribute type utilized to create the corresponding
158 [[`Attr1`, `Attr2`, ..., `AttrN`][One or more attributes.]]
161 [endsect] [/ Iterator Based Parser API]
163 [//////////////////////////////////////////////////////////////////////////////]
164 [section:stream_api Stream Based Parser API]
166 [heading Description]
168 The library provides a couple of Standard IO __iomanip__ allowing to integrate
169 __qi__ input parsing facilities with Standard input streams.
170 These parser manipulators have two forms. The first form, `match`, works on
171 the character level. The second `phrase_match` works on the phrase level
172 and requires a skip parser. Both versions can take in attributes by reference
173 that will hold the parsed values on a successful parse.
177 // forwards to <boost/spirit/home/qi/stream/match_manip.hpp>
178 #include <boost/spirit/include/qi_match.hpp>
180 For variadic attributes:
182 // forwards to <boost/spirit/home/qi/stream/match_manip_attr.hpp>
183 #include <boost/spirit/include/qi_match_attr.hpp>
185 The variadic attributes version of the API allows one or more
186 attributes to be passed into the parse manipulators. The manipulators taking
187 two or more attributes are usable when the parser expression is a
188 __qi_sequence__ only. In this case each of the attributes passed have to
189 match the corresponding part of the sequence.
191 For the API functions deducing the correct (matching) parser type from the
192 supplied attribute type:
194 // forwards to <boost/spirit/home/qi/match_auto.hpp>
195 #include <boost/spirit/include/qi_match_auto.hpp>
197 Also, see __include_structure__.
203 [[`boost::spirit::qi::match` ]]
204 [[`boost::spirit::qi::phrase_match` ]]
205 [[`boost::spirit::qi::skip_flag::postskip` ]]
206 [[`boost::spirit::qi::skip_flag::dont_postskip` ]]
211 namespace boost { namespace spirit { namespace qi
213 template <typename Expr>
218 template <typename Expr
219 , typename Attr1, typename Attr2, ..., typename AttrN>
223 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
225 template <typename Expr, typename Skipper>
230 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);
232 template <typename Expr, typename Skipper
233 , typename Attr1, typename Attr2, ..., typename AttrN>
238 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
240 template <typename Expr, typename Skipper
241 , typename Attr1, typename Attr2, ..., typename AttrN>
246 , BOOST_SCOPED_ENUM(skip_flag) post_skip
247 , Attr1& attr1, Attr2& attr2, ..., AttrN& attrN);
250 __qi__ parser API functions based on the automatic creation of the matching
253 namespace boost { namespace spirit { namespace qi
255 template <typename Attr>
260 template <typename Attr, typename Skipper>
265 , BOOST_SCOPED_ENUM(skip_flag) post_skip = skip_flag::postskip);
268 All functions above return a standard IO stream manipulator instance (see
269 __iomanip__), which when streamed from an input stream will result in parsing
270 the input using the embedded __qi__ parser expression. Any error (or failed
271 parse) occurring during the invocation of the __qi__ parsers will be reflected
272 in the streams status flag (`std::ios_base::failbit` will be set).
274 The maximum number of supported arguments is limited by the preprocessor
275 constant `SPIRIT_ARGUMENTS_LIMIT`. This constant defaults to the value defined
276 by the preprocessor constant `PHOENIX_LIMIT` (which in turn defaults to `10`).
278 [note The variadic manipulators with two or more attributes internally combine
279 references to all passed attributes into a `fusion::vector`
280 and forward this as a combined attribute to the corresponding manipulator
281 taking one attribute.]
283 The `phrase_match` manipulators not taking an explicit `skip_flag` as one of their
284 arguments invoke the passed skipper after a successful match of the parser
285 expression. This can be inhibited by using the other versions of that manipulator
286 while passing `skip_flag::dont_postskip` to the corresponding argument.
288 [heading Template parameters]
291 [[Parameter] [Description]]
292 [[`Expr`] [An expression that can be converted to a Qi parser.]]
293 [[`Skipper`] [Parser used to skip white spaces.]]
294 [[`Attr`] [An attribute type utilized to create the corresponding
296 [[`Attr1`, `Attr2`, ..., `AttrN`][One or more attributes.]]
299 [endsect] [/ Stream Based Parser API]
301 [//////////////////////////////////////////////////////////////////////////////]
302 [section:create_parser API for Automatic Parser Creation]
304 [heading Description]
306 The library implements a special API returning a parser instance for a
307 supplied attribute type. This function finds the best matching parser type
308 for the attribute based on a set of simple matching rules (as outlined in the
309 table below) applied recursively to the attribute type. The returned parser
310 can be utilized to match input for the provided attribute.
314 // forwards to <boost/spirit/home/qi/auto.hpp>
315 #include <boost/spirit/include/qi_auto.hpp>
317 Also, see __include_structure__.
323 [[`boost::spirit::qi::create_parser`]]
324 [[`boost::spirit::traits::create_parser_exists`]]
329 namespace boost { namespace spirit { namespace qi
331 template <typename Attr>
336 The returned instance can be directly passed as the parser (or the skipping
337 parser) to any of the __qi__ API functions. Additionally it
338 can be assigned to a rule as the rules right hand side expression. This
339 function will return a valid parser type only if the meta function
340 `traits::create_parser_exists` returns `mpl::true_`. Otherwise it will fail
343 namespace boost { namespace spirit { namespace traits
345 template <typename Attr>
346 struct create_parser_exists;
349 The meta function evaluates to `mpl::true_` if `create_parser` would return
350 a valid parser for the given type `Attr`.
352 The following table outlines the mapping rules from the attribute type to the
353 parser type. These rules are applied recursively to create the parser
354 type which can be used to match input for the given attribute type.
357 [[Attribute type] [Generator type]]
358 [[`char`, `wchar_t`] [`standard::char_`, `standard_wide::char_`]]
359 [[`short`, `int`, `long`] [`short_`, `int_`, `long_`]]
360 [[`unsigned short`, `unsigned int`, `unsigned long`]
361 [`ushort_`, `uint_`, `ulong_`]]
362 [[`float`, `double`, `long double`] [`float_`, `double_`, `long_double`]]
363 [[`short`, `int`, `long`] [`short_`, `int_`, `long_`]]
364 [[`long long`, `unsigned long long`]
365 [`long_long`, `ulong_long`]]
367 [[Any (STL) container] [Kleene Star (unary `'*'`)]]
368 [[Any Fusion sequence] [Sequence operator (`'<<'`)]]
369 [[`boost::optional<>`] [Optional operator (unary `'-'`)]]
370 [[`boost::variant<>`] [Alternative operator (`'|'`)]]
373 [important The mapping for the parsers `long_long` and `ulong_long` are only
374 available on platforms where the preprocessor constant
375 `BOOST_HAS_LONG_LONG` is defined (i.e. on platforms having native
376 support for `long long` and `unsigned long long` (64 bit) signed and
377 unsigned integer types).]
379 [heading Template parameters]
382 [[Parameter] [Description]]
383 [[`Attr`] [An attribute type utilized to create the corresponding
387 [endsect] [/ API for Automatic Parser Creation]