• 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</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="../parser_concepts.html" title="Parser Concepts">
9<link rel="prev" href="../parser_concepts.html" title="Parser Concepts">
10<link rel="next" href="primitiveparser.html" title="PrimitiveParser">
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="../parser_concepts.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parser_concepts.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="primitiveparser.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.parser_concepts.parser"></a><a class="link" href="parser.html" title="Parser">Parser</a>
28</h5></div></div></div>
29<h6>
30<a name="spirit.qi.reference.parser_concepts.parser.h0"></a>
31            <span class="phrase"><a name="spirit.qi.reference.parser_concepts.parser.description"></a></span><a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.description">Description</a>
32          </h6>
33<p>
34            The <span class="emphasis"><em>Parser</em></span> is the most fundamental concept. A Parser
35            has a member function, <code class="computeroutput"><span class="identifier">parse</span></code>,
36            that accepts a first-last <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> pair and returns
37            bool as its result. The iterators delimit the data being parsed. The
38            Parser's <code class="computeroutput"><span class="identifier">parse</span></code> member
39            function returns <code class="computeroutput"><span class="keyword">true</span></code> if
40            the parse succeeds, in which case the first iterator is advanced accordingly.
41            Each Parser can represent a specific pattern or algorithm, or it can
42            be a more complex parser formed as a composition of other Parsers.
43          </p>
44<div class="variablelist">
45<p class="title"><b>Notation</b></p>
46<dl class="variablelist">
47<dt><span class="term"><code class="computeroutput"><span class="identifier">p</span></code></span></dt>
48<dd><p>
49                  A <code class="computeroutput"><span class="identifier">Parser</span></code>.
50                </p></dd>
51<dt><span class="term"><code class="computeroutput"><span class="identifier">P</span></code></span></dt>
52<dd><p>
53                  A <code class="computeroutput"><span class="identifier">Parser</span></code> type.
54                </p></dd>
55<dt><span class="term"><code class="computeroutput"><span class="identifier">Iter</span></code></span></dt>
56<dd><p>
57                  a <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> type.
58                </p></dd>
59<dt><span class="term"><code class="computeroutput"><span class="identifier">f</span></code>, <code class="computeroutput"><span class="identifier">l</span></code></span></dt>
60<dd><p>
61                  <a href="http://en.cppreference.com/w/cpp/named_req/ForwardIterator" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a>. first/last
62                  iterator pair.
63                </p></dd>
64<dt><span class="term"><code class="computeroutput"><span class="identifier">Context</span></code></span></dt>
65<dd><p>
66                  The parser's Context type.
67                </p></dd>
68<dt><span class="term"><code class="computeroutput"><span class="identifier">context</span></code></span></dt>
69<dd><p>
70                  The parser's Context, or <code class="computeroutput"><span class="identifier">unused</span></code>.
71                </p></dd>
72<dt><span class="term"><code class="computeroutput"><span class="identifier">skip</span></code></span></dt>
73<dd><p>
74                  A skip Parser, or <code class="computeroutput"><span class="identifier">unused</span></code>.
75                </p></dd>
76<dt><span class="term"><code class="computeroutput"><span class="identifier">attrib</span></code></span></dt>
77<dd><p>
78                  A Compatible Attribute, or <code class="computeroutput"><span class="identifier">unused</span></code>.
79                </p></dd>
80</dl>
81</div>
82<h6>
83<a name="spirit.qi.reference.parser_concepts.parser.h1"></a>
84            <span class="phrase"><a name="spirit.qi.reference.parser_concepts.parser.valid_expressions"></a></span><a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.valid_expressions">Valid
85            Expressions</a>
86          </h6>
87<p>
88            In the expressions below, the behavior of the parser, <code class="computeroutput"><span class="identifier">p</span></code>,
89            and how <code class="computeroutput"><span class="identifier">skip</span></code> and <code class="computeroutput"><span class="identifier">attrib</span></code> are handled by <code class="computeroutput"><span class="identifier">p</span></code>, are left unspecified in the base
90            <code class="computeroutput"><span class="identifier">Parser</span></code> concept. These
91            are specified in subsequent, more refined concepts and by the actual
92            models thereof.
93          </p>
94<p>
95            For any Parser the following expressions must be valid:
96          </p>
97<div class="informaltable"><table class="table">
98<colgroup>
99<col>
100<col>
101<col>
102</colgroup>
103<thead><tr>
104<th>
105                    <p>
106                      Expression
107                    </p>
108                  </th>
109<th>
110                    <p>
111                      Semantics
112                    </p>
113                  </th>
114<th>
115                    <p>
116                      Return type
117                    </p>
118                  </th>
119</tr></thead>
120<tbody>
121<tr>
122<td>
123                    <p>
124</p>
125<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">p</span><span class="special">.</span><span class="identifier">parse</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">l</span><span class="special">,</span> <span class="identifier">context</span><span class="special">,</span> <span class="identifier">skip</span><span class="special">,</span> <span class="identifier">attr</span><span class="special">)</span></pre>
126<p>
127                    </p>
128                  </td>
129<td>
130                    <p>
131                      Match the input sequence starting from <code class="computeroutput"><span class="identifier">f</span></code>.
132                      Return <code class="computeroutput"><span class="keyword">true</span></code> if
133                      successful, otherwise return <code class="computeroutput"><span class="keyword">false</span></code>.
134                    </p>
135                  </td>
136<td>
137                    <p>
138                      <code class="computeroutput"><span class="keyword">bool</span></code>
139                    </p>
140                  </td>
141</tr>
142<tr>
143<td>
144                    <p>
145                      <code class="computeroutput"><span class="identifier">p</span><span class="special">.</span><span class="identifier">what</span><span class="special">(</span><span class="identifier">context</span><span class="special">)</span></code>
146                    </p>
147                  </td>
148<td>
149                    <p>
150                      Get information about a Parser.
151                    </p>
152                  </td>
153<td>
154                    <p>
155                      <code class="computeroutput"><span class="identifier">info</span></code>
156                    </p>
157                  </td>
158</tr>
159</tbody>
160</table></div>
161<h6>
162<a name="spirit.qi.reference.parser_concepts.parser.h2"></a>
163            <span class="phrase"><a name="spirit.qi.reference.parser_concepts.parser.type_expressions"></a></span><a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.type_expressions">Type
164            Expressions</a>
165          </h6>
166<div class="informaltable"><table class="table">
167<colgroup>
168<col>
169<col>
170</colgroup>
171<thead><tr>
172<th>
173                    <p>
174                      Expression
175                    </p>
176                  </th>
177<th>
178                    <p>
179                      Description
180                    </p>
181                  </th>
182</tr></thead>
183<tbody>
184<tr>
185<td>
186                    <p>
187                      <code class="computeroutput"><span class="identifier">P</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">attribute</span><span class="special">&lt;</span><span class="identifier">Context</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
188                    </p>
189                  </td>
190<td>
191                    <p>
192                      The Parser's expected attribute.
193                    </p>
194                  </td>
195</tr>
196<tr>
197<td>
198                    <p>
199                      <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">is_parser</span><span class="special">&lt;</span><span class="identifier">P</span><span class="special">&gt;::</span><span class="identifier">type</span></code>
200                    </p>
201                  </td>
202<td>
203                    <p>
204                      Metafunction that evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
205                      if a certain type, <code class="computeroutput"><span class="identifier">P</span></code>
206                      is a Parser, <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>
207                      otherwise (See <a href="../../../../../../../../libs/mpl/doc/refmanual/integral-constant.html" target="_top">MPL
208                      Boolean Constant</a>).
209                    </p>
210                  </td>
211</tr>
212</tbody>
213</table></div>
214<h6>
215<a name="spirit.qi.reference.parser_concepts.parser.h3"></a>
216            <span class="phrase"><a name="spirit.qi.reference.parser_concepts.parser.postcondition"></a></span><a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.postcondition">Postcondition</a>
217          </h6>
218<p>
219            Upon return from <code class="computeroutput"><span class="identifier">p</span><span class="special">.</span><span class="identifier">parse</span></code> the following post conditions
220            should hold:
221          </p>
222<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
223<li class="listitem">
224                On a successful match, <code class="computeroutput"><span class="identifier">f</span></code>
225                is positioned one past the last matching character/token.
226              </li>
227<li class="listitem">
228                On a failed match, if a <code class="computeroutput"><span class="identifier">skip</span></code>
229                parser is <code class="computeroutput"><span class="identifier">unused</span></code>,
230                <code class="computeroutput"><span class="identifier">f</span></code> is restored to
231                its original position prior to entry.
232              </li>
233<li class="listitem">
234                On a failed match, if a <code class="computeroutput"><span class="identifier">skip</span></code>
235                parser is not <code class="computeroutput"><span class="identifier">unused</span></code>,
236                <code class="computeroutput"><span class="identifier">f</span></code> is positioned one
237                past the last character/token matching <code class="computeroutput"><span class="identifier">skip</span></code>.
238              </li>
239<li class="listitem">
240                On a failed match, <code class="computeroutput"><span class="identifier">attrib</span></code>
241                state is undefined.
242              </li>
243<li class="listitem">
244                No post-skips: trailing <code class="computeroutput"><span class="identifier">skip</span></code>
245                characters/tokens will not be skipped.
246              </li>
247</ul></div>
248<h6>
249<a name="spirit.qi.reference.parser_concepts.parser.h4"></a>
250            <span class="phrase"><a name="spirit.qi.reference.parser_concepts.parser.models"></a></span><a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.models">Models</a>
251          </h6>
252<p>
253            All parsers in Spirit.Qi are models of the <span class="emphasis"><em>Parser</em></span>
254            concept.
255          </p>
256</div>
257<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
258<td align="left"></td>
259<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
260        Distributed under the Boost Software License, Version 1.0. (See accompanying
261        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>)
262      </p>
263</div></td>
264</tr></table>
265<hr>
266<div class="spirit-nav">
267<a accesskey="p" href="../parser_concepts.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../parser_concepts.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="primitiveparser.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
268</div>
269</body>
270</html>
271