dent_parse/
error.rs

1/// Error type returned by Dent.
2///
3/// This type is used for all errors returned by Dent, whether they are
4/// parsing errors, IO errors or otherwise.
5#[derive(Clone, PartialEq, Debug)]
6pub enum Error {
7    UnexpectedToken(String),
8    UnknownFunction(String),
9    UnexpectedEof,
10    UnexpectedChar(char),
11    Io(std::io::ErrorKind),
12}
13
14impl From<std::io::Error> for Error {
15    fn from(e: std::io::Error) -> Self {
16        Error::Io(e.kind())
17    }
18}
19
20impl ToString for Error {
21    fn to_string(&self) -> String {
22        match self {
23            Error::UnexpectedToken(token) => format!("Unexpected token: {}", token),
24            Error::UnknownFunction(name) => format!("Unknown function: {}", name),
25            Error::UnexpectedEof => "Unexpected end of file".to_string(),
26            Error::UnexpectedChar(c) => format!("Unexpected character: {}", c),
27            Error::Io(e) => format!("IO error: {}", e),
28        }
29    }
30}
31
32/// Result type returned by Dent.
33pub type Result<T> = std::result::Result<T, Error>;