Fix eager macro input spans being discarded

This commit is contained in:
Lukas Wirth 2023-12-01 16:29:58 +01:00
parent c11737cd63
commit efa67294ed
5 changed files with 101 additions and 94 deletions

View file

@ -17,16 +17,16 @@ pub struct TokenMap<S: Span> {
}
impl<S: Span> TokenMap<S> {
pub(crate) fn empty() -> Self {
pub fn empty() -> Self {
Self { spans: Vec::new() }
}
pub(crate) fn finish(&mut self) {
pub fn finish(&mut self) {
assert!(self.spans.iter().tuple_windows().all(|(a, b)| a.0 < b.0));
self.spans.shrink_to_fit();
}
pub(crate) fn push(&mut self, offset: TextSize, span: S) {
pub fn push(&mut self, offset: TextSize, span: S) {
self.spans.push((offset, span));
}
@ -54,4 +54,8 @@ impl<S: Span> TokenMap<S> {
let end_entry = self.spans[start_entry..].partition_point(|&(it, _)| it <= end); // FIXME: this might be wrong?
(&self.spans[start_entry..][..end_entry]).iter().map(|&(_, s)| s)
}
pub fn iter(&self) -> impl Iterator<Item = (TextSize, S)> + '_ {
self.spans.iter().copied()
}
}