aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/expressions/mod.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/mod.rs
parent4d293003964c8f9fabadb1ceb77eab29c0438de3 (diff)
nodes for blocks
Diffstat (limited to 'crates/libsyntax2/src/grammar/expressions/mod.rs')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/mod.rs67
1 files changed, 60 insertions, 7 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs
index 9ce0c1f8f..e133c1d9b 100644
--- a/crates/libsyntax2/src/grammar/expressions/mod.rs
+++ b/crates/libsyntax2/src/grammar/expressions/mod.rs
@@ -26,11 +26,62 @@ fn expr_no_struct(p: &mut Parser) {
26// fn c() { 1; 2; } 26// fn c() { 1; 2; }
27// fn d() { 1; 2 } 27// fn d() { 1; 2 }
28pub(super) fn block(p: &mut Parser) { 28pub(super) fn block(p: &mut Parser) {
29 if !p.at(L_CURLY) { 29 assert!(p.at(L_CURLY));
30 p.error("expected block"); 30 let m = p.start();
31 return; 31 p.bump();
32 while !p.at(EOF) && !p.at(R_CURLY) {
33 match p.current() {
34 LET_KW => let_stmt(p),
35 _ => {
36 // test block_items
37 // fn a() { fn b() {} }
38 let m = p.start();
39 match items::maybe_item(p, items::ItemFlavor::Mod) {
40 items::MaybeItem::Item(kind) => {
41 m.complete(p, kind);
42 }
43 items::MaybeItem::Modifiers => {
44 m.abandon(p);
45 p.error("expected an item");
46 }
47 // test pub_expr
48 // fn foo() { pub 92; } //FIXME
49 items::MaybeItem::None => {
50 let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
51 if p.eat(SEMI) || (is_blocklike && !p.at(R_CURLY)) {
52 m.complete(p, EXPR_STMT);
53 } else {
54 m.abandon(p);
55 }
56 }
57 }
58 }
59 }
60 }
61 p.expect(R_CURLY);
62 m.complete(p, BLOCK);
63
64 // test let_stmt;
65 // fn foo() {
66 // let a;
67 // let b: i32;
68 // let c = 92;
69 // let d: i32 = 92;
70 // }
71 fn let_stmt(p: &mut Parser) {
72 assert!(p.at(LET_KW));
73 let m = p.start();
74 p.bump();
75 patterns::pattern(p);
76 if p.at(COLON) {
77 types::ascription(p);
78 }
79 if p.eat(EQ) {
80 expressions::expr(p);
81 }
82 p.expect(SEMI);
83 m.complete(p, LET_STMT);
32 } 84 }
33 atom::block_expr(p);
34} 85}
35 86
36#[derive(Clone, Copy)] 87#[derive(Clone, Copy)]
@@ -339,7 +390,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
339 paths::expr_path(p); 390 paths::expr_path(p);
340 match p.current() { 391 match p.current() {
341 L_CURLY if !r.forbid_structs => { 392 L_CURLY if !r.forbid_structs => {
342 struct_lit(p); 393 named_field_list(p);
343 m.complete(p, STRUCT_LIT) 394 m.complete(p, STRUCT_LIT)
344 } 395 }
345 EXCL => { 396 EXCL => {
@@ -356,8 +407,9 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
356// S { x, y: 32, }; 407// S { x, y: 32, };
357// S { x, y: 32, ..Default::default() }; 408// S { x, y: 32, ..Default::default() };
358// } 409// }
359fn struct_lit(p: &mut Parser) { 410fn named_field_list(p: &mut Parser) {
360 assert!(p.at(L_CURLY)); 411 assert!(p.at(L_CURLY));
412 let m = p.start();
361 p.bump(); 413 p.bump();
362 while !p.at(EOF) && !p.at(R_CURLY) { 414 while !p.at(EOF) && !p.at(R_CURLY) {
363 match p.current() { 415 match p.current() {
@@ -367,7 +419,7 @@ fn struct_lit(p: &mut Parser) {
367 if p.eat(COLON) { 419 if p.eat(COLON) {
368 expr(p); 420 expr(p);
369 } 421 }
370 m.complete(p, STRUCT_LIT_FIELD); 422 m.complete(p, NAMED_FIELD);
371 } 423 }
372 DOTDOT => { 424 DOTDOT => {
373 p.bump(); 425 p.bump();
@@ -380,4 +432,5 @@ fn struct_lit(p: &mut Parser) {
380 } 432 }
381 } 433 }
382 p.expect(R_CURLY); 434 p.expect(R_CURLY);
435 m.complete(p, NAMED_FIELD_LIST);
383} 436}