diff options
author | DJMcNab <[email protected]> | 2019-01-26 21:35:03 +0000 |
---|---|---|
committer | DJMcNab <[email protected]> | 2019-01-26 21:35:03 +0000 |
commit | 55a3e21ac4cd24dd7979a44c37cd1e7a3d1b85fd (patch) | |
tree | 082a2cfaba26d870e564954ff6c74d6f0ece732d /crates/ra_syntax/src/grammar | |
parent | 0974e6abeb9c3f047e21c3e23769b93c9e7dcaf3 (diff) |
Support attributes on let statements
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions.rs | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 1604d9b5a..0b2f7b116 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs | |||
@@ -54,6 +54,7 @@ pub(crate) fn block(p: &mut Parser) { | |||
54 | _ => { | 54 | _ => { |
55 | // test block_items | 55 | // test block_items |
56 | // fn a() { fn b() {} } | 56 | // fn a() { fn b() {} } |
57 | let has_attrs = p.at(POUND); | ||
57 | let m = p.start(); | 58 | let m = p.start(); |
58 | match items::maybe_item(p, items::ItemFlavor::Mod) { | 59 | match items::maybe_item(p, items::ItemFlavor::Mod) { |
59 | items::MaybeItem::Item(kind) => { | 60 | items::MaybeItem::Item(kind) => { |
@@ -66,30 +67,39 @@ pub(crate) fn block(p: &mut Parser) { | |||
66 | // test pub_expr | 67 | // test pub_expr |
67 | // fn foo() { pub 92; } //FIXME | 68 | // fn foo() { pub 92; } //FIXME |
68 | items::MaybeItem::None => { | 69 | items::MaybeItem::None => { |
69 | let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; | 70 | if has_attrs { |
70 | if p.at(R_CURLY) { | ||
71 | m.abandon(p); | 71 | m.abandon(p); |
72 | if p.at(LET_KW) { | ||
73 | let_stmt(p); | ||
74 | } else { | ||
75 | p.error("expected a let statement"); | ||
76 | } | ||
72 | } else { | 77 | } else { |
73 | // test no_semi_after_block | 78 | let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; |
74 | // fn foo() { | 79 | if p.at(R_CURLY) { |
75 | // if true {} | 80 | m.abandon(p); |
76 | // loop {} | ||
77 | // match () {} | ||
78 | // while true {} | ||
79 | // for _ in () {} | ||
80 | // {} | ||
81 | // {} | ||
82 | // macro_rules! test { | ||
83 | // () => {} | ||
84 | // } | ||
85 | // test!{} | ||
86 | // } | ||
87 | if is_blocklike { | ||
88 | p.eat(SEMI); | ||
89 | } else { | 81 | } else { |
90 | p.expect(SEMI); | 82 | // test no_semi_after_block |
83 | // fn foo() { | ||
84 | // if true {} | ||
85 | // loop {} | ||
86 | // match () {} | ||
87 | // while true {} | ||
88 | // for _ in () {} | ||
89 | // {} | ||
90 | // {} | ||
91 | // macro_rules! test { | ||
92 | // () => {} | ||
93 | // } | ||
94 | // test!{} | ||
95 | // } | ||
96 | if is_blocklike { | ||
97 | p.eat(SEMI); | ||
98 | } else { | ||
99 | p.expect(SEMI); | ||
100 | } | ||
101 | m.complete(p, EXPR_STMT); | ||
91 | } | 102 | } |
92 | m.complete(p, EXPR_STMT); | ||
93 | } | 103 | } |
94 | } | 104 | } |
95 | } | 105 | } |