aboutsummaryrefslogtreecommitdiff
path: root/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'src/grammar')
-rw-r--r--src/grammar/expressions.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/grammar/expressions.rs b/src/grammar/expressions.rs
index e2be13a77..ed9236b02 100644
--- a/src/grammar/expressions.rs
+++ b/src/grammar/expressions.rs
@@ -145,14 +145,16 @@ fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
145 return Some(path_expr(p)); 145 return Some(path_expr(p));
146 } 146 }
147 147
148 match p.current() { 148 let done = match p.current() {
149 L_PAREN => Some(tuple_expr(p)), 149 L_PAREN => tuple_expr(p),
150 PIPE => Some(lambda_expr(p)), 150 PIPE => lambda_expr(p),
151 IF_KW => if_expr(p),
151 _ => { 152 _ => {
152 p.err_and_bump("expected expression"); 153 p.err_and_bump("expected expression");
153 None 154 return None;
154 } 155 }
155 } 156 };
157 Some(done)
156} 158}
157 159
158fn tuple_expr(p: &mut Parser) -> CompletedMarker { 160fn tuple_expr(p: &mut Parser) -> CompletedMarker {
@@ -182,6 +184,29 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
182 m.complete(p, LAMBDA_EXPR) 184 m.complete(p, LAMBDA_EXPR)
183} 185}
184 186
187// test if_expr
188// fn foo() {
189// if true {};
190// if true {} else {};
191// if true {} else if false {} else {}
192// }
193fn if_expr(p: &mut Parser) -> CompletedMarker {
194 assert!(p.at(IF_KW));
195 let m = p.start();
196 p.bump();
197 expr(p);
198 block(p);
199 if p.at(ELSE_KW) {
200 p.bump();
201 if p.at(IF_KW) {
202 if_expr(p);
203 } else {
204 block(p);
205 }
206 }
207 m.complete(p, IF_EXPR)
208}
209
185// test call_expr 210// test call_expr
186// fn foo() { 211// fn foo() {
187// let _ = f(); 212// let _ = f();