oak_fsharp/parser/element_type.rs
1use oak_core::{ElementType, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5/// F# element types
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum FSharpElementType {
9 /// Root node
10 Root,
11 /// Expression
12 Expression,
13 /// Whitespace
14 Whitespace,
15 /// Newline
16 Newline,
17
18 /// Identifier
19 Identifier,
20 /// Integer literal
21 IntegerLiteral,
22 /// Float literal
23 FloatLiteral,
24 /// String literal
25 StringLiteral,
26 /// Character literal
27 CharLiteral,
28 /// Boolean literal
29 BooleanLiteral,
30 /// Unit literal
31 UnitLiteral,
32
33 /// The 'let' keyword
34 Let,
35 /// The 'rec' keyword
36 Rec,
37 /// The 'and' keyword
38 And,
39 /// The 'in' keyword
40 In,
41 /// The 'if' keyword
42 If,
43 /// The 'then' keyword
44 Then,
45 /// The 'else' keyword
46 Else,
47 /// The 'elif' keyword
48 Elif,
49 /// The 'match' keyword
50 Match,
51 /// The 'with' keyword
52 With,
53 /// The 'when' keyword
54 When,
55 /// The 'function' keyword
56 Function,
57 /// The 'fun' keyword
58 Fun,
59
60 /// The 'type' keyword
61 Type,
62 /// The 'val' keyword
63 Val,
64 /// The 'mutable' keyword
65 Mutable,
66 /// The 'of' keyword
67 Of,
68 /// The 'as' keyword
69 As,
70
71 /// The 'module' keyword
72 Module,
73 /// The 'namespace' keyword
74 Namespace,
75 /// The 'open' keyword
76 Open,
77
78 /// The 'try' keyword
79 Try,
80 /// The 'finally' keyword
81 Finally,
82 /// The 'exception' keyword
83 Exception,
84 /// The 'raise' keyword
85 Raise,
86 /// The 'failwith' keyword
87 Failwith,
88
89 /// The 'for' keyword
90 For,
91 /// The 'to' keyword
92 To,
93 /// The 'downto' keyword
94 Downto,
95 /// The 'do' keyword
96 Do,
97 /// The 'done' keyword
98 Done,
99 /// The 'while' keyword
100 While,
101 /// The 'yield' keyword
102 Yield,
103 /// The 'return' keyword
104 Return,
105
106 /// The 'class' keyword
107 Class,
108 /// The 'interface' keyword
109 Interface,
110 /// The 'inherit' keyword
111 Inherit,
112 /// The 'abstract' keyword
113 Abstract,
114 /// The 'override' keyword
115 Override,
116 /// The 'default' keyword
117 Default,
118 /// The 'member' keyword
119 Member,
120 /// The 'static' keyword
121 Static,
122 /// The 'new' keyword
123 New,
124
125 /// The 'lazy' keyword
126 Lazy,
127 /// The 'async' keyword
128 Async,
129 /// The 'seq' keyword
130 Seq,
131 /// The 'use' keyword
132 Use,
133 /// The 'begin' keyword
134 Begin,
135 /// The 'end' keyword
136 End,
137 /// The 'struct' keyword
138 Struct,
139 /// The 'sig' keyword
140 Sig,
141
142 /// The 'true' keyword
143 True,
144 /// The 'false' keyword
145 False,
146 /// The 'null' keyword
147 Null,
148 /// The 'or' keyword
149 Or,
150
151 /// The 'public' keyword
152 Public,
153 /// The 'private' keyword
154 Private,
155 /// The 'internal' keyword
156 Internal,
157
158 /// The 'inline' keyword
159 Inline,
160 /// The 'extern' keyword
161 Extern,
162 /// The 'upcast' keyword
163 Upcast,
164 /// The 'downcast' keyword
165 Downcast,
166 /// The 'assert' keyword
167 Assert,
168 /// The 'global' keyword
169 Global,
170 /// The 'base' keyword
171 Base,
172 /// The 'this' keyword
173 This,
174 /// The 'void' keyword
175 Void,
176 /// The 'delegate' keyword
177 Delegate,
178 /// The 'select' keyword
179 Select,
180
181 /// The 'obj' keyword
182 Obj,
183 /// The 'unit' keyword
184 Unit,
185 /// The 'int' keyword
186 Int,
187 /// The 'float' keyword
188 Float,
189 /// The 'string' keyword
190 String,
191 /// The 'bool' keyword
192 Bool,
193 /// The 'char' keyword
194 Char,
195 /// The 'byte' keyword
196 Byte,
197 /// The 'sbyte' keyword
198 SByte,
199 /// The 'int16' keyword
200 Int16,
201 /// The 'uint16' keyword
202 UInt16,
203 /// The 'int32' keyword
204 Int32,
205 /// The 'uint32' keyword
206 UInt32,
207 /// The 'int64' keyword
208 Int64,
209 /// The 'uint64' keyword
210 UInt64,
211 /// The 'nativeint' keyword
212 NativeInt,
213 /// The 'unativeint' keyword
214 UNativeInt,
215 /// The 'decimal' keyword
216 Decimal,
217 /// The 'bigint' keyword
218 BigInt,
219
220 /// The '+' operator
221 Plus,
222 /// The '-' operator
223 Minus,
224 /// The '*' operator
225 Star,
226 /// The '/' operator
227 Slash,
228 /// The '%' operator
229 Percent,
230 /// The '**' operator
231 StarStar,
232
233 /// The '=' operator
234 Equal,
235 /// The '<>' operator
236 NotEqual,
237 /// The '<' operator
238 LessThan,
239 /// The '<=' operator
240 LessEqual,
241 /// The '>' operator
242 GreaterThan,
243 /// The '>=' operator
244 GreaterEqual,
245
246 /// The '&&' operator
247 AndAnd,
248 /// The '||' operator
249 OrOr,
250 /// The 'not' operator
251 Not,
252
253 /// The '&&&' operator
254 BitwiseAnd,
255 /// The '|||' operator
256 BitwiseOr,
257 /// The '^^^' operator
258 BitwiseXor,
259 /// The '~~~' operator
260 BitwiseNot,
261 /// The '<<<' operator
262 LeftShift,
263 /// The '>>>' operator
264 RightShift,
265
266 /// The '->' operator
267 Arrow,
268 /// The '=>' operator
269 DoubleArrow,
270 /// The '|' operator
271 Pipe,
272 /// The '|>' operator
273 PipeRight,
274 /// The '||' operator
275 DoublePipe,
276 /// The '::' operator
277 Cons,
278 /// The '@' operator
279 At,
280 /// The '>>' operator
281 Compose,
282 /// The '<<' operator
283 ComposeBack,
284 /// The '$' operator
285 Dollar,
286
287 /// The '&&' logical operator
288 LogicalAnd,
289 /// The '||' logical operator
290 LogicalOr,
291 /// The '&' operator
292 Ampersand,
293 /// The '^' operator
294 Caret,
295 /// The '~' operator
296 Tilde,
297 /// The '<' operator
298 Less,
299 /// The '>' operator
300 Greater,
301 /// The '|>' operator
302 PipeGreater,
303 /// The '!' operator
304 Exclamation,
305 /// The ':=' operator
306 ColonEqual,
307 /// The '<-' operator
308 LArrow,
309 /// The '++' operator
310 PlusPlus,
311 /// The '--' operator
312 MinusMinus,
313
314 /// The '(' delimiter
315 LeftParen,
316 /// The ')' delimiter
317 RightParen,
318 /// The '[' delimiter
319 LeftBracket,
320 /// The ']' delimiter
321 RightBracket,
322 /// The '[|' delimiter
323 LeftArrayBracket,
324 /// The '|]' delimiter
325 RightArrayBracket,
326 /// The '[<' delimiter
327 LeftBracketBar,
328 /// The '>]' delimiter
329 RightBracketBar,
330 /// The '[ <' delimiter
331 LeftBracketAngle,
332 /// The '> ]' delimiter
333 RightBracketAngle,
334 /// The '{' delimiter
335 LeftBrace,
336 /// The '}' delimiter
337 RightBrace,
338 /// The '<' delimiter
339 LeftAngle,
340 /// The '>' delimiter
341 RightAngle,
342
343 /// The ',' punctuation
344 Comma,
345 /// The ';' punctuation
346 Semicolon,
347 /// The ':' punctuation
348 Colon,
349 /// The '::' punctuation
350 DoubleColon,
351 /// The '.' punctuation
352 Dot,
353 /// The '..' punctuation
354 DotDot,
355 /// The '?' punctuation
356 Question,
357 /// The '_' punctuation
358 Underscore,
359 /// The ''' punctuation
360 Apostrophe,
361 /// The '`' punctuation
362 Backtick,
363 /// The '#' punctuation
364 Hash,
365
366 /// Line comment
367 LineComment,
368 /// Block comment
369 BlockComment,
370
371 /// Error
372 Error,
373 /// End of file
374 Eof,
375}
376
377impl FSharpElementType {
378 /// Checks if it is a keyword
379 pub fn is_keyword(&self) -> bool {
380 matches!(
381 self,
382 Self::Let
383 | Self::Rec
384 | Self::And
385 | Self::In
386 | Self::If
387 | Self::Then
388 | Self::Else
389 | Self::Elif
390 | Self::Match
391 | Self::With
392 | Self::When
393 | Self::Function
394 | Self::Fun
395 | Self::Type
396 | Self::Val
397 | Self::Mutable
398 | Self::Of
399 | Self::As
400 | Self::Module
401 | Self::Namespace
402 | Self::Open
403 | Self::Try
404 | Self::Finally
405 | Self::Exception
406 | Self::Raise
407 | Self::Failwith
408 | Self::For
409 | Self::To
410 | Self::Downto
411 | Self::Do
412 | Self::Done
413 | Self::While
414 | Self::Yield
415 | Self::Return
416 | Self::Class
417 | Self::Interface
418 | Self::Inherit
419 | Self::Abstract
420 | Self::Override
421 | Self::Default
422 | Self::Member
423 | Self::Static
424 | Self::New
425 | Self::Lazy
426 | Self::Async
427 | Self::Seq
428 | Self::Use
429 | Self::Begin
430 | Self::End
431 | Self::Struct
432 | Self::Sig
433 | Self::True
434 | Self::False
435 | Self::Null
436 | Self::Or
437 | Self::Public
438 | Self::Private
439 | Self::Internal
440 | Self::Inline
441 | Self::Extern
442 | Self::Upcast
443 | Self::Downcast
444 | Self::Assert
445 | Self::Delegate
446 | Self::Select
447 )
448 }
449}
450
451impl ElementType for FSharpElementType {
452 type Role = UniversalElementRole;
453
454 fn role(&self) -> Self::Role {
455 match self {
456 Self::Error => UniversalElementRole::Error,
457 _ => UniversalElementRole::None,
458 }
459 }
460}
461
462impl From<crate::lexer::token_type::FSharpTokenType> for FSharpElementType {
463 fn from(token: crate::lexer::token_type::FSharpTokenType) -> Self {
464 unsafe { std::mem::transmute(token) }
465 }
466}