yukigo-prolog-parser 0.2.3 → 0.2.7

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.
@@ -0,0 +1,4920 @@
1
+ var YukigoPrologParser = (() => {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // ../yukigo-ast/dist/globals/generics.js
37
+ var ASTNode, SourceLocation;
38
+ var init_generics = __esm({
39
+ "../yukigo-ast/dist/globals/generics.js"() {
40
+ ASTNode = class {
41
+ /** @hidden */
42
+ loc;
43
+ /** @hidden */
44
+ metadata = /* @__PURE__ */ new Map();
45
+ constructor(loc, metadata) {
46
+ this.loc = loc;
47
+ this.metadata = metadata ?? /* @__PURE__ */ new Map();
48
+ }
49
+ setMetadata(key, value) {
50
+ this.metadata.set(key, value);
51
+ }
52
+ getMetadata(key) {
53
+ return this.metadata.get(key);
54
+ }
55
+ hasMetadata(key) {
56
+ return this.metadata.has(key);
57
+ }
58
+ static [Symbol.hasInstance](instance) {
59
+ if (!instance || typeof instance !== "object")
60
+ return false;
61
+ let proto = Object.getPrototypeOf(instance);
62
+ while (proto) {
63
+ if (proto.constructor.name === this.name)
64
+ return true;
65
+ proto = Object.getPrototypeOf(proto);
66
+ }
67
+ return false;
68
+ }
69
+ is(nodeType) {
70
+ return this instanceof nodeType || this.constructor.name === nodeType.name;
71
+ }
72
+ dispatchVisit(visitor, callback) {
73
+ return callback ? callback.call(visitor, this) : visitor.fallback(this);
74
+ }
75
+ };
76
+ SourceLocation = class {
77
+ line;
78
+ column;
79
+ constructor(line, column) {
80
+ this.line = line;
81
+ this.column = column;
82
+ }
83
+ toJSON() {
84
+ return {
85
+ type: "SourceLocation",
86
+ line: this.line,
87
+ column: this.column
88
+ };
89
+ }
90
+ };
91
+ }
92
+ });
93
+
94
+ // ../yukigo-ast/dist/globals/expressions.js
95
+ var TupleExpression, FieldExpression, DataExpression, ConsExpression, LetInExpression, Otherwise, ListComprehension, Generator, RangeExpression, NamedArgument, GuardedExpression, Guard;
96
+ var init_expressions = __esm({
97
+ "../yukigo-ast/dist/globals/expressions.js"() {
98
+ init_generics();
99
+ TupleExpression = class extends ASTNode {
100
+ /** @hidden */
101
+ elements;
102
+ constructor(elements, loc) {
103
+ super(loc);
104
+ this.elements = elements;
105
+ }
106
+ accept(visitor) {
107
+ return this.dispatchVisit(visitor, visitor.visitTupleExpr);
108
+ }
109
+ toJSON() {
110
+ return {
111
+ type: "TupleExpression",
112
+ elements: this.elements.map((expr) => expr.toJSON())
113
+ };
114
+ }
115
+ };
116
+ FieldExpression = class extends ASTNode {
117
+ /** @hidden */
118
+ expression;
119
+ /** @hidden */
120
+ name;
121
+ constructor(name, expression, loc) {
122
+ super(loc);
123
+ this.name = name;
124
+ this.expression = expression;
125
+ }
126
+ accept(visitor) {
127
+ return this.dispatchVisit(visitor, visitor.visitFieldExpr);
128
+ }
129
+ toJSON() {
130
+ return {
131
+ type: "FieldExpression",
132
+ name: this.name.toJSON(),
133
+ expression: this.expression.toJSON()
134
+ };
135
+ }
136
+ };
137
+ DataExpression = class extends ASTNode {
138
+ /** @hidden */
139
+ contents;
140
+ /** @hidden */
141
+ name;
142
+ constructor(name, contents, loc) {
143
+ super(loc);
144
+ this.name = name;
145
+ this.contents = contents;
146
+ }
147
+ accept(visitor) {
148
+ return this.dispatchVisit(visitor, visitor.visitDataExpr);
149
+ }
150
+ toJSON() {
151
+ return {
152
+ type: "DataExpression",
153
+ name: this.name.toJSON(),
154
+ contents: this.contents.map((expr) => expr.toJSON())
155
+ };
156
+ }
157
+ };
158
+ ConsExpression = class extends ASTNode {
159
+ /** @hidden */
160
+ tail;
161
+ /** @hidden */
162
+ head;
163
+ constructor(head, tail, loc) {
164
+ super(loc);
165
+ this.head = head;
166
+ this.tail = tail;
167
+ }
168
+ accept(visitor) {
169
+ return this.dispatchVisit(visitor, visitor.visitConsExpr);
170
+ }
171
+ toJSON() {
172
+ return {
173
+ type: "ConsExpression",
174
+ head: this.head.toJSON(),
175
+ tail: this.tail.toJSON()
176
+ };
177
+ }
178
+ };
179
+ LetInExpression = class extends ASTNode {
180
+ /** @hidden */
181
+ expression;
182
+ /** @hidden */
183
+ declarations;
184
+ constructor(declarations, expression, loc) {
185
+ super(loc);
186
+ this.declarations = declarations;
187
+ this.expression = expression;
188
+ }
189
+ accept(visitor) {
190
+ return this.dispatchVisit(visitor, visitor.visitLetInExpr);
191
+ }
192
+ toJSON() {
193
+ return {
194
+ type: "LetInExpression",
195
+ declarations: this.declarations.toJSON(),
196
+ expression: this.expression.toJSON()
197
+ };
198
+ }
199
+ };
200
+ Otherwise = class extends ASTNode {
201
+ accept(visitor) {
202
+ return this.dispatchVisit(visitor, visitor.visitOtherwise);
203
+ }
204
+ toJSON() {
205
+ return {
206
+ type: "Otherwise"
207
+ };
208
+ }
209
+ };
210
+ ListComprehension = class extends ASTNode {
211
+ /** @hidden */
212
+ generators;
213
+ /** @hidden */
214
+ projection;
215
+ constructor(projection, generators, loc) {
216
+ super(loc);
217
+ this.projection = projection;
218
+ this.generators = generators;
219
+ }
220
+ accept(visitor) {
221
+ return this.dispatchVisit(visitor, visitor.visitListComprehension);
222
+ }
223
+ toJSON() {
224
+ return {
225
+ type: "ListComprehension",
226
+ projection: this.projection.toJSON(),
227
+ generators: this.generators.map((gen) => gen.toJSON())
228
+ };
229
+ }
230
+ };
231
+ Generator = class extends ASTNode {
232
+ /** @hidden */
233
+ expression;
234
+ /** @hidden */
235
+ variable;
236
+ constructor(variable2, expression, loc) {
237
+ super(loc);
238
+ this.variable = variable2;
239
+ this.expression = expression;
240
+ }
241
+ accept(visitor) {
242
+ return this.dispatchVisit(visitor, visitor.visitGenerator);
243
+ }
244
+ toJSON() {
245
+ return {
246
+ type: "Generator",
247
+ variable: this.variable.toJSON(),
248
+ expression: this.expression.toJSON()
249
+ };
250
+ }
251
+ };
252
+ RangeExpression = class extends ASTNode {
253
+ /** @hidden */
254
+ step;
255
+ /** @hidden */
256
+ end;
257
+ /** @hidden */
258
+ start;
259
+ constructor(start, end, step, loc) {
260
+ super(loc);
261
+ this.start = start;
262
+ this.end = end;
263
+ this.step = step;
264
+ }
265
+ accept(visitor) {
266
+ return this.dispatchVisit(visitor, visitor.visitRangeExpression);
267
+ }
268
+ toJSON() {
269
+ return {
270
+ type: "RangeExpression",
271
+ start: this.start.toJSON(),
272
+ end: this.end?.toJSON(),
273
+ step: this.step?.toJSON()
274
+ };
275
+ }
276
+ };
277
+ NamedArgument = class extends ASTNode {
278
+ identifier;
279
+ expression;
280
+ constructor(identifier, expression, loc) {
281
+ super(loc);
282
+ this.identifier = identifier;
283
+ this.expression = expression;
284
+ }
285
+ accept(visitor) {
286
+ return this.dispatchVisit(visitor, visitor.visitNamedArgument);
287
+ }
288
+ toJSON() {
289
+ return {
290
+ type: "NamedArgument",
291
+ identifier: this.identifier.toJSON(),
292
+ expression: this.expression.toJSON()
293
+ };
294
+ }
295
+ };
296
+ GuardedExpression = class extends ASTNode {
297
+ guards;
298
+ constructor(guards, loc) {
299
+ super(loc);
300
+ this.guards = guards;
301
+ }
302
+ accept(visitor) {
303
+ return this.dispatchVisit(visitor, visitor.visitGuardedExpression);
304
+ }
305
+ toJSON() {
306
+ return {
307
+ type: "GuardedExpression",
308
+ guards: this.guards.map((g) => g.toJSON())
309
+ };
310
+ }
311
+ };
312
+ Guard = class extends ASTNode {
313
+ /** @hidden */
314
+ body;
315
+ /** @hidden */
316
+ condition;
317
+ constructor(condition, body, loc) {
318
+ super(loc);
319
+ this.condition = condition;
320
+ this.body = body;
321
+ }
322
+ accept(visitor) {
323
+ return this.dispatchVisit(visitor, visitor.visitGuard);
324
+ }
325
+ toJSON() {
326
+ return {
327
+ type: "Guard",
328
+ condition: this.condition.toJSON(),
329
+ body: this.body.toJSON()
330
+ };
331
+ }
332
+ };
333
+ }
334
+ });
335
+
336
+ // ../yukigo-ast/dist/globals/primitives.js
337
+ function isYukigoPrimitive(node) {
338
+ return node instanceof BasePrimitive;
339
+ }
340
+ var BasePrimitive, NumberPrimitive, BooleanPrimitive, CharPrimitive, StringPrimitive, NilPrimitive, SymbolPrimitive, ListPrimitive;
341
+ var init_primitives = __esm({
342
+ "../yukigo-ast/dist/globals/primitives.js"() {
343
+ init_generics();
344
+ BasePrimitive = class extends ASTNode {
345
+ value;
346
+ constructor(value, loc) {
347
+ super(loc);
348
+ this.value = value;
349
+ }
350
+ /**
351
+ * Generic equality check.
352
+ */
353
+ equals(other) {
354
+ if (this.constructor !== other.constructor)
355
+ return false;
356
+ return this.value === other.value;
357
+ }
358
+ toJSON() {
359
+ return {
360
+ type: this.jsonType,
361
+ value: this.value
362
+ };
363
+ }
364
+ };
365
+ NumberPrimitive = class extends BasePrimitive {
366
+ get jsonType() {
367
+ return "YuNumber";
368
+ }
369
+ accept(visitor) {
370
+ return this.dispatchVisit(visitor, visitor.visitNumberPrimitive);
371
+ }
372
+ };
373
+ BooleanPrimitive = class extends BasePrimitive {
374
+ get jsonType() {
375
+ return "YuBoolean";
376
+ }
377
+ accept(visitor) {
378
+ return this.dispatchVisit(visitor, visitor.visitBooleanPrimitive);
379
+ }
380
+ };
381
+ CharPrimitive = class extends BasePrimitive {
382
+ get jsonType() {
383
+ return "YuChar";
384
+ }
385
+ accept(visitor) {
386
+ return this.dispatchVisit(visitor, visitor.visitCharPrimitive);
387
+ }
388
+ };
389
+ StringPrimitive = class extends BasePrimitive {
390
+ get jsonType() {
391
+ return "YuString";
392
+ }
393
+ accept(visitor) {
394
+ return this.dispatchVisit(visitor, visitor.visitStringPrimitive);
395
+ }
396
+ };
397
+ NilPrimitive = class extends BasePrimitive {
398
+ get jsonType() {
399
+ return "YuNil";
400
+ }
401
+ accept(visitor) {
402
+ return this.dispatchVisit(visitor, visitor.visitNilPrimitive);
403
+ }
404
+ };
405
+ SymbolPrimitive = class extends BasePrimitive {
406
+ get jsonType() {
407
+ return "YuSymbol";
408
+ }
409
+ accept(visitor) {
410
+ return this.dispatchVisit(visitor, visitor.visitSymbolPrimitive);
411
+ }
412
+ };
413
+ ListPrimitive = class _ListPrimitive extends BasePrimitive {
414
+ get jsonType() {
415
+ return "YuList";
416
+ }
417
+ accept(visitor) {
418
+ return this.dispatchVisit(visitor, visitor.visitListPrimitive);
419
+ }
420
+ equals(other) {
421
+ if (!(other instanceof _ListPrimitive))
422
+ return false;
423
+ if (this.value.length !== other.value.length)
424
+ return false;
425
+ return this.value.every((elem, i) => {
426
+ const otherElem = other.value[i];
427
+ if (!isYukigoPrimitive(otherElem))
428
+ return false;
429
+ if ("equals" in elem && typeof elem.equals === "function")
430
+ return elem.equals(otherElem);
431
+ return elem === otherElem;
432
+ });
433
+ }
434
+ };
435
+ }
436
+ });
437
+
438
+ // ../yukigo-ast/dist/globals/statements.js
439
+ var If, Return, Field, Constructor, Record, UnguardedBody, NativeBody, Equation, Function, Case, Switch, Catch, Try, Raise, Print, Input, For, Break, Continue, Variable, Assignment, Sequence;
440
+ var init_statements = __esm({
441
+ "../yukigo-ast/dist/globals/statements.js"() {
442
+ init_generics();
443
+ init_primitives();
444
+ If = class extends ASTNode {
445
+ /** @hidden */
446
+ elseExpr;
447
+ /** @hidden */
448
+ then;
449
+ /** @hidden */
450
+ condition;
451
+ constructor(condition, then, elseExpr, loc) {
452
+ super(loc);
453
+ this.condition = condition;
454
+ this.then = then;
455
+ this.elseExpr = elseExpr;
456
+ }
457
+ accept(visitor) {
458
+ return this.dispatchVisit(visitor, visitor.visitIf);
459
+ }
460
+ toJSON() {
461
+ return {
462
+ type: "If",
463
+ condition: this.condition.toJSON(),
464
+ then: this.then.toJSON(),
465
+ else: this.elseExpr.toJSON()
466
+ };
467
+ }
468
+ };
469
+ Return = class extends ASTNode {
470
+ /** @hidden */
471
+ body;
472
+ constructor(body = new NilPrimitive(null), loc) {
473
+ super(loc);
474
+ this.body = body;
475
+ }
476
+ accept(visitor) {
477
+ return this.dispatchVisit(visitor, visitor.visitReturn);
478
+ }
479
+ toJSON() {
480
+ return {
481
+ type: "Return",
482
+ body: this.body?.toJSON()
483
+ };
484
+ }
485
+ };
486
+ Field = class extends ASTNode {
487
+ /** @hidden */
488
+ value;
489
+ /** @hidden */
490
+ name;
491
+ constructor(name, value, loc) {
492
+ super(loc);
493
+ this.name = name;
494
+ this.value = value;
495
+ }
496
+ accept(visitor) {
497
+ return this.dispatchVisit(visitor, visitor.visitField);
498
+ }
499
+ toJSON() {
500
+ return {
501
+ type: "Field",
502
+ name: this.name?.toJSON(),
503
+ value: this.value.toJSON()
504
+ };
505
+ }
506
+ };
507
+ Constructor = class extends ASTNode {
508
+ /** @hidden */
509
+ fields;
510
+ /** @hidden */
511
+ name;
512
+ constructor(name, fields, loc) {
513
+ super(loc);
514
+ this.name = name;
515
+ this.fields = fields;
516
+ }
517
+ accept(visitor) {
518
+ return this.dispatchVisit(visitor, visitor.visitConstructor);
519
+ }
520
+ toJSON() {
521
+ return {
522
+ type: "Constructor",
523
+ name: this.name.toJSON(),
524
+ fields: this.fields.map((f) => f.toJSON())
525
+ };
526
+ }
527
+ };
528
+ Record = class extends ASTNode {
529
+ /** @hidden */
530
+ deriving;
531
+ /** @hidden */
532
+ contents;
533
+ /** @hidden */
534
+ name;
535
+ constructor(name, contents, deriving, loc) {
536
+ super(loc);
537
+ this.name = name;
538
+ this.contents = contents;
539
+ this.deriving = deriving;
540
+ }
541
+ accept(visitor) {
542
+ return this.dispatchVisit(visitor, visitor.visitRecord);
543
+ }
544
+ toJSON() {
545
+ return {
546
+ type: "Record",
547
+ name: this.name.toJSON(),
548
+ contents: this.contents.map((constructor) => constructor.toJSON()),
549
+ deriving: this.deriving?.map((d) => d.toJSON())
550
+ };
551
+ }
552
+ };
553
+ UnguardedBody = class extends ASTNode {
554
+ /** @hidden */
555
+ sequence;
556
+ constructor(sequence, loc) {
557
+ super(loc);
558
+ this.sequence = sequence;
559
+ }
560
+ accept(visitor) {
561
+ return this.dispatchVisit(visitor, visitor.visitUnguardedBody);
562
+ }
563
+ toJSON() {
564
+ return {
565
+ type: "UnguardedBody",
566
+ sequence: this.sequence.toJSON()
567
+ };
568
+ }
569
+ };
570
+ NativeBody = class extends ASTNode {
571
+ constructor(loc) {
572
+ super(loc);
573
+ }
574
+ accept(visitor) {
575
+ return this.dispatchVisit(visitor, visitor.visitNativeBody);
576
+ }
577
+ toJSON() {
578
+ return {
579
+ type: "NativeBody"
580
+ };
581
+ }
582
+ };
583
+ Equation = class extends ASTNode {
584
+ /** @hidden */
585
+ patterns;
586
+ /** @hidden */
587
+ body;
588
+ /** @hidden */
589
+ returnExpr;
590
+ constructor(patterns, body, returnExpr, loc) {
591
+ super(loc);
592
+ this.patterns = patterns;
593
+ this.body = body;
594
+ this.returnExpr = returnExpr;
595
+ }
596
+ /** @hidden */
597
+ accept(visitor) {
598
+ return this.dispatchVisit(visitor, visitor.visitEquation);
599
+ }
600
+ /** @hidden */
601
+ toJSON() {
602
+ return {
603
+ type: "Equation",
604
+ patterns: this.patterns.map((pattern) => pattern.toJSON()),
605
+ body: Array.isArray(this.body) ? this.body.map((guard) => guard.toJSON()) : this.body.toJSON(),
606
+ return: this.returnExpr?.toJSON()
607
+ };
608
+ }
609
+ };
610
+ Function = class extends ASTNode {
611
+ /** @hidden */
612
+ equations;
613
+ /** @hidden */
614
+ identifier;
615
+ constructor(identifier, equations, loc) {
616
+ super(loc);
617
+ this.identifier = identifier;
618
+ this.equations = equations;
619
+ }
620
+ accept(visitor) {
621
+ return this.dispatchVisit(visitor, visitor.visitFunction);
622
+ }
623
+ toJSON() {
624
+ return {
625
+ type: "Function",
626
+ identifier: this.identifier.toJSON(),
627
+ equations: this.equations.map((eq) => eq.toJSON())
628
+ };
629
+ }
630
+ };
631
+ Case = class extends ASTNode {
632
+ /** @hidden */
633
+ body;
634
+ /** @hidden */
635
+ condition;
636
+ constructor(condition, body, loc) {
637
+ super(loc);
638
+ this.condition = condition;
639
+ this.body = body;
640
+ }
641
+ accept(visitor) {
642
+ return this.dispatchVisit(visitor, visitor.visitCase);
643
+ }
644
+ toJSON() {
645
+ return {
646
+ type: "Case",
647
+ condition: this.condition.toJSON(),
648
+ body: this.body.toJSON()
649
+ };
650
+ }
651
+ };
652
+ Switch = class extends ASTNode {
653
+ /** @hidden */
654
+ defaultExpr;
655
+ /** @hidden */
656
+ cases;
657
+ /** @hidden */
658
+ value;
659
+ constructor(value, cases, defaultExpr, loc) {
660
+ super(loc);
661
+ this.value = value;
662
+ this.cases = cases;
663
+ this.defaultExpr = defaultExpr;
664
+ }
665
+ accept(visitor) {
666
+ return this.dispatchVisit(visitor, visitor.visitSwitch);
667
+ }
668
+ toJSON() {
669
+ return {
670
+ type: "Switch",
671
+ value: this.value.toJSON(),
672
+ cases: this.cases.map((caseVal) => ({
673
+ condition: caseVal.condition.toJSON(),
674
+ body: caseVal.body.toJSON()
675
+ })),
676
+ default: this.defaultExpr?.toJSON()
677
+ };
678
+ }
679
+ };
680
+ Catch = class extends ASTNode {
681
+ /** @hidden */
682
+ body;
683
+ /** @hidden */
684
+ patterns;
685
+ constructor(patterns, body, loc) {
686
+ super(loc);
687
+ this.patterns = patterns;
688
+ this.body = body;
689
+ }
690
+ accept(visitor) {
691
+ return this.dispatchVisit(visitor, visitor.visitCatch);
692
+ }
693
+ toJSON() {
694
+ return {
695
+ type: "Catch",
696
+ patterns: this.patterns.map((pat) => pat.toJSON()),
697
+ body: this.body.toJSON()
698
+ };
699
+ }
700
+ };
701
+ Try = class extends ASTNode {
702
+ /** @hidden */
703
+ finallyExpr;
704
+ /** @hidden */
705
+ catchExpr;
706
+ /** @hidden */
707
+ body;
708
+ constructor(body, catchExpr, finallyExpr, loc) {
709
+ super(loc);
710
+ this.body = body;
711
+ this.catchExpr = catchExpr;
712
+ this.finallyExpr = finallyExpr;
713
+ }
714
+ accept(visitor) {
715
+ return this.dispatchVisit(visitor, visitor.visitTry);
716
+ }
717
+ toJSON() {
718
+ return {
719
+ type: "Try",
720
+ body: this.body.toJSON(),
721
+ catch: this.catchExpr.map(({ patterns, body }) => ({
722
+ condition: patterns.map((pattern) => pattern.toJSON()),
723
+ body: body.toJSON()
724
+ })),
725
+ finally: this.finallyExpr.toJSON()
726
+ };
727
+ }
728
+ };
729
+ Raise = class extends ASTNode {
730
+ /** @hidden */
731
+ body;
732
+ constructor(body, loc) {
733
+ super(loc);
734
+ this.body = body;
735
+ }
736
+ accept(visitor) {
737
+ return this.dispatchVisit(visitor, visitor.visitRaise);
738
+ }
739
+ toJSON() {
740
+ return {
741
+ type: "Raise",
742
+ body: this.body.toJSON()
743
+ };
744
+ }
745
+ };
746
+ Print = class extends ASTNode {
747
+ /** @hidden */
748
+ expression;
749
+ constructor(expression, loc) {
750
+ super(loc);
751
+ this.expression = expression;
752
+ }
753
+ accept(visitor) {
754
+ return this.dispatchVisit(visitor, visitor.visitPrint);
755
+ }
756
+ toJSON() {
757
+ return {
758
+ type: "Print",
759
+ expression: this.expression.toJSON()
760
+ };
761
+ }
762
+ };
763
+ Input = class extends ASTNode {
764
+ /** @hidden */
765
+ variable;
766
+ /** @hidden */
767
+ message;
768
+ constructor(message, variable2, loc) {
769
+ super(loc);
770
+ this.message = message;
771
+ this.variable = variable2;
772
+ }
773
+ accept(visitor) {
774
+ return this.dispatchVisit(visitor, visitor.visitInput);
775
+ }
776
+ toJSON() {
777
+ return {
778
+ type: "Input",
779
+ message: this.message.toJSON(),
780
+ variable: this.variable.toJSON()
781
+ };
782
+ }
783
+ };
784
+ For = class extends ASTNode {
785
+ /** @hidden */
786
+ statements;
787
+ /** @hidden */
788
+ body;
789
+ constructor(body, statements, loc) {
790
+ super(loc);
791
+ this.body = body;
792
+ this.statements = statements;
793
+ }
794
+ accept(visitor) {
795
+ return this.dispatchVisit(visitor, visitor.visitFor);
796
+ }
797
+ toJSON() {
798
+ return {
799
+ type: "For",
800
+ body: this.body.toJSON(),
801
+ statements: this.statements.map((stmt) => stmt.toJSON())
802
+ };
803
+ }
804
+ };
805
+ Break = class extends ASTNode {
806
+ /** @hidden */
807
+ body;
808
+ constructor(body = new NilPrimitive(null), loc) {
809
+ super(loc);
810
+ this.body = body;
811
+ }
812
+ accept(visitor) {
813
+ return this.dispatchVisit(visitor, visitor.visitBreak);
814
+ }
815
+ toJSON() {
816
+ return {
817
+ type: "Break",
818
+ body: this.body?.toJSON()
819
+ };
820
+ }
821
+ };
822
+ Continue = class extends ASTNode {
823
+ /** @hidden */
824
+ body;
825
+ constructor(body = new NilPrimitive(null), loc) {
826
+ super(loc);
827
+ this.body = body;
828
+ }
829
+ accept(visitor) {
830
+ return this.dispatchVisit(visitor, visitor.visitContinue);
831
+ }
832
+ toJSON() {
833
+ return {
834
+ type: "Continue",
835
+ body: this.body?.toJSON()
836
+ };
837
+ }
838
+ };
839
+ Variable = class extends ASTNode {
840
+ /** @hidden */
841
+ variableType;
842
+ /** @hidden */
843
+ expression;
844
+ /** @hidden */
845
+ identifier;
846
+ constructor(identifier, expression, variableType, loc) {
847
+ super(loc);
848
+ this.identifier = identifier;
849
+ this.expression = expression;
850
+ this.variableType = variableType;
851
+ }
852
+ accept(visitor) {
853
+ return this.dispatchVisit(visitor, visitor.visitVariable);
854
+ }
855
+ toJSON() {
856
+ return {
857
+ type: "Variable",
858
+ identifier: this.identifier.toJSON(),
859
+ expression: this.expression.toJSON(),
860
+ variableType: this.variableType?.toJSON()
861
+ };
862
+ }
863
+ };
864
+ Assignment = class extends ASTNode {
865
+ /** @hidden */
866
+ expression;
867
+ /** @hidden */
868
+ identifier;
869
+ constructor(identifier, expression, loc) {
870
+ super(loc);
871
+ this.identifier = identifier;
872
+ this.expression = expression;
873
+ }
874
+ accept(visitor) {
875
+ return this.dispatchVisit(visitor, visitor.visitAssignment);
876
+ }
877
+ toJSON() {
878
+ return {
879
+ type: "Assignment",
880
+ identifier: this.identifier.toJSON(),
881
+ expression: this.expression.toJSON()
882
+ };
883
+ }
884
+ };
885
+ Sequence = class extends ASTNode {
886
+ /** @hidden */
887
+ statements;
888
+ constructor(statements, loc) {
889
+ super(loc);
890
+ this.statements = statements;
891
+ }
892
+ accept(visitor) {
893
+ return this.dispatchVisit(visitor, visitor.visitSequence);
894
+ }
895
+ toJSON() {
896
+ return {
897
+ type: "Sequence",
898
+ statements: this.statements.map((stmt) => stmt.toJSON())
899
+ };
900
+ }
901
+ };
902
+ }
903
+ });
904
+
905
+ // ../yukigo-ast/dist/globals/operators.js
906
+ var ArithmeticUnaryOperation, ArithmeticBinaryOperation, ListUnaryOperation, ListBinaryOperation, ComparisonOperation, LogicalBinaryOperation, LogicalUnaryOperation, BitwiseBinaryOperation, BitwiseUnaryOperation, StringOperation, UnifyOperation, AssignOperation;
907
+ var init_operators = __esm({
908
+ "../yukigo-ast/dist/globals/operators.js"() {
909
+ init_generics();
910
+ ArithmeticUnaryOperation = class extends ASTNode {
911
+ /** @hidden */
912
+ operand;
913
+ /** @hidden */
914
+ operator;
915
+ constructor(operator, operand, loc) {
916
+ super(loc);
917
+ this.operator = operator;
918
+ this.operand = operand;
919
+ }
920
+ accept(visitor) {
921
+ return this.dispatchVisit(visitor, visitor.visitArithmeticUnaryOperation);
922
+ }
923
+ toJSON() {
924
+ return {
925
+ type: "ArithmeticUnaryOperation",
926
+ operator: this.operator,
927
+ operand: this.operand
928
+ };
929
+ }
930
+ };
931
+ ArithmeticBinaryOperation = class extends ASTNode {
932
+ /** @hidden */
933
+ right;
934
+ /** @hidden */
935
+ left;
936
+ /** @hidden */
937
+ operator;
938
+ constructor(operator, left, right, loc) {
939
+ super(loc);
940
+ this.operator = operator;
941
+ this.left = left;
942
+ this.right = right;
943
+ }
944
+ accept(visitor) {
945
+ return this.dispatchVisit(visitor, visitor.visitArithmeticBinaryOperation);
946
+ }
947
+ toJSON() {
948
+ return {
949
+ type: "ArithmeticBinaryOperation",
950
+ operator: this.operator,
951
+ left: this.left,
952
+ right: this.right
953
+ };
954
+ }
955
+ };
956
+ ListUnaryOperation = class extends ASTNode {
957
+ /** @hidden */
958
+ operand;
959
+ /** @hidden */
960
+ operator;
961
+ constructor(operator, operand, loc) {
962
+ super(loc);
963
+ this.operator = operator;
964
+ this.operand = operand;
965
+ }
966
+ accept(visitor) {
967
+ return this.dispatchVisit(visitor, visitor.visitListUnaryOperation);
968
+ }
969
+ toJSON() {
970
+ return {
971
+ type: "ListUnaryOperation",
972
+ operator: this.operator,
973
+ operand: this.operand
974
+ };
975
+ }
976
+ };
977
+ ListBinaryOperation = class extends ASTNode {
978
+ /** @hidden */
979
+ right;
980
+ /** @hidden */
981
+ left;
982
+ /** @hidden */
983
+ operator;
984
+ constructor(operator, left, right, loc) {
985
+ super(loc);
986
+ this.operator = operator;
987
+ this.left = left;
988
+ this.right = right;
989
+ }
990
+ accept(visitor) {
991
+ return this.dispatchVisit(visitor, visitor.visitListBinaryOperation);
992
+ }
993
+ toJSON() {
994
+ return {
995
+ type: "ListBinaryOperation",
996
+ operator: this.operator,
997
+ left: this.left,
998
+ right: this.right
999
+ };
1000
+ }
1001
+ };
1002
+ ComparisonOperation = class extends ASTNode {
1003
+ /** @hidden */
1004
+ right;
1005
+ /** @hidden */
1006
+ left;
1007
+ /** @hidden */
1008
+ operator;
1009
+ constructor(operator, left, right, loc) {
1010
+ super(loc);
1011
+ this.operator = operator;
1012
+ this.left = left;
1013
+ this.right = right;
1014
+ }
1015
+ accept(visitor) {
1016
+ return this.dispatchVisit(visitor, visitor.visitComparisonOperation);
1017
+ }
1018
+ toJSON() {
1019
+ return {
1020
+ type: "ComparisonOperation",
1021
+ operator: this.operator,
1022
+ left: this.left,
1023
+ right: this.right
1024
+ };
1025
+ }
1026
+ };
1027
+ LogicalBinaryOperation = class extends ASTNode {
1028
+ /** @hidden */
1029
+ right;
1030
+ /** @hidden */
1031
+ left;
1032
+ /** @hidden */
1033
+ operator;
1034
+ constructor(operator, left, right, loc) {
1035
+ super(loc);
1036
+ this.operator = operator;
1037
+ this.left = left;
1038
+ this.right = right;
1039
+ }
1040
+ accept(visitor) {
1041
+ return this.dispatchVisit(visitor, visitor.visitLogicalBinaryOperation);
1042
+ }
1043
+ toJSON() {
1044
+ return {
1045
+ type: "LogicalBinaryOperation",
1046
+ operator: this.operator,
1047
+ left: this.left,
1048
+ right: this.right
1049
+ };
1050
+ }
1051
+ };
1052
+ LogicalUnaryOperation = class extends ASTNode {
1053
+ /** @hidden */
1054
+ operand;
1055
+ /** @hidden */
1056
+ operator;
1057
+ constructor(operator, operand, loc) {
1058
+ super(loc);
1059
+ this.operator = operator;
1060
+ this.operand = operand;
1061
+ }
1062
+ accept(visitor) {
1063
+ return this.dispatchVisit(visitor, visitor.visitLogicalUnaryOperation);
1064
+ }
1065
+ toJSON() {
1066
+ return {
1067
+ type: "LogicalUnaryOperation",
1068
+ operator: this.operator,
1069
+ operand: this.operand
1070
+ };
1071
+ }
1072
+ };
1073
+ BitwiseBinaryOperation = class extends ASTNode {
1074
+ /** @hidden */
1075
+ right;
1076
+ /** @hidden */
1077
+ left;
1078
+ /** @hidden */
1079
+ operator;
1080
+ constructor(operator, left, right, loc) {
1081
+ super(loc);
1082
+ this.operator = operator;
1083
+ this.left = left;
1084
+ this.right = right;
1085
+ }
1086
+ accept(visitor) {
1087
+ return this.dispatchVisit(visitor, visitor.visitBitwiseBinaryOperation);
1088
+ }
1089
+ toJSON() {
1090
+ return {
1091
+ type: "BitwiseBinaryOperation",
1092
+ operator: this.operator,
1093
+ left: this.left,
1094
+ right: this.right
1095
+ };
1096
+ }
1097
+ };
1098
+ BitwiseUnaryOperation = class extends ASTNode {
1099
+ /** @hidden */
1100
+ operand;
1101
+ /** @hidden */
1102
+ operator;
1103
+ constructor(operator, operand, loc) {
1104
+ super(loc);
1105
+ this.operator = operator;
1106
+ this.operand = operand;
1107
+ }
1108
+ accept(visitor) {
1109
+ return this.dispatchVisit(visitor, visitor.visitBitwiseUnaryOperation);
1110
+ }
1111
+ toJSON() {
1112
+ return {
1113
+ type: "BitwiseUnaryOperation",
1114
+ operator: this.operator,
1115
+ operand: this.operand
1116
+ };
1117
+ }
1118
+ };
1119
+ StringOperation = class extends ASTNode {
1120
+ /** @hidden */
1121
+ right;
1122
+ /** @hidden */
1123
+ left;
1124
+ /** @hidden */
1125
+ operator;
1126
+ constructor(operator, left, right, loc) {
1127
+ super(loc);
1128
+ this.operator = operator;
1129
+ this.left = left;
1130
+ this.right = right;
1131
+ }
1132
+ accept(visitor) {
1133
+ return this.dispatchVisit(visitor, visitor.visitStringOperation);
1134
+ }
1135
+ toJSON() {
1136
+ return {
1137
+ type: "StringOperation",
1138
+ operator: this.operator,
1139
+ left: this.left,
1140
+ right: this.right
1141
+ };
1142
+ }
1143
+ };
1144
+ UnifyOperation = class extends ASTNode {
1145
+ /** @hidden */
1146
+ right;
1147
+ /** @hidden */
1148
+ left;
1149
+ /** @hidden */
1150
+ operator;
1151
+ constructor(operator, left, right, loc) {
1152
+ super(loc);
1153
+ this.operator = operator;
1154
+ this.left = left;
1155
+ this.right = right;
1156
+ }
1157
+ accept(visitor) {
1158
+ return this.dispatchVisit(visitor, visitor.visitUnifyOperation);
1159
+ }
1160
+ toJSON() {
1161
+ return {
1162
+ type: "UnifyOperation",
1163
+ operator: this.operator,
1164
+ left: this.left,
1165
+ right: this.right
1166
+ };
1167
+ }
1168
+ };
1169
+ AssignOperation = class extends ASTNode {
1170
+ /** @hidden */
1171
+ right;
1172
+ /** @hidden */
1173
+ left;
1174
+ /** @hidden */
1175
+ operator;
1176
+ constructor(operator, left, right, loc) {
1177
+ super(loc);
1178
+ this.operator = operator;
1179
+ this.left = left;
1180
+ this.right = right;
1181
+ }
1182
+ accept(visitor) {
1183
+ return this.dispatchVisit(visitor, visitor.visitAssignOperation);
1184
+ }
1185
+ toJSON() {
1186
+ return {
1187
+ type: "AssignOperation",
1188
+ operator: this.operator,
1189
+ left: this.left,
1190
+ right: this.right
1191
+ };
1192
+ }
1193
+ };
1194
+ }
1195
+ });
1196
+
1197
+ // ../yukigo-ast/dist/globals/patterns.js
1198
+ function isPattern(node) {
1199
+ return node instanceof BasePattern;
1200
+ }
1201
+ var BasePattern, NamedPattern, ArgsPattern, ListBasedPattern, BinaryPattern, VariablePattern, LiteralPattern, ApplicationPattern, TuplePattern, ListPattern, FunctorPattern, AsPattern, WildcardPattern, UnionPattern, ConstructorPattern, ConsPattern, TypePattern;
1202
+ var init_patterns = __esm({
1203
+ "../yukigo-ast/dist/globals/patterns.js"() {
1204
+ init_generics();
1205
+ BasePattern = class extends ASTNode {
1206
+ constructor(loc) {
1207
+ super(loc);
1208
+ }
1209
+ };
1210
+ NamedPattern = class extends BasePattern {
1211
+ name;
1212
+ constructor(name, loc) {
1213
+ super(loc);
1214
+ this.name = name;
1215
+ }
1216
+ toJSON() {
1217
+ return {
1218
+ type: this.jsonType,
1219
+ name: this.name.toJSON()
1220
+ };
1221
+ }
1222
+ };
1223
+ ArgsPattern = class extends BasePattern {
1224
+ /** @hidden */
1225
+ identifier;
1226
+ /** @hidden */
1227
+ args;
1228
+ constructor(identifier, args, loc) {
1229
+ super(loc);
1230
+ this.identifier = identifier;
1231
+ this.args = args;
1232
+ }
1233
+ toJSON() {
1234
+ return {
1235
+ type: this.jsonType,
1236
+ identifier: this.identifier.toJSON(),
1237
+ args: this.args.map((arg) => arg.toJSON())
1238
+ };
1239
+ }
1240
+ };
1241
+ ListBasedPattern = class extends BasePattern {
1242
+ /** @hidden */
1243
+ elements;
1244
+ constructor(elements, loc) {
1245
+ super(loc);
1246
+ this.elements = elements;
1247
+ }
1248
+ toJSON() {
1249
+ return {
1250
+ type: this.jsonType,
1251
+ elements: this.elements.map((arg) => arg.toJSON())
1252
+ };
1253
+ }
1254
+ };
1255
+ BinaryPattern = class extends BasePattern {
1256
+ /** @hidden */
1257
+ left;
1258
+ /** @hidden */
1259
+ right;
1260
+ constructor(left, right, loc) {
1261
+ super(loc);
1262
+ this.left = left;
1263
+ this.right = right;
1264
+ }
1265
+ toJSON() {
1266
+ return {
1267
+ type: this.jsonType,
1268
+ left: this.left.toJSON(),
1269
+ right: this.right.toJSON()
1270
+ };
1271
+ }
1272
+ };
1273
+ VariablePattern = class extends NamedPattern {
1274
+ get jsonType() {
1275
+ return "VariablePattern";
1276
+ }
1277
+ constructor(name, loc) {
1278
+ super(name, loc);
1279
+ }
1280
+ accept(visitor) {
1281
+ return this.dispatchVisit(visitor, visitor.visitVariablePattern);
1282
+ }
1283
+ toString() {
1284
+ return this.name.value;
1285
+ }
1286
+ };
1287
+ LiteralPattern = class extends NamedPattern {
1288
+ get jsonType() {
1289
+ return "LiteralPattern";
1290
+ }
1291
+ constructor(name, loc) {
1292
+ super(name, loc);
1293
+ }
1294
+ accept(visitor) {
1295
+ return this.dispatchVisit(visitor, visitor.visitLiteralPattern);
1296
+ }
1297
+ toString() {
1298
+ const { name } = this;
1299
+ return String(name.value);
1300
+ }
1301
+ };
1302
+ ApplicationPattern = class extends ArgsPattern {
1303
+ get jsonType() {
1304
+ return "ApplicationPattern";
1305
+ }
1306
+ constructor(symbol, args, loc) {
1307
+ super(symbol, args, loc);
1308
+ }
1309
+ accept(visitor) {
1310
+ return this.dispatchVisit(visitor, visitor.visitApplicationPattern);
1311
+ }
1312
+ toString() {
1313
+ const constr = this.identifier.value;
1314
+ const args = this.args.map((pat) => pat.toString()).join(" ");
1315
+ return `${constr} ${args}`;
1316
+ }
1317
+ };
1318
+ TuplePattern = class extends ListBasedPattern {
1319
+ get jsonType() {
1320
+ return "TuplePattern";
1321
+ }
1322
+ constructor(elements, loc) {
1323
+ super(elements, loc);
1324
+ }
1325
+ accept(visitor) {
1326
+ return this.dispatchVisit(visitor, visitor.visitTuplePattern);
1327
+ }
1328
+ toString() {
1329
+ return `(${this.elements.map((e) => e.toString()).join(", ")})`;
1330
+ }
1331
+ };
1332
+ ListPattern = class extends ListBasedPattern {
1333
+ get jsonType() {
1334
+ return "ListPattern";
1335
+ }
1336
+ constructor(elements, loc) {
1337
+ super(elements, loc);
1338
+ }
1339
+ accept(visitor) {
1340
+ return this.dispatchVisit(visitor, visitor.visitListPattern);
1341
+ }
1342
+ toString() {
1343
+ const { elements } = this;
1344
+ if (elements.length === 0)
1345
+ return "[]";
1346
+ return `[${this.elements.map((e) => e.toString()).join(", ")}]`;
1347
+ }
1348
+ };
1349
+ FunctorPattern = class extends ArgsPattern {
1350
+ get jsonType() {
1351
+ return "FunctorPattern";
1352
+ }
1353
+ constructor(symbol, args, loc) {
1354
+ super(symbol, args, loc);
1355
+ }
1356
+ accept(visitor) {
1357
+ return this.dispatchVisit(visitor, visitor.visitFunctorPattern);
1358
+ }
1359
+ toString() {
1360
+ const constr = this.identifier.value;
1361
+ const args = this.args.map((pat) => pat.toString()).join(" ");
1362
+ return `${constr} ${args}`;
1363
+ }
1364
+ };
1365
+ AsPattern = class extends BinaryPattern {
1366
+ get jsonType() {
1367
+ return "AsPattern";
1368
+ }
1369
+ constructor(left, right, loc) {
1370
+ super(left, right, loc);
1371
+ }
1372
+ accept(visitor) {
1373
+ return this.dispatchVisit(visitor, visitor.visitAsPattern);
1374
+ }
1375
+ toString() {
1376
+ const alias = this.left.toString();
1377
+ const pattern = this.right.toString();
1378
+ return `${alias}@${pattern}`;
1379
+ }
1380
+ };
1381
+ WildcardPattern = class extends BasePattern {
1382
+ get jsonType() {
1383
+ return "WildcardPattern";
1384
+ }
1385
+ accept(visitor) {
1386
+ return this.dispatchVisit(visitor, visitor.visitWildcardPattern);
1387
+ }
1388
+ toJSON() {
1389
+ return {
1390
+ type: "WildcardPattern",
1391
+ name: "_"
1392
+ };
1393
+ }
1394
+ toString() {
1395
+ return "_";
1396
+ }
1397
+ };
1398
+ UnionPattern = class extends ListBasedPattern {
1399
+ get jsonType() {
1400
+ return "UnionPattern";
1401
+ }
1402
+ constructor(patterns, loc) {
1403
+ super(patterns, loc);
1404
+ }
1405
+ accept(visitor) {
1406
+ return this.dispatchVisit(visitor, visitor.visitUnionPattern);
1407
+ }
1408
+ toString() {
1409
+ const inner = this.elements.map((pat) => pat.toString()).join(" | ");
1410
+ return `(${inner})`;
1411
+ }
1412
+ };
1413
+ ConstructorPattern = class extends ArgsPattern {
1414
+ get jsonType() {
1415
+ return "ConstructorPattern";
1416
+ }
1417
+ constructor(symbol, args, loc) {
1418
+ super(symbol, args, loc);
1419
+ }
1420
+ accept(visitor) {
1421
+ return this.dispatchVisit(visitor, visitor.visitConstructorPattern);
1422
+ }
1423
+ toString() {
1424
+ const constr = this.identifier.value;
1425
+ const args = this.args.map((pat) => pat.toString()).join(" ");
1426
+ return `${constr} ${args}`;
1427
+ }
1428
+ };
1429
+ ConsPattern = class extends BinaryPattern {
1430
+ get jsonType() {
1431
+ return "ConsPattern";
1432
+ }
1433
+ constructor(left, right, loc) {
1434
+ super(left, right, loc);
1435
+ }
1436
+ accept(visitor) {
1437
+ return this.dispatchVisit(visitor, visitor.visitConsPattern);
1438
+ }
1439
+ toString() {
1440
+ const head = this.left.toString();
1441
+ const tail = this.right.toString();
1442
+ return `(${head}:${tail})`;
1443
+ }
1444
+ };
1445
+ TypePattern = class extends BasePattern {
1446
+ get jsonType() {
1447
+ return "TypePattern";
1448
+ }
1449
+ /** @hidden */
1450
+ targetType;
1451
+ /** @hidden */
1452
+ innerPattern;
1453
+ constructor(targetType, innerPattern, loc) {
1454
+ super(loc);
1455
+ this.targetType = targetType;
1456
+ this.innerPattern = innerPattern;
1457
+ }
1458
+ accept(visitor) {
1459
+ return this.dispatchVisit(visitor, visitor.visitTypePattern);
1460
+ }
1461
+ toJSON() {
1462
+ return {
1463
+ type: "TypePattern",
1464
+ targetType: this.targetType.toJSON(),
1465
+ innerPattern: this.innerPattern?.toJSON()
1466
+ };
1467
+ }
1468
+ toString() {
1469
+ const typeStr = this.targetType.toString();
1470
+ return this.innerPattern ? `(${typeStr} ${this.innerPattern.toString()})` : typeStr;
1471
+ }
1472
+ };
1473
+ }
1474
+ });
1475
+
1476
+ // ../yukigo-ast/dist/globals/types.js
1477
+ var SimpleType, TypeVar, TypeApplication, ListType, TupleType, Constraint, ParameterizedType, ConstrainedType, TypeAlias, TypeSignature, TypeCast;
1478
+ var init_types = __esm({
1479
+ "../yukigo-ast/dist/globals/types.js"() {
1480
+ init_generics();
1481
+ SimpleType = class extends ASTNode {
1482
+ /** @hidden */
1483
+ constraints;
1484
+ /** @hidden */
1485
+ value;
1486
+ constructor(value, constraints, loc) {
1487
+ super(loc);
1488
+ this.value = value;
1489
+ this.constraints = constraints;
1490
+ }
1491
+ accept(visitor) {
1492
+ return this.dispatchVisit(visitor, visitor.visitSimpleType);
1493
+ }
1494
+ toString() {
1495
+ return this.value;
1496
+ }
1497
+ toJSON() {
1498
+ return {
1499
+ type: "SimpleType",
1500
+ value: this.value,
1501
+ constraints: this.constraints.map((c) => c.toJSON())
1502
+ };
1503
+ }
1504
+ };
1505
+ TypeVar = class extends ASTNode {
1506
+ /** @hidden */
1507
+ constraints;
1508
+ /** @hidden */
1509
+ value;
1510
+ constructor(value, constraints, loc) {
1511
+ super(loc);
1512
+ this.value = value;
1513
+ this.constraints = constraints;
1514
+ }
1515
+ accept(visitor) {
1516
+ return this.dispatchVisit(visitor, visitor.visitTypeVar);
1517
+ }
1518
+ toString() {
1519
+ return this.value;
1520
+ }
1521
+ toJSON() {
1522
+ return {
1523
+ type: "TypeVar",
1524
+ value: this.value,
1525
+ constraints: this.constraints.map((c) => c.toJSON())
1526
+ };
1527
+ }
1528
+ };
1529
+ TypeApplication = class _TypeApplication extends ASTNode {
1530
+ /** @hidden */
1531
+ argument;
1532
+ /** @hidden */
1533
+ functionType;
1534
+ constructor(functionType, argument, loc) {
1535
+ super(loc);
1536
+ this.functionType = functionType;
1537
+ this.argument = argument;
1538
+ }
1539
+ accept(visitor) {
1540
+ return this.dispatchVisit(visitor, visitor.visitTypeApplication);
1541
+ }
1542
+ toString() {
1543
+ const func = this.functionType.toString();
1544
+ let arg = this.argument.toString();
1545
+ if (this.argument instanceof _TypeApplication || this.argument instanceof ParameterizedType) {
1546
+ arg = `(${arg})`;
1547
+ }
1548
+ return `${func} ${arg}`;
1549
+ }
1550
+ toJSON() {
1551
+ return {
1552
+ type: "TypeApplication",
1553
+ function: this.functionType.toJSON(),
1554
+ argument: this.argument.toJSON()
1555
+ };
1556
+ }
1557
+ };
1558
+ ListType = class extends ASTNode {
1559
+ /** @hidden */
1560
+ constraints;
1561
+ /** @hidden */
1562
+ values;
1563
+ constructor(values, constraints, loc) {
1564
+ super(loc);
1565
+ this.values = values;
1566
+ this.constraints = constraints;
1567
+ }
1568
+ accept(visitor) {
1569
+ return this.dispatchVisit(visitor, visitor.visitListType);
1570
+ }
1571
+ toString() {
1572
+ return `[${this.values.toString()}]`;
1573
+ }
1574
+ toJSON() {
1575
+ return {
1576
+ type: "ListType",
1577
+ values: this.values.toJSON(),
1578
+ constraints: this.constraints.map((c) => c.toJSON())
1579
+ };
1580
+ }
1581
+ };
1582
+ TupleType = class extends ASTNode {
1583
+ /** @hidden */
1584
+ constraints;
1585
+ /** @hidden */
1586
+ values;
1587
+ constructor(values, constraints, loc) {
1588
+ super(loc);
1589
+ this.values = values;
1590
+ this.constraints = constraints;
1591
+ }
1592
+ accept(visitor) {
1593
+ return this.dispatchVisit(visitor, visitor.visitTupleType);
1594
+ }
1595
+ toString() {
1596
+ return `(${this.values.map((t) => t.toString()).join(", ")})`;
1597
+ }
1598
+ toJSON() {
1599
+ return {
1600
+ type: "TupleType",
1601
+ values: this.values.map((val) => val.toJSON()),
1602
+ constraints: this.constraints.map((c) => c.toJSON())
1603
+ };
1604
+ }
1605
+ };
1606
+ Constraint = class extends ASTNode {
1607
+ /** @hidden */
1608
+ parameters;
1609
+ /** @hidden */
1610
+ name;
1611
+ constructor(name, parameters, loc) {
1612
+ super(loc);
1613
+ this.name = name;
1614
+ this.parameters = parameters;
1615
+ }
1616
+ accept(visitor) {
1617
+ return this.dispatchVisit(visitor, visitor.visitConstraint);
1618
+ }
1619
+ toJSON() {
1620
+ return {
1621
+ type: "Constraint",
1622
+ name: this.name,
1623
+ parameters: this.parameters.map((p) => p.toJSON())
1624
+ };
1625
+ }
1626
+ };
1627
+ ParameterizedType = class _ParameterizedType extends ASTNode {
1628
+ /** @hidden */
1629
+ constraints;
1630
+ /** @hidden */
1631
+ returnType;
1632
+ /** @hidden */
1633
+ inputs;
1634
+ constructor(inputs, returnType, constraints, loc) {
1635
+ super(loc);
1636
+ this.inputs = inputs;
1637
+ this.returnType = returnType;
1638
+ this.constraints = constraints;
1639
+ }
1640
+ accept(visitor) {
1641
+ return this.dispatchVisit(visitor, visitor.visitParameterizedType);
1642
+ }
1643
+ toString() {
1644
+ const inputs = this.inputs.map((t) => {
1645
+ const str = t.toString();
1646
+ return t instanceof _ParameterizedType ? `(${str})` : str;
1647
+ });
1648
+ const ret = this.returnType.toString();
1649
+ const signature = [...inputs, ret].join(" -> ");
1650
+ if (this.constraints.length > 0) {
1651
+ const constraints = this.constraints.map((c) => {
1652
+ const params = c.parameters.map((p) => p.toString()).join(" ");
1653
+ return params ? `${c.name} ${params}` : c.name;
1654
+ }).join(", ");
1655
+ const context = this.constraints.length > 1 ? `(${constraints})` : constraints;
1656
+ return `${context} => ${signature}`;
1657
+ }
1658
+ return signature;
1659
+ }
1660
+ toJSON() {
1661
+ return {
1662
+ type: "ParameterizedType",
1663
+ inputs: this.inputs.map((p) => p.toJSON()),
1664
+ return: this.returnType.toJSON(),
1665
+ constraints: this.constraints.map((p) => p.toJSON())
1666
+ };
1667
+ }
1668
+ };
1669
+ ConstrainedType = class extends ASTNode {
1670
+ /** @hidden */
1671
+ constraints;
1672
+ constructor(constraints, loc) {
1673
+ super(loc);
1674
+ this.constraints = constraints;
1675
+ }
1676
+ accept(visitor) {
1677
+ return this.dispatchVisit(visitor, visitor.visitConstrainedType);
1678
+ }
1679
+ toJSON() {
1680
+ return {
1681
+ type: "ConstrainedType",
1682
+ constraints: this.constraints.map((p) => p.toJSON())
1683
+ };
1684
+ }
1685
+ };
1686
+ TypeAlias = class extends ASTNode {
1687
+ /** @hidden */
1688
+ value;
1689
+ /** @hidden */
1690
+ variables;
1691
+ /** @hidden */
1692
+ identifier;
1693
+ constructor(identifier, variables, value, loc) {
1694
+ super(loc);
1695
+ this.identifier = identifier;
1696
+ this.variables = variables;
1697
+ this.value = value;
1698
+ }
1699
+ accept(visitor) {
1700
+ return this.dispatchVisit(visitor, visitor.visitTypeAlias);
1701
+ }
1702
+ toJSON() {
1703
+ return {
1704
+ type: "TypeAlias",
1705
+ identifier: this.identifier.toJSON(),
1706
+ variables: this.variables,
1707
+ value: this.value.toJSON()
1708
+ };
1709
+ }
1710
+ };
1711
+ TypeSignature = class extends ASTNode {
1712
+ /** @hidden */
1713
+ body;
1714
+ /** @hidden */
1715
+ identifier;
1716
+ constructor(identifier, body, loc) {
1717
+ super(loc);
1718
+ this.identifier = identifier;
1719
+ this.body = body;
1720
+ }
1721
+ accept(visitor) {
1722
+ return this.dispatchVisit(visitor, visitor.visitTypeSignature);
1723
+ }
1724
+ toJSON() {
1725
+ return {
1726
+ type: "TypeSignature",
1727
+ identifier: this.identifier.toJSON(),
1728
+ body: this.body.toJSON()
1729
+ };
1730
+ }
1731
+ };
1732
+ TypeCast = class extends ASTNode {
1733
+ /** @hidden */
1734
+ body;
1735
+ /** @hidden */
1736
+ expression;
1737
+ constructor(expression, body, loc) {
1738
+ super(loc);
1739
+ this.expression = expression;
1740
+ this.body = body;
1741
+ }
1742
+ accept(visitor) {
1743
+ return this.dispatchVisit(visitor, visitor.visitTypeCast);
1744
+ }
1745
+ toJSON() {
1746
+ return {
1747
+ type: "TypeCast",
1748
+ expression: this.expression.toJSON(),
1749
+ body: this.body.toJSON()
1750
+ };
1751
+ }
1752
+ };
1753
+ }
1754
+ });
1755
+
1756
+ // ../yukigo-ast/dist/globals/testing.js
1757
+ var TestGroup, Test, Assert, Truth, Equality, Failure;
1758
+ var init_testing = __esm({
1759
+ "../yukigo-ast/dist/globals/testing.js"() {
1760
+ init_generics();
1761
+ TestGroup = class extends ASTNode {
1762
+ name;
1763
+ group;
1764
+ constructor(name, group, loc) {
1765
+ super(loc);
1766
+ this.name = name;
1767
+ this.group = group;
1768
+ }
1769
+ accept(visitor) {
1770
+ return this.dispatchVisit(visitor, visitor.visitTestGroup);
1771
+ }
1772
+ toJSON() {
1773
+ return {
1774
+ type: "TestGroup",
1775
+ name: this.name,
1776
+ group: this.group
1777
+ };
1778
+ }
1779
+ };
1780
+ Test = class extends ASTNode {
1781
+ name;
1782
+ body;
1783
+ args;
1784
+ constructor(name, body, args = [], loc) {
1785
+ super(loc);
1786
+ this.name = name;
1787
+ this.body = body;
1788
+ this.args = args;
1789
+ }
1790
+ accept(visitor) {
1791
+ return this.dispatchVisit(visitor, visitor.visitTest);
1792
+ }
1793
+ toJSON() {
1794
+ return {
1795
+ type: "Test",
1796
+ name: this.name,
1797
+ body: this.body,
1798
+ args: this.args
1799
+ };
1800
+ }
1801
+ };
1802
+ Assert = class extends ASTNode {
1803
+ negated;
1804
+ body;
1805
+ constructor(negated, body, loc) {
1806
+ super(loc);
1807
+ this.negated = negated;
1808
+ this.body = body;
1809
+ }
1810
+ accept(visitor) {
1811
+ return this.dispatchVisit(visitor, visitor.visitAssert);
1812
+ }
1813
+ toJSON() {
1814
+ return {
1815
+ type: "Assert",
1816
+ negated: this.negated,
1817
+ body: this.body
1818
+ };
1819
+ }
1820
+ };
1821
+ Truth = class extends ASTNode {
1822
+ body;
1823
+ constructor(body, loc) {
1824
+ super(loc);
1825
+ this.body = body;
1826
+ }
1827
+ accept(visitor) {
1828
+ return this.dispatchVisit(visitor, visitor.visitTruth);
1829
+ }
1830
+ toJSON() {
1831
+ return {
1832
+ type: "Truth",
1833
+ body: this.body
1834
+ };
1835
+ }
1836
+ };
1837
+ Equality = class extends ASTNode {
1838
+ expected;
1839
+ value;
1840
+ constructor(expected, value, loc) {
1841
+ super(loc);
1842
+ this.expected = expected;
1843
+ this.value = value;
1844
+ }
1845
+ accept(visitor) {
1846
+ return this.dispatchVisit(visitor, visitor.visitEquality);
1847
+ }
1848
+ toJSON() {
1849
+ return {
1850
+ type: "Equality",
1851
+ expected: this.expected,
1852
+ value: this.value
1853
+ };
1854
+ }
1855
+ };
1856
+ Failure = class extends ASTNode {
1857
+ func;
1858
+ message;
1859
+ constructor(func, message, loc) {
1860
+ super(loc);
1861
+ this.func = func;
1862
+ this.message = message;
1863
+ }
1864
+ accept(visitor) {
1865
+ return this.dispatchVisit(visitor, visitor.visitFailure);
1866
+ }
1867
+ toJSON() {
1868
+ return {
1869
+ type: "Failure",
1870
+ func: this.func,
1871
+ message: this.message
1872
+ };
1873
+ }
1874
+ };
1875
+ }
1876
+ });
1877
+
1878
+ // ../yukigo-ast/dist/paradigms/functional.js
1879
+ var CompositionExpression, Lambda, Yield, Application;
1880
+ var init_functional = __esm({
1881
+ "../yukigo-ast/dist/paradigms/functional.js"() {
1882
+ init_generics();
1883
+ CompositionExpression = class extends ASTNode {
1884
+ /** @hidden */
1885
+ right;
1886
+ /** @hidden */
1887
+ left;
1888
+ constructor(left, right, loc) {
1889
+ super(loc);
1890
+ this.left = left;
1891
+ this.right = right;
1892
+ }
1893
+ accept(visitor) {
1894
+ return this.dispatchVisit(visitor, visitor.visitCompositionExpression);
1895
+ }
1896
+ toJSON() {
1897
+ return {
1898
+ type: "CompositionExpression",
1899
+ left: this.left.toJSON(),
1900
+ right: this.right.toJSON()
1901
+ };
1902
+ }
1903
+ };
1904
+ Lambda = class extends ASTNode {
1905
+ /** @hidden */
1906
+ body;
1907
+ /** @hidden */
1908
+ parameters;
1909
+ constructor(parameters, body, loc) {
1910
+ super(loc);
1911
+ this.parameters = parameters;
1912
+ this.body = body;
1913
+ }
1914
+ accept(visitor) {
1915
+ return this.dispatchVisit(visitor, visitor.visitLambda);
1916
+ }
1917
+ toJSON() {
1918
+ return {
1919
+ type: "Lambda",
1920
+ body: this.body.toJSON(),
1921
+ parameters: this.parameters.map((p) => p.toJSON())
1922
+ };
1923
+ }
1924
+ };
1925
+ Yield = class extends ASTNode {
1926
+ /** @hidden */
1927
+ expression;
1928
+ constructor(expression, loc) {
1929
+ super(loc);
1930
+ this.expression = expression;
1931
+ }
1932
+ accept(visitor) {
1933
+ return this.dispatchVisit(visitor, visitor.visitYield);
1934
+ }
1935
+ toJSON() {
1936
+ return {
1937
+ type: "Yield",
1938
+ expression: this.expression.toJSON()
1939
+ };
1940
+ }
1941
+ };
1942
+ Application = class extends ASTNode {
1943
+ /** @hidden */
1944
+ parameter;
1945
+ /** @hidden */
1946
+ functionExpr;
1947
+ constructor(functionExpr, parameter, loc) {
1948
+ super(loc);
1949
+ this.functionExpr = functionExpr;
1950
+ this.parameter = parameter;
1951
+ }
1952
+ accept(visitor) {
1953
+ return this.dispatchVisit(visitor, visitor.visitApplication);
1954
+ }
1955
+ toJSON() {
1956
+ return {
1957
+ type: "Application",
1958
+ function: this.functionExpr.toJSON(),
1959
+ parameter: this.parameter.toJSON()
1960
+ };
1961
+ }
1962
+ };
1963
+ }
1964
+ });
1965
+
1966
+ // ../yukigo-ast/dist/paradigms/object.js
1967
+ var Method, Attribute, Object2, Class, Interface, Send, New, Implement, Self, Super, PrimitiveMethod;
1968
+ var init_object = __esm({
1969
+ "../yukigo-ast/dist/paradigms/object.js"() {
1970
+ init_generics();
1971
+ Method = class extends ASTNode {
1972
+ /** @hidden */
1973
+ equations;
1974
+ /** @hidden */
1975
+ identifier;
1976
+ /** @hidden */
1977
+ isAbstract;
1978
+ constructor(identifier, equations, loc, isAbstract = false) {
1979
+ super(loc);
1980
+ this.identifier = identifier;
1981
+ this.equations = equations;
1982
+ this.isAbstract = isAbstract;
1983
+ }
1984
+ accept(visitor) {
1985
+ return this.dispatchVisit(visitor, visitor.visitMethod);
1986
+ }
1987
+ toJSON() {
1988
+ return {
1989
+ type: "Method",
1990
+ identifier: this.identifier.toJSON(),
1991
+ equations: this.equations.map((eq) => eq.toJSON())
1992
+ };
1993
+ }
1994
+ };
1995
+ Attribute = class extends ASTNode {
1996
+ /** @hidden */
1997
+ expression;
1998
+ /** @hidden */
1999
+ identifier;
2000
+ constructor(identifier, expression, loc) {
2001
+ super(loc);
2002
+ this.identifier = identifier;
2003
+ this.expression = expression;
2004
+ }
2005
+ accept(visitor) {
2006
+ return this.dispatchVisit(visitor, visitor.visitAttribute);
2007
+ }
2008
+ toJSON() {
2009
+ return {
2010
+ type: "Attribute",
2011
+ identifier: this.identifier.toJSON(),
2012
+ expression: this.expression.toJSON()
2013
+ };
2014
+ }
2015
+ };
2016
+ Object2 = class extends ASTNode {
2017
+ /** @hidden */
2018
+ expression;
2019
+ /** @hidden */
2020
+ identifier;
2021
+ /** @hidden */
2022
+ extendsSymbol;
2023
+ /** @hidden */
2024
+ extendsArgs;
2025
+ constructor(identifier, expression, loc) {
2026
+ super(loc);
2027
+ this.identifier = identifier;
2028
+ this.expression = expression;
2029
+ }
2030
+ accept(visitor) {
2031
+ return this.dispatchVisit(visitor, visitor.visitObject);
2032
+ }
2033
+ toJSON() {
2034
+ return {
2035
+ type: "Object",
2036
+ identifier: this.identifier.toJSON(),
2037
+ expression: this.expression.toJSON(),
2038
+ extendsSymbol: this.extendsSymbol ? this.extendsSymbol.toJSON() : void 0,
2039
+ extendsArgs: this.extendsArgs ? this.extendsArgs.map((a) => a.toJSON()) : void 0
2040
+ };
2041
+ }
2042
+ };
2043
+ Class = class extends ASTNode {
2044
+ /** @hidden */
2045
+ expression;
2046
+ /** @hidden */
2047
+ implementsNode;
2048
+ /** @hidden */
2049
+ extendsSymbol;
2050
+ /** @hidden */
2051
+ identifier;
2052
+ /** @hidden */
2053
+ includes;
2054
+ constructor(identifier, extendsSymbol, implementsNode, includes, expression, loc) {
2055
+ super(loc);
2056
+ this.identifier = identifier;
2057
+ this.extendsSymbol = extendsSymbol;
2058
+ this.implementsNode = implementsNode;
2059
+ this.includes = includes;
2060
+ this.expression = expression;
2061
+ }
2062
+ accept(visitor) {
2063
+ return this.dispatchVisit(visitor, visitor.visitClass);
2064
+ }
2065
+ toJSON() {
2066
+ return {
2067
+ type: "Class",
2068
+ identifier: this.identifier.toJSON(),
2069
+ extends: this.extendsSymbol?.toJSON(),
2070
+ implements: this.implementsNode?.toJSON(),
2071
+ includes: this.includes.map((s) => s.toJSON()),
2072
+ expression: this.expression.toJSON()
2073
+ };
2074
+ }
2075
+ };
2076
+ Interface = class extends ASTNode {
2077
+ /** @hidden */
2078
+ expression;
2079
+ /** @hidden */
2080
+ extendsSymbol;
2081
+ /** @hidden */
2082
+ identifier;
2083
+ constructor(identifier, extendsSymbol, expression, loc) {
2084
+ super(loc);
2085
+ this.identifier = identifier;
2086
+ this.extendsSymbol = extendsSymbol;
2087
+ this.expression = expression;
2088
+ }
2089
+ accept(visitor) {
2090
+ return this.dispatchVisit(visitor, visitor.visitInterface);
2091
+ }
2092
+ toJSON() {
2093
+ return {
2094
+ type: "Interface",
2095
+ identifier: this.identifier.toJSON(),
2096
+ extends: this.extendsSymbol.map((symbol) => symbol.toJSON()),
2097
+ expression: this.expression.toJSON()
2098
+ };
2099
+ }
2100
+ };
2101
+ Send = class extends ASTNode {
2102
+ /** @hidden */
2103
+ args;
2104
+ /** @hidden */
2105
+ selector;
2106
+ /** @hidden */
2107
+ receiver;
2108
+ /** @hidden */
2109
+ constructor(receiver, selector, args, loc) {
2110
+ super(loc);
2111
+ this.receiver = receiver;
2112
+ this.selector = selector;
2113
+ this.args = args;
2114
+ }
2115
+ accept(visitor) {
2116
+ return this.dispatchVisit(visitor, visitor.visitSend);
2117
+ }
2118
+ toJSON() {
2119
+ return {
2120
+ type: "Send",
2121
+ receiver: this.receiver.toJSON(),
2122
+ selector: this.selector.toJSON(),
2123
+ arguments: this.args.map((arg) => arg.toJSON())
2124
+ };
2125
+ }
2126
+ };
2127
+ New = class extends ASTNode {
2128
+ /** @hidden */
2129
+ args;
2130
+ /** @hidden */
2131
+ identifier;
2132
+ constructor(identifier, args, loc) {
2133
+ super(loc);
2134
+ this.identifier = identifier;
2135
+ this.args = args;
2136
+ }
2137
+ accept(visitor) {
2138
+ return this.dispatchVisit(visitor, visitor.visitNew);
2139
+ }
2140
+ toJSON() {
2141
+ return {
2142
+ type: "New",
2143
+ identifier: this.identifier.toJSON(),
2144
+ arguments: this.args.map((arg) => arg.toJSON())
2145
+ };
2146
+ }
2147
+ };
2148
+ Implement = class extends ASTNode {
2149
+ /** @hidden */
2150
+ identifier;
2151
+ constructor(identifier, loc) {
2152
+ super(loc);
2153
+ this.identifier = identifier;
2154
+ }
2155
+ accept(visitor) {
2156
+ return this.dispatchVisit(visitor, visitor.visitImplement);
2157
+ }
2158
+ toJSON() {
2159
+ return {
2160
+ type: "Implement",
2161
+ identifier: this.identifier.toJSON()
2162
+ };
2163
+ }
2164
+ };
2165
+ Self = class extends ASTNode {
2166
+ accept(visitor) {
2167
+ return this.dispatchVisit(visitor, visitor.visitSelf);
2168
+ }
2169
+ toJSON() {
2170
+ return {
2171
+ type: "Self"
2172
+ };
2173
+ }
2174
+ };
2175
+ Super = class extends ASTNode {
2176
+ /** @hidden */
2177
+ args;
2178
+ constructor(args, loc) {
2179
+ super(loc);
2180
+ this.args = args;
2181
+ }
2182
+ accept(visitor) {
2183
+ return this.dispatchVisit(visitor, visitor.visitSuper);
2184
+ }
2185
+ toJSON() {
2186
+ return {
2187
+ type: "Super",
2188
+ args: this.args
2189
+ };
2190
+ }
2191
+ };
2192
+ PrimitiveMethod = class extends ASTNode {
2193
+ operator;
2194
+ equations;
2195
+ constructor(operator, equations, loc) {
2196
+ super(loc);
2197
+ this.operator = operator;
2198
+ this.equations = equations;
2199
+ }
2200
+ accept(visitor) {
2201
+ return this.dispatchVisit(visitor, visitor.visitPrimitiveMethod);
2202
+ }
2203
+ toJSON() {
2204
+ return {
2205
+ type: "PrimitiveMethod",
2206
+ operator: this.operator,
2207
+ equations: this.equations
2208
+ };
2209
+ }
2210
+ };
2211
+ }
2212
+ });
2213
+
2214
+ // ../yukigo-ast/dist/paradigms/imperative.js
2215
+ var EntryPoint, Procedure, Structure, Enumeration, While, Repeat, ForLoop;
2216
+ var init_imperative = __esm({
2217
+ "../yukigo-ast/dist/paradigms/imperative.js"() {
2218
+ init_generics();
2219
+ EntryPoint = class extends ASTNode {
2220
+ /** @hidden */
2221
+ expression;
2222
+ /** @hidden */
2223
+ identifier;
2224
+ constructor(identifier, expression, loc) {
2225
+ super(loc);
2226
+ this.identifier = identifier;
2227
+ this.expression = expression;
2228
+ }
2229
+ accept(visitor) {
2230
+ return this.dispatchVisit(visitor, visitor.visitEntryPoint);
2231
+ }
2232
+ toJSON() {
2233
+ return {
2234
+ type: "EntryPoint",
2235
+ identifier: this.identifier.toJSON(),
2236
+ expression: this.expression.toJSON()
2237
+ };
2238
+ }
2239
+ };
2240
+ Procedure = class extends ASTNode {
2241
+ /** @hidden */
2242
+ equations;
2243
+ /** @hidden */
2244
+ identifier;
2245
+ constructor(identifier, equations, loc) {
2246
+ super(loc);
2247
+ this.identifier = identifier;
2248
+ this.equations = equations;
2249
+ }
2250
+ accept(visitor) {
2251
+ return this.dispatchVisit(visitor, visitor.visitProcedure);
2252
+ }
2253
+ toJSON() {
2254
+ return {
2255
+ type: "Procedure",
2256
+ identifier: this.identifier.toJSON(),
2257
+ equations: this.equations.map((eq) => eq.toJSON())
2258
+ };
2259
+ }
2260
+ };
2261
+ Structure = class extends ASTNode {
2262
+ /** @hidden */
2263
+ elements;
2264
+ /** @hidden */
2265
+ identifier;
2266
+ constructor(identifier, elements, loc) {
2267
+ super();
2268
+ this.identifier = identifier;
2269
+ this.elements = elements;
2270
+ this.loc = loc;
2271
+ }
2272
+ accept(visitor) {
2273
+ return this.dispatchVisit(visitor, visitor.visitStructure);
2274
+ }
2275
+ toJSON() {
2276
+ return {
2277
+ type: "Structure",
2278
+ identifier: this.identifier.toJSON(),
2279
+ expressions: this.elements.map((elem) => elem.toJSON())
2280
+ };
2281
+ }
2282
+ };
2283
+ Enumeration = class extends ASTNode {
2284
+ /** @hidden */
2285
+ contents;
2286
+ /** @hidden */
2287
+ identifier;
2288
+ constructor(identifier, contents, loc) {
2289
+ super(loc);
2290
+ this.identifier = identifier;
2291
+ this.contents = contents;
2292
+ }
2293
+ accept(visitor) {
2294
+ return this.dispatchVisit(visitor, visitor.visitEnumeration);
2295
+ }
2296
+ toJSON() {
2297
+ return {
2298
+ type: "Enumeration",
2299
+ identifier: this.identifier.toJSON(),
2300
+ expressions: this.contents.map((c) => c.toJSON())
2301
+ };
2302
+ }
2303
+ };
2304
+ While = class extends ASTNode {
2305
+ /** @hidden */
2306
+ body;
2307
+ /** @hidden */
2308
+ condition;
2309
+ constructor(condition, body, loc) {
2310
+ super(loc);
2311
+ this.condition = condition;
2312
+ this.body = body;
2313
+ }
2314
+ accept(visitor) {
2315
+ return this.dispatchVisit(visitor, visitor.visitWhile);
2316
+ }
2317
+ toJSON() {
2318
+ return {
2319
+ type: "While",
2320
+ condition: this.condition.toJSON(),
2321
+ body: this.body.toJSON()
2322
+ };
2323
+ }
2324
+ };
2325
+ Repeat = class extends ASTNode {
2326
+ /** @hidden */
2327
+ body;
2328
+ /** @hidden */
2329
+ count;
2330
+ constructor(count, body, loc) {
2331
+ super(loc);
2332
+ this.count = count;
2333
+ this.body = body;
2334
+ }
2335
+ accept(visitor) {
2336
+ return this.dispatchVisit(visitor, visitor.visitRepeat);
2337
+ }
2338
+ toJSON() {
2339
+ return {
2340
+ type: "Repeat",
2341
+ count: this.count.toJSON(),
2342
+ body: this.body.toJSON()
2343
+ };
2344
+ }
2345
+ };
2346
+ ForLoop = class extends ASTNode {
2347
+ /** @hidden */
2348
+ body;
2349
+ /** @hidden */
2350
+ update;
2351
+ /** @hidden */
2352
+ condition;
2353
+ /** @hidden */
2354
+ initialization;
2355
+ constructor(initialization, condition, update, body, loc) {
2356
+ super(loc);
2357
+ this.initialization = initialization;
2358
+ this.condition = condition;
2359
+ this.update = update;
2360
+ this.body = body;
2361
+ }
2362
+ accept(visitor) {
2363
+ return this.dispatchVisit(visitor, visitor.visitForLoop);
2364
+ }
2365
+ toJSON() {
2366
+ return {
2367
+ type: "ForLoop",
2368
+ initialization: this.initialization.toJSON(),
2369
+ condition: this.condition.toJSON(),
2370
+ update: this.update.toJSON(),
2371
+ body: this.body.toJSON()
2372
+ };
2373
+ }
2374
+ };
2375
+ }
2376
+ });
2377
+
2378
+ // ../yukigo-ast/dist/paradigms/logic.js
2379
+ var Rule, Call, Fact, Query, Exist, Not, Findall, Forall, Goal, LogicConstraint;
2380
+ var init_logic = __esm({
2381
+ "../yukigo-ast/dist/paradigms/logic.js"() {
2382
+ init_generics();
2383
+ Rule = class extends ASTNode {
2384
+ /** @hidden */
2385
+ equations;
2386
+ /** @hidden */
2387
+ identifier;
2388
+ constructor(identifier, equations, loc) {
2389
+ super(loc);
2390
+ this.identifier = identifier;
2391
+ this.equations = equations;
2392
+ }
2393
+ accept(visitor) {
2394
+ return this.dispatchVisit(visitor, visitor.visitRule);
2395
+ }
2396
+ toJSON() {
2397
+ return {
2398
+ type: "Rule",
2399
+ identifier: this.identifier.toJSON(),
2400
+ equations: this.equations.map((expr) => expr.toJSON())
2401
+ };
2402
+ }
2403
+ };
2404
+ Call = class extends ASTNode {
2405
+ /** @hidden */
2406
+ args;
2407
+ /** @hidden */
2408
+ callee;
2409
+ constructor(callee, args, loc) {
2410
+ super(loc);
2411
+ this.callee = callee;
2412
+ this.args = args;
2413
+ }
2414
+ accept(visitor) {
2415
+ return this.dispatchVisit(visitor, visitor.visitCall);
2416
+ }
2417
+ toJSON() {
2418
+ return {
2419
+ type: "Call",
2420
+ callee: this.callee.toJSON(),
2421
+ patterns: this.args.map((p) => p.toJSON())
2422
+ };
2423
+ }
2424
+ };
2425
+ Fact = class extends ASTNode {
2426
+ /** @hidden */
2427
+ patterns;
2428
+ /** @hidden */
2429
+ identifier;
2430
+ constructor(identifier, patterns, loc) {
2431
+ super(loc);
2432
+ this.identifier = identifier;
2433
+ this.patterns = patterns;
2434
+ }
2435
+ accept(visitor) {
2436
+ return this.dispatchVisit(visitor, visitor.visitFact);
2437
+ }
2438
+ toJSON() {
2439
+ return {
2440
+ type: "Fact",
2441
+ identifier: this.identifier.toJSON(),
2442
+ patterns: this.patterns.map((p) => p.toJSON())
2443
+ };
2444
+ }
2445
+ };
2446
+ Query = class extends ASTNode {
2447
+ /** @hidden */
2448
+ expressions;
2449
+ constructor(expressions, loc) {
2450
+ super(loc);
2451
+ this.expressions = expressions;
2452
+ }
2453
+ accept(visitor) {
2454
+ return this.dispatchVisit(visitor, visitor.visitQuery);
2455
+ }
2456
+ toJSON() {
2457
+ return {
2458
+ type: "Query",
2459
+ expressions: this.expressions.map((expr) => expr.toJSON())
2460
+ };
2461
+ }
2462
+ };
2463
+ Exist = class extends ASTNode {
2464
+ /** @hidden */
2465
+ patterns;
2466
+ /** @hidden */
2467
+ identifier;
2468
+ constructor(identifier, patterns, loc) {
2469
+ super(loc);
2470
+ this.identifier = identifier;
2471
+ this.patterns = patterns;
2472
+ }
2473
+ accept(visitor) {
2474
+ return this.dispatchVisit(visitor, visitor.visitExist);
2475
+ }
2476
+ toJSON() {
2477
+ return {
2478
+ type: "Exist",
2479
+ identifier: this.identifier.toJSON(),
2480
+ patterns: this.patterns.map((p) => p.toJSON())
2481
+ };
2482
+ }
2483
+ };
2484
+ Not = class extends ASTNode {
2485
+ /** @hidden */
2486
+ expression;
2487
+ constructor(expression, loc) {
2488
+ super(loc);
2489
+ this.expression = expression;
2490
+ }
2491
+ accept(visitor) {
2492
+ return this.dispatchVisit(visitor, visitor.visitNot);
2493
+ }
2494
+ toJSON() {
2495
+ return {
2496
+ type: "Not",
2497
+ expression: this.expression.toJSON()
2498
+ };
2499
+ }
2500
+ };
2501
+ Findall = class extends ASTNode {
2502
+ /** @hidden */
2503
+ bag;
2504
+ /** @hidden */
2505
+ goal;
2506
+ /** @hidden */
2507
+ template;
2508
+ constructor(template, goal, bag, loc) {
2509
+ super(loc);
2510
+ this.template = template;
2511
+ this.goal = goal;
2512
+ this.bag = bag;
2513
+ }
2514
+ accept(visitor) {
2515
+ return this.dispatchVisit(visitor, visitor.visitFindall);
2516
+ }
2517
+ toJSON() {
2518
+ return {
2519
+ type: "Findall",
2520
+ template: this.template.toJSON(),
2521
+ goal: this.goal.toJSON(),
2522
+ bag: this.bag.toJSON()
2523
+ };
2524
+ }
2525
+ };
2526
+ Forall = class extends ASTNode {
2527
+ /** @hidden */
2528
+ action;
2529
+ /** @hidden */
2530
+ condition;
2531
+ constructor(condition, action, loc) {
2532
+ super(loc);
2533
+ this.condition = condition;
2534
+ this.action = action;
2535
+ }
2536
+ accept(visitor) {
2537
+ return this.dispatchVisit(visitor, visitor.visitForall);
2538
+ }
2539
+ toJSON() {
2540
+ return {
2541
+ type: "Forall",
2542
+ condition: this.condition.toJSON(),
2543
+ action: this.action.toJSON()
2544
+ };
2545
+ }
2546
+ };
2547
+ Goal = class extends ASTNode {
2548
+ /** @hidden */
2549
+ args;
2550
+ /** @hidden */
2551
+ identifier;
2552
+ constructor(identifier, args, loc) {
2553
+ super(loc);
2554
+ this.identifier = identifier;
2555
+ this.args = args;
2556
+ }
2557
+ accept(visitor) {
2558
+ return this.dispatchVisit(visitor, visitor.visitGoal);
2559
+ }
2560
+ toJSON() {
2561
+ return {
2562
+ type: "Goal",
2563
+ identifier: this.identifier.toJSON(),
2564
+ arguments: this.args.map((arg) => arg.toJSON())
2565
+ };
2566
+ }
2567
+ };
2568
+ LogicConstraint = class extends ASTNode {
2569
+ /** @hidden */
2570
+ expression;
2571
+ constructor(expression, loc) {
2572
+ super(loc);
2573
+ this.expression = expression;
2574
+ }
2575
+ accept(visitor) {
2576
+ return this.dispatchVisit(visitor, visitor.visitLogicConstraint);
2577
+ }
2578
+ toJSON() {
2579
+ return {
2580
+ type: "LogicConstraint",
2581
+ expression: this.expression.toJSON()
2582
+ };
2583
+ }
2584
+ };
2585
+ }
2586
+ });
2587
+
2588
+ // ../yukigo-ast/dist/paradigms/typeclasses.js
2589
+ var TypeClass, Instance;
2590
+ var init_typeclasses = __esm({
2591
+ "../yukigo-ast/dist/paradigms/typeclasses.js"() {
2592
+ init_generics();
2593
+ TypeClass = class extends ASTNode {
2594
+ /** @hidden */
2595
+ name;
2596
+ /** @hidden */
2597
+ variable;
2598
+ /** @hidden */
2599
+ signatures;
2600
+ constructor(name, variable2, signatures, loc) {
2601
+ super(loc);
2602
+ this.name = name;
2603
+ this.variable = variable2;
2604
+ this.signatures = signatures;
2605
+ }
2606
+ accept(visitor) {
2607
+ return this.dispatchVisit(visitor, visitor.visitTypeClass);
2608
+ }
2609
+ toJSON() {
2610
+ return {
2611
+ type: "TypeClass",
2612
+ name: this.name.toJSON(),
2613
+ variable: this.variable.toJSON(),
2614
+ signatures: this.signatures.map((sig) => sig.toJSON())
2615
+ };
2616
+ }
2617
+ };
2618
+ Instance = class extends ASTNode {
2619
+ /** @hidden */
2620
+ className;
2621
+ /** @hidden */
2622
+ type;
2623
+ /** @hidden */
2624
+ functions;
2625
+ constructor(className, type, functions, loc) {
2626
+ super(loc);
2627
+ this.className = className;
2628
+ this.type = type;
2629
+ this.functions = functions;
2630
+ }
2631
+ accept(visitor) {
2632
+ return this.dispatchVisit(visitor, visitor.visitInstance);
2633
+ }
2634
+ toJSON() {
2635
+ return {
2636
+ type: "Instance",
2637
+ className: this.className.toJSON(),
2638
+ targetType: this.type.toJSON(),
2639
+ functions: this.functions.map((func) => func.toJSON())
2640
+ };
2641
+ }
2642
+ };
2643
+ }
2644
+ });
2645
+
2646
+ // ../yukigo-ast/dist/visitor/base.js
2647
+ var TraverseBase;
2648
+ var init_base = __esm({
2649
+ "../yukigo-ast/dist/visitor/base.js"() {
2650
+ TraverseBase = class {
2651
+ visit(node) {
2652
+ node.accept(this);
2653
+ }
2654
+ traverseCollection(nodes) {
2655
+ nodes.forEach((node) => node.accept(this));
2656
+ }
2657
+ };
2658
+ }
2659
+ });
2660
+
2661
+ // ../yukigo-ast/dist/visitor/expressions.js
2662
+ function ExpressionTraverser(Base) {
2663
+ class ExpressionTraverser2 extends Base {
2664
+ visitTupleExpr(node) {
2665
+ this.traverseCollection(node.elements);
2666
+ }
2667
+ visitFieldExpr(node) {
2668
+ node.name.accept(this);
2669
+ node.expression.accept(this);
2670
+ }
2671
+ visitDataExpr(node) {
2672
+ node.name.accept(this);
2673
+ this.traverseCollection(node.contents);
2674
+ }
2675
+ visitConsExpr(node) {
2676
+ node.head.accept(this);
2677
+ node.tail.accept(this);
2678
+ }
2679
+ visitLetInExpr(node) {
2680
+ node.expression.accept(this);
2681
+ node.declarations.accept(this);
2682
+ }
2683
+ visitGuardedExpression(node) {
2684
+ this.traverseCollection(node.guards);
2685
+ }
2686
+ visitGuard(node) {
2687
+ node.condition.accept(this);
2688
+ node.body.accept(this);
2689
+ }
2690
+ visitCall(node) {
2691
+ node.callee.accept(this);
2692
+ this.traverseCollection(node.args);
2693
+ }
2694
+ visitOtherwise(node) {
2695
+ }
2696
+ visitCompositionExpression(node) {
2697
+ node.left.accept(this);
2698
+ node.right.accept(this);
2699
+ }
2700
+ visitLambda(node) {
2701
+ node.body.accept(this);
2702
+ this.traverseCollection(node.parameters);
2703
+ }
2704
+ visitApplication(node) {
2705
+ node.functionExpr.accept(this);
2706
+ node.parameter.accept(this);
2707
+ }
2708
+ visitExist(node) {
2709
+ node.identifier.accept(this);
2710
+ this.traverseCollection(node.patterns);
2711
+ }
2712
+ visitNot(node) {
2713
+ node.expression.accept(this);
2714
+ }
2715
+ visitFindall(node) {
2716
+ node.template.accept(this);
2717
+ node.goal.accept(this);
2718
+ node.bag.accept(this);
2719
+ }
2720
+ visitForall(node) {
2721
+ node.condition.accept(this);
2722
+ node.action.accept(this);
2723
+ }
2724
+ visitGoal(node) {
2725
+ node.identifier.accept(this);
2726
+ this.traverseCollection(node.args);
2727
+ }
2728
+ visitSend(node) {
2729
+ node.selector.accept(this);
2730
+ node.receiver.accept(this);
2731
+ this.traverseCollection(node.args);
2732
+ }
2733
+ visitNew(node) {
2734
+ node.identifier.accept(this);
2735
+ this.traverseCollection(node.args);
2736
+ }
2737
+ visitImplement(node) {
2738
+ node.identifier.accept(this);
2739
+ }
2740
+ visitListComprehension(node) {
2741
+ node.projection.accept(this);
2742
+ this.traverseCollection(node.generators);
2743
+ }
2744
+ visitGenerator(node) {
2745
+ node.variable.accept(this);
2746
+ node.expression.accept(this);
2747
+ }
2748
+ visitRangeExpression(node) {
2749
+ node.start.accept(this);
2750
+ node.step?.accept(this);
2751
+ node.end?.accept(this);
2752
+ }
2753
+ visitNamedArgument(node) {
2754
+ node.identifier.accept(this);
2755
+ node.expression.accept(this);
2756
+ }
2757
+ visitYield(node) {
2758
+ node.expression.accept(this);
2759
+ }
2760
+ }
2761
+ ;
2762
+ return ExpressionTraverser2;
2763
+ }
2764
+ var init_expressions2 = __esm({
2765
+ "../yukigo-ast/dist/visitor/expressions.js"() {
2766
+ }
2767
+ });
2768
+
2769
+ // ../yukigo-ast/dist/visitor/operations.js
2770
+ function OperationTraverser(Base) {
2771
+ class OperationTraverser2 extends Base {
2772
+ traverseBinary(node) {
2773
+ node.left.accept(this);
2774
+ node.right.accept(this);
2775
+ }
2776
+ traverseUnary(node) {
2777
+ node.operand.accept(this);
2778
+ }
2779
+ visitArithmeticUnaryOperation(node) {
2780
+ this.traverseUnary(node);
2781
+ }
2782
+ visitArithmeticBinaryOperation(node) {
2783
+ this.traverseBinary(node);
2784
+ }
2785
+ visitListUnaryOperation(node) {
2786
+ this.traverseUnary(node);
2787
+ }
2788
+ visitListBinaryOperation(node) {
2789
+ this.traverseBinary(node);
2790
+ }
2791
+ visitComparisonOperation(node) {
2792
+ this.traverseBinary(node);
2793
+ }
2794
+ visitLogicalBinaryOperation(node) {
2795
+ this.traverseBinary(node);
2796
+ }
2797
+ visitLogicalUnaryOperation(node) {
2798
+ this.traverseUnary(node);
2799
+ }
2800
+ visitBitwiseBinaryOperation(node) {
2801
+ this.traverseBinary(node);
2802
+ }
2803
+ visitBitwiseUnaryOperation(node) {
2804
+ this.traverseUnary(node);
2805
+ }
2806
+ visitStringOperation(node) {
2807
+ this.traverseBinary(node);
2808
+ }
2809
+ visitUnifyOperation(node) {
2810
+ this.traverseBinary(node);
2811
+ }
2812
+ visitAssignOperation(node) {
2813
+ this.traverseBinary(node);
2814
+ }
2815
+ }
2816
+ return OperationTraverser2;
2817
+ }
2818
+ var init_operations = __esm({
2819
+ "../yukigo-ast/dist/visitor/operations.js"() {
2820
+ }
2821
+ });
2822
+
2823
+ // ../yukigo-ast/dist/visitor/patterns.js
2824
+ function PatternTraverser(Base) {
2825
+ class PatternTraverser2 extends Base {
2826
+ visitVariablePattern(node) {
2827
+ node.name.accept(this);
2828
+ }
2829
+ visitLiteralPattern(node) {
2830
+ node.name.accept(this);
2831
+ }
2832
+ visitApplicationPattern(node) {
2833
+ node.identifier.accept(this);
2834
+ this.traverseCollection(node.args);
2835
+ }
2836
+ visitTuplePattern(node) {
2837
+ this.traverseCollection(node.elements);
2838
+ }
2839
+ visitListPattern(node) {
2840
+ this.traverseCollection(node.elements);
2841
+ }
2842
+ visitFunctorPattern(node) {
2843
+ node.identifier.accept(this);
2844
+ this.traverseCollection(node.args);
2845
+ }
2846
+ visitAsPattern(node) {
2847
+ node.left.accept(this);
2848
+ node.right.accept(this);
2849
+ }
2850
+ visitWildcardPattern(node) {
2851
+ }
2852
+ visitUnionPattern(node) {
2853
+ this.traverseCollection(node.elements);
2854
+ }
2855
+ visitConstructorPattern(node) {
2856
+ this.traverseCollection(node.args);
2857
+ }
2858
+ visitConsPattern(node) {
2859
+ node.left.accept(this);
2860
+ node.right.accept(this);
2861
+ }
2862
+ visitTypePattern(node) {
2863
+ node.targetType.accept(this);
2864
+ node.innerPattern?.accept(this);
2865
+ }
2866
+ }
2867
+ ;
2868
+ return PatternTraverser2;
2869
+ }
2870
+ var init_patterns2 = __esm({
2871
+ "../yukigo-ast/dist/visitor/patterns.js"() {
2872
+ }
2873
+ });
2874
+
2875
+ // ../yukigo-ast/dist/visitor/primitives.js
2876
+ function PrimitiveTraverser(Base) {
2877
+ class PrimitiveTraverser2 extends Base {
2878
+ visitNumberPrimitive(node) {
2879
+ }
2880
+ visitBooleanPrimitive(node) {
2881
+ }
2882
+ visitStringPrimitive(node) {
2883
+ }
2884
+ visitListPrimitive(node) {
2885
+ this.traverseCollection(node.value);
2886
+ }
2887
+ visitNilPrimitive(node) {
2888
+ }
2889
+ visitSymbolPrimitive(node) {
2890
+ }
2891
+ visitCharPrimitive(node) {
2892
+ }
2893
+ }
2894
+ return PrimitiveTraverser2;
2895
+ }
2896
+ var init_primitives2 = __esm({
2897
+ "../yukigo-ast/dist/visitor/primitives.js"() {
2898
+ }
2899
+ });
2900
+
2901
+ // ../yukigo-ast/dist/visitor/statements.js
2902
+ function StatementTraverser(Base) {
2903
+ class StatementTraverser2 extends Base {
2904
+ visitSequence(node) {
2905
+ this.traverseCollection(node.statements);
2906
+ }
2907
+ visitSelf(node) {
2908
+ }
2909
+ visitSuper(node) {
2910
+ }
2911
+ visitIf(node) {
2912
+ node.condition.accept(this);
2913
+ node.then.accept(this);
2914
+ node.elseExpr.accept(this);
2915
+ }
2916
+ visitReturn(node) {
2917
+ node.body?.accept(this);
2918
+ }
2919
+ visitFunction(node) {
2920
+ node.identifier.accept(this);
2921
+ this.traverseCollection(node.equations);
2922
+ }
2923
+ visitField(node) {
2924
+ node.name?.accept(this);
2925
+ node.value.accept(this);
2926
+ }
2927
+ visitConstructor(node) {
2928
+ node.name.accept(this);
2929
+ this.traverseCollection(node.fields);
2930
+ }
2931
+ visitRecord(node) {
2932
+ node.name.accept(this);
2933
+ this.traverseCollection(node.contents);
2934
+ if (node.deriving)
2935
+ this.traverseCollection(node.deriving);
2936
+ }
2937
+ visitUnguardedBody(node) {
2938
+ node.sequence.accept(this);
2939
+ }
2940
+ visitNativeBody(node) {
2941
+ }
2942
+ visitEquation(node) {
2943
+ if (Array.isArray(node.body)) {
2944
+ this.traverseCollection(node.body);
2945
+ } else {
2946
+ node.body.accept(this);
2947
+ }
2948
+ this.traverseCollection(node.patterns);
2949
+ node.returnExpr?.accept(this);
2950
+ }
2951
+ visitSwitch(node) {
2952
+ node.value.accept(this);
2953
+ this.traverseCollection(node.cases);
2954
+ }
2955
+ visitCase(node) {
2956
+ node.condition.accept(this);
2957
+ node.body.accept(this);
2958
+ }
2959
+ visitTry(node) {
2960
+ node.body.accept(this);
2961
+ this.traverseCollection(node.catchExpr);
2962
+ node.finallyExpr.accept(this);
2963
+ }
2964
+ visitCatch(node) {
2965
+ node.body.accept(this);
2966
+ this.traverseCollection(node.patterns);
2967
+ }
2968
+ visitRaise(node) {
2969
+ node.body.accept(this);
2970
+ }
2971
+ visitPrint(node) {
2972
+ node.expression.accept(this);
2973
+ }
2974
+ visitInput(node) {
2975
+ node.message.accept(this);
2976
+ }
2977
+ visitFor(node) {
2978
+ node.body.accept(this);
2979
+ this.traverseCollection(node.statements);
2980
+ }
2981
+ visitBreak(node) {
2982
+ node.body?.accept(this);
2983
+ }
2984
+ visitContinue(node) {
2985
+ node.body?.accept(this);
2986
+ }
2987
+ visitVariable(node) {
2988
+ node.identifier.accept(this);
2989
+ node.expression.accept(this);
2990
+ node.variableType?.accept(this);
2991
+ }
2992
+ visitAssignment(node) {
2993
+ node.identifier.accept(this);
2994
+ node.expression.accept(this);
2995
+ }
2996
+ visitStructure(node) {
2997
+ this.traverseCollection(node.elements);
2998
+ }
2999
+ visitEntryPoint(node) {
3000
+ node.identifier.accept(this);
3001
+ node.expression.accept(this);
3002
+ }
3003
+ visitProcedure(node) {
3004
+ node.identifier.accept(this);
3005
+ this.traverseCollection(node.equations);
3006
+ }
3007
+ visitEnumeration(node) {
3008
+ node.identifier.accept(this);
3009
+ this.traverseCollection(node.contents);
3010
+ }
3011
+ visitWhile(node) {
3012
+ node.condition.accept(this);
3013
+ node.body.accept(this);
3014
+ }
3015
+ visitRepeat(node) {
3016
+ node.body.accept(this);
3017
+ node.count.accept(this);
3018
+ }
3019
+ visitForLoop(node) {
3020
+ node.initialization.accept(this);
3021
+ node.condition.accept(this);
3022
+ node.update.accept(this);
3023
+ node.body.accept(this);
3024
+ }
3025
+ visitRule(node) {
3026
+ node.identifier.accept(this);
3027
+ this.traverseCollection(node.equations);
3028
+ }
3029
+ visitFact(node) {
3030
+ node.identifier.accept(this);
3031
+ this.traverseCollection(node.patterns);
3032
+ }
3033
+ visitQuery(node) {
3034
+ this.traverseCollection(node.expressions);
3035
+ }
3036
+ visitMethod(node) {
3037
+ node.identifier.accept(this);
3038
+ this.traverseCollection(node.equations);
3039
+ }
3040
+ visitPrimitiveMethod(node) {
3041
+ this.traverseCollection(node.equations);
3042
+ }
3043
+ visitAttribute(node) {
3044
+ node.identifier.accept(this);
3045
+ node.expression.accept(this);
3046
+ }
3047
+ visitObject(node) {
3048
+ node.identifier.accept(this);
3049
+ node.expression.accept(this);
3050
+ node.extendsSymbol?.accept(this);
3051
+ if (node.extendsArgs) {
3052
+ this.traverseCollection(node.extendsArgs);
3053
+ }
3054
+ }
3055
+ visitClass(node) {
3056
+ node.identifier.accept(this);
3057
+ node.expression.accept(this);
3058
+ node.extendsSymbol?.accept(this);
3059
+ node.implementsNode?.accept(this);
3060
+ }
3061
+ visitInterface(node) {
3062
+ node.identifier.accept(this);
3063
+ this.traverseCollection(node.extendsSymbol);
3064
+ node.expression.accept(this);
3065
+ }
3066
+ visitLogicConstraint(node) {
3067
+ node.expression.accept(this);
3068
+ }
3069
+ }
3070
+ ;
3071
+ return StatementTraverser2;
3072
+ }
3073
+ var init_statements2 = __esm({
3074
+ "../yukigo-ast/dist/visitor/statements.js"() {
3075
+ }
3076
+ });
3077
+
3078
+ // ../yukigo-ast/dist/visitor/types.js
3079
+ function TypeTraverser(Base) {
3080
+ class TypeTraverser2 extends Base {
3081
+ visitSimpleType(node) {
3082
+ this.traverseCollection(node.constraints);
3083
+ }
3084
+ visitTypeVar(node) {
3085
+ this.traverseCollection(node.constraints);
3086
+ }
3087
+ visitTypeApplication(node) {
3088
+ node.functionType.accept(this);
3089
+ node.argument.accept(this);
3090
+ }
3091
+ visitListType(node) {
3092
+ this.traverseCollection(node.constraints);
3093
+ }
3094
+ visitTupleType(node) {
3095
+ this.traverseCollection(node.constraints);
3096
+ this.traverseCollection(node.values);
3097
+ }
3098
+ visitConstraint(node) {
3099
+ this.traverseCollection(node.parameters);
3100
+ }
3101
+ visitParameterizedType(node) {
3102
+ this.traverseCollection(node.inputs);
3103
+ this.traverseCollection(node.constraints);
3104
+ node.returnType.accept(this);
3105
+ }
3106
+ visitConstrainedType(node) {
3107
+ this.traverseCollection(node.constraints);
3108
+ }
3109
+ visitTypeAlias(node) {
3110
+ node.identifier.accept(this);
3111
+ node.value.accept(this);
3112
+ }
3113
+ visitTypeSignature(node) {
3114
+ node.body.accept(this);
3115
+ node.identifier.accept(this);
3116
+ }
3117
+ visitTypeCast(node) {
3118
+ node.body.accept(this);
3119
+ node.expression.accept(this);
3120
+ }
3121
+ }
3122
+ return TypeTraverser2;
3123
+ }
3124
+ var init_types2 = __esm({
3125
+ "../yukigo-ast/dist/visitor/types.js"() {
3126
+ }
3127
+ });
3128
+
3129
+ // ../yukigo-ast/dist/visitor/testing.js
3130
+ function TestingTraverser(Base) {
3131
+ class TestingTraverser2 extends Base {
3132
+ visitTestGroup(node) {
3133
+ node.name.accept(this);
3134
+ node.group.accept(this);
3135
+ }
3136
+ visitTest(node) {
3137
+ node.name.accept(this);
3138
+ this.traverseCollection(node.args);
3139
+ node.body.accept(this);
3140
+ }
3141
+ visitAssert(node) {
3142
+ node.negated.accept(this);
3143
+ node.body.accept(this);
3144
+ }
3145
+ visitTruth(node) {
3146
+ node.body.accept(this);
3147
+ }
3148
+ visitEquality(node) {
3149
+ node.expected.accept(this);
3150
+ node.value.accept(this);
3151
+ }
3152
+ visitFailure(node) {
3153
+ node.func.accept(this);
3154
+ node.message.accept(this);
3155
+ }
3156
+ }
3157
+ ;
3158
+ return TestingTraverser2;
3159
+ }
3160
+ var init_testing2 = __esm({
3161
+ "../yukigo-ast/dist/visitor/testing.js"() {
3162
+ }
3163
+ });
3164
+
3165
+ // ../yukigo-ast/dist/visitor/typeclasses.js
3166
+ function TypeClassTraverser(Base) {
3167
+ class TypeClassTraverser2 extends Base {
3168
+ visitTypeClass(node) {
3169
+ this.traverseCollection(node.signatures);
3170
+ }
3171
+ visitInstance(node) {
3172
+ this.traverseCollection(node.functions);
3173
+ }
3174
+ }
3175
+ ;
3176
+ return TypeClassTraverser2;
3177
+ }
3178
+ var init_typeclasses2 = __esm({
3179
+ "../yukigo-ast/dist/visitor/typeclasses.js"() {
3180
+ }
3181
+ });
3182
+
3183
+ // ../yukigo-ast/dist/visitor/index.js
3184
+ var StopTraversalException, TraverseVisitor;
3185
+ var init_visitor = __esm({
3186
+ "../yukigo-ast/dist/visitor/index.js"() {
3187
+ init_base();
3188
+ init_expressions2();
3189
+ init_operations();
3190
+ init_patterns2();
3191
+ init_primitives2();
3192
+ init_statements2();
3193
+ init_types2();
3194
+ init_testing2();
3195
+ init_typeclasses2();
3196
+ init_base();
3197
+ init_expressions2();
3198
+ init_operations();
3199
+ init_patterns2();
3200
+ init_primitives2();
3201
+ init_statements2();
3202
+ init_types2();
3203
+ init_testing2();
3204
+ init_typeclasses2();
3205
+ StopTraversalException = class extends Error {
3206
+ constructor() {
3207
+ super("Inspection found, aborting traversal.");
3208
+ }
3209
+ };
3210
+ TraverseVisitor = class extends TypeClassTraverser(TestingTraverser(TypeTraverser(StatementTraverser(PatternTraverser(OperationTraverser(PrimitiveTraverser(ExpressionTraverser(TraverseBase)))))))) {
3211
+ };
3212
+ }
3213
+ });
3214
+
3215
+ // ../yukigo-ast/dist/index.js
3216
+ var dist_exports = {};
3217
+ __export(dist_exports, {
3218
+ ASTNode: () => ASTNode,
3219
+ Application: () => Application,
3220
+ ApplicationPattern: () => ApplicationPattern,
3221
+ ArithmeticBinaryOperation: () => ArithmeticBinaryOperation,
3222
+ ArithmeticUnaryOperation: () => ArithmeticUnaryOperation,
3223
+ AsPattern: () => AsPattern,
3224
+ Assert: () => Assert,
3225
+ AssignOperation: () => AssignOperation,
3226
+ Assignment: () => Assignment,
3227
+ Attribute: () => Attribute,
3228
+ BitwiseBinaryOperation: () => BitwiseBinaryOperation,
3229
+ BitwiseUnaryOperation: () => BitwiseUnaryOperation,
3230
+ BooleanPrimitive: () => BooleanPrimitive,
3231
+ Break: () => Break,
3232
+ Call: () => Call,
3233
+ Case: () => Case,
3234
+ Catch: () => Catch,
3235
+ CharPrimitive: () => CharPrimitive,
3236
+ Class: () => Class,
3237
+ ComparisonOperation: () => ComparisonOperation,
3238
+ CompositionExpression: () => CompositionExpression,
3239
+ ConsExpression: () => ConsExpression,
3240
+ ConsPattern: () => ConsPattern,
3241
+ ConstrainedType: () => ConstrainedType,
3242
+ Constraint: () => Constraint,
3243
+ Constructor: () => Constructor,
3244
+ ConstructorPattern: () => ConstructorPattern,
3245
+ Continue: () => Continue,
3246
+ DataExpression: () => DataExpression,
3247
+ EntryPoint: () => EntryPoint,
3248
+ Enumeration: () => Enumeration,
3249
+ Equality: () => Equality,
3250
+ Equation: () => Equation,
3251
+ Exist: () => Exist,
3252
+ ExpressionTraverser: () => ExpressionTraverser,
3253
+ Fact: () => Fact,
3254
+ Failure: () => Failure,
3255
+ Field: () => Field,
3256
+ FieldExpression: () => FieldExpression,
3257
+ Findall: () => Findall,
3258
+ For: () => For,
3259
+ ForLoop: () => ForLoop,
3260
+ Forall: () => Forall,
3261
+ Function: () => Function,
3262
+ FunctorPattern: () => FunctorPattern,
3263
+ Generator: () => Generator,
3264
+ Goal: () => Goal,
3265
+ Guard: () => Guard,
3266
+ GuardedExpression: () => GuardedExpression,
3267
+ If: () => If,
3268
+ Implement: () => Implement,
3269
+ Input: () => Input,
3270
+ Instance: () => Instance,
3271
+ Interface: () => Interface,
3272
+ Lambda: () => Lambda,
3273
+ LetInExpression: () => LetInExpression,
3274
+ ListBinaryOperation: () => ListBinaryOperation,
3275
+ ListComprehension: () => ListComprehension,
3276
+ ListPattern: () => ListPattern,
3277
+ ListPrimitive: () => ListPrimitive,
3278
+ ListType: () => ListType,
3279
+ ListUnaryOperation: () => ListUnaryOperation,
3280
+ LiteralPattern: () => LiteralPattern,
3281
+ LogicConstraint: () => LogicConstraint,
3282
+ LogicalBinaryOperation: () => LogicalBinaryOperation,
3283
+ LogicalUnaryOperation: () => LogicalUnaryOperation,
3284
+ Method: () => Method,
3285
+ NamedArgument: () => NamedArgument,
3286
+ NativeBody: () => NativeBody,
3287
+ New: () => New,
3288
+ NilPrimitive: () => NilPrimitive,
3289
+ Not: () => Not,
3290
+ NumberPrimitive: () => NumberPrimitive,
3291
+ Object: () => Object2,
3292
+ OperationTraverser: () => OperationTraverser,
3293
+ Otherwise: () => Otherwise,
3294
+ ParameterizedType: () => ParameterizedType,
3295
+ PatternTraverser: () => PatternTraverser,
3296
+ PrimitiveMethod: () => PrimitiveMethod,
3297
+ PrimitiveTraverser: () => PrimitiveTraverser,
3298
+ Print: () => Print,
3299
+ Procedure: () => Procedure,
3300
+ Query: () => Query,
3301
+ Raise: () => Raise,
3302
+ RangeExpression: () => RangeExpression,
3303
+ Record: () => Record,
3304
+ Repeat: () => Repeat,
3305
+ Return: () => Return,
3306
+ Rule: () => Rule,
3307
+ Self: () => Self,
3308
+ Send: () => Send,
3309
+ Sequence: () => Sequence,
3310
+ SimpleType: () => SimpleType,
3311
+ SourceLocation: () => SourceLocation,
3312
+ StatementTraverser: () => StatementTraverser,
3313
+ StopTraversalException: () => StopTraversalException,
3314
+ StringOperation: () => StringOperation,
3315
+ StringPrimitive: () => StringPrimitive,
3316
+ Structure: () => Structure,
3317
+ Super: () => Super,
3318
+ Switch: () => Switch,
3319
+ SymbolPrimitive: () => SymbolPrimitive,
3320
+ Test: () => Test,
3321
+ TestGroup: () => TestGroup,
3322
+ TestingTraverser: () => TestingTraverser,
3323
+ TraverseBase: () => TraverseBase,
3324
+ TraverseVisitor: () => TraverseVisitor,
3325
+ Truth: () => Truth,
3326
+ Try: () => Try,
3327
+ TupleExpression: () => TupleExpression,
3328
+ TuplePattern: () => TuplePattern,
3329
+ TupleType: () => TupleType,
3330
+ TypeAlias: () => TypeAlias,
3331
+ TypeApplication: () => TypeApplication,
3332
+ TypeCast: () => TypeCast,
3333
+ TypeClass: () => TypeClass,
3334
+ TypeClassTraverser: () => TypeClassTraverser,
3335
+ TypePattern: () => TypePattern,
3336
+ TypeSignature: () => TypeSignature,
3337
+ TypeTraverser: () => TypeTraverser,
3338
+ TypeVar: () => TypeVar,
3339
+ UnguardedBody: () => UnguardedBody,
3340
+ UnifyOperation: () => UnifyOperation,
3341
+ UnionPattern: () => UnionPattern,
3342
+ Variable: () => Variable,
3343
+ VariablePattern: () => VariablePattern,
3344
+ While: () => While,
3345
+ WildcardPattern: () => WildcardPattern,
3346
+ Yield: () => Yield,
3347
+ isPattern: () => isPattern,
3348
+ isYukigoPrimitive: () => isYukigoPrimitive
3349
+ });
3350
+ var init_dist = __esm({
3351
+ "../yukigo-ast/dist/index.js"() {
3352
+ init_generics();
3353
+ init_expressions();
3354
+ init_statements();
3355
+ init_primitives();
3356
+ init_operators();
3357
+ init_patterns();
3358
+ init_types();
3359
+ init_testing();
3360
+ init_functional();
3361
+ init_object();
3362
+ init_imperative();
3363
+ init_logic();
3364
+ init_typeclasses();
3365
+ init_visitor();
3366
+ }
3367
+ });
3368
+
3369
+ // ../../node_modules/nearley/lib/nearley.js
3370
+ var require_nearley = __commonJS({
3371
+ "../../node_modules/nearley/lib/nearley.js"(exports, module) {
3372
+ (function(root, factory) {
3373
+ if (typeof module === "object" && module.exports) {
3374
+ module.exports = factory();
3375
+ } else {
3376
+ root.nearley = factory();
3377
+ }
3378
+ })(exports, function() {
3379
+ function Rule2(name, symbols, postprocess) {
3380
+ this.id = ++Rule2.highestId;
3381
+ this.name = name;
3382
+ this.symbols = symbols;
3383
+ this.postprocess = postprocess;
3384
+ return this;
3385
+ }
3386
+ Rule2.highestId = 0;
3387
+ Rule2.prototype.toString = function(withCursorAt) {
3388
+ var symbolSequence = typeof withCursorAt === "undefined" ? this.symbols.map(getSymbolShortDisplay).join(" ") : this.symbols.slice(0, withCursorAt).map(getSymbolShortDisplay).join(" ") + " \u25CF " + this.symbols.slice(withCursorAt).map(getSymbolShortDisplay).join(" ");
3389
+ return this.name + " \u2192 " + symbolSequence;
3390
+ };
3391
+ function State(rule, dot, reference, wantedBy) {
3392
+ this.rule = rule;
3393
+ this.dot = dot;
3394
+ this.reference = reference;
3395
+ this.data = [];
3396
+ this.wantedBy = wantedBy;
3397
+ this.isComplete = this.dot === rule.symbols.length;
3398
+ }
3399
+ State.prototype.toString = function() {
3400
+ return "{" + this.rule.toString(this.dot) + "}, from: " + (this.reference || 0);
3401
+ };
3402
+ State.prototype.nextState = function(child) {
3403
+ var state = new State(this.rule, this.dot + 1, this.reference, this.wantedBy);
3404
+ state.left = this;
3405
+ state.right = child;
3406
+ if (state.isComplete) {
3407
+ state.data = state.build();
3408
+ state.right = void 0;
3409
+ }
3410
+ return state;
3411
+ };
3412
+ State.prototype.build = function() {
3413
+ var children = [];
3414
+ var node = this;
3415
+ do {
3416
+ children.push(node.right.data);
3417
+ node = node.left;
3418
+ } while (node.left);
3419
+ children.reverse();
3420
+ return children;
3421
+ };
3422
+ State.prototype.finish = function() {
3423
+ if (this.rule.postprocess) {
3424
+ this.data = this.rule.postprocess(this.data, this.reference, Parser.fail);
3425
+ }
3426
+ };
3427
+ function Column(grammar2, index) {
3428
+ this.grammar = grammar2;
3429
+ this.index = index;
3430
+ this.states = [];
3431
+ this.wants = {};
3432
+ this.scannable = [];
3433
+ this.completed = {};
3434
+ }
3435
+ Column.prototype.process = function(nextColumn) {
3436
+ var states = this.states;
3437
+ var wants = this.wants;
3438
+ var completed = this.completed;
3439
+ for (var w = 0; w < states.length; w++) {
3440
+ var state = states[w];
3441
+ if (state.isComplete) {
3442
+ state.finish();
3443
+ if (state.data !== Parser.fail) {
3444
+ var wantedBy = state.wantedBy;
3445
+ for (var i = wantedBy.length; i--; ) {
3446
+ var left = wantedBy[i];
3447
+ this.complete(left, state);
3448
+ }
3449
+ if (state.reference === this.index) {
3450
+ var exp = state.rule.name;
3451
+ (this.completed[exp] = this.completed[exp] || []).push(state);
3452
+ }
3453
+ }
3454
+ } else {
3455
+ var exp = state.rule.symbols[state.dot];
3456
+ if (typeof exp !== "string") {
3457
+ this.scannable.push(state);
3458
+ continue;
3459
+ }
3460
+ if (wants[exp]) {
3461
+ wants[exp].push(state);
3462
+ if (completed.hasOwnProperty(exp)) {
3463
+ var nulls = completed[exp];
3464
+ for (var i = 0; i < nulls.length; i++) {
3465
+ var right = nulls[i];
3466
+ this.complete(state, right);
3467
+ }
3468
+ }
3469
+ } else {
3470
+ wants[exp] = [state];
3471
+ this.predict(exp);
3472
+ }
3473
+ }
3474
+ }
3475
+ };
3476
+ Column.prototype.predict = function(exp) {
3477
+ var rules = this.grammar.byName[exp] || [];
3478
+ for (var i = 0; i < rules.length; i++) {
3479
+ var r = rules[i];
3480
+ var wantedBy = this.wants[exp];
3481
+ var s = new State(r, 0, this.index, wantedBy);
3482
+ this.states.push(s);
3483
+ }
3484
+ };
3485
+ Column.prototype.complete = function(left, right) {
3486
+ var copy = left.nextState(right);
3487
+ this.states.push(copy);
3488
+ };
3489
+ function Grammar(rules, start) {
3490
+ this.rules = rules;
3491
+ this.start = start || this.rules[0].name;
3492
+ var byName = this.byName = {};
3493
+ this.rules.forEach(function(rule) {
3494
+ if (!byName.hasOwnProperty(rule.name)) {
3495
+ byName[rule.name] = [];
3496
+ }
3497
+ byName[rule.name].push(rule);
3498
+ });
3499
+ }
3500
+ Grammar.fromCompiled = function(rules, start) {
3501
+ var lexer = rules.Lexer;
3502
+ if (rules.ParserStart) {
3503
+ start = rules.ParserStart;
3504
+ rules = rules.ParserRules;
3505
+ }
3506
+ var rules = rules.map(function(r) {
3507
+ return new Rule2(r.name, r.symbols, r.postprocess);
3508
+ });
3509
+ var g = new Grammar(rules, start);
3510
+ g.lexer = lexer;
3511
+ return g;
3512
+ };
3513
+ function StreamLexer() {
3514
+ this.reset("");
3515
+ }
3516
+ StreamLexer.prototype.reset = function(data, state) {
3517
+ this.buffer = data;
3518
+ this.index = 0;
3519
+ this.line = state ? state.line : 1;
3520
+ this.lastLineBreak = state ? -state.col : 0;
3521
+ };
3522
+ StreamLexer.prototype.next = function() {
3523
+ if (this.index < this.buffer.length) {
3524
+ var ch = this.buffer[this.index++];
3525
+ if (ch === "\n") {
3526
+ this.line += 1;
3527
+ this.lastLineBreak = this.index;
3528
+ }
3529
+ return { value: ch };
3530
+ }
3531
+ };
3532
+ StreamLexer.prototype.save = function() {
3533
+ return {
3534
+ line: this.line,
3535
+ col: this.index - this.lastLineBreak
3536
+ };
3537
+ };
3538
+ StreamLexer.prototype.formatError = function(token, message) {
3539
+ var buffer = this.buffer;
3540
+ if (typeof buffer === "string") {
3541
+ var lines = buffer.split("\n").slice(
3542
+ Math.max(0, this.line - 5),
3543
+ this.line
3544
+ );
3545
+ var nextLineBreak = buffer.indexOf("\n", this.index);
3546
+ if (nextLineBreak === -1) nextLineBreak = buffer.length;
3547
+ var col = this.index - this.lastLineBreak;
3548
+ var lastLineDigits = String(this.line).length;
3549
+ message += " at line " + this.line + " col " + col + ":\n\n";
3550
+ message += lines.map(function(line, i) {
3551
+ return pad(this.line - lines.length + i + 1, lastLineDigits) + " " + line;
3552
+ }, this).join("\n");
3553
+ message += "\n" + pad("", lastLineDigits + col) + "^\n";
3554
+ return message;
3555
+ } else {
3556
+ return message + " at index " + (this.index - 1);
3557
+ }
3558
+ function pad(n, length) {
3559
+ var s = String(n);
3560
+ return Array(length - s.length + 1).join(" ") + s;
3561
+ }
3562
+ };
3563
+ function Parser(rules, start, options) {
3564
+ if (rules instanceof Grammar) {
3565
+ var grammar2 = rules;
3566
+ var options = start;
3567
+ } else {
3568
+ var grammar2 = Grammar.fromCompiled(rules, start);
3569
+ }
3570
+ this.grammar = grammar2;
3571
+ this.options = {
3572
+ keepHistory: false,
3573
+ lexer: grammar2.lexer || new StreamLexer()
3574
+ };
3575
+ for (var key in options || {}) {
3576
+ this.options[key] = options[key];
3577
+ }
3578
+ this.lexer = this.options.lexer;
3579
+ this.lexerState = void 0;
3580
+ var column = new Column(grammar2, 0);
3581
+ var table = this.table = [column];
3582
+ column.wants[grammar2.start] = [];
3583
+ column.predict(grammar2.start);
3584
+ column.process();
3585
+ this.current = 0;
3586
+ }
3587
+ Parser.fail = {};
3588
+ Parser.prototype.feed = function(chunk) {
3589
+ var lexer = this.lexer;
3590
+ lexer.reset(chunk, this.lexerState);
3591
+ var token;
3592
+ while (true) {
3593
+ try {
3594
+ token = lexer.next();
3595
+ if (!token) {
3596
+ break;
3597
+ }
3598
+ } catch (e) {
3599
+ var nextColumn = new Column(this.grammar, this.current + 1);
3600
+ this.table.push(nextColumn);
3601
+ var err = new Error(this.reportLexerError(e));
3602
+ err.offset = this.current;
3603
+ err.token = e.token;
3604
+ throw err;
3605
+ }
3606
+ var column = this.table[this.current];
3607
+ if (!this.options.keepHistory) {
3608
+ delete this.table[this.current - 1];
3609
+ }
3610
+ var n = this.current + 1;
3611
+ var nextColumn = new Column(this.grammar, n);
3612
+ this.table.push(nextColumn);
3613
+ var literal = token.text !== void 0 ? token.text : token.value;
3614
+ var value = lexer.constructor === StreamLexer ? token.value : token;
3615
+ var scannable = column.scannable;
3616
+ for (var w = scannable.length; w--; ) {
3617
+ var state = scannable[w];
3618
+ var expect = state.rule.symbols[state.dot];
3619
+ if (expect.test ? expect.test(value) : expect.type ? expect.type === token.type : expect.literal === literal) {
3620
+ var next = state.nextState({ data: value, token, isToken: true, reference: n - 1 });
3621
+ nextColumn.states.push(next);
3622
+ }
3623
+ }
3624
+ nextColumn.process();
3625
+ if (nextColumn.states.length === 0) {
3626
+ var err = new Error(this.reportError(token));
3627
+ err.offset = this.current;
3628
+ err.token = token;
3629
+ throw err;
3630
+ }
3631
+ if (this.options.keepHistory) {
3632
+ column.lexerState = lexer.save();
3633
+ }
3634
+ this.current++;
3635
+ }
3636
+ if (column) {
3637
+ this.lexerState = lexer.save();
3638
+ }
3639
+ this.results = this.finish();
3640
+ return this;
3641
+ };
3642
+ Parser.prototype.reportLexerError = function(lexerError) {
3643
+ var tokenDisplay, lexerMessage;
3644
+ var token = lexerError.token;
3645
+ if (token) {
3646
+ tokenDisplay = "input " + JSON.stringify(token.text[0]) + " (lexer error)";
3647
+ lexerMessage = this.lexer.formatError(token, "Syntax error");
3648
+ } else {
3649
+ tokenDisplay = "input (lexer error)";
3650
+ lexerMessage = lexerError.message;
3651
+ }
3652
+ return this.reportErrorCommon(lexerMessage, tokenDisplay);
3653
+ };
3654
+ Parser.prototype.reportError = function(token) {
3655
+ var tokenDisplay = (token.type ? token.type + " token: " : "") + JSON.stringify(token.value !== void 0 ? token.value : token);
3656
+ var lexerMessage = this.lexer.formatError(token, "Syntax error");
3657
+ return this.reportErrorCommon(lexerMessage, tokenDisplay);
3658
+ };
3659
+ Parser.prototype.reportErrorCommon = function(lexerMessage, tokenDisplay) {
3660
+ var lines = [];
3661
+ lines.push(lexerMessage);
3662
+ var lastColumnIndex = this.table.length - 2;
3663
+ var lastColumn = this.table[lastColumnIndex];
3664
+ var expectantStates = lastColumn.states.filter(function(state) {
3665
+ var nextSymbol = state.rule.symbols[state.dot];
3666
+ return nextSymbol && typeof nextSymbol !== "string";
3667
+ });
3668
+ if (expectantStates.length === 0) {
3669
+ lines.push("Unexpected " + tokenDisplay + ". I did not expect any more input. Here is the state of my parse table:\n");
3670
+ this.displayStateStack(lastColumn.states, lines);
3671
+ } else {
3672
+ lines.push("Unexpected " + tokenDisplay + ". Instead, I was expecting to see one of the following:\n");
3673
+ var stateStacks = expectantStates.map(function(state) {
3674
+ return this.buildFirstStateStack(state, []) || [state];
3675
+ }, this);
3676
+ stateStacks.forEach(function(stateStack) {
3677
+ var state = stateStack[0];
3678
+ var nextSymbol = state.rule.symbols[state.dot];
3679
+ var symbolDisplay = this.getSymbolDisplay(nextSymbol);
3680
+ lines.push("A " + symbolDisplay + " based on:");
3681
+ this.displayStateStack(stateStack, lines);
3682
+ }, this);
3683
+ }
3684
+ lines.push("");
3685
+ return lines.join("\n");
3686
+ };
3687
+ Parser.prototype.displayStateStack = function(stateStack, lines) {
3688
+ var lastDisplay;
3689
+ var sameDisplayCount = 0;
3690
+ for (var j = 0; j < stateStack.length; j++) {
3691
+ var state = stateStack[j];
3692
+ var display = state.rule.toString(state.dot);
3693
+ if (display === lastDisplay) {
3694
+ sameDisplayCount++;
3695
+ } else {
3696
+ if (sameDisplayCount > 0) {
3697
+ lines.push(" ^ " + sameDisplayCount + " more lines identical to this");
3698
+ }
3699
+ sameDisplayCount = 0;
3700
+ lines.push(" " + display);
3701
+ }
3702
+ lastDisplay = display;
3703
+ }
3704
+ };
3705
+ Parser.prototype.getSymbolDisplay = function(symbol) {
3706
+ return getSymbolLongDisplay(symbol);
3707
+ };
3708
+ Parser.prototype.buildFirstStateStack = function(state, visited) {
3709
+ if (visited.indexOf(state) !== -1) {
3710
+ return null;
3711
+ }
3712
+ if (state.wantedBy.length === 0) {
3713
+ return [state];
3714
+ }
3715
+ var prevState = state.wantedBy[0];
3716
+ var childVisited = [state].concat(visited);
3717
+ var childResult = this.buildFirstStateStack(prevState, childVisited);
3718
+ if (childResult === null) {
3719
+ return null;
3720
+ }
3721
+ return [state].concat(childResult);
3722
+ };
3723
+ Parser.prototype.save = function() {
3724
+ var column = this.table[this.current];
3725
+ column.lexerState = this.lexerState;
3726
+ return column;
3727
+ };
3728
+ Parser.prototype.restore = function(column) {
3729
+ var index = column.index;
3730
+ this.current = index;
3731
+ this.table[index] = column;
3732
+ this.table.splice(index + 1);
3733
+ this.lexerState = column.lexerState;
3734
+ this.results = this.finish();
3735
+ };
3736
+ Parser.prototype.rewind = function(index) {
3737
+ if (!this.options.keepHistory) {
3738
+ throw new Error("set option `keepHistory` to enable rewinding");
3739
+ }
3740
+ this.restore(this.table[index]);
3741
+ };
3742
+ Parser.prototype.finish = function() {
3743
+ var considerations = [];
3744
+ var start = this.grammar.start;
3745
+ var column = this.table[this.table.length - 1];
3746
+ column.states.forEach(function(t) {
3747
+ if (t.rule.name === start && t.dot === t.rule.symbols.length && t.reference === 0 && t.data !== Parser.fail) {
3748
+ considerations.push(t);
3749
+ }
3750
+ });
3751
+ return considerations.map(function(c) {
3752
+ return c.data;
3753
+ });
3754
+ };
3755
+ function getSymbolLongDisplay(symbol) {
3756
+ var type = typeof symbol;
3757
+ if (type === "string") {
3758
+ return symbol;
3759
+ } else if (type === "object") {
3760
+ if (symbol.literal) {
3761
+ return JSON.stringify(symbol.literal);
3762
+ } else if (symbol instanceof RegExp) {
3763
+ return "character matching " + symbol;
3764
+ } else if (symbol.type) {
3765
+ return symbol.type + " token";
3766
+ } else if (symbol.test) {
3767
+ return "token matching " + String(symbol.test);
3768
+ } else {
3769
+ throw new Error("Unknown symbol type: " + symbol);
3770
+ }
3771
+ }
3772
+ }
3773
+ function getSymbolShortDisplay(symbol) {
3774
+ var type = typeof symbol;
3775
+ if (type === "string") {
3776
+ return symbol;
3777
+ } else if (type === "object") {
3778
+ if (symbol.literal) {
3779
+ return JSON.stringify(symbol.literal);
3780
+ } else if (symbol instanceof RegExp) {
3781
+ return symbol.toString();
3782
+ } else if (symbol.type) {
3783
+ return "%" + symbol.type;
3784
+ } else if (symbol.test) {
3785
+ return "<" + String(symbol.test) + ">";
3786
+ } else {
3787
+ throw new Error("Unknown symbol type: " + symbol);
3788
+ }
3789
+ }
3790
+ }
3791
+ return {
3792
+ Parser,
3793
+ Grammar,
3794
+ Rule: Rule2
3795
+ };
3796
+ });
3797
+ }
3798
+ });
3799
+
3800
+ // ../../node_modules/moo/moo.js
3801
+ var require_moo = __commonJS({
3802
+ "../../node_modules/moo/moo.js"(exports, module) {
3803
+ (function(root, factory) {
3804
+ if (typeof define === "function" && define.amd) {
3805
+ define([], factory);
3806
+ } else if (typeof module === "object" && module.exports) {
3807
+ module.exports = factory();
3808
+ } else {
3809
+ root.moo = factory();
3810
+ }
3811
+ })(exports, function() {
3812
+ "use strict";
3813
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
3814
+ var toString = Object.prototype.toString;
3815
+ var hasSticky = typeof new RegExp().sticky === "boolean";
3816
+ function isRegExp(o) {
3817
+ return o && toString.call(o) === "[object RegExp]";
3818
+ }
3819
+ function isObject(o) {
3820
+ return o && typeof o === "object" && !isRegExp(o) && !Array.isArray(o);
3821
+ }
3822
+ function reEscape(s) {
3823
+ return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, function(x) {
3824
+ if (x === "-") return "\\x2d";
3825
+ return "\\" + x;
3826
+ });
3827
+ }
3828
+ function reGroups(s) {
3829
+ var re = new RegExp("|" + s);
3830
+ return re.exec("").length - 1;
3831
+ }
3832
+ function reCapture(s) {
3833
+ return "(" + s + ")";
3834
+ }
3835
+ function reUnion(regexps) {
3836
+ if (!regexps.length) return "(?!)";
3837
+ var source = regexps.map(function(s) {
3838
+ return "(?:" + s + ")";
3839
+ }).join("|");
3840
+ return "(?:" + source + ")";
3841
+ }
3842
+ function regexpOrLiteral(obj) {
3843
+ if (typeof obj === "string") {
3844
+ return "(?:" + reEscape(obj) + ")";
3845
+ } else if (isRegExp(obj)) {
3846
+ if (obj.ignoreCase) throw new Error("RegExp /i flag not allowed");
3847
+ if (obj.global) throw new Error("RegExp /g flag is implied");
3848
+ if (obj.sticky) throw new Error("RegExp /y flag is implied");
3849
+ if (obj.multiline) throw new Error("RegExp /m flag is implied");
3850
+ return obj.source;
3851
+ } else {
3852
+ throw new Error("Not a pattern: " + obj);
3853
+ }
3854
+ }
3855
+ function pad(s, length) {
3856
+ if (s.length > length) {
3857
+ return s;
3858
+ }
3859
+ return Array(length - s.length + 1).join(" ") + s;
3860
+ }
3861
+ function lastNLines(string2, numLines) {
3862
+ var position = string2.length;
3863
+ var lineBreaks = 0;
3864
+ while (true) {
3865
+ var idx = string2.lastIndexOf("\n", position - 1);
3866
+ if (idx === -1) {
3867
+ break;
3868
+ } else {
3869
+ lineBreaks++;
3870
+ }
3871
+ position = idx;
3872
+ if (lineBreaks === numLines) {
3873
+ break;
3874
+ }
3875
+ if (position === 0) {
3876
+ break;
3877
+ }
3878
+ }
3879
+ var startPosition = lineBreaks < numLines ? 0 : position + 1;
3880
+ return string2.substring(startPosition).split("\n");
3881
+ }
3882
+ function objectToRules(object) {
3883
+ var keys = Object.getOwnPropertyNames(object);
3884
+ var result = [];
3885
+ for (var i = 0; i < keys.length; i++) {
3886
+ var key = keys[i];
3887
+ var thing = object[key];
3888
+ var rules = [].concat(thing);
3889
+ if (key === "include") {
3890
+ for (var j = 0; j < rules.length; j++) {
3891
+ result.push({ include: rules[j] });
3892
+ }
3893
+ continue;
3894
+ }
3895
+ var match = [];
3896
+ rules.forEach(function(rule) {
3897
+ if (isObject(rule)) {
3898
+ if (match.length) result.push(ruleOptions(key, match));
3899
+ result.push(ruleOptions(key, rule));
3900
+ match = [];
3901
+ } else {
3902
+ match.push(rule);
3903
+ }
3904
+ });
3905
+ if (match.length) result.push(ruleOptions(key, match));
3906
+ }
3907
+ return result;
3908
+ }
3909
+ function arrayToRules(array) {
3910
+ var result = [];
3911
+ for (var i = 0; i < array.length; i++) {
3912
+ var obj = array[i];
3913
+ if (obj.include) {
3914
+ var include = [].concat(obj.include);
3915
+ for (var j = 0; j < include.length; j++) {
3916
+ result.push({ include: include[j] });
3917
+ }
3918
+ continue;
3919
+ }
3920
+ if (!obj.type) {
3921
+ throw new Error("Rule has no type: " + JSON.stringify(obj));
3922
+ }
3923
+ result.push(ruleOptions(obj.type, obj));
3924
+ }
3925
+ return result;
3926
+ }
3927
+ function ruleOptions(type, obj) {
3928
+ if (!isObject(obj)) {
3929
+ obj = { match: obj };
3930
+ }
3931
+ if (obj.include) {
3932
+ throw new Error("Matching rules cannot also include states");
3933
+ }
3934
+ var options = {
3935
+ defaultType: type,
3936
+ lineBreaks: !!obj.error || !!obj.fallback,
3937
+ pop: false,
3938
+ next: null,
3939
+ push: null,
3940
+ error: false,
3941
+ fallback: false,
3942
+ value: null,
3943
+ type: null,
3944
+ shouldThrow: false
3945
+ };
3946
+ for (var key in obj) {
3947
+ if (hasOwnProperty.call(obj, key)) {
3948
+ options[key] = obj[key];
3949
+ }
3950
+ }
3951
+ if (typeof options.type === "string" && type !== options.type) {
3952
+ throw new Error("Type transform cannot be a string (type '" + options.type + "' for token '" + type + "')");
3953
+ }
3954
+ var match = options.match;
3955
+ options.match = Array.isArray(match) ? match : match ? [match] : [];
3956
+ options.match.sort(function(a, b) {
3957
+ return isRegExp(a) && isRegExp(b) ? 0 : isRegExp(b) ? -1 : isRegExp(a) ? 1 : b.length - a.length;
3958
+ });
3959
+ return options;
3960
+ }
3961
+ function toRules(spec) {
3962
+ return Array.isArray(spec) ? arrayToRules(spec) : objectToRules(spec);
3963
+ }
3964
+ var defaultErrorRule = ruleOptions("error", { lineBreaks: true, shouldThrow: true });
3965
+ function compileRules(rules, hasStates) {
3966
+ var errorRule = null;
3967
+ var fast = /* @__PURE__ */ Object.create(null);
3968
+ var fastAllowed = true;
3969
+ var unicodeFlag = null;
3970
+ var groups = [];
3971
+ var parts = [];
3972
+ for (var i = 0; i < rules.length; i++) {
3973
+ if (rules[i].fallback) {
3974
+ fastAllowed = false;
3975
+ }
3976
+ }
3977
+ for (var i = 0; i < rules.length; i++) {
3978
+ var options = rules[i];
3979
+ if (options.include) {
3980
+ throw new Error("Inheritance is not allowed in stateless lexers");
3981
+ }
3982
+ if (options.error || options.fallback) {
3983
+ if (errorRule) {
3984
+ if (!options.fallback === !errorRule.fallback) {
3985
+ throw new Error("Multiple " + (options.fallback ? "fallback" : "error") + " rules not allowed (for token '" + options.defaultType + "')");
3986
+ } else {
3987
+ throw new Error("fallback and error are mutually exclusive (for token '" + options.defaultType + "')");
3988
+ }
3989
+ }
3990
+ errorRule = options;
3991
+ }
3992
+ var match = options.match.slice();
3993
+ if (fastAllowed) {
3994
+ while (match.length && typeof match[0] === "string" && match[0].length === 1) {
3995
+ var word = match.shift();
3996
+ fast[word.charCodeAt(0)] = options;
3997
+ }
3998
+ }
3999
+ if (options.pop || options.push || options.next) {
4000
+ if (!hasStates) {
4001
+ throw new Error("State-switching options are not allowed in stateless lexers (for token '" + options.defaultType + "')");
4002
+ }
4003
+ if (options.fallback) {
4004
+ throw new Error("State-switching options are not allowed on fallback tokens (for token '" + options.defaultType + "')");
4005
+ }
4006
+ }
4007
+ if (match.length === 0) {
4008
+ continue;
4009
+ }
4010
+ fastAllowed = false;
4011
+ groups.push(options);
4012
+ for (var j = 0; j < match.length; j++) {
4013
+ var obj = match[j];
4014
+ if (!isRegExp(obj)) {
4015
+ continue;
4016
+ }
4017
+ if (unicodeFlag === null) {
4018
+ unicodeFlag = obj.unicode;
4019
+ } else if (unicodeFlag !== obj.unicode && options.fallback === false) {
4020
+ throw new Error("If one rule is /u then all must be");
4021
+ }
4022
+ }
4023
+ var pat = reUnion(match.map(regexpOrLiteral));
4024
+ var regexp = new RegExp(pat);
4025
+ if (regexp.test("")) {
4026
+ throw new Error("RegExp matches empty string: " + regexp);
4027
+ }
4028
+ var groupCount = reGroups(pat);
4029
+ if (groupCount > 0) {
4030
+ throw new Error("RegExp has capture groups: " + regexp + "\nUse (?: \u2026 ) instead");
4031
+ }
4032
+ if (!options.lineBreaks && regexp.test("\n")) {
4033
+ throw new Error("Rule should declare lineBreaks: " + regexp);
4034
+ }
4035
+ parts.push(reCapture(pat));
4036
+ }
4037
+ var fallbackRule = errorRule && errorRule.fallback;
4038
+ var flags = hasSticky && !fallbackRule ? "ym" : "gm";
4039
+ var suffix = hasSticky || fallbackRule ? "" : "|";
4040
+ if (unicodeFlag === true) flags += "u";
4041
+ var combined = new RegExp(reUnion(parts) + suffix, flags);
4042
+ return { regexp: combined, groups, fast, error: errorRule || defaultErrorRule };
4043
+ }
4044
+ function compile(rules) {
4045
+ var result = compileRules(toRules(rules));
4046
+ return new Lexer({ start: result }, "start");
4047
+ }
4048
+ function checkStateGroup(g, name, map) {
4049
+ var state = g && (g.push || g.next);
4050
+ if (state && !map[state]) {
4051
+ throw new Error("Missing state '" + state + "' (in token '" + g.defaultType + "' of state '" + name + "')");
4052
+ }
4053
+ if (g && g.pop && +g.pop !== 1) {
4054
+ throw new Error("pop must be 1 (in token '" + g.defaultType + "' of state '" + name + "')");
4055
+ }
4056
+ }
4057
+ function compileStates(states, start) {
4058
+ var all = states.$all ? toRules(states.$all) : [];
4059
+ delete states.$all;
4060
+ var keys = Object.getOwnPropertyNames(states);
4061
+ if (!start) start = keys[0];
4062
+ var ruleMap = /* @__PURE__ */ Object.create(null);
4063
+ for (var i = 0; i < keys.length; i++) {
4064
+ var key = keys[i];
4065
+ ruleMap[key] = toRules(states[key]).concat(all);
4066
+ }
4067
+ for (var i = 0; i < keys.length; i++) {
4068
+ var key = keys[i];
4069
+ var rules = ruleMap[key];
4070
+ var included = /* @__PURE__ */ Object.create(null);
4071
+ for (var j = 0; j < rules.length; j++) {
4072
+ var rule = rules[j];
4073
+ if (!rule.include) continue;
4074
+ var splice = [j, 1];
4075
+ if (rule.include !== key && !included[rule.include]) {
4076
+ included[rule.include] = true;
4077
+ var newRules = ruleMap[rule.include];
4078
+ if (!newRules) {
4079
+ throw new Error("Cannot include nonexistent state '" + rule.include + "' (in state '" + key + "')");
4080
+ }
4081
+ for (var k = 0; k < newRules.length; k++) {
4082
+ var newRule = newRules[k];
4083
+ if (rules.indexOf(newRule) !== -1) continue;
4084
+ splice.push(newRule);
4085
+ }
4086
+ }
4087
+ rules.splice.apply(rules, splice);
4088
+ j--;
4089
+ }
4090
+ }
4091
+ var map = /* @__PURE__ */ Object.create(null);
4092
+ for (var i = 0; i < keys.length; i++) {
4093
+ var key = keys[i];
4094
+ map[key] = compileRules(ruleMap[key], true);
4095
+ }
4096
+ for (var i = 0; i < keys.length; i++) {
4097
+ var name = keys[i];
4098
+ var state = map[name];
4099
+ var groups = state.groups;
4100
+ for (var j = 0; j < groups.length; j++) {
4101
+ checkStateGroup(groups[j], name, map);
4102
+ }
4103
+ var fastKeys = Object.getOwnPropertyNames(state.fast);
4104
+ for (var j = 0; j < fastKeys.length; j++) {
4105
+ checkStateGroup(state.fast[fastKeys[j]], name, map);
4106
+ }
4107
+ }
4108
+ return new Lexer(map, start);
4109
+ }
4110
+ function keywordTransform(map) {
4111
+ var isMap = typeof Map !== "undefined";
4112
+ var reverseMap = isMap ? /* @__PURE__ */ new Map() : /* @__PURE__ */ Object.create(null);
4113
+ var types = Object.getOwnPropertyNames(map);
4114
+ for (var i = 0; i < types.length; i++) {
4115
+ var tokenType = types[i];
4116
+ var item = map[tokenType];
4117
+ var keywordList = Array.isArray(item) ? item : [item];
4118
+ keywordList.forEach(function(keyword) {
4119
+ if (typeof keyword !== "string") {
4120
+ throw new Error("keyword must be string (in keyword '" + tokenType + "')");
4121
+ }
4122
+ if (isMap) {
4123
+ reverseMap.set(keyword, tokenType);
4124
+ } else {
4125
+ reverseMap[keyword] = tokenType;
4126
+ }
4127
+ });
4128
+ }
4129
+ return function(k) {
4130
+ return isMap ? reverseMap.get(k) : reverseMap[k];
4131
+ };
4132
+ }
4133
+ var Lexer = function(states, state) {
4134
+ this.startState = state;
4135
+ this.states = states;
4136
+ this.buffer = "";
4137
+ this.stack = [];
4138
+ this.reset();
4139
+ };
4140
+ Lexer.prototype.reset = function(data, info) {
4141
+ this.buffer = data || "";
4142
+ this.index = 0;
4143
+ this.line = info ? info.line : 1;
4144
+ this.col = info ? info.col : 1;
4145
+ this.queuedToken = info ? info.queuedToken : null;
4146
+ this.queuedText = info ? info.queuedText : "";
4147
+ this.queuedThrow = info ? info.queuedThrow : null;
4148
+ this.setState(info ? info.state : this.startState);
4149
+ this.stack = info && info.stack ? info.stack.slice() : [];
4150
+ return this;
4151
+ };
4152
+ Lexer.prototype.save = function() {
4153
+ return {
4154
+ line: this.line,
4155
+ col: this.col,
4156
+ state: this.state,
4157
+ stack: this.stack.slice(),
4158
+ queuedToken: this.queuedToken,
4159
+ queuedText: this.queuedText,
4160
+ queuedThrow: this.queuedThrow
4161
+ };
4162
+ };
4163
+ Lexer.prototype.setState = function(state) {
4164
+ if (!state || this.state === state) return;
4165
+ this.state = state;
4166
+ var info = this.states[state];
4167
+ this.groups = info.groups;
4168
+ this.error = info.error;
4169
+ this.re = info.regexp;
4170
+ this.fast = info.fast;
4171
+ };
4172
+ Lexer.prototype.popState = function() {
4173
+ this.setState(this.stack.pop());
4174
+ };
4175
+ Lexer.prototype.pushState = function(state) {
4176
+ this.stack.push(this.state);
4177
+ this.setState(state);
4178
+ };
4179
+ var eat = hasSticky ? function(re, buffer) {
4180
+ return re.exec(buffer);
4181
+ } : function(re, buffer) {
4182
+ var match = re.exec(buffer);
4183
+ if (match[0].length === 0) {
4184
+ return null;
4185
+ }
4186
+ return match;
4187
+ };
4188
+ Lexer.prototype._getGroup = function(match) {
4189
+ var groupCount = this.groups.length;
4190
+ for (var i = 0; i < groupCount; i++) {
4191
+ if (match[i + 1] !== void 0) {
4192
+ return this.groups[i];
4193
+ }
4194
+ }
4195
+ throw new Error("Cannot find token type for matched text");
4196
+ };
4197
+ function tokenToString() {
4198
+ return this.value;
4199
+ }
4200
+ Lexer.prototype.next = function() {
4201
+ var index = this.index;
4202
+ if (this.queuedGroup) {
4203
+ var token = this._token(this.queuedGroup, this.queuedText, index);
4204
+ this.queuedGroup = null;
4205
+ this.queuedText = "";
4206
+ return token;
4207
+ }
4208
+ var buffer = this.buffer;
4209
+ if (index === buffer.length) {
4210
+ return;
4211
+ }
4212
+ var group = this.fast[buffer.charCodeAt(index)];
4213
+ if (group) {
4214
+ return this._token(group, buffer.charAt(index), index);
4215
+ }
4216
+ var re = this.re;
4217
+ re.lastIndex = index;
4218
+ var match = eat(re, buffer);
4219
+ var error = this.error;
4220
+ if (match == null) {
4221
+ return this._token(error, buffer.slice(index, buffer.length), index);
4222
+ }
4223
+ var group = this._getGroup(match);
4224
+ var text = match[0];
4225
+ if (error.fallback && match.index !== index) {
4226
+ this.queuedGroup = group;
4227
+ this.queuedText = text;
4228
+ return this._token(error, buffer.slice(index, match.index), index);
4229
+ }
4230
+ return this._token(group, text, index);
4231
+ };
4232
+ Lexer.prototype._token = function(group, text, offset) {
4233
+ var lineBreaks = 0;
4234
+ if (group.lineBreaks) {
4235
+ var matchNL = /\n/g;
4236
+ var nl = 1;
4237
+ if (text === "\n") {
4238
+ lineBreaks = 1;
4239
+ } else {
4240
+ while (matchNL.exec(text)) {
4241
+ lineBreaks++;
4242
+ nl = matchNL.lastIndex;
4243
+ }
4244
+ }
4245
+ }
4246
+ var token = {
4247
+ type: typeof group.type === "function" && group.type(text) || group.defaultType,
4248
+ value: typeof group.value === "function" ? group.value(text) : text,
4249
+ text,
4250
+ toString: tokenToString,
4251
+ offset,
4252
+ lineBreaks,
4253
+ line: this.line,
4254
+ col: this.col
4255
+ };
4256
+ var size = text.length;
4257
+ this.index += size;
4258
+ this.line += lineBreaks;
4259
+ if (lineBreaks !== 0) {
4260
+ this.col = size - nl + 1;
4261
+ } else {
4262
+ this.col += size;
4263
+ }
4264
+ if (group.shouldThrow) {
4265
+ var err = new Error(this.formatError(token, "invalid syntax"));
4266
+ throw err;
4267
+ }
4268
+ if (group.pop) this.popState();
4269
+ else if (group.push) this.pushState(group.push);
4270
+ else if (group.next) this.setState(group.next);
4271
+ return token;
4272
+ };
4273
+ if (typeof Symbol !== "undefined" && Symbol.iterator) {
4274
+ var LexerIterator = function(lexer) {
4275
+ this.lexer = lexer;
4276
+ };
4277
+ LexerIterator.prototype.next = function() {
4278
+ var token = this.lexer.next();
4279
+ return { value: token, done: !token };
4280
+ };
4281
+ LexerIterator.prototype[Symbol.iterator] = function() {
4282
+ return this;
4283
+ };
4284
+ Lexer.prototype[Symbol.iterator] = function() {
4285
+ return new LexerIterator(this);
4286
+ };
4287
+ }
4288
+ Lexer.prototype.formatError = function(token, message) {
4289
+ if (token == null) {
4290
+ var text = this.buffer.slice(this.index);
4291
+ var token = {
4292
+ text,
4293
+ offset: this.index,
4294
+ lineBreaks: text.indexOf("\n") === -1 ? 0 : 1,
4295
+ line: this.line,
4296
+ col: this.col
4297
+ };
4298
+ }
4299
+ var numLinesAround = 2;
4300
+ var firstDisplayedLine = Math.max(token.line - numLinesAround, 1);
4301
+ var lastDisplayedLine = token.line + numLinesAround;
4302
+ var lastLineDigits = String(lastDisplayedLine).length;
4303
+ var displayedLines = lastNLines(
4304
+ this.buffer,
4305
+ this.line - token.line + numLinesAround + 1
4306
+ ).slice(0, 5);
4307
+ var errorLines = [];
4308
+ errorLines.push(message + " at line " + token.line + " col " + token.col + ":");
4309
+ errorLines.push("");
4310
+ for (var i = 0; i < displayedLines.length; i++) {
4311
+ var line = displayedLines[i];
4312
+ var lineNo = firstDisplayedLine + i;
4313
+ errorLines.push(pad(String(lineNo), lastLineDigits) + " " + line);
4314
+ if (lineNo === token.line) {
4315
+ errorLines.push(pad("", lastLineDigits + token.col + 1) + "^");
4316
+ }
4317
+ }
4318
+ return errorLines.join("\n");
4319
+ };
4320
+ Lexer.prototype.clone = function() {
4321
+ return new Lexer(this.states, this.state);
4322
+ };
4323
+ Lexer.prototype.has = function(tokenType) {
4324
+ return true;
4325
+ };
4326
+ return {
4327
+ compile,
4328
+ states: compileStates,
4329
+ error: Object.freeze({ error: true }),
4330
+ fallback: Object.freeze({ fallback: true }),
4331
+ keywords: keywordTransform
4332
+ };
4333
+ });
4334
+ }
4335
+ });
4336
+
4337
+ // ../../node_modules/moo-ignore/index.js
4338
+ var require_moo_ignore = __commonJS({
4339
+ "../../node_modules/moo-ignore/index.js"(exports, module) {
4340
+ var moo2 = require_moo();
4341
+ function makeLexer2(tokens, ignoreTokens, options = {}) {
4342
+ let lexer;
4343
+ let oldnext;
4344
+ let newTokens = {};
4345
+ lexer = moo2.compile(tokens);
4346
+ oldnext = lexer.next;
4347
+ lexer.ignore = function(...types) {
4348
+ if (this.ignoreSet) {
4349
+ this.ignoreSet = /* @__PURE__ */ new Set([...this.ignoreSet, ...types]);
4350
+ } else this.ignoreSet = new Set(types);
4351
+ };
4352
+ lexer.next = function() {
4353
+ while (true) {
4354
+ let token = oldnext.call(this);
4355
+ if (token == void 0 || !this.ignoreSet.has(token.type)) {
4356
+ return token;
4357
+ }
4358
+ }
4359
+ };
4360
+ if (options.eof) {
4361
+ let oldReset = lexer.reset;
4362
+ lexer.reset = function(input) {
4363
+ if (tokens.EOF) input += tokens.EOF;
4364
+ return oldReset.call(this, input);
4365
+ };
4366
+ }
4367
+ if (ignoreTokens) {
4368
+ lexer.ignoreSet = new Set(ignoreTokens);
4369
+ }
4370
+ return lexer;
4371
+ }
4372
+ module.exports = {
4373
+ /**
4374
+ * The lexer constructor
4375
+ */
4376
+ makeLexer: makeLexer2,
4377
+ /**
4378
+ * The moo object (as built in `const moo = require("moo")`)
4379
+ */
4380
+ moo: moo2
4381
+ };
4382
+ }
4383
+ });
4384
+
4385
+ // src/parser/lexer.ts
4386
+ var lexer_exports = {};
4387
+ __export(lexer_exports, {
4388
+ PrologLexer: () => PrologLexer,
4389
+ PrologLexerConfig: () => PrologLexerConfig
4390
+ });
4391
+ var import_moo_ignore, import_moo, PrologLexerConfig, PrologLexer;
4392
+ var init_lexer = __esm({
4393
+ "src/parser/lexer.ts"() {
4394
+ import_moo_ignore = __toESM(require_moo_ignore(), 1);
4395
+ import_moo = __toESM(require_moo(), 1);
4396
+ PrologLexerConfig = {
4397
+ WS: /[ \t]+/,
4398
+ wildcard: "_",
4399
+ notOperator: { match: ["\\+", "not"] },
4400
+ forallRule: "forall",
4401
+ findallRule: "findall",
4402
+ comment: /%.*|\/\*[\s\S]*?\*\//,
4403
+ number: /\b(?:[0-9]+(?:\.[0-9]+(?:e[+-]?[0-9]+)?)?|0o[0-7]+|0x[0-9a-fA-F]+|0b[01]+)\b/,
4404
+ string: /(?:'(?:[^']|'')*'|"(?:[^"]|"")*")/,
4405
+ backtick: "`",
4406
+ lparen: "(",
4407
+ rparen: ")",
4408
+ lbracket: "{",
4409
+ rbracket: "}",
4410
+ lsquare: "[",
4411
+ rsquare: "]",
4412
+ comma: ",",
4413
+ arrow: "->",
4414
+ period: ".",
4415
+ semicolon: ";",
4416
+ colonDash: ":-",
4417
+ colon: ":",
4418
+ consOp: "|",
4419
+ queryOp: "?-",
4420
+ comparisonOp: /@<|@=<|@>=|@>|<|=<|>=|>|=@=|\\=@=|=:=|=\\=|==|\\==|\\=|=/,
4421
+ op: /\+|-|\*|\/|\/\/|~|\^|\?|\$|''|\.\./,
4422
+ variable: /[A-Z][a-zA-Z0-9_\u00C0-\u00FF]*/,
4423
+ atom: {
4424
+ match: /[a-z!][a-zA-Z0-9_\u00C0-\u00FF]*/,
4425
+ type: import_moo.default.keywords({
4426
+ primitiveOperator: ["round", "abs", "sqrt", "call", "max", "assertion"],
4427
+ testKeyword: ["test"]
4428
+ })
4429
+ },
4430
+ NL: { match: /\r?\n/, lineBreaks: true }
4431
+ };
4432
+ PrologLexer = (0, import_moo_ignore.makeLexer)(PrologLexerConfig, ["comment", "NL"]);
4433
+ }
4434
+ });
4435
+
4436
+ // src/parser/grammar.cjs
4437
+ var require_grammar = __commonJS({
4438
+ "src/parser/grammar.cjs"(exports, module) {
4439
+ (function() {
4440
+ function id(x) {
4441
+ return x[0];
4442
+ }
4443
+ const {
4444
+ NumberPrimitive: NumberPrimitive2,
4445
+ BooleanPrimitive: BooleanPrimitive2,
4446
+ StringPrimitive: StringPrimitive2,
4447
+ Rule: Rule2,
4448
+ Fact: Fact2,
4449
+ Query: Query2,
4450
+ ListPrimitive: ListPrimitive2,
4451
+ ConsExpression: ConsExpression2,
4452
+ ArithmeticBinaryOperation: ArithmeticBinaryOperation2,
4453
+ ArithmeticUnaryOperation: ArithmeticUnaryOperation2,
4454
+ ComparisonOperation: ComparisonOperation2,
4455
+ Exist: Exist2,
4456
+ Not: Not2,
4457
+ Findall: Findall2,
4458
+ Sequence: Sequence2,
4459
+ UnguardedBody: UnguardedBody2,
4460
+ Equation: Equation2,
4461
+ If: If2,
4462
+ Call: Call2,
4463
+ Forall: Forall2,
4464
+ SymbolPrimitive: SymbolPrimitive2,
4465
+ AssignOperation: AssignOperation2,
4466
+ UnifyOperation: UnifyOperation2,
4467
+ VariablePattern: VariablePattern2,
4468
+ FunctorPattern: FunctorPattern2,
4469
+ ConsPattern: ConsPattern2,
4470
+ ListPattern: ListPattern2,
4471
+ LogicConstraint: LogicConstraint2,
4472
+ LiteralPattern: LiteralPattern2,
4473
+ WildcardPattern: WildcardPattern2,
4474
+ TuplePattern: TuplePattern2,
4475
+ Test: Test2,
4476
+ Assert: Assert2,
4477
+ Truth: Truth2
4478
+ } = (init_dist(), __toCommonJS(dist_exports));
4479
+ const { PrologLexer: PrologLexer2 } = (init_lexer(), __toCommonJS(lexer_exports));
4480
+ const asSequence = (d) => {
4481
+ if (d instanceof Sequence2) return d;
4482
+ if (Array.isArray(d)) return d.length === 1 ? d[0] : new Sequence2(d);
4483
+ return new Sequence2([d]);
4484
+ };
4485
+ var grammar2 = {
4486
+ Lexer: PrologLexer2,
4487
+ ParserRules: [
4488
+ { "name": "program$ebnf$1", "symbols": [] },
4489
+ { "name": "program$ebnf$1$subexpression$1", "symbols": ["clause", "_"] },
4490
+ { "name": "program$ebnf$1", "symbols": ["program$ebnf$1", "program$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
4491
+ return d[0].concat([d[1]]);
4492
+ } },
4493
+ { "name": "program", "symbols": ["_", "program$ebnf$1"], "postprocess": (d) => d[1].map((x) => x[0]).filter((x) => x !== null).flat(Infinity) },
4494
+ { "name": "clause$subexpression$1", "symbols": ["fact"] },
4495
+ { "name": "clause$subexpression$1", "symbols": ["rule"] },
4496
+ { "name": "clause$subexpression$1", "symbols": ["query"] },
4497
+ { "name": "clause$subexpression$1", "symbols": ["test_rule"] },
4498
+ { "name": "clause", "symbols": ["clause$subexpression$1"], "postprocess": (d) => d[0][0] },
4499
+ { "name": "fact$ebnf$1", "symbols": ["arguments"], "postprocess": id },
4500
+ { "name": "fact$ebnf$1", "symbols": [], "postprocess": function(d) {
4501
+ return null;
4502
+ } },
4503
+ { "name": "fact", "symbols": ["any_atom", "fact$ebnf$1", "_", PrologLexer2.has("period") ? { type: "period" } : period], "postprocess": (d) => new Fact2(d[0], d[1] ?? []) },
4504
+ { "name": "rule", "symbols": ["any_atom", "equation", "_", PrologLexer2.has("period") ? { type: "period" } : period], "postprocess": (d) => new Rule2(d[0], [d[1]]) },
4505
+ { "name": "test_rule$ebnf$1", "symbols": ["test_args"], "postprocess": id },
4506
+ { "name": "test_rule$ebnf$1", "symbols": [], "postprocess": function(d) {
4507
+ return null;
4508
+ } },
4509
+ { "name": "test_rule$subexpression$1", "symbols": [PrologLexer2.has("colonDash") ? { type: "colonDash" } : colonDash] },
4510
+ { "name": "test_rule$subexpression$1", "symbols": [PrologLexer2.has("colon") ? { type: "colon" } : colon] },
4511
+ { "name": "test_rule", "symbols": [PrologLexer2.has("testKeyword") ? { type: "testKeyword" } : testKeyword, PrologLexer2.has("lparen") ? { type: "lparen" } : lparen, "_", "structural_literal", "test_rule$ebnf$1", "_", PrologLexer2.has("rparen") ? { type: "rparen" } : rparen, "_", "test_rule$subexpression$1", "_", "body", "_", PrologLexer2.has("period") ? { type: "period" } : period], "postprocess": (d) => new Test2(d[3], new Sequence2(d[10]), d[4] ? [d[4]] : []) },
4512
+ { "name": "test_args", "symbols": ["_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "pattern"], "postprocess": (d) => d[3] },
4513
+ { "name": "equation$ebnf$1", "symbols": ["arguments"], "postprocess": id },
4514
+ { "name": "equation$ebnf$1", "symbols": [], "postprocess": function(d) {
4515
+ return null;
4516
+ } },
4517
+ { "name": "equation", "symbols": ["equation$ebnf$1", "_", PrologLexer2.has("colonDash") ? { type: "colonDash" } : colonDash, "_", "body"], "postprocess": (d) => new Equation2(d[0] || [], new UnguardedBody2(new Sequence2(d[4]))) },
4518
+ { "name": "query", "symbols": [PrologLexer2.has("queryOp") ? { type: "queryOp" } : queryOp, "_", "body", "_", PrologLexer2.has("period") ? { type: "period" } : period], "postprocess": (d) => new Query2(d[2]) },
4519
+ { "name": "body$ebnf$1", "symbols": [] },
4520
+ { "name": "body$ebnf$1$subexpression$1$subexpression$1", "symbols": [PrologLexer2.has("comma") ? { type: "comma" } : comma] },
4521
+ { "name": "body$ebnf$1$subexpression$1$subexpression$1", "symbols": [PrologLexer2.has("semicolon") ? { type: "semicolon" } : semicolon] },
4522
+ { "name": "body$ebnf$1$subexpression$1", "symbols": ["_", "body$ebnf$1$subexpression$1$subexpression$1", "_", "expression"] },
4523
+ { "name": "body$ebnf$1", "symbols": ["body$ebnf$1", "body$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
4524
+ return d[0].concat([d[1]]);
4525
+ } },
4526
+ { "name": "body", "symbols": ["expression", "body$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map((x) => x[3])] },
4527
+ { "name": "expression$subexpression$1", "symbols": ["conditional"] },
4528
+ { "name": "expression$subexpression$1", "symbols": ["forall"] },
4529
+ { "name": "expression$subexpression$1", "symbols": ["findall"] },
4530
+ { "name": "expression$subexpression$1", "symbols": ["unification"] },
4531
+ { "name": "expression$subexpression$1", "symbols": ["assignment"] },
4532
+ { "name": "expression$subexpression$1", "symbols": ["comparison"] },
4533
+ { "name": "expression$subexpression$1", "symbols": ["not"] },
4534
+ { "name": "expression$subexpression$1", "symbols": ["exist"] },
4535
+ { "name": "expression$subexpression$1", "symbols": ["assertion"] },
4536
+ { "name": "expression", "symbols": ["expression$subexpression$1"], "postprocess": (d) => d[0][0] },
4537
+ { "name": "expression", "symbols": [{ "literal": "(" }, "_", "body", "_", { "literal": ")" }], "postprocess": (d) => new Sequence2(d[2]) },
4538
+ {
4539
+ "name": "conditional",
4540
+ "symbols": [{ "literal": "(" }, "_", "body", "_", { "literal": "->" }, "_", "body", "_", PrologLexer2.has("semicolon") ? { type: "semicolon" } : semicolon, "_", "body", "_", { "literal": ")" }],
4541
+ "postprocess": (d) => new If2(
4542
+ asSequence(d[2]),
4543
+ asSequence(d[6]),
4544
+ asSequence(d[10])
4545
+ )
4546
+ },
4547
+ { "name": "forall", "symbols": [PrologLexer2.has("forallRule") ? { type: "forallRule" } : forallRule, { "literal": "(" }, "_", "expression", "_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "expression", "_", { "literal": ")" }], "postprocess": (d) => new Forall2(d[3], d[7]) },
4548
+ { "name": "findall", "symbols": [PrologLexer2.has("findallRule") ? { type: "findallRule" } : findallRule, { "literal": "(" }, "_", "pattern", "_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "expression", "_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "pattern", "_", { "literal": ")" }], "postprocess": (d) => new Findall2(d[3], d[7], d[11]) },
4549
+ { "name": "not", "symbols": [{ "literal": "not" }, { "literal": "(" }, "_", "expression", "_", { "literal": ")" }], "postprocess": (d) => new Not2(asSequence(d[3])) },
4550
+ { "name": "not", "symbols": [{ "literal": "\\+" }, "_", "expression"], "postprocess": (d) => new Not2(d[2]) },
4551
+ { "name": "exist", "symbols": [{ "literal": "call" }, PrologLexer2.has("lparen") ? { type: "lparen" } : lparen, "_", "pattern_list", "_", PrologLexer2.has("rparen") ? { type: "rparen" } : rparen], "postprocess": (d) => {
4552
+ const [callee, ...rest] = d[3];
4553
+ return new Call2(callee.name, rest);
4554
+ } },
4555
+ { "name": "exist$ebnf$1", "symbols": ["arguments"], "postprocess": id },
4556
+ { "name": "exist$ebnf$1", "symbols": [], "postprocess": function(d) {
4557
+ return null;
4558
+ } },
4559
+ { "name": "exist", "symbols": ["any_atom", "exist$ebnf$1"], "postprocess": (d, l, reject) => {
4560
+ const val = d[0].value;
4561
+ if (["not", "\\+", "call", "assertion"].includes(val)) return reject;
4562
+ return new Exist2(d[0], d[1] ?? []);
4563
+ } },
4564
+ { "name": "exist", "symbols": ["variable"], "postprocess": (d) => new Exist2(d[0], []) },
4565
+ {
4566
+ "name": "assertion",
4567
+ "symbols": [{ "literal": "assertion" }, PrologLexer2.has("lparen") ? { type: "lparen" } : lparen, "_", "expression", "_", PrologLexer2.has("rparen") ? { type: "rparen" } : rparen],
4568
+ "postprocess": (d) => new Assert2(new BooleanPrimitive2(false), new Truth2(asSequence(d[3])))
4569
+ },
4570
+ {
4571
+ "name": "assignment",
4572
+ "symbols": ["addition", "_", { "literal": "is" }, "_", "addition"],
4573
+ "postprocess": (d) => new LogicConstraint2(new AssignOperation2("Assign", d[0], d[4]))
4574
+ },
4575
+ { "name": "unification", "symbols": ["addition", "_", { "literal": "=" }, "_", "addition"], "postprocess": (d) => new LogicConstraint2(new UnifyOperation2("Unify", d[0], d[4])) },
4576
+ {
4577
+ "name": "comparison",
4578
+ "symbols": ["addition", "_", "comparison_op", "_", "addition"],
4579
+ "postprocess": (d) => new LogicConstraint2(new ComparisonOperation2(d[2], d[0], d[4]))
4580
+ },
4581
+ { "name": "addition", "symbols": ["multiplication", "_", { "literal": "+" }, "_", "addition"], "postprocess": (d) => new ArithmeticBinaryOperation2("Plus", d[0], d[4]) },
4582
+ { "name": "addition", "symbols": ["multiplication", "_", { "literal": "-" }, "_", "addition"], "postprocess": (d) => new ArithmeticBinaryOperation2("Minus", d[0], d[4]) },
4583
+ { "name": "addition", "symbols": ["multiplication"], "postprocess": id },
4584
+ { "name": "multiplication", "symbols": ["primary", "_", { "literal": "*" }, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation2("Multiply", d[0], d[4]) },
4585
+ { "name": "multiplication", "symbols": ["primary", "_", { "literal": "/" }, "_", "multiplication"], "postprocess": (d) => new ArithmeticBinaryOperation2("Divide", d[0], d[4]) },
4586
+ { "name": "multiplication", "symbols": ["primary"], "postprocess": id },
4587
+ { "name": "primary", "symbols": ["arithmetic_literal"], "postprocess": id },
4588
+ { "name": "primary", "symbols": ["variable"], "postprocess": id },
4589
+ { "name": "primary", "symbols": [{ "literal": "-" }, "_", "primary"], "postprocess": (d) => new ArithmeticUnaryOperation2("Negation", d[2]) },
4590
+ { "name": "primary", "symbols": ["strict_atom", "arguments"], "postprocess": (d, l, reject) => {
4591
+ const val = d[0].value;
4592
+ if (["abs", "round", "sqrt", "max", "assertion"].includes(val)) return reject;
4593
+ return new Exist2(d[0], d[1] ?? []);
4594
+ } },
4595
+ { "name": "primary", "symbols": ["primitiveOperation"], "postprocess": id },
4596
+ { "name": "primary", "symbols": ["cons_expr"], "postprocess": id },
4597
+ { "name": "primary", "symbols": ["list_expr"], "postprocess": id },
4598
+ { "name": "primary", "symbols": [{ "literal": "(" }, "_", "addition", "_", { "literal": ")" }], "postprocess": (d) => d[2] },
4599
+ { "name": "list_expr$ebnf$1", "symbols": ["primary_list"], "postprocess": id },
4600
+ { "name": "list_expr$ebnf$1", "symbols": [], "postprocess": function(d) {
4601
+ return null;
4602
+ } },
4603
+ { "name": "list_expr", "symbols": [{ "literal": "[" }, "_", "list_expr$ebnf$1", "_", { "literal": "]" }], "postprocess": (d) => new ListPrimitive2(d[2] || []) },
4604
+ { "name": "cons_expr", "symbols": [{ "literal": "[" }, "_", "primary_list", "_", PrologLexer2.has("consOp") ? { type: "consOp" } : consOp, "_", "addition", "_", { "literal": "]" }], "postprocess": (d) => {
4605
+ const heads = d[2];
4606
+ const tail = d[6];
4607
+ let current = tail;
4608
+ for (let i = heads.length - 1; i >= 0; i--) {
4609
+ current = new ConsExpression2(heads[i], current);
4610
+ }
4611
+ return current;
4612
+ } },
4613
+ { "name": "primitiveOperation", "symbols": [{ "literal": "round" }, "__", "addition"], "postprocess": (d) => new ArithmeticUnaryOperation2("Round", d[2]) },
4614
+ { "name": "primitiveOperation", "symbols": [{ "literal": "abs" }, "__", "addition"], "postprocess": (d) => new ArithmeticUnaryOperation2("Absolute", d[2]) },
4615
+ { "name": "primitiveOperation", "symbols": [{ "literal": "sqrt" }, "__", "addition"], "postprocess": (d) => new ArithmeticUnaryOperation2("Sqrt", d[2]) },
4616
+ { "name": "primitiveOperation", "symbols": [{ "literal": "max" }, { "literal": "(" }, "_", "addition", "_", { "literal": "," }, "_", "addition", "_", { "literal": ")" }], "postprocess": (d) => new ArithmeticBinaryOperation2("Max", d[3], d[7]) },
4617
+ { "name": "primitiveArguments", "symbols": [PrologLexer2.has("lparen") ? { type: "lparen" } : lparen, "_", "primary_list", "_", PrologLexer2.has("rparen") ? { type: "rparen" } : rparen], "postprocess": (d) => d[2] },
4618
+ { "name": "primary_list$ebnf$1", "symbols": [] },
4619
+ { "name": "primary_list$ebnf$1$subexpression$1", "symbols": ["_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "addition"] },
4620
+ { "name": "primary_list$ebnf$1", "symbols": ["primary_list$ebnf$1", "primary_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
4621
+ return d[0].concat([d[1]]);
4622
+ } },
4623
+ { "name": "primary_list", "symbols": ["addition", "primary_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map((x) => x[3])] },
4624
+ { "name": "arguments", "symbols": [PrologLexer2.has("lparen") ? { type: "lparen" } : lparen, "_", "pattern_list", "_", PrologLexer2.has("rparen") ? { type: "rparen" } : rparen], "postprocess": (d) => d[2] },
4625
+ { "name": "pattern_list$ebnf$1", "symbols": [] },
4626
+ { "name": "pattern_list$ebnf$1$subexpression$1", "symbols": ["_", PrologLexer2.has("comma") ? { type: "comma" } : comma, "_", "pattern"] },
4627
+ { "name": "pattern_list$ebnf$1", "symbols": ["pattern_list$ebnf$1", "pattern_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
4628
+ return d[0].concat([d[1]]);
4629
+ } },
4630
+ { "name": "pattern_list", "symbols": ["pattern", "pattern_list$ebnf$1"], "postprocess": (d) => [d[0], ...d[1].map((x) => x[3])] },
4631
+ { "name": "pattern", "symbols": ["infix_pattern"], "postprocess": id },
4632
+ { "name": "pattern", "symbols": ["primary_pattern"], "postprocess": id },
4633
+ { "name": "primary_pattern", "symbols": ["variable"], "postprocess": (d) => new VariablePattern2(d[0]) },
4634
+ { "name": "primary_pattern", "symbols": ["structural_literal"], "postprocess": (d) => new LiteralPattern2(d[0]) },
4635
+ { "name": "primary_pattern", "symbols": [PrologLexer2.has("wildcard") ? { type: "wildcard" } : wildcard], "postprocess": (d) => new WildcardPattern2() },
4636
+ { "name": "primary_pattern", "symbols": ["any_atom", "arguments"], "postprocess": (d) => new FunctorPattern2(d[0], d[1]) },
4637
+ { "name": "primary_pattern", "symbols": [{ "literal": "(" }, "_", "pattern_list", "_", { "literal": ")" }], "postprocess": (d) => new TuplePattern2(d[2]) },
4638
+ { "name": "primary_pattern", "symbols": [{ "literal": "[" }, "_", "pattern_list", "_", PrologLexer2.has("consOp") ? { type: "consOp" } : consOp, "_", "pattern", "_", { "literal": "]" }], "postprocess": (d) => {
4639
+ const heads = d[2];
4640
+ const tail = d[6];
4641
+ let current = tail;
4642
+ for (let i = heads.length - 1; i >= 0; i--) {
4643
+ current = new ConsPattern2(heads[i], current);
4644
+ }
4645
+ return current;
4646
+ } },
4647
+ { "name": "primary_pattern$ebnf$1", "symbols": ["pattern_list"], "postprocess": id },
4648
+ { "name": "primary_pattern$ebnf$1", "symbols": [], "postprocess": function(d) {
4649
+ return null;
4650
+ } },
4651
+ { "name": "primary_pattern", "symbols": [{ "literal": "[" }, "_", "primary_pattern$ebnf$1", "_", { "literal": "]" }], "postprocess": (d) => new ListPattern2(d[2] ? d[2] : []) },
4652
+ { "name": "infix_pattern", "symbols": ["primary_pattern", "_", "any_atom", "_", "pattern"], "postprocess": (d) => new FunctorPattern2(d[2], [d[0], d[4]]) },
4653
+ { "name": "variable", "symbols": [PrologLexer2.has("variable") ? { type: "variable" } : variable], "postprocess": (d) => new SymbolPrimitive2(d[0].value) },
4654
+ { "name": "strict_atom", "symbols": [PrologLexer2.has("atom") ? { type: "atom" } : atom], "postprocess": (d) => new SymbolPrimitive2(d[0].value) },
4655
+ { "name": "strict_atom", "symbols": [PrologLexer2.has("primitiveOperator") ? { type: "primitiveOperator" } : primitiveOperator], "postprocess": (d) => new SymbolPrimitive2(d[0].value) },
4656
+ { "name": "any_atom", "symbols": ["strict_atom"], "postprocess": id },
4657
+ { "name": "any_atom$subexpression$1", "symbols": [PrologLexer2.has("op") ? { type: "op" } : op] },
4658
+ { "name": "any_atom$subexpression$1", "symbols": [PrologLexer2.has("comparisonOp") ? { type: "comparisonOp" } : comparisonOp] },
4659
+ { "name": "any_atom", "symbols": ["any_atom$subexpression$1"], "postprocess": (d) => new SymbolPrimitive2(d[0][0].value) },
4660
+ { "name": "arithmetic_literal", "symbols": ["strict_atom"], "postprocess": id },
4661
+ { "name": "arithmetic_literal", "symbols": [PrologLexer2.has("number") ? { type: "number" } : number], "postprocess": (d) => new NumberPrimitive2(Number(d[0].value)) },
4662
+ { "name": "arithmetic_literal", "symbols": [PrologLexer2.has("string") ? { type: "string" } : string], "postprocess": (d) => new StringPrimitive2(d[0].value) },
4663
+ { "name": "structural_literal", "symbols": ["any_atom"], "postprocess": id },
4664
+ { "name": "structural_literal", "symbols": [PrologLexer2.has("number") ? { type: "number" } : number], "postprocess": (d) => new NumberPrimitive2(Number(d[0].value)) },
4665
+ { "name": "structural_literal", "symbols": [PrologLexer2.has("string") ? { type: "string" } : string], "postprocess": (d) => new StringPrimitive2(d[0].value) },
4666
+ { "name": "comparison_op", "symbols": [{ "literal": "=:=" }], "postprocess": (d) => "Equal" },
4667
+ { "name": "comparison_op", "symbols": [{ "literal": "=\\=" }], "postprocess": (d) => "NotEqual" },
4668
+ { "name": "comparison_op", "symbols": [{ "literal": "==" }], "postprocess": (d) => "Same" },
4669
+ { "name": "comparison_op", "symbols": [{ "literal": "\\==" }], "postprocess": (d) => "NotSame" },
4670
+ { "name": "comparison_op", "symbols": [{ "literal": "\\=" }], "postprocess": (d) => "NotSame" },
4671
+ { "name": "comparison_op", "symbols": [{ "literal": "@<" }], "postprocess": (d) => "LessThan" },
4672
+ { "name": "comparison_op", "symbols": [{ "literal": "@=<" }], "postprocess": (d) => "LessOrEqualThan" },
4673
+ { "name": "comparison_op", "symbols": [{ "literal": "@>" }], "postprocess": (d) => "GreaterThan" },
4674
+ { "name": "comparison_op", "symbols": [{ "literal": "@>=" }], "postprocess": (d) => "GreaterOrEqualThan" },
4675
+ { "name": "comparison_op", "symbols": [{ "literal": "<" }], "postprocess": (d) => "LessThan" },
4676
+ { "name": "comparison_op", "symbols": [{ "literal": "=<" }], "postprocess": (d) => "LessOrEqualThan" },
4677
+ { "name": "comparison_op", "symbols": [{ "literal": ">" }], "postprocess": (d) => "GreaterThan" },
4678
+ { "name": "comparison_op", "symbols": [{ "literal": ">=" }], "postprocess": (d) => "GreaterOrEqualThan" },
4679
+ { "name": "comparison_op", "symbols": [{ "literal": "=@=" }], "postprocess": (d) => "Same" },
4680
+ { "name": "comparison_op", "symbols": [{ "literal": "\\=@=" }], "postprocess": (d) => "NotSame" },
4681
+ { "name": "_$ebnf$1", "symbols": [] },
4682
+ { "name": "_$ebnf$1", "symbols": ["_$ebnf$1", PrologLexer2.has("WS") ? { type: "WS" } : WS], "postprocess": function arrpush(d) {
4683
+ return d[0].concat([d[1]]);
4684
+ } },
4685
+ { "name": "_", "symbols": ["_$ebnf$1"] },
4686
+ { "name": "__$ebnf$1", "symbols": [PrologLexer2.has("WS") ? { type: "WS" } : WS], "postprocess": id },
4687
+ { "name": "__$ebnf$1", "symbols": [], "postprocess": function(d) {
4688
+ return null;
4689
+ } },
4690
+ { "name": "__", "symbols": ["__$ebnf$1"] }
4691
+ ],
4692
+ ParserStart: "program"
4693
+ };
4694
+ if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
4695
+ module.exports = grammar2;
4696
+ } else {
4697
+ window.grammar = grammar2;
4698
+ }
4699
+ })();
4700
+ }
4701
+ });
4702
+
4703
+ // src/index.ts
4704
+ var index_exports = {};
4705
+ __export(index_exports, {
4706
+ YukigoPrologParser: () => YukigoPrologParser,
4707
+ groupRuleDeclarations: () => groupRuleDeclarations
4708
+ });
4709
+ init_dist();
4710
+ var import_nearley = __toESM(require_nearley(), 1);
4711
+ var import_grammar = __toESM(require_grammar(), 1);
4712
+
4713
+ // src/std.ts
4714
+ var stdCode = `
4715
+ % between(+Low, +High, ?Value)
4716
+ % True if Low =< Value =< High (assuming integers)
4717
+ between(Low, High, Low) :- Low =< High.
4718
+ between(Low, High, Value) :-
4719
+ Low < High,
4720
+ NextLow is Low + 1,
4721
+ between(NextLow, High, Value).
4722
+
4723
+ % union(+List1, +List2, -Union)
4724
+ % Union of two lists without duplicates (order not preserved)
4725
+ union([], L, L).
4726
+ union([H|T], L2, Union) :-
4727
+ ( member(H, L2)
4728
+ -> union(T, L2, Union)
4729
+ ; Union = [H|Rest],
4730
+ union(T, L2, Rest)
4731
+ ).
4732
+
4733
+ % intersection(+List1, +List2, -Intersection)
4734
+ intersection([], _, []).
4735
+ intersection([H|T], L2, [H|Rest]) :-
4736
+ member(H, L2),
4737
+ !,
4738
+ intersection(T, L2, Rest).
4739
+ intersection([_|T], L2, Rest) :-
4740
+ intersection(T, L2, Rest).
4741
+
4742
+ % max_member(-Max, +List)
4743
+ max_member(Max, [Max]) :- !.
4744
+ max_member(Max, [H|T]) :-
4745
+ max_member(M, T),
4746
+ ( H > M
4747
+ -> Max = H
4748
+ ; Max = M
4749
+ ).
4750
+
4751
+ % min_member(-Min, +List)
4752
+ min_member(Min, [Min]) :- !.
4753
+ min_member(Min, [H|T]) :-
4754
+ min_member(M, T),
4755
+ ( H < M
4756
+ -> Min = H
4757
+ ; Min = M
4758
+ ).
4759
+
4760
+ % sumlist(+List, -Sum)
4761
+ sumlist([], 0).
4762
+ sumlist([H|T], Sum) :-
4763
+ sumlist(T, RestSum),
4764
+ Sum is H + RestSum.
4765
+
4766
+ % length(?List, ?Length)
4767
+ length([], 0).
4768
+ length([_|Tail], N) :-
4769
+ length(Tail, M),
4770
+ N is M + 1.
4771
+
4772
+ % flatten(+NestedList, -FlatList)
4773
+ flatten([], []).
4774
+ flatten([H|T], Flat) :-
4775
+ !,
4776
+ flatten(H, FlatH),
4777
+ flatten(T, FlatT),
4778
+ append(FlatH, FlatT, Flat).
4779
+ flatten(X, [X]).
4780
+
4781
+ % reverse(+List, -Reversed)
4782
+ reverse(List, Reversed) :-
4783
+ reverse_acc(List, [], Reversed).
4784
+
4785
+ reverse_acc([], Acc, Acc).
4786
+ reverse_acc([H|T], Acc, Reversed) :-
4787
+ reverse_acc(T, [H|Acc], Reversed).
4788
+
4789
+ % list_to_set(+List, -Set)
4790
+ % Removes duplicates, keeps first occurrence
4791
+ list_to_set([], []).
4792
+ list_to_set([H|T], [H|Rest]) :-
4793
+ exclude(==(H), T, T1),
4794
+ list_to_set(T1, Rest).
4795
+
4796
+ ==(H, T) :-
4797
+ H == T.
4798
+
4799
+ % nth0(?Index, ?List, ?Elem)
4800
+ % Index starts at 0
4801
+ nth0(0, [H|_], H).
4802
+ nth0(N, [_|T], Elem) :-
4803
+ N > 0,
4804
+ N1 is N - 1,
4805
+ nth0(N1, T, Elem).
4806
+
4807
+ % nth1(?Index, ?List, ?Elem)
4808
+ % Index starts at 1
4809
+ nth1(1, [H|_], H).
4810
+ nth1(N, [_|T], Elem) :-
4811
+ N > 1,
4812
+ N1 is N - 1,
4813
+ nth1(N1, T, Elem).
4814
+
4815
+ % append/3 (needed for flatten and union)
4816
+ append([], L, L).
4817
+ append([H|T], L, [H|R]) :-
4818
+ append(T, L, R).
4819
+
4820
+ % member/2 (needed for many predicates)
4821
+ member(H, [H|_]).
4822
+ member(H, [_|T]) :-
4823
+ member(H, T).
4824
+
4825
+ % exclude(+Pred, +List, -Filtered)
4826
+ % Removes elements satisfying Pred
4827
+ exclude(_, [], []).
4828
+ exclude(Pred, [H|T], Rest) :-
4829
+ ( call(Pred, H)
4830
+ -> exclude(Pred, T, Rest)
4831
+ ; Rest = [H|Rest2],
4832
+ exclude(Pred, T, Rest2)
4833
+ ).
4834
+
4835
+ % Arithmetic predicates
4836
+ abs(X, Y) :- Y is abs(X).
4837
+ round(X, Y) :- Y is round(X).
4838
+ sqrt(X, Y) :- Y is sqrt(X).
4839
+
4840
+
4841
+ max_list([X], X).
4842
+ max_list([H|T], Max) :-
4843
+ max_list(T, MaxTail),
4844
+ Max is max(H, MaxTail).
4845
+ `;
4846
+
4847
+ // src/index.ts
4848
+ var UnexpectedToken = class extends Error {
4849
+ constructor(token) {
4850
+ super(
4851
+ `Parser: Unexpected '${token.type}' token '${token.value}' at line ${token.line} col ${token.col}.`
4852
+ );
4853
+ }
4854
+ };
4855
+ var AmbiguityError = class extends Error {
4856
+ constructor(amountAST) {
4857
+ super(
4858
+ `Parser: Too much ambiguity. ${amountAST} ASTs parsed. Output not generated.`
4859
+ );
4860
+ }
4861
+ };
4862
+ var YukigoPrologParser = class {
4863
+ errors = [];
4864
+ std;
4865
+ constructor(std = stdCode) {
4866
+ this.errors = [];
4867
+ this.std = this.feedParser(std);
4868
+ }
4869
+ parse(code) {
4870
+ const result = this.feedParser(code);
4871
+ const ast = groupRuleDeclarations(this.std.concat(result));
4872
+ return ast;
4873
+ }
4874
+ parseExpression(code) {
4875
+ const expr = this.feedParser(code)[0];
4876
+ return expr;
4877
+ }
4878
+ feedParser(code) {
4879
+ const parser = new import_nearley.default.Parser(
4880
+ import_nearley.default.Grammar.fromCompiled(import_grammar.default)
4881
+ );
4882
+ try {
4883
+ parser.feed(code);
4884
+ parser.finish();
4885
+ } catch (e) {
4886
+ const error = e;
4887
+ if (error.token) {
4888
+ throw new UnexpectedToken(error.token);
4889
+ }
4890
+ throw error;
4891
+ }
4892
+ const { results } = parser;
4893
+ if (results.length > 1) throw new AmbiguityError(results.length);
4894
+ if (results.length == 0) return [];
4895
+ return results[0];
4896
+ }
4897
+ };
4898
+ function groupRuleDeclarations(ast) {
4899
+ const groups = {};
4900
+ const others = [];
4901
+ for (const node of ast) {
4902
+ if (node instanceof Rule) {
4903
+ const name = node.identifier.value;
4904
+ if (!groups[name]) {
4905
+ groups[name] = [];
4906
+ }
4907
+ groups[name].push(node);
4908
+ } else {
4909
+ others.push(node);
4910
+ }
4911
+ }
4912
+ const ruleGroups = Object.values(groups).map((rules) => {
4913
+ const identifier = rules[0].identifier;
4914
+ const allEquations = rules.flatMap((r) => r.equations);
4915
+ return new Rule(identifier, allEquations, identifier.loc);
4916
+ });
4917
+ return [...others, ...ruleGroups];
4918
+ }
4919
+ return __toCommonJS(index_exports);
4920
+ })();