-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostTypeDeclarationExtractionAst.ts
162 lines (139 loc) · 3.23 KB
/
postTypeDeclarationExtractionAst.ts
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import SourceLocation from './parser-lib/sourceLocation';
import { Leaf } from './ast';
import { Variable } from './api';
import { TypeExpression } from './frontend';
export type ReturnStatement = {
kind: 'returnStatement';
sourceLocation: SourceLocation;
expression: Expression;
};
export type Ternary = {
kind: 'ternary';
sourceLocation: SourceLocation;
condition: Expression;
ifTrue: Expression;
ifFalse: Expression;
};
export type Equality = {
kind: 'equality';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: Expression;
};
export type Declaration = {
kind: 'declaration';
sourceLocation: SourceLocation;
destination: string;
type: TypeExpression | undefined;
expression: Expression;
exported: boolean;
};
export type Reassignment = {
kind: 'reassignment';
sourceLocation: SourceLocation;
destination: string;
expression: Expression;
};
export type FunctionCall = {
kind: 'callExpression';
sourceLocation: SourceLocation;
name: string;
arguments: Expression[];
};
export type MemberStyleCall = {
kind: 'memberStyleCall';
sourceLocation: SourceLocation;
lhs: Expression;
memberName: string;
params: Expression[];
};
export type MemberAccess = {
kind: 'memberAccess';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: string;
};
export type Parameter = {
name: string;
type: TypeExpression;
};
export type FunctionLiteral = {
kind: 'functionLiteral';
sourceLocation: SourceLocation;
body: Statement[];
parameters: Parameter[];
};
export type Addition = {
kind: 'addition';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: Expression;
};
export type Subtraction = {
kind: 'subtraction';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: Expression;
};
export type Product = {
kind: 'product';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: Expression;
};
export type Concatenation = {
kind: 'concatenation';
sourceLocation: SourceLocation;
lhs: Expression;
rhs: Expression;
};
export type ForLoop = {
kind: 'forLoop';
sourceLocation: SourceLocation;
var: Variable;
list: Expression;
body: Statement[];
};
export type ObjectMember = {
name: string;
expression: Expression;
};
export type ObjectLiteral = {
kind: 'objectLiteral';
sourceLocation: SourceLocation;
typeName: string;
members: ObjectMember[];
};
export type ListLiteral = {
kind: 'listLiteral';
sourceLocation: SourceLocation;
items: Expression[];
};
export type IndexAccess = {
kind: 'indexAccess';
sourceLocation: SourceLocation;
index: Expression;
accessed: Expression;
};
export type Program = {
kind: 'program';
sourceLocation: SourceLocation;
statements: Statement[];
};
export type Statement = Declaration | Reassignment | ForLoop | ReturnStatement;
export type Expression =
| Leaf
| ObjectLiteral
| Ternary
| Equality
| FunctionCall
| FunctionLiteral
| Subtraction
| Addition
| Product
| Concatenation
| MemberAccess
| MemberStyleCall
| ListLiteral
| IndexAccess;
export type Ast = Statement | Program | Expression;