use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)]
pub struct Location {
pub line: u64,
pub column: u64,
}
impl Location {
pub const fn empty() -> Self {
Self { line: 0, column: 0 }
}
pub const fn new(line: u64, column: u64) -> Self {
Self { line, column }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Span {
pub start: Location,
pub end: Location,
}
impl Span {
pub const fn empty() -> Self {
Self {
start: Location::empty(),
end: Location::empty(),
}
}
pub const fn new(start: Location, end: Location) -> Self {
Self { start, end }
}
pub fn union(&self, other: &Span) -> Span {
if self.start.line == 0 {
return *other;
}
if other.start.line == 0 {
return *self;
}
Span {
start: core::cmp::min(self.start, other.start),
end: core::cmp::max(self.end, other.end),
}
}
}
pub trait Spanned {
fn span(&self) -> Span;
}