1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum TypeScriptSyntaxKind {
6 Root,
8 SourceFile,
9 Module,
10
11 VariableDeclaration,
13 FunctionDeclaration,
14 ClassDeclaration,
15 InterfaceDeclaration,
16 TypeAliasDeclaration,
17 EnumDeclaration,
18 NamespaceDeclaration,
19 ImportDeclaration,
20 ExportDeclaration,
21
22 BinaryExpression,
24 UnaryExpression,
25 ConditionalExpression,
26 CallExpression,
27 NewExpression,
28 MemberExpression,
29 ArrayExpression,
30 ObjectExpression,
31 FunctionExpression,
32 ArrowFunction,
33 TemplateExpression,
34 TaggedTemplateExpression,
35 AsExpression,
36 TypeAssertionExpression,
37 NonNullExpression,
38
39 ExpressionStatement,
41 BlockStatement,
42 IfStatement,
43 WhileStatement,
44 ForStatement,
45 ForInStatement,
46 ForOfStatement,
47 DoWhileStatement,
48 SwitchStatement,
49 CaseClause,
50 DefaultClause,
51 TryStatement,
52 CatchClause,
53 FinallyClause,
54 ThrowStatement,
55 ReturnStatement,
56 BreakStatement,
57 ContinueStatement,
58 DebuggerStatement,
59 WithStatement,
60
61 BindingPattern,
63 ArrayBindingPattern,
64 ObjectBindingPattern,
65 BindingElement,
66
67 TypeReference,
69 TypeLiteral,
70 FunctionType,
71 ConstructorType,
72 ArrayType,
73 TupleType,
74 UnionType,
75 IntersectionType,
76 ConditionalType,
77 MappedType,
78 IndexedAccessType,
79 TypeQuery,
80 TypePredicate,
81
82 Error,
84
85 Abstract,
87 Any,
88 As,
89 Asserts,
90 Async,
91 Await,
92 Boolean,
93 Break,
94 Case,
95 Catch,
96 Class,
97 Const,
98 Constructor,
99 Continue,
100 Debugger,
101 Declare,
102 Default,
103 Delete,
104 Do,
105 Else,
106 Enum,
107 Export,
108 Extends,
109 False,
110 Finally,
111 For,
112 From,
113 Function,
114 Get,
115 Global,
116 If,
117 Implements,
118 Import,
119 In,
120 Infer,
121 Instanceof,
122 Interface,
123 Is,
124 Keyof,
125 Let,
126 Namespace,
127 Never,
128 New,
129 Null,
130 Number,
131 Object,
132 Of,
133 Package,
134 Private,
135 Protected,
136 Public,
137 Readonly,
138 Require,
139 Return,
140 Set,
141 Static,
142 String,
143 Super,
144 Switch,
145 Symbol,
146 This,
147 Throw,
148 True,
149 Try,
150 Type,
151 Typeof,
152 Undefined,
153 Unique,
154 Unknown,
155 Var,
156 Void,
157 While,
158 With,
159 Yield,
160
161 Plus,
163 Minus,
164 Star,
165 Slash,
166 Percent,
167 StarStar,
168
169 Less,
171 Greater,
172 LessEqual,
173 GreaterEqual,
174 EqualEqual,
175 NotEqual,
176 EqualEqualEqual,
177 NotEqualEqual,
178
179 AmpersandAmpersand,
181 PipePipe,
182 Exclamation,
183
184 Ampersand,
186 Pipe,
187 Caret,
188 Tilde,
189 LeftShift,
190 RightShift,
191 UnsignedRightShift,
192
193 Equal,
195 PlusEqual,
196 MinusEqual,
197 StarEqual,
198 SlashEqual,
199 PercentEqual,
200 StarStarEqual,
201 LeftShiftEqual,
202 RightShiftEqual,
203 UnsignedRightShiftEqual,
204 AmpersandEqual,
205 PipeEqual,
206 CaretEqual,
207 AmpersandAmpersandEqual,
208 PipePipeEqual,
209 QuestionQuestionEqual,
210
211 PlusPlus,
213 MinusMinus,
214
215 Question,
217 QuestionQuestion,
218 QuestionDot,
219 Arrow,
220
221 LeftParen,
223 RightParen,
224 LeftBrace,
225 RightBrace,
226 LeftBracket,
227 RightBracket,
228 Semicolon,
229 Comma,
230 Dot,
231 DotDotDot,
232 Colon,
233
234 StringLiteral,
236 NumericLiteral,
237 BigIntLiteral,
238 TemplateString,
239 RegexLiteral,
240
241 IdentifierName,
243
244 LineComment,
246 BlockComment,
247 Whitespace,
248 Newline,
249
250 Eof,
252}
253
254impl SyntaxKind for TypeScriptSyntaxKind {
255 fn is_trivia(&self) -> bool {
256 matches!(
257 self,
258 TypeScriptSyntaxKind::LineComment
259 | TypeScriptSyntaxKind::BlockComment
260 | TypeScriptSyntaxKind::Whitespace
261 | TypeScriptSyntaxKind::Newline
262 )
263 }
264
265 fn is_comment(&self) -> bool {
266 matches!(self, TypeScriptSyntaxKind::LineComment | TypeScriptSyntaxKind::BlockComment)
267 }
268
269 fn is_whitespace(&self) -> bool {
270 matches!(self, TypeScriptSyntaxKind::Whitespace | TypeScriptSyntaxKind::Newline)
271 }
272
273 fn is_token_type(&self) -> bool {
274 !matches!(
275 self,
276 TypeScriptSyntaxKind::Root
277 | TypeScriptSyntaxKind::SourceFile
278 | TypeScriptSyntaxKind::Module
279 | TypeScriptSyntaxKind::VariableDeclaration
280 | TypeScriptSyntaxKind::FunctionDeclaration
281 | TypeScriptSyntaxKind::ClassDeclaration
282 | TypeScriptSyntaxKind::InterfaceDeclaration
283 | TypeScriptSyntaxKind::TypeAliasDeclaration
284 | TypeScriptSyntaxKind::EnumDeclaration
285 | TypeScriptSyntaxKind::NamespaceDeclaration
286 | TypeScriptSyntaxKind::ImportDeclaration
287 | TypeScriptSyntaxKind::ExportDeclaration
288 | TypeScriptSyntaxKind::BinaryExpression
289 | TypeScriptSyntaxKind::UnaryExpression
290 | TypeScriptSyntaxKind::ConditionalExpression
291 | TypeScriptSyntaxKind::CallExpression
292 | TypeScriptSyntaxKind::NewExpression
293 | TypeScriptSyntaxKind::MemberExpression
294 | TypeScriptSyntaxKind::ArrayExpression
295 | TypeScriptSyntaxKind::ObjectExpression
296 | TypeScriptSyntaxKind::FunctionExpression
297 | TypeScriptSyntaxKind::ArrowFunction
298 | TypeScriptSyntaxKind::TemplateExpression
299 | TypeScriptSyntaxKind::TaggedTemplateExpression
300 | TypeScriptSyntaxKind::AsExpression
301 | TypeScriptSyntaxKind::TypeAssertionExpression
302 | TypeScriptSyntaxKind::NonNullExpression
303 | TypeScriptSyntaxKind::ExpressionStatement
304 | TypeScriptSyntaxKind::BlockStatement
305 | TypeScriptSyntaxKind::IfStatement
306 | TypeScriptSyntaxKind::WhileStatement
307 | TypeScriptSyntaxKind::ForStatement
308 | TypeScriptSyntaxKind::ForInStatement
309 | TypeScriptSyntaxKind::ForOfStatement
310 | TypeScriptSyntaxKind::DoWhileStatement
311 | TypeScriptSyntaxKind::SwitchStatement
312 | TypeScriptSyntaxKind::CaseClause
313 | TypeScriptSyntaxKind::DefaultClause
314 | TypeScriptSyntaxKind::TryStatement
315 | TypeScriptSyntaxKind::CatchClause
316 | TypeScriptSyntaxKind::FinallyClause
317 | TypeScriptSyntaxKind::ThrowStatement
318 | TypeScriptSyntaxKind::ReturnStatement
319 | TypeScriptSyntaxKind::BreakStatement
320 | TypeScriptSyntaxKind::ContinueStatement
321 | TypeScriptSyntaxKind::DebuggerStatement
322 | TypeScriptSyntaxKind::WithStatement
323 | TypeScriptSyntaxKind::BindingPattern
324 | TypeScriptSyntaxKind::ArrayBindingPattern
325 | TypeScriptSyntaxKind::ObjectBindingPattern
326 | TypeScriptSyntaxKind::BindingElement
327 | TypeScriptSyntaxKind::TypeReference
328 | TypeScriptSyntaxKind::TypeLiteral
329 | TypeScriptSyntaxKind::FunctionType
330 | TypeScriptSyntaxKind::ConstructorType
331 | TypeScriptSyntaxKind::ArrayType
332 | TypeScriptSyntaxKind::TupleType
333 | TypeScriptSyntaxKind::UnionType
334 | TypeScriptSyntaxKind::IntersectionType
335 | TypeScriptSyntaxKind::ConditionalType
336 | TypeScriptSyntaxKind::MappedType
337 | TypeScriptSyntaxKind::IndexedAccessType
338 | TypeScriptSyntaxKind::TypeQuery
339 | TypeScriptSyntaxKind::TypePredicate
340 | TypeScriptSyntaxKind::Error
341 )
342 }
343
344 fn is_element_type(&self) -> bool {
345 matches!(
346 self,
347 TypeScriptSyntaxKind::Root
348 | TypeScriptSyntaxKind::SourceFile
349 | TypeScriptSyntaxKind::Module
350 | TypeScriptSyntaxKind::VariableDeclaration
351 | TypeScriptSyntaxKind::FunctionDeclaration
352 | TypeScriptSyntaxKind::ClassDeclaration
353 | TypeScriptSyntaxKind::InterfaceDeclaration
354 | TypeScriptSyntaxKind::TypeAliasDeclaration
355 | TypeScriptSyntaxKind::EnumDeclaration
356 | TypeScriptSyntaxKind::NamespaceDeclaration
357 | TypeScriptSyntaxKind::ImportDeclaration
358 | TypeScriptSyntaxKind::ExportDeclaration
359 | TypeScriptSyntaxKind::BinaryExpression
360 | TypeScriptSyntaxKind::UnaryExpression
361 | TypeScriptSyntaxKind::ConditionalExpression
362 | TypeScriptSyntaxKind::CallExpression
363 | TypeScriptSyntaxKind::NewExpression
364 | TypeScriptSyntaxKind::MemberExpression
365 | TypeScriptSyntaxKind::ArrayExpression
366 | TypeScriptSyntaxKind::ObjectExpression
367 | TypeScriptSyntaxKind::FunctionExpression
368 | TypeScriptSyntaxKind::ArrowFunction
369 | TypeScriptSyntaxKind::TemplateExpression
370 | TypeScriptSyntaxKind::TaggedTemplateExpression
371 | TypeScriptSyntaxKind::AsExpression
372 | TypeScriptSyntaxKind::TypeAssertionExpression
373 | TypeScriptSyntaxKind::NonNullExpression
374 | TypeScriptSyntaxKind::ExpressionStatement
375 | TypeScriptSyntaxKind::BlockStatement
376 | TypeScriptSyntaxKind::IfStatement
377 | TypeScriptSyntaxKind::WhileStatement
378 | TypeScriptSyntaxKind::ForStatement
379 | TypeScriptSyntaxKind::ForInStatement
380 | TypeScriptSyntaxKind::ForOfStatement
381 | TypeScriptSyntaxKind::DoWhileStatement
382 | TypeScriptSyntaxKind::SwitchStatement
383 | TypeScriptSyntaxKind::CaseClause
384 | TypeScriptSyntaxKind::DefaultClause
385 | TypeScriptSyntaxKind::TryStatement
386 | TypeScriptSyntaxKind::CatchClause
387 | TypeScriptSyntaxKind::FinallyClause
388 | TypeScriptSyntaxKind::ThrowStatement
389 | TypeScriptSyntaxKind::ReturnStatement
390 | TypeScriptSyntaxKind::BreakStatement
391 | TypeScriptSyntaxKind::ContinueStatement
392 | TypeScriptSyntaxKind::DebuggerStatement
393 | TypeScriptSyntaxKind::WithStatement
394 | TypeScriptSyntaxKind::BindingPattern
395 | TypeScriptSyntaxKind::ArrayBindingPattern
396 | TypeScriptSyntaxKind::ObjectBindingPattern
397 | TypeScriptSyntaxKind::BindingElement
398 | TypeScriptSyntaxKind::TypeReference
399 | TypeScriptSyntaxKind::TypeLiteral
400 | TypeScriptSyntaxKind::FunctionType
401 | TypeScriptSyntaxKind::ConstructorType
402 | TypeScriptSyntaxKind::ArrayType
403 | TypeScriptSyntaxKind::TupleType
404 | TypeScriptSyntaxKind::UnionType
405 | TypeScriptSyntaxKind::IntersectionType
406 | TypeScriptSyntaxKind::ConditionalType
407 | TypeScriptSyntaxKind::MappedType
408 | TypeScriptSyntaxKind::IndexedAccessType
409 | TypeScriptSyntaxKind::TypeQuery
410 | TypeScriptSyntaxKind::TypePredicate
411 | TypeScriptSyntaxKind::Error
412 )
413 }
414}