987: Refactor maybe_item to use Marker argument r=pcpthm a=pcpthm

As suggested at <https://github.com/rust-analyzer/rust-analyzer/pull/980#issuecomment-473659745>.
For expression paring functions, changing signature
- from `fn(&mut Parser) -> Option<CompletedMarker>` to `fn(&mut Parser, Marker) -> Result<CompletedMarker, Marker>`
- from `fn(&mut Parser) -> CompletedMarker` to `fn(&mut Parser, Marker) -> CompletedMarker`
is my plan.

Co-authored-by: pcpthm <pcpthm@gmail.com>
This commit is contained in:
bors[bot] 2019-03-18 04:16:20 +00:00
commit 4c1ea0b628
2 changed files with 70 additions and 84 deletions

View file

@ -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 => {
let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) {
Ok(()) => continue,
Err(m) => m,
};
// 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);
}
}
}