2023-01-24 15:01:09 +00:00
|
|
|
mod lex_error;
|
2023-03-14 21:10:43 +00:00
|
|
|
mod syntax_error;
|
2023-01-24 15:01:09 +00:00
|
|
|
|
|
|
|
pub trait PrintableError {
|
|
|
|
fn get_error_str(&self, chars: &Vec<char>) -> String;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum MistiError {
|
2023-03-14 21:10:43 +00:00
|
|
|
Lex(LexError),
|
|
|
|
Syntax(SyntaxError),
|
2023-01-24 15:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LexError {
|
|
|
|
pub position: usize,
|
|
|
|
pub reason: String,
|
|
|
|
}
|
|
|
|
|
2023-03-14 21:10:43 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SyntaxError {
|
2023-03-15 21:33:00 +00:00
|
|
|
pub error_start: usize,
|
|
|
|
pub error_end: usize,
|
2023-03-14 21:10:43 +00:00
|
|
|
pub reason: String,
|
|
|
|
}
|
2023-01-24 15:01:09 +00:00
|
|
|
|
|
|
|
impl PrintableError for MistiError {
|
|
|
|
fn get_error_str(&self, chars: &Vec<char>) -> String {
|
|
|
|
match self {
|
2023-03-14 21:10:43 +00:00
|
|
|
Self::Lex(err) => err.get_error_str(chars),
|
|
|
|
Self::Syntax(err) => err.get_error_str(chars),
|
2023-01-24 15:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|