• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Stream Based Parser API</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="../parse_api.html" title="Parser API">
9<link rel="prev" href="iterator_api.html" title="Iterator Based Parser API">
10<link rel="next" href="create_parser.html" title="API for Automatic Parser Creation">
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="iterator_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.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="create_parser.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.parse_api.stream_api"></a><a class="link" href="stream_api.html" title="Stream Based Parser API">Stream
28          Based Parser API</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.qi.reference.parse_api.stream_api.h0"></a>
32            <span class="phrase"><a name="spirit.qi.reference.parse_api.stream_api.description"></a></span><a class="link" href="stream_api.html#spirit.qi.reference.parse_api.stream_api.description">Description</a>
33          </h6>
34<p>
35            The library provides a couple of Standard IO <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>
36            allowing to integrate <span class="emphasis"><em>Spirit.Qi</em></span> input parsing facilities
37            with Standard input streams. These parser manipulators have two forms.
38            The first form, <code class="computeroutput"><span class="identifier">match</span></code>,
39            works on the character level. The second <code class="computeroutput"><span class="identifier">phrase_match</span></code>
40            works on the phrase level and requires a skip parser. Both versions can
41            take in attributes by reference that will hold the parsed values on a
42            successful parse.
43          </p>
44<h6>
45<a name="spirit.qi.reference.parse_api.stream_api.h1"></a>
46            <span class="phrase"><a name="spirit.qi.reference.parse_api.stream_api.header"></a></span><a class="link" href="stream_api.html#spirit.qi.reference.parse_api.stream_api.header">Header</a>
47          </h6>
48<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/stream/match_manip.hpp&gt;</span>
49<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_match</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
50</pre>
51<p>
52            For variadic attributes:
53          </p>
54<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/stream/match_manip_attr.hpp&gt;</span>
55<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_match_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
56</pre>
57<p>
58            The variadic attributes version of the API allows one or more attributes
59            to be passed into the parse manipulators. The manipulators taking two
60            or more attributes are usable when the parser expression is a <a class="link" href="../operator/sequence.html" title="Sequence Parser (a &gt;&gt; b)">Sequence</a>
61            only. In this case each of the attributes passed have to match the corresponding
62            part of the sequence.
63          </p>
64<p>
65            For the API functions deducing the correct (matching) parser type from
66            the supplied attribute type:
67          </p>
68<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/match_auto.hpp&gt;</span>
69<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_match_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
70</pre>
71<p>
72            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
73          </p>
74<h6>
75<a name="spirit.qi.reference.parse_api.stream_api.h2"></a>
76            <span class="phrase"><a name="spirit.qi.reference.parse_api.stream_api.namespace"></a></span><a class="link" href="stream_api.html#spirit.qi.reference.parse_api.stream_api.namespace">Namespace</a>
77          </h6>
78<div class="informaltable"><table class="table">
79<colgroup><col></colgroup>
80<thead><tr><th>
81                    <p>
82                      Name
83                    </p>
84                  </th></tr></thead>
85<tbody>
86<tr><td>
87                    <p>
88                      <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">match</span></code>
89                    </p>
90                  </td></tr>
91<tr><td>
92                    <p>
93                      <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">phrase_match</span></code>
94                    </p>
95                  </td></tr>
96<tr><td>
97                    <p>
98                      <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">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span></code>
99                    </p>
100                  </td></tr>
101<tr><td>
102                    <p>
103                      <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">skip_flag</span><span class="special">::</span><span class="identifier">dont_postskip</span></code>
104                    </p>
105                  </td></tr>
106</tbody>
107</table></div>
108<h6>
109<a name="spirit.qi.reference.parse_api.stream_api.h3"></a>
110            <span class="phrase"><a name="spirit.qi.reference.parse_api.stream_api.synopsis"></a></span><a class="link" href="stream_api.html#spirit.qi.reference.parse_api.stream_api.synopsis">Synopsis</a>
111          </h6>
112<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">qi</span>
113<span class="special">{</span>
114    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">&gt;</span>
115    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
116    <span class="identifier">match</span><span class="special">(</span>
117        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span><span class="special">);</span>
118
119    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span>
120      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
121    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
122    <span class="identifier">match</span><span class="special">(</span>
123        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span>
124      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
125
126    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span><span class="special">&gt;</span>
127    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
128    <span class="identifier">phrase_match</span><span class="special">(</span>
129        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
130      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">s</span>
131      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span> <span class="special">=</span> <span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span><span class="special">);</span>
132
133    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span>
134      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
135    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
136    <span class="identifier">phrase_match</span><span class="special">(</span>
137        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
138      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">s</span>
139      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
140
141    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span>
142      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
143    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
144    <span class="identifier">phrase_match</span><span class="special">(</span>
145        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
146      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">s</span>
147      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span>
148      <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
149<span class="special">}}}</span>
150</pre>
151<p>
152            <span class="emphasis"><em>Spirit.Qi</em></span> parser API functions based on the automatic
153            creation of the matching parser type:
154          </p>
155<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">qi</span>
156<span class="special">{</span>
157    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
158    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
159    <span class="identifier">match</span><span class="special">(</span>
160        <span class="identifier">Attr</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">);</span>
161
162    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Skipper</span><span class="special">&gt;</span>
163    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
164    <span class="identifier">phrase_match</span><span class="special">(</span>
165        <span class="identifier">Attr</span><span class="special">&amp;</span> <span class="identifier">attr</span>
166      <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">s</span>
167      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">skip_flag</span><span class="special">)</span> <span class="identifier">post_skip</span> <span class="special">=</span> <span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">postskip</span><span class="special">);</span>
168<span class="special">}}}</span>
169</pre>
170<p>
171            All functions above return a standard IO stream manipulator instance
172            (see <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>),
173            which when streamed from an input stream will result in parsing the input
174            using the embedded <span class="emphasis"><em>Spirit.Qi</em></span> parser expression.
175            Any error (or failed parse) occurring during the invocation of the <span class="emphasis"><em>Spirit.Qi</em></span>
176            parsers will be reflected in the streams status flag (<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failbit</span></code>
177            will be set).
178          </p>
179<p>
180            The maximum number of supported arguments is limited by the preprocessor
181            constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>.
182            This constant defaults to the value defined by the preprocessor constant
183            <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which
184            in turn defaults to <code class="computeroutput"><span class="number">10</span></code>).
185          </p>
186<div class="note"><table border="0" summary="Note">
187<tr>
188<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
189<th align="left">Note</th>
190</tr>
191<tr><td align="left" valign="top"><p>
192              The variadic manipulators with two or more attributes internally combine
193              references to all passed attributes into a <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">vector</span></code>
194              and forward this as a combined attribute to the corresponding manipulator
195              taking one attribute.
196            </p></td></tr>
197</table></div>
198<p>
199            The <code class="computeroutput"><span class="identifier">phrase_match</span></code> manipulators
200            not taking an explicit <code class="computeroutput"><span class="identifier">skip_flag</span></code>
201            as one of their arguments invoke the passed skipper after a successful
202            match of the parser expression. This can be inhibited by using the other
203            versions of that manipulator while passing <code class="computeroutput"><span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">dont_postskip</span></code>
204            to the corresponding argument.
205          </p>
206<h6>
207<a name="spirit.qi.reference.parse_api.stream_api.h4"></a>
208            <span class="phrase"><a name="spirit.qi.reference.parse_api.stream_api.template_parameters"></a></span><a class="link" href="stream_api.html#spirit.qi.reference.parse_api.stream_api.template_parameters">Template
209            parameters</a>
210          </h6>
211<div class="informaltable"><table class="table">
212<colgroup>
213<col>
214<col>
215</colgroup>
216<thead><tr>
217<th>
218                    <p>
219                      Parameter
220                    </p>
221                  </th>
222<th>
223                    <p>
224                      Description
225                    </p>
226                  </th>
227</tr></thead>
228<tbody>
229<tr>
230<td>
231                    <p>
232                      <code class="computeroutput"><span class="identifier">Expr</span></code>
233                    </p>
234                  </td>
235<td>
236                    <p>
237                      An expression that can be converted to a Qi parser.
238                    </p>
239                  </td>
240</tr>
241<tr>
242<td>
243                    <p>
244                      <code class="computeroutput"><span class="identifier">Skipper</span></code>
245                    </p>
246                  </td>
247<td>
248                    <p>
249                      Parser used to skip white spaces.
250                    </p>
251                  </td>
252</tr>
253<tr>
254<td>
255                    <p>
256                      <code class="computeroutput"><span class="identifier">Attr</span></code>
257                    </p>
258                  </td>
259<td>
260                    <p>
261                      An attribute type utilized to create the corresponding parser
262                      type from.
263                    </p>
264                  </td>
265</tr>
266<tr>
267<td>
268                    <p>
269                      <code class="computeroutput"><span class="identifier">Attr1</span></code>, <code class="computeroutput"><span class="identifier">Attr2</span></code>, ..., <code class="computeroutput"><span class="identifier">AttrN</span></code>
270                    </p>
271                  </td>
272<td>
273                    <p>
274                      One or more attributes.
275                    </p>
276                  </td>
277</tr>
278</tbody>
279</table></div>
280</div>
281<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
282<td align="left"></td>
283<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
284        Distributed under the Boost Software License, Version 1.0. (See accompanying
285        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>)
286      </p>
287</div></td>
288</tr></table>
289<hr>
290<div class="spirit-nav">
291<a accesskey="p" href="iterator_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parse_api.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="create_parser.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
292</div>
293</body>
294</html>
295