lexer_rs/lexer/
simple_parse_error.rs1use crate::{LexerError, UserPosn};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct SimpleParseError<P>
13where
14 P: UserPosn,
15{
16 pub ch: char,
18
19 pub pos: P,
21}
22
23impl<P> std::error::Error for SimpleParseError<P> where P: UserPosn {}
25
26impl<P> LexerError<P> for SimpleParseError<P>
28where
29 P: UserPosn,
30{
31 fn failed_to_parse(pos: P, ch: char) -> Self {
32 Self { ch, pos }
33 }
34}
35
36impl<P> std::fmt::Display for SimpleParseError<P>
38where
39 P: UserPosn,
40{
41 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
42 write!(fmt, "Failed to parse: unexpected char '{}' at ", self.ch)?;
43 self.pos.error_fmt(fmt)
44 }
45}