oak_vbnet/lexer/token_type.rs
1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3/// A VB.NET token.
4pub type VbNetToken = Token<VbNetTokenType>;
5
6/// VB.NET token types
7#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum VbNetTokenType {
10 /// Root node
11 Root,
12 /// Expression
13 Expression,
14 /// Whitespace
15 Whitespace,
16 /// Newline
17 Newline,
18
19 /// Identifier
20 Identifier,
21 /// Integer literal
22 IntegerLiteral,
23 /// Float literal
24 FloatLiteral,
25 /// String literal
26 StringLiteral,
27 /// Character literal
28 CharLiteral,
29 /// Boolean literal
30 BooleanLiteral,
31 /// Date literal
32 DateLiteral,
33 /// Nothing literal
34 NothingLiteral,
35
36 /// The 'Namespace' keyword
37 Namespace,
38 /// The 'Imports' keyword
39 Imports,
40 /// The 'Class' keyword
41 Class,
42 /// The 'Interface' keyword
43 Interface,
44 /// The 'Structure' keyword
45 Structure,
46 /// The 'Enum' keyword
47 Enum,
48 /// The 'Module' keyword
49 Module,
50 /// The 'Delegate' keyword
51 Delegate,
52 /// The 'Event' keyword
53 Event,
54 /// The 'Function' keyword
55 Function,
56 /// The 'Sub' keyword
57 Sub,
58 /// The 'Property' keyword
59 Property,
60 /// The 'Dim' keyword
61 Dim,
62 /// The 'Const' keyword
63 Const,
64 /// The 'As' keyword
65 As,
66 /// The 'In' keyword
67 In,
68 /// The 'If' keyword
69 If,
70 /// The 'Then' keyword
71 Then,
72 /// The 'Else' keyword
73 Else,
74 /// The 'ElseIf' keyword
75 ElseIf,
76 /// The 'End' keyword
77 End,
78 /// The 'For' keyword
79 For,
80 /// The 'Each' keyword
81 Each,
82 /// The 'To' keyword
83 To,
84 /// The 'Step' keyword
85 Step,
86 /// The 'While' keyword
87 While,
88 /// The 'Do' keyword
89 Do,
90 /// The 'Loop' keyword
91 Loop,
92 /// The 'Until' keyword
93 Until,
94 /// The 'Select' keyword
95 Select,
96 /// The 'Case' keyword
97 Case,
98 /// The 'Default' keyword
99 Default,
100 /// The 'With' keyword
101 With,
102 /// The 'Try' keyword
103 Try,
104 /// The 'Catch' keyword
105 Catch,
106 /// The 'Finally' keyword
107 Finally,
108 /// The 'Throw' keyword
109 Throw,
110 /// The 'Exit' keyword
111 Exit,
112 /// The 'Continue' keyword
113 Continue,
114 /// The 'Next' keyword
115 Next,
116 /// The 'Return' keyword
117 Return,
118 /// The 'Me' keyword
119 Me,
120 /// The 'MyBase' keyword
121 MyBase,
122 /// The 'MyClass' keyword
123 MyClass,
124 /// The 'New' keyword
125 New,
126 /// The 'Of' keyword
127 Of,
128 /// The 'ByVal' keyword
129 ByVal,
130 /// The 'ByRef' keyword
131 ByRef,
132 /// The 'Optional' keyword
133 Optional,
134 /// The 'ParamArray' keyword
135 ParamArray,
136 /// The 'Public' keyword
137 Public,
138 /// The 'Private' keyword
139 Private,
140 /// The 'Protected' keyword
141 Protected,
142 /// The 'Friend' keyword
143 Friend,
144 /// The 'ProtectedFriend' keyword
145 ProtectedFriend,
146 /// The 'Shared' keyword
147 Shared,
148 /// The 'MustInherit' keyword
149 MustInherit,
150 /// The 'NotInheritable' keyword
151 NotInheritable,
152 /// The 'MustOverride' keyword
153 MustOverride,
154 /// The 'Overridable' keyword
155 Overridable,
156 /// The 'Overrides' keyword
157 Overrides,
158 /// The 'NotOverridable' keyword
159 NotOverridable,
160 /// The 'MustOverrideReadOnly' keyword
161 MustOverrideReadOnly,
162 /// The 'ReadOnly' keyword
163 ReadOnly,
164 /// The 'WriteOnly' keyword
165 WriteOnly,
166 /// The 'Static' keyword
167 Static,
168 /// The 'Partial' keyword
169 Partial,
170 /// The 'Async' keyword
171 Async,
172 /// The 'Await' keyword
173 Await,
174 /// The 'From' keyword for LINQ
175 From,
176 /// The 'Where' keyword for LINQ
177 Where,
178 /// The 'Order' keyword for LINQ
179 Order,
180 /// The 'By' keyword for LINQ
181 By,
182 /// The 'Group' keyword for LINQ
183 Group,
184 /// The 'Join' keyword for LINQ
185 Join,
186 /// The 'On' keyword for LINQ
187 On,
188 /// The 'Into' keyword for LINQ
189 Into,
190 /// The 'Let' keyword for LINQ
191 Let,
192 /// The 'Overloads' keyword
193 Overloads,
194 /// The 'Inherits' keyword
195 Inherits,
196 /// The 'Implements' keyword
197 Implements,
198 /// The 'Get' keyword
199 Get,
200 /// The 'Set' keyword
201 Set,
202 /// The 'Equals' keyword
203 Equals,
204 /// The 'Statement' keyword
205 Statement,
206
207 /// The '+' operator
208 Plus,
209 /// The '-' operator
210 Minus,
211 /// The '*' operator
212 Star,
213 /// The '/' operator
214 Slash,
215 /// The '\' operator
216 Backslash,
217 /// The '%' operator
218 Percent,
219 /// The '^' operator
220 Caret,
221
222 /// The '=' operator
223 Equal,
224 /// The '<>' operator
225 NotEqual,
226 /// The '<' operator
227 LessThan,
228 /// The '<=' operator
229 LessEqual,
230 /// The '>' operator
231 GreaterThan,
232 /// The '>=' operator
233 GreaterEqual,
234
235 /// The 'And' operator
236 And,
237 /// The 'Or' operator
238 Or,
239 /// The 'Not' operator
240 Not,
241 /// The 'Xor' operator
242 Xor,
243 /// The 'AndAlso' operator
244 AndAlso,
245 /// The 'OrElse' operator
246 OrElse,
247 /// The 'Is' operator
248 Is,
249 /// The 'IsNot' operator
250 IsNot,
251 /// The 'Like' operator
252 Like,
253 /// The 'TypeOf' operator
254 TypeOf,
255
256 /// The '(' delimiter
257 LeftParen,
258 /// The ')' delimiter
259 RightParen,
260 /// The '[' delimiter
261 LeftBracket,
262 /// The ']' delimiter
263 RightBracket,
264 /// The '{' delimiter
265 LeftBrace,
266 /// The '}' delimiter
267 RightBrace,
268
269 /// The ',' punctuation
270 Comma,
271 /// The ';' punctuation
272 Semicolon,
273 /// The ':' punctuation
274 Colon,
275 /// The '.' punctuation
276 Dot,
277 /// The '!' punctuation
278 Exclamation,
279 /// The '#' punctuation
280 Hash,
281 /// The '&' punctuation
282 Ampersand,
283
284 /// Line comment
285 LineComment,
286 /// Block comment
287 BlockComment,
288
289 /// Error
290 Error,
291 /// End of file
292 Eof,
293}
294
295impl VbNetTokenType {
296 /// Checks if it is a keyword
297 pub fn is_keyword(&self) -> bool {
298 matches!(
299 self,
300 Self::Namespace
301 | Self::Imports
302 | Self::Class
303 | Self::Interface
304 | Self::Structure
305 | Self::Enum
306 | Self::Module
307 | Self::Delegate
308 | Self::Event
309 | Self::Function
310 | Self::Sub
311 | Self::Property
312 | Self::Dim
313 | Self::Const
314 | Self::As
315 | Self::In
316 | Self::If
317 | Self::Then
318 | Self::Else
319 | Self::ElseIf
320 | Self::End
321 | Self::For
322 | Self::Each
323 | Self::To
324 | Self::Step
325 | Self::While
326 | Self::Do
327 | Self::Loop
328 | Self::Until
329 | Self::Select
330 | Self::Case
331 | Self::Default
332 | Self::With
333 | Self::Try
334 | Self::Catch
335 | Self::Finally
336 | Self::Throw
337 | Self::Exit
338 | Self::Continue
339 | Self::Return
340 | Self::Me
341 | Self::MyBase
342 | Self::MyClass
343 | Self::New
344 | Self::Of
345 | Self::ByVal
346 | Self::ByRef
347 | Self::Optional
348 | Self::ParamArray
349 | Self::Public
350 | Self::Private
351 | Self::Protected
352 | Self::Friend
353 | Self::ProtectedFriend
354 | Self::Shared
355 | Self::MustInherit
356 | Self::NotInheritable
357 | Self::MustOverride
358 | Self::Overridable
359 | Self::Overrides
360 | Self::NotOverridable
361 | Self::MustOverrideReadOnly
362 | Self::ReadOnly
363 | Self::WriteOnly
364 | Self::Static
365 | Self::Partial
366 | Self::Async
367 | Self::Await
368 | Self::From
369 | Self::Where
370 | Self::Order
371 | Self::By
372 | Self::Group
373 | Self::Join
374 | Self::On
375 | Self::Into
376 | Self::Let
377 | Self::And
378 | Self::Or
379 | Self::Not
380 | Self::Xor
381 | Self::AndAlso
382 | Self::OrElse
383 | Self::Is
384 | Self::IsNot
385 | Self::Like
386 | Self::TypeOf
387 | Self::Overloads
388 | Self::Inherits
389 | Self::Implements
390 | Self::Get
391 | Self::Set
392 | Self::Equals
393 | Self::Statement
394 )
395 }
396}
397
398impl TokenType for VbNetTokenType {
399 type Role = UniversalTokenRole;
400 const END_OF_STREAM: Self = Self::Eof;
401
402 fn is_ignored(&self) -> bool {
403 matches!(self, Self::Whitespace | Self::Newline | Self::LineComment | Self::BlockComment)
404 }
405
406 fn role(&self) -> Self::Role {
407 match self {
408 Self::Error => UniversalTokenRole::Error,
409 _ if self.is_keyword() => UniversalTokenRole::Keyword,
410 Self::Identifier => UniversalTokenRole::Name,
411 Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::BooleanLiteral | Self::DateLiteral | Self::NothingLiteral => UniversalTokenRole::Literal,
412 _ => UniversalTokenRole::None,
413 }
414 }
415}