1use oak_core::{ElementType, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4pub type DartToken = Token<DartSyntaxKind>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum DartSyntaxKind {
9 Root,
11 ClassDeclaration,
13 FunctionDeclaration,
15 Whitespace,
17 Newline,
19
20 Identifier,
22 IntegerLiteral,
24 DoubleLiteral,
26 StringLiteral,
28 BooleanLiteral,
30 NullLiteral,
32
33 Abstract,
35 As,
37 Assert,
39 Async,
41 Await,
43 Break,
45 Case,
47 Catch,
49 Class,
51 Const,
53 Continue,
55 Covariant,
57 Default,
59 Deferred,
61 Do,
63 Dynamic,
65 Else,
67 Enum,
69 Export,
71 Extends,
73 Extension,
75 External,
77 Factory,
79 False,
81 Final,
83 Finally,
85 For,
87 Function,
89 Get,
91 Hide,
93 If,
95 Implements,
97 Import,
99 In,
101 Interface,
103 Is,
105 Late,
107 Library,
109 Mixin,
111 New,
113 Null,
115 On,
117 Operator,
119 Part,
121 Required,
123 Rethrow,
125 Return,
127 Set,
129 Show,
131 Static,
133 Super,
135 Switch,
137 Sync,
139 This,
141 Throw,
143 True,
145 Try,
147 Typedef,
149 Var,
151 Void,
153 While,
155 With,
157 Yield,
159
160 Plus,
162 Minus,
164 Star,
166 Slash,
168 Percent,
170 TildeSlash,
172 Equal,
174 EqualEqual,
176 BangEqual,
178 Less,
180 Greater,
182 LessEqual,
184 GreaterEqual,
186 LeftShift,
188 RightShift,
190 Ampersand,
192 Pipe,
194 Caret,
196 Tilde,
198 Bang,
200 AmpersandAmpersand,
202 PipePipe,
204 Question,
206 QuestionQuestion,
208 PlusPlus,
210 MinusMinus,
212 PlusEqual,
214 MinusEqual,
216 StarEqual,
218 SlashEqual,
220 PercentEqual,
222 TildeSlashEqual,
224 LeftShiftEqual,
226 RightShiftEqual,
228 AmpersandEqual,
230 PipeEqual,
232 CaretEqual,
234 QuestionQuestionEqual,
236 Arrow,
238 Dot,
240 DotDot,
242 DotDotDot,
244 QuestionDot,
246
247 LeftParen,
249 RightParen,
251 LeftBracket,
253 RightBracket,
255 LeftBrace,
257 RightBrace,
259 Semicolon,
261 Comma,
263 Colon,
265 At,
267 Hash,
269
270 LineComment,
272 BlockComment,
274 DocComment,
276
277 Error,
279
280 Eof,
282 VariableDeclaration,
284}
285
286impl TokenType for DartSyntaxKind {
287 const END_OF_STREAM: Self = Self::Eof;
288 type Role = UniversalTokenRole;
289
290 fn is_ignored(&self) -> bool {
291 matches!(self, Self::Whitespace | Self::Newline | Self::LineComment | Self::BlockComment | Self::DocComment)
292 }
293
294 fn is_comment(&self) -> bool {
295 matches!(self, Self::LineComment | Self::BlockComment | Self::DocComment)
296 }
297
298 fn is_whitespace(&self) -> bool {
299 matches!(self, Self::Whitespace | Self::Newline)
300 }
301
302 fn role(&self) -> Self::Role {
303 match self {
304 Self::Whitespace => UniversalTokenRole::Whitespace,
305 Self::Newline => UniversalTokenRole::Whitespace,
306 Self::Identifier => UniversalTokenRole::Name,
307 Self::IntegerLiteral | Self::DoubleLiteral | Self::StringLiteral | Self::BooleanLiteral | Self::NullLiteral => UniversalTokenRole::Literal,
308 Self::Abstract
309 | Self::As
310 | Self::Assert
311 | Self::Async
312 | Self::Await
313 | Self::Break
314 | Self::Case
315 | Self::Catch
316 | Self::Class
317 | Self::Const
318 | Self::Continue
319 | Self::Covariant
320 | Self::Default
321 | Self::Deferred
322 | Self::Do
323 | Self::Dynamic
324 | Self::Else
325 | Self::Enum
326 | Self::Export
327 | Self::Extends
328 | Self::Extension
329 | Self::External
330 | Self::Factory
331 | Self::False
332 | Self::Final
333 | Self::Finally
334 | Self::For
335 | Self::Function
336 | Self::Get
337 | Self::Hide
338 | Self::If
339 | Self::Implements
340 | Self::Import
341 | Self::In
342 | Self::Interface
343 | Self::Is
344 | Self::Late
345 | Self::Library
346 | Self::Mixin
347 | Self::New
348 | Self::Null
349 | Self::On
350 | Self::Operator
351 | Self::Part
352 | Self::Required
353 | Self::Rethrow
354 | Self::Return
355 | Self::Set
356 | Self::Show
357 | Self::Static
358 | Self::Super
359 | Self::Switch
360 | Self::Sync
361 | Self::This
362 | Self::Throw
363 | Self::True
364 | Self::Try
365 | Self::Typedef
366 | Self::Var
367 | Self::Void
368 | Self::While
369 | Self::With
370 | Self::Yield => UniversalTokenRole::Keyword,
371 Self::Plus
372 | Self::Minus
373 | Self::Star
374 | Self::Slash
375 | Self::Percent
376 | Self::TildeSlash
377 | Self::Equal
378 | Self::EqualEqual
379 | Self::BangEqual
380 | Self::Less
381 | Self::Greater
382 | Self::LessEqual
383 | Self::GreaterEqual
384 | Self::LeftShift
385 | Self::RightShift
386 | Self::Ampersand
387 | Self::Pipe
388 | Self::Caret
389 | Self::Tilde
390 | Self::Bang
391 | Self::AmpersandAmpersand
392 | Self::PipePipe
393 | Self::Question
394 | Self::QuestionQuestion
395 | Self::PlusPlus
396 | Self::MinusMinus
397 | Self::PlusEqual
398 | Self::MinusEqual
399 | Self::StarEqual
400 | Self::SlashEqual
401 | Self::PercentEqual
402 | Self::TildeSlashEqual
403 | Self::LeftShiftEqual
404 | Self::RightShiftEqual
405 | Self::AmpersandEqual
406 | Self::PipeEqual
407 | Self::CaretEqual
408 | Self::QuestionQuestionEqual
409 | Self::Arrow
410 | Self::Dot
411 | Self::DotDot
412 | Self::DotDotDot
413 | Self::QuestionDot => UniversalTokenRole::Operator,
414 Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::LeftBrace | Self::RightBrace | Self::Semicolon | Self::Comma | Self::Colon | Self::At | Self::Hash => UniversalTokenRole::Punctuation,
415 Self::LineComment | Self::BlockComment | Self::DocComment => UniversalTokenRole::Comment,
416 Self::Error => UniversalTokenRole::Error,
417 Self::Eof | Self::Root | Self::ClassDeclaration | Self::FunctionDeclaration | Self::VariableDeclaration => UniversalTokenRole::None,
418 }
419 }
420}
421
422impl ElementType for DartSyntaxKind {
423 type Role = UniversalElementRole;
424
425 fn is_root(&self) -> bool {
426 matches!(self, Self::Root)
427 }
428
429 fn is_error(&self) -> bool {
430 matches!(self, Self::Error)
431 }
432
433 fn role(&self) -> Self::Role {
434 match self {
435 Self::Root => UniversalElementRole::Root,
436 Self::ClassDeclaration => UniversalElementRole::Definition,
437 Self::FunctionDeclaration => UniversalElementRole::Definition,
438 Self::VariableDeclaration => UniversalElementRole::Definition,
439 Self::Error => UniversalElementRole::Error,
440 _ => UniversalElementRole::None,
441 }
442 }
443}