use std::{error, fmt::Display};
use super::position::Position;
#[derive(Debug, Clone)]
pub struct Error {
pub kind: ErrorKind,
pub msg: String,
pub start: Option<Position>,
pub stop: Option<Position>,
}
impl Error {
pub fn new(kind: ErrorKind, msg: &str, start: Position, stop: Position) -> Self {
Self { kind, msg: msg.to_owned(), start: Some(start), stop: Some(stop), }
}
pub fn create_error_without_location(kind: ErrorKind, msg: &str) -> Self {
Self { kind, msg: msg.to_owned(), start: None, stop: None }
}
}
#[derive(Debug, Clone)]
pub enum ErrorKind {
LexerScanOverflow, LexerNoMatch, LexerRecoverFail,
TokenStreamOutOfRange, ConsumedTokenExhausted,
Unknown, }
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
fn description(&self) -> &str {
"description() is deprecated; use Display"
}
fn cause(&self) -> Option<&dyn error::Error> {
self.source()
}
}
impl Display for Error {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}