use crate::lex::token::Token;
use std::fmt;
use std::ops::Range;
#[derive(Debug, Clone)]
pub enum LexerOutput {
Flat(Vec<(Token, Range<usize>)>),
}
#[derive(Debug, Clone)]
pub enum LexError {
Error(String),
Transformation(String),
}
impl fmt::Display for LexError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LexError::Error(msg) => write!(f, "Lexing error: {msg}"),
LexError::Transformation(msg) => write!(f, "Transformation error: {msg}"),
}
}
}
impl std::error::Error for LexError {}
impl From<LexError> for String {
fn from(err: LexError) -> Self {
err.to_string()
}
}
pub trait Lexer {
fn lex(&self, source: &str) -> Result<LexerOutput, LexError>;
}