1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Iterator 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="../parse_api.html" title="Parser API"> 10<link rel="next" href="stream_api.html" title="Stream Based Parser API"> 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="../parse_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="stream_api.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.iterator_api"></a><a class="link" href="iterator_api.html" title="Iterator Based Parser API">Iterator 28 Based Parser API</a> 29</h5></div></div></div> 30<h6> 31<a name="spirit.qi.reference.parse_api.iterator_api.h0"></a> 32 <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.description"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.description">Description</a> 33 </h6> 34<p> 35 The library provides a couple of free functions to make parsing a snap. 36 These parser functions have two forms. The first form <code class="computeroutput"><span class="identifier">parse</span></code> 37 works on the character level. The second <code class="computeroutput"><span class="identifier">phrase_parse</span></code> 38 works on the phrase level and requires skip parser. Both versions can 39 take in attributes by reference that will hold the parsed values on a 40 successful parse. 41 </p> 42<h6> 43<a name="spirit.qi.reference.parse_api.iterator_api.h1"></a> 44 <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.header"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.header">Header</a> 45 </h6> 46<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/parse.hpp></span> 47<span class="preprocessor">#include</span> <span class="special"><</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_parse</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 48</pre> 49<p> 50 For variadic attributes: 51 </p> 52<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/parse_attr.hpp></span> 53<span class="preprocessor">#include</span> <span class="special"><</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_parse_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 54</pre> 55<p> 56 The variadic attributes version of the API allows one or more attributes 57 to be passed into the parse functions. The functions taking two or more 58 are usable when the parser expression is a <a class="link" href="../operator/sequence.html" title="Sequence Parser (a >> b)">Sequence</a> 59 only. In this case each of the attributes passed have to match the corresponding 60 part of the sequence. 61 </p> 62<p> 63 For the API functions deducing the correct (matching) parser type from 64 the supplied attribute type: 65 </p> 66<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/detail/parse_auto.hpp></span> 67<span class="preprocessor">#include</span> <span class="special"><</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_parse_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 68</pre> 69<p> 70 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 71 </p> 72<h6> 73<a name="spirit.qi.reference.parse_api.iterator_api.h2"></a> 74 <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.namespace"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.namespace">Namespace</a> 75 </h6> 76<div class="informaltable"><table class="table"> 77<colgroup><col></colgroup> 78<thead><tr><th> 79 <p> 80 Name 81 </p> 82 </th></tr></thead> 83<tbody> 84<tr><td> 85 <p> 86 <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">parse</span></code> 87 </p> 88 </td></tr> 89<tr><td> 90 <p> 91 <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_parse</span></code> 92 </p> 93 </td></tr> 94<tr><td> 95 <p> 96 <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> 97 </p> 98 </td></tr> 99<tr><td> 100 <p> 101 <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> 102 </p> 103 </td></tr> 104</tbody> 105</table></div> 106<h6> 107<a name="spirit.qi.reference.parse_api.iterator_api.h3"></a> 108 <span class="phrase"><a name="spirit.qi.reference.parse_api.iterator_api.synopsis"></a></span><a class="link" href="iterator_api.html#spirit.qi.reference.parse_api.iterator_api.synopsis">Synopsis</a> 109 </h6> 110<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> 111<span class="special">{</span> 112 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">></span> 113 <span class="keyword">inline</span> <span class="keyword">bool</span> 114 <span class="identifier">parse</span><span class="special">(</span> 115 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 116 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 117 <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">expr</span><span class="special">);</span> 118 119 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</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">></span> 121 <span class="keyword">inline</span> <span class="keyword">bool</span> 122 <span class="identifier">parse</span><span class="special">(</span> 123 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 124 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 125 <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">expr</span> 126 <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&</span> <span class="identifier">attrN</span><span class="special">);</span> 127 128 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</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">></span> 129 <span class="keyword">inline</span> <span class="keyword">bool</span> 130 <span class="identifier">phrase_parse</span><span class="special">(</span> 131 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 132 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 133 <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">expr</span> 134 <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">skipper</span> 135 <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> 136 137 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</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> 138 <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">></span> 139 <span class="keyword">inline</span> <span class="keyword">bool</span> 140 <span class="identifier">phrase_parse</span><span class="special">(</span> 141 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 142 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 143 <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">expr</span> 144 <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">skipper</span> 145 <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&</span> <span class="identifier">attrN</span><span class="special">);</span> 146 147 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</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> 148 <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">></span> 149 <span class="keyword">inline</span> <span class="keyword">bool</span> 150 <span class="identifier">phrase_parse</span><span class="special">(</span> 151 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 152 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 153 <span class="special">,</span> <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">expr</span> 154 <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">skipper</span> 155 <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> 156 <span class="special">,</span> <span class="identifier">Attr1</span><span class="special">&</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span><span class="special">&</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span><span class="special">&</span> <span class="identifier">attrN</span><span class="special">);</span> 157<span class="special">}}}</span> 158</pre> 159<div class="note"><table border="0" summary="Note"> 160<tr> 161<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 162<th align="left">Note</th> 163</tr> 164<tr><td align="left" valign="top"><p> 165 Starting with <a href="http://boost-spirit.com" target="_top">Spirit</a> V2.5 166 (distributed with Boost V1.47) the placeholder <code class="computeroutput"><span class="identifier">_val</span></code> 167 can be used in semantic actions attached to top level parser components. 168 In this case <code class="computeroutput"><span class="identifier">_val</span></code> refers 169 to the supplied attribute as a whole. For API functions taking more 170 than one attribute argument <code class="computeroutput"><span class="identifier">_val</span></code> 171 will refer to a Fusion vector or references to the attributes. 172 </p></td></tr> 173</table></div> 174<p> 175 <span class="emphasis"><em>Spirit.Qi</em></span> parser API functions based on the automatic 176 creation of the matching parser type: 177 </p> 178<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> 179<span class="special">{</span> 180 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">></span> 181 <span class="keyword">inline</span> <span class="keyword">bool</span> 182 <span class="identifier">parse</span><span class="special">(</span> 183 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 184 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 185 <span class="special">,</span> <span class="identifier">Attr</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">);</span> 186 187 188 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">,</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">></span> 189 <span class="keyword">inline</span> <span class="keyword">bool</span> 190 <span class="identifier">phrase_parse</span><span class="special">(</span> 191 <span class="identifier">Iterator</span><span class="special">&</span> <span class="identifier">first</span> 192 <span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">last</span> 193 <span class="special">,</span> <span class="identifier">Attr</span><span class="special">&</span> <span class="identifier">attr</span> 194 <span class="special">,</span> <span class="identifier">Skipper</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">skipper</span> 195 <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> 196<span class="special">}}}</span> 197</pre> 198<p> 199 All functions above return <code class="computeroutput"><span class="keyword">true</span></code> 200 if none of the involved parser components failed, and <code class="computeroutput"><span class="keyword">false</span></code> 201 otherwise. 202 </p> 203<p> 204 The maximum number of supported arguments is limited by the preprocessor 205 constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>. 206 This constant defaults to the value defined by the preprocessor constant 207 <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which 208 in turn defaults to <code class="computeroutput"><span class="number">10</span></code>). 209 </p> 210<div class="note"><table border="0" summary="Note"> 211<tr> 212<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 213<th align="left">Note</th> 214</tr> 215<tr><td align="left" valign="top"><p> 216 The variadic functions with two or more attributes internally combine 217 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> 218 and forward this as a combined attribute to the corresponding one attribute 219 function. 220 </p></td></tr> 221</table></div> 222<p> 223 The <code class="computeroutput"><span class="identifier">phrase_parse</span></code> functions 224 not taking an explicit <code class="computeroutput"><span class="identifier">skip_flag</span></code> 225 as one of their arguments invoke the passed skipper after a successful 226 match of the parser expression. This can be inhibited by using the other 227 versions of that function while passing <code class="computeroutput"><span class="identifier">skip_flag</span><span class="special">::</span><span class="identifier">dont_postskip</span></code> 228 to the corresponding argument. 229 </p> 230<div class="informaltable"><table class="table"> 231<colgroup> 232<col> 233<col> 234</colgroup> 235<thead><tr> 236<th> 237 <p> 238 Parameter 239 </p> 240 </th> 241<th> 242 <p> 243 Description 244 </p> 245 </th> 246</tr></thead> 247<tbody> 248<tr> 249<td> 250 <p> 251 <code class="computeroutput"><span class="identifier">Iterator</span></code> 252 </p> 253 </td> 254<td> 255 <p> 256 <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> pointing 257 to the source to parse. 258 </p> 259 </td> 260</tr> 261<tr> 262<td> 263 <p> 264 <code class="computeroutput"><span class="identifier">Expr</span></code> 265 </p> 266 </td> 267<td> 268 <p> 269 An expression that can be converted to a Qi parser. 270 </p> 271 </td> 272</tr> 273<tr> 274<td> 275 <p> 276 <code class="computeroutput"><span class="identifier">Skipper</span></code> 277 </p> 278 </td> 279<td> 280 <p> 281 Parser used to skip white spaces. 282 </p> 283 </td> 284</tr> 285<tr> 286<td> 287 <p> 288 <code class="computeroutput"><span class="identifier">Attr</span></code> 289 </p> 290 </td> 291<td> 292 <p> 293 An attribute type utilized to create the corresponding parser 294 type from. 295 </p> 296 </td> 297</tr> 298<tr> 299<td> 300 <p> 301 <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> 302 </p> 303 </td> 304<td> 305 <p> 306 One or more attributes. 307 </p> 308 </td> 309</tr> 310</tbody> 311</table></div> 312</div> 313<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 314<td align="left"></td> 315<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 316 Distributed under the Boost Software License, Version 1.0. (See accompanying 317 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>) 318 </p> 319</div></td> 320</tr></table> 321<hr> 322<div class="spirit-nav"> 323<a accesskey="p" href="../parse_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="stream_api.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 324</div> 325</body> 326</html> 327