3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
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.78.1">
7 <link rel="home" href="../../../../index.html" title="Spirit 2.5.2">
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[])">
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>
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>
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>
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>
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
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>
43 <pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/directive/matches.hpp></span>
44 <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_matches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
47 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
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>
53 <div class="informaltable"><table class="table">
54 <colgroup><col></colgroup>
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>
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
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>
80 A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>.
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
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>.
93 <div class="informaltable"><table class="table">
113 <code class="computeroutput"><span class="identifier">matches</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
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.
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>
129 <div class="informaltable"><table class="table">
149 <code class="computeroutput"><span class="identifier">matches</span><span class="special">[</span><span class="identifier">a</span><span class="special">]</span></code>
154 <code class="computeroutput"><span class="keyword">bool</span></code>
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>
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>
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>
171 <div class="note"><table border="0" summary="Note">
173 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
174 <th align="left">Note</th>
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>
182 Some using declarations:
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>
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:
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"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special"><<</span> <span class="identifier">result</span> <span class="special"><<</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>
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:
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"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special"><<</span> <span class="identifier">result</span> <span class="special"><<</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>
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>)
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>