1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pub(crate) const ESCAPED_LT: char = '\0';
#[derive(Debug, PartialEq, Clone)]
pub struct Token {
pub line: usize,
pub column: usize,
pub kind: Kind,
pub value: String,
}
impl Token {
pub fn new(kind: Kind, value: String, line: usize, column: usize) -> Self {
Token {
line,
column,
kind,
value,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Kind {
// Brackets and delimiters
LBracket, // [
RBracket, // ]
LParen, // (
RParen, // )
LBrace, // {
RBrace, // }
Semicolon, // ;
Comma, // ,
Colon, // :
// Operators
Equals, // = (assignment)
BinaryOperator, // +, -, *, /, %
ComparisonOperator, // <, >, <=, >=, = (in comparison context)
LogicalAnd, // &
LogicalOr, // |
Not, // !
// Special characters
Underscore, // _
Dot, // . (for dot-prefixed command names)
ScriptCall, // ~ (gosub operator)
JumpCall, // @ (jump operator)
Hash, // # (unused but lexed)
// Keywords
Trigger, // proc, clientscript, label, etc.
Command, // engine commands
Def, // def_int, def_string, etc.
Return, // return
If, // if
Else, // else
While, // while
Switch, // switch_int, switch_str, etc.
Case, // case
Default, // default
Calc, // calc
Null, // null
// Identifiers and literals
Identifier, // Regular identifiers
LocalVar, // $ prefixed variables
GameVar, // % prefixed variables (varp/varn/vars)
ConstantVar, // ^ prefixed constants
Number, // Numeric literals (integer)
LongLiteral, // Long literals (suffixed with L)
StringLiteral, // "string contents"
RawStringLiteral,
BooleanTrue, // true
BooleanFalse, // false
CharLiteral, // 'x'
CoordLiteral, // coordinate literal (0_0_0_0_0)
// Comments
SingleLineComment,
MultiLineComment,
// End of file token
EndOfFile,
}