Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
Difference Parser (a - b)
Description

The difference operator, a - b, is a binary operator that matches the first (LHS) operand but not the second (RHS). [8]

Header
// forwards to <boost/spirit/home/qi/operator/difference.hpp>
#include <boost/spirit/include/qi_difference.hpp>

Also, see Include Structure.

Model of

BinaryParser

Notation

a, b

A Parser

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in BinaryParser.

Expression

Semantics

a - b

Parse a but not b.

Attributes

See Compound Attribute Notation.

Expression

Attribute

a - b

a: A, b: B --> (a - b): A
a: Unused, b: B --> (a - b): Unused

Complexity

The complexity of the difference parser is defined by the sum of the complexities of both operands.

Example
[Note] Note

The test harness for the example(s) below is presented in the Basics Examples section.

Some using declarations:

using boost::spirit::ascii::char_;

Parse a C/C++ style comment:

test_parser("/*A Comment*/", "/*" >> *(char_ - "*/") >> "*/");



[8] Unlike classic Spirit, with Spirit2, the expression will always fail if the RHS is a successful match regardless if the RHS matches less characters. For example, the rule lit("policeman") - "police" will always fail to match. Spirit2 does not count the matching chars while parsing and there is no reliable and fast way to check if the LHS matches more than the RHS.


PrevUpHomeNext