...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Here are all the tables containing the various Boost.Parser parsers, examples, etc., all in one place. These are repeated elsewhere in different sections of the tutorial.
This table lists all the Boost.Parser parsers. For the callable parsers, a
separate entry exists for each possible arity of arguments. For a parser p
, if there is no entry for p
without arguments, p
is a function, and cannot itself be used as a parser; it must be called. In
the table below:
char
");
RESOLVE
()
is a notional macro that expands to the resolution of parse argument or
evaluation of a parse predicate (see The
Parsers And Their Uses);
RESOLVE
(pred) == true
"
is a shorthand notation for "RESOLVE
(pred)
is contextually convertible to bool
and true
";
likewise for false
;
c
is a character of type
char
, char8_t
,
or char32_t
;
str
is a string literal
of type char const[]
, char8_t
const []
,
or char32_t const
[]
;
pred
is a parse predicate;
arg0
, arg1
,
arg2
, ... are parse arguments;
a
is a semantic action;
r
is an object whose type
models parsable_range
;
p
, p1
,
p2
, ... are parsers; and
escapes
is a symbols<T>
object, where T
is char
or char32_t
.
![]() |
Note |
---|---|
The definition of
template<typename T> concept parsable_range = std::ranges::forward_range<T> && code_unit<std::ranges::range_value_t<T>>;
|
![]() |
Note |
---|---|
Some of the parsers in this table consume no input. All parsers consume the input they match unless otherwise stated in the table below. |
Table 26.1. Parsers and Their Semantics
Parser |
Semantics |
Attribute Type |
Notes |
---|---|---|---|
Matches epsilon, the empty string. Always matches, and consumes no input. |
None. |
Matching |
|
|
Fails to match the input if |
None. |
|
Matches a single whitespace code point (see note), according to the Unicode White_Space property. |
None. |
For more info, see the Unicode
properties. |
|
Matches a single newline (see note), following the "hard" line breaks in the Unicode line breaking algorithm. |
None. |
For more info, see the Unicode
Line Breaking Algorithm. |
|
Matches only at the end of input, and consumes no input. |
None. |
||
|
Always matches, and consumes no input. Generates the attribute |
|
An important use case for |
Matches any single code point. |
The code point type in Unicode parsing, or |
||
|
Matches exactly the code point |
The code point type in Unicode parsing, or |
|
|
Matches the next code point |
The code point type in Unicode parsing, or |
|
|
Matches the next code point |
The code point type in Unicode parsing, or |
|
Matches a single code point. |
|
Similar to |
|
Matches a single code point. |
|
Similar to |
|
The code point type in Unicode parsing, or |
|||
Matches a single control-character code point. |
The code point type in Unicode parsing, or |
||
Matches a single decimal digit code point. |
The code point type in Unicode parsing, or |
||
Matches a single punctuation code point. |
The code point type in Unicode parsing, or |
||
Matches a single hexidecimal digit code point. |
The code point type in Unicode parsing, or |
||
Matches a single lower-case code point. |
The code point type in Unicode parsing, or |
||
Matches a single upper-case code point. |
The code point type in Unicode parsing, or |
||
|
Matches exactly the given code point |
None. |
|
|
Matches exactly the given code point |
None. |
|
|
Matches exactly the given string |
None. |
|
|
Matches exactly the given string |
None. |
This is a UDL
that represents |
|
Matches exactly |
|
|
|
Matches exactly |
|
This is a UDL
that represents |
Matches |
|
||
Matches a binary unsigned integral value. |
|
For example, |
|
|
Matches exactly the binary unsigned integral value |
|
|
Matches an octal unsigned integral value. |
|
For example, |
|
|
Matches exactly the octal unsigned integral value |
|
|
Matches a hexadecimal unsigned integral value. |
|
For example, |
|
|
Matches exactly the hexadecimal unsigned integral value |
|
|
Matches an unsigned integral value. |
|
||
|
Matches exactly the unsigned integral value |
|
|
Matches an unsigned integral value. |
|
||
|
Matches exactly the unsigned integral value |
|
|
Matches an unsigned integral value. |
|
||
|
Matches exactly the unsigned integral value |
|
|
Matches an unsigned integral value. |
|
||
|
Matches exactly the unsigned integral value |
|
|
Matches a signed integral value. |
|
||
|
Matches exactly the signed integral value |
|
|
Matches a signed integral value. |
|
||
|
Matches exactly the signed integral value |
|
|
Matches a signed integral value. |
|
||
|
Matches exactly the signed integral value |
|
|
Matches a signed integral value. |
|
||
|
Matches exactly the signed integral value |
|
|
Matches a floating-point number. |
|
||
Matches a floating-point number. |
|
||
|
Matches iff |
|
The special value |
|
Matches iff |
|
The special value |
|
Equivalent to |
|
It is an error to write |
|
Equivalent to |
|
It is an error to write |
|
|
Unlike the other entries in this table, |
|
Matches |
|
The result does not include the quotes. A quote within the string
can be written by escaping it with a backslash. A backslash within
the string can be written by writing two consecutive backslashes.
Any other use of a backslash will fail the parse. Skipping is disabled
while parsing the entire string, as if using |
|
Matches |
|
The result does not include the |
|
Matches some character |
|
The result does not include the |
|
|
Matches |
|
The result does not include the |
|
Matches some character |
|
The result does not include the |
![]() |
Important |
---|---|
All the character parsers, like |
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 26.2. 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.
This table summarizes the attributes generated for all Boost.Parser parsers. In the table below:
RESOLVE
()
is a notional macro that expands to the resolution of parse argument or
evaluation of a parse predicate (see The
Parsers And Their Uses); and
x
and y
represent arbitrary objects.
Table 26.3. Parsers and Their Attributes
Parser |
Attribute Type |
Notes |
---|---|---|
None. |
||
None. |
||
None. |
||
|
|
|
The code point type in Unicode parsing, or |
Includes all the |
|
|
||
|
||
|
None. |
Includes all the |
|
|
Includes all the |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
char_
is a bit odd, since its attribute type is polymorphic. When you use char_
to parse text in the non-Unicode code path (i.e. a string of char
), the attribute is char
.
When you use the exact same char_
to parse in the Unicode-aware
code path, all matching is code point based, and so the attribute type is the
type used to represent code points, char32_t
.
All parsing of UTF-8 falls under this case.
Here, we're parsing plain char
s,
meaning that the parsing is in the non-Unicode code path, the attribute of
char_
is char
:
auto result = parse("some text", boost::parser::char_); static_assert(std::is_same_v<decltype(result), std::optional<char>>));
When you parse UTF-8, the matching is done on a code point basis, so the attribute
type is char32_t
:
auto result = parse("some text" | boost::parser::as_utf8, boost::parser::char_); static_assert(std::is_same_v<decltype(result), std::optional<char32_t>>));
The good news is that usually you don't parse characters individually. When
you parse with char_
,
you usually parse repetition of then, which will produce a std::string
,
regardless of whether you're in Unicode parsing mode or not. If you do need
to parse individual characters, and want to lock down their attribute type,
you can use cp
and/or cu
to enforce a non-polymorphic attribute type.
Combining operations of course affect the generation of attributes. In the tables below:
m
and n
are parse arguments that resolve to integral values;
pred
is a parse predicate;
arg0
, arg1
,
arg2
, ... are parse arguments;
a
is a semantic action;
and
p
, p1
,
p2
, ... are parsers that
generate attributes.
Table 26.4. Combining Operations and Their Attributes
Parser |
Attribute Type |
---|---|
|
None. |
|
None. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
None. |
|
|
|
|
|
|
|
|
![]() |
Important |
---|---|
All the character parsers, like |
![]() |
Important |
---|---|
In case you did not notice it above, adding a semantic action to a parser
erases the parser's attribute. The attribute is still available inside the
semantic action as |
In the table: a
is a semantic
action; and p
, p1
, p2
,
... are parsers that generate attributes. Note that only >>
is used here; >
has the exact
same attribute generation rules.
Table 26.5. Sequence and Alternative Combining Operations and Their Attributes
Expression |
Attribute Type |
---|---|
None. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
None. |
|
|
|
|
|
|
|
|
|
|