Notation
Grammar
The following notations are used by the Lexer and Syntax grammar snippets:
| Notation | Examples | Meaning |
|---|---|---|
| CAPITAL | IDENTIFIER, INTEGER_LITERAL | A token produced by the lexer |
| ItalicCamelCase | LetStatement, Item | A syntactical production |
string | x, 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..b | HEX_DIGIT1..6 | a to b repetitions of x |
| Rule1 Rule2 | fn Name Parameters | Sequence of rules in order |
| | | i32 | u32, Block | Item | Alternation (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+xxxx | U+0060 | A single Unicode character |
| <text> | <any ASCII char except CR> | An English description of what should be matched |
| Rule suffix | IDENTIFIER_OR_KEYWORD except crate | A 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.