use alloc::sync::Arc;
use core::{fmt, ops::Range};
use super::ByteIndex;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Location {
pub path: Arc<str>,
pub start: ByteIndex,
pub end: ByteIndex,
}
impl Location {
pub const fn new(path: Arc<str>, start: ByteIndex, end: ByteIndex) -> Self {
Self { path, start, end }
}
pub fn path(&self) -> Arc<str> {
self.path.clone()
}
pub const fn range(&self) -> Range<ByteIndex> {
self.start..self.end
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FileLineCol {
pub path: Arc<str>,
pub line: u32,
pub column: u32,
}
impl FileLineCol {
pub const fn new(path: Arc<str>, line: u32, column: u32) -> Self {
Self { path, line, column }
}
pub fn path(&self) -> Arc<str> {
self.path.clone()
}
pub const fn line(&self) -> u32 {
self.line
}
pub fn move_column(&mut self, offset: u32) {
self.column += offset;
}
}
impl fmt::Display for FileLineCol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}@{}:{}]", &self.path, self.line, self.column)
}
}