use crate::{LexerError, UserPosn};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SimpleParseError<P>
where
P: UserPosn,
{
pub ch: char,
pub pos: P,
}
impl<P> std::error::Error for SimpleParseError<P> where P: UserPosn {}
impl<P> LexerError<P> for SimpleParseError<P>
where
P: UserPosn,
{
fn failed_to_parse(pos: P, ch: char) -> Self {
Self { ch, pos }
}
}
impl<P> std::fmt::Display for SimpleParseError<P>
where
P: UserPosn,
{
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(fmt, "Failed to parse: unexpected char '{}' at ", self.ch)?;
self.pos.error_fmt(fmt)
}
}