Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/lib.rs')
| -rw-r--r-- | crates/mbe/src/lib.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index a043e8222d..d20641062c 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -107,6 +107,9 @@ pub struct DeclarativeMacro { rules: Vec<Rule>, /// Highest id of the token we have in TokenMap shift: Shift, + // This is used for correctly determining the behavior of the pat fragment + // FIXME: This should be tracked by hygiene of the fragment identifier! + is_2021: bool, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -190,7 +193,10 @@ pub enum Origin { impl DeclarativeMacro { /// The old, `macro_rules! m {}` flavor. - pub fn parse_macro_rules(tt: &tt::Subtree) -> Result<DeclarativeMacro, ParseError> { + pub fn parse_macro_rules( + tt: &tt::Subtree, + is_2021: bool, + ) -> Result<DeclarativeMacro, ParseError> { // Note: this parsing can be implemented using mbe machinery itself, by // matching against `$($lhs:tt => $rhs:tt);*` pattern, but implementing // manually seems easier. @@ -211,11 +217,11 @@ impl DeclarativeMacro { validate(lhs)?; } - Ok(DeclarativeMacro { rules, shift: Shift::new(tt) }) + Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 }) } /// The new, unstable `macro m {}` flavor. - pub fn parse_macro2(tt: &tt::Subtree) -> Result<DeclarativeMacro, ParseError> { + pub fn parse_macro2(tt: &tt::Subtree, is_2021: bool) -> Result<DeclarativeMacro, ParseError> { let mut src = TtIter::new(tt); let mut rules = Vec::new(); @@ -244,14 +250,14 @@ impl DeclarativeMacro { validate(lhs)?; } - Ok(DeclarativeMacro { rules, shift: Shift::new(tt) }) + Ok(DeclarativeMacro { rules, shift: Shift::new(tt), is_2021 }) } pub fn expand(&self, tt: &tt::Subtree) -> ExpandResult<tt::Subtree> { // apply shift let mut tt = tt.clone(); self.shift.shift_all(&mut tt); - expander::expand_rules(&self.rules, &tt) + expander::expand_rules(&self.rules, &tt, self.is_2021) } pub fn map_id_down(&self, id: tt::TokenId) -> tt::TokenId { |