• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Qi Distinct Parser Directive</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="../directives.html" title="Qi Parser Directives">
9<link rel="prev" href="confix.html" title="Qi Confix Parser Directive">
10<link rel="next" href="kwd.html" title="Qi Keyword Parser Directive">
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="confix.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directives.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="kwd.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.directives.distinct"></a><a class="link" href="distinct.html" title="Qi Distinct Parser Directive">Qi
28        Distinct Parser Directive</a>
29</h4></div></div></div>
30<h6>
31<a name="spirit_repository.qi_components.directives.distinct.h0"></a>
32          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.description"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.description">Description</a>
33        </h6>
34<p>
35          The <span class="emphasis"><em>Spirit.Qi</em></span> <code class="computeroutput"><span class="identifier">distinct</span></code>
36          parser is a directive component allowing to avoid partial matches while
37          parsing using a skipper. A simple example is the common task of matching
38          a C keyword. Consider:
39        </p>
40<pre class="programlisting"><span class="string">"description"</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">":"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span>
41</pre>
42<p>
43          intended to match a line in a configuration file. Let's assume further,
44          that this rule is used with a <code class="computeroutput"><span class="identifier">space</span></code>
45          skipper and that we have the following strings in the input:
46        </p>
47<pre class="programlisting"><span class="string">"description: ident\n"</span>
48<span class="string">"description ident\n"</span>
49<span class="string">"descriptionident\n"</span>
50</pre>
51<p>
52          It might seem unexpected, but the parser above matches all three inputs
53          just fine, even if the third input should not match at all! In order to
54          avoid the unwanted match we are forced to make our rule more complicated:
55        </p>
56<pre class="programlisting"><span class="identifier">lexeme</span><span class="special">[</span><span class="string">"description"</span> <span class="special">&gt;&gt;</span> <span class="special">!</span><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-zA-Z_0-9"</span><span class="special">)]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">":"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span>
57</pre>
58<p>
59          (the rule reads as: match <code class="computeroutput"><span class="string">"description"</span></code>
60          as long as it's not <span class="emphasis"><em>directly</em></span> followed by a valid identifier).
61        </p>
62<p>
63          The <code class="computeroutput"><span class="identifier">distinct</span><span class="special">[]</span></code>
64          directive is meant to simplify the rule above:
65        </p>
66<pre class="programlisting"><span class="identifier">distinct</span><span class="special">(</span><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-zA-Z_0-9"</span><span class="special">))[</span><span class="string">"description"</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">":"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span>
67</pre>
68<p>
69          Using the <code class="computeroutput"><span class="identifier">distinct</span><span class="special">[]</span></code>
70          component instead of the explicit sequence has the advantage of being able
71          to encapsulate the tail (i.e the <code class="computeroutput"><span class="identifier">char_</span><span class="special">(</span><span class="string">"a-zA-Z_0-9"</span><span class="special">)</span></code>) as a separate parser construct. The following
72          code snippet illustrates the idea (for the full code of this example please
73          see <a href="../../../../../test/qi/distinct.cpp" target="_top">distinct.cpp</a>):
74        </p>
75<p>
76</p>
77<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>
78<span class="keyword">namespace</span> <span class="identifier">ascii</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">ascii</span><span class="special">;</span>
79<span class="keyword">namespace</span> <span class="identifier">repo</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>
80
81<span class="comment">// Define metafunctions allowing to compute the type of the distinct()</span>
82<span class="comment">// and ascii::char_() constructs</span>
83<span class="keyword">namespace</span> <span class="identifier">traits</span>
84<span class="special">{</span>
85    <span class="comment">// Metafunction allowing to get the type of any repository::distinct(...) </span>
86    <span class="comment">// construct</span>
87    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Tail</span><span class="special">&gt;</span>
88    <span class="keyword">struct</span> <span class="identifier">distinct_spec</span>
89      <span class="special">:</span> <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">result_of</span><span class="special">::</span><span class="identifier">terminal</span><span class="special">&lt;</span><span class="identifier">repo</span><span class="special">::</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">distinct</span><span class="special">(</span><span class="identifier">Tail</span><span class="special">)&gt;</span>
90    <span class="special">{};</span>
91
92    <span class="comment">// Metafunction allowing to get the type of any ascii::char_(...) construct</span>
93    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">String</span><span class="special">&gt;</span>
94    <span class="keyword">struct</span> <span class="identifier">char_spec</span>
95      <span class="special">:</span> <span class="identifier">spirit</span><span class="special">::</span><span class="identifier">result_of</span><span class="special">::</span><span class="identifier">terminal</span><span class="special">&lt;</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">String</span><span class="special">)&gt;</span>
96    <span class="special">{};</span>
97<span class="special">}</span>
98
99<span class="comment">// Define a helper function allowing to create a distinct() construct from </span>
100<span class="comment">// an arbitrary tail parser</span>
101<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Tail</span><span class="special">&gt;</span>
102<span class="keyword">inline</span> <span class="keyword">typename</span> <span class="identifier">traits</span><span class="special">::</span><span class="identifier">distinct_spec</span><span class="special">&lt;</span><span class="identifier">Tail</span><span class="special">&gt;::</span><span class="identifier">type</span>
103<span class="identifier">distinct_spec</span><span class="special">(</span><span class="identifier">Tail</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">tail</span><span class="special">)</span>
104<span class="special">{</span>
105    <span class="keyword">return</span> <span class="identifier">repo</span><span class="special">::</span><span class="identifier">distinct</span><span class="special">(</span><span class="identifier">tail</span><span class="special">);</span>
106<span class="special">}</span>
107
108<span class="comment">// Define a helper function allowing to create a ascii::char_() construct </span>
109<span class="comment">// from an arbitrary string representation</span>
110<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">String</span><span class="special">&gt;</span>
111<span class="keyword">inline</span> <span class="keyword">typename</span> <span class="identifier">traits</span><span class="special">::</span><span class="identifier">char_spec</span><span class="special">&lt;</span><span class="identifier">String</span><span class="special">&gt;::</span><span class="identifier">type</span>
112<span class="identifier">char_spec</span><span class="special">(</span><span class="identifier">String</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">str</span><span class="special">)</span>
113<span class="special">{</span>
114    <span class="keyword">return</span> <span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">(</span><span class="identifier">str</span><span class="special">);</span>
115<span class="special">}</span>
116
117<span class="comment">// the following constructs the type of a distinct_spec holding a</span>
118<span class="comment">// charset("0-9a-zA-Z_") as its tail parser</span>
119<span class="keyword">typedef</span> <span class="identifier">traits</span><span class="special">::</span><span class="identifier">char_spec</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">charset_tag_type</span><span class="special">;</span>
120<span class="keyword">typedef</span> <span class="identifier">traits</span><span class="special">::</span><span class="identifier">distinct_spec</span><span class="special">&lt;</span><span class="identifier">charset_tag_type</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">keyword_tag_type</span><span class="special">;</span>
121
122<span class="comment">// Define a new Qi 'keyword' directive usable as a shortcut for a</span>
123<span class="comment">// repository::distinct(char_(std::string("0-9a-zA-Z_")))</span>
124<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="identifier">keyword_spec</span><span class="special">(</span><span class="string">"0-9a-zA-Z_"</span><span class="special">);</span>
125<span class="identifier">keyword_tag_type</span> <span class="keyword">const</span> <span class="identifier">keyword</span> <span class="special">=</span> <span class="identifier">distinct_spec</span><span class="special">(</span><span class="identifier">char_spec</span><span class="special">(</span><span class="identifier">keyword_spec</span><span class="special">));</span>
126</pre>
127<p>
128        </p>
129<p>
130          These definitions define a new Qi parser recognizing keywords! This allows
131          to rewrite our declaration parser expression as:
132        </p>
133<pre class="programlisting"><span class="identifier">keyword</span><span class="special">[</span><span class="string">"description"</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">":"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="identifier">eol</span><span class="special">)</span>
134</pre>
135<p>
136          which is much more readable and concise if compared to the original parser
137          expression. In addition the new <code class="computeroutput"><span class="identifier">keyword</span><span class="special">[]</span></code> directive has the advantage to be usable
138          for wrapping any parser expression, not only strings as in the example
139          above.
140        </p>
141<h6>
142<a name="spirit_repository.qi_components.directives.distinct.h1"></a>
143          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.header"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.header">Header</a>
144        </h6>
145<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/repository/home/qi/directive/distinct.hpp&gt;</span>
146<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">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_distinct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
147</pre>
148<h6>
149<a name="spirit_repository.qi_components.directives.distinct.h2"></a>
150          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.synopsis"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.synopsis">Synopsis</a>
151        </h6>
152<pre class="programlisting"><span class="identifier">distinct</span><span class="special">(</span><span class="identifier">tail</span><span class="special">)[</span><span class="identifier">subject</span><span class="special">]</span>
153</pre>
154<h6>
155<a name="spirit_repository.qi_components.directives.distinct.h3"></a>
156          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.parameters"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.parameters">Parameters</a>
157        </h6>
158<div class="informaltable"><table class="table">
159<colgroup>
160<col>
161<col>
162</colgroup>
163<thead><tr>
164<th>
165                  <p>
166                    Parameter
167                  </p>
168                </th>
169<th>
170                  <p>
171                    Description
172                  </p>
173                </th>
174</tr></thead>
175<tbody>
176<tr>
177<td>
178                  <p>
179                    <code class="computeroutput"><span class="identifier">tail</span></code>
180                  </p>
181                </td>
182<td>
183                  <p>
184                    The parser construct specifying what whould not follow the subject
185                    in order to match the overall expression.
186                  </p>
187                </td>
188</tr>
189<tr>
190<td>
191                  <p>
192                    <code class="computeroutput"><span class="identifier">subject</span></code>
193                  </p>
194                </td>
195<td>
196                  <p>
197                    The parser construct to use to match the current input. The distinct
198                    directive makes sure that no unexpected partial matches occur.
199                  </p>
200                </td>
201</tr>
202</tbody>
203</table></div>
204<p>
205          All two parameters can be arbitrary complex parsers themselves.
206        </p>
207<h6>
208<a name="spirit_repository.qi_components.directives.distinct.h4"></a>
209          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.attribute"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.attribute">Attribute</a>
210        </h6>
211<p>
212          The <code class="computeroutput"><span class="identifier">distinct</span></code> component
213          exposes the attribute type of its subject as its own attribute type. If
214          the <code class="computeroutput"><span class="identifier">subject</span></code> does not expose
215          any attribute (the type is <code class="computeroutput"><span class="identifier">unused_type</span></code>),
216          then the <code class="computeroutput"><span class="identifier">distinct</span></code> does
217          not expose any attribute either.
218        </p>
219<pre class="programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--&gt;</span> <span class="identifier">distinct</span><span class="special">(</span><span class="identifier">b</span><span class="special">)[</span><span class="identifier">a</span><span class="special">]:</span> <span class="identifier">A</span>
220</pre>
221<h6>
222<a name="spirit_repository.qi_components.directives.distinct.h5"></a>
223          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.example"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.example">Example</a>
224        </h6>
225<p>
226          The following example shows simple use cases of the <code class="computeroutput"><span class="identifier">distinct</span></code>
227          parser. <a href="../../../../../example/qi/distinct.cpp" target="_top">distinct.cpp</a>)
228        </p>
229<h6>
230<a name="spirit_repository.qi_components.directives.distinct.h6"></a>
231          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.prerequisites"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.prerequisites">Prerequisites</a>
232        </h6>
233<p>
234          In addition to the main header file needed to include the core components
235          implemented in <span class="emphasis"><em>Spirit.Qi</em></span> we add the header file needed
236          for the new <code class="computeroutput"><span class="identifier">distinct</span></code> generator.
237        </p>
238<p>
239</p>
240<pre class="programlisting"><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</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
241<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">repository</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_distinct</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
242</pre>
243<p>
244        </p>
245<p>
246          To make all the code below more readable we introduce the following namespaces.
247        </p>
248<p>
249</p>
250<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">;</span>
251<span class="keyword">using</span> <span class="keyword">namespace</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>
252<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">distinct</span><span class="special">;</span>
253</pre>
254<p>
255        </p>
256<h6>
257<a name="spirit_repository.qi_components.directives.distinct.h7"></a>
258          <span class="phrase"><a name="spirit_repository.qi_components.directives.distinct.using_the_distinct_directive_to_match_keywords"></a></span><a class="link" href="distinct.html#spirit_repository.qi_components.directives.distinct.using_the_distinct_directive_to_match_keywords">Using
259          The Distinct Directive to Match keywords</a>
260        </h6>
261<p>
262          We show several examples of how the <code class="computeroutput"><span class="identifier">distinct</span><span class="special">[]</span></code> directive can be used to force correct
263          behavior while matching keywords. The first two code snippets show the
264          correct matching of the <code class="computeroutput"><span class="identifier">description</span></code>
265          keyword (in this hypothetical example we allow keywords to be directly
266          followed by an optional <code class="computeroutput"><span class="string">"--"</span></code>):
267        </p>
268<p>
269</p>
270<pre class="programlisting"><span class="special">{</span>
271    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">(</span><span class="string">"description ident"</span><span class="special">);</span>
272    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">iterator</span> <span class="identifier">first</span><span class="special">(</span><span class="identifier">str</span><span class="special">.</span><span class="identifier">begin</span><span class="special">());</span>
273    <span class="keyword">bool</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span>
274      <span class="special">,</span> <span class="identifier">distinct</span><span class="special">(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)[</span><span class="string">"description"</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">"--"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">+(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)</span>
275      <span class="special">,</span> <span class="identifier">space</span><span class="special">);</span>
276    <span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">r</span> <span class="special">&amp;&amp;</span> <span class="identifier">first</span> <span class="special">==</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
277<span class="special">}</span>
278</pre>
279<p>
280        </p>
281<p>
282</p>
283<pre class="programlisting"><span class="special">{</span>
284    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">(</span><span class="string">"description--ident"</span><span class="special">);</span>
285    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">iterator</span> <span class="identifier">first</span><span class="special">(</span><span class="identifier">str</span><span class="special">.</span><span class="identifier">begin</span><span class="special">());</span>
286    <span class="keyword">bool</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span>
287      <span class="special">,</span> <span class="identifier">distinct</span><span class="special">(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)[</span><span class="string">"description"</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">"--"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">+(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)</span>
288      <span class="special">,</span> <span class="identifier">space</span><span class="special">);</span>
289    <span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">r</span> <span class="special">&amp;&amp;</span> <span class="identifier">first</span> <span class="special">==</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
290<span class="special">}</span>
291</pre>
292<p>
293        </p>
294<p>
295          The last example shows that the <code class="computeroutput"><span class="identifier">distinct</span><span class="special">[]</span></code> parser component correctly refuses to
296          match "description-ident":
297        </p>
298<p>
299</p>
300<pre class="programlisting"><span class="special">{</span>
301    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">(</span><span class="string">"description-ident"</span><span class="special">);</span>
302    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">iterator</span> <span class="identifier">first</span><span class="special">(</span><span class="identifier">str</span><span class="special">.</span><span class="identifier">begin</span><span class="special">());</span>
303    <span class="keyword">bool</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">qi</span><span class="special">::</span><span class="identifier">phrase_parse</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span>
304      <span class="special">,</span> <span class="identifier">distinct</span><span class="special">(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)[</span><span class="string">"description"</span><span class="special">]</span> <span class="special">&gt;&gt;</span> <span class="special">-</span><span class="identifier">lit</span><span class="special">(</span><span class="string">"--"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="special">+(</span><span class="identifier">alnum</span> <span class="special">|</span> <span class="char">'_'</span><span class="special">)</span>
305      <span class="special">,</span> <span class="identifier">space</span><span class="special">);</span>
306    <span class="identifier">BOOST_ASSERT</span><span class="special">(!</span><span class="identifier">r</span> <span class="special">&amp;&amp;</span> <span class="identifier">first</span> <span class="special">==</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">begin</span><span class="special">());</span>
307<span class="special">}</span>
308</pre>
309<p>
310        </p>
311</div>
312<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
313<td align="left"></td>
314<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
315        Distributed under the Boost Software License, Version 1.0. (See accompanying
316        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>)
317      </p>
318</div></td>
319</tr></table>
320<hr>
321<div class="spirit-nav">
322<a accesskey="p" href="confix.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directives.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="kwd.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
323</div>
324</body>
325</html>
326