Notation

Grammar

The following notations are used by the Lexer and Syntax grammar snippets:

NotationExamplesMeaning
CAPITALIDENTIFIER, INTEGER_LITERALA token produced by the lexer
ItalicCamelCaseLetStatement, ItemA syntactical production
stringx, while, *The exact character(s)
x?mut?An optional item
x*OuterAttribute*0 or more of x
x+Statement+1 or more of x
xa..bHEX_DIGIT1..6a to b repetitions of x
Rule1 Rule2fn Name ParametersSequence of rules in order
|i32 | u32, Block | ItemAlternation (matches one of the alternatives)
[ ][b B]Any of the characters listed
[ - ][a-z]Any of the characters in the range
~[ ]~[b B]Any characters, except those listed
~string~\n, ~*/Any characters, except this sequence
( )(, Parameter)?Groups items
U+xxxxU+0060A single Unicode character
<text><any ASCII char except CR>An English description of what should be matched
Rule suffixIDENTIFIER_OR_KEYWORD except crateA modification to the previous rule

Sequencing has higher precedence than | alternation.

String-table productions

String-table productions

Certain rules, including unary operators, binary operators, and keywords, are defined as tables of literal strings. In syntax productions, literal string references implicitly match the corresponding token produced by lexical analysis. See Tokens.

Grammar visualizations

Grammar productions appear in the chapters that define them. Lexer rules use uppercase names; syntax rules use mixed-case names. The button below each grammar block shows its syntax diagram, where rectangles represent nonterminals and rounded rectangles represent terminals.

Common productions

The following are common definitions used in the grammar.

Lexer
CHAR → <a 7-bit ASCII source character>

SPACE → U+0020

TAB → U+0009

LF → U+000A

CR → U+000D

CHAR a 7-bit ASCII source character
SPACE U+0020
TAB U+0009
LF U+000A
CR U+000D