mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 12:22:42 +00:00
25 lines
534 B
Rust
25 lines
534 B
Rust
|
|
use std::fmt::{Debug, Display};
|
||
|
|
|
||
|
|
#[derive(Copy, Clone)]
|
||
|
|
pub struct CodePos {
|
||
|
|
pub line: u32,
|
||
|
|
pub col: u32,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for CodePos {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self { line: 1, col: 0 }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Display for CodePos {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
write!(f, "line {}, col {}", self.line, self.col)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Debug for CodePos {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
write!(f, "{}:{}", self.line, self.col)
|
||
|
|
}
|
||
|
|
}
|