49 lines
822 B
Rust
49 lines
822 B
Rust
#[derive(Clone, PartialEq, Debug)]
|
|
pub struct Pos {
|
|
pub index: usize,
|
|
pub line: i64,
|
|
pub col: i64,
|
|
}
|
|
|
|
impl Pos {
|
|
pub fn new(index: usize, line: i64, col: i64) -> Self {
|
|
Self { index, line, col }
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Error {
|
|
pub kind: ErrorKind,
|
|
pub pos: Option<Pos>,
|
|
pub msg: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum ErrorKind {
|
|
LexerError,
|
|
ParserError,
|
|
CheckerError,
|
|
}
|
|
|
|
pub struct ErrorAcc {
|
|
errors: Vec<Error>,
|
|
}
|
|
|
|
impl ErrorAcc {
|
|
pub fn new() -> Self {
|
|
Self { errors: Vec::new() }
|
|
}
|
|
|
|
pub fn ok(&self) -> bool {
|
|
self.errors.is_empty()
|
|
}
|
|
|
|
pub fn add(&mut self, error: Error) {
|
|
self.errors.push(error)
|
|
}
|
|
|
|
pub fn iter(&self) -> impl Iterator<Item = &Error> {
|
|
self.errors.iter()
|
|
}
|
|
}
|