-
Notifications
You must be signed in to change notification settings - Fork 3
/
statements.ts
257 lines (233 loc) · 5.12 KB
/
statements.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import CodeLocation from "../CodeLocation";
import DocComment from "../comments/DocComment";
import LiteralToken from "../LiteralToken";
import Token from "../Token";
import AssignmentNode from "./AssignmentNode";
import ASTNode from "./ASTNode";
import ASTVisitor from "./ASTVisitor";
import { Expression } from "./expressions";
/**
* @category AST
*/
export abstract class Statement extends ASTNode {}
/**
* @category AST
*/
export class UseStmt extends Statement {
/**
*
* @param pos
* @param filename The used filename
*/
constructor(
public filename: string,
public tokens: {
useKeyword: Token;
filename: LiteralToken<string>;
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitUseStmt(this);
}
}
/**
* @category AST
*/
export class IncludeStmt extends Statement {
/**
*
* @param pos
* @param filename The used filename
*/
constructor(
public filename: string,
public tokens: {
includeKeyword: Token;
filename: LiteralToken<string>;
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitIncludeStmt(this);
}
}
/**
* Represents a statement that can be prefixed with the !%#* symbols to change it's behaviour.
* @category AST
*/
export interface TaggableStatement {
/**
* Set to true if this module instantation has been tagged with a '!' symbol.
*/
tagRoot: boolean;
/**
* Set to true if this module instantation has been tagged with a '#' symbol.
*/
tagHighlight: boolean;
/**
* Set to true if this module instantation has been tagged with a '%' symbol.
*/
tagBackground: boolean;
/**
* Set to true if this module instantation has been tagged with a '*' symbol.
*/
tagDisabled: boolean;
}
/**
* @category AST
*/
export class ModuleInstantiationStmt
extends Statement
implements TaggableStatement
{
/**
* !
*/
public tagRoot: boolean = false;
/**
* #
*/
public tagHighlight: boolean = false;
/**
* %
*/
public tagBackground: boolean = false;
/**
* *
*/
public tagDisabled: boolean = false;
constructor(
public name: string,
public args: AssignmentNode[],
/**
* The child statement in a module instantiation chain.
* Can be null if this is the last statement in the chain.
*/
public child: Statement | null,
public tokens: {
name: Token;
firstParen: Token;
secondParen: Token;
modifiersInOrder: Token[];
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitModuleInstantiationStmt(this);
}
}
/**
* @category AST
*/
export class ModuleDeclarationStmt extends Statement {
constructor(
public name: string,
public definitionArgs: AssignmentNode[],
public stmt: Statement,
public tokens: {
moduleKeyword: Token;
name: Token;
firstParen: Token;
secondParen: Token;
},
public docComment: DocComment
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitModuleDeclarationStmt(this);
}
}
/**
* FunctionDeclarationStmt reperesents a named function declaration statement.
* @category AST
*/
export class FunctionDeclarationStmt extends Statement {
constructor(
public name: string,
public definitionArgs: AssignmentNode[],
public expr: Expression,
public tokens: {
functionKeyword: Token;
name: Token;
firstParen: Token;
secondParen: Token;
equals: Token;
semicolon: Token;
},
public docComment: DocComment
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitFunctionDeclarationStmt(this);
}
}
/**
* @category AST
*/
export class BlockStmt extends Statement {
constructor(
public children: Statement[],
public tokens: {
firstBrace: Token;
secondBrace: Token;
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitBlockStmt(this);
}
}
/**
* @category AST
*/
export class NoopStmt extends Statement {
constructor(
public tokens: {
semicolon: Token;
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitNoopStmt(this);
}
}
/**
* IfElseStmt represents an if-else statement. elseIfs are represented as
* additional IfElseStmt instances in the else branch (simmilar to how C works).
* @category AST
*/
export class IfElseStatement extends Statement implements TaggableStatement {
public tagRoot: boolean = false;
public tagHighlight: boolean = false;
public tagBackground: boolean = false;
public tagDisabled: boolean = false;
constructor(
public cond: Expression,
public thenBranch: Statement,
/**
* The else branch.
* It can be null if there is no else branch.
*/
public elseBranch: Statement | null,
public tokens: {
ifKeyword: Token;
firstParen: Token;
secondParen: Token;
elseKeyword: Token | null;
modifiersInOrder: Token[];
}
) {
super();
}
accept<R>(visitor: ASTVisitor<R>): R {
return visitor.visitIfElseStatement(this);
}
}