diff --git a/src/attributes.md b/src/attributes.md index d6cbed613..df3ca82bd 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -116,9 +116,7 @@ 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/expressions/array-expr.md b/src/expressions/array-expr.md index 04374f3f3..49ae66c6d 100644 --- a/src/expressions/array-expr.md +++ b/src/expressions/array-expr.md @@ -8,8 +8,7 @@ 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..cc971e4f9 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..dd37e99aa 100644 --- a/src/expressions/operator-expr.md +++ b/src/expressions/operator-expr.md @@ -58,10 +58,7 @@ 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] @@ -291,16 +288,7 @@ 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 +342,7 @@ 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 +396,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 +791,7 @@ 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..0274432f3 100644 --- a/src/inline-assembly.md +++ b/src/inline-assembly.md @@ -75,18 +75,18 @@ AsmOption -> RegOperand -> (ParamName `=`)? ( - DirSpec `(` RegSpec `)` Expression + ((DirSpec `(` RegSpec `)`) + | `const` + ) Expression | DualDirSpec `(` RegSpec `)` DualDirSpecExpression | `sym` PathExpression - | `const` Expression | `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..d336080e9 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..31409343e 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -21,7 +21,7 @@ FunctionParameters -> SelfParam -> OuterAttribute* ( ShorthandSelf | TypedSelf ) -ShorthandSelf -> (`&` | `&` Lifetime)? `mut`? `self` +ShorthandSelf -> (`&` Lifetime?)? `mut`? `self` TypedSelf -> `mut`? `self` `:` Type diff --git a/src/items/modules.md b/src/items/modules.md index 295d1d7b5..7d701c381 100644 --- a/src/items/modules.md +++ b/src/items/modules.md @@ -4,11 +4,7 @@ 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..998481cff 100644 --- a/src/items/use-declarations.md +++ b/src/items/use-declarations.md @@ -6,8 +6,7 @@ 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..b596218ef 100644 --- a/src/macros-by-example.md +++ b/src/macros-by-example.md @@ -7,9 +7,10 @@ MacroRulesDefinition -> `macro_rules` `!` IDENTIFIER MacroRulesDef MacroRulesDef -> - `(` MacroRules `)` `;` - | `[` MacroRules `]` `;` - | `{` MacroRules `}` + ( (`(` MacroRules `)`) + | (`[` MacroRules `]`) + )`;` + | (`{` MacroRules `}`) MacroRules -> MacroRule ( `;` MacroRule )* `;`? @@ -25,8 +26,8 @@ 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..79f3b67b6 100644 --- a/src/macros.md +++ b/src/macros.md @@ -29,9 +29,7 @@ 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..1dd1d615a 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..8a6893914 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/tokens.md b/src/tokens.md index 294753e69..70e9654dd 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -657,9 +657,9 @@ 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?) + | ((`.` DEC_LITERAL)? FLOAT_EXPONENT SUFFIX?)) FLOAT_EXPONENT -> (`e`|`E`) (`+`|`-`)? (DEC_DIGIT|`_`)* DEC_DIGIT (DEC_DIGIT|`_`)* diff --git a/src/trait-bounds.md b/src/trait-bounds.md index f31265fbc..dfccba1be 100644 --- a/src/trait-bounds.md +++ b/src/trait-bounds.md @@ -21,8 +21,7 @@ Lifetime -> UseBound -> `use` UseBoundGenericArgs UseBoundGenericArgs -> - `<` `>` - | `<` ( UseBoundGenericArg `,`)* UseBoundGenericArg `,`? `>` + `<` (( UseBoundGenericArg `,`)* UseBoundGenericArg `,`?)? `>` UseBoundGenericArg -> Lifetime diff --git a/src/types/tuple.md b/src/types/tuple.md index a686cfb8f..f7c322e9d 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..e5469be40 100644 --- a/src/visibility-and-privacy.md +++ b/src/visibility-and-privacy.md @@ -4,11 +4,7 @@ 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]