1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Qi flush_multi_pass 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 Repository 0.2"> 8<link rel="up" href="../primitive.html" title="Qi Parser Primitives"> 9<link rel="prev" href="advance.html" title="Qi advance Parser"> 10<link rel="next" href="../directives.html" title="Qi Parser Directives"> 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="advance.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../primitive.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="../directives.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="spirit_repository.qi_components.primitive.flush_multi_pass"></a><a class="link" href="flush_multi_pass.html" title="Qi flush_multi_pass parser">Qi 28 flush_multi_pass parser</a> 29</h4></div></div></div> 30<h6> 31<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h0"></a> 32 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.description"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.description">Description</a> 33 </h6> 34<p> 35 The <span class="emphasis"><em>Spirit.Qi</em></span> <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> 36 parser is a primitive (pseudo) parser component allowing to clear the internal 37 buffer of a <code class="computeroutput"><span class="identifier">multi_pass</span></code> 38 iterator. Clearing the buffer of a <code class="computeroutput"><span class="identifier">multi_pass</span></code> 39 might be beneficial for grammars where it is clear that no backtracking 40 can occur. The general syntax for using the <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> 41 is: 42 </p> 43<pre class="programlisting"><span class="identifier">flush_multi_pass</span> 44</pre> 45<p> 46 which will call the <code class="computeroutput"><span class="identifier">clear_queue</span><span class="special">()</span></code> member function if the current iterators 47 are of the type <code class="computeroutput"><span class="identifier">multi_pass</span></code>. 48 This will cause any buffered data to be erased. This also will invalidate 49 all other copies of multi_pass and they should not be used. If they are, 50 an <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">illegal_backtracking</span></code> exception will be 51 thrown. For all other iterator types this is a no-op. The <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> generates a parser component 52 which always succeeds and which does not consume any input (very much like 53 <code class="computeroutput"><span class="identifier">eps</span></code>). 54 </p> 55<h6> 56<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h1"></a> 57 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.header"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.header">Header</a> 58 </h6> 59<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/repository/home/qi/primitive/flush_multi_pass.hpp></span> 60<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">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_flush_multi_pass</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 61</pre> 62<h6> 63<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h2"></a> 64 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.synopsis"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.synopsis">Synopsis</a> 65 </h6> 66<pre class="programlisting"><span class="identifier">flush_multi_pass</span> 67</pre> 68<h6> 69<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h3"></a> 70 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.parameters"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.parameters">Parameters</a> 71 </h6> 72<p> 73 The <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> does 74 not require any parameters. 75 </p> 76<h6> 77<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h4"></a> 78 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.attribute"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.attribute">Attribute</a> 79 </h6> 80<p> 81 The <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> component 82 exposes no attribute (the exposed attribute type is <code class="computeroutput"><span class="identifier">unused_type</span></code>): 83 </p> 84<pre class="programlisting"><span class="identifier">flush_multi_pass</span> <span class="special">--></span> <span class="identifier">unused</span> 85</pre> 86<h6> 87<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h5"></a> 88 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.example"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.example">Example</a> 89 </h6> 90<p> 91 The following example shows a simple use case of the <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> 92 parser. 93 </p> 94<p> 95 We will illustrate its usage by generating different comment styles and 96 a function prototype (for the full example code see here: <a href="../../../../../example/qi/flush_multi_pass.cpp" target="_top">flush_multi_pass.cpp</a>) 97 </p> 98<h6> 99<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h6"></a> 100 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.prerequisites"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.prerequisites">Prerequisites</a> 101 </h6> 102<p> 103 In addition to the main header file needed to include the core components 104 implemented in <span class="emphasis"><em>Spirit.Qi</em></span> we add the header file needed 105 for the new <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> 106 parser. 107 </p> 108<p> 109</p> 110<pre class="programlisting"><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</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 111<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">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_flush_multi_pass</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 112</pre> 113<p> 114 </p> 115<p> 116 To make all the code below more readable we introduce the following namespaces. 117 </p> 118<p> 119</p> 120<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">;</span> 121<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">repository</span><span class="special">::</span><span class="identifier">flush_multi_pass</span><span class="special">;</span> 122</pre> 123<p> 124 </p> 125<h6> 126<a name="spirit_repository.qi_components.primitive.flush_multi_pass.h7"></a> 127 <span class="phrase"><a name="spirit_repository.qi_components.primitive.flush_multi_pass.clearing_the_internal_buffer"></a></span><a class="link" href="flush_multi_pass.html#spirit_repository.qi_components.primitive.flush_multi_pass.clearing_the_internal_buffer">Clearing 128 the internal buffer</a> 129 </h6> 130<p> 131 The example grammar recognizes the (simplified) preprocessor commands 132 <code class="computeroutput"><span class="preprocessor">#define</span></code> and <code class="computeroutput"><span class="preprocessor">#undef</span></code> both of which are constraint 133 to a single line. This makes it possible to delete all internal iterator 134 buffers on each detected line break. This is safe as no backtracking will 135 occur after any line end. The following code snippet shows the usage of 136 <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> for this 137 purpose. 138 </p> 139<p> 140</p> 141<pre class="programlisting"><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">Skipper</span><span class="special">></span> 142<span class="keyword">struct</span> <span class="identifier">preprocessor</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">grammar</span><span class="special"><</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">Skipper</span><span class="special">></span> 143<span class="special">{</span> 144 <span class="comment">// This is a simplified preprocessor grammar recognizing</span> 145 <span class="comment">//</span> 146 <span class="comment">// #define MACRONAME something</span> 147 <span class="comment">// #undef MACRONAME</span> 148 <span class="comment">//</span> 149 <span class="comment">// Its sole purpose is to show an example how to use the </span> 150 <span class="comment">// flush_multi_pass parser. At the end of each line no backtracking can</span> 151 <span class="comment">// occur anymore so that it's safe to clear all internal buffers in the </span> 152 <span class="comment">// multi_pass.</span> 153 <span class="identifier">preprocessor</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">preprocessor</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">file</span><span class="special">)</span> 154 <span class="special">{</span> 155 <span class="keyword">using</span> <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span> 156 <span class="keyword">using</span> <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">eol</span><span class="special">;</span> 157 <span class="keyword">using</span> <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">lit</span><span class="special">;</span> 158 159 <span class="identifier">file</span> <span class="special">=</span> 160 <span class="special">*</span><span class="identifier">line</span> 161 <span class="special">;</span> 162 163 <span class="identifier">line</span> <span class="special">=</span> <span class="special">(</span> <span class="identifier">command</span> <span class="special">|</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span> <span class="special">)</span> 164 <span class="special">>></span> <span class="identifier">eol</span> 165 <span class="special">>></span> <span class="identifier">flush_multi_pass</span> 166 <span class="special">;</span> 167 168 <span class="identifier">command</span> <span class="special">=</span> 169 <span class="string">"#define"</span> <span class="special">>></span> <span class="special">*</span><span class="identifier">lit</span><span class="special">(</span><span class="char">' '</span><span class="special">)</span> <span class="special">>></span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="char">' '</span><span class="special">)</span> <span class="special">>></span> <span class="special">*</span><span class="identifier">lit</span><span class="special">(</span><span class="char">' '</span><span class="special">)</span> <span class="special">>></span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span> 170 <span class="special">|</span> <span class="string">"#undef"</span> <span class="special">>></span> <span class="special">*</span><span class="identifier">lit</span><span class="special">(</span><span class="char">' '</span><span class="special">)</span> <span class="special">>></span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span> 171 <span class="special">;</span> 172 <span class="special">}</span> 173 174 <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">rule</span><span class="special"><</span><span class="identifier">Iterator</span><span class="special">,</span> <span class="identifier">Skipper</span><span class="special">></span> <span class="identifier">file</span><span class="special">,</span> <span class="identifier">line</span><span class="special">,</span> <span class="identifier">command</span><span class="special">;</span> 175<span class="special">};</span> 176</pre> 177<p> 178 </p> 179<div class="note"><table border="0" summary="Note"> 180<tr> 181<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td> 182<th align="left">Note</th> 183</tr> 184<tr><td align="left" valign="top"><p> 185 Using the <code class="computeroutput"><span class="identifier">flush_multi_pass</span></code> 186 parser component with iterators other than <code class="computeroutput"><span class="identifier">multi_pass</span></code> 187 is safe as it has no effect on the parsing. 188 </p></td></tr> 189</table></div> 190</div> 191<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 192<td align="left"></td> 193<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 194 Distributed under the Boost Software License, Version 1.0. (See accompanying 195 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>) 196 </p> 197</div></td> 198</tr></table> 199<hr> 200<div class="spirit-nav"> 201<a accesskey="p" href="advance.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../primitive.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="../directives.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 202</div> 203</body> 204</html> 205