diff --git a/src/attributes.md b/src/attributes.md index d6cbed613..887d184c9 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -116,9 +116,10 @@ attributes]. It has the following grammar: r[attributes.meta.syntax] ```grammar,attributes MetaItem -> - SimplePath - | SimplePath `=` Expression - | SimplePath `(` MetaSeq? `)` + SimplePath ( + `=` Expression + | `(` MetaSeq? `)` + )? MetaSeq -> MetaItemInner ( `,` MetaItemInner )* `,`? diff --git a/src/comments.md b/src/comments.md index 8ffa56551..c77e8b1d4 100644 --- a/src/comments.md +++ b/src/comments.md @@ -4,8 +4,7 @@ r[comments] r[comments.syntax] ```grammar,lexer @root LINE_COMMENT -> - `//` (~[`/` `!` LF] | `//`) ~LF* - | `//` + `//` ( ( ~[`/` `!` LF] | `//` ) ~LF* )? BLOCK_COMMENT -> `/*` diff --git a/src/expressions/array-expr.md b/src/expressions/array-expr.md index 04374f3f3..622505f1a 100644 --- a/src/expressions/array-expr.md +++ b/src/expressions/array-expr.md @@ -8,8 +8,10 @@ r[expr.array.syntax] ArrayExpression -> `[` ArrayElements? `]` ArrayElements -> - Expression ( `,` Expression )* `,`? - | Expression `;` Expression + Expression ( + ( `,` Expression )* `,`? + | `;` Expression + ) ``` r[expr.array.constructor] diff --git a/src/expressions/block-expr.md b/src/expressions/block-expr.md index da0f93b36..489d177c7 100644 --- a/src/expressions/block-expr.md +++ b/src/expressions/block-expr.md @@ -10,8 +10,7 @@ BlockExpression -> `}` Statements -> - Statement+ - | Statement+ ExpressionWithoutBlock + Statement+ ExpressionWithoutBlock? | ExpressionWithoutBlock ``` diff --git a/src/expressions/operator-expr.md b/src/expressions/operator-expr.md index 5151bd2c6..88d714918 100644 --- a/src/expressions/operator-expr.md +++ b/src/expressions/operator-expr.md @@ -58,10 +58,9 @@ r[expr.operator.borrow] r[expr.operator.borrow.syntax] ```grammar,expressions BorrowExpression -> - (`&`|`&&`) Expression - | (`&`|`&&`) `mut` Expression - | (`&`|`&&`) `raw` `const` Expression - | (`&`|`&&`) `raw` `mut` Expression + ( `&` | `&&` ) + ( `mut` | `raw` ( `const` | `mut` ) )? + Expression ``` r[expr.operator.borrow.intro] @@ -257,8 +256,7 @@ r[expr.negate] r[expr.negate.syntax] ```grammar,expressions NegationExpression -> - `-` Expression - | `!` Expression + ( `-` | `!`) Expression ``` r[expr.negate.intro] @@ -291,16 +289,9 @@ r[expr.arith-logic] r[expr.arith-logic.syntax] ```grammar,expressions ArithmeticOrLogicalExpression -> - Expression `+` Expression - | Expression `-` Expression - | Expression `*` Expression - | Expression `/` Expression - | Expression `%` Expression - | Expression `&` Expression - | Expression `|` Expression - | Expression `^` Expression - | Expression `<<` Expression - | Expression `>>` Expression + Expression ( + `+` | `-` | `*` | `/` | `%` | `&` | `|` | `^` | `<<` | `>>` + ) Expression ``` r[expr.arith-logic.intro] @@ -354,12 +345,9 @@ r[expr.cmp] r[expr.cmp.syntax] ```grammar,expressions ComparisonExpression -> - Expression `==` Expression - | Expression `!=` Expression - | Expression `>` Expression - | Expression `<` Expression - | Expression `>=` Expression - | Expression `<=` Expression + Expression ( + `==` | `!=` | `>` | `<` | `>=` | `<=` + ) Expression ``` r[expr.cmp.intro] @@ -413,8 +401,7 @@ r[expr.bool-logic] r[expr.bool-logic.syntax] ```grammar,expressions LazyBooleanExpression -> - Expression `||` Expression - | Expression `&&` Expression + Expression (`||` | `&&`) Expression ``` r[expr.bool-logic.intro] @@ -809,16 +796,11 @@ r[expr.compound-assign] r[expr.compound-assign.syntax] ```grammar,expressions CompoundAssignmentExpression -> - Expression `+=` Expression - | Expression `-=` Expression - | Expression `*=` Expression - | Expression `/=` Expression - | Expression `%=` Expression - | Expression `&=` Expression - | Expression `|=` Expression - | Expression `^=` Expression - | Expression `<<=` Expression - | Expression `>>=` Expression + Expression ( + `+=` | `-=` | `*=` | `/=` | `%=` + | `&=` | `|=` | `^=` + | `<<=` | `>>=` + ) Expression ``` r[expr.compound-assign.intro] diff --git a/src/inline-assembly.md b/src/inline-assembly.md index f1d19974b..33a8bfcce 100644 --- a/src/inline-assembly.md +++ b/src/inline-assembly.md @@ -73,20 +73,21 @@ AsmOption -> | `att_syntax` | `raw` -RegOperand -> (ParamName `=`)? - ( - DirSpec `(` RegSpec `)` Expression - | DualDirSpec `(` RegSpec `)` DualDirSpecExpression - | `sym` PathExpression - | `const` Expression - | `label` `{` Statements? `}` +RegOperand -> + (ParamName `=`)? ( + ( + DirSpec `(` RegSpec `)` + | `const` + ) Expression + | DualDirSpec `(` RegSpec `)` DualDirSpecExpression + | `sym` PathExpression + | `label` `{` Statements? `}` ) ParamName -> IDENTIFIER_OR_KEYWORD | RAW_IDENTIFIER DualDirSpecExpression -> - Expression - | Expression `=>` Expression + Expression ( `=>` Expression )? RegSpec -> RegisterClass | ExplicitRegister diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index 0053969a1..4bd9e0150 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -11,9 +11,8 @@ ExternBlock -> ExternalItem -> OuterAttribute* ( - MacroInvocationSemi - | Visibility? StaticItem - | Visibility? Function + Visibility? ( StaticItem | Function ) + | MacroInvocationSemi ) ``` diff --git a/src/items/functions.md b/src/items/functions.md index 806cacf04..873e2a2a2 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -16,15 +16,17 @@ ItemSafety -> `safe`[^extern-safe] | `unsafe` Abi -> STRING_LITERAL | RAW_STRING_LITERAL FunctionParameters -> - SelfParam `,`? - | (SelfParam `,`)? FunctionParam (`,` FunctionParam)* `,`? + SelfParam ( `,` FunctionParams? )? + | FunctionParams SelfParam -> OuterAttribute* ( ShorthandSelf | TypedSelf ) -ShorthandSelf -> (`&` | `&` Lifetime)? `mut`? `self` +ShorthandSelf -> ( `&` Lifetime? )? `mut`? `self` TypedSelf -> `mut`? `self` `:` Type +FunctionParams -> FunctionParam ( `,` FunctionParam )* `,`? + FunctionParam -> OuterAttribute* ( FunctionParamPattern | `...` | Type[^fn-param-2015] ) FunctionParamPattern -> PatternNoTopAlt `:` ( Type | `...` ) diff --git a/src/items/modules.md b/src/items/modules.md index 295d1d7b5..7d7d1dccb 100644 --- a/src/items/modules.md +++ b/src/items/modules.md @@ -4,11 +4,10 @@ r[items.mod] r[items.mod.syntax] ```grammar,items Module -> - `unsafe`? `mod` IDENTIFIER `;` - | `unsafe`? `mod` IDENTIFIER `{` - InnerAttribute* - Item* - `}` + `unsafe`? `mod` IDENTIFIER ( + `{` InnerAttribute* Item* `}` + | `;` + ) ``` r[items.mod.intro] diff --git a/src/items/use-declarations.md b/src/items/use-declarations.md index ec993d737..c1f5dbb8d 100644 --- a/src/items/use-declarations.md +++ b/src/items/use-declarations.md @@ -6,8 +6,10 @@ r[items.use.syntax] UseDeclaration -> `use` UseTree `;` UseTree -> - (SimplePath? `::`)? `*` - | (SimplePath? `::`)? `{` (UseTree ( `,` UseTree )* `,`?)? `}` + ( SimplePath? `::` )? ( + `{` ( UseTree ( `,` UseTree )* `,`? )? `}` + | `*` + ) | SimplePath ( `as` ( IDENTIFIER | `_` ) )? ``` diff --git a/src/macros-by-example.md b/src/macros-by-example.md index 9bdb93fce..f8c822d4b 100644 --- a/src/macros-by-example.md +++ b/src/macros-by-example.md @@ -7,8 +7,10 @@ MacroRulesDefinition -> `macro_rules` `!` IDENTIFIER MacroRulesDef MacroRulesDef -> - `(` MacroRules `)` `;` - | `[` MacroRules `]` `;` + ( + `(` MacroRules `)` + | `[` MacroRules `]` + ) `;` | `{` MacroRules `}` MacroRules -> @@ -25,8 +27,11 @@ MacroMatcher -> MacroMatch -> Token _except `$` and [delimiters][lex.token.delim]_ | MacroMatcher - | `$` ( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` ) `:` MacroFragSpec - | `$` `(` MacroMatch+ `)` MacroRepSep? MacroRepOp + | `$` ( + ( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` ) + `:` MacroFragSpec + | `(` MacroMatch+ `)` MacroRepSep? MacroRepOp + ) MacroFragSpec -> `block` | `expr` | `expr_2021` | `ident` | `item` | `lifetime` | `literal` diff --git a/src/macros.md b/src/macros.md index 48555fb25..1e2073ee4 100644 --- a/src/macros.md +++ b/src/macros.md @@ -29,9 +29,13 @@ TokenTree -> Token _except [delimiters][lex.token.delim]_ | DelimTokenTree MacroInvocationSemi -> - SimplePath `!` `(` TokenTree* `)` `;` - | SimplePath `!` `[` TokenTree* `]` `;` - | SimplePath `!` `{` TokenTree* `}` + SimplePath `!` ( + ( + `(` TokenTree* `)` + | `[` TokenTree* `]` + ) `;` + | `{` TokenTree* `}` + ) ``` r[macro.invocation.intro] diff --git a/src/paths.md b/src/paths.md index afa5b82ec..e5ef466bc 100644 --- a/src/paths.md +++ b/src/paths.md @@ -54,16 +54,14 @@ PathIdentSegment -> IDENTIFIER | `super` | `self` | `Self` | `crate` | `$crate` GenericArgs -> - `<` `>` - | `<` ( GenericArg `,` )* GenericArg `,`? `>` + `<` ( GenericArg ( `,` GenericArg )* `,`? )? `>` GenericArg -> Lifetime | Type | GenericArgsConst | GenericArgsBinding | GenericArgsBounds GenericArgsConst -> BlockExpression - | LiteralExpression - | `-` LiteralExpression + | `-`? LiteralExpression | SimplePathSegment GenericArgsBinding -> diff --git a/src/patterns.md b/src/patterns.md index 2d9ddb5ac..ef51b974d 100644 --- a/src/patterns.md +++ b/src/patterns.md @@ -149,8 +149,7 @@ LiteralPattern -> | RAW_BYTE_STRING_LITERAL | C_STRING_LITERAL | RAW_C_STRING_LITERAL - | `-`? INTEGER_LITERAL - | `-`? FLOAT_LITERAL + | `-`? ( INTEGER_LITERAL | FLOAT_LITERAL ) ``` r[patterns.literal.intro] @@ -499,8 +498,7 @@ ObsoleteRangePattern -> RangePatternBound -> CHAR_LITERAL | BYTE_LITERAL - | `-`? INTEGER_LITERAL - | `-`? FLOAT_LITERAL + | `-`? ( INTEGER_LITERAL | FLOAT_LITERAL ) | PathExpression ``` @@ -708,7 +706,7 @@ StructPattern -> `}` StructPatternElements -> - StructPatternFields (`,` | `,` StructPatternEtCetera)? + StructPatternFields ( `,` StructPatternEtCetera? )? | StructPatternEtCetera StructPatternFields -> @@ -717,8 +715,7 @@ StructPatternFields -> StructPatternField -> OuterAttribute* ( - TUPLE_INDEX `:` Pattern - | IDENTIFIER `:` Pattern + ( TUPLE_INDEX | IDENTIFIER ) `:` Pattern | `ref`? `mut`? IDENTIFIER ) @@ -837,9 +834,8 @@ r[patterns.tuple.syntax] TuplePattern -> `(` TuplePatternItems? `)` TuplePatternItems -> - Pattern `,` + Pattern ( `,` | ( `,` Pattern )+ `,`? ) | RestPattern - | Pattern (`,` Pattern)+ `,`? ``` r[patterns.tuple.intro] diff --git a/src/statements.md b/src/statements.md index 8b10f0971..fe0c4ce5c 100644 --- a/src/statements.md +++ b/src/statements.md @@ -61,8 +61,11 @@ r[statement.let.syntax] LetStatement -> OuterAttribute* `let` PatternNoTopAlt ( `:` Type )? ( - `=` Expression - | `=` Expression _except [LazyBooleanExpression] or end with a `}`_ `else` BlockExpression + `=` ( + Expression _except [LazyBooleanExpression] or end with a `}`_ + `else` BlockExpression + | Expression + ) )? `;` ``` diff --git a/src/tokens.md b/src/tokens.md index 294753e69..4f0675df1 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -657,9 +657,11 @@ r[lex.token.literal.float] r[lex.token.literal.float.syntax] ```grammar,lexer FLOAT_LITERAL -> - DEC_LITERAL `.` _not immediately followed by `.`, `_` or an XID_Start character_ - | DEC_LITERAL `.` DEC_LITERAL SUFFIX_NO_E? - | DEC_LITERAL (`.` DEC_LITERAL)? FLOAT_EXPONENT SUFFIX? + DEC_LITERAL ( + `.` _not immediately followed by `.`, `_` or an XID_Start character_ + | `.` DEC_LITERAL ( SUFFIX_NO_E? | FLOAT_EXPONENT SUFFIX? ) + | FLOAT_EXPONENT SUFFIX? + ) FLOAT_EXPONENT -> (`e`|`E`) (`+`|`-`)? (DEC_DIGIT|`_`)* DEC_DIGIT (DEC_DIGIT|`_`)* @@ -714,8 +716,11 @@ r[lex.token.literal.reserved.syntax] RESERVED_NUMBER -> BIN_LITERAL [`2`-`9`] | OCT_LITERAL [`8`-`9`] - | ( BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) `.` _not immediately followed by `.`, `_` or an XID_Start character_ - | ( BIN_LITERAL | OCT_LITERAL ) (`e`|`E`) + | ( BIN_LITERAL | OCT_LITERAL ) ( + `.` _not immediately followed by `.`, `_` or an XID_Start character_ + | (`e`|`E`) + ) + | HEX_LITERAL `.` _not immediately followed by `.`, `_` or an XID_Start character_ | `0b` `_`* | `0o` `_`* | `0x` `_`* diff --git a/src/trait-bounds.md b/src/trait-bounds.md index f31265fbc..ffaa4b849 100644 --- a/src/trait-bounds.md +++ b/src/trait-bounds.md @@ -7,9 +7,9 @@ TypeParamBounds -> TypeParamBound ( `+` TypeParamBound )* `+`? TypeParamBound -> Lifetime | TraitBound | UseBound -TraitBound -> - ( `?` | ForLifetimes )? TypePath - | `(` ( `?` | ForLifetimes )? TypePath `)` +TraitBound -> `(` TraitBoundNoParens `)` | TraitBoundNoParens + +TraitBoundNoParens -> ( `?` | ForLifetimes )? TypePath LifetimeBounds -> ( Lifetime `+` )* Lifetime? @@ -21,8 +21,7 @@ Lifetime -> UseBound -> `use` UseBoundGenericArgs UseBoundGenericArgs -> - `<` `>` - | `<` ( UseBoundGenericArg `,`)* UseBoundGenericArg `,`? `>` + `<` ( UseBoundGenericArg ( `,` UseBoundGenericArg )* `,`? )? `>` UseBoundGenericArg -> Lifetime diff --git a/src/types/function-pointer.md b/src/types/function-pointer.md index 03c879366..b69c5ed30 100644 --- a/src/types/function-pointer.md +++ b/src/types/function-pointer.md @@ -21,7 +21,7 @@ MaybeNamedParam -> OuterAttribute* ( ( IDENTIFIER | `_` ) `:` )? Type MaybeNamedFunctionParametersVariadic -> - ( MaybeNamedParam `,` )* MaybeNamedParam `,` OuterAttribute* `...` + MaybeNamedParam ( `,` MaybeNamedParam )* `,` OuterAttribute* `...` ``` r[type.fn-pointer.intro] diff --git a/src/types/tuple.md b/src/types/tuple.md index a686cfb8f..51a2643b7 100644 --- a/src/types/tuple.md +++ b/src/types/tuple.md @@ -4,8 +4,7 @@ r[type.tuple] r[type.tuple.syntax] ```grammar,types TupleType -> - `(` `)` - | `(` ( Type `,` )+ Type? `)` + `(` ( ( Type `,` )+ Type? )? `)` ``` r[type.tuple.intro] diff --git a/src/visibility-and-privacy.md b/src/visibility-and-privacy.md index 847d46977..e39ed5c81 100644 --- a/src/visibility-and-privacy.md +++ b/src/visibility-and-privacy.md @@ -4,11 +4,14 @@ r[vis] r[vis.syntax] ```grammar,items Visibility -> - `pub` - | `pub` `(` `crate` `)` - | `pub` `(` `self` `)` - | `pub` `(` `super` `)` - | `pub` `(` `in` SimplePath `)` + `pub` ( + `(` ( + `crate` + | `self` + | `super` + | `in` SimplePath + ) `)` + )? ``` r[vis.intro]