Skip to content

Compactify syntax diagrams #1818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )* `,`?
Expand Down
3 changes: 1 addition & 2 deletions src/expressions/array-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ r[expr.array.syntax]
ArrayExpression -> `[` ArrayElements? `]`

ArrayElements ->
Expression ( `,` Expression )* `,`?
| Expression `;` Expression
Expression (( `,` Expression )* `,`? | (`;` Expression ))
```

r[expr.array.constructor]
Expand Down
3 changes: 1 addition & 2 deletions src/expressions/block-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ BlockExpression ->
`}`

Statements ->
Statement+
| Statement+ ExpressionWithoutBlock
Statement+ ExpressionWithoutBlock?
| ExpressionWithoutBlock
```

Expand Down
37 changes: 5 additions & 32 deletions src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/inline-assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions src/items/external-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ ExternBlock ->

ExternalItem ->
OuterAttribute* (
MacroInvocationSemi
| Visibility? StaticItem
| Visibility? Function
Visibility? (StaticItem | Function)
| MacroInvocationSemi
)
```

Expand Down
2 changes: 1 addition & 1 deletion src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FunctionParameters ->

SelfParam -> OuterAttribute* ( ShorthandSelf | TypedSelf )

ShorthandSelf -> (`&` | `&` Lifetime)? `mut`? `self`
ShorthandSelf -> (`&` Lifetime?)? `mut`? `self`

TypedSelf -> `mut`? `self` `:` Type

Expand Down
6 changes: 1 addition & 5 deletions src/items/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/items/use-declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ r[items.use.syntax]
UseDeclaration -> `use` UseTree `;`

UseTree ->
(SimplePath? `::`)? `*`
| (SimplePath? `::`)? `{` (UseTree ( `,` UseTree )* `,`?)? `}`
(SimplePath? `::`)? (`*` | (`{` (UseTree ( `,` UseTree )* `,`?)? `}`))
| SimplePath ( `as` ( IDENTIFIER | `_` ) )?
```

Expand Down
11 changes: 6 additions & 5 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ MacroRulesDefinition ->
`macro_rules` `!` IDENTIFIER MacroRulesDef

MacroRulesDef ->
`(` MacroRules `)` `;`
| `[` MacroRules `]` `;`
| `{` MacroRules `}`
( (`(` MacroRules `)`)
| (`[` MacroRules `]`)
)`;`
| (`{` MacroRules `}`)

MacroRules ->
MacroRule ( `;` MacroRule )* `;`?
Expand All @@ -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`
Expand Down
4 changes: 1 addition & 3 deletions src/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions src/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
14 changes: 5 additions & 9 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -499,8 +498,7 @@ ObsoleteRangePattern ->
RangePatternBound ->
CHAR_LITERAL
| BYTE_LITERAL
| `-`? INTEGER_LITERAL
| `-`? FLOAT_LITERAL
| `-`? (INTEGER_LITERAL | FLOAT_LITERAL)
| PathExpression
```

Expand Down Expand Up @@ -708,7 +706,7 @@ StructPattern ->
`}`

StructPatternElements ->
StructPatternFields (`,` | `,` StructPatternEtCetera)?
StructPatternFields (`,` StructPatternEtCetera?)?
| StructPatternEtCetera

StructPatternFields ->
Expand All @@ -717,8 +715,7 @@ StructPatternFields ->
StructPatternField ->
OuterAttribute*
(
TUPLE_INDEX `:` Pattern
| IDENTIFIER `:` Pattern
(TUPLE_INDEX | IDENTIFIER) `:` Pattern
| `ref`? `mut`? IDENTIFIER
)

Expand Down Expand Up @@ -837,9 +834,8 @@ r[patterns.tuple.syntax]
TuplePattern -> `(` TuplePatternItems? `)`

TuplePatternItems ->
Pattern `,`
Pattern (`,` | (`,` Pattern)+ `,`?)
| RestPattern
| Pattern (`,` Pattern)+ `,`?
```

r[patterns.tuple.intro]
Expand Down
6 changes: 3 additions & 3 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|`_`)*
Expand Down
3 changes: 1 addition & 2 deletions src/trait-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Lifetime ->
UseBound -> `use` UseBoundGenericArgs

UseBoundGenericArgs ->
`<` `>`
| `<` ( UseBoundGenericArg `,`)* UseBoundGenericArg `,`? `>`
`<` (( UseBoundGenericArg `,`)* UseBoundGenericArg `,`?)? `>`

UseBoundGenericArg ->
Lifetime
Expand Down
3 changes: 1 addition & 2 deletions src/types/tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ r[type.tuple]
r[type.tuple.syntax]
```grammar,types
TupleType ->
`(` `)`
| `(` ( Type `,` )+ Type? `)`
`(` (( Type `,` )+ Type?)? `)`
```

r[type.tuple.intro]
Expand Down
6 changes: 1 addition & 5 deletions src/visibility-and-privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down