From 25ae8b0c161e84a5b4e6ca3aa51af5aea14e9b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 12:58:25 +0100 Subject: [PATCH] Errors - Interpreter error --- src/errors.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/errors.rs b/src/errors.rs index f3f65bb..bf71198 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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); + } +}