• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Sequence Parser (a &gt;&gt; b)</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="../operator.html" title="Parser Operators">
9<link rel="prev" href="plus.html" title="Plus Parser (+a)">
10<link rel="next" href="sequential_or.html" title="Sequential Or Parser (a || b)">
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="plus.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="sequential_or.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.operator.sequence"></a><a class="link" href="sequence.html" title="Sequence Parser (a &gt;&gt; b)">Sequence Parser
28          (<code class="computeroutput"><span class="identifier">a</span> <span class="special">&gt;&gt;</span>
29          <span class="identifier">b</span></code>)</a>
30</h5></div></div></div>
31<h6>
32<a name="spirit.qi.reference.operator.sequence.h0"></a>
33            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.description"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.description">Description</a>
34          </h6>
35<p>
36            The sequence operator, <code class="computeroutput"><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span></code>,
37            parses two or more operands (<code class="computeroutput"><span class="identifier">a</span></code>,
38            <code class="computeroutput"><span class="identifier">b</span></code>, ... etc.), in sequence:
39          </p>
40<pre class="programlisting"><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span> <span class="special">&gt;&gt;</span> <span class="special">...</span>
41</pre>
42<h6>
43<a name="spirit.qi.reference.operator.sequence.h1"></a>
44            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.header"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.header">Header</a>
45          </h6>
46<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/operator/sequence.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_sequence</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.operator.sequence.h2"></a>
54            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.model_of"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.model_of">Model
55            of</a>
56          </h6>
57<div class="blockquote"><blockquote class="blockquote"><p>
58              <a class="link" href="../parser_concepts/naryparser.html" title="NaryParser"><code class="computeroutput"><span class="identifier">NaryParser</span></code></a>
59            </p></blockquote></div>
60<div class="variablelist">
61<p class="title"><b>Notation</b></p>
62<dl class="variablelist">
63<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code>, <code class="computeroutput"><span class="identifier">b</span></code></span></dt>
64<dd><p>
65                  A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>
66                </p></dd>
67</dl>
68</div>
69<h6>
70<a name="spirit.qi.reference.operator.sequence.h3"></a>
71            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.expression_semantics"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.expression_semantics">Expression
72            Semantics</a>
73          </h6>
74<p>
75            Semantics of an expression is defined only where it differs from, or
76            is not defined in <a class="link" href="../parser_concepts/naryparser.html" title="NaryParser"><code class="computeroutput"><span class="identifier">NaryParser</span></code></a>.
77          </p>
78<div class="informaltable"><table class="table">
79<colgroup>
80<col>
81<col>
82</colgroup>
83<thead><tr>
84<th>
85                    <p>
86                      Expression
87                    </p>
88                  </th>
89<th>
90                    <p>
91                      Semantics
92                    </p>
93                  </th>
94</tr></thead>
95<tbody><tr>
96<td>
97                    <p>
98                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">&gt;&gt;</span>
99                      <span class="identifier">b</span></code>
100                    </p>
101                  </td>
102<td>
103                    <p>
104                      Match <code class="computeroutput"><span class="identifier">a</span></code> followed
105                      by <code class="computeroutput"><span class="identifier">b</span></code>.
106                    </p>
107                  </td>
108</tr></tbody>
109</table></div>
110<h6>
111<a name="spirit.qi.reference.operator.sequence.h4"></a>
112            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.attributes"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.attributes">Attributes</a>
113          </h6>
114<p>
115            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.qi.quick_reference.compound_attribute_rules.notation">Compound
116            Attribute Notation</a>.
117          </p>
118<div class="informaltable"><table class="table">
119<colgroup>
120<col>
121<col>
122</colgroup>
123<thead><tr>
124<th>
125                    <p>
126                      Expression
127                    </p>
128                  </th>
129<th>
130                    <p>
131                      Attribute
132                    </p>
133                  </th>
134</tr></thead>
135<tbody><tr>
136<td>
137                    <p>
138                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">&gt;&gt;</span>
139                      <span class="identifier">b</span></code>
140                    </p>
141                  </td>
142<td>
143                    <p>
144</p>
145<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">tuple</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">,</span> <span class="identifier">B</span><span class="special">&gt;</span>
146<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">A</span>
147<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">B</span>
148<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">Unused</span>
149
150<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
151<span class="identifier">a</span><span class="special">:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">A</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
152<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span>
153<span class="identifier">a</span><span class="special">:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span> <span class="special">--&gt;</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">A</span><span class="special">&gt;</span></pre>
154<p>
155                    </p>
156                  </td>
157</tr></tbody>
158</table></div>
159<h6>
160<a name="spirit.qi.reference.operator.sequence.h5"></a>
161            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.complexity"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.complexity">Complexity</a>
162          </h6>
163<div class="blockquote"><blockquote class="blockquote"><p>
164              The overall complexity of the sequence parser is defined by the sum
165              of the complexities of its elements. The complexity of the sequence
166              itself is O(N), where N is the number of elements in the sequence.
167            </p></blockquote></div>
168<h6>
169<a name="spirit.qi.reference.operator.sequence.h6"></a>
170            <span class="phrase"><a name="spirit.qi.reference.operator.sequence.example"></a></span><a class="link" href="sequence.html#spirit.qi.reference.operator.sequence.example">Example</a>
171          </h6>
172<p>
173            Some using declarations:
174          </p>
175<p>
176</p>
177<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">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span>
178<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>
179<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">_2</span><span class="special">;</span>
180<span class="keyword">namespace</span> <span class="identifier">bf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">fusion</span><span class="special">;</span>
181</pre>
182<p>
183          </p>
184<div class="note"><table border="0" summary="Note">
185<tr>
186<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
187<th align="left">Note</th>
188</tr>
189<tr><td align="left" valign="top"><p>
190              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>
191              section.
192            </p></td></tr>
193</table></div>
194<p>
195            Simple usage:
196          </p>
197<p>
198</p>
199<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"xy"</span><span class="special">,</span> <span class="identifier">char_</span> <span class="special">&gt;&gt;</span> <span class="identifier">char_</span><span class="special">);</span>
200</pre>
201<p>
202          </p>
203<p>
204            Extracting the attribute tuple (using <a href="../../../../../../../../libs/fusion/doc/html/index.html" target="_top">Boost.Fusion</a>):
205          </p>
206<p>
207</p>
208<pre class="programlisting"><span class="identifier">bf</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">attr</span><span class="special">;</span>
209<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"xy"</span><span class="special">,</span> <span class="identifier">char_</span> <span class="special">&gt;&gt;</span> <span class="identifier">char_</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">);</span>
210<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">bf</span><span class="special">::</span><span class="identifier">at_c</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">attr</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="char">','</span> <span class="special">&lt;&lt;</span> <span class="identifier">bf</span><span class="special">::</span><span class="identifier">at_c</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">attr</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
211</pre>
212<p>
213          </p>
214<p>
215            Extracting the attribute vector (using <a href="https://en.wikipedia.org/wiki/Standard_Template_Library" target="_top">STL</a>):
216          </p>
217<p>
218</p>
219<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="identifier">vec</span><span class="special">;</span>
220<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"xy"</span><span class="special">,</span> <span class="identifier">char_</span> <span class="special">&gt;&gt;</span> <span class="identifier">char_</span><span class="special">,</span> <span class="identifier">vec</span><span class="special">);</span>
221<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">vec</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">&lt;&lt;</span> <span class="char">','</span> <span class="special">&lt;&lt;</span> <span class="identifier">vec</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
222</pre>
223<p>
224          </p>
225<p>
226            Extracting the attributes using Semantic Actions (using <a href="../../../../../../../../libs/phoenix/doc/html/index.html" target="_top">Boost.Phoenix</a>):
227          </p>
228<p>
229</p>
230<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"xy"</span><span class="special">,</span> <span class="special">(</span><span class="identifier">char_</span> <span class="special">&gt;&gt;</span> <span class="identifier">char_</span><span class="special">)[</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">_1</span> <span class="special">&lt;&lt;</span> <span class="char">','</span> <span class="special">&lt;&lt;</span> <span class="identifier">_2</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">]);</span>
231</pre>
232<p>
233          </p>
234</div>
235<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
236<td align="left"></td>
237<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
238        Distributed under the Boost Software License, Version 1.0. (See accompanying
239        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>)
240      </p>
241</div></td>
242</tr></table>
243<hr>
244<div class="spirit-nav">
245<a accesskey="p" href="plus.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="sequential_or.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
246</div>
247</body>
248</html>
249