Unnamed repository; edit this file 'description' to name the repository.
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?
Aleksey Kladov 2021-09-26
parent 378b785 · commit 7eb4702
-rw-r--r--lib/ungrammar/rust.ungram7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/ungrammar/rust.ungram b/lib/ungrammar/rust.ungram
index 5a8e116137..938843ffce 100644
--- a/lib/ungrammar/rust.ungram
+++ b/lib/ungrammar/rust.ungram
@@ -331,7 +331,6 @@ Expr =
| CastExpr
| ClosureExpr
| ContinueExpr
-| EffectExpr
| FieldExpr
| ForExpr
| IfExpr
@@ -366,7 +365,7 @@ Literal =
PathExpr =
Attr* Path
-BlockExpr =
+StmtList =
'{'
Attr*
statements:Stmt*
@@ -379,8 +378,8 @@ RefExpr =
TryExpr =
Attr* Expr '?'
-EffectExpr =
- Attr* Label? ('try' | 'unsafe' | 'async' | 'const') BlockExpr
+BlockExpr =
+ Attr* Label? ('try' | 'unsafe' | 'async' | 'const') StmtList
PrefixExpr =
Attr* op:('-' | '!' | '*') Expr