From 55a3e21ac4cd24dd7979a44c37cd1e7a3d1b85fd Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 26 Jan 2019 21:35:03 +0000 Subject: Support attributes on let statements --- crates/ra_syntax/src/grammar/expressions.rs | 50 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'crates/ra_syntax/src/grammar/expressions.rs') 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) { _ => { // test block_items // fn a() { fn b() {} } + let has_attrs = p.at(POUND); let m = p.start(); match items::maybe_item(p, items::ItemFlavor::Mod) { items::MaybeItem::Item(kind) => { @@ -66,30 +67,39 @@ pub(crate) fn block(p: &mut Parser) { // test pub_expr // fn foo() { pub 92; } //FIXME items::MaybeItem::None => { - let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; - if p.at(R_CURLY) { + if has_attrs { m.abandon(p); + if p.at(LET_KW) { + let_stmt(p); + } else { + p.error("expected a let statement"); + } } else { - // test no_semi_after_block - // fn foo() { - // if true {} - // loop {} - // match () {} - // while true {} - // for _ in () {} - // {} - // {} - // macro_rules! test { - // () => {} - // } - // test!{} - // } - if is_blocklike { - p.eat(SEMI); + let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; + if p.at(R_CURLY) { + m.abandon(p); } else { - p.expect(SEMI); + // test no_semi_after_block + // fn foo() { + // if true {} + // loop {} + // match () {} + // while true {} + // for _ in () {} + // {} + // {} + // macro_rules! test { + // () => {} + // } + // test!{} + // } + if is_blocklike { + p.eat(SEMI); + } else { + p.expect(SEMI); + } + m.complete(p, EXPR_STMT); } - m.complete(p, EXPR_STMT); } } } -- cgit v1.2.3