use crate::token::Span;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SyntaxError {
pub message: String,
pub span: Span,
}
impl LexError {
pub fn new(message: impl Into<String>, span: Span) -> LexError {
LexError {
message: message.into(),
span,
}
}
pub fn line(&self) -> u32 {
self.span.start.line
}
pub fn column(&self) -> u32 {
self.span.start.column
}
}
pub type LexError = SyntaxError;
pub type ParseError = SyntaxError;
impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}: {}", self.line(), self.column(), self.message)
}
}
impl std::error::Error for SyntaxError {}
pub type Result<T> = std::result::Result<T, SyntaxError>;