@cbortech/cbor 0.25.9 → 0.25.10
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/README.ja.md +28 -4
- package/README.md +28 -4
- package/dist/ast/CborByteString.d.ts +9 -0
- package/dist/ast/CborFloat.d.ts +9 -0
- package/dist/ast/CborTextString.d.ts +3 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor/encode.d.ts +11 -0
- package/dist/cbor.d.ts +8 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +36 -0
- package/dist/cdn/tokenizer.d.ts +37 -2
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -75
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-B-INYL6l.cjs +11 -0
- package/dist/mapEntries-B-INYL6l.cjs.map +1 -0
- package/dist/{mapEntries-I8f0WuwK.js → mapEntries-B8riGPMD.js} +1027 -867
- package/dist/mapEntries-B8riGPMD.js.map +1 -0
- package/dist/tokenizer-CVcIyZZa.cjs +30 -0
- package/dist/tokenizer-CVcIyZZa.cjs.map +1 -0
- package/dist/{tokenizer-CETZf2NR.js → tokenizer-DkLlZ1gc.js} +161 -349
- package/dist/tokenizer-DkLlZ1gc.js.map +1 -0
- package/dist/types.d.ts +56 -1
- package/dist/utils/hex.d.ts +5 -0
- package/package.json +3 -3
- package/dist/mapEntries-BkcJsv3C.cjs +0 -12
- package/dist/mapEntries-BkcJsv3C.cjs.map +0 -1
- package/dist/mapEntries-I8f0WuwK.js.map +0 -1
- package/dist/tokenizer-CETZf2NR.js.map +0 -1
- package/dist/tokenizer-CMK8MtYl.cjs +0 -30
- package/dist/tokenizer-CMK8MtYl.cjs.map +0 -1
|
@@ -8,10 +8,41 @@ var e = class extends SyntaxError {
|
|
|
8
8
|
let n = t?.line === void 0 ? "" : ` at line ${t.line}, column ${t.column}`;
|
|
9
9
|
super(`EDN parse error${n}: ${e}`), this.name = "CdnSyntaxError", this.offset = t?.offset, this.line = t?.line, this.column = t?.column, this.endOffset = t?.endOffset;
|
|
10
10
|
}
|
|
11
|
-
};
|
|
11
|
+
}, t = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0")), n = (/* @__PURE__ */ new Int8Array(128)).fill(-1);
|
|
12
|
+
for (let e = 0; e < 16; e++) n["0123456789abcdef".charCodeAt(e)] = e, n["0123456789ABCDEF".charCodeAt(e)] = e;
|
|
13
|
+
var r = typeof Uint8Array.prototype.toHex == "function", i = typeof Uint8Array.fromHex == "function", a = 256;
|
|
14
|
+
function o(e) {
|
|
15
|
+
if (r) return e.toHex();
|
|
16
|
+
let n = "";
|
|
17
|
+
for (let r = 0; r < e.length; r++) n += t[e[r]];
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
var s = Array.from({ length: 256 }, (e, t) => t.toString(16).toUpperCase().padStart(2, "0"));
|
|
21
|
+
function c(e) {
|
|
22
|
+
return s[e];
|
|
23
|
+
}
|
|
24
|
+
function l(e) {
|
|
25
|
+
let t = "";
|
|
26
|
+
for (let n = 0; n < e.length; n++) n > 0 && (t += " "), t += s[e[n]];
|
|
27
|
+
return t;
|
|
28
|
+
}
|
|
29
|
+
function u(e) {
|
|
30
|
+
if (e.length % 2 != 0) throw SyntaxError(`hex string has odd length: ${e.length}`);
|
|
31
|
+
if (i && e.length >= a) return Uint8Array.fromHex(e);
|
|
32
|
+
let t = new Uint8Array(e.length / 2);
|
|
33
|
+
for (let r = 0, i = 0; r < e.length; r += 2, i++) {
|
|
34
|
+
let a = e.charCodeAt(r), o = e.charCodeAt(r + 1), s = a < 128 ? n[a] : -1, c = o < 128 ? n[o] : -1;
|
|
35
|
+
if ((s | c) < 0) {
|
|
36
|
+
let t = s < 0 ? e[r] : e[r + 1];
|
|
37
|
+
throw SyntaxError(`invalid character ${JSON.stringify(t)} in hex string`);
|
|
38
|
+
}
|
|
39
|
+
t[i] = s << 4 | c;
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
12
43
|
//#endregion
|
|
13
44
|
//#region src/cdn/tokenizer.ts
|
|
14
|
-
function
|
|
45
|
+
function d(e, t, n) {
|
|
15
46
|
let r = 1, i = 1;
|
|
16
47
|
for (let a = 0; a < e.length; a++) {
|
|
17
48
|
if (r === t && i === n) return a;
|
|
@@ -19,7 +50,7 @@ function t(e, t, n) {
|
|
|
19
50
|
}
|
|
20
51
|
return e.length;
|
|
21
52
|
}
|
|
22
|
-
function
|
|
53
|
+
function f(e, t) {
|
|
23
54
|
let n = 1, r = 1;
|
|
24
55
|
for (let i = 0; i < t; i++) e[i] === "\n" ? (n++, r = 1) : r++;
|
|
25
56
|
return {
|
|
@@ -27,10 +58,10 @@ function n(e, t) {
|
|
|
27
58
|
col: r
|
|
28
59
|
};
|
|
29
60
|
}
|
|
30
|
-
function
|
|
61
|
+
function p(e) {
|
|
31
62
|
return e >= 48 && e <= 57 || e >= 97 && e <= 102 || e >= 65 && e <= 70;
|
|
32
63
|
}
|
|
33
|
-
var
|
|
64
|
+
var m = new TextEncoder(), h = class {
|
|
34
65
|
input;
|
|
35
66
|
pos;
|
|
36
67
|
line;
|
|
@@ -42,10 +73,10 @@ var i = new TextEncoder(), a = class {
|
|
|
42
73
|
onEscapeWarning;
|
|
43
74
|
constructor(e, t) {
|
|
44
75
|
this.input = e;
|
|
45
|
-
let
|
|
46
|
-
if (this.skipRS = t?.skipRS ?? !1, !Number.isInteger(
|
|
47
|
-
let
|
|
48
|
-
this.pos =
|
|
76
|
+
let n = t?.offset ?? 0;
|
|
77
|
+
if (this.skipRS = t?.skipRS ?? !1, !Number.isInteger(n) || n < 0 || n > e.length) throw RangeError(`EDN parse offset must be an integer between 0 and ${e.length}`);
|
|
78
|
+
let r = f(e, n);
|
|
79
|
+
this.pos = n, this.line = r.line, this.col = r.col, this._lastConsumedEndOffset = n;
|
|
49
80
|
}
|
|
50
81
|
peek() {
|
|
51
82
|
return this._peeked === null && (this._peeked = this._readNext()), this._peeked;
|
|
@@ -70,11 +101,13 @@ var i = new TextEncoder(), a = class {
|
|
|
70
101
|
let e = this.input[this.pos++] ?? "";
|
|
71
102
|
return e === "\n" ? (this.line++, this.col = 1) : this.col++, e;
|
|
72
103
|
}
|
|
73
|
-
_fail(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
_fail(t, n = this.line, r = this.col) {
|
|
105
|
+
let i = n === this.line && r === this.col ? this.pos : d(this.input, n, r);
|
|
106
|
+
throw new e(t, {
|
|
107
|
+
offset: i,
|
|
108
|
+
line: n,
|
|
109
|
+
column: r,
|
|
110
|
+
endOffset: Math.min(Math.max(this.pos, i + 1), this.input.length)
|
|
78
111
|
});
|
|
79
112
|
}
|
|
80
113
|
_skipWS() {
|
|
@@ -315,29 +348,29 @@ var i = new TextEncoder(), a = class {
|
|
|
315
348
|
}
|
|
316
349
|
if (this.onEscapeWarning) {
|
|
317
350
|
if (a === "0") {
|
|
318
|
-
this.onEscapeWarning("\\0 is a non-standard escape sequence; use \\u0000 instead", t, n, i), r += "\0";
|
|
351
|
+
this.onEscapeWarning("\\0 is a non-standard escape sequence; use \\u0000 instead", t, n, i, this.pos), r += "\0";
|
|
319
352
|
break;
|
|
320
353
|
}
|
|
321
354
|
if (a === "v") {
|
|
322
|
-
this.onEscapeWarning("\\v is a non-standard escape sequence; use \\u000b instead", t, n, i), r += "\v";
|
|
355
|
+
this.onEscapeWarning("\\v is a non-standard escape sequence; use \\u000b instead", t, n, i, this.pos), r += "\v";
|
|
323
356
|
break;
|
|
324
357
|
}
|
|
325
358
|
if (a === "x") {
|
|
326
359
|
let e = this._ch(), a = this.input[this.pos + 1] ?? "";
|
|
327
360
|
(!/[0-9a-fA-F]/.test(e) || !/[0-9a-fA-F]/.test(a)) && this._fail("\\x escape requires exactly two hex digits", n, i), this._advance(), this._advance();
|
|
328
361
|
let o = parseInt(e + a, 16);
|
|
329
|
-
this.onEscapeWarning(`\\x${e}${a} is a non-standard escape sequence; use \\u00${e}${a} instead`, t, n, i), r += String.fromCharCode(o);
|
|
362
|
+
this.onEscapeWarning(`\\x${e}${a} is a non-standard escape sequence; use \\u00${e}${a} instead`, t, n, i, this.pos), r += String.fromCharCode(o);
|
|
330
363
|
break;
|
|
331
364
|
}
|
|
332
365
|
if (a === "\"" || a === "'") {
|
|
333
|
-
this.onEscapeWarning(`\\${a} inside ${e === "\"" ? "double" : "single"}-quoted string is non-standard`, t, n, i), r += a;
|
|
366
|
+
this.onEscapeWarning(`\\${a} inside ${e === "\"" ? "double" : "single"}-quoted string is non-standard`, t, n, i, this.pos), r += a;
|
|
334
367
|
break;
|
|
335
368
|
}
|
|
336
369
|
if (a === "\n" || a === "\r") {
|
|
337
|
-
a === "\r" && this._ch() === "\n" && this._advance(), this.onEscapeWarning("line continuation (\\<newline>) is non-standard; the newline is ignored", t, n, i);
|
|
370
|
+
a === "\r" && this._ch() === "\n" && this._advance(), this.onEscapeWarning("line continuation (\\<newline>) is non-standard; the newline is ignored", t, n, i, this.pos);
|
|
338
371
|
break;
|
|
339
372
|
}
|
|
340
|
-
this.onEscapeWarning(`\\${a} is an unknown escape sequence; interpreted as '${a}'`, t, n, i), r += a;
|
|
373
|
+
this.onEscapeWarning(`\\${a} is an unknown escape sequence; interpreted as '${a}'`, t, n, i, this.pos), r += a;
|
|
341
374
|
break;
|
|
342
375
|
}
|
|
343
376
|
this._fail(`invalid escape sequence \\${a} in ${e === "\"" ? "double" : "single"}-quoted string`, n, i);
|
|
@@ -351,7 +384,7 @@ var i = new TextEncoder(), a = class {
|
|
|
351
384
|
if (e === "'" && o >= 32 && o <= 126) {
|
|
352
385
|
let e = `\\u escape for printable ASCII U+${o.toString(16).padStart(4, "0").toUpperCase()} is not allowed in single-quoted strings (§5.1 hexchar-s)`;
|
|
353
386
|
if (this.onEscapeWarning) {
|
|
354
|
-
this.onEscapeWarning(e, t ?? this.pos, n ?? i, r ?? a);
|
|
387
|
+
this.onEscapeWarning(e, t ?? this.pos, n ?? i, r ?? a, this.pos);
|
|
355
388
|
return;
|
|
356
389
|
}
|
|
357
390
|
this._fail(e, i, a);
|
|
@@ -422,35 +455,35 @@ var i = new TextEncoder(), a = class {
|
|
|
422
455
|
this._fail("unterminated raw string literal", e, t);
|
|
423
456
|
}
|
|
424
457
|
_processRawHexContent(e, t, n) {
|
|
425
|
-
let
|
|
426
|
-
for (;
|
|
427
|
-
let
|
|
428
|
-
if (
|
|
429
|
-
|
|
458
|
+
let r = "", i = !1, a = 0;
|
|
459
|
+
for (; a < e.length;) {
|
|
460
|
+
let o = e[a];
|
|
461
|
+
if (o === "\n" || o === " " || o === "\r") {
|
|
462
|
+
a++;
|
|
430
463
|
continue;
|
|
431
464
|
}
|
|
432
|
-
|
|
433
|
-
let
|
|
434
|
-
if (
|
|
435
|
-
|
|
465
|
+
o === " " && this._fail("horizontal tab (HT) is not allowed inside h`` raw byte string literals (§5.3.3)", t, n);
|
|
466
|
+
let s = this._skipRawComment(e, a, "h`` raw byte string", t, n);
|
|
467
|
+
if (s !== -1) {
|
|
468
|
+
a = s;
|
|
436
469
|
continue;
|
|
437
470
|
}
|
|
438
|
-
if (
|
|
439
|
-
for (
|
|
440
|
-
|
|
471
|
+
if (o === "." && e[a + 1] === "." && e[a + 2] === ".") {
|
|
472
|
+
for (a += 3; a < e.length && e[a] === ".";) a++;
|
|
473
|
+
r += "...", i = !0;
|
|
441
474
|
continue;
|
|
442
475
|
}
|
|
443
|
-
if (
|
|
444
|
-
let t =
|
|
445
|
-
for (;
|
|
446
|
-
|
|
476
|
+
if (p(e.charCodeAt(a))) {
|
|
477
|
+
let t = a;
|
|
478
|
+
for (; a < e.length && p(e.charCodeAt(a));) a++;
|
|
479
|
+
r += e.slice(t, a);
|
|
447
480
|
continue;
|
|
448
481
|
}
|
|
449
|
-
this._fail(`unexpected character ${JSON.stringify(
|
|
482
|
+
this._fail(`unexpected character ${JSON.stringify(o)} in h\`\` raw byte string`, t, n);
|
|
450
483
|
}
|
|
451
484
|
return {
|
|
452
|
-
value:
|
|
453
|
-
elided:
|
|
485
|
+
value: r,
|
|
486
|
+
elided: i
|
|
454
487
|
};
|
|
455
488
|
}
|
|
456
489
|
_processRawB64Content(e, t, n) {
|
|
@@ -513,24 +546,24 @@ var i = new TextEncoder(), a = class {
|
|
|
513
546
|
this._advance();
|
|
514
547
|
let t = "", n = !1;
|
|
515
548
|
for (; !this._eof() && this._ch() !== e;) {
|
|
516
|
-
let
|
|
517
|
-
if (
|
|
549
|
+
let r = this._ch();
|
|
550
|
+
if (r === "\n" || r === " " || r === "\r") {
|
|
518
551
|
this._advance();
|
|
519
552
|
continue;
|
|
520
553
|
}
|
|
521
|
-
if (
|
|
522
|
-
if (
|
|
554
|
+
if (r === " " && this._fail("horizontal tab (HT) is not allowed inside hex byte string literals (§5.2.1)", this.line, this.col), !this._skipByteStringComment(e)) {
|
|
555
|
+
if (r === "." && (this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
|
|
523
556
|
for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
|
|
524
557
|
t.endsWith("...") || (t += "..."), n = !0;
|
|
525
558
|
continue;
|
|
526
559
|
}
|
|
527
|
-
if (r
|
|
528
|
-
let e = this.pos, n = this.pos,
|
|
529
|
-
for (; n <
|
|
560
|
+
if (p(r.charCodeAt(0))) {
|
|
561
|
+
let e = this.pos, n = this.pos, r = this.input.length;
|
|
562
|
+
for (; n < r && p(this.input.charCodeAt(n));) n++;
|
|
530
563
|
this.col += n - e, this.pos = n, t += this.input.slice(e, n);
|
|
531
564
|
continue;
|
|
532
565
|
}
|
|
533
|
-
this._fail(`unexpected character ${JSON.stringify(
|
|
566
|
+
this._fail(`unexpected character ${JSON.stringify(r)} in hex byte string`);
|
|
534
567
|
}
|
|
535
568
|
}
|
|
536
569
|
return this._eof() && this._fail("unterminated hex byte string literal"), this._advance(), {
|
|
@@ -538,135 +571,67 @@ var i = new TextEncoder(), a = class {
|
|
|
538
571
|
elided: n
|
|
539
572
|
};
|
|
540
573
|
}
|
|
574
|
+
_tokStart = 0;
|
|
541
575
|
_readNext() {
|
|
542
|
-
this._skipWS();
|
|
543
|
-
|
|
576
|
+
return this._skipWS(), this._tokStart = this.pos, this._readNextCore();
|
|
577
|
+
}
|
|
578
|
+
_tok(e, t, n, r, i) {
|
|
579
|
+
let a = this._tokStart, o = {
|
|
580
|
+
type: e,
|
|
581
|
+
value: t,
|
|
582
|
+
raw: this.input.slice(a, this.pos),
|
|
583
|
+
line: n,
|
|
584
|
+
col: r,
|
|
585
|
+
offset: a,
|
|
586
|
+
endOffset: this.pos
|
|
587
|
+
};
|
|
588
|
+
return i !== void 0 && (o.appPrefix = i), o;
|
|
589
|
+
}
|
|
590
|
+
_tokV(e, t, n, r) {
|
|
544
591
|
return {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
592
|
+
type: e,
|
|
593
|
+
value: t,
|
|
594
|
+
raw: t,
|
|
595
|
+
line: n,
|
|
596
|
+
col: r,
|
|
597
|
+
offset: this._tokStart,
|
|
548
598
|
endOffset: this.pos
|
|
549
599
|
};
|
|
550
600
|
}
|
|
551
601
|
_readNextCore() {
|
|
552
602
|
let e = this.line, t = this.col;
|
|
553
|
-
if (this._eof()) return
|
|
554
|
-
type: "EOF",
|
|
555
|
-
value: "",
|
|
556
|
-
line: e,
|
|
557
|
-
col: t
|
|
558
|
-
};
|
|
603
|
+
if (this._eof()) return this._tokV("EOF", "", e, t);
|
|
559
604
|
let n = this._ch();
|
|
560
605
|
switch (n) {
|
|
561
|
-
case "[": return this._advance(),
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
case "
|
|
568
|
-
|
|
569
|
-
value: "]",
|
|
570
|
-
line: e,
|
|
571
|
-
col: t
|
|
572
|
-
};
|
|
573
|
-
case "{": return this._advance(), {
|
|
574
|
-
type: "LBRACE",
|
|
575
|
-
value: "{",
|
|
576
|
-
line: e,
|
|
577
|
-
col: t
|
|
578
|
-
};
|
|
579
|
-
case "}": return this._advance(), {
|
|
580
|
-
type: "RBRACE",
|
|
581
|
-
value: "}",
|
|
582
|
-
line: e,
|
|
583
|
-
col: t
|
|
584
|
-
};
|
|
585
|
-
case "(": return this._advance(), {
|
|
586
|
-
type: "LPAREN",
|
|
587
|
-
value: "(",
|
|
588
|
-
line: e,
|
|
589
|
-
col: t
|
|
590
|
-
};
|
|
591
|
-
case ")": return this._advance(), {
|
|
592
|
-
type: "RPAREN",
|
|
593
|
-
value: ")",
|
|
594
|
-
line: e,
|
|
595
|
-
col: t
|
|
596
|
-
};
|
|
597
|
-
case ":": return this._advance(), {
|
|
598
|
-
type: "COLON",
|
|
599
|
-
value: ":",
|
|
600
|
-
line: e,
|
|
601
|
-
col: t
|
|
602
|
-
};
|
|
603
|
-
case ",": return this._advance(), {
|
|
604
|
-
type: "COMMA",
|
|
605
|
-
value: ",",
|
|
606
|
-
line: e,
|
|
607
|
-
col: t
|
|
608
|
-
};
|
|
606
|
+
case "[": return this._advance(), this._tokV("LBRACKET", "[", e, t);
|
|
607
|
+
case "]": return this._advance(), this._tokV("RBRACKET", "]", e, t);
|
|
608
|
+
case "{": return this._advance(), this._tokV("LBRACE", "{", e, t);
|
|
609
|
+
case "}": return this._advance(), this._tokV("RBRACE", "}", e, t);
|
|
610
|
+
case "(": return this._advance(), this._tokV("LPAREN", "(", e, t);
|
|
611
|
+
case ")": return this._advance(), this._tokV("RPAREN", ")", e, t);
|
|
612
|
+
case ":": return this._advance(), this._tokV("COLON", ":", e, t);
|
|
613
|
+
case ",": return this._advance(), this._tokV("COMMA", ",", e, t);
|
|
609
614
|
case "<":
|
|
610
|
-
if ((this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(),
|
|
611
|
-
type: "LT_LT",
|
|
612
|
-
value: "<<",
|
|
613
|
-
line: e,
|
|
614
|
-
col: t
|
|
615
|
-
};
|
|
615
|
+
if ((this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), this._tokV("LT_LT", "<<", e, t);
|
|
616
616
|
this._fail("unexpected character '<'", e, t);
|
|
617
617
|
case ">":
|
|
618
|
-
if ((this.input[this.pos + 1] ?? "") === ">") return this._advance(), this._advance(),
|
|
619
|
-
type: "GT_GT",
|
|
620
|
-
value: ">>",
|
|
621
|
-
line: e,
|
|
622
|
-
col: t
|
|
623
|
-
};
|
|
618
|
+
if ((this.input[this.pos + 1] ?? "") === ">") return this._advance(), this._advance(), this._tokV("GT_GT", ">>", e, t);
|
|
624
619
|
this._fail("unexpected character '>'", e, t);
|
|
625
620
|
case "+": {
|
|
626
621
|
let n = this._readSignedInfinity("+", e, t);
|
|
627
622
|
if (n !== null) return n;
|
|
628
623
|
let r = this.input[this.pos + 1] ?? "";
|
|
629
|
-
return r >= "0" && r <= "9" || r === "." ? (this._advance(), this._readNumber(e, t)) : (this._advance(),
|
|
630
|
-
type: "PLUS",
|
|
631
|
-
value: "+",
|
|
632
|
-
line: e,
|
|
633
|
-
col: t
|
|
634
|
-
});
|
|
624
|
+
return r >= "0" && r <= "9" || r === "." ? (this._advance(), this._readNumber(e, t)) : (this._advance(), this._tokV("PLUS", "+", e, t));
|
|
635
625
|
}
|
|
636
|
-
case "`": return
|
|
637
|
-
type: "RAWSTRING",
|
|
638
|
-
value: this._readRawStringContent(),
|
|
639
|
-
line: e,
|
|
640
|
-
col: t
|
|
641
|
-
};
|
|
626
|
+
case "`": return this._tok("RAWSTRING", this._readRawStringContent(), e, t);
|
|
642
627
|
case "\"": {
|
|
643
628
|
let n = this._readStringContent("\"");
|
|
644
|
-
return n === "" && this._ch() === "_" && !/[0-7i]/.test(this.input[this.pos + 1] ?? "") ? (this._advance(),
|
|
645
|
-
type: "EMPTY_INDEF_TEXT",
|
|
646
|
-
value: "",
|
|
647
|
-
line: e,
|
|
648
|
-
col: t
|
|
649
|
-
}) : {
|
|
650
|
-
type: "TSTR",
|
|
651
|
-
value: n,
|
|
652
|
-
line: e,
|
|
653
|
-
col: t
|
|
654
|
-
};
|
|
629
|
+
return n === "" && this._ch() === "_" && !/[0-7i]/.test(this.input[this.pos + 1] ?? "") ? (this._advance(), this._tok("EMPTY_INDEF_TEXT", "", e, t)) : this._tok("TSTR", n, e, t);
|
|
655
630
|
}
|
|
656
631
|
case "'": {
|
|
657
|
-
if ((this.input[this.pos + 1] ?? "") === "'" && (this.input[this.pos + 2] ?? "") === "_" && !/[0-7i]/.test(this.input[this.pos + 3] ?? "")) return this._advance(), this._advance(), this._advance(),
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
line: e,
|
|
661
|
-
col: t
|
|
662
|
-
};
|
|
663
|
-
let n = this._readStringContent("'"), r = i.encode(n);
|
|
664
|
-
return {
|
|
665
|
-
type: "SQSTR",
|
|
666
|
-
value: Array.from(r, (e) => e.toString(16).padStart(2, "0")).join(""),
|
|
667
|
-
line: e,
|
|
668
|
-
col: t
|
|
669
|
-
};
|
|
632
|
+
if ((this.input[this.pos + 1] ?? "") === "'" && (this.input[this.pos + 2] ?? "") === "_" && !/[0-7i]/.test(this.input[this.pos + 3] ?? "")) return this._advance(), this._advance(), this._advance(), this._tok("EMPTY_INDEF_BYTES", "", e, t);
|
|
633
|
+
let n = this._readStringContent("'"), r = m.encode(n), i = this._tok("SQSTR", o(r), e, t);
|
|
634
|
+
return Object.defineProperty(i, "_sqstrBytes", { value: r }), i;
|
|
670
635
|
}
|
|
671
636
|
}
|
|
672
637
|
if (n === "-") {
|
|
@@ -678,12 +643,7 @@ var i = new TextEncoder(), a = class {
|
|
|
678
643
|
if (n === ".") {
|
|
679
644
|
if ((this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
|
|
680
645
|
for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
|
|
681
|
-
return
|
|
682
|
-
type: "ELLIPSIS",
|
|
683
|
-
value: "...",
|
|
684
|
-
line: e,
|
|
685
|
-
col: t
|
|
686
|
-
};
|
|
646
|
+
return this._tok("ELLIPSIS", "...", e, t);
|
|
687
647
|
}
|
|
688
648
|
this._fail("unexpected character '.'", e, t);
|
|
689
649
|
}
|
|
@@ -696,16 +656,11 @@ var i = new TextEncoder(), a = class {
|
|
|
696
656
|
this._advance();
|
|
697
657
|
for (let e = 0; e < 8; e++) this._advance();
|
|
698
658
|
let a = e === "-" ? "-Infinity" : "Infinity";
|
|
699
|
-
return i && (a += this._advance() + this._advance()),
|
|
700
|
-
type: "FLOAT",
|
|
701
|
-
value: a,
|
|
702
|
-
line: t,
|
|
703
|
-
col: n
|
|
704
|
-
};
|
|
659
|
+
return i && (a += this._advance() + this._advance()), this._tok("FLOAT", a, t, n);
|
|
705
660
|
}
|
|
706
661
|
_skipHexDigits() {
|
|
707
662
|
let e = this.pos, t = this.input.length;
|
|
708
|
-
for (; e < t &&
|
|
663
|
+
for (; e < t && p(this.input.charCodeAt(e));) e++;
|
|
709
664
|
this.col += e - this.pos, this.pos = e;
|
|
710
665
|
}
|
|
711
666
|
_skipDecimalDigits() {
|
|
@@ -723,68 +678,43 @@ var i = new TextEncoder(), a = class {
|
|
|
723
678
|
(e >= "0" && e <= "7" || e === "i") && !/[0-9a-zA-Z_]/.test(t) && (this._advance(), this._advance());
|
|
724
679
|
}
|
|
725
680
|
_readNumber(e, t) {
|
|
726
|
-
let n = this.pos, r = () => this.input.slice(n, this.pos);
|
|
681
|
+
let n = this.pos, r = () => this.input.slice(n, this.pos), i = (i) => n === this._tokStart ? this._tokV(i, r(), e, t) : this._tok(i, r(), e, t);
|
|
727
682
|
if (this._ch() === "-" && this._advance(), this._ch() === "0") {
|
|
728
683
|
let n = this.input[this.pos + 1] ?? "";
|
|
729
684
|
if (n === "x" || n === "X") {
|
|
730
685
|
this._advance(), this._advance();
|
|
731
686
|
let n = this.pos;
|
|
732
687
|
this._skipHexDigits();
|
|
733
|
-
let
|
|
688
|
+
let a = this.pos > n, o = !1, s = !1;
|
|
734
689
|
if (!this._eof() && this._ch() === ".") {
|
|
735
|
-
|
|
690
|
+
o = !0, this._advance();
|
|
736
691
|
let e = this.pos;
|
|
737
|
-
this._skipHexDigits(),
|
|
692
|
+
this._skipHexDigits(), s = this.pos > e;
|
|
738
693
|
}
|
|
739
694
|
if (!this._eof() && (this._ch() === "p" || this._ch() === "P")) {
|
|
740
|
-
|
|
695
|
+
o = !0, !a && !s && this._fail(`hex float has no mantissa digits: ${r()}`, e, t), this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && this._advance();
|
|
741
696
|
let n = this.pos;
|
|
742
697
|
this._skipDecimalDigits(), this.pos === n && this._fail(`hex float missing exponent digits: ${r()}`, e, t);
|
|
743
|
-
} else
|
|
744
|
-
return
|
|
745
|
-
type: "FLOAT",
|
|
746
|
-
value: r(),
|
|
747
|
-
line: e,
|
|
748
|
-
col: t
|
|
749
|
-
}) : {
|
|
750
|
-
type: "INTEGER",
|
|
751
|
-
value: r(),
|
|
752
|
-
line: e,
|
|
753
|
-
col: t
|
|
754
|
-
};
|
|
698
|
+
} else o && this._fail(`hex float missing 'p' exponent: ${r()}`, e, t);
|
|
699
|
+
return o ? (this._tryConsumeEncodingSuffix(), i("FLOAT")) : i("INTEGER");
|
|
755
700
|
}
|
|
756
701
|
if (n === "o" || n === "O") {
|
|
757
702
|
for (this._advance(), this._advance(); !this._eof() && this._ch() >= "0" && this._ch() <= "7";) this._advance();
|
|
758
|
-
return
|
|
759
|
-
type: "INTEGER",
|
|
760
|
-
value: r(),
|
|
761
|
-
line: e,
|
|
762
|
-
col: t
|
|
763
|
-
};
|
|
703
|
+
return i("INTEGER");
|
|
764
704
|
}
|
|
765
705
|
if (n === "b" || n === "B") {
|
|
766
706
|
for (this._advance(), this._advance(); !this._eof() && (this._ch() === "0" || this._ch() === "1");) this._advance();
|
|
767
|
-
return
|
|
768
|
-
type: "INTEGER",
|
|
769
|
-
value: r(),
|
|
770
|
-
line: e,
|
|
771
|
-
col: t
|
|
772
|
-
};
|
|
707
|
+
return i("INTEGER");
|
|
773
708
|
}
|
|
774
709
|
}
|
|
775
710
|
this._skipDecimalDigits();
|
|
776
|
-
let
|
|
777
|
-
if (!this._eof() && this._ch() === "." && (
|
|
778
|
-
|
|
711
|
+
let a = !1;
|
|
712
|
+
if (!this._eof() && this._ch() === "." && (a = !0, this._advance(), this._skipDecimalDigits()), !this._eof() && (this._ch() === "e" || this._ch() === "E")) {
|
|
713
|
+
a = !0, this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && this._advance();
|
|
779
714
|
let n = this.pos;
|
|
780
715
|
this._skipDecimalDigits(), this.pos === n && this._fail(`float exponent has no digits: ${JSON.stringify(r())}`, e, t);
|
|
781
716
|
}
|
|
782
|
-
return this._tryConsumeEncodingSuffix(),
|
|
783
|
-
type: i ? "FLOAT" : "INTEGER",
|
|
784
|
-
value: r(),
|
|
785
|
-
line: e,
|
|
786
|
-
col: t
|
|
787
|
-
};
|
|
717
|
+
return this._tryConsumeEncodingSuffix(), i(a ? "FLOAT" : "INTEGER");
|
|
788
718
|
}
|
|
789
719
|
_readIdent(e, t) {
|
|
790
720
|
let n = this.pos;
|
|
@@ -799,30 +729,10 @@ var i = new TextEncoder(), a = class {
|
|
|
799
729
|
}
|
|
800
730
|
let r = this.input.slice(n, this.pos);
|
|
801
731
|
switch (r) {
|
|
802
|
-
case "true": return
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
col: t
|
|
807
|
-
};
|
|
808
|
-
case "false": return {
|
|
809
|
-
type: "FALSE",
|
|
810
|
-
value: r,
|
|
811
|
-
line: e,
|
|
812
|
-
col: t
|
|
813
|
-
};
|
|
814
|
-
case "null": return {
|
|
815
|
-
type: "NULL",
|
|
816
|
-
value: r,
|
|
817
|
-
line: e,
|
|
818
|
-
col: t
|
|
819
|
-
};
|
|
820
|
-
case "undefined": return {
|
|
821
|
-
type: "UNDEFINED",
|
|
822
|
-
value: r,
|
|
823
|
-
line: e,
|
|
824
|
-
col: t
|
|
825
|
-
};
|
|
732
|
+
case "true": return this._tokV("TRUE", r, e, t);
|
|
733
|
+
case "false": return this._tokV("FALSE", r, e, t);
|
|
734
|
+
case "null": return this._tokV("NULL", r, e, t);
|
|
735
|
+
case "undefined": return this._tokV("UNDEFINED", r, e, t);
|
|
826
736
|
case "NaN":
|
|
827
737
|
case "NaN_0":
|
|
828
738
|
case "NaN_1":
|
|
@@ -842,78 +752,18 @@ var i = new TextEncoder(), a = class {
|
|
|
842
752
|
case "Infinity_5":
|
|
843
753
|
case "Infinity_6":
|
|
844
754
|
case "Infinity_7":
|
|
845
|
-
case "Infinity_i": return
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
case "
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
case "_": return {
|
|
858
|
-
type: "UNDERSCORE",
|
|
859
|
-
value: "_",
|
|
860
|
-
line: e,
|
|
861
|
-
col: t
|
|
862
|
-
};
|
|
863
|
-
case "_0": return {
|
|
864
|
-
type: "ENCODING_INDICATOR",
|
|
865
|
-
value: "0",
|
|
866
|
-
line: e,
|
|
867
|
-
col: t
|
|
868
|
-
};
|
|
869
|
-
case "_1": return {
|
|
870
|
-
type: "ENCODING_INDICATOR",
|
|
871
|
-
value: "1",
|
|
872
|
-
line: e,
|
|
873
|
-
col: t
|
|
874
|
-
};
|
|
875
|
-
case "_2": return {
|
|
876
|
-
type: "ENCODING_INDICATOR",
|
|
877
|
-
value: "2",
|
|
878
|
-
line: e,
|
|
879
|
-
col: t
|
|
880
|
-
};
|
|
881
|
-
case "_3": return {
|
|
882
|
-
type: "ENCODING_INDICATOR",
|
|
883
|
-
value: "3",
|
|
884
|
-
line: e,
|
|
885
|
-
col: t
|
|
886
|
-
};
|
|
887
|
-
case "_4": return {
|
|
888
|
-
type: "ENCODING_INDICATOR",
|
|
889
|
-
value: "4",
|
|
890
|
-
line: e,
|
|
891
|
-
col: t
|
|
892
|
-
};
|
|
893
|
-
case "_5": return {
|
|
894
|
-
type: "ENCODING_INDICATOR",
|
|
895
|
-
value: "5",
|
|
896
|
-
line: e,
|
|
897
|
-
col: t
|
|
898
|
-
};
|
|
899
|
-
case "_6": return {
|
|
900
|
-
type: "ENCODING_INDICATOR",
|
|
901
|
-
value: "6",
|
|
902
|
-
line: e,
|
|
903
|
-
col: t
|
|
904
|
-
};
|
|
905
|
-
case "_7": return {
|
|
906
|
-
type: "ENCODING_INDICATOR",
|
|
907
|
-
value: "7",
|
|
908
|
-
line: e,
|
|
909
|
-
col: t
|
|
910
|
-
};
|
|
911
|
-
case "_i": return {
|
|
912
|
-
type: "ENCODING_INDICATOR",
|
|
913
|
-
value: "i",
|
|
914
|
-
line: e,
|
|
915
|
-
col: t
|
|
916
|
-
};
|
|
755
|
+
case "Infinity_i": return this._tokV("FLOAT", r, e, t);
|
|
756
|
+
case "simple": return this._tokV("SIMPLE", r, e, t);
|
|
757
|
+
case "_": return this._tokV("UNDERSCORE", "_", e, t);
|
|
758
|
+
case "_0": return this._tok("ENCODING_INDICATOR", "0", e, t);
|
|
759
|
+
case "_1": return this._tok("ENCODING_INDICATOR", "1", e, t);
|
|
760
|
+
case "_2": return this._tok("ENCODING_INDICATOR", "2", e, t);
|
|
761
|
+
case "_3": return this._tok("ENCODING_INDICATOR", "3", e, t);
|
|
762
|
+
case "_4": return this._tok("ENCODING_INDICATOR", "4", e, t);
|
|
763
|
+
case "_5": return this._tok("ENCODING_INDICATOR", "5", e, t);
|
|
764
|
+
case "_6": return this._tok("ENCODING_INDICATOR", "6", e, t);
|
|
765
|
+
case "_7": return this._tok("ENCODING_INDICATOR", "7", e, t);
|
|
766
|
+
case "_i": return this._tok("ENCODING_INDICATOR", "i", e, t);
|
|
917
767
|
}
|
|
918
768
|
let i = r[0] ?? "", a = i >= "a" && i <= "z";
|
|
919
769
|
if (a || i >= "A" && i <= "Z") {
|
|
@@ -930,67 +780,29 @@ var i = new TextEncoder(), a = class {
|
|
|
930
780
|
if (i === "\"" && this._fail(`"${r}" prefix requires single quotes or backticks, not double quotes`, e, t), i === "'") switch (r) {
|
|
931
781
|
case "h": {
|
|
932
782
|
let { value: n, elided: r } = this._readHexByteContentElisionAware(i);
|
|
933
|
-
return
|
|
934
|
-
type: r ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
|
|
935
|
-
value: n,
|
|
936
|
-
line: e,
|
|
937
|
-
col: t
|
|
938
|
-
};
|
|
783
|
+
return this._tok(r ? "BYTES_HEX_ELIDED" : "BYTES_HEX", n, e, t);
|
|
939
784
|
}
|
|
940
|
-
case "b64": return
|
|
941
|
-
|
|
942
|
-
value: this._readByteContent(i),
|
|
943
|
-
line: e,
|
|
944
|
-
col: t
|
|
945
|
-
};
|
|
946
|
-
default: return {
|
|
947
|
-
type: "APP_STRING",
|
|
948
|
-
appPrefix: r,
|
|
949
|
-
value: this._readStringContent(i),
|
|
950
|
-
line: e,
|
|
951
|
-
col: t
|
|
952
|
-
};
|
|
785
|
+
case "b64": return this._tok("BYTES_B64", this._readByteContent(i), e, t);
|
|
786
|
+
default: return this._tok("APP_STRING", this._readStringContent(i), e, t, r);
|
|
953
787
|
}
|
|
954
788
|
if (i === "`") {
|
|
955
789
|
let n = this._readRawStringContent();
|
|
956
790
|
switch (r) {
|
|
957
791
|
case "h": {
|
|
958
792
|
let { value: r, elided: i } = this._processRawHexContent(n, e, t);
|
|
959
|
-
return
|
|
960
|
-
type: i ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
|
|
961
|
-
value: r,
|
|
962
|
-
line: e,
|
|
963
|
-
col: t
|
|
964
|
-
};
|
|
793
|
+
return this._tok(i ? "BYTES_HEX_ELIDED" : "BYTES_HEX", r, e, t);
|
|
965
794
|
}
|
|
966
|
-
case "b64": return
|
|
967
|
-
|
|
968
|
-
value: this._processRawB64Content(n, e, t),
|
|
969
|
-
line: e,
|
|
970
|
-
col: t
|
|
971
|
-
};
|
|
972
|
-
default: return {
|
|
973
|
-
type: "APP_STRING",
|
|
974
|
-
appPrefix: r,
|
|
975
|
-
value: n,
|
|
976
|
-
line: e,
|
|
977
|
-
col: t
|
|
978
|
-
};
|
|
795
|
+
case "b64": return this._tok("BYTES_B64", this._processRawB64Content(n, e, t), e, t);
|
|
796
|
+
default: return this._tok("APP_STRING", n, e, t, r);
|
|
979
797
|
}
|
|
980
798
|
}
|
|
981
|
-
if (i === "<" && (this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(),
|
|
982
|
-
type: "APP_SEQUENCE",
|
|
983
|
-
appPrefix: r,
|
|
984
|
-
value: "",
|
|
985
|
-
line: e,
|
|
986
|
-
col: t
|
|
987
|
-
};
|
|
799
|
+
if (i === "<" && (this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), this._tok("APP_SEQUENCE", "", e, t, r);
|
|
988
800
|
}
|
|
989
801
|
}
|
|
990
802
|
this._fail(`unknown identifier ${JSON.stringify(r)}`, e, t);
|
|
991
803
|
}
|
|
992
804
|
};
|
|
993
805
|
//#endregion
|
|
994
|
-
export {
|
|
806
|
+
export { u as a, l as i, c as n, e as o, o as r, h as t };
|
|
995
807
|
|
|
996
|
-
//# sourceMappingURL=tokenizer-
|
|
808
|
+
//# sourceMappingURL=tokenizer-DkLlZ1gc.js.map
|