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`

0 commit comments

Comments
 (0)