Skip to content

Commit 7d720ec

Browse files
committed
Compactify syntax diagrams
1 parent 0ba97b1 commit 7d720ec

17 files changed

+37
-87
lines changed

src/attributes.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ attributes]. It has the following grammar:
116116
r[attributes.meta.syntax]
117117
```grammar,attributes
118118
MetaItem ->
119-
SimplePath
120-
| SimplePath `=` Expression
121-
| SimplePath `(` MetaSeq? `)`
119+
SimplePath ((`=` Expression) | (`(` MetaSeq? `)`))?
122120
123121
MetaSeq ->
124122
MetaItemInner ( `,` MetaItemInner )* `,`?

src/expressions/array-expr.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ r[expr.array.syntax]
88
ArrayExpression -> `[` ArrayElements? `]`
99
1010
ArrayElements ->
11-
Expression ( `,` Expression )* `,`?
12-
| Expression `;` Expression
11+
Expression (( `,` Expression )* `,`? | (`;` Expression ))
1312
```
1413

1514
r[expr.array.constructor]

src/expressions/block-expr.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ BlockExpression ->
1010
`}`
1111
1212
Statements ->
13-
Statement+
14-
| Statement+ ExpressionWithoutBlock
13+
Statement+ ExpressionWithoutBlock?
1514
| ExpressionWithoutBlock
1615
```
1716

src/expressions/operator-expr.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ r[expr.operator.borrow]
5858
r[expr.operator.borrow.syntax]
5959
```grammar,expressions
6060
BorrowExpression ->
61-
(`&`|`&&`) Expression
62-
| (`&`|`&&`) `mut` Expression
63-
| (`&`|`&&`) `raw` `const` Expression
64-
| (`&`|`&&`) `raw` `mut` Expression
61+
(`&`|`&&`) ( `mut` | (`raw` (`const` | `mut`))) Expression
6562
```
6663

6764
r[expr.operator.borrow.intro]
@@ -291,16 +288,7 @@ r[expr.arith-logic]
291288
r[expr.arith-logic.syntax]
292289
```grammar,expressions
293290
ArithmeticOrLogicalExpression ->
294-
Expression `+` Expression
295-
| Expression `-` Expression
296-
| Expression `*` Expression
297-
| Expression `/` Expression
298-
| Expression `%` Expression
299-
| Expression `&` Expression
300-
| Expression `|` Expression
301-
| Expression `^` Expression
302-
| Expression `<<` Expression
303-
| Expression `>>` Expression
291+
Expression ( `+` | `-` | `*` | `/` | `%` | `&` | `|` | `^` | `<<` | `>>` ) Expression
304292
```
305293

306294
r[expr.arith-logic.intro]
@@ -354,12 +342,7 @@ r[expr.cmp]
354342
r[expr.cmp.syntax]
355343
```grammar,expressions
356344
ComparisonExpression ->
357-
Expression `==` Expression
358-
| Expression `!=` Expression
359-
| Expression `>` Expression
360-
| Expression `<` Expression
361-
| Expression `>=` Expression
362-
| Expression `<=` Expression
345+
Expression ( `==` | `!=` | `>` | `<` | `>=` | `<=` ) Expression
363346
```
364347

365348
r[expr.cmp.intro]
@@ -413,8 +396,7 @@ r[expr.bool-logic]
413396
r[expr.bool-logic.syntax]
414397
```grammar,expressions
415398
LazyBooleanExpression ->
416-
Expression `||` Expression
417-
| Expression `&&` Expression
399+
Expression (`||` | `&&`) Expression
418400
```
419401

420402
r[expr.bool-logic.intro]
@@ -809,16 +791,7 @@ r[expr.compound-assign]
809791
r[expr.compound-assign.syntax]
810792
```grammar,expressions
811793
CompoundAssignmentExpression ->
812-
Expression `+=` Expression
813-
| Expression `-=` Expression
814-
| Expression `*=` Expression
815-
| Expression `/=` Expression
816-
| Expression `%=` Expression
817-
| Expression `&=` Expression
818-
| Expression `|=` Expression
819-
| Expression `^=` Expression
820-
| Expression `<<=` Expression
821-
| Expression `>>=` Expression
794+
Expression (`+=` | `-=` | `*=` | `/=` | `%=` | `&=` | `|=` | `^=` | `<<=` | `>>=`) Expression
822795
```
823796

824797
r[expr.compound-assign.intro]

src/inline-assembly.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ AsmOption ->
7575
7676
RegOperand -> (ParamName `=`)?
7777
(
78-
DirSpec `(` RegSpec `)` Expression
78+
((DirSpec `(` RegSpec `)`)
79+
| `const`
80+
) Expression
7981
| DualDirSpec `(` RegSpec `)` DualDirSpecExpression
8082
| `sym` PathExpression
81-
| `const` Expression
8283
| `label` `{` Statements? `}`
8384
)
8485
8586
ParamName -> IDENTIFIER_OR_KEYWORD | RAW_IDENTIFIER
8687
8788
DualDirSpecExpression ->
88-
Expression
89-
| Expression `=>` Expression
89+
Expression (`=>` Expression)?
9090
9191
RegSpec -> RegisterClass | ExplicitRegister
9292

src/items/external-blocks.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ ExternBlock ->
1111
1212
ExternalItem ->
1313
OuterAttribute* (
14-
MacroInvocationSemi
15-
| Visibility? StaticItem
16-
| Visibility? Function
14+
Visibility? (StaticItem | Function)
15+
| MacroInvocationSemi
1716
)
1817
```
1918

src/items/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FunctionParameters ->
2121
2222
SelfParam -> OuterAttribute* ( ShorthandSelf | TypedSelf )
2323
24-
ShorthandSelf -> (`&` | `&` Lifetime)? `mut`? `self`
24+
ShorthandSelf -> (`&` Lifetime?)? `mut`? `self`
2525
2626
TypedSelf -> `mut`? `self` `:` Type
2727

src/items/modules.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ r[items.mod]
44
r[items.mod.syntax]
55
```grammar,items
66
Module ->
7-
`unsafe`? `mod` IDENTIFIER `;`
8-
| `unsafe`? `mod` IDENTIFIER `{`
9-
InnerAttribute*
10-
Item*
11-
`}`
7+
`unsafe`? `mod` IDENTIFIER ( `;` | (`{` InnerAttribute* Item* `}` ))
128
```
139

1410
r[items.mod.intro]

src/items/use-declarations.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ r[items.use.syntax]
66
UseDeclaration -> `use` UseTree `;`
77
88
UseTree ->
9-
(SimplePath? `::`)? `*`
10-
| (SimplePath? `::`)? `{` (UseTree ( `,` UseTree )* `,`?)? `}`
9+
(SimplePath? `::`)? (`*` | (`{` (UseTree ( `,` UseTree )* `,`?)? `}`))
1110
| SimplePath ( `as` ( IDENTIFIER | `_` ) )?
1211
```
1312

src/macros-by-example.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ MacroRulesDefinition ->
77
`macro_rules` `!` IDENTIFIER MacroRulesDef
88
99
MacroRulesDef ->
10-
`(` MacroRules `)` `;`
11-
| `[` MacroRules `]` `;`
12-
| `{` MacroRules `}`
10+
( (`(` MacroRules `)`)
11+
| (`[` MacroRules `]`)
12+
)`;`
13+
| (`{` MacroRules `}`)
1314
1415
MacroRules ->
1516
MacroRule ( `;` MacroRule )* `;`?
@@ -25,8 +26,8 @@ MacroMatcher ->
2526
MacroMatch ->
2627
Token _except `$` and [delimiters][lex.token.delim]_
2728
| MacroMatcher
28-
| `$` ( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` ) `:` MacroFragSpec
29-
| `$` `(` MacroMatch+ `)` MacroRepSep? MacroRepOp
29+
| `$` ((( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` ) `:` MacroFragSpec)
30+
| (`(` MacroMatch+ `)` MacroRepSep? MacroRepOp))
3031
3132
MacroFragSpec ->
3233
`block` | `expr` | `expr_2021` | `ident` | `item` | `lifetime` | `literal`

src/macros.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ TokenTree ->
2929
Token _except [delimiters][lex.token.delim]_ | DelimTokenTree
3030
3131
MacroInvocationSemi ->
32-
SimplePath `!` `(` TokenTree* `)` `;`
33-
| SimplePath `!` `[` TokenTree* `]` `;`
34-
| SimplePath `!` `{` TokenTree* `}`
32+
SimplePath `!` ( ( ( `(` TokenTree* `)` ) | ( `[` TokenTree* `]` )) `;` | ( `{` TokenTree* `}` ))
3533
```
3634

3735
r[macro.invocation.intro]

src/paths.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,14 @@ PathIdentSegment ->
5454
IDENTIFIER | `super` | `self` | `Self` | `crate` | `$crate`
5555
5656
GenericArgs ->
57-
`<` `>`
58-
| `<` ( GenericArg `,` )* GenericArg `,`? `>`
57+
`<` (( GenericArg `,` )* GenericArg `,`?)? `>`
5958
6059
GenericArg ->
6160
Lifetime | Type | GenericArgsConst | GenericArgsBinding | GenericArgsBounds
6261
6362
GenericArgsConst ->
6463
BlockExpression
65-
| LiteralExpression
66-
| `-` LiteralExpression
64+
| `-`? LiteralExpression
6765
| SimplePathSegment
6866
6967
GenericArgsBinding ->

src/patterns.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ LiteralPattern ->
149149
| RAW_BYTE_STRING_LITERAL
150150
| C_STRING_LITERAL
151151
| RAW_C_STRING_LITERAL
152-
| `-`? INTEGER_LITERAL
153-
| `-`? FLOAT_LITERAL
152+
| `-`? (INTEGER_LITERAL | FLOAT_LITERAL)
154153
```
155154

156155
r[patterns.literal.intro]
@@ -499,8 +498,7 @@ ObsoleteRangePattern ->
499498
RangePatternBound ->
500499
CHAR_LITERAL
501500
| BYTE_LITERAL
502-
| `-`? INTEGER_LITERAL
503-
| `-`? FLOAT_LITERAL
501+
| `-`? (INTEGER_LITERAL | FLOAT_LITERAL)
504502
| PathExpression
505503
```
506504

@@ -708,7 +706,7 @@ StructPattern ->
708706
`}`
709707
710708
StructPatternElements ->
711-
StructPatternFields (`,` | `,` StructPatternEtCetera)?
709+
StructPatternFields (`,` StructPatternEtCetera?)?
712710
| StructPatternEtCetera
713711
714712
StructPatternFields ->
@@ -717,8 +715,7 @@ StructPatternFields ->
717715
StructPatternField ->
718716
OuterAttribute*
719717
(
720-
TUPLE_INDEX `:` Pattern
721-
| IDENTIFIER `:` Pattern
718+
(TUPLE_INDEX | IDENTIFIER) `:` Pattern
722719
| `ref`? `mut`? IDENTIFIER
723720
)
724721
@@ -837,9 +834,8 @@ r[patterns.tuple.syntax]
837834
TuplePattern -> `(` TuplePatternItems? `)`
838835
839836
TuplePatternItems ->
840-
Pattern `,`
837+
Pattern (`,` | (`,` Pattern)+ `,`?)
841838
| RestPattern
842-
| Pattern (`,` Pattern)+ `,`?
843839
```
844840

845841
r[patterns.tuple.intro]

src/tokens.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,9 @@ r[lex.token.literal.float]
657657
r[lex.token.literal.float.syntax]
658658
```grammar,lexer
659659
FLOAT_LITERAL ->
660-
DEC_LITERAL `.` _not immediately followed by `.`, `_` or an XID_Start character_
661-
| DEC_LITERAL `.` DEC_LITERAL SUFFIX_NO_E?
662-
| DEC_LITERAL (`.` DEC_LITERAL)? FLOAT_EXPONENT SUFFIX?
660+
DEC_LITERAL ((`.` _not immediately followed by `.`, `_` or an XID_Start character_ )
661+
| (`.` DEC_LITERAL SUFFIX_NO_E?)
662+
| ((`.` DEC_LITERAL)? FLOAT_EXPONENT SUFFIX?))
663663
664664
FLOAT_EXPONENT ->
665665
(`e`|`E`) (`+`|`-`)? (DEC_DIGIT|`_`)* DEC_DIGIT (DEC_DIGIT|`_`)*

src/trait-bounds.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Lifetime ->
2121
UseBound -> `use` UseBoundGenericArgs
2222
2323
UseBoundGenericArgs ->
24-
`<` `>`
25-
| `<` ( UseBoundGenericArg `,`)* UseBoundGenericArg `,`? `>`
24+
`<` (( UseBoundGenericArg `,`)* UseBoundGenericArg `,`?)? `>`
2625
2726
UseBoundGenericArg ->
2827
Lifetime

src/types/tuple.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ r[type.tuple]
44
r[type.tuple.syntax]
55
```grammar,types
66
TupleType ->
7-
`(` `)`
8-
| `(` ( Type `,` )+ Type? `)`
7+
`(` (( Type `,` )+ Type?)? `)`
98
```
109

1110
r[type.tuple.intro]

src/visibility-and-privacy.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ r[vis]
44
r[vis.syntax]
55
```grammar,items
66
Visibility ->
7-
`pub`
8-
| `pub` `(` `crate` `)`
9-
| `pub` `(` `self` `)`
10-
| `pub` `(` `super` `)`
11-
| `pub` `(` `in` SimplePath `)`
7+
`pub` ( `(` (`crate` | `self` | `super` | (`in` SimplePath)) `)` )?
128
```
139

1410
r[vis.intro]

0 commit comments

Comments
 (0)