stackr_rs/interpreter/
location.rsuse std::{fmt::Display, path::PathBuf};
#[derive(Debug, PartialEq, Clone)]
pub struct Location {
pub line: usize,
pub column: usize,
pub path: Option<PathBuf>,
}
impl Location {
pub fn new(path: Option<PathBuf>) -> Self {
Location {
line: 1,
column: 1,
path,
}
}
pub fn next(&mut self) {
self.column += 1;
}
pub fn new_line(&mut self) {
self.column = 0;
self.line += 1;
}
}
impl Default for Location {
fn default() -> Self {
Location {
line: 1,
column: 1,
path: None,
}
}
}
impl Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.path {
Some(path) => write!(f, "{}:{}:{}", path.display(), self.line, self.column),
None => write!(f, "{}:{}:{}", "stdin", self.line, self.column),
}
}
}