use thiserror::Error;
use crate::token::Token;
#[derive(Error, Debug)]
pub enum ParseError {
#[error("{0}: expected `{1}` got `{2}`")]
Unexpected(ErrorContext, Token, Token),
}
#[derive(Error, Debug)]
pub enum ScanError {
#[error("{0}: incomplete UTF8")]
IncompleteUtf8(ErrorContext),
#[error("{0}: unexpected character `{1}`")]
Unexpected(ErrorContext, char),
}
pub struct ErrorContext {
pub path: String,
pub line: usize,
pub col: usize,
pub start_of_line: usize,
}
impl std::fmt::Display for ErrorContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}:{}", self.path, self.line, self.col)
}
}
impl std::fmt::Debug for ErrorContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}:{}", self.path, self.line, self.col)
}
}