]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/============================================================================== |
2 | Copyright (C) 2001-2011 Joel de Guzman | |
3 | Copyright (C) 2001-2011 Hartmut Kaiser | |
4 | ||
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 | ||
9 | [section:auto Auto Parser] | |
10 | ||
11 | [heading Description] | |
12 | ||
13 | This module includes the description of the `auto_` parser. This parser | |
14 | can be used to automatically create a parser based on the supplied attribute | |
15 | type. | |
16 | ||
17 | [heading Header] | |
18 | ||
19 | // forwards to <boost/spirit/home/qi/auto.hpp> | |
20 | #include <boost/spirit/include/qi_auto.hpp> | |
21 | ||
22 | Also, see __include_structure__. | |
23 | ||
24 | [heading Namespace] | |
25 | ||
26 | [table | |
27 | [[Name]] | |
28 | [[`boost::spirit::auto_ // alias: boost::spirit::qi::auto_`]] | |
29 | ] | |
30 | ||
31 | [heading Model of] | |
32 | ||
33 | [:__primitive_parser_concept__] | |
34 | ||
35 | [heading Expression Semantics] | |
36 | ||
37 | Semantics of an expression is defined only where it differs from, or is | |
38 | not defined in __primitive_generator_concept__. | |
39 | ||
40 | [table | |
41 | [[Expression] [Description]] | |
42 | [[`auto_`] [Create a parser instance compatible with the | |
43 | supplied attribute type and use it for input | |
44 | matching.]] | |
45 | ] | |
46 | ||
47 | [heading Additional Requirements] | |
48 | ||
49 | The `auto_` parsers can be used to match input for any data type for which | |
50 | a mapping to a parser type is defined (the meta function | |
51 | `traits::create_parser_exists` returns `mpl::true_`). | |
52 | The following table outlines the predefined mapping rules from the attribute | |
53 | type to the parser type. These rules are applied recursively to create the parser | |
54 | type which can be used to match input for the given attribute type. | |
55 | ||
56 | [table | |
57 | [[Attribute type] [Parser type]] | |
58 | [[`char`, `wchar_t`] [`standard::char_`, `standard_wide::char_`]] | |
59 | [[`short`, `int`, `long`] [`short_`, `int_`, `long_`]] | |
60 | [[`unsigned short`, `unsigned int`, `unsigned long`] | |
61 | [`ushort_`, `uint_`, `ulong_`]] | |
62 | [[`float`, `double`, `long double`] [`float_`, `double_`, `long_double`]] | |
63 | [[`long long`, `unsigned long long`] | |
64 | [`long_long`, `ulong_long`]] | |
65 | [[`bool`] [`bool_`]] | |
66 | [[Any (STL) container] [Kleene Star (unary `'*'`)]] | |
67 | [[Any Fusion sequence] [Sequence operator (`'>>'`)]] | |
68 | [[`boost::optional<>`] [Optional operator (unary `'-'`)]] | |
69 | [[`boost::variant<>`] [Alternative operator (`'|'`)]] | |
70 | ] | |
71 | ||
72 | It is possible to add support for any custom data type by implementing a | |
73 | specialization of the customization point __customize_create_parser__. This | |
74 | customization can be used also to redefined any of the predefined mappings. | |
75 | ||
76 | [heading Attributes] | |
77 | ||
78 | [table | |
79 | [[Expression] [Attribute]] | |
80 | [[`auto_`] [`hold_any`]] | |
81 | ] | |
82 | ||
83 | [important The attribute type `hold_any` exposed by the `auto_` | |
84 | parser is semantically and syntactically equivalent to | |
85 | the type implemented by __boost_any__. It has been added to /Spirit/ | |
86 | as it has better a performance and a smaller footprint if compared to | |
87 | __boost_any__. | |
88 | ] | |
89 | ||
90 | [heading Complexity] | |
91 | ||
92 | [:The complexity of the `auto_` parser depends on the supplied attribute type. Each | |
93 | attribute type results in a different parser type to be instantiated which | |
94 | defines the overall complexity.] | |
95 | ||
96 | [heading Example] | |
97 | ||
98 | [note The test harness for the example(s) below is presented in the | |
99 | __qi_basics_examples__ section.] | |
100 | ||
101 | Some includes: | |
102 | ||
103 | [reference_includes] | |
104 | ||
105 | Some using declarations: | |
106 | ||
107 | [reference_qi_using_declarations_auto] | |
108 | ||
109 | And a class definition used in the examples: | |
110 | ||
111 | [reference_qi_complex] | |
112 | [reference_qi_auto_complex] | |
113 | ||
114 | Some usage examples of `auto_` parsers: | |
115 | ||
116 | [reference_qi_auto] | |
117 | ||
118 | [endsect] |