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