yukigo-ast 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/globals/generics.d.ts +740 -0
- package/dist/globals/generics.js +1128 -0
- package/dist/globals/helpers.d.ts +4 -0
- package/dist/globals/helpers.js +76 -0
- package/dist/globals/operators.d.ts +251 -0
- package/dist/globals/operators.js +336 -0
- package/dist/globals/patterns.d.ts +170 -0
- package/dist/globals/patterns.js +261 -0
- package/dist/globals/runtime.d.ts +22 -0
- package/dist/globals/runtime.js +6 -0
- package/dist/globals/types.d.ts +185 -0
- package/dist/globals/types.js +329 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/paradigms/data.d.ts +246 -0
- package/dist/paradigms/data.js +348 -0
- package/dist/paradigms/functional.d.ts +59 -0
- package/dist/paradigms/functional.js +103 -0
- package/dist/paradigms/imperative.d.ts +124 -0
- package/dist/paradigms/imperative.js +188 -0
- package/dist/paradigms/logic.d.ts +163 -0
- package/dist/paradigms/logic.js +240 -0
- package/dist/paradigms/object.d.ts +201 -0
- package/dist/paradigms/object.js +308 -0
- package/dist/visitor.d.ts +254 -0
- package/dist/visitor.js +426 -0
- package/package.json +25 -0
- package/src/globals/generics.ts +1421 -0
- package/src/globals/helpers.ts +107 -0
- package/src/globals/operators.ts +515 -0
- package/src/globals/patterns.ts +321 -0
- package/src/globals/runtime.ts +33 -0
- package/src/globals/types.ts +375 -0
- package/src/index.ts +12 -0
- package/src/paradigms/data.ts +393 -0
- package/src/paradigms/functional.ts +129 -0
- package/src/paradigms/imperative.ts +232 -0
- package/src/paradigms/logic.ts +314 -0
- package/src/paradigms/object.ts +366 -0
- package/src/visitor.ts +692 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASTNode,
|
|
3
|
+
Equation,
|
|
4
|
+
Expression,
|
|
5
|
+
SourceLocation,
|
|
6
|
+
SymbolPrimitive,
|
|
7
|
+
} from "../globals/generics.js";
|
|
8
|
+
import { Operator } from "../globals/operators.js";
|
|
9
|
+
import { Visitor } from "../visitor.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a method definition within a class or object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* method exhaust() {
|
|
16
|
+
* energy -= 5
|
|
17
|
+
* }
|
|
18
|
+
* @category OOP
|
|
19
|
+
*/
|
|
20
|
+
export class Method extends ASTNode {
|
|
21
|
+
/** @hidden */
|
|
22
|
+
public equations: Equation[];
|
|
23
|
+
/** @hidden */
|
|
24
|
+
public identifier: SymbolPrimitive;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
identifier: SymbolPrimitive,
|
|
28
|
+
equations: Equation[],
|
|
29
|
+
loc?: SourceLocation
|
|
30
|
+
) {
|
|
31
|
+
super(loc);
|
|
32
|
+
this.identifier = identifier;
|
|
33
|
+
this.equations = equations;
|
|
34
|
+
}
|
|
35
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
36
|
+
return visitor.visitMethod?.(this);
|
|
37
|
+
}
|
|
38
|
+
public toJSON() {
|
|
39
|
+
return {
|
|
40
|
+
type: "Method",
|
|
41
|
+
identifier: this.identifier.toJSON(),
|
|
42
|
+
equations: this.equations.map((eq) => eq.toJSON()),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents an attribute or instance variable of an object.
|
|
49
|
+
* @category OOP
|
|
50
|
+
*/
|
|
51
|
+
export class Attribute extends ASTNode {
|
|
52
|
+
/** @hidden */
|
|
53
|
+
public expression: Expression;
|
|
54
|
+
/** @hidden */
|
|
55
|
+
public identifier: SymbolPrimitive;
|
|
56
|
+
|
|
57
|
+
constructor(
|
|
58
|
+
identifier: SymbolPrimitive,
|
|
59
|
+
expression: Expression,
|
|
60
|
+
loc?: SourceLocation
|
|
61
|
+
) {
|
|
62
|
+
super(loc);
|
|
63
|
+
this.identifier = identifier;
|
|
64
|
+
this.expression = expression;
|
|
65
|
+
}
|
|
66
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
67
|
+
return visitor.visitAttribute?.(this);
|
|
68
|
+
}
|
|
69
|
+
public toJSON() {
|
|
70
|
+
return {
|
|
71
|
+
type: "Attribute",
|
|
72
|
+
identifier: this.identifier.toJSON(),
|
|
73
|
+
expression: this.expression.toJSON(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Represents an object definition or a singleton object.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* object pepita { ... }
|
|
83
|
+
* @category OOP
|
|
84
|
+
*/
|
|
85
|
+
export class Object extends ASTNode {
|
|
86
|
+
/** @hidden */
|
|
87
|
+
public expression: Expression;
|
|
88
|
+
/** @hidden */
|
|
89
|
+
public identifier: SymbolPrimitive;
|
|
90
|
+
|
|
91
|
+
constructor(
|
|
92
|
+
identifier: SymbolPrimitive,
|
|
93
|
+
expression: Expression,
|
|
94
|
+
loc?: SourceLocation
|
|
95
|
+
) {
|
|
96
|
+
super(loc);
|
|
97
|
+
this.identifier = identifier;
|
|
98
|
+
this.expression = expression;
|
|
99
|
+
}
|
|
100
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
101
|
+
return visitor.visitObject?.(this);
|
|
102
|
+
}
|
|
103
|
+
public toJSON() {
|
|
104
|
+
return {
|
|
105
|
+
type: "Object",
|
|
106
|
+
identifier: this.identifier.toJSON(),
|
|
107
|
+
expression: this.expression.toJSON(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Represents a class definition, a blueprint for objects.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* class Bird inherits Animal { ... }
|
|
117
|
+
* @category OOP
|
|
118
|
+
*/
|
|
119
|
+
export class Class extends ASTNode {
|
|
120
|
+
/** @hidden */
|
|
121
|
+
public expression: Expression;
|
|
122
|
+
/** @hidden */
|
|
123
|
+
public implementsNode: Implement | undefined;
|
|
124
|
+
/** @hidden */
|
|
125
|
+
public extendsSymbol: SymbolPrimitive | undefined;
|
|
126
|
+
/** @hidden */
|
|
127
|
+
public identifier: SymbolPrimitive;
|
|
128
|
+
|
|
129
|
+
constructor(
|
|
130
|
+
identifier: SymbolPrimitive,
|
|
131
|
+
extendsSymbol: SymbolPrimitive | undefined,
|
|
132
|
+
implementsNode: Implement | undefined,
|
|
133
|
+
expression: Expression,
|
|
134
|
+
loc?: SourceLocation
|
|
135
|
+
) {
|
|
136
|
+
super(loc);
|
|
137
|
+
this.identifier = identifier;
|
|
138
|
+
this.extendsSymbol = extendsSymbol;
|
|
139
|
+
this.implementsNode = implementsNode;
|
|
140
|
+
this.expression = expression;
|
|
141
|
+
}
|
|
142
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
143
|
+
return visitor.visitClass?.(this);
|
|
144
|
+
}
|
|
145
|
+
public toJSON() {
|
|
146
|
+
return {
|
|
147
|
+
type: "Class",
|
|
148
|
+
identifier: this.identifier.toJSON(),
|
|
149
|
+
extends: this.extendsSymbol.toJSON(),
|
|
150
|
+
implements: this.implementsNode.toJSON(),
|
|
151
|
+
expression: this.expression.toJSON(),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Represents an interface or protocol definition.
|
|
158
|
+
* @category OOP
|
|
159
|
+
*/
|
|
160
|
+
export class Interface extends ASTNode {
|
|
161
|
+
/** @hidden */
|
|
162
|
+
public expression: Expression;
|
|
163
|
+
/** @hidden */
|
|
164
|
+
public extendsSymbol: SymbolPrimitive[];
|
|
165
|
+
/** @hidden */
|
|
166
|
+
public identifier: SymbolPrimitive;
|
|
167
|
+
|
|
168
|
+
constructor(
|
|
169
|
+
identifier: SymbolPrimitive,
|
|
170
|
+
extendsSymbol: SymbolPrimitive[],
|
|
171
|
+
expression: Expression,
|
|
172
|
+
loc?: SourceLocation
|
|
173
|
+
) {
|
|
174
|
+
super(loc);
|
|
175
|
+
this.identifier = identifier;
|
|
176
|
+
this.extendsSymbol = extendsSymbol;
|
|
177
|
+
this.expression = expression;
|
|
178
|
+
}
|
|
179
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
180
|
+
return visitor.visitInterface?.(this);
|
|
181
|
+
}
|
|
182
|
+
public toJSON() {
|
|
183
|
+
return {
|
|
184
|
+
type: "Interface",
|
|
185
|
+
identifier: this.identifier.toJSON(),
|
|
186
|
+
extends: this.extendsSymbol.map((symbol) => symbol.toJSON()),
|
|
187
|
+
expression: this.expression.toJSON(),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Represents a message send or method invocation on an object.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* pepita.fly(10)
|
|
197
|
+
* @category OOP
|
|
198
|
+
*/
|
|
199
|
+
export class Send extends ASTNode {
|
|
200
|
+
/** @hidden */
|
|
201
|
+
public args: Expression[];
|
|
202
|
+
/** @hidden */
|
|
203
|
+
public selector: Expression;
|
|
204
|
+
/** @hidden */
|
|
205
|
+
public receiver: Expression;
|
|
206
|
+
|
|
207
|
+
constructor(
|
|
208
|
+
receiver: Expression,
|
|
209
|
+
selector: Expression,
|
|
210
|
+
args: Expression[],
|
|
211
|
+
loc?: SourceLocation
|
|
212
|
+
) {
|
|
213
|
+
super(loc);
|
|
214
|
+
this.receiver = receiver;
|
|
215
|
+
this.selector = selector;
|
|
216
|
+
this.args = args;
|
|
217
|
+
}
|
|
218
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
219
|
+
return visitor.visitSend?.(this);
|
|
220
|
+
}
|
|
221
|
+
public toJSON() {
|
|
222
|
+
return {
|
|
223
|
+
type: "Send",
|
|
224
|
+
receiver: this.receiver.toJSON(),
|
|
225
|
+
selector: this.selector.toJSON(),
|
|
226
|
+
arguments: this.args.map((arg) => arg.toJSON()),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Represents the instantiation of a class.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* new Bird()
|
|
236
|
+
* @category OOP
|
|
237
|
+
*/
|
|
238
|
+
export class New extends ASTNode {
|
|
239
|
+
/** @hidden */
|
|
240
|
+
public args: Expression[];
|
|
241
|
+
/** @hidden */
|
|
242
|
+
public identifier: SymbolPrimitive;
|
|
243
|
+
|
|
244
|
+
constructor(
|
|
245
|
+
identifier: SymbolPrimitive,
|
|
246
|
+
args: Expression[],
|
|
247
|
+
loc?: SourceLocation
|
|
248
|
+
) {
|
|
249
|
+
super(loc);
|
|
250
|
+
this.identifier = identifier;
|
|
251
|
+
this.args = args;
|
|
252
|
+
}
|
|
253
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
254
|
+
return visitor.visitNew?.(this);
|
|
255
|
+
}
|
|
256
|
+
public toJSON() {
|
|
257
|
+
return {
|
|
258
|
+
type: "New",
|
|
259
|
+
identifier: this.identifier.toJSON(),
|
|
260
|
+
arguments: this.args.map((arg) => arg.toJSON()),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Represents an implementation clause for an interface.
|
|
267
|
+
* @category OOP
|
|
268
|
+
*/
|
|
269
|
+
export class Implement extends ASTNode {
|
|
270
|
+
/** @hidden */
|
|
271
|
+
public identifier: SymbolPrimitive;
|
|
272
|
+
|
|
273
|
+
constructor(identifier: SymbolPrimitive, loc?: SourceLocation) {
|
|
274
|
+
super(loc);
|
|
275
|
+
this.identifier = identifier;
|
|
276
|
+
}
|
|
277
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
278
|
+
return visitor.visitImplement?.(this);
|
|
279
|
+
}
|
|
280
|
+
public toJSON() {
|
|
281
|
+
return {
|
|
282
|
+
type: "Implement",
|
|
283
|
+
identifier: this.identifier.toJSON(),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Represents the inclusion of a module or mixin.
|
|
290
|
+
* @category OOP
|
|
291
|
+
*/
|
|
292
|
+
export class Include extends ASTNode {
|
|
293
|
+
/** @hidden */
|
|
294
|
+
public identifier: SymbolPrimitive;
|
|
295
|
+
|
|
296
|
+
constructor(identifier: SymbolPrimitive, loc?: SourceLocation) {
|
|
297
|
+
super(loc);
|
|
298
|
+
this.identifier = identifier;
|
|
299
|
+
}
|
|
300
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
301
|
+
return visitor.visitInclude?.(this);
|
|
302
|
+
}
|
|
303
|
+
public toJSON() {
|
|
304
|
+
return {
|
|
305
|
+
type: "Include",
|
|
306
|
+
identifier: this.identifier.toJSON(),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Represents a reference to the current object instance (self/this).
|
|
312
|
+
* @category OOP
|
|
313
|
+
*/
|
|
314
|
+
export class Self extends ASTNode {
|
|
315
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
316
|
+
return visitor.visitSelf?.(this);
|
|
317
|
+
}
|
|
318
|
+
public toJSON() {
|
|
319
|
+
return {
|
|
320
|
+
type: "Self",
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Represents a reference to the superclass or parent object.
|
|
326
|
+
* @category OOP
|
|
327
|
+
*/
|
|
328
|
+
export class Super extends ASTNode {
|
|
329
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
330
|
+
return visitor.visitSuper?.(this);
|
|
331
|
+
}
|
|
332
|
+
public toJSON() {
|
|
333
|
+
return {
|
|
334
|
+
type: "Super",
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Declaration of custom primitive operators - also known as operator overriding.
|
|
340
|
+
* @category OOP
|
|
341
|
+
* @example
|
|
342
|
+
* def ==(other)
|
|
343
|
+
* end
|
|
344
|
+
* def hash
|
|
345
|
+
* end
|
|
346
|
+
|
|
347
|
+
*/
|
|
348
|
+
export class PrimitiveMethod extends ASTNode {
|
|
349
|
+
public operator: Operator;
|
|
350
|
+
public equations: Equation[];
|
|
351
|
+
constructor(operator: Operator, equations: Equation[], loc: SourceLocation) {
|
|
352
|
+
super(loc);
|
|
353
|
+
this.operator = operator;
|
|
354
|
+
this.equations = equations;
|
|
355
|
+
}
|
|
356
|
+
public accept<R>(visitor: Visitor<R>): R {
|
|
357
|
+
return visitor.visitPrimitiveMethod?.(this);
|
|
358
|
+
}
|
|
359
|
+
public toJSON() {
|
|
360
|
+
return {
|
|
361
|
+
type: "PrimitiveMethod",
|
|
362
|
+
operator: this.operator,
|
|
363
|
+
equations: this.equations,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|