1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::Serialize;
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Hash)]
5pub enum FSharpSyntaxKind {
6 Root,
8 Whitespace,
9 Newline,
10
11 Identifier,
13 IntegerLiteral,
14 FloatLiteral,
15 StringLiteral,
16 CharLiteral,
17 BooleanLiteral,
18 UnitLiteral,
19
20 Let,
22 Rec,
23 And,
24 In,
25 If,
26 Then,
27 Else,
28 Elif,
29 Match,
30 With,
31 When,
32 Function,
33 Fun,
34
35 Type,
37 Val,
38 Mutable,
39 Of,
40 As,
41
42 Module,
44 Namespace,
45 Open,
46
47 Try,
49 Finally,
50 Exception,
51 Raise,
52 Failwith,
53
54 For,
56 To,
57 Downto,
58 Do,
59 Done,
60 While,
61 Yield,
62 Return,
63
64 Class,
66 Interface,
67 Inherit,
68 Abstract,
69 Override,
70 Default,
71 Member,
72 Static,
73 New,
74
75 Lazy,
77 Async,
78 Seq,
79 Use,
80 Begin,
81 End,
82 Struct,
83 Sig,
84
85 True,
87 False,
88 Null,
89 Or,
90
91 Public,
93 Private,
94 Internal,
95
96 Inline,
98 Extern,
99 Upcast,
100 Downcast,
101 Assert,
102 Global,
103 Base,
104 This,
105 Void,
106
107 Obj,
109 Unit,
110 Int,
111 Float,
112 String,
113 Bool,
114 Char,
115 Byte,
116 SByte,
117 Int16,
118 UInt16,
119 Int32,
120 UInt32,
121 Int64,
122 UInt64,
123 NativeInt,
124 UNativeInt,
125 Decimal,
126 BigInt,
127
128 Plus, Minus, Star, Slash, Percent, StarStar, Equal, NotEqual, LessThan, LessEqual, GreaterThan, GreaterEqual, AndAnd, OrOr, Not, BitwiseAnd, BitwiseOr, BitwiseXor, BitwiseNot, LeftShift, RightShift, Arrow, DoubleArrow, Pipe, PipeRight, DoublePipe, Cons, At, Compose, ComposeBack, Dollar, LogicalAnd, LogicalOr, Ampersand, Caret, Tilde, Less, Greater, PipeGreater, Exclamation, ColonEqual, LArrow, PlusPlus, MinusMinus, LeftParen, RightParen, LeftBracket, RightBracket, LeftArrayBracket, RightArrayBracket, LeftBracketBar, RightBracketBar, LeftBracketAngle, RightBracketAngle, LeftBrace, RightBrace, LeftAngle, RightAngle, Comma, Semicolon, Colon, DoubleColon, Dot, DotDot, Question, Underscore, Apostrophe, Backtick, Hash, LineComment, BlockComment, Error,
219 Eof,
220}
221
222impl FSharpSyntaxKind {
223 pub fn is_keyword(&self) -> bool {
224 matches!(
225 self,
226 Self::Let
227 | Self::Rec
228 | Self::And
229 | Self::In
230 | Self::If
231 | Self::Then
232 | Self::Else
233 | Self::Elif
234 | Self::Match
235 | Self::With
236 | Self::When
237 | Self::Function
238 | Self::Fun
239 | Self::Type
240 | Self::Val
241 | Self::Mutable
242 | Self::Of
243 | Self::As
244 | Self::Module
245 | Self::Namespace
246 | Self::Open
247 | Self::Try
248 | Self::Finally
249 | Self::Exception
250 | Self::Raise
251 | Self::Failwith
252 | Self::For
253 | Self::To
254 | Self::Downto
255 | Self::Do
256 | Self::Done
257 | Self::While
258 | Self::Yield
259 | Self::Return
260 | Self::Class
261 | Self::Interface
262 | Self::Inherit
263 | Self::Abstract
264 | Self::Override
265 | Self::Default
266 | Self::Member
267 | Self::Static
268 | Self::New
269 | Self::Lazy
270 | Self::Async
271 | Self::Seq
272 | Self::Use
273 | Self::Begin
274 | Self::End
275 | Self::Struct
276 | Self::Sig
277 | Self::True
278 | Self::False
279 | Self::Null
280 | Self::Or
281 | Self::Public
282 | Self::Private
283 | Self::Internal
284 | Self::Inline
285 | Self::Extern
286 | Self::Upcast
287 | Self::Downcast
288 | Self::Assert
289 )
290 }
291}
292
293impl TokenType for FSharpSyntaxKind {
294 const END_OF_STREAM: Self = Self::Eof;
295 type Role = UniversalTokenRole;
296
297 fn role(&self) -> Self::Role {
298 match self {
299 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
300 Self::LineComment | Self::BlockComment => UniversalTokenRole::Comment,
301 Self::Identifier => UniversalTokenRole::Name,
302 Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::BooleanLiteral | Self::UnitLiteral => UniversalTokenRole::Literal,
303 _ if self.is_keyword() => UniversalTokenRole::Keyword,
304 Self::Plus
305 | Self::Minus
306 | Self::Star
307 | Self::Slash
308 | Self::Percent
309 | Self::Equal
310 | Self::NotEqual
311 | Self::Less
312 | Self::Greater
313 | Self::LessEqual
314 | Self::GreaterEqual
315 | Self::Pipe
316 | Self::PipeGreater
317 | Self::Ampersand
318 | Self::Exclamation
319 | Self::ColonEqual
320 | Self::Arrow
321 | Self::LArrow
322 | Self::DoubleColon
323 | Self::PlusPlus
324 | Self::MinusMinus => UniversalTokenRole::Operator,
325 Self::LeftParen
326 | Self::RightParen
327 | Self::LeftBracket
328 | Self::RightBracket
329 | Self::LeftBrace
330 | Self::RightBrace
331 | Self::LeftBracketBar
332 | Self::RightBracketBar
333 | Self::LeftBracketAngle
334 | Self::RightBracketAngle
335 | Self::Comma
336 | Self::Semicolon
337 | Self::Colon
338 | Self::Dot
339 | Self::DotDot
340 | Self::Hash => UniversalTokenRole::Punctuation,
341 Self::Eof => UniversalTokenRole::Eof,
342 _ => UniversalTokenRole::None,
343 }
344 }
345
346 fn is_comment(&self) -> bool {
347 matches!(self, Self::LineComment | Self::BlockComment)
348 }
349
350 fn is_whitespace(&self) -> bool {
351 matches!(self, Self::Whitespace | Self::Newline)
352 }
353}
354
355impl ElementType for FSharpSyntaxKind {
356 type Role = UniversalElementRole;
357
358 fn role(&self) -> Self::Role {
359 match self {
360 Self::Root => UniversalElementRole::Root,
361 Self::Error => UniversalElementRole::Error,
362 _ => UniversalElementRole::None,
363 }
364 }
365
366 fn is_error(&self) -> bool {
367 matches!(self, Self::Error)
368 }
369
370 fn is_root(&self) -> bool {
371 matches!(self, Self::Root)
372 }
373}