From 0ab1e255ee5c70aedd4d243e0e11109fc4bbcef2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Aug 2018 16:11:40 +0300 Subject: Generalize blocklike --- src/grammar/items/mod.rs | 19 +++++++------------ src/grammar/mod.rs | 6 ++++++ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/grammar/items/mod.rs b/src/grammar/items/mod.rs index 657078765..83f1833b5 100644 --- a/src/grammar/items/mod.rs +++ b/src/grammar/items/mod.rs @@ -27,8 +27,8 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { MaybeItem::None => { if paths::is_path_start(p) { match macro_call(p) { - MacroFlavor::Curly => (), - MacroFlavor::NonCurly => { + BlockLike::Block => (), + BlockLike::NotBlock => { p.expect(SEMI); } } @@ -277,32 +277,27 @@ fn mod_item(p: &mut Parser) { } } -pub(super) enum MacroFlavor { - Curly, - NonCurly, -} - -fn macro_call(p: &mut Parser) -> MacroFlavor { +fn macro_call(p: &mut Parser) -> BlockLike { assert!(paths::is_path_start(p)); paths::use_path(p); macro_call_after_excl(p) } -pub(super) fn macro_call_after_excl(p: &mut Parser) -> MacroFlavor { +pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { p.expect(EXCL); p.eat(IDENT); let flavor = match p.current() { L_CURLY => { token_tree(p); - MacroFlavor::Curly + BlockLike::Block } L_PAREN | L_BRACK => { token_tree(p); - MacroFlavor::NonCurly + BlockLike::NotBlock } _ => { p.error("expected `{`, `[`, `(`"); - MacroFlavor::NonCurly + BlockLike::NotBlock }, }; diff --git a/src/grammar/mod.rs b/src/grammar/mod.rs index b558da477..1b997d861 100644 --- a/src/grammar/mod.rs +++ b/src/grammar/mod.rs @@ -43,6 +43,12 @@ pub(crate) fn file(p: &mut Parser) { file.complete(p, FILE); } + +enum BlockLike { + Block, + NotBlock, +} + fn visibility(p: &mut Parser) { if p.at(PUB_KW) { let vis = p.start(); -- cgit v1.2.3