Skip to main content

runec/
token.rs

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