1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#![cfg_attr(coverage_nightly, coverage(off))]
//! Language-agnostic AST node kind enumerations.
use serde::{Deserialize, Serialize};
/// Language-agnostic AST node kinds
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u16)]
pub enum AstKind {
// Universal constructs
Function(FunctionKind),
Class(ClassKind),
Variable(VarKind),
Import(ImportKind),
Expression(ExprKind),
Statement(StmtKind),
Type(TypeKind),
Module(ModuleKind),
Macro(MacroKind), // C-specific preprocessor macros
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FunctionKind {
Regular,
Method,
Constructor,
Getter,
Setter,
Lambda,
Closure,
Destructor, // C++ destructor
Operator, // C++ operator overload
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClassKind {
Regular,
Abstract,
Interface,
Trait,
Enum,
Struct,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum VarKind {
Let,
Const,
Static,
Field,
Parameter,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ImportKind {
Module,
Named,
Default,
Namespace,
Dynamic,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ExprKind {
Call,
Member,
Binary,
Unary,
Literal,
Identifier,
Array,
Object,
New, // C++ new expression
Delete, // C++ delete expression
Lambda, // C++ lambda expression
Conditional, // TypeScript conditional expression (?:)
This, // TypeScript this expression
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StmtKind {
Block,
If,
For,
While,
Return,
Throw,
Try,
Switch,
Goto, // C-specific
Label, // C-specific
DoWhile, // C-specific
ForEach, // C++ range-based for
Catch, // C++ catch clause
Break, // break statement
Continue, // continue statement
Case, // case statement in switch
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TypeKind {
Primitive,
Array,
Tuple,
Union,
Intersection,
Generic,
Function,
Object,
Pointer, // C-specific
Struct, // C-specific (distinct from Object)
Enum, // C-specific enum (distinct from Rust enum)
Typedef, // C-specific
Class, // C++ class
Template, // C++ template
Namespace, // C++ namespace
Alias, // C++ using alias
Interface, // TypeScript interface
Module, // TypeScript module
Annotation, // TypeScript type annotation
Mapped, // TypeScript mapped type
Conditional, // TypeScript conditional type
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ModuleKind {
File,
Namespace,
Package,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum MacroKind {
ObjectLike, // #define PI 3.14
FunctionLike, // #define MAX(a,b) ((a)>(b)?(a):(b))
Variadic, // #define DEBUG(...) fprintf(stderr, __VA_ARGS__)
Include, // #include <stdio.h>
Conditional, // #ifdef, #ifndef, #if, #elif, #else, #endif
Export, // TypeScript export macro
Decorator, // TypeScript decorator
}