aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/atom.rs34
-rw-r--r--src/syntax_kinds/generated.rs2
3 files changed, 30 insertions, 7 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index 8ce5ebc49..9f80b3ebf 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -135,6 +135,7 @@ Grammar(
135 "PATH_EXPR", 135 "PATH_EXPR",
136 "LAMBDA_EXPR", 136 "LAMBDA_EXPR",
137 "IF_EXPR", 137 "IF_EXPR",
138 "WHILE_EXPR",
138 "BLOCK_EXPR", 139 "BLOCK_EXPR",
139 "RETURN_EXPR", 140 "RETURN_EXPR",
140 "MATCH_EXPR", 141 "MATCH_EXPR",
diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs
index ad654df9e..6a0d47d82 100644
--- a/src/grammar/expressions/atom.rs
+++ b/src/grammar/expressions/atom.rs
@@ -29,7 +29,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
29pub(super) const ATOM_EXPR_FIRST: TokenSet = 29pub(super) const ATOM_EXPR_FIRST: TokenSet =
30 token_set_union![ 30 token_set_union![
31 LITERAL_FIRST, 31 LITERAL_FIRST,
32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW, 32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW,
33 IDENT, SELF_KW, SUPER_KW, COLONCOLON ], 33 IDENT, SELF_KW, SUPER_KW, COLONCOLON ],
34 ]; 34 ];
35 35
@@ -47,6 +47,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
47 PIPE => lambda_expr(p), 47 PIPE => lambda_expr(p),
48 MOVE_KW if la == PIPE => lambda_expr(p), 48 MOVE_KW if la == PIPE => lambda_expr(p),
49 IF_KW => if_expr(p), 49 IF_KW => if_expr(p),
50 WHILE_KW => while_expr(p),
50 MATCH_KW => match_expr(p), 51 MATCH_KW => match_expr(p),
51 UNSAFE_KW if la == L_CURLY => block_expr(p), 52 UNSAFE_KW if la == L_CURLY => block_expr(p),
52 L_CURLY => block_expr(p), 53 L_CURLY => block_expr(p),
@@ -97,7 +98,8 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
97fn if_expr(p: &mut Parser) -> CompletedMarker { 98fn if_expr(p: &mut Parser) -> CompletedMarker {
98 assert!(p.at(IF_KW)); 99 assert!(p.at(IF_KW));
99 let m = p.start(); 100 let m = p.start();
100 if_head(p); 101 p.bump();
102 cond(p);
101 block(p); 103 block(p);
102 if p.at(ELSE_KW) { 104 if p.at(ELSE_KW) {
103 p.bump(); 105 p.bump();
@@ -110,10 +112,28 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
110 m.complete(p, IF_EXPR) 112 m.complete(p, IF_EXPR)
111} 113}
112 114
113fn if_head(p: &mut Parser) { 115// test while_expr
114 assert!(p.at(IF_KW)); 116// fn foo() {
117// while true {};
118// while let Some(x) = it.next() {};
119// }
120fn while_expr(p: &mut Parser) -> CompletedMarker {
121 assert!(p.at(WHILE_KW));
122 let m = p.start();
115 p.bump(); 123 p.bump();
116 expr_no_struct(p); 124 cond(p);
125 block(p);
126 m.complete(p, WHILE_EXPR)
127}
128
129// test cond
130// fn foo() { if let Some(_) = None {} }
131fn cond(p: &mut Parser) {
132 if p.eat(LET_KW) {
133 patterns::pattern(p);
134 p.expect(EQ);
135 }
136 expr_no_struct(p)
117} 137}
118 138
119// test match_expr 139// test match_expr
@@ -152,8 +172,8 @@ fn match_arm(p: &mut Parser) {
152 break; 172 break;
153 } 173 }
154 } 174 }
155 if p.at(IF_KW) { 175 if p.eat(IF_KW) {
156 if_head(p) 176 expr_no_struct(p);
157 } 177 }
158 p.expect(FAT_ARROW); 178 p.expect(FAT_ARROW);
159 expr(p); 179 expr(p);
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 7bdd0267c..1d3d3b9c1 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -125,6 +125,7 @@ pub enum SyntaxKind {
125 PATH_EXPR, 125 PATH_EXPR,
126 LAMBDA_EXPR, 126 LAMBDA_EXPR,
127 IF_EXPR, 127 IF_EXPR,
128 WHILE_EXPR,
128 BLOCK_EXPR, 129 BLOCK_EXPR,
129 RETURN_EXPR, 130 RETURN_EXPR,
130 MATCH_EXPR, 131 MATCH_EXPR,
@@ -343,6 +344,7 @@ impl SyntaxKind {
343 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" }, 344 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" },
344 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, 345 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
345 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, 346 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
347 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" },
346 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, 348 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" },
347 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, 349 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" },
348 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" }, 350 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" },