use smol_str::SmolStr;
use strum::{Display, EnumString};
use crate::Span;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
pub kind: TokenKind,
pub span: Span,
pub text: SmolStr,
}
impl Token {
pub fn new(kind: TokenKind, span: Span, text: impl Into<SmolStr>) -> Self {
Self {
kind,
span,
text: text.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, EnumString)]
pub enum TokenKind {
Word,
NumberLiteral,
StringLiteral,
QuotedIdentifier,
Dot,
Comma,
Semicolon,
LParen,
RParen,
Star,
Plus,
Minus,
Slash,
Percent,
Eq,
Neq, Lt,
Gt,
LtEq,
GtEq,
Concat, ColonColon, AtSign, Colon, LBracket, RBracket,
Whitespace,
Newline,
LineComment, BlockComment,
Placeholder,
Eof,
}
impl TokenKind {
pub fn is_trivia(self) -> bool {
matches!(
self,
TokenKind::Whitespace
| TokenKind::Newline
| TokenKind::LineComment
| TokenKind::BlockComment
)
}
}