• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Parser Rule</title>
5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8">
8<link rel="up" href="../nonterminal.html" title="Nonterminal Parsers">
9<link rel="prev" href="../nonterminal.html" title="Nonterminal Parsers">
10<link rel="next" href="grammar.html" title="Parser Grammar">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../nonterminal.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../nonterminal.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="grammar.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="spirit.qi.reference.nonterminal.rule"></a><a class="link" href="rule.html" title="Parser Rule">Parser Rule</a>
28</h5></div></div></div>
29<h6>
30<a name="spirit.qi.reference.nonterminal.rule.h0"></a>
31            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.description"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.description">Description</a>
32          </h6>
33<p>
34            The rule is a polymorphic parser that acts as a named placeholder capturing
35            the behavior of a <a class="link" href="../../../abstracts/parsing_expression_grammar.html" title="Parsing Expression Grammar">Parsing
36            Expression Grammar</a> expression assigned to it. Naming a <a class="link" href="../../../abstracts/parsing_expression_grammar.html" title="Parsing Expression Grammar">Parsing
37            Expression Grammar</a> expression allows it to be referenced later
38            and makes it possible for the rule to call itself. This is one of the
39            most important mechanisms and the reason behind the word "recursive"
40            in recursive descent parsing.
41          </p>
42<h6>
43<a name="spirit.qi.reference.nonterminal.rule.h1"></a>
44            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.header"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.header">Header</a>
45          </h6>
46<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/nonterminal/rule.hpp&gt;</span>
47<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_rule</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
48</pre>
49<p>
50            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
51          </p>
52<h6>
53<a name="spirit.qi.reference.nonterminal.rule.h2"></a>
54            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.namespace"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.namespace">Namespace</a>
55          </h6>
56<div class="informaltable"><table class="table">
57<colgroup><col></colgroup>
58<thead><tr><th>
59                    <p>
60                      Name
61                    </p>
62                  </th></tr></thead>
63<tbody><tr><td>
64                    <p>
65                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">rule</span></code>
66                    </p>
67                  </td></tr></tbody>
68</table></div>
69<h6>
70<a name="spirit.qi.reference.nonterminal.rule.h3"></a>
71            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.synopsis"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.synopsis">Synopsis</a>
72          </h6>
73<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A2</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A3</span><span class="special">&gt;</span>
74<span class="keyword">struct</span> <span class="identifier">rule</span><span class="special">;</span>
75</pre>
76<h6>
77<a name="spirit.qi.reference.nonterminal.rule.h4"></a>
78            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.template_parameters"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.template_parameters">Template
79            parameters</a>
80          </h6>
81<div class="informaltable"><table class="table">
82<colgroup>
83<col>
84<col>
85<col>
86</colgroup>
87<thead><tr>
88<th>
89                    <p>
90                      Parameter
91                    </p>
92                  </th>
93<th>
94                    <p>
95                      Description
96                    </p>
97                  </th>
98<th>
99                    <p>
100                      Default
101                    </p>
102                  </th>
103</tr></thead>
104<tbody>
105<tr>
106<td>
107                    <p>
108                      <code class="computeroutput"><span class="identifier">Iterator</span></code>
109                    </p>
110                  </td>
111<td>
112                    <p>
113                      The underlying iterator type that the rule is expected to work
114                      on.
115                    </p>
116                  </td>
117<td>
118                    <p>
119                      none
120                    </p>
121                  </td>
122</tr>
123<tr>
124<td>
125                    <p>
126                      <code class="computeroutput"><span class="identifier">A1</span></code>, <code class="computeroutput"><span class="identifier">A2</span></code>, <code class="computeroutput"><span class="identifier">A3</span></code>
127                    </p>
128                  </td>
129<td>
130                    <p>
131                      Either <code class="computeroutput"><span class="identifier">Signature</span></code>,
132                      <code class="computeroutput"><span class="identifier">Skipper</span></code> or
133                      <code class="computeroutput"><span class="identifier">Locals</span></code> in any
134                      order. See table below.
135                    </p>
136                  </td>
137<td>
138                    <p>
139                      See table below.
140                    </p>
141                  </td>
142</tr>
143</tbody>
144</table></div>
145<p>
146            Here is more information about the template parameters:
147          </p>
148<div class="informaltable"><table class="table">
149<colgroup>
150<col>
151<col>
152<col>
153</colgroup>
154<thead><tr>
155<th>
156                    <p>
157                      Parameter
158                    </p>
159                  </th>
160<th>
161                    <p>
162                      Description
163                    </p>
164                  </th>
165<th>
166                    <p>
167                      Default
168                    </p>
169                  </th>
170</tr></thead>
171<tbody>
172<tr>
173<td>
174                    <p>
175                      <code class="computeroutput"><span class="identifier">Signature</span></code>
176                    </p>
177                  </td>
178<td>
179                    <p>
180                      Specifies the rule's synthesized (return value) and inherited
181                      attributes (arguments). More on this here: <a class="link" href="../parser_concepts/nonterminal.html" title="Nonterminal"><code class="computeroutput"><span class="identifier">Nonterminal</span></code></a>.
182                    </p>
183                  </td>
184<td>
185                    <p>
186                      <code class="computeroutput"><span class="identifier">unused_type</span></code>.
187                      When <code class="computeroutput"><span class="identifier">Signature</span></code>
188                      defaults to <code class="computeroutput"><span class="identifier">unused_type</span></code>,
189                      the effect is the same as specifying a signature of <code class="computeroutput"><span class="keyword">void</span><span class="special">()</span></code>
190                      which is also equivalent to <code class="computeroutput"><span class="identifier">unused_type</span><span class="special">()</span></code>
191                    </p>
192                  </td>
193</tr>
194<tr>
195<td>
196                    <p>
197                      <code class="computeroutput"><span class="identifier">Skipper</span></code>
198                    </p>
199                  </td>
200<td>
201                    <p>
202                      Specifies the rule's skipper parser. Specify this if you want
203                      the rule to skip white spaces. If this is not specified, the
204                      rule is an "implicit lexeme" and will not skip spaces.
205                      "implicit lexeme" rules can still be called with
206                      a skipper. In such a case, the rule does a pre-skip just as
207                      all lexemes and primitives do.
208                    </p>
209                  </td>
210<td>
211                    <p>
212                      <code class="computeroutput"><span class="identifier">unused_type</span></code>
213                    </p>
214                  </td>
215</tr>
216<tr>
217<td>
218                    <p>
219                      <code class="computeroutput"><span class="identifier">Locals</span></code>
220                    </p>
221                  </td>
222<td>
223                    <p>
224                      Specifies the rule's local variables. See <a class="link" href="../parser_concepts/nonterminal.html" title="Nonterminal"><code class="computeroutput"><span class="identifier">Nonterminal</span></code></a>.
225                    </p>
226                  </td>
227<td>
228                    <p>
229                      <code class="computeroutput"><span class="identifier">unused_type</span></code>
230                    </p>
231                  </td>
232</tr>
233</tbody>
234</table></div>
235<h6>
236<a name="spirit.qi.reference.nonterminal.rule.h5"></a>
237            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.model_of"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.model_of">Model
238            of</a>
239          </h6>
240<div class="blockquote"><blockquote class="blockquote"><p>
241              <a class="link" href="../parser_concepts/nonterminal.html" title="Nonterminal"><code class="computeroutput"><span class="identifier">Nonterminal</span></code></a>
242            </p></blockquote></div>
243<div class="variablelist">
244<p class="title"><b>Notation</b></p>
245<dl class="variablelist">
246<dt><span class="term"><code class="computeroutput"><span class="identifier">r</span><span class="special">,</span>
247              <span class="identifier">r2</span></code></span></dt>
248<dd><p>
249                  Rules
250                </p></dd>
251<dt><span class="term"><code class="computeroutput"><span class="identifier">p</span></code></span></dt>
252<dd><p>
253                  A parser expression
254                </p></dd>
255<dt><span class="term"><code class="computeroutput"><span class="identifier">Iterator</span></code></span></dt>
256<dd><p>
257                  The underlying iterator type that the rule is expected to work
258                  on.
259                </p></dd>
260<dt><span class="term"><code class="computeroutput"><span class="identifier">A1</span></code>, <code class="computeroutput"><span class="identifier">A2</span></code>, <code class="computeroutput"><span class="identifier">A3</span></code></span></dt>
261<dd><p>
262                  Either <code class="computeroutput"><span class="identifier">Signature</span></code>,
263                  <code class="computeroutput"><span class="identifier">Skipper</span></code> or <code class="computeroutput"><span class="identifier">Locals</span></code> in any order.
264                </p></dd>
265</dl>
266</div>
267<h6>
268<a name="spirit.qi.reference.nonterminal.rule.h6"></a>
269            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.expression_semantics"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.expression_semantics">Expression
270            Semantics</a>
271          </h6>
272<p>
273            Semantics of an expression is defined only where it differs from, or
274            is not defined in <a class="link" href="../parser_concepts/nonterminal.html" title="Nonterminal"><code class="computeroutput"><span class="identifier">Nonterminal</span></code></a>.
275          </p>
276<div class="informaltable"><table class="table">
277<colgroup>
278<col>
279<col>
280</colgroup>
281<thead><tr>
282<th>
283                    <p>
284                      Expression
285                    </p>
286                  </th>
287<th>
288                    <p>
289                      Description
290                    </p>
291                  </th>
292</tr></thead>
293<tbody>
294<tr>
295<td>
296                    <p>
297</p>
298<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span><span class="special">&gt;</span>
299    <span class="identifier">r</span><span class="special">(</span><span class="identifier">name</span><span class="special">);</span></pre>
300<p>
301                    </p>
302                  </td>
303<td>
304                    <p>
305                      Rule declaration. <code class="computeroutput"><span class="identifier">Iterator</span></code>
306                      is required. <code class="computeroutput"><span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span></code>
307                      are optional and can be specified in any order. <code class="computeroutput"><span class="identifier">name</span></code> is an optional string
308                      that gives the rule its name, useful for debugging and error
309                      handling.
310                    </p>
311                  </td>
312</tr>
313<tr>
314<td>
315                    <p>
316</p>
317<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span><span class="special">&gt;</span>
318    <span class="identifier">r</span><span class="special">(</span><span class="identifier">r2</span><span class="special">);</span></pre>
319<p>
320                    </p>
321                  </td>
322<td>
323                    <p>
324                      Copy construct rule <code class="computeroutput"><span class="identifier">r</span></code>
325                      from rule <code class="computeroutput"><span class="identifier">r2</span></code>.
326                    </p>
327                  </td>
328</tr>
329<tr>
330<td>
331                    <p>
332                      <code class="computeroutput"><span class="identifier">r</span> <span class="special">=</span>
333                      <span class="identifier">r2</span><span class="special">;</span></code>
334                    </p>
335                  </td>
336<td>
337                    <p>
338                      Assign rule <code class="computeroutput"><span class="identifier">r2</span></code>
339                      to <code class="computeroutput"><span class="identifier">r</span></code>.
340                    </p>
341                  </td>
342</tr>
343<tr>
344<td>
345                    <p>
346                      <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">alias</span><span class="special">()</span></code>
347                    </p>
348                  </td>
349<td>
350                    <p>
351                      return an alias of <code class="computeroutput"><span class="identifier">r</span></code>.
352                      The alias is a parser that holds a reference to <code class="computeroutput"><span class="identifier">r</span></code>.
353                    </p>
354                  </td>
355</tr>
356<tr>
357<td>
358                    <p>
359                      <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">copy</span><span class="special">()</span></code>
360                    </p>
361                  </td>
362<td>
363                    <p>
364                      Get a copy of <code class="computeroutput"><span class="identifier">r</span></code>.
365                    </p>
366                  </td>
367</tr>
368<tr>
369<td>
370                    <p>
371                      <code class="computeroutput"><span class="identifier">r</span> <span class="special">=</span>
372                      <span class="identifier">p</span><span class="special">;</span></code>
373                    </p>
374                  </td>
375<td>
376                    <p>
377                      Rule definition. This is equivalent to <code class="computeroutput"><span class="identifier">r</span>
378                      <span class="special">%=</span> <span class="identifier">p</span></code>
379                      (see below) if there are no semantic actions attached anywhere
380                      in <code class="computeroutput"><span class="identifier">p</span></code>.
381                    </p>
382                  </td>
383</tr>
384<tr>
385<td>
386                    <p>
387                      <code class="computeroutput"><span class="identifier">r</span> <span class="special">%=</span>
388                      <span class="identifier">p</span><span class="special">;</span></code>
389                    </p>
390                  </td>
391<td>
392                    <p>
393                      Auto-rule definition. The attribute of <code class="computeroutput"><span class="identifier">p</span></code>
394                      must be compatible with the synthesized attribute of <code class="computeroutput"><span class="identifier">r</span></code>. If <code class="computeroutput"><span class="identifier">p</span></code>
395                      is successful, its attribute is automatically propagated to
396                      <code class="computeroutput"><span class="identifier">r</span></code>'s synthesized
397                      attribute. Semantic actions, if present, may not change the
398                      attribute's type.
399                    </p>
400                  </td>
401</tr>
402<tr>
403<td>
404                    <p>
405                      <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">name</span><span class="special">()</span></code>
406                    </p>
407                  </td>
408<td>
409                    <p>
410                      Retrieve the current name of the rule object.
411                    </p>
412                  </td>
413</tr>
414<tr>
415<td>
416                    <p>
417                      <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span></code>
418                    </p>
419                  </td>
420<td>
421                    <p>
422                      Set the current name of the rule object to be <code class="computeroutput"><span class="identifier">name</span></code>.
423                    </p>
424                  </td>
425</tr>
426</tbody>
427</table></div>
428<h6>
429<a name="spirit.qi.reference.nonterminal.rule.h7"></a>
430            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.attributes"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.attributes">Attributes</a>
431          </h6>
432<div class="blockquote"><blockquote class="blockquote"><p>
433              The parser attribute of the rule is <code class="computeroutput"><span class="identifier">T</span></code>,
434              its synthesized attribute. See <a class="link" href="../parser_concepts/nonterminal.html#spirit.qi.reference.parser_concepts.nonterminal.attributes"><code class="computeroutput"><span class="identifier">Attribute</span></code></a>
435            </p></blockquote></div>
436<h6>
437<a name="spirit.qi.reference.nonterminal.rule.h8"></a>
438            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.complexity"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.complexity">Complexity</a>
439          </h6>
440<div class="blockquote"><blockquote class="blockquote"><p>
441              The complexity is defined by the complexity of the RHS parser, <code class="computeroutput"><span class="identifier">p</span></code>
442            </p></blockquote></div>
443<h6>
444<a name="spirit.qi.reference.nonterminal.rule.h9"></a>
445            <span class="phrase"><a name="spirit.qi.reference.nonterminal.rule.example"></a></span><a class="link" href="rule.html#spirit.qi.reference.nonterminal.rule.example">Example</a>
446          </h6>
447<div class="note"><table border="0" summary="Note">
448<tr>
449<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
450<th align="left">Note</th>
451</tr>
452<tr><td align="left" valign="top"><p>
453              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a>
454              section.
455            </p></td></tr>
456</table></div>
457<p>
458            Some using declarations:
459          </p>
460<p>
461</p>
462<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">rule</span><span class="special">;</span>
463<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">int_</span><span class="special">;</span>
464<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">locals</span><span class="special">;</span>
465<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">_1</span><span class="special">;</span>
466<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">_a</span><span class="special">;</span>
467<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">alpha</span><span class="special">;</span>
468<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span>
469<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">space_type</span><span class="special">;</span>
470</pre>
471<p>
472          </p>
473<p>
474            Basic rule:
475          </p>
476<p>
477</p>
478<pre class="programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*&gt;</span> <span class="identifier">r</span><span class="special">;</span>
479<span class="identifier">r</span> <span class="special">=</span> <span class="identifier">int_</span><span class="special">;</span>
480<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"123"</span><span class="special">,</span> <span class="identifier">r</span><span class="special">);</span>
481</pre>
482<p>
483          </p>
484<p>
485            Rule with synthesized attribute:
486          </p>
487<p>
488</p>
489<pre class="programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*,</span> <span class="keyword">int</span><span class="special">()&gt;</span> <span class="identifier">ra</span><span class="special">;</span>
490<span class="identifier">ra</span> <span class="special">=</span> <span class="identifier">int_</span><span class="special">;</span>
491<span class="keyword">int</span> <span class="identifier">i</span><span class="special">;</span>
492<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"123"</span><span class="special">,</span> <span class="identifier">ra</span><span class="special">,</span> <span class="identifier">i</span><span class="special">);</span>
493<span class="identifier">assert</span><span class="special">(</span><span class="identifier">i</span> <span class="special">==</span>  <span class="number">123</span><span class="special">);</span>
494</pre>
495<p>
496          </p>
497<p>
498            Rule with skipper and synthesized attribute:
499          </p>
500<p>
501</p>
502<pre class="programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;(),</span> <span class="identifier">space_type</span><span class="special">&gt;</span> <span class="identifier">rs</span><span class="special">;</span>
503<span class="identifier">rs</span> <span class="special">=</span> <span class="special">*</span><span class="identifier">int_</span><span class="special">;</span>
504<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">;</span>
505<span class="identifier">test_phrase_parser_attr</span><span class="special">(</span><span class="string">"123 456 789"</span><span class="special">,</span> <span class="identifier">rs</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
506<span class="identifier">assert</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">==</span>  <span class="number">123</span><span class="special">);</span>
507<span class="identifier">assert</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">==</span>  <span class="number">456</span><span class="special">);</span>
508<span class="identifier">assert</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="number">2</span><span class="special">]</span> <span class="special">==</span>  <span class="number">789</span><span class="special">);</span>
509</pre>
510<p>
511          </p>
512<p>
513            Rule with one local variable:
514          </p>
515<p>
516</p>
517<pre class="programlisting"><span class="identifier">rule</span><span class="special">&lt;</span><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*,</span> <span class="identifier">locals</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">rl</span><span class="special">;</span>
518<span class="identifier">rl</span> <span class="special">=</span> <span class="identifier">alpha</span><span class="special">[</span><span class="identifier">_a</span> <span class="special">=</span> <span class="identifier">_1</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="identifier">char_</span><span class="special">(</span><span class="identifier">_a</span><span class="special">);</span> <span class="comment">// get two identical characters</span>
519<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"aa"</span><span class="special">,</span> <span class="identifier">rl</span><span class="special">);</span> <span class="comment">// pass</span>
520<span class="identifier">test_parser</span><span class="special">(</span><span class="string">"ax"</span><span class="special">,</span> <span class="identifier">rl</span><span class="special">);</span> <span class="comment">// fail</span>
521</pre>
522<p>
523          </p>
524</div>
525<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
526<td align="left"></td>
527<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
528        Distributed under the Boost Software License, Version 1.0. (See accompanying
529        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
530      </p>
531</div></td>
532</tr></table>
533<hr>
534<div class="spirit-nav">
535<a accesskey="p" href="../nonterminal.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../nonterminal.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="grammar.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
536</div>
537</body>
538</html>
539