1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::fmt::Debug;
use super::*;
#[derive(Debug)]
/// Information about the error which occured when the
/// [Lexer::lex] failed.
pub struct Error<'code> {
pub buffer: Buffer<'code>,
/// This is included not just for debug information,
/// but also to allow [lexerus_derive::Lexer]
/// to obtain some basic information about how many
/// tokens were matched before the program
/// failed. This is useful when debugging `enum`
/// because it would not be immediately obvious
/// which match pattern failed.
pub matched: usize,
pub kind: Kind,
}
impl<'code> ::std::fmt::Display for Error<'code> {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
::std::fmt::Debug::fmt(&self, f)
}
}
#[cfg(test)]
impl<'code> ::std::error::Error for Error<'code> {}
#[derive(Debug, PartialEq, Eq)]
/// Describes the type of error found.
pub enum Kind {
/// This means that the token was not found
NotFound(&'static str),
/// This means that an unexpected token was encountered.
UnexpectedToken(&'static str),
}