• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Lazy Parser (lazy)</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="../auxiliary.html" title="Auxiliary Parsers">
9<link rel="prev" href="eps.html" title="Epsilon Parser (eps)">
10<link rel="next" href="../binary.html" title="Binary Parsers">
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="eps.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auxiliary.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="../binary.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.auxiliary.lazy"></a><a class="link" href="lazy.html" title="Lazy Parser (lazy)">Lazy Parser (<code class="computeroutput"><span class="identifier">lazy</span></code>)</a>
28</h5></div></div></div>
29<h6>
30<a name="spirit.qi.reference.auxiliary.lazy.h0"></a>
31            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.description"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.description">Description</a>
32          </h6>
33<p>
34            The <code class="computeroutput"><span class="identifier">lazy</span></code> parser, as its
35            name suggests, invokes a lazy <a href="../../../../../../../../libs/phoenix/doc/html/index.html" target="_top">Boost.Phoenix</a>
36            function that returns a parser at parse time. This parser will be used
37            once it is created to continue the parse.
38          </p>
39<h6>
40<a name="spirit.qi.reference.auxiliary.lazy.h1"></a>
41            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.header"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.header">Header</a>
42          </h6>
43<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/auxiliary/lazy.hpp&gt;</span>
44<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_lazy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
45</pre>
46<p>
47            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
48          </p>
49<h6>
50<a name="spirit.qi.reference.auxiliary.lazy.h2"></a>
51            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.namespace"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.namespace">Namespace</a>
52          </h6>
53<div class="informaltable"><table class="table">
54<colgroup><col></colgroup>
55<thead><tr><th>
56                    <p>
57                      Name
58                    </p>
59                  </th></tr></thead>
60<tbody><tr><td>
61                    <p>
62                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">lazy</span> <span class="comment">// alias:
63                      boost::spirit::qi::lazy</span></code>
64                    </p>
65                  </td></tr></tbody>
66</table></div>
67<h6>
68<a name="spirit.qi.reference.auxiliary.lazy.h3"></a>
69            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.model_of"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.model_of">Model
70            of</a>
71          </h6>
72<div class="blockquote"><blockquote class="blockquote"><p>
73              <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>
74            </p></blockquote></div>
75<div class="variablelist">
76<p class="title"><b>Notation</b></p>
77<dl class="variablelist">
78<dt><span class="term"><code class="computeroutput"><span class="identifier">fp</span></code></span></dt>
79<dd><p>
80                  A <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
81                  Argument</a> that evaluates to a <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>.
82                </p></dd>
83</dl>
84</div>
85<h6>
86<a name="spirit.qi.reference.auxiliary.lazy.h4"></a>
87            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.expression_semantics"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.expression_semantics">Expression
88            Semantics</a>
89          </h6>
90<p>
91            Semantics of an expression is defined only where it differs from, or
92            is not defined in <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>.
93          </p>
94<div class="informaltable"><table class="table">
95<colgroup>
96<col>
97<col>
98</colgroup>
99<thead><tr>
100<th>
101                    <p>
102                      Expression
103                    </p>
104                  </th>
105<th>
106                    <p>
107                      Semantics
108                    </p>
109                  </th>
110</tr></thead>
111<tbody>
112<tr>
113<td>
114                    <p>
115                      <code class="computeroutput"><span class="identifier">fp</span></code>
116                    </p>
117                  </td>
118<td>
119                    <p>
120                      Create a lazy-parser from a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
121                      Argument</a>, <code class="computeroutput"><span class="identifier">fp</span></code>.
122                      <code class="computeroutput"><span class="identifier">fp</span></code> will be
123                      invoked at parse time. <code class="computeroutput"><span class="identifier">fp</span></code>
124                      is expected to return a <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a> object. This
125                      parser is then invoked in order to parse the input.
126                    </p>
127                  </td>
128</tr>
129<tr>
130<td>
131                    <p>
132                      <code class="computeroutput"><span class="identifier">lazy</span><span class="special">(</span><span class="identifier">fp</span><span class="special">)</span></code>
133                    </p>
134                  </td>
135<td>
136                    <p>
137                      Create a lazy-parser from a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
138                      Argument</a>, <code class="computeroutput"><span class="identifier">fp</span></code>.
139                      <code class="computeroutput"><span class="identifier">fp</span></code> will be
140                      invoked at parse time. <code class="computeroutput"><span class="identifier">fp</span></code>
141                      is expected to return a <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a> object. This
142                      parser is then invoked in order to parse the input.
143                    </p>
144                  </td>
145</tr>
146</tbody>
147</table></div>
148<h6>
149<a name="spirit.qi.reference.auxiliary.lazy.h5"></a>
150            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.attributes"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.attributes">Attributes</a>
151          </h6>
152<div class="informaltable"><table class="table">
153<colgroup>
154<col>
155<col>
156</colgroup>
157<thead><tr>
158<th>
159                    <p>
160                      Expression
161                    </p>
162                  </th>
163<th>
164                    <p>
165                      Attribute
166                    </p>
167                  </th>
168</tr></thead>
169<tbody>
170<tr>
171<td>
172                    <p>
173                      <code class="computeroutput"><span class="identifier">fp</span></code>
174                    </p>
175                  </td>
176<td>
177                    <p>
178                      The attribute type of the return type of <code class="computeroutput"><span class="identifier">fp</span></code>.
179                    </p>
180                  </td>
181</tr>
182<tr>
183<td>
184                    <p>
185                      <code class="computeroutput"><span class="identifier">lazy</span><span class="special">(</span><span class="identifier">fp</span><span class="special">)</span></code>
186                    </p>
187                  </td>
188<td>
189                    <p>
190                      The attribute type of the return type of <code class="computeroutput"><span class="identifier">fp</span></code>.
191                    </p>
192                  </td>
193</tr>
194</tbody>
195</table></div>
196<h6>
197<a name="spirit.qi.reference.auxiliary.lazy.h6"></a>
198            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.complexity"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.complexity">Complexity</a>
199          </h6>
200<p>
201            The complexity of the <code class="computeroutput"><span class="identifier">lazy</span></code>
202            parser is determined by the complexity of the parser returned from <code class="computeroutput"><span class="identifier">fp</span></code>.
203          </p>
204<h6>
205<a name="spirit.qi.reference.auxiliary.lazy.h7"></a>
206            <span class="phrase"><a name="spirit.qi.reference.auxiliary.lazy.example"></a></span><a class="link" href="lazy.html#spirit.qi.reference.auxiliary.lazy.example">Example</a>
207          </h6>
208<div class="note"><table border="0" summary="Note">
209<tr>
210<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
211<th align="left">Note</th>
212</tr>
213<tr><td align="left" valign="top"><p>
214              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>
215              section.
216            </p></td></tr>
217</table></div>
218<p>
219            Some using declarations:
220          </p>
221<p>
222</p>
223<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">qi</span><span class="special">::</span><span class="identifier">lazy</span><span class="special">;</span>
224<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">string</span><span class="special">;</span>
225<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">val</span><span class="special">;</span>
226</pre>
227<p>
228          </p>
229<p>
230            Using <code class="computeroutput"><span class="identifier">lazy</span></code>:
231          </p>
232<p>
233            Here, the phoenix::val expression creates a function that returns its
234            argument when invoked. The lazy expression defers the invocation of this
235            function at parse time. Then, this parser (string parser) is called into
236            action. All this takes place at parse time.
237          </p>
238<p>
239</p>
240<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"Hello"</span><span class="special">,</span> <span class="identifier">lazy</span><span class="special">(</span><span class="identifier">val</span><span class="special">(</span><span class="identifier">string</span><span class="special">(</span><span class="string">"Hello"</span><span class="special">))));</span>
241</pre>
242<p>
243          </p>
244<p>
245            The above is equivalent to:
246          </p>
247<p>
248</p>
249<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"Hello"</span><span class="special">,</span> <span class="identifier">string</span><span class="special">(</span><span class="string">"Hello"</span><span class="special">));</span>
250</pre>
251<p>
252          </p>
253</div>
254<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
255<td align="left"></td>
256<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
257        Distributed under the Boost Software License, Version 1.0. (See accompanying
258        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>)
259      </p>
260</div></td>
261</tr></table>
262<hr>
263<div class="spirit-nav">
264<a accesskey="p" href="eps.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../auxiliary.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="../binary.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
265</div>
266</body>
267</html>
268