Fix the eager token maps by re-mapping the textranges between the input and input expansion

This commit is contained in:
Lukas Wirth 2023-07-13 09:17:07 +02:00
parent 2366c16bf9
commit 6a7b905c86
18 changed files with 434 additions and 157 deletions

View file

@ -68,6 +68,21 @@ pub mod token_id {
Self::Subtree(Subtree { delimiter: Delimiter::unspecified(), token_trees: vec![] })
}
}
impl Subtree {
pub fn visit_ids(&mut self, f: &impl Fn(TokenId) -> TokenId) {
self.delimiter.open = f(self.delimiter.open);
self.delimiter.close = f(self.delimiter.close);
self.token_trees.iter_mut().for_each(|tt| match tt {
crate::TokenTree::Leaf(leaf) => match leaf {
crate::Leaf::Literal(it) => it.span = f(it.span),
crate::Leaf::Punct(it) => it.span = f(it.span),
crate::Leaf::Ident(it) => it.span = f(it.span),
},
crate::TokenTree::Subtree(s) => s.visit_ids(f),
})
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]