Errors - Interpreter error

This commit is contained in:
Emmanuel BENOîT 2022-12-31 12:58:25 +01:00
parent 58a986d280
commit 25ae8b0c16

View file

@ -52,3 +52,26 @@ impl ParserError {
err_hdl.report(self.line, &self.pos, &self.message);
}
}
/// An error that occurred while trying to evaluate the code.
#[derive(Debug, Clone)]
pub struct InterpreterError {
line: usize,
message: String,
}
impl InterpreterError {
/// Initialize an interpreter error.
pub fn new(token: &Token, message: &str) -> Self {
Self {
line: token.line,
message: String::from(message),
}
}
/// Report the error to an error handler.
pub fn report(&self, err_hdl: &mut ErrorHandler) {
err_hdl.report(self.line, "", &self.message);
}
}