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,65 +43,64 @@ 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(()) // }
// } if p.current() == SEMI {
SEMI => p.bump(), p.bump();
_ => { continue;
// test block_items }
// fn a() { fn b() {} }
let m = p.start(); // test block_items
let has_attrs = p.at(POUND); // fn a() { fn b() {} }
attributes::outer_attributes(p); let m = p.start();
if p.at(LET_KW) { let has_attrs = p.at(POUND);
let_stmt(p, m); 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 { } else {
match items::maybe_item(p, items::ItemFlavor::Mod) { let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block;
items::MaybeItem::Item(kind) => { if p.at(R_CURLY) {
m.complete(p, kind); m.abandon(p);
} } else {
items::MaybeItem::Modifiers => { // test no_semi_after_block
m.abandon(p); // fn foo() {
p.error("expected an item"); // if true {}
} // loop {}
// test pub_expr // match () {}
// fn foo() { pub 92; } //FIXME // while true {}
items::MaybeItem::None => { // for _ in () {}
if has_attrs { // {}
m.abandon(p); // {}
p.error( // macro_rules! test {
"expected a let statement or an item after attributes in block", // () => {}
); // }
} else { // test!{}
let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; // }
if p.at(R_CURLY) { if is_blocklike {
m.abandon(p); p.eat(SEMI);
} else { } else {
// test no_semi_after_block p.expect(SEMI);
// 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);
} }
} }
} }