Certain overloaded operators are defined for all parsers in Boost.Parser.
We've already seen some of them used in this tutorial, especially operator>>,
operator|,
and operator||,
which are used to form sequence parsers, alternative parsers, and permutation
parsers, respectively.
Here are all the operator overloaded for parsers. In the tables below:
c is a character of type
char or char32_t;
a is a semantic action;
r is an object whose
type models parsable_range
(see Concepts); and
p, p1,
p2, ... are parsers.
![]() |
Note |
|---|---|
Some of the expressions in this table consume no input. All parsers consume the input they match unless otherwise stated in the table below. |
Table 1.7. Combining Operations and Their Semantics
|
Expression |
Semantics |
Attribute Type |
Notes |
|---|---|---|---|
|
|
Matches iff |
None. |
|
|
|
Matches iff |
None. |
|
|
|
Parses using |
|
Matching |
|
|
Parses using |
|
Matching |
|
|
Equivalent to |
|
|
|
|
Matches iff |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Matches iff |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Matches iff either |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Matches iff |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Equivalent to |
|
|
|
|
Matches iff |
None. |
![]() |
Important |
|---|---|
All the character parsers, like |
There are a couple of special rules not captured in the table above:
First, the zero-or-more and one-or-more repetitions (operator*() and operator+(), respectively) may collapse when combined.
For any parser p, +(+p)
collapses to +p;
**p,
*+p,
and +*p
each collapse to just *p.
Second, using eps
in an alternative parser as any alternative except
the last one is a common source of errors; Boost.Parser disallows it. This
is true because, for any parser p,
eps
| p
is equivalent to eps,
since eps
always matches. This is not true for eps parameterized with a condition.
For any condition cond,
eps(cond)
is allowed to appear anywhere within an alternative parser.
![]() |
Note |
|---|---|
When looking at Boost.Parser parsers in a debugger, or when looking at
their reference documentation, you may see reference to the template |