Errors - Position for interpreter errors
This commit is contained in:
parent
ca3ec46bdc
commit
8b74cd932d
1 changed files with 3 additions and 1 deletions
|
@ -68,6 +68,7 @@ impl ParserError {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InterpreterError {
|
pub struct InterpreterError {
|
||||||
line: usize,
|
line: usize,
|
||||||
|
pos: String,
|
||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,12 +77,13 @@ impl InterpreterError {
|
||||||
pub fn new(token: &Token, message: &str) -> Self {
|
pub fn new(token: &Token, message: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
line: token.line,
|
line: token.line,
|
||||||
|
pos: format!(" at '{}'", token.lexeme),
|
||||||
message: String::from(message),
|
message: String::from(message),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Report the error to an error handler.
|
/// Report the error to an error handler.
|
||||||
pub fn report(&self, err_hdl: &mut ErrorHandler) {
|
pub fn report(&self, err_hdl: &mut ErrorHandler) {
|
||||||
err_hdl.report(ErrorType::Runtime, self.line, "", &self.message);
|
err_hdl.report(ErrorType::Runtime, self.line, &self.pos, &self.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue