2021-12-12 19:59:43 +00:00
|
|
|
use std::fmt::{Debug, Display, Error, Formatter};
|
2021-12-03 21:13:19 +00:00
|
|
|
|
|
|
|
use super::MpsOp;
|
2021-12-12 19:59:43 +00:00
|
|
|
use crate::tokens::MpsToken;
|
2021-12-03 21:13:19 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SyntaxError {
|
|
|
|
pub line: usize,
|
|
|
|
pub token: MpsToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for SyntaxError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
2021-12-12 19:59:43 +00:00
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"SyntaxError (line {}): Unexpected {}",
|
|
|
|
&self.line, &self.token
|
|
|
|
)
|
2021-12-03 21:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MpsLanguageError for SyntaxError {
|
2021-12-12 19:59:43 +00:00
|
|
|
fn set_line(&mut self, line: usize) {
|
|
|
|
self.line = line
|
|
|
|
}
|
2021-12-03 21:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct RuntimeError {
|
|
|
|
pub line: usize,
|
|
|
|
pub op: Box<dyn MpsOp>,
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for RuntimeError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
|
|
|
write!(f, "{} (line {}): {}", &self.msg, &self.line, &self.op)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MpsLanguageError for RuntimeError {
|
2021-12-12 19:59:43 +00:00
|
|
|
fn set_line(&mut self, line: usize) {
|
|
|
|
self.line = line
|
|
|
|
}
|
2021-12-03 21:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait MpsLanguageError: Display + Debug {
|
|
|
|
fn set_line(&mut self, line: usize);
|
|
|
|
}
|