use crate::compiler::token::Token;
#[derive(Debug, Clone, PartialEq)]
pub enum CompileError {
Lex(String),
Parse(ParseError),
}
#[derive(Debug, Clone, PartialEq)]
pub enum ParseError {
UnexpectedToken { expected: String, found: Token },
InvalidFooter(String),
}
impl std::fmt::Display for CompileError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CompileError::Lex(msg) => write!(f, "Lexer error: {}", msg),
CompileError::Parse(err) => write!(f, "Parse error: {}", err),
}
}
}
impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ParseError::UnexpectedToken { expected, found } => {
write!(f, "expected {}, found {}", expected, found)
}
ParseError::InvalidFooter(raw) => {
write!(f, "invalid footer syntax: '{}'", raw)
}
}
}
}
impl std::error::Error for CompileError {}
impl std::error::Error for ParseError {}