#[derive(Debug, Clone, PartialEq)]
pub struct TokenInfo {
pub text: String,
pub kind: Option<TokenKind>,
}
impl TokenInfo {
pub fn new(text: impl Into<String>) -> Self {
Self {
text: text.into(),
kind: None,
}
}
pub fn with_kind(mut self, kind: TokenKind) -> Self {
self.kind = Some(kind);
self
}
pub fn end_of_input() -> Self {
Self {
text: String::new(),
kind: Some(TokenKind::EndOfInput),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum TokenKind {
Identifier,
Keyword(String),
Number,
String,
Operator,
Punctuation,
EndOfInput,
Whitespace,
Comment,
Unknown,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ExpectedToken {
Literal(String),
Rule(String),
Category(TokenCategory),
}
impl ExpectedToken {
pub fn literal(s: impl Into<String>) -> Self {
Self::Literal(s.into())
}
pub fn rule(s: impl Into<String>) -> Self {
Self::Rule(s.into())
}
pub fn category(c: TokenCategory) -> Self {
Self::Category(c)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TokenCategory {
Expression,
Statement,
Type,
Pattern,
Identifier,
Literal,
Operator,
Delimiter,
}