Support if- and while-let chains
RFC 2497 https://github.com/rust-lang/rfcs/blob/master/text/2497-if-let-chains.md.
diff --git a/Cargo.toml b/Cargo.toml
index 8e732c8..bbfb0f5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "ungrammar"
description = "A DSL for describing concrete syntax trees"
-version = "1.14.9"
+version = "1.15.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/matklad/ungrammar"
edition = "2018"
diff --git a/rust.ungram b/rust.ungram
index d2ef552..7d7f184 100644
--- a/rust.ungram
+++ b/rust.ungram
@@ -357,6 +357,7 @@
| TupleExpr
| WhileExpr
| YieldExpr
+| LetExpr
Literal =
Attr* value:(
@@ -448,13 +449,9 @@
body:Expr
IfExpr =
- Attr* 'if' Condition then_branch:BlockExpr
+ Attr* 'if' condition:Expr then_branch:BlockExpr
('else' else_branch:(IfExpr | BlockExpr))?
-Condition =
- 'let' Pat '=' Expr
-| Expr
-
LoopExpr =
Attr* Label? 'loop'
loop_body:BlockExpr
@@ -464,7 +461,7 @@
loop_body:BlockExpr
WhileExpr =
- Attr* Label? 'while' Condition
+ Attr* Label? 'while' condition:Expr
loop_body:BlockExpr
Label =
@@ -492,7 +489,7 @@
Attr* Pat guard:MatchGuard? '=>' Expr ','?
MatchGuard =
- 'if' ('let' Pat '=')? Expr
+ 'if' condition:Expr
ReturnExpr =
Attr* 'return' Expr?
@@ -500,6 +497,9 @@
YieldExpr =
Attr* 'yield' Expr?
+LetExpr =
+ Attr* 'let' Pat '=' Expr
+
AwaitExpr =
Attr* Expr '.' 'await'