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:nonterminal Nonterminal Parsers]
11 [heading Module Headers]
13 // forwards to <boost/spirit/home/qi/nonterminal.hpp>
14 #include <boost/spirit/include/qi_nonterminal.hpp>
16 Also, see __include_structure__.
18 [/------------------------------------------------------------------------------]
19 [section:rule Parser Rule]
23 The rule is a polymorphic parser that acts as a named placeholder
24 capturing the behavior of a __peg__ expression assigned to it. Naming a
25 __peg__ expression allows it to be referenced later and makes it
26 possible for the rule to call itself. This is one of the most important
27 mechanisms and the reason behind the word "recursive" in recursive
32 // forwards to <boost/spirit/home/qi/nonterminal/rule.hpp>
33 #include <boost/spirit/include/qi_rule.hpp>
35 Also, see __include_structure__.
41 [[`boost::spirit::qi::rule`]]
46 template <typename Iterator, typename A1, typename A2, typename A3>
49 [heading Template parameters]
52 [[Parameter] [Description] [Default]]
53 [[`Iterator`] [The underlying iterator
55 expected to work on.] [none]]
56 [[`A1`, `A2`, `A3`] [Either `Signature`,
57 `Skipper` or `Locals` in
58 any order. See table below.] [See table below.]]
61 Here is more information about the template parameters:
64 [[Parameter] [Description] [Default]]
65 [[`Signature`] [Specifies the rule's synthesized
66 (return value) and inherited
67 attributes (arguments). More on
68 this here: __qi_nonterminal__.] [__unused_type__.
69 When `Signature` defaults
70 to __unused_type__, the effect
71 is the same as specifying a signature
72 of `void()` which is also equivalent
74 [[`Skipper`] [Specifies the rule's skipper
75 parser. Specify this if you
76 want the rule to skip white
77 spaces. If this is not specified,
78 the rule is an "implicit lexeme"
79 and will not skip spaces.
80 "implicit lexeme" rules can
81 still be called with a skipper.
82 In such a case, the rule does a
83 pre-skip just as all lexemes
84 and primitives do.] [__unused_type__]]
85 [[`Locals`] [Specifies the rule's local
87 See __qi_nonterminal__.] [__unused_type__]]
94 [variablelist Notation
96 [[`p`] [A parser expression]]
97 [[`Iterator`] [The underlying iterator type that the rule is
98 expected to work on.]]
99 [[`A1`, `A2`, `A3`] [Either `Signature`, `Skipper` or `Locals` in
103 [heading Expression Semantics]
105 Semantics of an expression is defined only where it differs from, or is
106 not defined in __qi_nonterminal__.
109 [[Expression] [Description]]
111 ``rule<Iterator, A1, A2, A3>
112 r(name);``] [Rule declaration. `Iterator` is required.
113 `A1, A2, A3` are optional and can be specified in any order.
114 `name` is an optional string that gives the rule
115 its name, useful for debugging and error handling.]]
117 ``rule<Iterator, A1, A2, A3>
118 r(r2);``] [Copy construct rule `r` from rule `r2`.]]
119 [[`r = r2;`] [Assign rule `r2` to `r`.]]
120 [[`r.alias()`] [return an alias of `r`. The alias is a parser that
121 holds a reference to `r`.]]
122 [[`r.copy()`] [Get a copy of `r`.]]
123 [[`r = p;`] [Rule definition. This is equivalent to `r %= p`
124 (see below) if there are no semantic actions attached
126 [[`r %= p;`] [Auto-rule definition. The attribute of `p` should be
127 compatible with the synthesized attribute of `r`. When `p`
128 is successful, its attribute is automatically propagated
129 to `r`'s synthesized attribute.]]
130 [[`r.name()`] [Retrieve the current name of the rule object.]]
131 [[`r.name(name)`] [Set the current name of the rule object to be `name`.]]
136 [:The parser attribute of the rule is `T`, its synthesized attribute. See
137 __qi_nonterminal_attribute__]
141 [:The complexity is defined by the complexity of the RHS parser, `p`]
145 [note The test harness for the example(s) below is presented in the
146 __qi_basics_examples__ section.]
152 [/------------------------------------------------------------------------------]
153 [section:grammar Parser Grammar]
155 [heading Description]
157 The grammar encapsulates a set of __qi_rules__ (as well as primitive
158 parsers (__primitive_parser_concept__) and sub-grammars). The grammar is
159 the main mechanism for modularization and composition. Grammars can be
160 composed to form more complex grammars.
164 // forwards to <boost/spirit/home/qi/nonterminal/grammar.hpp>
165 #include <boost/spirit/include/qi_grammar.hpp>
167 Also, see __include_structure__.
173 [[`boost::spirit::qi::grammar`]]
178 template <typename Iterator, typename A1, typename A2, typename A3>
181 [heading Template parameters]
184 [[Parameter] [Description] [Default]]
185 [[`Iterator`] [The underlying iterator
186 type that the rule is
187 expected to work on.] [none]]
188 [[`A1`, `A2`, `A3`] [Either `Signature`,
189 `Skipper` or `Locals` in
190 any order. See table below.] [See table below.]]
193 Here is more information about the template parameters:
196 [[Parameter] [Description] [Default]]
197 [[`Signature`] [Specifies the grammar's synthesized
198 (return value) and inherited
199 attributes (arguments). More on
200 this here: __qi_nonterminal__.] [__unused_type__.
201 When `Signature` defaults
202 to __unused_type__, the effect
203 is the same as specifying a signature
204 of `void()` which is also equivalent
206 [[`Skipper`] [Specifies the grammar's skipper
207 parser. Specify this if you
208 want the grammar to skip white
209 spaces.] [__unused_type__]]
210 [[`Locals`] [Specifies the grammar's local
211 variables. See __qi_nonterminal__.] [__unused_type__]]
216 [:__qi_nonterminal__]
218 [variablelist Notation
222 [heading Expression Semantics]
224 Semantics of an expression is defined only where it differs from, or is not
225 defined in __qi_nonterminal__.
228 [[Expression] [Semantics]]
231 template <typename Iterator>
232 struct my_grammar : grammar<Iterator, A1, A2, A3>
234 my_grammar() : my_grammar::base_type(start, name)
240 rule<Iterator, A1, A2, A3> start;
241 // more rule declarations...
244 ] [Grammar definition. `name` is an optional string that gives the
245 grammar its name, useful for debugging and error handling.]]
248 [note The template parameters of a grammar and its start rule (the rule passed
249 to the grammar's base class constructor) must match, otherwise you will
250 see compilation errors.]
254 [:The parser attribute of the grammar is `T`, its synthesized attribute. See
255 __qi_nonterminal_attribute__]
259 [:The complexity is defined by the complexity of the its definition.]
263 [note The test harness for the example(s) below is presented in the
264 __qi_basics_examples__ section.]
266 [reference_grammar_using]
268 [reference_grammar_definition]
272 [endsect] [/ Grammar]
274 [endsect] [/ Nonterminal]