fluid_parser/
error.rs

1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Copy, Default)]
4pub struct Location {
5    pub line: usize,
6    pub col: usize,
7}
8
9impl fmt::Display for Location {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        write!(f, "{}:{}", self.line, self.col)
12    }
13}
14
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum FluidError {
17    UnexpectedToken(Location),
18    UnexpectedEof(Location),
19    Parse(String, Location),
20}
21
22impl fmt::Display for FluidError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            FluidError::UnexpectedToken(loc) => write!(f, "{}: Unexpected token", loc),
26            FluidError::UnexpectedEof(loc) => write!(f, "{}: Unexpected eof", loc),
27            FluidError::Parse(s, loc) => write!(f, "{}: Failed to parse `{}`", loc, s),
28        }
29    }
30}
31
32impl std::error::Error for FluidError {}