• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Directive Testing if Parser Succeeded (matches[])</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="../directive.html" title="Parser Directives">
9<link rel="prev" href="repeat.html" title="Repetition Parser Directive (repeat[])">
10<link rel="next" href="skip.html" title="Parser Directive Re-Establishing Skipping (skip[])">
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="repeat.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.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="skip.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.directive.matches"></a><a class="link" href="matches.html" title="Directive Testing if Parser Succeeded (matches[])">Directive
28          Testing if Parser Succeeded (<code class="computeroutput"><span class="identifier">matches</span><span class="special">[]</span></code>)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.qi.reference.directive.matches.h0"></a>
32            <span class="phrase"><a name="spirit.qi.reference.directive.matches.description"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.description">Description</a>
33          </h6>
34<p>
35            The <code class="computeroutput"><span class="identifier">matches</span><span class="special">[]</span></code>
36            directive executes the embedded parser and returns whether it succeeded
37            matching.
38          </p>
39<h6>
40<a name="spirit.qi.reference.directive.matches.h1"></a>
41            <span class="phrase"><a name="spirit.qi.reference.directive.matches.header"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.header">Header</a>
42          </h6>
43<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/directive/matches.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_matches</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.directive.matches.h2"></a>
51            <span class="phrase"><a name="spirit.qi.reference.directive.matches.namespace"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.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">matches</span> <span class="comment">//
63                      alias: boost::spirit::qi::matches</span></code>
64                    </p>
65                  </td></tr></tbody>
66</table></div>
67<h6>
68<a name="spirit.qi.reference.directive.matches.h3"></a>
69            <span class="phrase"><a name="spirit.qi.reference.directive.matches.model_of"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.model_of">Model
70            of</a>
71          </h6>
72<div class="blockquote"><blockquote class="blockquote"><p>
73              <a class="link" href="../parser_concepts/unaryparser.html" title="UnaryParser"><code class="computeroutput"><span class="identifier">UnaryParser</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">a</span></code></span></dt>
79<dd><p>
80                  A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>.
81                </p></dd>
82</dl>
83</div>
84<h6>
85<a name="spirit.qi.reference.directive.matches.h4"></a>
86            <span class="phrase"><a name="spirit.qi.reference.directive.matches.expression_semantics"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.expression_semantics">Expression
87            Semantics</a>
88          </h6>
89<p>
90            Semantics of an expression is defined only where it differs from, or
91            is not defined in <a class="link" href="../parser_concepts/unaryparser.html" title="UnaryParser"><code class="computeroutput"><span class="identifier">UnaryParser</span></code></a>.
92          </p>
93<div class="informaltable"><table class="table">
94<colgroup>
95<col>
96<col>
97</colgroup>
98<thead><tr>
99<th>
100                    <p>
101                      Expression
102                    </p>
103                  </th>
104<th>
105                    <p>
106                      Semantics
107                    </p>
108                  </th>
109</tr></thead>
110<tbody><tr>
111<td>
112                    <p>
113                      <code class="computeroutput"><span class="identifier">matches</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
114                    </p>
115                  </td>
116<td>
117                    <p>
118                      Execute the subject parser <code class="computeroutput"><span class="identifier">a</span></code>,
119                      and return as its attribute whether it succeeded. The directive
120                      itself does always succeed.
121                    </p>
122                  </td>
123</tr></tbody>
124</table></div>
125<h6>
126<a name="spirit.qi.reference.directive.matches.h5"></a>
127            <span class="phrase"><a name="spirit.qi.reference.directive.matches.attributes"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.attributes">Attributes</a>
128          </h6>
129<div class="informaltable"><table class="table">
130<colgroup>
131<col>
132<col>
133</colgroup>
134<thead><tr>
135<th>
136                    <p>
137                      Expression
138                    </p>
139                  </th>
140<th>
141                    <p>
142                      Attribute
143                    </p>
144                  </th>
145</tr></thead>
146<tbody><tr>
147<td>
148                    <p>
149                      <code class="computeroutput"><span class="identifier">matches</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
150                    </p>
151                  </td>
152<td>
153                    <p>
154                      <code class="computeroutput"><span class="keyword">bool</span></code>
155                    </p>
156                  </td>
157</tr></tbody>
158</table></div>
159<h6>
160<a name="spirit.qi.reference.directive.matches.h6"></a>
161            <span class="phrase"><a name="spirit.qi.reference.directive.matches.complexity"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.complexity">Complexity</a>
162          </h6>
163<div class="blockquote"><blockquote class="blockquote"><p>
164              The complexity is defined by the complexity of the subject parser,
165              <code class="computeroutput"><span class="identifier">a</span></code>
166            </p></blockquote></div>
167<h6>
168<a name="spirit.qi.reference.directive.matches.h7"></a>
169            <span class="phrase"><a name="spirit.qi.reference.directive.matches.example"></a></span><a class="link" href="matches.html#spirit.qi.reference.directive.matches.example">Example</a>
170          </h6>
171<div class="note"><table border="0" summary="Note">
172<tr>
173<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
174<th align="left">Note</th>
175</tr>
176<tr><td align="left" valign="top"><p>
177              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>
178              section.
179            </p></td></tr>
180</table></div>
181<p>
182            Some using declarations:
183          </p>
184<p>
185</p>
186<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">matches</span><span class="special">;</span>
187<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">int_</span><span class="special">;</span>
188</pre>
189<p>
190          </p>
191<p>
192            This parser tries to match an <code class="computeroutput"><span class="keyword">int</span></code>
193            and returns <code class="computeroutput"><span class="keyword">true</span></code> a its attribute
194            as it succeeded matching:
195          </p>
196<p>
197</p>
198<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">result</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
199<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"345"</span><span class="special">,</span> <span class="identifier">matches</span><span class="special">[</span><span class="identifier">int_</span><span class="special">],</span> <span class="identifier">result</span><span class="special">);</span>
200<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">result</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// should print: true</span>
201</pre>
202<p>
203          </p>
204<p>
205            This parser tries to match an <code class="computeroutput"><span class="keyword">int</span></code>
206            as well and returns <code class="computeroutput"><span class="keyword">false</span></code>
207            as its attribute as it fails matching:
208          </p>
209<p>
210</p>
211<pre class="programlisting"><span class="identifier">result</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
212<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"abc"</span><span class="special">,</span> <span class="identifier">matches</span><span class="special">[</span><span class="identifier">int_</span><span class="special">],</span> <span class="identifier">result</span><span class="special">);</span>
213<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">result</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// should print: false</span>
214</pre>
215<p>
216          </p>
217</div>
218<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
219<td align="left"></td>
220<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
221        Distributed under the Boost Software License, Version 1.0. (See accompanying
222        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>)
223      </p>
224</div></td>
225</tr></table>
226<hr>
227<div class="spirit-nav">
228<a accesskey="p" href="repeat.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../directive.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="skip.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
229</div>
230</body>
231</html>
232