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