Chapter 7

This commit is contained in:
Moritz Gmeiner 2023-01-20 16:10:03 +01:00
commit 42dbe531ad
15 changed files with 1112 additions and 0 deletions

25
src/misc.rs Normal file
View file

@ -0,0 +1,25 @@
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)
}
}