use thiserror::Error;
#[derive(Error, Debug)]
pub enum A2mlError {
#[error("parse error at line {line}, column {column}: {message}")]
ParseError {
line: usize,
column: usize,
message: String,
},
#[error("unknown directive: {0}")]
UnknownDirective(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("render error: {0}")]
RenderError(String),
}
pub type Result<T> = std::result::Result<T, A2mlError>;
impl A2mlError {
pub fn parse(line: usize, column: usize, message: impl Into<String>) -> Self {
Self::ParseError {
line,
column,
message: message.into(),
}
}
}
impl A2mlError {
pub fn diagnostic(&self) -> String {
match self {
Self::ParseError {
line,
column,
message,
} => {
format!("error[A2ML]: {}:{}: {}", line, column, message)
}
other => format!("error[A2ML]: {}", other),
}
}
}