From a8271cb31f3b16f64a5720f0cc317b8d1cb8fcd8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 Mar 2019 13:14:17 +0300 Subject: simplify parsing blocks a bit --- crates/ra_parser/src/grammar/expressions.rs | 113 ++++++++++++++-------------- 1 file changed, 56 insertions(+), 57 deletions(-) (limited to 'crates/ra_parser/src/grammar') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 70c71a8e1..d1f27dadf 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -43,65 +43,64 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { attributes::inner_attributes(p); while !p.at(EOF) && !p.at(R_CURLY) { - match p.current() { - // test nocontentexpr - // fn foo(){ - // ;;;some_expr();;;;{;;;};;;;Ok(()) - // } - SEMI => p.bump(), - _ => { - // test block_items - // fn a() { fn b() {} } - let m = p.start(); - let has_attrs = p.at(POUND); - attributes::outer_attributes(p); - if p.at(LET_KW) { - let_stmt(p, m); + // test nocontentexpr + // fn foo(){ + // ;;;some_expr();;;;{;;;};;;;Ok(()) + // } + if p.current() == SEMI { + p.bump(); + continue; + } + + // test block_items + // fn a() { fn b() {} } + let m = p.start(); + let has_attrs = p.at(POUND); + attributes::outer_attributes(p); + if p.at(LET_KW) { + let_stmt(p, m); + continue; + } + + match items::maybe_item(p, items::ItemFlavor::Mod) { + items::MaybeItem::Item(kind) => { + m.complete(p, kind); + } + items::MaybeItem::Modifiers => { + m.abandon(p); + p.error("expected an item"); + } + // test pub_expr + // fn foo() { pub 92; } //FIXME + items::MaybeItem::None => { + if has_attrs { + m.abandon(p); + p.error("expected a let statement or an item after attributes in block"); } else { - match items::maybe_item(p, items::ItemFlavor::Mod) { - items::MaybeItem::Item(kind) => { - m.complete(p, kind); - } - items::MaybeItem::Modifiers => { - m.abandon(p); - p.error("expected an item"); - } - // test pub_expr - // fn foo() { pub 92; } //FIXME - items::MaybeItem::None => { - if has_attrs { - m.abandon(p); - p.error( - "expected a let statement or an item after attributes in block", - ); - } else { - let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; - if p.at(R_CURLY) { - m.abandon(p); - } 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); - } else { - p.expect(SEMI); - } - m.complete(p, EXPR_STMT); - } - } + let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; + if p.at(R_CURLY) { + m.abandon(p); + } 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); + } else { + p.expect(SEMI); } + m.complete(p, EXPR_STMT); } } } -- cgit v1.2.3