Skip to content

Commit 2da46ff

Browse files
committed
canonical grammar for block expressions
Historically, we struggled with formulating the right grammar for block expressions. Today's EffectExpr is the best we've come up so far, but, if you are thinking "WTF is an effect expression?", you are not wrong. I think in this commit I've come up with what can be called a reasonable grammar for block expressions. Observe that *all* things in `{}` we call list: item list, assoc item list, match arm list, record field list, record expr field list. In fact, `BlockExpr` is the only exception. So, let's just call the stuff in `{}` a statement list. This isn't forced: *all* things inside a block are statements, and `;` is a statement separator, just like `,`. Trailing `;` is allowed, but not required. Then, statement list with modifiers such as `async` or attributes or labels is just a block expression. Why haven't I thought of it from the start?
1 parent 1523dde commit 2da46ff

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

rust.ungram

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ Expr =
331331
| CastExpr
332332
| ClosureExpr
333333
| ContinueExpr
334-
| EffectExpr
335334
| FieldExpr
336335
| ForExpr
337336
| IfExpr
@@ -366,7 +365,7 @@ Literal =
366365
PathExpr =
367366
Attr* Path
368367

369-
BlockExpr =
368+
StmtList =
370369
'{'
371370
Attr*
372371
statements:Stmt*
@@ -379,8 +378,8 @@ RefExpr =
379378
TryExpr =
380379
Attr* Expr '?'
381380

382-
EffectExpr =
383-
Attr* Label? ('try' | 'unsafe' | 'async' | 'const') BlockExpr
381+
BlockExpr =
382+
Attr* Label? ('try' | 'unsafe' | 'async' | 'const') StmtList
384383

385384
PrefixExpr =
386385
Attr* op:('-' | '!' | '*') Expr

0 commit comments

Comments
 (0)