• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Difference Parser (a - b)</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="../operator.html" title="Parser Operators">
9<link rel="prev" href="and_predicate.html" title="And-Predicate Parser (&amp;a)">
10<link rel="next" href="expect.html" title="Expectation Operator (a &gt; b)">
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="and_predicate.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="expect.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.operator.difference"></a><a class="link" href="difference.html" title="Difference Parser (a - b)">Difference
28          Parser (<code class="computeroutput"><span class="identifier">a</span> <span class="special">-</span>
29          <span class="identifier">b</span></code>)</a>
30</h5></div></div></div>
31<h6>
32<a name="spirit.qi.reference.operator.difference.h0"></a>
33            <span class="phrase"><a name="spirit.qi.reference.operator.difference.description"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.description">Description</a>
34          </h6>
35<p>
36            The difference operator, <code class="computeroutput"><span class="identifier">a</span>
37            <span class="special">-</span> <span class="identifier">b</span></code>,
38            is a binary operator that matches the first (LHS) operand but not the
39            second (RHS). <a href="#ftn.spirit.qi.reference.operator.difference.f0" class="footnote" name="spirit.qi.reference.operator.difference.f0"><sup class="footnote">[8]</sup></a>
40          </p>
41<h6>
42<a name="spirit.qi.reference.operator.difference.h1"></a>
43            <span class="phrase"><a name="spirit.qi.reference.operator.difference.header"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.header">Header</a>
44          </h6>
45<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/operator/difference.hpp&gt;</span>
46<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_difference</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
47</pre>
48<p>
49            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
50          </p>
51<h6>
52<a name="spirit.qi.reference.operator.difference.h2"></a>
53            <span class="phrase"><a name="spirit.qi.reference.operator.difference.model_of"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.model_of">Model of</a>
54          </h6>
55<div class="blockquote"><blockquote class="blockquote"><p>
56              <a class="link" href="../parser_concepts/binaryparser.html" title="BinaryParser"><code class="computeroutput"><span class="identifier">BinaryParser</span></code></a>
57            </p></blockquote></div>
58<div class="variablelist">
59<p class="title"><b>Notation</b></p>
60<dl class="variablelist">
61<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code>, <code class="computeroutput"><span class="identifier">b</span></code></span></dt>
62<dd><p>
63                  A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a>
64                </p></dd>
65</dl>
66</div>
67<h6>
68<a name="spirit.qi.reference.operator.difference.h3"></a>
69            <span class="phrase"><a name="spirit.qi.reference.operator.difference.expression_semantics"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.expression_semantics">Expression
70            Semantics</a>
71          </h6>
72<p>
73            Semantics of an expression is defined only where it differs from, or
74            is not defined in <a class="link" href="../parser_concepts/binaryparser.html" title="BinaryParser"><code class="computeroutput"><span class="identifier">BinaryParser</span></code></a>.
75          </p>
76<div class="informaltable"><table class="table">
77<colgroup>
78<col>
79<col>
80</colgroup>
81<thead><tr>
82<th>
83                    <p>
84                      Expression
85                    </p>
86                  </th>
87<th>
88                    <p>
89                      Semantics
90                    </p>
91                  </th>
92</tr></thead>
93<tbody><tr>
94<td>
95                    <p>
96                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">-</span>
97                      <span class="identifier">b</span></code>
98                    </p>
99                  </td>
100<td>
101                    <p>
102                      Parse <code class="computeroutput"><span class="identifier">a</span></code> but
103                      not <code class="computeroutput"><span class="identifier">b</span></code>.
104                    </p>
105                  </td>
106</tr></tbody>
107</table></div>
108<h6>
109<a name="spirit.qi.reference.operator.difference.h4"></a>
110            <span class="phrase"><a name="spirit.qi.reference.operator.difference.attributes"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.attributes">Attributes</a>
111          </h6>
112<p>
113            See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.qi.quick_reference.compound_attribute_rules.notation">Compound
114            Attribute Notation</a>.
115          </p>
116<div class="informaltable"><table class="table">
117<colgroup>
118<col>
119<col>
120</colgroup>
121<thead><tr>
122<th>
123                    <p>
124                      Expression
125                    </p>
126                  </th>
127<th>
128                    <p>
129                      Attribute
130                    </p>
131                  </th>
132</tr></thead>
133<tbody><tr>
134<td>
135                    <p>
136                      <code class="computeroutput"><span class="identifier">a</span> <span class="special">-</span>
137                      <span class="identifier">b</span></code>
138                    </p>
139                  </td>
140<td>
141                    <p>
142</p>
143<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-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="special">(</span><span class="identifier">a</span> <span class="special">-</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">A</span>
144<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</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="special">(</span><span class="identifier">a</span> <span class="special">-</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">Unused</span></pre>
145<p>
146                    </p>
147                  </td>
148</tr></tbody>
149</table></div>
150<h6>
151<a name="spirit.qi.reference.operator.difference.h5"></a>
152            <span class="phrase"><a name="spirit.qi.reference.operator.difference.complexity"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.complexity">Complexity</a>
153          </h6>
154<div class="blockquote"><blockquote class="blockquote"><p>
155              The complexity of the difference parser is defined by the sum of the
156              complexities of both operands.
157            </p></blockquote></div>
158<h6>
159<a name="spirit.qi.reference.operator.difference.h6"></a>
160            <span class="phrase"><a name="spirit.qi.reference.operator.difference.example"></a></span><a class="link" href="difference.html#spirit.qi.reference.operator.difference.example">Example</a>
161          </h6>
162<div class="note"><table border="0" summary="Note">
163<tr>
164<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
165<th align="left">Note</th>
166</tr>
167<tr><td align="left" valign="top"><p>
168              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>
169              section.
170            </p></td></tr>
171</table></div>
172<p>
173            Some using declarations:
174          </p>
175<p>
176</p>
177<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">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span>
178</pre>
179<p>
180          </p>
181<p>
182            Parse a C/C++ style comment:
183          </p>
184<p>
185</p>
186<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"/*A Comment*/"</span><span class="special">,</span> <span class="string">"/*"</span> <span class="special">&gt;&gt;</span> <span class="special">*(</span><span class="identifier">char_</span> <span class="special">-</span> <span class="string">"*/"</span><span class="special">)</span> <span class="special">&gt;&gt;</span> <span class="string">"*/"</span><span class="special">);</span>
187</pre>
188<p>
189          </p>
190<div class="footnotes">
191<br><hr style="width:100; text-align:left;margin-left: 0">
192<div id="ftn.spirit.qi.reference.operator.difference.f0" class="footnote"><p><a href="#spirit.qi.reference.operator.difference.f0" class="para"><sup class="para">[8] </sup></a>
193              Unlike classic Spirit, with Spirit2, the expression will always fail
194              if the RHS is a successful match regardless if the RHS matches less
195              characters. For example, the rule <code class="computeroutput"><span class="identifier">lit</span><span class="special">(</span><span class="string">"policeman"</span><span class="special">)</span> <span class="special">-</span> <span class="string">"police"</span></code> will always fail to
196              match. Spirit2 does not count the matching chars while parsing and
197              there is no reliable and fast way to check if the LHS matches more
198              than the RHS.
199            </p></div>
200</div>
201</div>
202<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
203<td align="left"></td>
204<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
205        Distributed under the Boost Software License, Version 1.0. (See accompanying
206        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>)
207      </p>
208</div></td>
209</tr></table>
210<hr>
211<div class="spirit-nav">
212<a accesskey="p" href="and_predicate.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.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="expect.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
213</div>
214</body>
215</html>
216