use super::super::common::SourceBlock;
use crate::slice_file::Location;
use std::fmt;
pub type Token<'a> = (Location, TokenKind<'a>, Location);
pub type Error = (Location, ErrorKind, Location);
#[derive(Clone, Debug)]
pub enum TokenKind<'input> {
SourceBlock(SourceBlock<'input>),
Identifier(&'input str),
DefineKeyword, UndefineKeyword, IfKeyword, ElifKeyword, ElseKeyword, EndifKeyword,
DirectiveEnd,
Not, And, Or,
LeftParenthesis, RightParenthesis, }
#[derive(Clone, Debug)]
pub enum ErrorKind {
UnknownSymbol { symbol: String, suggestion: Option<String> },
UnknownDirective { keyword: String },
MissingDirective,
}
impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownSymbol { symbol, suggestion } => match suggestion {
Some(s) => write!(f, "unknown symbol '{symbol}', try using '{s}' instead"),
None => write!(f, "unknown symbol '{symbol}'"),
},
Self::UnknownDirective { keyword } => write!(f, "unknown preprocessor directive: '{keyword}'"),
Self::MissingDirective => f.write_str("missing preprocessor directive"),
}
}
}