@mirascript/typed 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/type.js ADDED
@@ -0,0 +1,1218 @@
1
+ // @generated by Peggy 5.1.0.
2
+ //
3
+ // https://peggyjs.org/
4
+
5
+
6
+ class peg$SyntaxError extends SyntaxError {
7
+ constructor(message, expected, found, location) {
8
+ super(message);
9
+ this.expected = expected;
10
+ this.found = found;
11
+ this.location = location;
12
+ this.name = "SyntaxError";
13
+ }
14
+
15
+ format(sources) {
16
+ let str = "Error: " + this.message;
17
+ if (this.location) {
18
+ let src = null;
19
+ const st = sources.find(s => s.source === this.location.source);
20
+ if (st) {
21
+ src = st.text.split(/\r\n|\n|\r/g);
22
+ }
23
+ const s = this.location.start;
24
+ const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
25
+ ? this.location.source.offset(s)
26
+ : s;
27
+ const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
28
+ if (src) {
29
+ const e = this.location.end;
30
+ const filler = "".padEnd(offset_s.line.toString().length, " ");
31
+ const line = src[s.line - 1];
32
+ const last = s.line === e.line ? e.column : line.length + 1;
33
+ const hatLen = (last - s.column) || 1;
34
+ str += "\n --> " + loc + "\n"
35
+ + filler + " |\n"
36
+ + offset_s.line + " | " + line + "\n"
37
+ + filler + " | " + "".padEnd(s.column - 1, " ")
38
+ + "".padEnd(hatLen, "^");
39
+ } else {
40
+ str += "\n at " + loc;
41
+ }
42
+ }
43
+ return str;
44
+ }
45
+
46
+ static buildMessage(expected, found) {
47
+ function hex(ch) {
48
+ return ch.codePointAt(0).toString(16).toUpperCase();
49
+ }
50
+
51
+ const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
52
+ ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
53
+ : null;
54
+ function unicodeEscape(s) {
55
+ if (nonPrintable) {
56
+ return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
57
+ }
58
+ return s;
59
+ }
60
+
61
+ function literalEscape(s) {
62
+ return unicodeEscape(s
63
+ .replace(/\\/g, "\\\\")
64
+ .replace(/"/g, "\\\"")
65
+ .replace(/\0/g, "\\0")
66
+ .replace(/\t/g, "\\t")
67
+ .replace(/\n/g, "\\n")
68
+ .replace(/\r/g, "\\r")
69
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
70
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
71
+ }
72
+
73
+ function classEscape(s) {
74
+ return unicodeEscape(s
75
+ .replace(/\\/g, "\\\\")
76
+ .replace(/\]/g, "\\]")
77
+ .replace(/\^/g, "\\^")
78
+ .replace(/-/g, "\\-")
79
+ .replace(/\0/g, "\\0")
80
+ .replace(/\t/g, "\\t")
81
+ .replace(/\n/g, "\\n")
82
+ .replace(/\r/g, "\\r")
83
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
84
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
85
+ }
86
+
87
+ const DESCRIBE_EXPECTATION_FNS = {
88
+ literal(expectation) {
89
+ return "\"" + literalEscape(expectation.text) + "\"";
90
+ },
91
+
92
+ class(expectation) {
93
+ const escapedParts = expectation.parts.map(
94
+ part => (Array.isArray(part)
95
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
96
+ : classEscape(part))
97
+ );
98
+
99
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
100
+ },
101
+
102
+ any() {
103
+ return "any character";
104
+ },
105
+
106
+ end() {
107
+ return "end of input";
108
+ },
109
+
110
+ other(expectation) {
111
+ return expectation.description;
112
+ },
113
+ };
114
+
115
+ function describeExpectation(expectation) {
116
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
117
+ }
118
+
119
+ function describeExpected(expected) {
120
+ const descriptions = expected.map(describeExpectation);
121
+ descriptions.sort();
122
+
123
+ if (descriptions.length > 0) {
124
+ let j = 1;
125
+ for (let i = 1; i < descriptions.length; i++) {
126
+ if (descriptions[i - 1] !== descriptions[i]) {
127
+ descriptions[j] = descriptions[i];
128
+ j++;
129
+ }
130
+ }
131
+ descriptions.length = j;
132
+ }
133
+
134
+ switch (descriptions.length) {
135
+ case 1:
136
+ return descriptions[0];
137
+
138
+ case 2:
139
+ return descriptions[0] + " or " + descriptions[1];
140
+
141
+ default:
142
+ return descriptions.slice(0, -1).join(", ")
143
+ + ", or "
144
+ + descriptions[descriptions.length - 1];
145
+ }
146
+ }
147
+
148
+ function describeFound(found) {
149
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
150
+ }
151
+
152
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
153
+ }
154
+ }
155
+
156
+ function peg$parse(input, options) {
157
+ options = options !== undefined ? options : {};
158
+
159
+ const peg$FAILED = {};
160
+ const peg$source = options.grammarSource;
161
+
162
+ const peg$startRuleFunctions = {
163
+ Start: peg$parseStart,
164
+ };
165
+ let peg$startRuleFunction = peg$parseStart;
166
+
167
+ const peg$c0 = "|";
168
+ const peg$c1 = "[]";
169
+ const peg$c2 = "<";
170
+ const peg$c3 = ">";
171
+ const peg$c4 = "(";
172
+ const peg$c5 = ")";
173
+ const peg$c6 = ",";
174
+ const peg$c7 = "?";
175
+ const peg$c8 = ":";
176
+ const peg$c9 = "\"";
177
+ const peg$c10 = "'";
178
+
179
+ const peg$r0 = /^[^"]/;
180
+ const peg$r1 = /^[^']/;
181
+ const peg$r2 = /^[a-zA-Z_]/;
182
+ const peg$r3 = /^[a-zA-Z0-9_]/;
183
+ const peg$r4 = /^[ \t\r\n]/;
184
+
185
+ const peg$e0 = peg$literalExpectation("|", false);
186
+ const peg$e1 = peg$literalExpectation("[]", false);
187
+ const peg$e2 = peg$literalExpectation("<", false);
188
+ const peg$e3 = peg$literalExpectation(">", false);
189
+ const peg$e4 = peg$literalExpectation("(", false);
190
+ const peg$e5 = peg$literalExpectation(")", false);
191
+ const peg$e6 = peg$literalExpectation(",", false);
192
+ const peg$e7 = peg$literalExpectation("?", false);
193
+ const peg$e8 = peg$literalExpectation(":", false);
194
+ const peg$e9 = peg$literalExpectation("\"", false);
195
+ const peg$e10 = peg$classExpectation(["\""], true, false, false);
196
+ const peg$e11 = peg$literalExpectation("'", false);
197
+ const peg$e12 = peg$classExpectation(["'"], true, false, false);
198
+ const peg$e13 = peg$classExpectation([["a", "z"], ["A", "Z"], "_"], false, false, false);
199
+ const peg$e14 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_"], false, false, false);
200
+ const peg$e15 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false, false);
201
+
202
+ function peg$f0(t) { return t; }
203
+ function peg$f1(head) {
204
+ return head;
205
+ }
206
+ function peg$f2(first, rest) {
207
+ return union([
208
+ first,
209
+ ...rest.map(x => x[3])
210
+ ]);
211
+ }
212
+ function peg$f3(first, rest) {
213
+ return union([
214
+ first,
215
+ ...rest.map(x => x[3])
216
+ ]);
217
+ }
218
+ function peg$f4(base, suffix) {
219
+ let t = base;
220
+ for (const _ of suffix)
221
+ t = array(t);
222
+ return t;
223
+ }
224
+ function peg$f5(name, generic) {
225
+ if (generic) {
226
+ const t = generic[3];
227
+ if (name === 'array') return array(t);
228
+ if (name === 'record') return { kind: "record", fields: [], value: t };
229
+ }
230
+ if (name === 'true') return { kind: "literal", value: true };
231
+ if (name === 'false') return { kind: "literal", value: false };
232
+ return named(name);
233
+ }
234
+ function peg$f6(lit) {
235
+ return { kind: "literal", value: lit };
236
+ }
237
+ function peg$f7(t) {
238
+ return t;
239
+ }
240
+ function peg$f8() { return record([]); }
241
+ function peg$f9(fields) { return record(fields); }
242
+ function peg$f10(fields) {
243
+ return fields;
244
+ }
245
+ function peg$f11(name, opt, t) {
246
+ return {
247
+ name,
248
+ optional: opt !== null,
249
+ type: t
250
+ };
251
+ }
252
+ function peg$f12(t) {
253
+ return {
254
+ type: t
255
+ };
256
+ }
257
+ let peg$currPos = options.peg$currPos | 0;
258
+ let peg$savedPos = peg$currPos;
259
+ const peg$posDetailsCache = [{ line: 1, column: 1 }];
260
+ let peg$maxFailPos = peg$currPos;
261
+ let peg$maxFailExpected = options.peg$maxFailExpected || [];
262
+ let peg$silentFails = options.peg$silentFails | 0;
263
+
264
+ let peg$result;
265
+
266
+ if (options.startRule) {
267
+ if (!(options.startRule in peg$startRuleFunctions)) {
268
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
269
+ }
270
+
271
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
272
+ }
273
+
274
+ function text() {
275
+ return input.substring(peg$savedPos, peg$currPos);
276
+ }
277
+
278
+ function offset() {
279
+ return peg$savedPos;
280
+ }
281
+
282
+ function range() {
283
+ return {
284
+ source: peg$source,
285
+ start: peg$savedPos,
286
+ end: peg$currPos,
287
+ };
288
+ }
289
+
290
+ function location() {
291
+ return peg$computeLocation(peg$savedPos, peg$currPos);
292
+ }
293
+
294
+ function expected(description, location) {
295
+ location = location !== undefined
296
+ ? location
297
+ : peg$computeLocation(peg$savedPos, peg$currPos);
298
+
299
+ throw peg$buildStructuredError(
300
+ [peg$otherExpectation(description)],
301
+ input.substring(peg$savedPos, peg$currPos),
302
+ location
303
+ );
304
+ }
305
+
306
+ function error(message, location) {
307
+ location = location !== undefined
308
+ ? location
309
+ : peg$computeLocation(peg$savedPos, peg$currPos);
310
+
311
+ throw peg$buildSimpleError(message, location);
312
+ }
313
+
314
+ function peg$getUnicode(pos = peg$currPos) {
315
+ const cp = input.codePointAt(pos);
316
+ if (cp === undefined) {
317
+ return "";
318
+ }
319
+ return String.fromCodePoint(cp);
320
+ }
321
+
322
+ function peg$literalExpectation(text, ignoreCase) {
323
+ return { type: "literal", text, ignoreCase };
324
+ }
325
+
326
+ function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
327
+ return { type: "class", parts, inverted, ignoreCase, unicode };
328
+ }
329
+
330
+ function peg$anyExpectation() {
331
+ return { type: "any" };
332
+ }
333
+
334
+ function peg$endExpectation() {
335
+ return { type: "end" };
336
+ }
337
+
338
+ function peg$otherExpectation(description) {
339
+ return { type: "other", description };
340
+ }
341
+
342
+ function peg$computePosDetails(pos) {
343
+ let details = peg$posDetailsCache[pos];
344
+ let p;
345
+
346
+ if (details) {
347
+ return details;
348
+ } else {
349
+ if (pos >= peg$posDetailsCache.length) {
350
+ p = peg$posDetailsCache.length - 1;
351
+ } else {
352
+ p = pos;
353
+ while (!peg$posDetailsCache[--p]) {}
354
+ }
355
+
356
+ details = peg$posDetailsCache[p];
357
+ details = {
358
+ line: details.line,
359
+ column: details.column,
360
+ };
361
+
362
+ while (p < pos) {
363
+ if (input.charCodeAt(p) === 10) {
364
+ details.line++;
365
+ details.column = 1;
366
+ } else {
367
+ details.column++;
368
+ }
369
+
370
+ p++;
371
+ }
372
+
373
+ peg$posDetailsCache[pos] = details;
374
+
375
+ return details;
376
+ }
377
+ }
378
+
379
+ function peg$computeLocation(startPos, endPos, offset) {
380
+ const startPosDetails = peg$computePosDetails(startPos);
381
+ const endPosDetails = peg$computePosDetails(endPos);
382
+
383
+ const res = {
384
+ source: peg$source,
385
+ start: {
386
+ offset: startPos,
387
+ line: startPosDetails.line,
388
+ column: startPosDetails.column,
389
+ },
390
+ end: {
391
+ offset: endPos,
392
+ line: endPosDetails.line,
393
+ column: endPosDetails.column,
394
+ },
395
+ };
396
+ if (offset && peg$source && (typeof peg$source.offset === "function")) {
397
+ res.start = peg$source.offset(res.start);
398
+ res.end = peg$source.offset(res.end);
399
+ }
400
+ return res;
401
+ }
402
+
403
+ function peg$fail(expected) {
404
+ if (peg$currPos < peg$maxFailPos) { return; }
405
+
406
+ if (peg$currPos > peg$maxFailPos) {
407
+ peg$maxFailPos = peg$currPos;
408
+ peg$maxFailExpected = [];
409
+ }
410
+
411
+ peg$maxFailExpected.push(expected);
412
+ }
413
+
414
+ function peg$buildSimpleError(message, location) {
415
+ return new peg$SyntaxError(message, null, null, location);
416
+ }
417
+
418
+ function peg$buildStructuredError(expected, found, location) {
419
+ return new peg$SyntaxError(
420
+ peg$SyntaxError.buildMessage(expected, found),
421
+ expected,
422
+ found,
423
+ location
424
+ );
425
+ }
426
+
427
+ function peg$parseStart() {
428
+ let s0, s1, s2, s3;
429
+
430
+ s0 = peg$currPos;
431
+ s1 = peg$parse_();
432
+ s2 = peg$parseType();
433
+ if (s2 !== peg$FAILED) {
434
+ s3 = peg$parse_();
435
+ peg$savedPos = s0;
436
+ s0 = peg$f0(s2);
437
+ } else {
438
+ peg$currPos = s0;
439
+ s0 = peg$FAILED;
440
+ }
441
+
442
+ return s0;
443
+ }
444
+
445
+ function peg$parseType() {
446
+ let s0, s1;
447
+
448
+ s0 = peg$currPos;
449
+ s1 = peg$parseUnionType();
450
+ if (s1 !== peg$FAILED) {
451
+ peg$savedPos = s0;
452
+ s1 = peg$f1(s1);
453
+ }
454
+ s0 = s1;
455
+
456
+ return s0;
457
+ }
458
+
459
+ function peg$parseUnionType() {
460
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
461
+
462
+ s0 = peg$currPos;
463
+ s1 = peg$parse_();
464
+ if (input.charCodeAt(peg$currPos) === 124) {
465
+ s2 = peg$c0;
466
+ peg$currPos++;
467
+ } else {
468
+ s2 = peg$FAILED;
469
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
470
+ }
471
+ if (s2 !== peg$FAILED) {
472
+ s3 = peg$parse_();
473
+ s4 = peg$parsePostfixType();
474
+ if (s4 !== peg$FAILED) {
475
+ s5 = [];
476
+ s6 = peg$currPos;
477
+ s7 = peg$parse_();
478
+ if (input.charCodeAt(peg$currPos) === 124) {
479
+ s8 = peg$c0;
480
+ peg$currPos++;
481
+ } else {
482
+ s8 = peg$FAILED;
483
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
484
+ }
485
+ if (s8 !== peg$FAILED) {
486
+ s9 = peg$parse_();
487
+ s10 = peg$parsePostfixType();
488
+ if (s10 !== peg$FAILED) {
489
+ s7 = [s7, s8, s9, s10];
490
+ s6 = s7;
491
+ } else {
492
+ peg$currPos = s6;
493
+ s6 = peg$FAILED;
494
+ }
495
+ } else {
496
+ peg$currPos = s6;
497
+ s6 = peg$FAILED;
498
+ }
499
+ while (s6 !== peg$FAILED) {
500
+ s5.push(s6);
501
+ s6 = peg$currPos;
502
+ s7 = peg$parse_();
503
+ if (input.charCodeAt(peg$currPos) === 124) {
504
+ s8 = peg$c0;
505
+ peg$currPos++;
506
+ } else {
507
+ s8 = peg$FAILED;
508
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
509
+ }
510
+ if (s8 !== peg$FAILED) {
511
+ s9 = peg$parse_();
512
+ s10 = peg$parsePostfixType();
513
+ if (s10 !== peg$FAILED) {
514
+ s7 = [s7, s8, s9, s10];
515
+ s6 = s7;
516
+ } else {
517
+ peg$currPos = s6;
518
+ s6 = peg$FAILED;
519
+ }
520
+ } else {
521
+ peg$currPos = s6;
522
+ s6 = peg$FAILED;
523
+ }
524
+ }
525
+ peg$savedPos = s0;
526
+ s0 = peg$f2(s4, s5);
527
+ } else {
528
+ peg$currPos = s0;
529
+ s0 = peg$FAILED;
530
+ }
531
+ } else {
532
+ peg$currPos = s0;
533
+ s0 = peg$FAILED;
534
+ }
535
+ if (s0 === peg$FAILED) {
536
+ s0 = peg$currPos;
537
+ s1 = peg$parsePostfixType();
538
+ if (s1 !== peg$FAILED) {
539
+ s2 = [];
540
+ s3 = peg$currPos;
541
+ s4 = peg$parse_();
542
+ if (input.charCodeAt(peg$currPos) === 124) {
543
+ s5 = peg$c0;
544
+ peg$currPos++;
545
+ } else {
546
+ s5 = peg$FAILED;
547
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
548
+ }
549
+ if (s5 !== peg$FAILED) {
550
+ s6 = peg$parse_();
551
+ s7 = peg$parsePostfixType();
552
+ if (s7 !== peg$FAILED) {
553
+ s4 = [s4, s5, s6, s7];
554
+ s3 = s4;
555
+ } else {
556
+ peg$currPos = s3;
557
+ s3 = peg$FAILED;
558
+ }
559
+ } else {
560
+ peg$currPos = s3;
561
+ s3 = peg$FAILED;
562
+ }
563
+ if (s3 !== peg$FAILED) {
564
+ while (s3 !== peg$FAILED) {
565
+ s2.push(s3);
566
+ s3 = peg$currPos;
567
+ s4 = peg$parse_();
568
+ if (input.charCodeAt(peg$currPos) === 124) {
569
+ s5 = peg$c0;
570
+ peg$currPos++;
571
+ } else {
572
+ s5 = peg$FAILED;
573
+ if (peg$silentFails === 0) { peg$fail(peg$e0); }
574
+ }
575
+ if (s5 !== peg$FAILED) {
576
+ s6 = peg$parse_();
577
+ s7 = peg$parsePostfixType();
578
+ if (s7 !== peg$FAILED) {
579
+ s4 = [s4, s5, s6, s7];
580
+ s3 = s4;
581
+ } else {
582
+ peg$currPos = s3;
583
+ s3 = peg$FAILED;
584
+ }
585
+ } else {
586
+ peg$currPos = s3;
587
+ s3 = peg$FAILED;
588
+ }
589
+ }
590
+ } else {
591
+ s2 = peg$FAILED;
592
+ }
593
+ if (s2 !== peg$FAILED) {
594
+ peg$savedPos = s0;
595
+ s0 = peg$f3(s1, s2);
596
+ } else {
597
+ peg$currPos = s0;
598
+ s0 = peg$FAILED;
599
+ }
600
+ } else {
601
+ peg$currPos = s0;
602
+ s0 = peg$FAILED;
603
+ }
604
+ if (s0 === peg$FAILED) {
605
+ s0 = peg$parsePostfixType();
606
+ }
607
+ }
608
+
609
+ return s0;
610
+ }
611
+
612
+ function peg$parsePostfixType() {
613
+ let s0, s1, s2, s3, s4, s5;
614
+
615
+ s0 = peg$currPos;
616
+ s1 = peg$parsePrimaryType();
617
+ if (s1 !== peg$FAILED) {
618
+ s2 = [];
619
+ s3 = peg$currPos;
620
+ if (input.substr(peg$currPos, 2) === peg$c1) {
621
+ s4 = peg$c1;
622
+ peg$currPos += 2;
623
+ } else {
624
+ s4 = peg$FAILED;
625
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
626
+ }
627
+ if (s4 !== peg$FAILED) {
628
+ s5 = peg$parse_();
629
+ s4 = [s4, s5];
630
+ s3 = s4;
631
+ } else {
632
+ peg$currPos = s3;
633
+ s3 = peg$FAILED;
634
+ }
635
+ while (s3 !== peg$FAILED) {
636
+ s2.push(s3);
637
+ s3 = peg$currPos;
638
+ if (input.substr(peg$currPos, 2) === peg$c1) {
639
+ s4 = peg$c1;
640
+ peg$currPos += 2;
641
+ } else {
642
+ s4 = peg$FAILED;
643
+ if (peg$silentFails === 0) { peg$fail(peg$e1); }
644
+ }
645
+ if (s4 !== peg$FAILED) {
646
+ s5 = peg$parse_();
647
+ s4 = [s4, s5];
648
+ s3 = s4;
649
+ } else {
650
+ peg$currPos = s3;
651
+ s3 = peg$FAILED;
652
+ }
653
+ }
654
+ peg$savedPos = s0;
655
+ s0 = peg$f4(s1, s2);
656
+ } else {
657
+ peg$currPos = s0;
658
+ s0 = peg$FAILED;
659
+ }
660
+
661
+ return s0;
662
+ }
663
+
664
+ function peg$parsePrimaryType() {
665
+ let s0, s1, s2, s3, s4, s5, s6, s7, s8;
666
+
667
+ s0 = peg$currPos;
668
+ s1 = peg$parseIdentifier();
669
+ if (s1 !== peg$FAILED) {
670
+ s2 = peg$currPos;
671
+ s3 = peg$parse_();
672
+ if (input.charCodeAt(peg$currPos) === 60) {
673
+ s4 = peg$c2;
674
+ peg$currPos++;
675
+ } else {
676
+ s4 = peg$FAILED;
677
+ if (peg$silentFails === 0) { peg$fail(peg$e2); }
678
+ }
679
+ if (s4 !== peg$FAILED) {
680
+ s5 = peg$parse_();
681
+ s6 = peg$parseType();
682
+ if (s6 !== peg$FAILED) {
683
+ s7 = peg$parse_();
684
+ if (input.charCodeAt(peg$currPos) === 62) {
685
+ s8 = peg$c3;
686
+ peg$currPos++;
687
+ } else {
688
+ s8 = peg$FAILED;
689
+ if (peg$silentFails === 0) { peg$fail(peg$e3); }
690
+ }
691
+ if (s8 !== peg$FAILED) {
692
+ s3 = [s3, s4, s5, s6, s7, s8];
693
+ s2 = s3;
694
+ } else {
695
+ peg$currPos = s2;
696
+ s2 = peg$FAILED;
697
+ }
698
+ } else {
699
+ peg$currPos = s2;
700
+ s2 = peg$FAILED;
701
+ }
702
+ } else {
703
+ peg$currPos = s2;
704
+ s2 = peg$FAILED;
705
+ }
706
+ if (s2 === peg$FAILED) {
707
+ s2 = null;
708
+ }
709
+ peg$savedPos = s0;
710
+ s0 = peg$f5(s1, s2);
711
+ } else {
712
+ peg$currPos = s0;
713
+ s0 = peg$FAILED;
714
+ }
715
+ if (s0 === peg$FAILED) {
716
+ s0 = peg$currPos;
717
+ s1 = peg$parseString();
718
+ if (s1 !== peg$FAILED) {
719
+ peg$savedPos = s0;
720
+ s1 = peg$f6(s1);
721
+ }
722
+ s0 = s1;
723
+ if (s0 === peg$FAILED) {
724
+ s0 = peg$currPos;
725
+ if (input.charCodeAt(peg$currPos) === 40) {
726
+ s1 = peg$c4;
727
+ peg$currPos++;
728
+ } else {
729
+ s1 = peg$FAILED;
730
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
731
+ }
732
+ if (s1 !== peg$FAILED) {
733
+ s2 = peg$parse_();
734
+ s3 = peg$parseType();
735
+ if (s3 !== peg$FAILED) {
736
+ s4 = peg$parse_();
737
+ if (input.charCodeAt(peg$currPos) === 41) {
738
+ s5 = peg$c5;
739
+ peg$currPos++;
740
+ } else {
741
+ s5 = peg$FAILED;
742
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
743
+ }
744
+ if (s5 !== peg$FAILED) {
745
+ peg$savedPos = s0;
746
+ s0 = peg$f7(s3);
747
+ } else {
748
+ peg$currPos = s0;
749
+ s0 = peg$FAILED;
750
+ }
751
+ } else {
752
+ peg$currPos = s0;
753
+ s0 = peg$FAILED;
754
+ }
755
+ } else {
756
+ peg$currPos = s0;
757
+ s0 = peg$FAILED;
758
+ }
759
+ if (s0 === peg$FAILED) {
760
+ s0 = peg$parseRecordType();
761
+ }
762
+ }
763
+ }
764
+
765
+ return s0;
766
+ }
767
+
768
+ function peg$parseRecordType() {
769
+ let s0, s1, s2, s3, s4, s5;
770
+
771
+ s0 = peg$currPos;
772
+ if (input.charCodeAt(peg$currPos) === 40) {
773
+ s1 = peg$c4;
774
+ peg$currPos++;
775
+ } else {
776
+ s1 = peg$FAILED;
777
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
778
+ }
779
+ if (s1 !== peg$FAILED) {
780
+ s2 = peg$parse_();
781
+ if (input.charCodeAt(peg$currPos) === 41) {
782
+ s3 = peg$c5;
783
+ peg$currPos++;
784
+ } else {
785
+ s3 = peg$FAILED;
786
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
787
+ }
788
+ if (s3 !== peg$FAILED) {
789
+ peg$savedPos = s0;
790
+ s0 = peg$f8();
791
+ } else {
792
+ peg$currPos = s0;
793
+ s0 = peg$FAILED;
794
+ }
795
+ } else {
796
+ peg$currPos = s0;
797
+ s0 = peg$FAILED;
798
+ }
799
+ if (s0 === peg$FAILED) {
800
+ s0 = peg$currPos;
801
+ if (input.charCodeAt(peg$currPos) === 40) {
802
+ s1 = peg$c4;
803
+ peg$currPos++;
804
+ } else {
805
+ s1 = peg$FAILED;
806
+ if (peg$silentFails === 0) { peg$fail(peg$e4); }
807
+ }
808
+ if (s1 !== peg$FAILED) {
809
+ s2 = peg$parse_();
810
+ s3 = peg$parseFieldList();
811
+ if (s3 !== peg$FAILED) {
812
+ s4 = peg$parse_();
813
+ if (input.charCodeAt(peg$currPos) === 41) {
814
+ s5 = peg$c5;
815
+ peg$currPos++;
816
+ } else {
817
+ s5 = peg$FAILED;
818
+ if (peg$silentFails === 0) { peg$fail(peg$e5); }
819
+ }
820
+ if (s5 !== peg$FAILED) {
821
+ peg$savedPos = s0;
822
+ s0 = peg$f9(s3);
823
+ } else {
824
+ peg$currPos = s0;
825
+ s0 = peg$FAILED;
826
+ }
827
+ } else {
828
+ peg$currPos = s0;
829
+ s0 = peg$FAILED;
830
+ }
831
+ } else {
832
+ peg$currPos = s0;
833
+ s0 = peg$FAILED;
834
+ }
835
+ }
836
+
837
+ return s0;
838
+ }
839
+
840
+ function peg$parseFieldList() {
841
+ let s0, s1, s2, s3, s4, s5, s6, s7;
842
+
843
+ s0 = peg$currPos;
844
+ s1 = peg$currPos;
845
+ s2 = [];
846
+ s3 = peg$parseField();
847
+ while (s3 !== peg$FAILED) {
848
+ s2.push(s3);
849
+ s3 = peg$currPos;
850
+ s4 = peg$currPos;
851
+ s5 = peg$parse_();
852
+ if (input.charCodeAt(peg$currPos) === 44) {
853
+ s6 = peg$c6;
854
+ peg$currPos++;
855
+ } else {
856
+ s6 = peg$FAILED;
857
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
858
+ }
859
+ if (s6 !== peg$FAILED) {
860
+ s7 = peg$parse_();
861
+ s5 = [s5, s6, s7];
862
+ s4 = s5;
863
+ } else {
864
+ peg$currPos = s4;
865
+ s4 = peg$FAILED;
866
+ }
867
+ if (s4 !== peg$FAILED) {
868
+ s4 = peg$parseField();
869
+ if (s4 === peg$FAILED) {
870
+ peg$currPos = s3;
871
+ s3 = peg$FAILED;
872
+ } else {
873
+ s3 = s4;
874
+ }
875
+ } else {
876
+ s3 = s4;
877
+ }
878
+ }
879
+ if (s2.length < 1) {
880
+ peg$currPos = s1;
881
+ s1 = peg$FAILED;
882
+ } else {
883
+ s1 = s2;
884
+ }
885
+ if (s1 !== peg$FAILED) {
886
+ s2 = peg$currPos;
887
+ s3 = peg$parse_();
888
+ if (input.charCodeAt(peg$currPos) === 44) {
889
+ s4 = peg$c6;
890
+ peg$currPos++;
891
+ } else {
892
+ s4 = peg$FAILED;
893
+ if (peg$silentFails === 0) { peg$fail(peg$e6); }
894
+ }
895
+ if (s4 !== peg$FAILED) {
896
+ s5 = peg$parse_();
897
+ s3 = [s3, s4, s5];
898
+ s2 = s3;
899
+ } else {
900
+ peg$currPos = s2;
901
+ s2 = peg$FAILED;
902
+ }
903
+ if (s2 === peg$FAILED) {
904
+ s2 = null;
905
+ }
906
+ peg$savedPos = s0;
907
+ s0 = peg$f10(s1);
908
+ } else {
909
+ peg$currPos = s0;
910
+ s0 = peg$FAILED;
911
+ }
912
+
913
+ return s0;
914
+ }
915
+
916
+ function peg$parseField() {
917
+ let s0, s1, s2, s3, s4, s5, s6;
918
+
919
+ s0 = peg$currPos;
920
+ s1 = peg$parseFieldName();
921
+ if (s1 !== peg$FAILED) {
922
+ if (input.charCodeAt(peg$currPos) === 63) {
923
+ s2 = peg$c7;
924
+ peg$currPos++;
925
+ } else {
926
+ s2 = peg$FAILED;
927
+ if (peg$silentFails === 0) { peg$fail(peg$e7); }
928
+ }
929
+ if (s2 === peg$FAILED) {
930
+ s2 = null;
931
+ }
932
+ s3 = peg$parse_();
933
+ if (input.charCodeAt(peg$currPos) === 58) {
934
+ s4 = peg$c8;
935
+ peg$currPos++;
936
+ } else {
937
+ s4 = peg$FAILED;
938
+ if (peg$silentFails === 0) { peg$fail(peg$e8); }
939
+ }
940
+ if (s4 !== peg$FAILED) {
941
+ s5 = peg$parse_();
942
+ s6 = peg$parseType();
943
+ if (s6 !== peg$FAILED) {
944
+ peg$savedPos = s0;
945
+ s0 = peg$f11(s1, s2, s6);
946
+ } else {
947
+ peg$currPos = s0;
948
+ s0 = peg$FAILED;
949
+ }
950
+ } else {
951
+ peg$currPos = s0;
952
+ s0 = peg$FAILED;
953
+ }
954
+ } else {
955
+ peg$currPos = s0;
956
+ s0 = peg$FAILED;
957
+ }
958
+ if (s0 === peg$FAILED) {
959
+ s0 = peg$currPos;
960
+ s1 = peg$parseType();
961
+ if (s1 !== peg$FAILED) {
962
+ peg$savedPos = s0;
963
+ s1 = peg$f12(s1);
964
+ }
965
+ s0 = s1;
966
+ }
967
+
968
+ return s0;
969
+ }
970
+
971
+ function peg$parseFieldName() {
972
+ let s0;
973
+
974
+ s0 = peg$parseIdentifier();
975
+ if (s0 === peg$FAILED) {
976
+ s0 = peg$parseString();
977
+ }
978
+
979
+ return s0;
980
+ }
981
+
982
+ function peg$parseString() {
983
+ let s0, s1, s2, s3, s4;
984
+
985
+ s0 = peg$currPos;
986
+ if (input.charCodeAt(peg$currPos) === 34) {
987
+ s1 = peg$c9;
988
+ peg$currPos++;
989
+ } else {
990
+ s1 = peg$FAILED;
991
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
992
+ }
993
+ if (s1 !== peg$FAILED) {
994
+ s2 = peg$currPos;
995
+ s3 = [];
996
+ s4 = input.charAt(peg$currPos);
997
+ if (peg$r0.test(s4)) {
998
+ peg$currPos++;
999
+ } else {
1000
+ s4 = peg$FAILED;
1001
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
1002
+ }
1003
+ while (s4 !== peg$FAILED) {
1004
+ s3.push(s4);
1005
+ s4 = input.charAt(peg$currPos);
1006
+ if (peg$r0.test(s4)) {
1007
+ peg$currPos++;
1008
+ } else {
1009
+ s4 = peg$FAILED;
1010
+ if (peg$silentFails === 0) { peg$fail(peg$e10); }
1011
+ }
1012
+ }
1013
+ s2 = input.substring(s2, peg$currPos);
1014
+ if (input.charCodeAt(peg$currPos) === 34) {
1015
+ s3 = peg$c9;
1016
+ peg$currPos++;
1017
+ } else {
1018
+ s3 = peg$FAILED;
1019
+ if (peg$silentFails === 0) { peg$fail(peg$e9); }
1020
+ }
1021
+ if (s3 !== peg$FAILED) {
1022
+ s0 = s2;
1023
+ } else {
1024
+ peg$currPos = s0;
1025
+ s0 = peg$FAILED;
1026
+ }
1027
+ } else {
1028
+ peg$currPos = s0;
1029
+ s0 = peg$FAILED;
1030
+ }
1031
+ if (s0 === peg$FAILED) {
1032
+ s0 = peg$currPos;
1033
+ if (input.charCodeAt(peg$currPos) === 39) {
1034
+ s1 = peg$c10;
1035
+ peg$currPos++;
1036
+ } else {
1037
+ s1 = peg$FAILED;
1038
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
1039
+ }
1040
+ if (s1 !== peg$FAILED) {
1041
+ s2 = peg$currPos;
1042
+ s3 = [];
1043
+ s4 = input.charAt(peg$currPos);
1044
+ if (peg$r1.test(s4)) {
1045
+ peg$currPos++;
1046
+ } else {
1047
+ s4 = peg$FAILED;
1048
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1049
+ }
1050
+ while (s4 !== peg$FAILED) {
1051
+ s3.push(s4);
1052
+ s4 = input.charAt(peg$currPos);
1053
+ if (peg$r1.test(s4)) {
1054
+ peg$currPos++;
1055
+ } else {
1056
+ s4 = peg$FAILED;
1057
+ if (peg$silentFails === 0) { peg$fail(peg$e12); }
1058
+ }
1059
+ }
1060
+ s2 = input.substring(s2, peg$currPos);
1061
+ if (input.charCodeAt(peg$currPos) === 39) {
1062
+ s3 = peg$c10;
1063
+ peg$currPos++;
1064
+ } else {
1065
+ s3 = peg$FAILED;
1066
+ if (peg$silentFails === 0) { peg$fail(peg$e11); }
1067
+ }
1068
+ if (s3 !== peg$FAILED) {
1069
+ s0 = s2;
1070
+ } else {
1071
+ peg$currPos = s0;
1072
+ s0 = peg$FAILED;
1073
+ }
1074
+ } else {
1075
+ peg$currPos = s0;
1076
+ s0 = peg$FAILED;
1077
+ }
1078
+ }
1079
+
1080
+ return s0;
1081
+ }
1082
+
1083
+ function peg$parseIdentifier() {
1084
+ let s0, s1, s2, s3, s4;
1085
+
1086
+ s0 = peg$currPos;
1087
+ s1 = peg$currPos;
1088
+ s2 = input.charAt(peg$currPos);
1089
+ if (peg$r2.test(s2)) {
1090
+ peg$currPos++;
1091
+ } else {
1092
+ s2 = peg$FAILED;
1093
+ if (peg$silentFails === 0) { peg$fail(peg$e13); }
1094
+ }
1095
+ if (s2 !== peg$FAILED) {
1096
+ s3 = [];
1097
+ s4 = input.charAt(peg$currPos);
1098
+ if (peg$r3.test(s4)) {
1099
+ peg$currPos++;
1100
+ } else {
1101
+ s4 = peg$FAILED;
1102
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1103
+ }
1104
+ while (s4 !== peg$FAILED) {
1105
+ s3.push(s4);
1106
+ s4 = input.charAt(peg$currPos);
1107
+ if (peg$r3.test(s4)) {
1108
+ peg$currPos++;
1109
+ } else {
1110
+ s4 = peg$FAILED;
1111
+ if (peg$silentFails === 0) { peg$fail(peg$e14); }
1112
+ }
1113
+ }
1114
+ s2 = [s2, s3];
1115
+ s1 = s2;
1116
+ } else {
1117
+ peg$currPos = s1;
1118
+ s1 = peg$FAILED;
1119
+ }
1120
+ if (s1 !== peg$FAILED) {
1121
+ s0 = input.substring(s0, peg$currPos);
1122
+ } else {
1123
+ s0 = s1;
1124
+ }
1125
+
1126
+ return s0;
1127
+ }
1128
+
1129
+ function peg$parse_() {
1130
+ let s0, s1;
1131
+
1132
+ s0 = [];
1133
+ s1 = input.charAt(peg$currPos);
1134
+ if (peg$r4.test(s1)) {
1135
+ peg$currPos++;
1136
+ } else {
1137
+ s1 = peg$FAILED;
1138
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1139
+ }
1140
+ while (s1 !== peg$FAILED) {
1141
+ s0.push(s1);
1142
+ s1 = input.charAt(peg$currPos);
1143
+ if (peg$r4.test(s1)) {
1144
+ peg$currPos++;
1145
+ } else {
1146
+ s1 = peg$FAILED;
1147
+ if (peg$silentFails === 0) { peg$fail(peg$e15); }
1148
+ }
1149
+ }
1150
+
1151
+ return s0;
1152
+ }
1153
+
1154
+
1155
+ function named(name) {
1156
+ return name;
1157
+ }
1158
+
1159
+ function array(element) {
1160
+ return { kind: "array", element };
1161
+ }
1162
+
1163
+ function union(types) {
1164
+ if (types.length === 1) return types[0];
1165
+ return { kind: "union", types };
1166
+ }
1167
+
1168
+ function record(fields) {
1169
+ for(let i = 0; i < fields.length; i++) {
1170
+ fields[i].name ??= String(i);
1171
+ }
1172
+ return { kind: "record", fields };
1173
+ }
1174
+
1175
+ peg$result = peg$startRuleFunction();
1176
+
1177
+ const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
1178
+ function peg$throw() {
1179
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1180
+ peg$fail(peg$endExpectation());
1181
+ }
1182
+
1183
+ throw peg$buildStructuredError(
1184
+ peg$maxFailExpected,
1185
+ peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null,
1186
+ peg$maxFailPos < input.length
1187
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
1188
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
1189
+ );
1190
+ }
1191
+ if (options.peg$library) {
1192
+ return /** @type {any} */ ({
1193
+ peg$result,
1194
+ peg$currPos,
1195
+ peg$FAILED,
1196
+ peg$maxFailExpected,
1197
+ peg$maxFailPos,
1198
+ peg$success,
1199
+ peg$throw: peg$success ? undefined : peg$throw,
1200
+ });
1201
+ }
1202
+ if (peg$success) {
1203
+ return peg$result;
1204
+ } else {
1205
+ peg$throw();
1206
+ }
1207
+ }
1208
+
1209
+ const peg$allowedStartRules = [
1210
+ "Start"
1211
+ ];
1212
+
1213
+ export {
1214
+ peg$allowedStartRules as StartRules,
1215
+ peg$SyntaxError as SyntaxError,
1216
+ peg$parse as parse
1217
+ };
1218
+ //# sourceMappingURL=type.js.map