use std::{ fmt::{ self, Debug, Display, Formatter }, sync::Arc };
#[macro_export]
macro_rules! location_here
{
() => {
$crate::language::text::location::Location::new(file!(),
line!() as usize,
column!() as usize)
};
}
#[derive(Clone, PartialEq, PartialOrd, Eq)]
pub struct Location
{
pub origin: Arc<str>,
pub line: usize,
pub column: usize
}
impl Location
{
pub fn new(origin: impl Into<Arc<str>>, line: usize, column: usize) -> Self
{
Self { origin: origin.into(), line, column }
}
}
impl Default for Location
{
fn default() -> Self
{
Self { origin: Arc::from("<unspecified>"), line: 1, column: 1 }
}
}
impl Display for Location
{
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), fmt::Error>
{
write!(formatter, "{}: ({}, {})", self.origin, self.line, self.column)
}
}
impl Debug for Location
{
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), fmt::Error>
{
write!(formatter, "{}", self)
}
}