From 76290afa9a654c9d2325acd644133c71a941faa9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Sep 2019 23:39:29 +0300 Subject: minor cleanup --- crates/ra_mbe/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 41720df79..a0904323c 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -52,6 +52,9 @@ pub(crate) struct Rule { impl MacroRules { pub fn parse(tt: &tt::Subtree) -> Result { + // Note: this parsing can be implemented using mbe machinery itself, by + // matching against `$($lhs:tt => $rhs:tt);*` pattern, but implementing + // manually seems easier. let mut src = TtIter::new(tt); let mut rules = Vec::new(); while src.len() > 0 { @@ -64,6 +67,11 @@ impl MacroRules { break; } } + + for rule in rules.iter() { + validate(&rule.lhs)?; + } + Ok(MacroRules { rules }) } pub fn expand(&self, tt: &tt::Subtree) -> Result { @@ -77,7 +85,6 @@ impl Rule { .expect_subtree() .map_err(|()| ParseError::Expected("expected subtree".to_string()))? .clone(); - validate(&lhs)?; lhs.delimiter = tt::Delimiter::None; src.expect_char('=').map_err(|()| ParseError::Expected("expected `=`".to_string()))?; src.expect_char('>').map_err(|()| ParseError::Expected("expected `>`".to_string()))?; -- cgit v1.2.3