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
use crate::lexer::{tokens::Token, Lexer, LexicalError};

impl std::fmt::Display for LexicalError {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    match self {
      LexicalError::InvalidToken => write!(f, "Invalid token"),
      _ => unreachable!(),
    }
  }
}

impl<'input> std::fmt::Display for Lexer<'input> {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    for (token, span) in self.token_stream.clone().spanned() {
      let token = token.unwrap();
      writeln!(f, "{{ {:?} {:?} }}", token, span)?;
    }

    Ok(())
  }
}

impl std::fmt::Display for Token {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    write!(f, "{:?}", self)
  }
}