still works

This commit is contained in:
nora 2022-06-25 18:59:23 +02:00
parent 955effd621
commit f53c054a9a
5 changed files with 200 additions and 149 deletions

View file

@ -8,6 +8,8 @@ mod parser;
mod pre;
mod token;
pub type Spanned<T> = (T, Span);
#[derive(PartialEq, Eq, Clone, Copy, Default)]
pub struct Span {
pub start: usize,
@ -22,6 +24,16 @@ impl Span {
pub fn extend(&self, rhs: Self) -> Self {
Self::start_end(self.start, rhs.end)
}
pub fn extend_option(&self, rhs: Option<Self>) -> Self {
rhs.map(|s| self.extend(s)).unwrap_or(*self)
}
pub fn span_of_spanned_list<T>(list: &[Spanned<T>]) -> Option<Span> {
list.iter().fold(None, |old_span, &(_, span)| {
Some(old_span.map(|s| s.extend(span)).unwrap_or(span))
})
}
}
impl dbg_pls::DebugPls for Span {