aboutsummaryrefslogtreecommitdiff
path: root/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/grammar')
-rw-r--r--src/grammar/expressions/atom.rs34
1 files changed, 27 insertions, 7 deletions
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);