#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Span {
pub start: Position,
pub end: Position,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Position {
pub line: usize,
pub column: usize,
}
impl Span {
pub fn new(start: Position, end: Position) -> Self {
Self { start, end }
}
pub fn from_coords(
start_line: usize,
start_col: usize,
end_line: usize,
end_col: usize,
) -> Self {
Self {
start: Position::new(start_line, start_col),
end: Position::new(end_line, end_col),
}
}
pub fn contains(&self, position: Position) -> bool {
if position.line < self.start.line || position.line > self.end.line {
return false;
}
if position.line == self.start.line && position.column < self.start.column {
return false;
}
if position.line == self.end.line && position.column > self.end.column {
return false;
}
true
}
}
impl Position {
pub fn new(line: usize, column: usize) -> Self {
Self { line, column }
}
}