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,348 @@
1
+ import { ASTNode } from "../globals/generics.js";
2
+ /**
3
+ * Represents a query to retrieve data from a database table.
4
+ * @category SQL
5
+ * @example
6
+ * SELECT * FROM users WHERE age > 18
7
+ */
8
+ export class Select extends ASTNode {
9
+ /** @hidden */
10
+ columns;
11
+ /** @hidden */
12
+ from;
13
+ /** @hidden */
14
+ where;
15
+ constructor(columns, from, where, loc) {
16
+ super(loc);
17
+ this.columns = columns;
18
+ this.from = from;
19
+ this.where = where;
20
+ }
21
+ accept(visitor) {
22
+ return visitor.visitSelect?.(this);
23
+ }
24
+ toJSON() {
25
+ return {
26
+ type: "Select",
27
+ columns: this.columns.map((c) => c.toJSON()),
28
+ from: this.from,
29
+ where: this.where.toJSON(),
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * Represents a command to modify existing records in a database table.
35
+ * @category SQL
36
+ * @example
37
+ * UPDATE products SET price = 10 WHERE id = 1
38
+ */
39
+ export class Update extends ASTNode {
40
+ /** @hidden */
41
+ table;
42
+ /** @hidden */
43
+ assignments;
44
+ /** @hidden */
45
+ where;
46
+ constructor(table, assignments, where, loc) {
47
+ super(loc);
48
+ this.table = table;
49
+ this.assignments = assignments;
50
+ this.where = where;
51
+ }
52
+ accept(visitor) {
53
+ return visitor.visitUpdate?.(this);
54
+ }
55
+ toJSON() {
56
+ return {
57
+ type: "Update",
58
+ table: this.table,
59
+ assignments: this.assignments.map((assign) => assign.toJSON()),
60
+ where: this.where.toJSON(),
61
+ };
62
+ }
63
+ }
64
+ /**
65
+ * Represents a command to remove records from a database table.
66
+ * @category SQL
67
+ * @example
68
+ * DELETE FROM sessions WHERE last_active < '2023-01-01'
69
+ */
70
+ export class Delete extends ASTNode {
71
+ /** @hidden */
72
+ table;
73
+ /** @hidden */
74
+ where;
75
+ constructor(table, where, loc) {
76
+ super(loc);
77
+ this.table = table;
78
+ this.where = where;
79
+ }
80
+ accept(visitor) {
81
+ return visitor.visitDelete?.(this);
82
+ }
83
+ toJSON() {
84
+ return {
85
+ type: "Delete",
86
+ table: this.table,
87
+ where: this.where.toJSON(),
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * Represents a command to insert new records into a database table.
93
+ * @category SQL
94
+ * @example
95
+ * INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')
96
+ */
97
+ export class InsertInto extends ASTNode {
98
+ /** @hidden */
99
+ table;
100
+ /** @hidden */
101
+ columns;
102
+ /** @hidden */
103
+ values;
104
+ constructor(table, columns, values, loc) {
105
+ super(loc);
106
+ this.table = table;
107
+ this.columns = columns;
108
+ this.values = values;
109
+ }
110
+ accept(visitor) {
111
+ return visitor.visitInsertInto?.(this);
112
+ }
113
+ toJSON() {
114
+ return {
115
+ type: "InsertInto",
116
+ table: this.table,
117
+ columns: this.columns,
118
+ values: this.values.map((val) => val.map((v) => v.toJSON())),
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Represents a command to create a new database container.
124
+ * @category SQL
125
+ * @example
126
+ * CREATE DATABASE production_db
127
+ */
128
+ export class CreateDatabase extends ASTNode {
129
+ /** @hidden */
130
+ name;
131
+ constructor(name, loc) {
132
+ super(loc);
133
+ this.name = name;
134
+ }
135
+ accept(visitor) {
136
+ return visitor.visitCreateDatabase?.(this);
137
+ }
138
+ toJSON() {
139
+ return {
140
+ type: "CreateDatabase",
141
+ name: this.name,
142
+ };
143
+ }
144
+ }
145
+ /**
146
+ * Represents a command to modify the properties of an existing database.
147
+ * @category SQL
148
+ * @example
149
+ * ALTER DATABASE production_db SET READ_ONLY = OFF
150
+ */
151
+ export class AlterDatabase extends ASTNode {
152
+ /** @hidden */
153
+ name;
154
+ /** @hidden */
155
+ action;
156
+ constructor(name, action, loc) {
157
+ super(loc);
158
+ this.name = name;
159
+ this.action = action;
160
+ }
161
+ accept(visitor) {
162
+ return visitor.visitAlterDatabase?.(this);
163
+ }
164
+ toJSON() {
165
+ return {
166
+ type: "AlterDatabase",
167
+ name: this.name,
168
+ action: this.action,
169
+ };
170
+ }
171
+ }
172
+ /**
173
+ * Represents a command to define a new table and its schema.
174
+ * @category SQL
175
+ * @example
176
+ * CREATE TABLE employees (id INT, name VARCHAR(100))
177
+ */
178
+ export class CreateTable extends ASTNode {
179
+ /** @hidden */
180
+ name;
181
+ /** @hidden */
182
+ columns;
183
+ constructor(name, columns, loc) {
184
+ super(loc);
185
+ this.name = name;
186
+ this.columns = columns;
187
+ }
188
+ accept(visitor) {
189
+ return visitor.visitCreateTable?.(this);
190
+ }
191
+ toJSON() {
192
+ return {
193
+ type: "CreateTable",
194
+ name: this.name,
195
+ columns: this.columns.map((c) => c.toJSON()),
196
+ };
197
+ }
198
+ }
199
+ /**
200
+ * Represents a command to modify an existing table structure (e.g., adding columns).
201
+ * @category SQL
202
+ * @example
203
+ * ALTER TABLE employees ADD COLUMN email VARCHAR(255)
204
+ */
205
+ export class AlterTable extends ASTNode {
206
+ /** @hidden */
207
+ name;
208
+ /** @hidden */
209
+ action;
210
+ constructor(name, action, loc) {
211
+ super(loc);
212
+ this.name = name;
213
+ this.action = action;
214
+ }
215
+ accept(visitor) {
216
+ return visitor.visitAlterTable?.(this);
217
+ }
218
+ toJSON() {
219
+ return {
220
+ type: "AlterTable",
221
+ name: this.name,
222
+ action: this.action.toJSON(),
223
+ };
224
+ }
225
+ }
226
+ /**
227
+ * Represents a command to delete a table and all its data permanently.
228
+ * @category SQL
229
+ * @example
230
+ * DROP TABLE old_logs
231
+ */
232
+ export class DropTable extends ASTNode {
233
+ /** @hidden */
234
+ name;
235
+ constructor(name, loc) {
236
+ super(loc);
237
+ this.name = name;
238
+ }
239
+ accept(visitor) {
240
+ return visitor.visitDropTable?.(this);
241
+ }
242
+ toJSON() {
243
+ return {
244
+ type: "DropTable",
245
+ name: this.name,
246
+ };
247
+ }
248
+ }
249
+ /**
250
+ * Represents a command to create a search index on table columns to improve query performance.
251
+ * @category SQL
252
+ * @example
253
+ * CREATE INDEX idx_lastname ON employees (lastname)
254
+ */
255
+ export class CreateIndex extends ASTNode {
256
+ /** @hidden */
257
+ name;
258
+ /** @hidden */
259
+ table;
260
+ /** @hidden */
261
+ columns;
262
+ constructor(name, table, columns, loc) {
263
+ super(loc);
264
+ this.name = name;
265
+ this.table = table;
266
+ this.columns = columns;
267
+ }
268
+ accept(visitor) {
269
+ return visitor.visitCreateIndex?.(this);
270
+ }
271
+ toJSON() {
272
+ return {
273
+ type: "CreateIndex",
274
+ name: this.name,
275
+ table: this.table,
276
+ columns: this.columns,
277
+ };
278
+ }
279
+ }
280
+ /**
281
+ * Represents a command to remove an existing search index.
282
+ * @category SQL
283
+ * @example
284
+ * DROP INDEX idx_lastname
285
+ */
286
+ export class DropIndex extends ASTNode {
287
+ /** @hidden */
288
+ name;
289
+ constructor(name, loc) {
290
+ super(loc);
291
+ this.name = name;
292
+ }
293
+ accept(visitor) {
294
+ return visitor.visitDropIndex?.(this);
295
+ }
296
+ toJSON() {
297
+ return {
298
+ type: "DropIndex",
299
+ name: this.name,
300
+ };
301
+ }
302
+ }
303
+ /**
304
+ * Represents a command to save changes made in a transaction.
305
+ * @category SQL
306
+ * @example
307
+ * COMMIT TRAN transaction_name
308
+ */
309
+ export class Commit extends ASTNode {
310
+ /** @hidden */
311
+ name;
312
+ constructor(name, loc) {
313
+ super(loc);
314
+ this.name = name;
315
+ }
316
+ accept(visitor) {
317
+ return visitor.visitCommit?.(this);
318
+ }
319
+ toJSON() {
320
+ return {
321
+ type: "Commit",
322
+ name: this.name,
323
+ };
324
+ }
325
+ }
326
+ /**
327
+ * Represents a command to undo changes made in a transaction.
328
+ * @category SQL
329
+ * @example
330
+ * ROLLBACK TRAN transaction_name
331
+ */
332
+ export class Rollback extends ASTNode {
333
+ /** @hidden */
334
+ name;
335
+ constructor(name, loc) {
336
+ super(loc);
337
+ this.name = name;
338
+ }
339
+ accept(visitor) {
340
+ return visitor.visitRollback?.(this);
341
+ }
342
+ toJSON() {
343
+ return {
344
+ type: "Rollback",
345
+ name: this.name,
346
+ };
347
+ }
348
+ }
@@ -0,0 +1,59 @@
1
+ import { ASTNode, Expression, SourceLocation } from "../globals/generics.js";
2
+ import { Pattern } from "../globals/patterns.js";
3
+ import { Visitor } from "../visitor.js";
4
+ /**
5
+ * Represents function composition (e.g., f . g).
6
+ * @category Expressions
7
+ */
8
+ export declare class CompositionExpression extends ASTNode {
9
+ /** @hidden */
10
+ right: Expression;
11
+ /** @hidden */
12
+ left: Expression;
13
+ constructor(left: Expression, right: Expression, loc?: SourceLocation);
14
+ accept<R>(visitor: Visitor<R>): R;
15
+ toJSON(): any;
16
+ }
17
+ /**
18
+ * Represents an anonymous function or lambda abstraction.
19
+ *
20
+ * @example
21
+ * \x -> x + 1
22
+ * @category Expressions
23
+ */
24
+ export declare class Lambda extends ASTNode {
25
+ /** @hidden */
26
+ body: Expression;
27
+ /** @hidden */
28
+ parameters: Pattern[];
29
+ constructor(parameters: Pattern[], body: Expression, loc?: SourceLocation);
30
+ accept<R>(visitor: Visitor<R>): R;
31
+ toJSON(): any;
32
+ }
33
+ /**
34
+ * Represents a yield statement, often used in generators or coroutines.
35
+ * @category Statements
36
+ */
37
+ export declare class Yield extends ASTNode {
38
+ /** @hidden */
39
+ expression: Expression;
40
+ constructor(expression: Expression, loc?: SourceLocation);
41
+ accept<R>(visitor: Visitor<R>): R;
42
+ toJSON(): any;
43
+ }
44
+ /**
45
+ * Represents the application of a function to an argument.
46
+ *
47
+ * @example
48
+ * map (*2) [1..5]
49
+ * @category Expressions
50
+ */
51
+ export declare class Application extends ASTNode {
52
+ /** @hidden */
53
+ parameter: Expression;
54
+ /** @hidden */
55
+ functionExpr: Expression;
56
+ constructor(functionExpr: Expression, parameter: Expression, loc?: SourceLocation);
57
+ accept<R>(visitor: Visitor<R>): R;
58
+ toJSON(): any;
59
+ }
@@ -0,0 +1,103 @@
1
+ import { ASTNode, } from "../globals/generics.js";
2
+ /**
3
+ * Represents function composition (e.g., f . g).
4
+ * @category Expressions
5
+ */
6
+ export class CompositionExpression extends ASTNode {
7
+ /** @hidden */
8
+ right;
9
+ /** @hidden */
10
+ left;
11
+ constructor(left, right, loc) {
12
+ super(loc);
13
+ this.left = left;
14
+ this.right = right;
15
+ }
16
+ accept(visitor) {
17
+ return visitor.visitCompositionExpression?.(this);
18
+ }
19
+ toJSON() {
20
+ return {
21
+ type: "CompositionExpression",
22
+ left: this.left.toJSON(),
23
+ right: this.right.toJSON(),
24
+ };
25
+ }
26
+ }
27
+ /**
28
+ * Represents an anonymous function or lambda abstraction.
29
+ *
30
+ * @example
31
+ * \x -> x + 1
32
+ * @category Expressions
33
+ */
34
+ export class Lambda extends ASTNode {
35
+ /** @hidden */
36
+ body;
37
+ /** @hidden */
38
+ parameters;
39
+ constructor(parameters, body, loc) {
40
+ super(loc);
41
+ this.parameters = parameters;
42
+ this.body = body;
43
+ }
44
+ accept(visitor) {
45
+ return visitor.visitLambda?.(this);
46
+ }
47
+ toJSON() {
48
+ return {
49
+ type: "Lambda",
50
+ body: this.body.toJSON(),
51
+ parameters: this.parameters.map((p) => p.toJSON()),
52
+ };
53
+ }
54
+ }
55
+ /**
56
+ * Represents a yield statement, often used in generators or coroutines.
57
+ * @category Statements
58
+ */
59
+ export class Yield extends ASTNode {
60
+ /** @hidden */
61
+ expression;
62
+ constructor(expression, loc) {
63
+ super(loc);
64
+ this.expression = expression;
65
+ }
66
+ accept(visitor) {
67
+ return visitor.visitYield?.(this);
68
+ }
69
+ toJSON() {
70
+ return {
71
+ type: "Yield",
72
+ expression: this.expression.toJSON(),
73
+ };
74
+ }
75
+ }
76
+ /**
77
+ * Represents the application of a function to an argument.
78
+ *
79
+ * @example
80
+ * map (*2) [1..5]
81
+ * @category Expressions
82
+ */
83
+ export class Application extends ASTNode {
84
+ /** @hidden */
85
+ parameter;
86
+ /** @hidden */
87
+ functionExpr;
88
+ constructor(functionExpr, parameter, loc) {
89
+ super(loc);
90
+ this.functionExpr = functionExpr;
91
+ this.parameter = parameter;
92
+ }
93
+ accept(visitor) {
94
+ return visitor.visitApplication?.(this);
95
+ }
96
+ toJSON() {
97
+ return {
98
+ type: "Application",
99
+ function: this.functionExpr.toJSON(),
100
+ parameter: this.parameter.toJSON(),
101
+ };
102
+ }
103
+ }
@@ -0,0 +1,124 @@
1
+ import { ASTNode, Equation, Expression, Sequence, SourceLocation, SymbolPrimitive, Variable } from "../globals/generics.js";
2
+ import { Visitor } from "../visitor.js";
3
+ /**
4
+ * Represents the main entry point of a program.
5
+ * @category Declarations
6
+ */
7
+ export declare class EntryPoint extends ASTNode {
8
+ /** @hidden */
9
+ expression: Sequence;
10
+ /** @hidden */
11
+ identifier: SymbolPrimitive;
12
+ constructor(identifier: SymbolPrimitive, expression: Sequence, loc?: SourceLocation);
13
+ accept<R>(visitor: Visitor<R>): R;
14
+ toJSON(): {
15
+ type: string;
16
+ identifier: {
17
+ type: string;
18
+ value: string;
19
+ };
20
+ expression: any;
21
+ };
22
+ }
23
+ /**
24
+ * Represents a procedure definition, typically a function without a return value.
25
+ * @category Declarations
26
+ */
27
+ export declare class Procedure extends ASTNode {
28
+ /** @hidden */
29
+ equations: Equation[];
30
+ /** @hidden */
31
+ identifier: SymbolPrimitive;
32
+ constructor(identifier: SymbolPrimitive, equations: Equation[], loc?: SourceLocation);
33
+ accept<R>(visitor: Visitor<R>): R;
34
+ toJSON(): {
35
+ type: string;
36
+ identifier: {
37
+ type: string;
38
+ value: string;
39
+ };
40
+ equations: any[];
41
+ };
42
+ }
43
+ /**
44
+ * Represents a definition of a structured data type (struct).
45
+ * @category Declarations
46
+ */
47
+ export declare class Structure extends ASTNode {
48
+ /** @hidden */
49
+ elements: (Variable | Structure)[];
50
+ /** @hidden */
51
+ identifier: SymbolPrimitive;
52
+ constructor(identifier: SymbolPrimitive, elements: (Variable | Structure)[], loc?: SourceLocation);
53
+ accept<R>(visitor: Visitor<R>): R;
54
+ toJSON(): any;
55
+ }
56
+ /**
57
+ * Represents an enumeration type definition.
58
+ * @category Declarations
59
+ */
60
+ export declare class Enumeration extends ASTNode {
61
+ /** @hidden */
62
+ contents: SymbolPrimitive[];
63
+ /** @hidden */
64
+ identifier: SymbolPrimitive;
65
+ constructor(identifier: SymbolPrimitive, contents: SymbolPrimitive[], loc?: SourceLocation);
66
+ accept<R>(visitor: Visitor<R>): R;
67
+ toJSON(): {
68
+ type: string;
69
+ identifier: {
70
+ type: string;
71
+ value: string;
72
+ };
73
+ expressions: {
74
+ type: string;
75
+ value: string;
76
+ }[];
77
+ };
78
+ }
79
+ /**
80
+ * Represents a while loop control structure.
81
+ *
82
+ * @example
83
+ * while (x > 0) { ... }
84
+ * @category Statements
85
+ */
86
+ export declare class While extends ASTNode {
87
+ /** @hidden */
88
+ body: Expression;
89
+ /** @hidden */
90
+ condition: Expression;
91
+ constructor(condition: Expression, body: Expression, loc?: SourceLocation);
92
+ accept<R>(visitor: Visitor<R>): R;
93
+ toJSON(): any;
94
+ }
95
+ /**
96
+ * Represents a repeat-until loop control structure.
97
+ * @category Statements
98
+ */
99
+ export declare class Repeat extends ASTNode {
100
+ /** @hidden */
101
+ body: Expression;
102
+ /** @hidden */
103
+ count: Expression;
104
+ constructor(count: Expression, body: Expression, loc?: SourceLocation);
105
+ accept<R>(visitor: Visitor<R>): R;
106
+ toJSON(): any;
107
+ }
108
+ /**
109
+ * Represents a C-style or range-based for loop.
110
+ * @category Statements
111
+ */
112
+ export declare class ForLoop extends ASTNode {
113
+ /** @hidden */
114
+ body: Expression;
115
+ /** @hidden */
116
+ update: Expression;
117
+ /** @hidden */
118
+ condition: Expression;
119
+ /** @hidden */
120
+ initialization: Expression;
121
+ constructor(initialization: Expression, condition: Expression, update: Expression, body: Expression, loc?: SourceLocation);
122
+ accept<R>(visitor: Visitor<R>): R;
123
+ toJSON(): any;
124
+ }