Refactor maybe_item to use Marker argument

This commit is contained in:
pcpthm 2019-03-17 22:04:25 +09:00
parent aea9c98f53
commit e570267515
2 changed files with 75 additions and 86 deletions

View file

@ -54,7 +54,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
// test block_items
// fn a() { fn b() {} }
let m = p.start();
let mut m = p.start();
let has_attrs = p.at(POUND);
attributes::outer_attributes(p);
if p.at(LET_KW) {
@ -62,47 +62,41 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
continue;
}
match items::maybe_item(p, items::ItemFlavor::Mod) {
items::MaybeItem::Item(kind) => {
m.complete(p, kind);
}
items::MaybeItem::Modifiers => {
m = match items::maybe_item(p, m, items::ItemFlavor::Mod) {
Some(m) => m,
None => continue,
};
// test pub_expr
// fn foo() { pub 92; } //FIXME
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);
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 {
// 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 {
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);
}
p.expect(SEMI);
}
m.complete(p, EXPR_STMT);
}
}
}