@bcts/dcbor-parse 1.0.0-alpha.15 → 1.0.0-alpha.17
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/index.cjs +165 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +17 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +165 -165
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +165 -165
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/token.ts +117 -117
package/dist/index.cjs
CHANGED
|
@@ -28,120 +28,120 @@ const parseError = {
|
|
|
28
28
|
unexpectedEndOfInput() {
|
|
29
29
|
return { type: "UnexpectedEndOfInput" };
|
|
30
30
|
},
|
|
31
|
-
extraData(span
|
|
31
|
+
extraData(span) {
|
|
32
32
|
return {
|
|
33
33
|
type: "ExtraData",
|
|
34
|
-
span
|
|
34
|
+
span
|
|
35
35
|
};
|
|
36
36
|
},
|
|
37
|
-
unexpectedToken(token
|
|
37
|
+
unexpectedToken(token, span) {
|
|
38
38
|
return {
|
|
39
39
|
type: "UnexpectedToken",
|
|
40
|
-
token
|
|
41
|
-
span
|
|
40
|
+
token,
|
|
41
|
+
span
|
|
42
42
|
};
|
|
43
43
|
},
|
|
44
|
-
unrecognizedToken(span
|
|
44
|
+
unrecognizedToken(span) {
|
|
45
45
|
return {
|
|
46
46
|
type: "UnrecognizedToken",
|
|
47
|
-
span
|
|
47
|
+
span
|
|
48
48
|
};
|
|
49
49
|
},
|
|
50
|
-
expectedComma(span
|
|
50
|
+
expectedComma(span) {
|
|
51
51
|
return {
|
|
52
52
|
type: "ExpectedComma",
|
|
53
|
-
span
|
|
53
|
+
span
|
|
54
54
|
};
|
|
55
55
|
},
|
|
56
|
-
expectedColon(span
|
|
56
|
+
expectedColon(span) {
|
|
57
57
|
return {
|
|
58
58
|
type: "ExpectedColon",
|
|
59
|
-
span
|
|
59
|
+
span
|
|
60
60
|
};
|
|
61
61
|
},
|
|
62
|
-
unmatchedParentheses(span
|
|
62
|
+
unmatchedParentheses(span) {
|
|
63
63
|
return {
|
|
64
64
|
type: "UnmatchedParentheses",
|
|
65
|
-
span
|
|
65
|
+
span
|
|
66
66
|
};
|
|
67
67
|
},
|
|
68
|
-
unmatchedBraces(span
|
|
68
|
+
unmatchedBraces(span) {
|
|
69
69
|
return {
|
|
70
70
|
type: "UnmatchedBraces",
|
|
71
|
-
span
|
|
71
|
+
span
|
|
72
72
|
};
|
|
73
73
|
},
|
|
74
|
-
expectedMapKey(span
|
|
74
|
+
expectedMapKey(span) {
|
|
75
75
|
return {
|
|
76
76
|
type: "ExpectedMapKey",
|
|
77
|
-
span
|
|
77
|
+
span
|
|
78
78
|
};
|
|
79
79
|
},
|
|
80
|
-
invalidTagValue(value, span
|
|
80
|
+
invalidTagValue(value, span) {
|
|
81
81
|
return {
|
|
82
82
|
type: "InvalidTagValue",
|
|
83
83
|
value,
|
|
84
|
-
span
|
|
84
|
+
span
|
|
85
85
|
};
|
|
86
86
|
},
|
|
87
|
-
unknownTagName(name, span
|
|
87
|
+
unknownTagName(name, span) {
|
|
88
88
|
return {
|
|
89
89
|
type: "UnknownTagName",
|
|
90
90
|
name,
|
|
91
|
-
span
|
|
91
|
+
span
|
|
92
92
|
};
|
|
93
93
|
},
|
|
94
|
-
invalidHexString(span
|
|
94
|
+
invalidHexString(span) {
|
|
95
95
|
return {
|
|
96
96
|
type: "InvalidHexString",
|
|
97
|
-
span
|
|
97
|
+
span
|
|
98
98
|
};
|
|
99
99
|
},
|
|
100
|
-
invalidBase64String(span
|
|
100
|
+
invalidBase64String(span) {
|
|
101
101
|
return {
|
|
102
102
|
type: "InvalidBase64String",
|
|
103
|
-
span
|
|
103
|
+
span
|
|
104
104
|
};
|
|
105
105
|
},
|
|
106
|
-
unknownUrType(urType, span
|
|
106
|
+
unknownUrType(urType, span) {
|
|
107
107
|
return {
|
|
108
108
|
type: "UnknownUrType",
|
|
109
109
|
urType,
|
|
110
|
-
span
|
|
110
|
+
span
|
|
111
111
|
};
|
|
112
112
|
},
|
|
113
|
-
invalidUr(message, span
|
|
113
|
+
invalidUr(message, span) {
|
|
114
114
|
return {
|
|
115
115
|
type: "InvalidUr",
|
|
116
116
|
message,
|
|
117
|
-
span
|
|
117
|
+
span
|
|
118
118
|
};
|
|
119
119
|
},
|
|
120
|
-
invalidKnownValue(value, span
|
|
120
|
+
invalidKnownValue(value, span) {
|
|
121
121
|
return {
|
|
122
122
|
type: "InvalidKnownValue",
|
|
123
123
|
value,
|
|
124
|
-
span
|
|
124
|
+
span
|
|
125
125
|
};
|
|
126
126
|
},
|
|
127
|
-
unknownKnownValueName(name, span
|
|
127
|
+
unknownKnownValueName(name, span) {
|
|
128
128
|
return {
|
|
129
129
|
type: "UnknownKnownValueName",
|
|
130
130
|
name,
|
|
131
|
-
span
|
|
131
|
+
span
|
|
132
132
|
};
|
|
133
133
|
},
|
|
134
|
-
invalidDateString(dateString, span
|
|
134
|
+
invalidDateString(dateString, span) {
|
|
135
135
|
return {
|
|
136
136
|
type: "InvalidDateString",
|
|
137
137
|
dateString,
|
|
138
|
-
span
|
|
138
|
+
span
|
|
139
139
|
};
|
|
140
140
|
},
|
|
141
|
-
duplicateMapKey(span
|
|
141
|
+
duplicateMapKey(span) {
|
|
142
142
|
return {
|
|
143
143
|
type: "DuplicateMapKey",
|
|
144
|
-
span
|
|
144
|
+
span
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
};
|
|
@@ -311,8 +311,8 @@ function unwrapErr(result) {
|
|
|
311
311
|
if (!result.ok) return result.error;
|
|
312
312
|
throw new Error("Called unwrapErr on an Ok result");
|
|
313
313
|
}
|
|
314
|
-
function tokenDebugString(token
|
|
315
|
-
return JSON.stringify(token
|
|
314
|
+
function tokenDebugString(token) {
|
|
315
|
+
return JSON.stringify(token);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
//#endregion
|
|
@@ -437,65 +437,65 @@ const token = {
|
|
|
437
437
|
* Corresponds to the Rust `logos::Lexer` used in parse.rs
|
|
438
438
|
*/
|
|
439
439
|
var Lexer = class {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
440
|
+
_source;
|
|
441
|
+
_position;
|
|
442
|
+
_tokenStart;
|
|
443
|
+
_tokenEnd;
|
|
444
444
|
constructor(source) {
|
|
445
|
-
this
|
|
446
|
-
this
|
|
447
|
-
this
|
|
448
|
-
this
|
|
445
|
+
this._source = source;
|
|
446
|
+
this._position = 0;
|
|
447
|
+
this._tokenStart = 0;
|
|
448
|
+
this._tokenEnd = 0;
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
451
|
* Gets the current span (position range of the last token).
|
|
452
452
|
*/
|
|
453
453
|
span() {
|
|
454
|
-
return span(this
|
|
454
|
+
return span(this._tokenStart, this._tokenEnd);
|
|
455
455
|
}
|
|
456
456
|
/**
|
|
457
457
|
* Gets the slice of source corresponding to the last token.
|
|
458
458
|
*/
|
|
459
459
|
slice() {
|
|
460
|
-
return this
|
|
460
|
+
return this._source.slice(this._tokenStart, this._tokenEnd);
|
|
461
461
|
}
|
|
462
462
|
/**
|
|
463
463
|
* Gets the next token, or undefined if at end of input.
|
|
464
464
|
* Returns a Result to handle lexing errors.
|
|
465
465
|
*/
|
|
466
466
|
next() {
|
|
467
|
-
this
|
|
468
|
-
if (this
|
|
469
|
-
this
|
|
470
|
-
const result = this
|
|
467
|
+
this._skipWhitespaceAndComments();
|
|
468
|
+
if (this._position >= this._source.length) return;
|
|
469
|
+
this._tokenStart = this._position;
|
|
470
|
+
const result = this._tryMatchKeyword() ?? this._tryMatchDateLiteral() ?? this._tryMatchTagValueOrNumber() ?? this._tryMatchTagName() ?? this._tryMatchString() ?? this._tryMatchByteStringHex() ?? this._tryMatchByteStringBase64() ?? this._tryMatchKnownValue() ?? this._tryMatchUR() ?? this._tryMatchPunctuation();
|
|
471
471
|
if (result === void 0) {
|
|
472
|
-
this
|
|
473
|
-
this
|
|
472
|
+
this._position++;
|
|
473
|
+
this._tokenEnd = this._position;
|
|
474
474
|
return err(parseError.unrecognizedToken(this.span()));
|
|
475
475
|
}
|
|
476
476
|
return result;
|
|
477
477
|
}
|
|
478
|
-
|
|
479
|
-
while (this
|
|
480
|
-
const ch = this
|
|
478
|
+
_skipWhitespaceAndComments() {
|
|
479
|
+
while (this._position < this._source.length) {
|
|
480
|
+
const ch = this._source[this._position];
|
|
481
481
|
if (ch === " " || ch === " " || ch === "\r" || ch === "\n" || ch === "\f") {
|
|
482
|
-
this
|
|
482
|
+
this._position++;
|
|
483
483
|
continue;
|
|
484
484
|
}
|
|
485
|
-
if (ch === "/" && this
|
|
486
|
-
this
|
|
487
|
-
while (this
|
|
488
|
-
if (this
|
|
485
|
+
if (ch === "/" && this._position + 1 < this._source.length && this._source[this._position + 1] !== "/") {
|
|
486
|
+
this._position++;
|
|
487
|
+
while (this._position < this._source.length && this._source[this._position] !== "/") this._position++;
|
|
488
|
+
if (this._position < this._source.length) this._position++;
|
|
489
489
|
continue;
|
|
490
490
|
}
|
|
491
491
|
if (ch === "#") {
|
|
492
|
-
while (this
|
|
492
|
+
while (this._position < this._source.length && this._source[this._position] !== "\n") this._position++;
|
|
493
493
|
continue;
|
|
494
494
|
}
|
|
495
495
|
break;
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
|
-
|
|
498
|
+
_tryMatchKeyword() {
|
|
499
499
|
const keywords = [
|
|
500
500
|
["true", token.bool(true)],
|
|
501
501
|
["false", token.bool(false)],
|
|
@@ -505,23 +505,23 @@ var Lexer = class {
|
|
|
505
505
|
["-Infinity", token.negInfinity()],
|
|
506
506
|
["Unit", token.unit()]
|
|
507
507
|
];
|
|
508
|
-
for (const [keyword, tok] of keywords) if (this
|
|
509
|
-
const nextChar = this
|
|
510
|
-
if (nextChar === void 0 || !this
|
|
511
|
-
this
|
|
508
|
+
for (const [keyword, tok] of keywords) if (this._matchLiteral(keyword)) {
|
|
509
|
+
const nextChar = this._source[this._position];
|
|
510
|
+
if (nextChar === void 0 || !this._isIdentifierChar(nextChar)) {
|
|
511
|
+
this._tokenEnd = this._position;
|
|
512
512
|
return ok(tok);
|
|
513
513
|
}
|
|
514
|
-
this
|
|
514
|
+
this._position = this._tokenStart;
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
-
|
|
517
|
+
_tryMatchDateLiteral() {
|
|
518
518
|
const dateRegex = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/;
|
|
519
|
-
const remaining = this
|
|
519
|
+
const remaining = this._source.slice(this._position);
|
|
520
520
|
const match = dateRegex.exec(remaining);
|
|
521
521
|
if (match !== null) {
|
|
522
522
|
const dateStr = match[0];
|
|
523
|
-
this
|
|
524
|
-
this
|
|
523
|
+
this._position += dateStr.length;
|
|
524
|
+
this._tokenEnd = this._position;
|
|
525
525
|
if (!isValidDateString(dateStr)) return err(parseError.invalidDateString(dateStr, this.span()));
|
|
526
526
|
try {
|
|
527
527
|
const date = _bcts_dcbor.CborDate.fromString(dateStr);
|
|
@@ -531,91 +531,91 @@ var Lexer = class {
|
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
|
-
|
|
534
|
+
_tryMatchTagValueOrNumber() {
|
|
535
535
|
const numberRegex = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
536
|
-
const remaining = this
|
|
536
|
+
const remaining = this._source.slice(this._position);
|
|
537
537
|
const match = numberRegex.exec(remaining);
|
|
538
538
|
if (match !== null) {
|
|
539
539
|
const numStr = match[0];
|
|
540
|
-
if (this
|
|
541
|
-
this
|
|
542
|
-
this
|
|
540
|
+
if (this._source[this._position + numStr.length] === "(" && !numStr.includes(".") && !numStr.includes("e") && !numStr.includes("E") && !numStr.startsWith("-")) {
|
|
541
|
+
this._position += numStr.length + 1;
|
|
542
|
+
this._tokenEnd = this._position;
|
|
543
543
|
const tagValue = parseInt(numStr, 10);
|
|
544
|
-
if (!Number.isSafeInteger(tagValue) || tagValue < 0) return err(parseError.invalidTagValue(numStr, span(this
|
|
544
|
+
if (!Number.isSafeInteger(tagValue) || tagValue < 0) return err(parseError.invalidTagValue(numStr, span(this._tokenStart, this._tokenStart + numStr.length)));
|
|
545
545
|
return ok(token.tagValue(tagValue));
|
|
546
546
|
}
|
|
547
|
-
this
|
|
548
|
-
this
|
|
547
|
+
this._position += numStr.length;
|
|
548
|
+
this._tokenEnd = this._position;
|
|
549
549
|
const num = parseFloat(numStr);
|
|
550
550
|
return ok(token.number(num));
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
|
-
|
|
553
|
+
_tryMatchTagName() {
|
|
554
554
|
const tagNameRegex = /^[a-zA-Z_][a-zA-Z0-9_-]*\(/;
|
|
555
|
-
const remaining = this
|
|
555
|
+
const remaining = this._source.slice(this._position);
|
|
556
556
|
const match = tagNameRegex.exec(remaining);
|
|
557
557
|
if (match !== null) {
|
|
558
558
|
const fullMatch = match[0];
|
|
559
559
|
const name = fullMatch.slice(0, -1);
|
|
560
|
-
this
|
|
561
|
-
this
|
|
560
|
+
this._position += fullMatch.length;
|
|
561
|
+
this._tokenEnd = this._position;
|
|
562
562
|
return ok(token.tagName(name));
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
|
-
|
|
566
|
-
if (this
|
|
565
|
+
_tryMatchString() {
|
|
566
|
+
if (this._source[this._position] !== "\"") return;
|
|
567
567
|
const stringRegex = /^"([^"\\\x00-\x1F]|\\(["\\bnfrt/]|u[a-fA-F0-9]{4}))*"/;
|
|
568
|
-
const remaining = this
|
|
568
|
+
const remaining = this._source.slice(this._position);
|
|
569
569
|
const match = stringRegex.exec(remaining);
|
|
570
570
|
if (match !== null) {
|
|
571
571
|
const fullMatch = match[0];
|
|
572
|
-
this
|
|
573
|
-
this
|
|
572
|
+
this._position += fullMatch.length;
|
|
573
|
+
this._tokenEnd = this._position;
|
|
574
574
|
return ok(token.string(fullMatch));
|
|
575
575
|
}
|
|
576
|
-
this
|
|
577
|
-
while (this
|
|
578
|
-
const ch = this
|
|
576
|
+
this._position++;
|
|
577
|
+
while (this._position < this._source.length) {
|
|
578
|
+
const ch = this._source[this._position];
|
|
579
579
|
if (ch === "\"" || ch === "\n") {
|
|
580
|
-
if (ch === "\"") this
|
|
580
|
+
if (ch === "\"") this._position++;
|
|
581
581
|
break;
|
|
582
582
|
}
|
|
583
|
-
if (ch === "\\") this
|
|
584
|
-
else this
|
|
583
|
+
if (ch === "\\") this._position += 2;
|
|
584
|
+
else this._position++;
|
|
585
585
|
}
|
|
586
|
-
this
|
|
586
|
+
this._tokenEnd = this._position;
|
|
587
587
|
return err(parseError.unrecognizedToken(this.span()));
|
|
588
588
|
}
|
|
589
|
-
|
|
590
|
-
if (!this
|
|
589
|
+
_tryMatchByteStringHex() {
|
|
590
|
+
if (!this._matchLiteral("h'")) return;
|
|
591
591
|
const hexRegex = /^[0-9a-fA-F]*/;
|
|
592
|
-
const remaining = this
|
|
592
|
+
const remaining = this._source.slice(this._position);
|
|
593
593
|
const match = hexRegex.exec(remaining);
|
|
594
594
|
const hexPart = match !== null ? match[0] : "";
|
|
595
|
-
this
|
|
596
|
-
if (this
|
|
597
|
-
this
|
|
595
|
+
this._position += hexPart.length;
|
|
596
|
+
if (this._source[this._position] !== "'") {
|
|
597
|
+
this._tokenEnd = this._position;
|
|
598
598
|
return err(parseError.invalidHexString(this.span()));
|
|
599
599
|
}
|
|
600
|
-
this
|
|
601
|
-
this
|
|
600
|
+
this._position++;
|
|
601
|
+
this._tokenEnd = this._position;
|
|
602
602
|
if (hexPart.length % 2 !== 0) return err(parseError.invalidHexString(this.span()));
|
|
603
603
|
const bytes = hexToBytes(hexPart);
|
|
604
604
|
return ok(token.byteStringHex(bytes));
|
|
605
605
|
}
|
|
606
|
-
|
|
607
|
-
if (!this
|
|
606
|
+
_tryMatchByteStringBase64() {
|
|
607
|
+
if (!this._matchLiteral("b64'")) return;
|
|
608
608
|
const base64Regex = /^[A-Za-z0-9+/=]*/;
|
|
609
|
-
const remaining = this
|
|
609
|
+
const remaining = this._source.slice(this._position);
|
|
610
610
|
const match = base64Regex.exec(remaining);
|
|
611
611
|
const base64Part = match !== null ? match[0] : "";
|
|
612
|
-
this
|
|
613
|
-
if (this
|
|
614
|
-
this
|
|
612
|
+
this._position += base64Part.length;
|
|
613
|
+
if (this._source[this._position] !== "'") {
|
|
614
|
+
this._tokenEnd = this._position;
|
|
615
615
|
return err(parseError.invalidBase64String(this.span()));
|
|
616
616
|
}
|
|
617
|
-
this
|
|
618
|
-
this
|
|
617
|
+
this._position++;
|
|
618
|
+
this._tokenEnd = this._position;
|
|
619
619
|
if (base64Part.length < 2) return err(parseError.invalidBase64String(this.span()));
|
|
620
620
|
try {
|
|
621
621
|
const bytes = base64ToBytes(base64Part);
|
|
@@ -624,47 +624,47 @@ var Lexer = class {
|
|
|
624
624
|
return err(parseError.invalidBase64String(this.span()));
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
|
-
|
|
628
|
-
if (this
|
|
629
|
-
if (this
|
|
630
|
-
this
|
|
631
|
-
this
|
|
627
|
+
_tryMatchKnownValue() {
|
|
628
|
+
if (this._source[this._position] !== "'") return;
|
|
629
|
+
if (this._source[this._position + 1] === "'") {
|
|
630
|
+
this._position += 2;
|
|
631
|
+
this._tokenEnd = this._position;
|
|
632
632
|
return ok(token.knownValueName(""));
|
|
633
633
|
}
|
|
634
634
|
const numericRegex = /^'(0|[1-9][0-9]*)'/;
|
|
635
|
-
const remaining = this
|
|
635
|
+
const remaining = this._source.slice(this._position);
|
|
636
636
|
let match = numericRegex.exec(remaining);
|
|
637
637
|
if (match !== null) {
|
|
638
638
|
const fullMatch = match[0];
|
|
639
639
|
const numStr = match[1];
|
|
640
|
-
this
|
|
641
|
-
this
|
|
640
|
+
this._position += fullMatch.length;
|
|
641
|
+
this._tokenEnd = this._position;
|
|
642
642
|
const value = parseInt(numStr, 10);
|
|
643
|
-
if (!Number.isSafeInteger(value) || value < 0) return err(parseError.invalidKnownValue(numStr, span(this
|
|
643
|
+
if (!Number.isSafeInteger(value) || value < 0) return err(parseError.invalidKnownValue(numStr, span(this._tokenStart + 1, this._tokenEnd - 1)));
|
|
644
644
|
return ok(token.knownValueNumber(value));
|
|
645
645
|
}
|
|
646
646
|
match = /^'([a-zA-Z_][a-zA-Z0-9_-]*)'/.exec(remaining);
|
|
647
647
|
if (match !== null) {
|
|
648
648
|
const fullMatch = match[0];
|
|
649
649
|
const name = match[1];
|
|
650
|
-
this
|
|
651
|
-
this
|
|
650
|
+
this._position += fullMatch.length;
|
|
651
|
+
this._tokenEnd = this._position;
|
|
652
652
|
return ok(token.knownValueName(name));
|
|
653
653
|
}
|
|
654
|
-
this
|
|
655
|
-
while (this
|
|
656
|
-
if (this
|
|
657
|
-
this
|
|
654
|
+
this._position++;
|
|
655
|
+
while (this._position < this._source.length && this._source[this._position] !== "'") this._position++;
|
|
656
|
+
if (this._position < this._source.length) this._position++;
|
|
657
|
+
this._tokenEnd = this._position;
|
|
658
658
|
return err(parseError.unrecognizedToken(this.span()));
|
|
659
659
|
}
|
|
660
|
-
|
|
660
|
+
_tryMatchUR() {
|
|
661
661
|
const urRegex = /^ur:([a-zA-Z0-9][a-zA-Z0-9-]*)\/([a-zA-Z]{8,})/;
|
|
662
|
-
const remaining = this
|
|
662
|
+
const remaining = this._source.slice(this._position);
|
|
663
663
|
const match = urRegex.exec(remaining);
|
|
664
664
|
if (match !== null) {
|
|
665
665
|
const fullMatch = match[0];
|
|
666
|
-
this
|
|
667
|
-
this
|
|
666
|
+
this._position += fullMatch.length;
|
|
667
|
+
this._tokenEnd = this._position;
|
|
668
668
|
try {
|
|
669
669
|
const ur = _bcts_uniform_resources.UR.fromURString(fullMatch);
|
|
670
670
|
return ok(token.ur(ur));
|
|
@@ -674,8 +674,8 @@ var Lexer = class {
|
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
}
|
|
677
|
-
|
|
678
|
-
const ch = this
|
|
677
|
+
_tryMatchPunctuation() {
|
|
678
|
+
const ch = this._source[this._position];
|
|
679
679
|
const matched = {
|
|
680
680
|
"{": token.braceOpen(),
|
|
681
681
|
"}": token.braceClose(),
|
|
@@ -687,19 +687,19 @@ var Lexer = class {
|
|
|
687
687
|
",": token.comma()
|
|
688
688
|
}[ch];
|
|
689
689
|
if (matched !== void 0) {
|
|
690
|
-
this
|
|
691
|
-
this
|
|
690
|
+
this._position++;
|
|
691
|
+
this._tokenEnd = this._position;
|
|
692
692
|
return ok(matched);
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
|
-
|
|
696
|
-
if (this
|
|
697
|
-
this
|
|
695
|
+
_matchLiteral(literal) {
|
|
696
|
+
if (this._source.slice(this._position, this._position + literal.length) === literal) {
|
|
697
|
+
this._position += literal.length;
|
|
698
698
|
return true;
|
|
699
699
|
}
|
|
700
700
|
return false;
|
|
701
701
|
}
|
|
702
|
-
|
|
702
|
+
_isIdentifierChar(ch) {
|
|
703
703
|
return /[a-zA-Z0-9_-]/.test(ch);
|
|
704
704
|
}
|
|
705
705
|
};
|
|
@@ -856,28 +856,28 @@ function expectToken(lexer) {
|
|
|
856
856
|
}
|
|
857
857
|
return result;
|
|
858
858
|
}
|
|
859
|
-
function parseItemToken(token
|
|
860
|
-
switch (token
|
|
861
|
-
case "Bool": return ok((0, _bcts_dcbor.cbor)(token
|
|
859
|
+
function parseItemToken(token, lexer) {
|
|
860
|
+
switch (token.type) {
|
|
861
|
+
case "Bool": return ok((0, _bcts_dcbor.cbor)(token.value));
|
|
862
862
|
case "Null": return ok((0, _bcts_dcbor.cbor)(null));
|
|
863
|
-
case "ByteStringHex": return ok((0, _bcts_dcbor.cbor)(token
|
|
864
|
-
case "ByteStringBase64": return ok((0, _bcts_dcbor.cbor)(token
|
|
865
|
-
case "DateLiteral": return ok((0, _bcts_dcbor.cbor)(token
|
|
866
|
-
case "Number": return ok((0, _bcts_dcbor.cbor)(token
|
|
863
|
+
case "ByteStringHex": return ok((0, _bcts_dcbor.cbor)(token.value));
|
|
864
|
+
case "ByteStringBase64": return ok((0, _bcts_dcbor.cbor)(token.value));
|
|
865
|
+
case "DateLiteral": return ok((0, _bcts_dcbor.cbor)(token.value));
|
|
866
|
+
case "Number": return ok((0, _bcts_dcbor.cbor)(token.value));
|
|
867
867
|
case "NaN": return ok((0, _bcts_dcbor.cbor)(NaN));
|
|
868
868
|
case "Infinity": return ok((0, _bcts_dcbor.cbor)(Number.POSITIVE_INFINITY));
|
|
869
869
|
case "NegInfinity": return ok((0, _bcts_dcbor.cbor)(Number.NEGATIVE_INFINITY));
|
|
870
|
-
case "String": return parseString(token
|
|
871
|
-
case "UR": return parseUr(token
|
|
872
|
-
case "TagValue": return parseNumberTag(token
|
|
873
|
-
case "TagName": return parseNameTag(token
|
|
874
|
-
case "KnownValueNumber": return ok(new _bcts_known_values.KnownValue(token
|
|
870
|
+
case "String": return parseString(token.value, lexer.span());
|
|
871
|
+
case "UR": return parseUr(token.value, lexer.span());
|
|
872
|
+
case "TagValue": return parseNumberTag(token.value, lexer);
|
|
873
|
+
case "TagName": return parseNameTag(token.value, lexer);
|
|
874
|
+
case "KnownValueNumber": return ok(new _bcts_known_values.KnownValue(token.value).taggedCbor());
|
|
875
875
|
case "KnownValueName": {
|
|
876
|
-
if (token
|
|
877
|
-
const knownValue = knownValueForName(token
|
|
876
|
+
if (token.value === "") return ok(new _bcts_known_values.KnownValue(0).taggedCbor());
|
|
877
|
+
const knownValue = knownValueForName(token.value);
|
|
878
878
|
if (knownValue !== void 0) return ok(knownValue.taggedCbor());
|
|
879
879
|
const tokenSpan = lexer.span();
|
|
880
|
-
return err(parseError.unknownKnownValueName(token
|
|
880
|
+
return err(parseError.unknownKnownValueName(token.value, span(tokenSpan.start + 1, tokenSpan.end - 1)));
|
|
881
881
|
}
|
|
882
882
|
case "Unit": return ok(new _bcts_known_values.KnownValue(0).taggedCbor());
|
|
883
883
|
case "BracketOpen": return parseArray(lexer);
|
|
@@ -887,7 +887,7 @@ function parseItemToken(token$1, lexer) {
|
|
|
887
887
|
case "ParenthesisOpen":
|
|
888
888
|
case "ParenthesisClose":
|
|
889
889
|
case "Colon":
|
|
890
|
-
case "Comma": return err(parseError.unexpectedToken(token
|
|
890
|
+
case "Comma": return err(parseError.unexpectedToken(token, lexer.span()));
|
|
891
891
|
}
|
|
892
892
|
}
|
|
893
893
|
function parseString(s, tokenSpan) {
|
|
@@ -946,15 +946,15 @@ function parseArray(lexer) {
|
|
|
946
946
|
while (true) {
|
|
947
947
|
const tokenResult = expectToken(lexer);
|
|
948
948
|
if (!tokenResult.ok) return tokenResult;
|
|
949
|
-
const token
|
|
950
|
-
if (token
|
|
951
|
-
if (token
|
|
949
|
+
const token = tokenResult.value;
|
|
950
|
+
if (token.type === "BracketClose" && !awaitsItem) return ok((0, _bcts_dcbor.cbor)(items));
|
|
951
|
+
if (token.type === "Comma" && awaitsComma) {
|
|
952
952
|
awaitsItem = true;
|
|
953
953
|
awaitsComma = false;
|
|
954
954
|
continue;
|
|
955
955
|
}
|
|
956
956
|
if (awaitsComma) return err(parseError.expectedComma(lexer.span()));
|
|
957
|
-
const itemResult = parseItemToken(token
|
|
957
|
+
const itemResult = parseItemToken(token, lexer);
|
|
958
958
|
if (!itemResult.ok) return itemResult;
|
|
959
959
|
items.push(itemResult.value);
|
|
960
960
|
awaitsItem = false;
|
|
@@ -971,15 +971,15 @@ function parseMap(lexer) {
|
|
|
971
971
|
if (tokenResult.error.type === "UnexpectedEndOfInput") return err(parseError.unmatchedBraces(lexer.span()));
|
|
972
972
|
return tokenResult;
|
|
973
973
|
}
|
|
974
|
-
const token
|
|
975
|
-
if (token
|
|
976
|
-
if (token
|
|
974
|
+
const token = tokenResult.value;
|
|
975
|
+
if (token.type === "BraceClose" && !awaitsKey) return ok((0, _bcts_dcbor.cbor)(map));
|
|
976
|
+
if (token.type === "Comma" && awaitsComma) {
|
|
977
977
|
awaitsKey = true;
|
|
978
978
|
awaitsComma = false;
|
|
979
979
|
continue;
|
|
980
980
|
}
|
|
981
981
|
if (awaitsComma) return err(parseError.expectedComma(lexer.span()));
|
|
982
|
-
const keyResult = parseItemToken(token
|
|
982
|
+
const keyResult = parseItemToken(token, lexer);
|
|
983
983
|
if (!keyResult.ok) return keyResult;
|
|
984
984
|
const key = keyResult.value;
|
|
985
985
|
const keySpan = lexer.span();
|