| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> |
| <title>Parser</title> |
| <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.75.0"> |
| <link rel="home" href="../../../../index.html" title="Spirit 2.4.1"> |
| <link rel="up" href="../parser_concepts.html" title="Parser Concepts"> |
| <link rel="prev" href="../parser_concepts.html" title="Parser Concepts"> |
| <link rel="next" href="primitiveparser.html" title="PrimitiveParser"> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table cellpadding="2" width="100%"><tr> |
| <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> |
| <td align="center"><a href="../../../../../../../../index.html">Home</a></td> |
| <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> |
| <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> |
| <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> |
| <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <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> |
| </div> |
| <div class="section"> |
| <div class="titlepage"><div><div><h5 class="title"> |
| <a name="spirit.qi.reference.parser_concepts.parser"></a><a class="link" href="parser.html" title="Parser">Parser</a> |
| </h5></div></div></div> |
| <a name="spirit.qi.reference.parser_concepts.parser.description"></a><h6> |
| <a name="id837323"></a> |
| <a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.description">Description</a> |
| </h6> |
| <p> |
| The <span class="emphasis"><em>Parser</em></span> is the most fundamental concept. A Parser |
| has a member function, <code class="computeroutput"><span class="identifier">parse</span></code>, |
| that accepts a first-last <a href="http://www.sgi.com/tech/stl/ForwardIterator.html" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> pair and returns |
| bool as its result. The iterators delimit the data being parsed. The |
| Parser's <code class="computeroutput"><span class="identifier">parse</span></code> member |
| function returns <code class="computeroutput"><span class="keyword">true</span></code> if |
| the parse succeeds, in which case the first iterator is advanced accordingly. |
| Each Parser can represent a specific pattern or algorithm, or it can |
| be a more complex parser formed as a composition of other Parsers. |
| </p> |
| <div class="variablelist"> |
| <p class="title"><b>Notation</b></p> |
| <dl> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">p</span></code></span></dt> |
| <dd><p> |
| A <code class="computeroutput"><span class="identifier">Parser</span></code>. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">P</span></code></span></dt> |
| <dd><p> |
| A <code class="computeroutput"><span class="identifier">Parser</span></code> type. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">Iter</span></code></span></dt> |
| <dd><p> |
| a <a href="http://www.sgi.com/tech/stl/ForwardIterator.html" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a> type. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">f</span></code>, <code class="computeroutput"><span class="identifier">l</span></code></span></dt> |
| <dd><p> |
| <a href="http://www.sgi.com/tech/stl/ForwardIterator.html" target="_top"><code class="computeroutput"><span class="identifier">ForwardIterator</span></code></a>. first/last |
| iterator pair. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">Context</span></code></span></dt> |
| <dd><p> |
| The parser's Context type. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">context</span></code></span></dt> |
| <dd><p> |
| The parser's Context, or <code class="computeroutput"><span class="identifier">unused</span></code>. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">skip</span></code></span></dt> |
| <dd><p> |
| A skip Parser, or <code class="computeroutput"><span class="identifier">unused</span></code>. |
| </p></dd> |
| <dt><span class="term"><code class="computeroutput"><span class="identifier">attrib</span></code></span></dt> |
| <dd><p> |
| A Compatible Attribute, or <code class="computeroutput"><span class="identifier">unused</span></code>. |
| </p></dd> |
| </dl> |
| </div> |
| <a name="spirit.qi.reference.parser_concepts.parser.valid_expressions"></a><h6> |
| <a name="id837603"></a> |
| <a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.valid_expressions">Valid |
| Expressions</a> |
| </h6> |
| <p> |
| In the expressions below, the behavior of the parser, <code class="computeroutput"><span class="identifier">p</span></code>, |
| 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 |
| <code class="computeroutput"><span class="identifier">Parser</span></code> concept. These |
| are specified in subsequent, more refined concepts and by the actual |
| models thereof. |
| </p> |
| <p> |
| For any Parser the following expressions must be valid: |
| </p> |
| <div class="informaltable"><table class="table"> |
| <colgroup> |
| <col> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Expression |
| </p> |
| </th> |
| <th> |
| <p> |
| Semantics |
| </p> |
| </th> |
| <th> |
| <p> |
| Return type |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| |
| </p> |
| <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> |
| <p> |
| </p> |
| </td> |
| <td> |
| <p> |
| Match the input sequence starting from <code class="computeroutput"><span class="identifier">f</span></code>. |
| Return <code class="computeroutput"><span class="keyword">true</span></code> if |
| successful, otherwise return <code class="computeroutput"><span class="keyword">false</span></code>. |
| </p> |
| </td> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="keyword">bool</span></code> |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <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> |
| </p> |
| </td> |
| <td> |
| <p> |
| Get information about a Parser. |
| </p> |
| </td> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">info</span></code> |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| <a name="spirit.qi.reference.parser_concepts.parser.type_expressions"></a><h6> |
| <a name="id838088"></a> |
| <a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.type_expressions">Type |
| Expressions</a> |
| </h6> |
| <div class="informaltable"><table class="table"> |
| <colgroup> |
| <col> |
| <col> |
| </colgroup> |
| <thead><tr> |
| <th> |
| <p> |
| Expression |
| </p> |
| </th> |
| <th> |
| <p> |
| Description |
| </p> |
| </th> |
| </tr></thead> |
| <tbody> |
| <tr> |
| <td> |
| <p> |
| <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"><</span><span class="identifier">Context</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">>::</span><span class="identifier">type</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| The Parser's expected attribute. |
| </p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <p> |
| <code class="computeroutput"><span class="identifier">traits</span><span class="special">::</span><span class="identifier">is_parser</span><span class="special"><</span><span class="identifier">P</span><span class="special">>::</span><span class="identifier">type</span></code> |
| </p> |
| </td> |
| <td> |
| <p> |
| Metafunction that evaluates to <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code> |
| if a certain type, <code class="computeroutput"><span class="identifier">P</span></code> |
| is a Parser, <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code> |
| otherwise (See <a href="../../../../../../../../libs/mpl/doc/refmanual/integral-constant.html" target="_top">MPL |
| Boolean Constant</a>). |
| </p> |
| </td> |
| </tr> |
| </tbody> |
| </table></div> |
| <a name="spirit.qi.reference.parser_concepts.parser.postcondition"></a><h6> |
| <a name="id838289"></a> |
| <a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.postcondition">Postcondition</a> |
| </h6> |
| <p> |
| 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 |
| should hold: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" type="disc"> |
| <li class="listitem"> |
| On a successful match, <code class="computeroutput"><span class="identifier">f</span></code> |
| is positioned one past the last matching character/token. |
| </li> |
| <li class="listitem"> |
| On a failed match, if a <code class="computeroutput"><span class="identifier">skip</span></code> |
| parser is <code class="computeroutput"><span class="identifier">unused</span></code>, |
| <code class="computeroutput"><span class="identifier">f</span></code> is restored to |
| its original position prior to entry. |
| </li> |
| <li class="listitem"> |
| On a failed match, if a <code class="computeroutput"><span class="identifier">skip</span></code> |
| parser is not <code class="computeroutput"><span class="identifier">unused</span></code>, |
| <code class="computeroutput"><span class="identifier">f</span></code> is positioned one |
| past the last character/token matching <code class="computeroutput"><span class="identifier">skip</span></code>. |
| </li> |
| <li class="listitem"> |
| On a failed match, <code class="computeroutput"><span class="identifier">attrib</span></code> |
| is left untouched. |
| </li> |
| <li class="listitem"> |
| No post-skips: trailing <code class="computeroutput"><span class="identifier">skip</span></code> |
| characters/tokens will not be skipped. |
| </li> |
| </ul></div> |
| <a name="spirit.qi.reference.parser_concepts.parser.models"></a><h6> |
| <a name="id838434"></a> |
| <a class="link" href="parser.html#spirit.qi.reference.parser_concepts.parser.models">Models</a> |
| </h6> |
| <p> |
| All parsers in Spirit.Qi are models of the <span class="emphasis"><em>Parser</em></span> |
| concept. |
| </p> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2001-2010 Joel de Guzman, Hartmut Kaiser<p> |
| Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 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>) |
| </p> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <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> |
| </div> |
| </body> |
| </html> |