use std::ops::Range;
use serde::{Deserialize, Serialize};
use crate::span::Ranged;
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
pub struct Position {
pub start: Point,
pub end: Point,
}
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
pub struct Point {
pub line: usize,
pub column: usize,
pub offset: usize,
}
impl Position {
pub fn new(start: Point, end: Point) -> Self {
Position { start, end }
}
}
impl Ranged<usize> for Position {
fn range(&self) -> Range<usize> {
self.start.offset..self.end.offset
}
}
impl Point {
pub fn new(line: usize, column: usize, offset: usize) -> Self {
Self {
line,
column,
offset,
}
}
}