mini_builder_rs/tokenizer/
token.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum TokenType {
3 Source,
5 QuestionMark,
7 Colon,
8 Comma,
9 Dot,
10 LBracket,
11 RBracket,
12 SquareLBracket,
13 SquareRBracket,
14 Plus,
16 Minus,
17 Star,
18 Slash,
19 Or,
21 And,
22 Not,
23 Assign,
25 Open,
27 Close,
28 Pound,
29 At,
30 Equals,
32 NotEquals,
33 GreaterThan,
34 SmallerThan,
35 GreaterEquals,
36 SmallerEquals,
37 If,
39 Else,
40 Elif,
41 For,
42 Identifier,
44 FilePath,
45 StringLiteral,
46 NumericalLiteral,
47 NoneLiteral,
48}
49
50impl TokenType {
51 pub fn is_comparison_token(&self) -> bool {
52 match *self {
53 Self::Equals
54 | Self::NotEquals
55 | Self::GreaterThan
56 | Self::SmallerThan
57 | Self::GreaterEquals
58 | Self::SmallerEquals => true,
59 _ => false,
60 }
61 }
62}
63
64pub struct Token<'a> {
65 pub tt: TokenType,
66 pub content: &'a str,
67 pub location: usize,
68}
69
70impl<'a> Token<'a> {
71 pub fn new(tt: TokenType, content: &'a str, location: usize) -> Self {
72 Self {
73 tt,
74 content: content,
75 location,
76 }
77 }
78}