aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/lib.rs9
1 files changed, 8 insertions, 1 deletions
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 {
52 52
53impl MacroRules { 53impl MacroRules {
54 pub fn parse(tt: &tt::Subtree) -> Result<MacroRules, ParseError> { 54 pub fn parse(tt: &tt::Subtree) -> Result<MacroRules, ParseError> {
55 // Note: this parsing can be implemented using mbe machinery itself, by
56 // matching against `$($lhs:tt => $rhs:tt);*` pattern, but implementing
57 // manually seems easier.
55 let mut src = TtIter::new(tt); 58 let mut src = TtIter::new(tt);
56 let mut rules = Vec::new(); 59 let mut rules = Vec::new();
57 while src.len() > 0 { 60 while src.len() > 0 {
@@ -64,6 +67,11 @@ impl MacroRules {
64 break; 67 break;
65 } 68 }
66 } 69 }
70
71 for rule in rules.iter() {
72 validate(&rule.lhs)?;
73 }
74
67 Ok(MacroRules { rules }) 75 Ok(MacroRules { rules })
68 } 76 }
69 pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree, ExpandError> { 77 pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree, ExpandError> {
@@ -77,7 +85,6 @@ impl Rule {
77 .expect_subtree() 85 .expect_subtree()
78 .map_err(|()| ParseError::Expected("expected subtree".to_string()))? 86 .map_err(|()| ParseError::Expected("expected subtree".to_string()))?
79 .clone(); 87 .clone();
80 validate(&lhs)?;
81 lhs.delimiter = tt::Delimiter::None; 88 lhs.delimiter = tt::Delimiter::None;
82 src.expect_char('=').map_err(|()| ParseError::Expected("expected `=`".to_string()))?; 89 src.expect_char('=').map_err(|()| ParseError::Expected("expected `=`".to_string()))?;
83 src.expect_char('>').map_err(|()| ParseError::Expected("expected `>`".to_string()))?; 90 src.expect_char('>').map_err(|()| ParseError::Expected("expected `>`".to_string()))?;