simplify parsing blocks a bit

This commit is contained in:
Aleksey Kladov 2019-03-17 13:14:17 +03:00
parent 7d3f48cdaf
commit a8271cb31f

View file

@ -43,13 +43,15 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
attributes::inner_attributes(p); attributes::inner_attributes(p);
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {
match p.current() {
// test nocontentexpr // test nocontentexpr
// fn foo(){ // fn foo(){
// ;;;some_expr();;;;{;;;};;;;Ok(()) // ;;;some_expr();;;;{;;;};;;;Ok(())
// } // }
SEMI => p.bump(), if p.current() == SEMI {
_ => { p.bump();
continue;
}
// test block_items // test block_items
// fn a() { fn b() {} } // fn a() { fn b() {} }
let m = p.start(); let m = p.start();
@ -57,7 +59,9 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
attributes::outer_attributes(p); attributes::outer_attributes(p);
if p.at(LET_KW) { if p.at(LET_KW) {
let_stmt(p, m); let_stmt(p, m);
} else { continue;
}
match items::maybe_item(p, items::ItemFlavor::Mod) { match items::maybe_item(p, items::ItemFlavor::Mod) {
items::MaybeItem::Item(kind) => { items::MaybeItem::Item(kind) => {
m.complete(p, kind); m.complete(p, kind);
@ -71,9 +75,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
items::MaybeItem::None => { items::MaybeItem::None => {
if has_attrs { if has_attrs {
m.abandon(p); m.abandon(p);
p.error( p.error("expected a let statement or an item after attributes in block");
"expected a let statement or an item after attributes in block",
);
} else { } else {
let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
if p.at(R_CURLY) { if p.at(R_CURLY) {
@ -104,9 +106,6 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
} }
} }
} }
}
}
}
// test let_stmt; // test let_stmt;
// fn foo() { // fn foo() {