From 519ee21bcb754bf972b5f127f17035c5efe196d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 27 Dec 2021 15:39:17 +0300 Subject: [PATCH] internal: move block to prefix entry point --- crates/mbe/src/expander/matcher.rs | 12 ++++++------ crates/parser/src/grammar.rs | 4 ++++ crates/parser/src/lib.rs | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index 3636979d00..621ff791d4 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -695,7 +695,11 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult ParserEntryPoint::Type, "pat" | "pat_param" => ParserEntryPoint::Pattern, // FIXME: edition2021 "stmt" => ParserEntryPoint::Statement, - "block" => ParserEntryPoint::Block, + "block" => { + return input + .expect_fragment2(parser::PrefixEntryPoint::Block) + .map(|tt| tt.map(Fragment::Tokens)); + } "meta" => ParserEntryPoint::MetaItem, "item" => ParserEntryPoint::Item, _ => { @@ -725,7 +729,7 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult Ok(input.eat_vis()), + "vis" => Ok(input.expect_fragment2(parser::PrefixEntryPoint::Vis).value), _ => Err(ExpandError::UnexpectedToken), }; return tt_result.map(|it| it.map(Fragment::Tokens)).into(); @@ -894,10 +898,6 @@ impl<'a> TtIter<'a> { .into()) } - fn eat_vis(&mut self) -> Option { - self.expect_fragment2(parser::PrefixEntryPoint::Vis).value - } - fn eat_char(&mut self, c: char) -> Option { let mut fork = self.clone(); match fork.expect_char(c) { diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 1c58f217a3..cf17e8453b 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -53,6 +53,10 @@ pub(crate) mod entry { pub(crate) fn vis(p: &mut Parser) { let _ = opt_visibility(p, false); } + + pub(crate) fn block(p: &mut Parser) { + expressions::block_expr(p); + } } } diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index f4ce5a21e8..778c8b10ec 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -52,12 +52,14 @@ pub use crate::{ #[derive(Debug)] pub enum PrefixEntryPoint { Vis, + Block, } impl PrefixEntryPoint { pub fn parse(&self, input: &Input) -> Output { let entry_point: fn(&'_ mut parser::Parser) = match self { PrefixEntryPoint::Vis => grammar::entry::prefix::vis, + PrefixEntryPoint::Block => grammar::entry::prefix::block, }; let mut p = parser::Parser::new(input); entry_point(&mut p);