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