#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Span {
pub start: usize,
pub end: usize,
pub line: u32,
pub column: u32,
}
impl Default for Span {
fn default() -> Self {
Self {
start: 0,
end: 0,
line: 1,
column: 1,
}
}
}
impl Span {
pub fn new(start: usize, end: usize, line: u32, column: u32) -> Self {
Self {
start,
end,
line,
column,
}
}
pub fn merge(self, other: Span) -> Span {
Span {
start: self.start.min(other.start),
end: self.end.max(other.end),
line: self.line.min(other.line),
column: if self.line < other.line {
self.column
} else {
other.column
},
}
}
}