Parsing Expression Grammar notation
Parsing Expression Grammars are described informally in ยง2 of Ford 2004.
The notation used in this document is the variant used by the Pest Rust library, so that it's easy to keep in sync with the comparable implementation.
In particular:
- the sequencing operator is written explicitly, as
~
- the ordered choice operator is
|
?
,*
, and+
have their usual senses (as expression suffixes){0, 255}
is a repetition suffix, meaning "from 0 to 255 repetitions"- the not-predicate (for negative lookahead) is
!
(as an expression prefix) - a terminal matching an individual character is written like
"x"
- a terminal matching a sequence of characters is written like
"abc"
- a terminal matching a range of characters is written like
'0'..'9'
"\""
matches a single " character"\\"
matches a single \ character"\n"
matches a single LF character
The ordered choice operator |
has the lowest precedence, so
a ~ b | c ~ d
is equivalent to
( a ~ b ) | ( c ~ d )
The sequencing operator ~
has the next-lowest precedence, so
!"." ~ SOMETHING
is equivalent to
(!".") ~ SOMETHING
"Any character except" is written using the not-predicate and ANY
, for example
( !"'" ~ ANY )
matches any single character except '.
See Grammar for raw string literals for a discussion of extensions used to model raw string literals.