use debug::DebugWithContext;
pub mod db;
pub mod debug;
pub mod lexer;
pub struct Spanned<T> {
pub loc: Loc,
pub value: T,
}
impl<C, T: DebugWithContext<C>> DebugWithContext<C> for Spanned<T> {
fn fmt(&self, ctx: &C, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.value.fmt(ctx, f)
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Loc {
pub start: u32,
pub end: u32,
}
impl Loc {
pub fn start(&self) -> usize {
self.start.try_into().unwrap()
}
pub fn end(&self) -> usize {
self.end.try_into().unwrap()
}
pub fn span(&self, other: Loc) -> Loc {
Loc {
start: self.start,
end: other.end,
}
}
pub fn with<T>(self, value: T) -> Spanned<T> {
Spanned { loc: self, value }
}
}