@arkadia/data 0.1.7 → 0.1.9
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/.prettierrc +8 -0
- package/README.md +159 -112
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/Decoder.d.ts.map +1 -1
- package/dist/core/Decoder.js +123 -97
- package/dist/core/Decoder.js.map +1 -1
- package/dist/core/Encoder.d.ts +1 -2
- package/dist/core/Encoder.d.ts.map +1 -1
- package/dist/core/Encoder.js +74 -76
- package/dist/core/Encoder.js.map +1 -1
- package/dist/core/Parser.d.ts +1 -1
- package/dist/core/Parser.d.ts.map +1 -1
- package/dist/core/Parser.js +11 -11
- package/dist/core/Parser.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/models/Meta.d.ts +3 -2
- package/dist/models/Meta.d.ts.map +1 -1
- package/dist/models/Meta.js +3 -3
- package/dist/models/Meta.js.map +1 -1
- package/dist/models/Node.d.ts +4 -3
- package/dist/models/Node.d.ts.map +1 -1
- package/dist/models/Node.js +29 -23
- package/dist/models/Node.js.map +1 -1
- package/dist/models/Schema.d.ts.map +1 -1
- package/dist/models/Schema.js +27 -21
- package/dist/models/Schema.js.map +1 -1
- package/eslint.config.mjs +42 -0
- package/package.json +11 -1
- package/scripts/verify-build.js +95 -92
- package/src/config.ts +75 -75
- package/src/core/Decoder.ts +984 -922
- package/src/core/Encoder.ts +364 -371
- package/src/core/Parser.ts +112 -112
- package/src/index.ts +18 -20
- package/src/models/Meta.ts +107 -107
- package/src/models/Node.ts +190 -185
- package/src/models/Schema.ts +198 -193
- package/tests/00.meta.test.ts +19 -25
- package/tests/00.node.test.ts +40 -48
- package/tests/00.primitive.test.ts +121 -95
- package/tests/00.schema.test.ts +28 -35
- package/tests/01.schema.test.ts +42 -52
- package/tests/02.data.test.ts +69 -75
- package/tests/03.errors.test.ts +53 -55
- package/tests/04.list.test.ts +192 -193
- package/tests/05.record.test.ts +54 -56
- package/tests/06.meta.test.ts +393 -389
- package/tests/utils.ts +47 -44
- package/tsconfig.json +27 -29
- package/vitest.config.ts +1 -1
package/dist/core/Decoder.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Decoder = exports.DecodeWarning = exports.DecodeError = void 0;
|
|
4
|
+
const Meta_1 = require("../models/Meta");
|
|
4
5
|
const Node_1 = require("../models/Node");
|
|
5
6
|
const Schema_1 = require("../models/Schema");
|
|
6
|
-
const Meta_1 = require("../models/Meta");
|
|
7
7
|
// --- ANSI Colors Helper ---
|
|
8
8
|
class Ansi {
|
|
9
9
|
}
|
|
10
|
-
Ansi.RESET =
|
|
11
|
-
Ansi.DIM =
|
|
12
|
-
Ansi.BOLD =
|
|
13
|
-
Ansi.CYAN =
|
|
14
|
-
Ansi.YELLOW =
|
|
15
|
-
Ansi.GREEN =
|
|
16
|
-
Ansi.RED =
|
|
17
|
-
Ansi.MAGENTA =
|
|
10
|
+
Ansi.RESET = '\x1b[0m';
|
|
11
|
+
Ansi.DIM = '\x1b[2m';
|
|
12
|
+
Ansi.BOLD = '\x1b[1m';
|
|
13
|
+
Ansi.CYAN = '\x1b[36m';
|
|
14
|
+
Ansi.YELLOW = '\x1b[33m';
|
|
15
|
+
Ansi.GREEN = '\x1b[32m';
|
|
16
|
+
Ansi.RED = '\x1b[31m';
|
|
17
|
+
Ansi.MAGENTA = '\x1b[35m';
|
|
18
|
+
// eslint-disable-next-line no-control-regex
|
|
18
19
|
const ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
19
20
|
// --- Error/Warning Data Structures ---
|
|
20
21
|
class DecodeError {
|
|
21
22
|
constructor(message, position, schema = null, node = null) {
|
|
22
|
-
this.context =
|
|
23
|
+
this.context = '';
|
|
23
24
|
this.schema = null;
|
|
24
25
|
this.node = null;
|
|
25
26
|
this.message = message;
|
|
@@ -46,7 +47,7 @@ class DecodeWarning {
|
|
|
46
47
|
exports.DecodeWarning = DecodeWarning;
|
|
47
48
|
// --- DECODER CLASS ---
|
|
48
49
|
class Decoder {
|
|
49
|
-
constructor(text, schema =
|
|
50
|
+
constructor(text, schema = '', removeAnsiColors = false, debug = false) {
|
|
50
51
|
// Cursor State
|
|
51
52
|
this.i = 0;
|
|
52
53
|
this.line = 0;
|
|
@@ -70,7 +71,7 @@ class Decoder {
|
|
|
70
71
|
// ENTRY
|
|
71
72
|
// =========================================================
|
|
72
73
|
decode() {
|
|
73
|
-
this._dbg(
|
|
74
|
+
this._dbg('decode() start');
|
|
74
75
|
this.parseMeta();
|
|
75
76
|
let rootSchemaContext = null;
|
|
76
77
|
// 1. Schema Processing Loop
|
|
@@ -125,12 +126,12 @@ class Decoder {
|
|
|
125
126
|
this.parseMeta();
|
|
126
127
|
this.applyMeta(rootNode);
|
|
127
128
|
this.popNode(); // Just in case
|
|
128
|
-
this._dbg(
|
|
129
|
+
this._dbg('decode() end');
|
|
129
130
|
return {
|
|
130
131
|
node: rootNode,
|
|
131
132
|
schema: rootSchemaContext,
|
|
132
133
|
errors: this.errors,
|
|
133
|
-
warnings: this.warnings
|
|
134
|
+
warnings: this.warnings,
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
// =========================================================
|
|
@@ -154,8 +155,8 @@ class Decoder {
|
|
|
154
155
|
}
|
|
155
156
|
return new Schema_1.Schema(Schema_1.SchemaKind.RECORD, { typeName });
|
|
156
157
|
}
|
|
157
|
-
parseSchemaBody(typeName =
|
|
158
|
-
const typeNamePrefix = typeName ? `@${typeName}` :
|
|
158
|
+
parseSchemaBody(typeName = '') {
|
|
159
|
+
const typeNamePrefix = typeName ? `@${typeName}` : '';
|
|
159
160
|
this._dbg(`START parse_schema_body '<' ${typeNamePrefix}`);
|
|
160
161
|
if (!this.expect('<')) {
|
|
161
162
|
const s = this.createSchema(Schema_1.SchemaKind.ANY, typeName);
|
|
@@ -181,7 +182,7 @@ class Decoder {
|
|
|
181
182
|
// LIST Schema: < [ ... ] >
|
|
182
183
|
if (ch === '[') {
|
|
183
184
|
this.advance(1);
|
|
184
|
-
this._dbg(
|
|
185
|
+
this._dbg('LIST schema begin');
|
|
185
186
|
schema.kind = Schema_1.SchemaKind.LIST;
|
|
186
187
|
schema.clearFields(); // Python: schema._fields_list = []
|
|
187
188
|
this.applyMeta(schema); // Apply any pending meta
|
|
@@ -201,7 +202,7 @@ class Decoder {
|
|
|
201
202
|
}
|
|
202
203
|
const name = this.parseIdent();
|
|
203
204
|
if (!name) {
|
|
204
|
-
this.addError(
|
|
205
|
+
this.addError('Expected identifier');
|
|
205
206
|
this.advance(1);
|
|
206
207
|
continue;
|
|
207
208
|
}
|
|
@@ -217,7 +218,7 @@ class Decoder {
|
|
|
217
218
|
fieldSchema = this.parseSchemaType();
|
|
218
219
|
}
|
|
219
220
|
else {
|
|
220
|
-
fieldSchema = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName:
|
|
221
|
+
fieldSchema = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName: 'any' });
|
|
221
222
|
}
|
|
222
223
|
fieldSchema.name = name;
|
|
223
224
|
this.applyMeta(fieldSchema);
|
|
@@ -276,7 +277,7 @@ class Decoder {
|
|
|
276
277
|
parseNode(_parent = null) {
|
|
277
278
|
this.parseMeta(this.currentNode);
|
|
278
279
|
if (this.eof()) {
|
|
279
|
-
this.addError(
|
|
280
|
+
this.addError('Unexpected EOF while expecting a node');
|
|
280
281
|
return this.createNode(null);
|
|
281
282
|
}
|
|
282
283
|
const ch = this.peek();
|
|
@@ -292,15 +293,15 @@ class Decoder {
|
|
|
292
293
|
else if (ch === '{')
|
|
293
294
|
node = this.parseNamedRecord();
|
|
294
295
|
else if (ch === '"') {
|
|
295
|
-
this._dbg(
|
|
296
|
+
this._dbg('Dispatch: String');
|
|
296
297
|
node = this.parseString();
|
|
297
298
|
}
|
|
298
299
|
else if ((ch && /\d/.test(ch)) || ch === '-') {
|
|
299
|
-
this._dbg(
|
|
300
|
+
this._dbg('Dispatch: Number');
|
|
300
301
|
node = this.parseNumber();
|
|
301
302
|
}
|
|
302
|
-
else if (
|
|
303
|
-
this._dbg(
|
|
303
|
+
else if (ch && /[a-zA-Z_]/.test(ch)) {
|
|
304
|
+
this._dbg('Dispatch: RawString/Ident');
|
|
304
305
|
node = this.parseRawString();
|
|
305
306
|
}
|
|
306
307
|
else {
|
|
@@ -312,7 +313,7 @@ class Decoder {
|
|
|
312
313
|
return node;
|
|
313
314
|
}
|
|
314
315
|
parseNodeWithSchemaRef() {
|
|
315
|
-
this._dbg(
|
|
316
|
+
this._dbg('Start Node with Ref (@)');
|
|
316
317
|
const schema = this.parseSchemaAtRef();
|
|
317
318
|
this.pushSchema(schema);
|
|
318
319
|
const node = this.parseNode();
|
|
@@ -321,7 +322,7 @@ class Decoder {
|
|
|
321
322
|
return node;
|
|
322
323
|
}
|
|
323
324
|
parseNodeWithInlineSchema() {
|
|
324
|
-
this._dbg(
|
|
325
|
+
this._dbg('Start Node with Inline (<)');
|
|
325
326
|
const schema = this.parseSchemaBody();
|
|
326
327
|
this.pushSchema(schema);
|
|
327
328
|
const node = this.parseNode();
|
|
@@ -333,13 +334,13 @@ class Decoder {
|
|
|
333
334
|
// STRUCTURE PARSERS
|
|
334
335
|
// =========================================================
|
|
335
336
|
parseList() {
|
|
336
|
-
this._dbg(
|
|
337
|
+
this._dbg('Start LIST [');
|
|
337
338
|
this.advance(1); // [
|
|
338
339
|
const node = this.createNode();
|
|
339
340
|
node.elements = [];
|
|
340
341
|
if (node.schema.kind !== Schema_1.SchemaKind.LIST) {
|
|
341
342
|
node.schema.kind = Schema_1.SchemaKind.LIST;
|
|
342
|
-
node.schema.typeName =
|
|
343
|
+
node.schema.typeName = 'list';
|
|
343
344
|
node.schema.element = new Schema_1.Schema(Schema_1.SchemaKind.ANY);
|
|
344
345
|
}
|
|
345
346
|
const parentSchema = node.schema;
|
|
@@ -352,7 +353,7 @@ class Decoder {
|
|
|
352
353
|
this.parseMeta(node); // Passes node, so blocks /.../ apply to list
|
|
353
354
|
this.pushSchema(childSchema);
|
|
354
355
|
if (this.eof()) {
|
|
355
|
-
this.addError(
|
|
356
|
+
this.addError('Unexpected EOF: List not closed');
|
|
356
357
|
break;
|
|
357
358
|
}
|
|
358
359
|
if (this.peek() === ']') {
|
|
@@ -375,16 +376,16 @@ class Decoder {
|
|
|
375
376
|
this.popSchema();
|
|
376
377
|
}
|
|
377
378
|
this.popSchema();
|
|
378
|
-
this._dbg(
|
|
379
|
+
this._dbg('End LIST ]');
|
|
379
380
|
return node;
|
|
380
381
|
}
|
|
381
382
|
parsePositionalRecord() {
|
|
382
|
-
this._dbg(
|
|
383
|
+
this._dbg('Start RECORD (');
|
|
383
384
|
this.advance(1); // (
|
|
384
385
|
const node = this.createNode();
|
|
385
386
|
if (node.schema.kind !== Schema_1.SchemaKind.RECORD) {
|
|
386
387
|
node.schema.kind = Schema_1.SchemaKind.RECORD;
|
|
387
|
-
node.schema.typeName =
|
|
388
|
+
node.schema.typeName = 'any';
|
|
388
389
|
}
|
|
389
390
|
let index = 0;
|
|
390
391
|
const predefinedFields = node.schema.fields ? [...node.schema.fields] : [];
|
|
@@ -413,7 +414,9 @@ class Decoder {
|
|
|
413
414
|
}
|
|
414
415
|
else {
|
|
415
416
|
const name = `_${index}`;
|
|
416
|
-
const inferred = new Schema_1.Schema(valNode.schema.kind, {
|
|
417
|
+
const inferred = new Schema_1.Schema(valNode.schema.kind, {
|
|
418
|
+
typeName: valNode.schema.typeName || 'any',
|
|
419
|
+
});
|
|
417
420
|
inferred.name = name;
|
|
418
421
|
node.schema.addField(inferred);
|
|
419
422
|
node.fields[name] = valNode;
|
|
@@ -423,17 +426,17 @@ class Decoder {
|
|
|
423
426
|
this.popSchema();
|
|
424
427
|
index++;
|
|
425
428
|
}
|
|
426
|
-
this._dbg(
|
|
429
|
+
this._dbg('End RECORD )');
|
|
427
430
|
return node;
|
|
428
431
|
}
|
|
429
432
|
parseNamedRecord() {
|
|
430
|
-
this._dbg(
|
|
433
|
+
this._dbg('Start NAMED RECORD {');
|
|
431
434
|
this.advance(1); // {
|
|
432
435
|
const node = this.createNode();
|
|
433
436
|
node.fields = {};
|
|
434
437
|
if (node.schema.kind !== Schema_1.SchemaKind.RECORD) {
|
|
435
438
|
node.schema.kind = Schema_1.SchemaKind.RECORD;
|
|
436
|
-
node.schema.typeName =
|
|
439
|
+
node.schema.typeName = 'any';
|
|
437
440
|
}
|
|
438
441
|
const currentSchema = node.schema;
|
|
439
442
|
let valNode = null;
|
|
@@ -455,7 +458,7 @@ class Decoder {
|
|
|
455
458
|
keyName = this.readQuotedString();
|
|
456
459
|
}
|
|
457
460
|
else {
|
|
458
|
-
this.addError(
|
|
461
|
+
this.addError('Expected key in record');
|
|
459
462
|
this.advance(1);
|
|
460
463
|
continue;
|
|
461
464
|
}
|
|
@@ -477,7 +480,9 @@ class Decoder {
|
|
|
477
480
|
currentSchema.replaceField(valNode.schema);
|
|
478
481
|
}
|
|
479
482
|
else if (!existing) {
|
|
480
|
-
const inferred = new Schema_1.Schema(valNode.schema.kind, {
|
|
483
|
+
const inferred = new Schema_1.Schema(valNode.schema.kind, {
|
|
484
|
+
typeName: valNode.schema.typeName || 'any',
|
|
485
|
+
});
|
|
481
486
|
inferred.name = keyName;
|
|
482
487
|
node.schema.addField(inferred);
|
|
483
488
|
}
|
|
@@ -487,7 +492,7 @@ class Decoder {
|
|
|
487
492
|
this.popNode();
|
|
488
493
|
this.popSchema();
|
|
489
494
|
}
|
|
490
|
-
this._dbg(
|
|
495
|
+
this._dbg('End NAMED RECORD }');
|
|
491
496
|
return node;
|
|
492
497
|
}
|
|
493
498
|
// =========================================================
|
|
@@ -514,10 +519,10 @@ class Decoder {
|
|
|
514
519
|
}
|
|
515
520
|
}
|
|
516
521
|
parseCommentBlock() {
|
|
517
|
-
this._dbg(
|
|
522
|
+
this._dbg('START block comment');
|
|
518
523
|
this.advance(2);
|
|
519
524
|
let nesting = 1;
|
|
520
|
-
|
|
525
|
+
const content = [];
|
|
521
526
|
while (!this.eof() && nesting > 0) {
|
|
522
527
|
const ch = this.text[this.i];
|
|
523
528
|
if (ch === '\\') {
|
|
@@ -530,22 +535,22 @@ class Decoder {
|
|
|
530
535
|
if (ch === '/' && this.peekNext() === '*') {
|
|
531
536
|
nesting++;
|
|
532
537
|
this.advance(2);
|
|
533
|
-
content.push(
|
|
538
|
+
content.push('/*');
|
|
534
539
|
continue;
|
|
535
540
|
}
|
|
536
541
|
if (ch === '*' && this.peekNext() === '/') {
|
|
537
542
|
nesting--;
|
|
538
543
|
this.advance(2);
|
|
539
544
|
if (nesting > 0)
|
|
540
|
-
content.push(
|
|
545
|
+
content.push('*/');
|
|
541
546
|
continue;
|
|
542
547
|
}
|
|
543
548
|
content.push(ch);
|
|
544
549
|
this.advance(1);
|
|
545
550
|
}
|
|
546
551
|
if (nesting > 0)
|
|
547
|
-
this.addError(
|
|
548
|
-
return content.join(
|
|
552
|
+
this.addError('Unterminated comment');
|
|
553
|
+
return content.join('').trim();
|
|
549
554
|
}
|
|
550
555
|
parseModifierInline() {
|
|
551
556
|
const ch = this.peek();
|
|
@@ -560,7 +565,7 @@ class Decoder {
|
|
|
560
565
|
}
|
|
561
566
|
parseMetaBlock(obj = null) {
|
|
562
567
|
this.expect('/');
|
|
563
|
-
this._dbg(
|
|
568
|
+
this._dbg('START meta header /.../');
|
|
564
569
|
const meta = new Meta_1.MetaInfo();
|
|
565
570
|
while (!this.eof()) {
|
|
566
571
|
this.skipWhitespace();
|
|
@@ -609,7 +614,7 @@ class Decoder {
|
|
|
609
614
|
this.addWarning(`There is no parent to add the meta block '${meta}'`);
|
|
610
615
|
this.pendingMeta.applyMeta(meta);
|
|
611
616
|
}
|
|
612
|
-
this._dbg(
|
|
617
|
+
this._dbg('END meta header');
|
|
613
618
|
return meta;
|
|
614
619
|
}
|
|
615
620
|
parseMetaAttribute(meta) {
|
|
@@ -635,7 +640,7 @@ class Decoder {
|
|
|
635
640
|
const flag = this.parseIdent();
|
|
636
641
|
if (flag === 'required') {
|
|
637
642
|
meta.required = true;
|
|
638
|
-
this._dbg(
|
|
643
|
+
this._dbg('Meta Flag: !required');
|
|
639
644
|
}
|
|
640
645
|
else {
|
|
641
646
|
this.addWarning(`Unknown flag: !${flag}`);
|
|
@@ -648,10 +653,10 @@ class Decoder {
|
|
|
648
653
|
this.skipWhitespace();
|
|
649
654
|
const start = this.i;
|
|
650
655
|
if (this.eof())
|
|
651
|
-
return
|
|
656
|
+
return '';
|
|
652
657
|
const ch = this.text[this.i];
|
|
653
|
-
if (
|
|
654
|
-
return
|
|
658
|
+
if (!/[a-zA-Z_]/.test(ch))
|
|
659
|
+
return '';
|
|
655
660
|
this.advance(1);
|
|
656
661
|
while (!this.eof()) {
|
|
657
662
|
const c = this.text[this.i];
|
|
@@ -673,11 +678,11 @@ class Decoder {
|
|
|
673
678
|
parseRawString() {
|
|
674
679
|
const raw = this.parseIdent();
|
|
675
680
|
let val = raw;
|
|
676
|
-
if (raw ===
|
|
681
|
+
if (raw === 'true')
|
|
677
682
|
val = true;
|
|
678
|
-
else if (raw ===
|
|
683
|
+
else if (raw === 'false')
|
|
679
684
|
val = false;
|
|
680
|
-
else if (raw ===
|
|
685
|
+
else if (raw === 'null')
|
|
681
686
|
val = null;
|
|
682
687
|
return this.createNode(val);
|
|
683
688
|
}
|
|
@@ -690,25 +695,30 @@ class Decoder {
|
|
|
690
695
|
if (/\d/.test(ch) || ch === '-')
|
|
691
696
|
return this.readNumber();
|
|
692
697
|
const raw = this.parseIdent();
|
|
693
|
-
if (raw ===
|
|
698
|
+
if (raw === 'true')
|
|
694
699
|
return true;
|
|
695
|
-
if (raw ===
|
|
700
|
+
if (raw === 'false')
|
|
696
701
|
return false;
|
|
697
|
-
if (raw ===
|
|
702
|
+
if (raw === 'null')
|
|
698
703
|
return null;
|
|
699
704
|
return raw;
|
|
700
705
|
}
|
|
701
706
|
readQuotedString() {
|
|
702
707
|
this.expect('"');
|
|
703
|
-
let res =
|
|
708
|
+
let res = '';
|
|
704
709
|
while (!this.eof()) {
|
|
705
710
|
const ch = this.text[this.i];
|
|
706
|
-
|
|
711
|
+
// End of string found
|
|
712
|
+
if (ch === '"') {
|
|
707
713
|
break;
|
|
714
|
+
}
|
|
715
|
+
// Escape sequence start
|
|
708
716
|
if (ch === '\\') {
|
|
709
|
-
this.advance(1);
|
|
710
|
-
if (this.eof())
|
|
717
|
+
this.advance(1); // Skip the backslash
|
|
718
|
+
if (this.eof()) {
|
|
719
|
+
this.addError('Unexpected EOF inside string escape');
|
|
711
720
|
break;
|
|
721
|
+
}
|
|
712
722
|
const esc = this.text[this.i];
|
|
713
723
|
if (esc === 'n')
|
|
714
724
|
res += '\n';
|
|
@@ -721,13 +731,13 @@ class Decoder {
|
|
|
721
731
|
else if (esc === '\\')
|
|
722
732
|
res += '\\';
|
|
723
733
|
else
|
|
724
|
-
res += esc;
|
|
725
|
-
this.advance(1);
|
|
726
|
-
|
|
727
|
-
else {
|
|
728
|
-
res += ch;
|
|
729
|
-
this.advance(1);
|
|
734
|
+
res += esc; // Fallback: append character literally
|
|
735
|
+
this.advance(1); // Move past the escaped char
|
|
736
|
+
continue;
|
|
730
737
|
}
|
|
738
|
+
// Normal character
|
|
739
|
+
res += ch;
|
|
740
|
+
this.advance(1);
|
|
731
741
|
}
|
|
732
742
|
this.expect('"');
|
|
733
743
|
return res;
|
|
@@ -764,7 +774,7 @@ class Decoder {
|
|
|
764
774
|
get currentSchema() {
|
|
765
775
|
return this.schemaStack.length > 0 ? this.schemaStack[this.schemaStack.length - 1] : null;
|
|
766
776
|
}
|
|
767
|
-
createSchema(kind, typeName =
|
|
777
|
+
createSchema(kind, typeName = '') {
|
|
768
778
|
const s = new Schema_1.Schema(kind, { typeName });
|
|
769
779
|
this.applyMeta(s);
|
|
770
780
|
this.pushSchema(s);
|
|
@@ -805,11 +815,11 @@ class Decoder {
|
|
|
805
815
|
if (value !== null) {
|
|
806
816
|
let inferred = null;
|
|
807
817
|
if (typeof value === 'boolean')
|
|
808
|
-
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName:
|
|
818
|
+
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName: 'bool' });
|
|
809
819
|
else if (typeof value === 'number')
|
|
810
|
-
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName:
|
|
820
|
+
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName: 'number' });
|
|
811
821
|
else if (typeof value === 'string')
|
|
812
|
-
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName:
|
|
822
|
+
inferred = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName: 'string' });
|
|
813
823
|
if (inferred) {
|
|
814
824
|
let compatible = false;
|
|
815
825
|
if (currentS.kind === Schema_1.SchemaKind.ANY) {
|
|
@@ -819,7 +829,8 @@ class Decoder {
|
|
|
819
829
|
else if (currentS.typeName === inferred.typeName) {
|
|
820
830
|
compatible = true;
|
|
821
831
|
}
|
|
822
|
-
else if (currentS.typeName ===
|
|
832
|
+
else if (currentS.typeName === 'number' &&
|
|
833
|
+
(inferred.typeName === 'int' || inferred.typeName === 'float')) {
|
|
823
834
|
compatible = true;
|
|
824
835
|
}
|
|
825
836
|
if (!compatible) {
|
|
@@ -832,7 +843,7 @@ class Decoder {
|
|
|
832
843
|
finalS = currentS;
|
|
833
844
|
}
|
|
834
845
|
else {
|
|
835
|
-
finalS = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName:
|
|
846
|
+
finalS = new Schema_1.Schema(Schema_1.SchemaKind.PRIMITIVE, { typeName: 'null' });
|
|
836
847
|
}
|
|
837
848
|
}
|
|
838
849
|
const node = new Node_1.Node(finalS, { value });
|
|
@@ -845,7 +856,7 @@ class Decoder {
|
|
|
845
856
|
this.pendingMeta = new Meta_1.MetaInfo();
|
|
846
857
|
}
|
|
847
858
|
advance(n = 1) {
|
|
848
|
-
let lastChar =
|
|
859
|
+
let lastChar = '';
|
|
849
860
|
for (let k = 0; k < n; k++) {
|
|
850
861
|
if (this.i >= this.text.length)
|
|
851
862
|
break;
|
|
@@ -873,9 +884,15 @@ class Decoder {
|
|
|
873
884
|
}
|
|
874
885
|
}
|
|
875
886
|
}
|
|
876
|
-
eof() {
|
|
877
|
-
|
|
878
|
-
|
|
887
|
+
eof() {
|
|
888
|
+
return this.i >= this.text.length;
|
|
889
|
+
}
|
|
890
|
+
peek() {
|
|
891
|
+
return this.eof() ? null : this.text[this.i];
|
|
892
|
+
}
|
|
893
|
+
peekNext() {
|
|
894
|
+
return this.i + 1 < this.text.length ? this.text[this.i + 1] : null;
|
|
895
|
+
}
|
|
879
896
|
expect(ch) {
|
|
880
897
|
if (this.peek() !== ch) {
|
|
881
898
|
this.addError(`Expected '${ch}', got '${this.peek()}'`);
|
|
@@ -899,53 +916,62 @@ class Decoder {
|
|
|
899
916
|
return;
|
|
900
917
|
const locStr = `${this.line + 1}:${this.col + 1}`;
|
|
901
918
|
const depth = this.nodeStack.length;
|
|
902
|
-
let treePrefix =
|
|
919
|
+
let treePrefix = '';
|
|
903
920
|
if (depth > 0) {
|
|
904
921
|
// Python: "│ " * (depth - 1)
|
|
905
|
-
treePrefix = Ansi.DIM +
|
|
922
|
+
treePrefix = Ansi.DIM + '│ '.repeat(depth - 1) + '├─ ' + Ansi.RESET;
|
|
906
923
|
}
|
|
907
924
|
const start = Math.max(0, this.i - 10);
|
|
908
925
|
const end = Math.min(this.text.length, this.i + 11);
|
|
909
926
|
// Raw Before: replace newlines, pad start
|
|
910
|
-
const rawBefore = this.text.substring(start, this.i)
|
|
911
|
-
.padStart(10)
|
|
912
|
-
.replace(/\n/g, "↩︎");
|
|
927
|
+
const rawBefore = this.text.substring(start, this.i).padStart(10).replace(/\n/g, '↩︎');
|
|
913
928
|
// Raw Current: handle EOF, replace whitespace
|
|
914
929
|
// Note: undefined check needed if i is out of bounds (EOF)
|
|
915
|
-
const charAtI = this.text[this.i] ||
|
|
916
|
-
const rawCurrent = charAtI
|
|
917
|
-
.replace(/\n/g, "↩︎")
|
|
918
|
-
.replace(/ /g, "·")
|
|
919
|
-
.replace(/\t/g, "→");
|
|
930
|
+
const charAtI = this.text[this.i] || ' ';
|
|
931
|
+
const rawCurrent = charAtI.replace(/\n/g, '↩︎').replace(/ /g, '·').replace(/\t/g, '→');
|
|
920
932
|
// Raw After: replace newlines, pad end
|
|
921
|
-
const rawAfter = this.text
|
|
933
|
+
const rawAfter = this.text
|
|
934
|
+
.substring(this.i + 1, end)
|
|
922
935
|
.padEnd(10)
|
|
923
|
-
.replace(/\n/g,
|
|
936
|
+
.replace(/\n/g, '↩︎');
|
|
924
937
|
const context = `${Ansi.DIM}${rawBefore}${Ansi.RESET}${Ansi.YELLOW}${rawCurrent}${Ansi.RESET}${Ansi.DIM}${rawAfter}${Ansi.RESET}`;
|
|
925
938
|
let msgColor = Ansi.RESET;
|
|
926
|
-
if (msg.includes(
|
|
939
|
+
if (msg.includes('ERROR')) {
|
|
927
940
|
msgColor = Ansi.RED;
|
|
928
941
|
}
|
|
929
|
-
else if (msg.includes(
|
|
942
|
+
else if (msg.includes('WARNING')) {
|
|
930
943
|
msgColor = Ansi.YELLOW;
|
|
931
944
|
}
|
|
932
|
-
else if (msg.includes(
|
|
945
|
+
else if (msg.includes('→')) {
|
|
933
946
|
msgColor = Ansi.GREEN;
|
|
934
947
|
}
|
|
935
|
-
else if (msg.includes(
|
|
948
|
+
else if (msg.includes('PUSH') || msg.includes('POP')) {
|
|
936
949
|
msgColor = Ansi.MAGENTA;
|
|
937
950
|
}
|
|
938
|
-
else if (msg.includes(
|
|
951
|
+
else if (msg.includes('START') || msg.includes('END')) {
|
|
939
952
|
msgColor = Ansi.DIM;
|
|
940
953
|
}
|
|
941
954
|
console.log(`${Ansi.CYAN}|${locStr.padStart(8)}|${Ansi.RESET}${Ansi.DIM} ${Ansi.RESET}${context}${Ansi.DIM}${Ansi.CYAN}|${Ansi.RESET} ${Ansi.YELLOW}${treePrefix}${Ansi.YELLOW}@${depth}${Ansi.RESET} ${Ansi.DIM}|${Ansi.RESET} ${msgColor}${msg}${Ansi.RESET}`);
|
|
942
955
|
}
|
|
943
956
|
}
|
|
944
957
|
exports.Decoder = Decoder;
|
|
945
|
-
Decoder.PRIMITIVES = new Set([
|
|
958
|
+
Decoder.PRIMITIVES = new Set([
|
|
959
|
+
'string',
|
|
960
|
+
'bool',
|
|
961
|
+
'number',
|
|
962
|
+
'null',
|
|
963
|
+
'int',
|
|
964
|
+
'float',
|
|
965
|
+
'binary',
|
|
966
|
+
]);
|
|
946
967
|
Decoder.PRIMITIVES_MAPPING = {
|
|
947
|
-
|
|
948
|
-
|
|
968
|
+
string: 'string',
|
|
969
|
+
bool: 'bool',
|
|
970
|
+
number: 'number',
|
|
971
|
+
null: 'null',
|
|
972
|
+
int: 'number',
|
|
973
|
+
float: 'number',
|
|
974
|
+
binary: 'binary',
|
|
949
975
|
};
|
|
950
976
|
Decoder.MAX_ERRORS = 50;
|
|
951
977
|
//# sourceMappingURL=Decoder.js.map
|