aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/expressions/atom.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-24 17:27:30 +0100
committerAleksey Kladov <[email protected]>2018-08-24 17:27:30 +0100
commit7edab6ae6b4c5d0c411e88f10e923b91dca31de3 (patch)
tree4c17856285f568c56adb7c02024ef80e821dd367 /crates/libsyntax2/src/grammar/expressions/atom.rs
parent4d293003964c8f9fabadb1ceb77eab29c0438de3 (diff)
nodes for blocks
Diffstat (limited to 'crates/libsyntax2/src/grammar/expressions/atom.rs')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs73
1 files changed, 18 insertions, 55 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs
index 9d98340af..417366026 100644
--- a/crates/libsyntax2/src/grammar/expressions/atom.rs
+++ b/crates/libsyntax2/src/grammar/expressions/atom.rs
@@ -148,7 +148,11 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
148 p.eat(MOVE_KW); 148 p.eat(MOVE_KW);
149 params::param_list_opt_types(p); 149 params::param_list_opt_types(p);
150 if opt_fn_ret_type(p) { 150 if opt_fn_ret_type(p) {
151 block(p); 151 if p.at(L_CURLY) {
152 block(p);
153 } else {
154 p.error("expected a block");
155 }
152 } else { 156 } else {
153 expr(p); 157 expr(p);
154 } 158 }
@@ -254,6 +258,17 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
254 let m = p.start(); 258 let m = p.start();
255 p.bump(); 259 p.bump();
256 expr_no_struct(p); 260 expr_no_struct(p);
261 if p.at(L_CURLY) {
262 match_arm_list(p);
263 } else {
264 p.error("expected `{`")
265 }
266 m.complete(p, MATCH_EXPR)
267}
268
269fn match_arm_list(p: &mut Parser) {
270 assert!(p.at(L_CURLY));
271 let m = p.start();
257 p.eat(L_CURLY); 272 p.eat(L_CURLY);
258 while !p.at(EOF) && !p.at(R_CURLY) { 273 while !p.at(EOF) && !p.at(R_CURLY) {
259 // test match_arms_commas 274 // test match_arms_commas
@@ -271,7 +286,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
271 } 286 }
272 } 287 }
273 p.expect(R_CURLY); 288 p.expect(R_CURLY);
274 m.complete(p, MATCH_EXPR) 289 m.complete(p, MATCH_ARM_LIST);
275} 290}
276 291
277// test match_arm 292// test match_arm
@@ -307,62 +322,10 @@ pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker {
307 assert!(p.at(L_CURLY) || p.at(UNSAFE_KW) && p.nth(1) == L_CURLY); 322 assert!(p.at(L_CURLY) || p.at(UNSAFE_KW) && p.nth(1) == L_CURLY);
308 let m = p.start(); 323 let m = p.start();
309 p.eat(UNSAFE_KW); 324 p.eat(UNSAFE_KW);
310 p.bump(); 325 block(p);
311 while !p.at(EOF) && !p.at(R_CURLY) {
312 match p.current() {
313 LET_KW => let_stmt(p),
314 _ => {
315 // test block_items
316 // fn a() { fn b() {} }
317 let m = p.start();
318 match items::maybe_item(p, items::ItemFlavor::Mod) {
319 items::MaybeItem::Item(kind) => {
320 m.complete(p, kind);
321 }
322 items::MaybeItem::Modifiers => {
323 m.abandon(p);
324 p.error("expected an item");
325 }
326 // test pub_expr
327 // fn foo() { pub 92; } //FIXME
328 items::MaybeItem::None => {
329 let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
330 if p.eat(SEMI) || (is_blocklike && !p.at(R_CURLY)) {
331 m.complete(p, EXPR_STMT);
332 } else {
333 m.abandon(p);
334 }
335 }
336 }
337 }
338 }
339 }
340 p.expect(R_CURLY);
341 m.complete(p, BLOCK_EXPR) 326 m.complete(p, BLOCK_EXPR)
342} 327}
343 328
344// test let_stmt;
345// fn foo() {
346// let a;
347// let b: i32;
348// let c = 92;
349// let d: i32 = 92;
350// }
351fn let_stmt(p: &mut Parser) {
352 assert!(p.at(LET_KW));
353 let m = p.start();
354 p.bump();
355 patterns::pattern(p);
356 if p.at(COLON) {
357 types::ascription(p);
358 }
359 if p.eat(EQ) {
360 expressions::expr(p);
361 }
362 p.expect(SEMI);
363 m.complete(p, LET_STMT);
364}
365
366// test return_expr 329// test return_expr
367// fn foo() { 330// fn foo() {
368// return; 331// return;