1use smol_str::SmolStr;
2use strum::{Display, EnumString};
3
4use crate::Span;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct Token {
9 pub kind: TokenKind,
10 pub span: Span,
11 pub text: SmolStr,
12}
13
14impl Token {
15 pub fn new(kind: TokenKind, span: Span, text: impl Into<SmolStr>) -> Self {
16 Self {
17 kind,
18 span,
19 text: text.into(),
20 }
21 }
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, EnumString)]
26pub enum TokenKind {
27 Word,
30
31 NumberLiteral,
33 StringLiteral,
35 QuotedIdentifier,
37
38 Dot,
40 Comma,
41 Semicolon,
42 LParen,
43 RParen,
44 Star,
45 Plus,
46 Minus,
47 Slash,
48 Percent,
49 Eq,
50 Neq, Lt,
52 Gt,
53 LtEq,
54 GtEq,
55 Concat, ColonColon, AtSign, Colon, Whitespace,
62 Newline,
63 LineComment, BlockComment, Placeholder,
69 Eof,
71}
72
73impl TokenKind {
74 pub fn is_trivia(self) -> bool {
76 matches!(
77 self,
78 TokenKind::Whitespace
79 | TokenKind::Newline
80 | TokenKind::LineComment
81 | TokenKind::BlockComment
82 )
83 }
84}