Skip to content

Commit 5a4d768

Browse files
committed
Rework grammar compactions
Let's fix up the grammar compactions to follow the indentation and spacing style we use for this grammar (especially as the indentation is preserved into the rendering), remove superfluous parentheses, and add line breaks in alternations and elsewhere to add clarity.
1 parent eb020fc commit 5a4d768

17 files changed

+83
-41
lines changed

src/attributes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ attributes]. It has the following grammar:
116116
r[attributes.meta.syntax]
117117
```grammar,attributes
118118
MetaItem ->
119-
SimplePath ((`=` Expression) | (`(` MetaSeq? `)`))?
119+
SimplePath (
120+
`=` Expression
121+
| `(` MetaSeq? `)`
122+
)?
120123
121124
MetaSeq ->
122125
MetaItemInner ( `,` MetaItemInner )* `,`?

src/expressions/array-expr.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ r[expr.array.syntax]
88
ArrayExpression -> `[` ArrayElements? `]`
99
1010
ArrayElements ->
11-
Expression (( `,` Expression )* `,`? | (`;` Expression ))
11+
Expression (
12+
( `,` Expression )* `,`?
13+
| `;` Expression
14+
)
1215
```
1316

1417
r[expr.array.constructor]

src/expressions/block-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BlockExpression ->
1010
`}`
1111
1212
Statements ->
13-
Statement+ ExpressionWithoutBlock?
13+
Statement+ ExpressionWithoutBlock?
1414
| ExpressionWithoutBlock
1515
```
1616

src/expressions/operator-expr.md

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

6466
r[expr.operator.borrow.intro]
@@ -288,7 +290,9 @@ r[expr.arith-logic]
288290
r[expr.arith-logic.syntax]
289291
```grammar,expressions
290292
ArithmeticOrLogicalExpression ->
291-
Expression ( `+` | `-` | `*` | `/` | `%` | `&` | `|` | `^` | `<<` | `>>` ) Expression
293+
Expression (
294+
`+` | `-` | `*` | `/` | `%` | `&` | `|` | `^` | `<<` | `>>`
295+
) Expression
292296
```
293297

294298
r[expr.arith-logic.intro]
@@ -342,7 +346,9 @@ r[expr.cmp]
342346
r[expr.cmp.syntax]
343347
```grammar,expressions
344348
ComparisonExpression ->
345-
Expression ( `==` | `!=` | `>` | `<` | `>=` | `<=` ) Expression
349+
Expression (
350+
`==` | `!=` | `>` | `<` | `>=` | `<=`
351+
) Expression
346352
```
347353

348354
r[expr.cmp.intro]
@@ -396,7 +402,7 @@ r[expr.bool-logic]
396402
r[expr.bool-logic.syntax]
397403
```grammar,expressions
398404
LazyBooleanExpression ->
399-
Expression (`||` | `&&`) Expression
405+
Expression (`||` | `&&`) Expression
400406
```
401407

402408
r[expr.bool-logic.intro]
@@ -791,7 +797,11 @@ r[expr.compound-assign]
791797
r[expr.compound-assign.syntax]
792798
```grammar,expressions
793799
CompoundAssignmentExpression ->
794-
Expression (`+=` | `-=` | `*=` | `/=` | `%=` | `&=` | `|=` | `^=` | `<<=` | `>>=`) Expression
800+
Expression (
801+
`+=` | `-=` | `*=` | `/=` | `%=`
802+
| `&=` | `|=` | `^=`
803+
| `<<=` | `>>=`
804+
) Expression
795805
```
796806

797807
r[expr.compound-assign.intro]

src/inline-assembly.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,21 @@ AsmOption ->
7373
| `att_syntax`
7474
| `raw`
7575
76-
RegOperand -> (ParamName `=`)?
77-
(
78-
((DirSpec `(` RegSpec `)`)
79-
| `const`
80-
) Expression
81-
| DualDirSpec `(` RegSpec `)` DualDirSpecExpression
82-
| `sym` PathExpression
83-
| `label` `{` Statements? `}`
76+
RegOperand ->
77+
(ParamName `=`)? (
78+
(
79+
DirSpec `(` RegSpec `)`
80+
| `const`
81+
) Expression
82+
| DualDirSpec `(` RegSpec `)` DualDirSpecExpression
83+
| `sym` PathExpression
84+
| `label` `{` Statements? `}`
8485
)
8586
8687
ParamName -> IDENTIFIER_OR_KEYWORD | RAW_IDENTIFIER
8788
8889
DualDirSpecExpression ->
89-
Expression (`=>` Expression)?
90+
Expression ( `=>` Expression )?
9091
9192
RegSpec -> RegisterClass | ExplicitRegister
9293

src/items/external-blocks.md

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

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ r[items.mod]
44
r[items.mod.syntax]
55
```grammar,items
66
Module ->
7-
`unsafe`? `mod` IDENTIFIER ( `;` | (`{` InnerAttribute* Item* `}` ))
7+
`unsafe`? `mod` IDENTIFIER (
8+
`{` InnerAttribute* Item* `}`
9+
| `;`
10+
)
811
```
912

1013
r[items.mod.intro]

src/items/use-declarations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ r[items.use.syntax]
66
UseDeclaration -> `use` UseTree `;`
77
88
UseTree ->
9-
(SimplePath? `::`)? (`*` | (`{` (UseTree ( `,` UseTree )* `,`?)? `}`))
9+
( SimplePath? `::` )? (
10+
`{` ( UseTree ( `,` UseTree )* `,`? )? `}`
11+
| `*`
12+
)
1013
| SimplePath ( `as` ( IDENTIFIER | `_` ) )?
1114
```
1215

src/macros-by-example.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ MacroRulesDefinition ->
77
`macro_rules` `!` IDENTIFIER MacroRulesDef
88
99
MacroRulesDef ->
10-
( (`(` MacroRules `)`)
11-
| (`[` MacroRules `]`)
12-
)`;`
13-
| (`{` MacroRules `}`)
10+
(
11+
`(` MacroRules `)`
12+
| `[` MacroRules `]`
13+
) `;`
14+
| `{` MacroRules `}`
1415
1516
MacroRules ->
1617
MacroRule ( `;` MacroRule )* `;`?
@@ -26,8 +27,11 @@ MacroMatcher ->
2627
MacroMatch ->
2728
Token _except `$` and [delimiters][lex.token.delim]_
2829
| MacroMatcher
29-
| `$` ((( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` ) `:` MacroFragSpec)
30-
| (`(` MacroMatch+ `)` MacroRepSep? MacroRepOp))
30+
| `$` (
31+
( IDENTIFIER_OR_KEYWORD _except `crate`_ | RAW_IDENTIFIER | `_` )
32+
`:` MacroFragSpec
33+
| `(` MacroMatch+ `)` MacroRepSep? MacroRepOp
34+
)
3135
3236
MacroFragSpec ->
3337
`block` | `expr` | `expr_2021` | `ident` | `item` | `lifetime` | `literal`

0 commit comments

Comments
 (0)