backyard_lexer/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::fmt::{ Display, Formatter };

#[derive(Debug, Clone, PartialEq)]
pub enum LexError {
  Unrecognized {
    token: String,
    line: usize,
    column: usize,
  },
  Eof,
}

impl Display for LexError {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    match self {
      LexError::Unrecognized { token, line, column } =>
        write!(f, "Unrecognized character '{}' at line {}, column {}", token, line, column),
      LexError::Eof => write!(f, "End of file"),
    }
  }
}

pub type LexResult = Result<(), LexError>;