xplshn
·
2025-08-16
token.go
Go
1package token
2
3type Type int
4
5const (
6 // Meta
7 EOF Type = iota
8 Comment
9 Directive
10
11 // Literals
12 Ident
13 Number
14 String
15
16 // Keywords
17 Auto
18 Extrn
19 If
20 Else
21 While
22 Return
23 Goto
24 Switch
25 Case
26 Default
27 Break
28 Continue
29 Asm // `__asm__`
30
31 // Bx Type System Keywords that are not types themselves
32 TypeKeyword // 'type'
33 Struct
34 Const
35
36 // Bx Type System Keywords that ARE types
37 Void
38 Bool
39 Byte
40 Int
41 Uint
42 Int8
43 Uint8
44 Int16
45 Uint16
46 Int32
47 Uint32
48 Int64
49 Uint64
50 Float
51 Float32
52 Float64
53 StringKeyword // 'string'
54 Any
55
56 // Punctuation
57 LParen
58 RParen
59 LBrace
60 RBrace
61 LBracket
62 RBracket
63 Semi
64 Comma
65 Colon
66 Question
67 Dots
68 Dot
69
70 // Assignment Operators
71 Eq
72 Define
73 PlusEq
74 MinusEq
75 StarEq
76 SlashEq
77 RemEq
78 AndEq
79 OrEq
80 XorEq
81 ShlEq
82 ShrEq
83 EqPlus
84 EqMinus
85 EqStar
86 EqSlash
87 EqRem
88 EqAnd
89 EqOr
90 EqXor
91 EqShl
92 EqShr
93
94 // Binary Operators
95 Plus
96 Minus
97 Star
98 Slash
99 Rem
100 And
101 Or
102 Xor
103 Shl
104 Shr
105 EqEq
106 Neq
107 Lt
108 Gt
109 Gte
110 Lte
111 AndAnd
112 OrOr
113
114 // Unary & Postfix Operators
115 Not
116 Complement
117 Inc
118 Dec
119)
120
121var KeywordMap = map[string]Type{
122 "auto": Auto,
123 "if": If,
124 "else": Else,
125 "while": While,
126 "return": Return,
127 "goto": Goto,
128 "switch": Switch,
129 "case": Case,
130 "default": Default,
131 "extrn": Extrn,
132 "__asm__": Asm,
133 "break": Break,
134 "continue": Continue,
135 "void": Void,
136 "type": TypeKeyword,
137 "struct": Struct,
138 "const": Const,
139 "bool": Bool,
140 "byte": Byte,
141 "int": Int,
142 "uint": Uint,
143 "int8": Int8,
144 "uint8": Uint8,
145 "int16": Int16,
146 "uint16": Uint16,
147 "int32": Int32,
148 "uint32": Uint32,
149 "int64": Int64,
150 "uint64": Uint64,
151 "float": Float,
152 "float32": Float32,
153 "float64": Float64,
154 "string": StringKeyword,
155 "any": Any,
156}
157
158type Token struct {
159 Type Type
160 Value string
161 FileIndex int
162 Line int
163 Column int
164 Len int
165}