@cbortech/cbor 0.25.2 → 0.25.4

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.
@@ -0,0 +1,995 @@
1
+ //#region src/cdn/errors.ts
2
+ var e = class extends SyntaxError {
3
+ offset;
4
+ line;
5
+ column;
6
+ endOffset;
7
+ constructor(e, t) {
8
+ let n = t?.line === void 0 ? "" : ` at line ${t.line}, column ${t.column}`;
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
+ }
11
+ };
12
+ //#endregion
13
+ //#region src/cdn/tokenizer.ts
14
+ function t(e, t, n) {
15
+ let r = 1, i = 1;
16
+ for (let a = 0; a < e.length; a++) {
17
+ if (r === t && i === n) return a;
18
+ e[a] === "\n" ? (r++, i = 1) : i++;
19
+ }
20
+ return e.length;
21
+ }
22
+ function n(e, t) {
23
+ let n = 1, r = 1;
24
+ for (let i = 0; i < t; i++) e[i] === "\n" ? (n++, r = 1) : r++;
25
+ return {
26
+ line: n,
27
+ col: r
28
+ };
29
+ }
30
+ function r(e) {
31
+ return e >= 48 && e <= 57 || e >= 97 && e <= 102 || e >= 65 && e <= 70;
32
+ }
33
+ var i = new TextEncoder(), a = class {
34
+ input;
35
+ pos;
36
+ line;
37
+ col;
38
+ _peeked = null;
39
+ _lastConsumedEndOffset;
40
+ comments = [];
41
+ onEscapeWarning;
42
+ constructor(e, t) {
43
+ this.input = e;
44
+ let r = t?.offset ?? 0;
45
+ if (!Number.isInteger(r) || r < 0 || r > e.length) throw RangeError(`EDN parse offset must be an integer between 0 and ${e.length}`);
46
+ let i = n(e, r);
47
+ this.pos = r, this.line = i.line, this.col = i.col, this._lastConsumedEndOffset = r;
48
+ }
49
+ peek() {
50
+ return this._peeked === null && (this._peeked = this._readNext()), this._peeked;
51
+ }
52
+ consume() {
53
+ let e = this._peeked === null ? this._readNext() : this._peeked;
54
+ return this._peeked = null, this._lastConsumedEndOffset = e.endOffset, e;
55
+ }
56
+ get lastEndOffset() {
57
+ return this._lastConsumedEndOffset;
58
+ }
59
+ get source() {
60
+ return this.input;
61
+ }
62
+ _ch() {
63
+ return this.input[this.pos] ?? "";
64
+ }
65
+ _eof() {
66
+ return this.pos >= this.input.length;
67
+ }
68
+ _advance() {
69
+ let e = this.input[this.pos++] ?? "";
70
+ return e === "\n" ? (this.line++, this.col = 1) : this.col++, e;
71
+ }
72
+ _fail(n, r = this.line, i = this.col) {
73
+ throw new e(n, {
74
+ offset: r === this.line && i === this.col ? this.pos : t(this.input, r, i),
75
+ line: r,
76
+ column: i
77
+ });
78
+ }
79
+ _skipWS() {
80
+ for (;;) {
81
+ for (;;) {
82
+ let e = this.input[this.pos];
83
+ if (e === void 0) return;
84
+ if (e === " " || e === "\n" || e === " " || e === "\r") {
85
+ this._advance();
86
+ continue;
87
+ }
88
+ if (e > " " && e <= "~") break;
89
+ if (/\s/.test(e)) {
90
+ this._advance();
91
+ continue;
92
+ }
93
+ break;
94
+ }
95
+ let e = this._ch();
96
+ if (e === "#") {
97
+ let e = this.pos, t = this.line, n = this.col;
98
+ for (; !this._eof() && this._ch() !== "\n";) this._advance();
99
+ this.comments.push({
100
+ kind: "line",
101
+ marker: "#",
102
+ text: this.input.slice(e, this.pos),
103
+ start: e,
104
+ end: this.pos,
105
+ line: t,
106
+ col: n
107
+ });
108
+ continue;
109
+ }
110
+ if (e === "/") {
111
+ let e = this.input[this.pos + 1] ?? "";
112
+ if (e === "/") {
113
+ let e = this.pos, t = this.line, n = this.col;
114
+ for (this._advance(), this._advance(); !this._eof() && this._ch() !== "\n";) this._advance();
115
+ this.comments.push({
116
+ kind: "line",
117
+ marker: "//",
118
+ text: this.input.slice(e, this.pos),
119
+ start: e,
120
+ end: this.pos,
121
+ line: t,
122
+ col: n
123
+ });
124
+ continue;
125
+ }
126
+ if (e === "*") {
127
+ let e = this.pos, t = this.line, n = this.col;
128
+ this._advance(), this._advance(), this._skipBlockCommentStar(), this.comments.push({
129
+ kind: "block",
130
+ marker: "/*",
131
+ text: this.input.slice(e, this.pos),
132
+ start: e,
133
+ end: this.pos,
134
+ line: t,
135
+ col: n
136
+ });
137
+ continue;
138
+ }
139
+ let t = this.pos, n = this.line, r = this.col;
140
+ this._advance(), this._skipBlockCommentSlash(), this.comments.push({
141
+ kind: "block",
142
+ marker: "/",
143
+ text: this.input.slice(t, this.pos),
144
+ start: t,
145
+ end: this.pos,
146
+ line: n,
147
+ col: r
148
+ });
149
+ continue;
150
+ }
151
+ return;
152
+ }
153
+ }
154
+ _skipByteStringComment(e) {
155
+ let t = this._ch();
156
+ if (t === "/") {
157
+ let t = this.input[this.pos + 1] ?? "";
158
+ if (t === "/") {
159
+ for (this._advance(), this._advance(); !this._eof() && this._ch() !== "\n";) {
160
+ if (this._ch() === "\\") {
161
+ this._advance(), !this._eof() && this._ch() !== "\n" && this._advance();
162
+ continue;
163
+ }
164
+ if (this._ch() === e) break;
165
+ this._advance();
166
+ }
167
+ return !0;
168
+ }
169
+ return t === "*" ? (this._advance(), this._advance(), this._skipBlockCommentStar(), !0) : (this._advance(), this._skipBlockCommentSlash(), !0);
170
+ }
171
+ if (t === "#") {
172
+ for (; !this._eof() && this._ch() !== "\n";) {
173
+ if (this._ch() === "\\") {
174
+ if (this._advance(), this._eof() || this._ch() === "\n") continue;
175
+ this._advance() === "u" && this._validateHexCommentUnicodeEscape();
176
+ continue;
177
+ }
178
+ if (this._ch() === e) break;
179
+ this._advance();
180
+ }
181
+ return !0;
182
+ }
183
+ return !1;
184
+ }
185
+ _validateHexCommentUnicodeEscape() {
186
+ let e = this.line, t = this.col;
187
+ if (!this._eof() && this._ch() === "{") {
188
+ this._advance();
189
+ let n = "";
190
+ for (; !this._eof() && this._ch() !== "}" && this._ch() !== "\n";) n += this._advance();
191
+ !this._eof() && this._ch() === "}" && this._advance();
192
+ let r = parseInt(n || "0", 16);
193
+ r >= 55296 && r <= 57343 && this._fail(`\\u{${n}} is a surrogate code point, not allowed in hex string comments`, e, t);
194
+ return;
195
+ }
196
+ let n = "";
197
+ for (let e = 0; e < 4 && !(this._eof() || this._ch() === "\n" || !/[0-9a-fA-F]/.test(this._ch())); e++) n += this._advance();
198
+ if (n.length < 4) return;
199
+ let r = parseInt(n, 16);
200
+ if (r >= 55296 && r <= 56319) {
201
+ (this._ch() !== "\\" || (this.input[this.pos + 1] ?? "") !== "u") && this._fail(`lone high surrogate \\u${n} in hex string comment`, e, t), this._advance(), this._advance();
202
+ let r = "";
203
+ for (let e = 0; e < 4 && !(this._eof() || this._ch() === "\n" || !/[0-9a-fA-F]/.test(this._ch())); e++) r += this._advance();
204
+ let i = parseInt(r || "0", 16);
205
+ (i < 56320 || i > 57343) && this._fail(`\\u${n} (high surrogate) not followed by valid low surrogate in hex string comment`, e, t);
206
+ return;
207
+ }
208
+ r >= 56320 && r <= 57343 && this._fail(`lone low surrogate \\u${n} in hex string comment`, e, t);
209
+ }
210
+ _skipRawComment(e, t, n, r, i) {
211
+ let a = e[t];
212
+ if (a === "/") {
213
+ if (t++, e[t] === "/") {
214
+ for (t++; t < e.length && e[t] !== "\n";) t++;
215
+ return t;
216
+ }
217
+ if (e[t] === "*") {
218
+ for (t++; t < e.length;) {
219
+ if (e[t] === "*" && e[t + 1] === "/") return t + 2;
220
+ t++;
221
+ }
222
+ return t;
223
+ }
224
+ for (; t < e.length && e[t] !== "/";) t++;
225
+ return t >= e.length && this._fail(`unterminated block comment in ${n}`, r, i), t + 1;
226
+ }
227
+ if (a === "#") {
228
+ for (; t < e.length && e[t] !== "\n";) t++;
229
+ return t;
230
+ }
231
+ return -1;
232
+ }
233
+ _skipBlockCommentSlash() {
234
+ let e = this.line, t = this.col;
235
+ for (; !this._eof();) {
236
+ if (this._ch() === "\\") {
237
+ this._advance(), this._eof() || this._advance();
238
+ continue;
239
+ }
240
+ if (this._ch() === "/") break;
241
+ this._advance();
242
+ }
243
+ this._eof() && this._fail("unterminated block comment", e, t), this._advance();
244
+ }
245
+ _skipBlockCommentStar() {
246
+ let e = this.line, t = this.col;
247
+ for (; !this._eof();) {
248
+ if (this._ch() === "*" && (this.input[this.pos + 1] ?? "") === "/") {
249
+ this._advance(), this._advance();
250
+ return;
251
+ }
252
+ this._advance();
253
+ }
254
+ this._fail("unterminated block comment", e, t);
255
+ }
256
+ _readStringContent(e) {
257
+ this._advance();
258
+ let t = e.charCodeAt(0), n = this.input.length, r = "";
259
+ for (; !this._eof() && this._ch() !== e;) {
260
+ let i = this.pos, a = 0, o = -1;
261
+ for (; i < n;) {
262
+ let e = this.input.charCodeAt(i);
263
+ if (e === t || e === 92 || e === 127) break;
264
+ if (e < 32) {
265
+ if (e !== 10) break;
266
+ a++, o = i;
267
+ }
268
+ i++;
269
+ }
270
+ if (i > this.pos) {
271
+ r += this.input.slice(this.pos, i), a > 0 ? (this.line += a, this.col = i - o) : this.col += i - this.pos, this.pos = i;
272
+ continue;
273
+ }
274
+ let s = this._ch();
275
+ if (s === "\r") {
276
+ this._advance();
277
+ continue;
278
+ }
279
+ let c = s.codePointAt(0);
280
+ if ((c < 32 && c !== 10 || c === 127) && this._fail(`unescaped control character U+${c.toString(16).padStart(4, "0")} is not allowed in string literals`), s === "\\") {
281
+ let t = this.pos, n = this.line, i = this.col;
282
+ this._advance();
283
+ let a = this._advance();
284
+ switch (a) {
285
+ case "n":
286
+ r += "\n";
287
+ break;
288
+ case "r":
289
+ r += "\r";
290
+ break;
291
+ case "t":
292
+ r += " ";
293
+ break;
294
+ case "b":
295
+ r += "\b";
296
+ break;
297
+ case "f":
298
+ r += "\f";
299
+ break;
300
+ case "\\":
301
+ r += "\\";
302
+ break;
303
+ case "u":
304
+ r += this._readUnicodeEscape(e, t, n, i);
305
+ break;
306
+ default:
307
+ if (a === e) {
308
+ r += a;
309
+ break;
310
+ }
311
+ if (a === "/") {
312
+ e === "'" && this._fail("\\/ is not a valid escape in single-quoted byte strings (§5.1)", n, i), r += "/";
313
+ break;
314
+ }
315
+ if (this.onEscapeWarning) {
316
+ if (a === "0") {
317
+ this.onEscapeWarning("\\0 is a non-standard escape sequence; use \\u0000 instead", t, n, i), r += "\0";
318
+ break;
319
+ }
320
+ if (a === "v") {
321
+ this.onEscapeWarning("\\v is a non-standard escape sequence; use \\u000b instead", t, n, i), r += "\v";
322
+ break;
323
+ }
324
+ if (a === "x") {
325
+ let e = this._ch(), a = this.input[this.pos + 1] ?? "";
326
+ (!/[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();
327
+ let o = parseInt(e + a, 16);
328
+ this.onEscapeWarning(`\\x${e}${a} is a non-standard escape sequence; use \\u00${e}${a} instead`, t, n, i), r += String.fromCharCode(o);
329
+ break;
330
+ }
331
+ if (a === "\"" || a === "'") {
332
+ this.onEscapeWarning(`\\${a} inside ${e === "\"" ? "double" : "single"}-quoted string is non-standard`, t, n, i), r += a;
333
+ break;
334
+ }
335
+ if (a === "\n" || a === "\r") {
336
+ a === "\r" && this._ch() === "\n" && this._advance(), this.onEscapeWarning("line continuation (\\<newline>) is non-standard; the newline is ignored", t, n, i);
337
+ break;
338
+ }
339
+ this.onEscapeWarning(`\\${a} is an unknown escape sequence; interpreted as '${a}'`, t, n, i), r += a;
340
+ break;
341
+ }
342
+ this._fail(`invalid escape sequence \\${a} in ${e === "\"" ? "double" : "single"}-quoted string`, n, i);
343
+ }
344
+ } else r += this._advance();
345
+ }
346
+ return this._eof() && this._fail("unterminated string literal"), this._advance(), r;
347
+ }
348
+ _readUnicodeEscape(e, t, n, r) {
349
+ let i = this.line, a = this.col, o = (o) => {
350
+ if (e === "'" && o >= 32 && o <= 126) {
351
+ 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)`;
352
+ if (this.onEscapeWarning) {
353
+ this.onEscapeWarning(e, t ?? this.pos, n ?? i, r ?? a);
354
+ return;
355
+ }
356
+ this._fail(e, i, a);
357
+ }
358
+ };
359
+ if (!this._eof() && this._ch() === "{") {
360
+ this._advance();
361
+ let e = "";
362
+ for (; !this._eof() && this._ch() !== "}";) {
363
+ let t = this._ch();
364
+ /[0-9a-fA-F]/.test(t) || this._fail(`invalid character in \\u{} escape: ${JSON.stringify(t)}`, i, a), e += this._advance();
365
+ }
366
+ this._eof() && this._fail("unterminated \\u{} escape", i, a), this._advance(), e.length === 0 && this._fail("empty \\u{} escape", i, a);
367
+ let t = parseInt(e, 16);
368
+ return t > 1114111 && this._fail(`\\u{${e}} exceeds maximum Unicode code point U+10FFFF`, i, a), t >= 55296 && t <= 57343 && this._fail(`\\u{${e}} is a surrogate code point, which is not a valid Unicode scalar value`, i, a), o(t), String.fromCodePoint(t);
369
+ }
370
+ let s = "";
371
+ for (let e = 0; e < 4; e++) {
372
+ this._eof() && this._fail("truncated \\uXXXX escape", i, a);
373
+ let e = this._ch();
374
+ /[0-9a-fA-F]/.test(e) || this._fail(`invalid hex digit in \\uXXXX escape: ${JSON.stringify(e)}`, i, a), s += this._advance();
375
+ }
376
+ let c = parseInt(s, 16);
377
+ if (c >= 55296 && c <= 56319) {
378
+ (this._ch() !== "\\" || (this.input[this.pos + 1] ?? "") !== "u") && this._fail(`lone high surrogate \\u${s} must be followed by \\uDC00–\\uDFFF`, i, a), this._advance(), this._advance();
379
+ let e = this.line, t = this.col, n = "";
380
+ for (let r = 0; r < 4; r++) this._eof() && this._fail("truncated low-surrogate escape", e, t), n += this._advance();
381
+ let r = parseInt(n, 16);
382
+ return (r < 56320 || r > 57343) && this._fail(`\\u${s} (high surrogate) not followed by a valid low surrogate (got \\u${n})`, i, a), String.fromCodePoint(65536 + (c - 55296) * 1024 + (r - 56320));
383
+ }
384
+ return c >= 56320 && c <= 57343 && this._fail(`lone low surrogate \\u${s} is not valid`, i, a), o(c), String.fromCharCode(c);
385
+ }
386
+ _readRawStringContent() {
387
+ let e = this.line, t = this.col, n = 0;
388
+ for (; !this._eof() && this._ch() === "`";) this._advance(), n++;
389
+ !this._eof() && this._ch() === "\r" && this._advance(), !this._eof() && this._ch() === "\n" && this._advance();
390
+ let r = this.input.length, i = "";
391
+ for (; !this._eof();) {
392
+ let a = this.pos, o = 0, s = -1;
393
+ for (; a < r;) {
394
+ let e = this.input.charCodeAt(a);
395
+ if (e === 96 || e === 127) break;
396
+ if (e < 32) {
397
+ if (e !== 10) break;
398
+ o++, s = a;
399
+ }
400
+ a++;
401
+ }
402
+ if (a > this.pos) {
403
+ i += this.input.slice(this.pos, a), o > 0 ? (this.line += o, this.col = a - s) : this.col += a - this.pos, this.pos = a;
404
+ continue;
405
+ }
406
+ let c = this._ch();
407
+ if (c === "\r") {
408
+ this._advance();
409
+ continue;
410
+ }
411
+ if (c === "`") {
412
+ let r = 0;
413
+ for (; !this._eof() && this._ch() === "`";) this._advance(), r++;
414
+ if (r >= n) return i += "`".repeat(r - n), i === "" && this._fail("raw string must not be empty (§2.5.3)", e, t), i;
415
+ i += "`".repeat(r);
416
+ } else {
417
+ let e = c.codePointAt(0);
418
+ e < 32 && e !== 10 && e !== 13 && this._fail(`raw string content must not contain control character U+${e.toString(16).toUpperCase().padStart(4, "0")} (§2.5.3)`, this.line, this.col), e === 127 && this._fail("raw string content must not contain DEL (U+007F) (§2.5.3)", this.line, this.col), i += this._advance();
419
+ }
420
+ }
421
+ this._fail("unterminated raw string literal", e, t);
422
+ }
423
+ _processRawHexContent(e, t, n) {
424
+ let i = "", a = !1, o = 0;
425
+ for (; o < e.length;) {
426
+ let s = e[o];
427
+ if (s === "\n" || s === " " || s === "\r") {
428
+ o++;
429
+ continue;
430
+ }
431
+ s === " " && this._fail("horizontal tab (HT) is not allowed inside h`` raw byte string literals (§5.3.3)", t, n);
432
+ let c = this._skipRawComment(e, o, "h`` raw byte string", t, n);
433
+ if (c !== -1) {
434
+ o = c;
435
+ continue;
436
+ }
437
+ if (s === "." && e[o + 1] === "." && e[o + 2] === ".") {
438
+ for (o += 3; o < e.length && e[o] === ".";) o++;
439
+ i += "...", a = !0;
440
+ continue;
441
+ }
442
+ if (r(e.charCodeAt(o))) {
443
+ let t = o;
444
+ for (; o < e.length && r(e.charCodeAt(o));) o++;
445
+ i += e.slice(t, o);
446
+ continue;
447
+ }
448
+ this._fail(`unexpected character ${JSON.stringify(s)} in h\`\` raw byte string`, t, n);
449
+ }
450
+ return {
451
+ value: i,
452
+ elided: a
453
+ };
454
+ }
455
+ _processRawB64Content(e, t, n) {
456
+ let r = "", i = 0;
457
+ for (; i < e.length;) {
458
+ let a = e[i];
459
+ if (a === "\n" || a === " " || a === "\r") {
460
+ i++;
461
+ continue;
462
+ }
463
+ if (a === " " && this._fail("horizontal tab (HT) is not allowed inside b64`` raw byte string literals (§5.3.4)", t, n), a === "#") {
464
+ for (; i < e.length && e[i] !== "\n";) i++;
465
+ continue;
466
+ }
467
+ let o = i;
468
+ for (; i < e.length;) {
469
+ let t = e[i];
470
+ if (t === "\n" || t === " " || t === "\r" || t === " " || t === "#") break;
471
+ i++;
472
+ }
473
+ r += e.slice(o, i);
474
+ }
475
+ return r;
476
+ }
477
+ _readByteContent(e) {
478
+ this._advance();
479
+ let t = "";
480
+ for (; !this._eof() && this._ch() !== e;) {
481
+ let n = this._ch();
482
+ if (n === "\n" || n === " ") {
483
+ this._advance();
484
+ continue;
485
+ }
486
+ if (n === "\r") {
487
+ this._advance();
488
+ continue;
489
+ }
490
+ if (n === " " && this._fail("horizontal tab (HT) is not allowed inside byte string literals (§5.2.2)", this.line, this.col), n === "#") {
491
+ for (; !this._eof() && this._ch() !== "\n";) {
492
+ if (this._ch() === "\\") {
493
+ this._advance(), !this._eof() && this._ch() !== "\n" && this._advance();
494
+ continue;
495
+ }
496
+ if (this._ch() === e) break;
497
+ this._advance();
498
+ }
499
+ continue;
500
+ }
501
+ let r = this.pos, i = this.pos, a = this.input.length;
502
+ for (; i < a;) {
503
+ let t = this.input[i];
504
+ if (t === e || t === "\n" || t === " " || t === "\r" || t === " " || t === "#") break;
505
+ i++;
506
+ }
507
+ this.col += i - r, this.pos = i, t += this.input.slice(r, i);
508
+ }
509
+ return this._eof() && this._fail("unterminated byte string literal"), this._advance(), t;
510
+ }
511
+ _readHexByteContentElisionAware(e) {
512
+ this._advance();
513
+ let t = "", n = !1;
514
+ for (; !this._eof() && this._ch() !== e;) {
515
+ let i = this._ch();
516
+ if (i === "\n" || i === " " || i === "\r") {
517
+ this._advance();
518
+ continue;
519
+ }
520
+ if (i === " " && this._fail("horizontal tab (HT) is not allowed inside hex byte string literals (§5.2.1)", this.line, this.col), !this._skipByteStringComment(e)) {
521
+ if (i === "." && (this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
522
+ for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
523
+ t.endsWith("...") || (t += "..."), n = !0;
524
+ continue;
525
+ }
526
+ if (r(i.charCodeAt(0))) {
527
+ let e = this.pos, n = this.pos, i = this.input.length;
528
+ for (; n < i && r(this.input.charCodeAt(n));) n++;
529
+ this.col += n - e, this.pos = n, t += this.input.slice(e, n);
530
+ continue;
531
+ }
532
+ this._fail(`unexpected character ${JSON.stringify(i)} in hex byte string`);
533
+ }
534
+ }
535
+ return this._eof() && this._fail("unterminated hex byte string literal"), this._advance(), {
536
+ value: t,
537
+ elided: n
538
+ };
539
+ }
540
+ _readNext() {
541
+ this._skipWS();
542
+ let e = this.pos;
543
+ return {
544
+ ...this._readNextCore(),
545
+ raw: this.input.slice(e, this.pos),
546
+ offset: e,
547
+ endOffset: this.pos
548
+ };
549
+ }
550
+ _readNextCore() {
551
+ let e = this.line, t = this.col;
552
+ if (this._eof()) return {
553
+ type: "EOF",
554
+ value: "",
555
+ line: e,
556
+ col: t
557
+ };
558
+ let n = this._ch();
559
+ switch (n) {
560
+ case "[": return this._advance(), {
561
+ type: "LBRACKET",
562
+ value: "[",
563
+ line: e,
564
+ col: t
565
+ };
566
+ case "]": return this._advance(), {
567
+ type: "RBRACKET",
568
+ value: "]",
569
+ line: e,
570
+ col: t
571
+ };
572
+ case "{": return this._advance(), {
573
+ type: "LBRACE",
574
+ value: "{",
575
+ line: e,
576
+ col: t
577
+ };
578
+ case "}": return this._advance(), {
579
+ type: "RBRACE",
580
+ value: "}",
581
+ line: e,
582
+ col: t
583
+ };
584
+ case "(": return this._advance(), {
585
+ type: "LPAREN",
586
+ value: "(",
587
+ line: e,
588
+ col: t
589
+ };
590
+ case ")": return this._advance(), {
591
+ type: "RPAREN",
592
+ value: ")",
593
+ line: e,
594
+ col: t
595
+ };
596
+ case ":": return this._advance(), {
597
+ type: "COLON",
598
+ value: ":",
599
+ line: e,
600
+ col: t
601
+ };
602
+ case ",": return this._advance(), {
603
+ type: "COMMA",
604
+ value: ",",
605
+ line: e,
606
+ col: t
607
+ };
608
+ case "<":
609
+ if ((this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), {
610
+ type: "LT_LT",
611
+ value: "<<",
612
+ line: e,
613
+ col: t
614
+ };
615
+ this._fail("unexpected character '<'", e, t);
616
+ case ">":
617
+ if ((this.input[this.pos + 1] ?? "") === ">") return this._advance(), this._advance(), {
618
+ type: "GT_GT",
619
+ value: ">>",
620
+ line: e,
621
+ col: t
622
+ };
623
+ this._fail("unexpected character '>'", e, t);
624
+ case "+": {
625
+ let n = this._readSignedInfinity("+", e, t);
626
+ if (n !== null) return n;
627
+ let r = this.input[this.pos + 1] ?? "";
628
+ return r >= "0" && r <= "9" || r === "." ? (this._advance(), this._readNumber(e, t)) : (this._advance(), {
629
+ type: "PLUS",
630
+ value: "+",
631
+ line: e,
632
+ col: t
633
+ });
634
+ }
635
+ case "`": return {
636
+ type: "RAWSTRING",
637
+ value: this._readRawStringContent(),
638
+ line: e,
639
+ col: t
640
+ };
641
+ case "\"": {
642
+ let n = this._readStringContent("\"");
643
+ return n === "" && this._ch() === "_" ? (this._advance(), {
644
+ type: "EMPTY_INDEF_TEXT",
645
+ value: "",
646
+ line: e,
647
+ col: t
648
+ }) : {
649
+ type: "TSTR",
650
+ value: n,
651
+ line: e,
652
+ col: t
653
+ };
654
+ }
655
+ case "'": {
656
+ if ((this.input[this.pos + 1] ?? "") === "'" && (this.input[this.pos + 2] ?? "") === "_") return this._advance(), this._advance(), this._advance(), {
657
+ type: "EMPTY_INDEF_BYTES",
658
+ value: "",
659
+ line: e,
660
+ col: t
661
+ };
662
+ let n = this._readStringContent("'"), r = i.encode(n);
663
+ return {
664
+ type: "SQSTR",
665
+ value: Array.from(r, (e) => e.toString(16).padStart(2, "0")).join(""),
666
+ line: e,
667
+ col: t
668
+ };
669
+ }
670
+ }
671
+ if (n === "-") {
672
+ let n = this._readSignedInfinity("-", e, t);
673
+ return n === null ? this._readNumber(e, t) : n;
674
+ }
675
+ if (n >= "0" && n <= "9" || n === "." && /[0-9]/.test(this.input[this.pos + 1] ?? "")) return this._readNumber(e, t);
676
+ if (/[a-zA-Z_]/.test(n)) return this._readIdent(e, t);
677
+ if (n === ".") {
678
+ if ((this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
679
+ for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
680
+ return {
681
+ type: "ELLIPSIS",
682
+ value: "...",
683
+ line: e,
684
+ col: t
685
+ };
686
+ }
687
+ this._fail("unexpected character '.'", e, t);
688
+ }
689
+ this._fail(`unexpected character ${JSON.stringify(n)}`, e, t);
690
+ }
691
+ _readSignedInfinity(e, t, n) {
692
+ if (!this.input.startsWith("Infinity", this.pos + 1)) return null;
693
+ let r = this.input[this.pos + 9] ?? "", i = r === "_" && /[0-7i]/.test(this.input[this.pos + 10] ?? "") && !/[a-zA-Z0-9_]/.test(this.input[this.pos + 11] ?? "");
694
+ if (/[a-zA-Z0-9_]/.test(r) && !i) return null;
695
+ this._advance();
696
+ for (let e = 0; e < 8; e++) this._advance();
697
+ let a = e === "-" ? "-Infinity" : "Infinity";
698
+ return i && (a += this._advance() + this._advance()), {
699
+ type: "FLOAT",
700
+ value: a,
701
+ line: t,
702
+ col: n
703
+ };
704
+ }
705
+ _skipHexDigits() {
706
+ let e = this.pos, t = this.input.length;
707
+ for (; e < t && r(this.input.charCodeAt(e));) e++;
708
+ this.col += e - this.pos, this.pos = e;
709
+ }
710
+ _skipDecimalDigits() {
711
+ let e = this.pos, t = this.input.length;
712
+ for (; e < t;) {
713
+ let t = this.input.charCodeAt(e);
714
+ if (t < 48 || t > 57) break;
715
+ e++;
716
+ }
717
+ this.col += e - this.pos, this.pos = e;
718
+ }
719
+ _tryConsumeEncodingSuffix() {
720
+ if (this._ch() !== "_") return;
721
+ let e = this.input[this.pos + 1] ?? "", t = this.input[this.pos + 2] ?? "";
722
+ (e >= "0" && e <= "7" || e === "i") && !/[0-9a-zA-Z_]/.test(t) && (this._advance(), this._advance());
723
+ }
724
+ _readNumber(e, t) {
725
+ let n = this.pos, r = () => this.input.slice(n, this.pos);
726
+ if (this._ch() === "-" && this._advance(), this._ch() === "0") {
727
+ let n = this.input[this.pos + 1] ?? "";
728
+ if (n === "x" || n === "X") {
729
+ this._advance(), this._advance();
730
+ let n = this.pos;
731
+ this._skipHexDigits();
732
+ let i = this.pos > n, a = !1, o = !1;
733
+ if (!this._eof() && this._ch() === ".") {
734
+ a = !0, this._advance();
735
+ let e = this.pos;
736
+ this._skipHexDigits(), o = this.pos > e;
737
+ }
738
+ if (!this._eof() && (this._ch() === "p" || this._ch() === "P")) {
739
+ a = !0, !i && !o && this._fail(`hex float has no mantissa digits: ${r()}`, e, t), this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && this._advance();
740
+ let n = this.pos;
741
+ this._skipDecimalDigits(), this.pos === n && this._fail(`hex float missing exponent digits: ${r()}`, e, t);
742
+ } else a && this._fail(`hex float missing 'p' exponent: ${r()}`, e, t);
743
+ return a ? (this._tryConsumeEncodingSuffix(), {
744
+ type: "FLOAT",
745
+ value: r(),
746
+ line: e,
747
+ col: t
748
+ }) : {
749
+ type: "INTEGER",
750
+ value: r(),
751
+ line: e,
752
+ col: t
753
+ };
754
+ }
755
+ if (n === "o" || n === "O") {
756
+ for (this._advance(), this._advance(); !this._eof() && this._ch() >= "0" && this._ch() <= "7";) this._advance();
757
+ return {
758
+ type: "INTEGER",
759
+ value: r(),
760
+ line: e,
761
+ col: t
762
+ };
763
+ }
764
+ if (n === "b" || n === "B") {
765
+ for (this._advance(), this._advance(); !this._eof() && (this._ch() === "0" || this._ch() === "1");) this._advance();
766
+ return {
767
+ type: "INTEGER",
768
+ value: r(),
769
+ line: e,
770
+ col: t
771
+ };
772
+ }
773
+ }
774
+ this._skipDecimalDigits();
775
+ let i = !1;
776
+ if (!this._eof() && this._ch() === "." && (i = !0, this._advance(), this._skipDecimalDigits()), !this._eof() && (this._ch() === "e" || this._ch() === "E")) {
777
+ i = !0, this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && this._advance();
778
+ let n = this.pos;
779
+ this._skipDecimalDigits(), this.pos === n && this._fail(`float exponent has no digits: ${JSON.stringify(r())}`, e, t);
780
+ }
781
+ return this._tryConsumeEncodingSuffix(), {
782
+ type: i ? "FLOAT" : "INTEGER",
783
+ value: r(),
784
+ line: e,
785
+ col: t
786
+ };
787
+ }
788
+ _readIdent(e, t) {
789
+ let n = this.pos;
790
+ {
791
+ let e = this.pos, t = this.input.length;
792
+ for (; e < t;) {
793
+ let t = this.input.charCodeAt(e);
794
+ if (!(t >= 97 && t <= 122 || t >= 65 && t <= 90 || t >= 48 && t <= 57 || t === 95)) break;
795
+ e++;
796
+ }
797
+ this.col += e - this.pos, this.pos = e;
798
+ }
799
+ let r = this.input.slice(n, this.pos);
800
+ switch (r) {
801
+ case "true": return {
802
+ type: "TRUE",
803
+ value: r,
804
+ line: e,
805
+ col: t
806
+ };
807
+ case "false": return {
808
+ type: "FALSE",
809
+ value: r,
810
+ line: e,
811
+ col: t
812
+ };
813
+ case "null": return {
814
+ type: "NULL",
815
+ value: r,
816
+ line: e,
817
+ col: t
818
+ };
819
+ case "undefined": return {
820
+ type: "UNDEFINED",
821
+ value: r,
822
+ line: e,
823
+ col: t
824
+ };
825
+ case "NaN":
826
+ case "NaN_0":
827
+ case "NaN_1":
828
+ case "NaN_2":
829
+ case "NaN_3":
830
+ case "NaN_4":
831
+ case "NaN_5":
832
+ case "NaN_6":
833
+ case "NaN_7":
834
+ case "NaN_i":
835
+ case "Infinity":
836
+ case "Infinity_0":
837
+ case "Infinity_1":
838
+ case "Infinity_2":
839
+ case "Infinity_3":
840
+ case "Infinity_4":
841
+ case "Infinity_5":
842
+ case "Infinity_6":
843
+ case "Infinity_7":
844
+ case "Infinity_i": return {
845
+ type: "FLOAT",
846
+ value: r,
847
+ line: e,
848
+ col: t
849
+ };
850
+ case "simple": return {
851
+ type: "SIMPLE",
852
+ value: r,
853
+ line: e,
854
+ col: t
855
+ };
856
+ case "_": return {
857
+ type: "UNDERSCORE",
858
+ value: "_",
859
+ line: e,
860
+ col: t
861
+ };
862
+ case "_0": return {
863
+ type: "ENCODING_INDICATOR",
864
+ value: "0",
865
+ line: e,
866
+ col: t
867
+ };
868
+ case "_1": return {
869
+ type: "ENCODING_INDICATOR",
870
+ value: "1",
871
+ line: e,
872
+ col: t
873
+ };
874
+ case "_2": return {
875
+ type: "ENCODING_INDICATOR",
876
+ value: "2",
877
+ line: e,
878
+ col: t
879
+ };
880
+ case "_3": return {
881
+ type: "ENCODING_INDICATOR",
882
+ value: "3",
883
+ line: e,
884
+ col: t
885
+ };
886
+ case "_4": return {
887
+ type: "ENCODING_INDICATOR",
888
+ value: "4",
889
+ line: e,
890
+ col: t
891
+ };
892
+ case "_5": return {
893
+ type: "ENCODING_INDICATOR",
894
+ value: "5",
895
+ line: e,
896
+ col: t
897
+ };
898
+ case "_6": return {
899
+ type: "ENCODING_INDICATOR",
900
+ value: "6",
901
+ line: e,
902
+ col: t
903
+ };
904
+ case "_7": return {
905
+ type: "ENCODING_INDICATOR",
906
+ value: "7",
907
+ line: e,
908
+ col: t
909
+ };
910
+ case "_i": return {
911
+ type: "ENCODING_INDICATOR",
912
+ value: "i",
913
+ line: e,
914
+ col: t
915
+ };
916
+ }
917
+ let i = r[0] ?? "", a = i >= "a" && i <= "z";
918
+ if (a || i >= "A" && i <= "Z") {
919
+ let n = r.slice(1);
920
+ if (a ? /^[a-z0-9]*$/.test(n) : /^[A-Z0-9]*$/.test(n)) {
921
+ let n = this.pos;
922
+ for (; !this._eof();) {
923
+ let e = this._ch();
924
+ if (!(a ? e >= "a" && e <= "z" || e >= "0" && e <= "9" || e === "-" : e >= "A" && e <= "Z" || e >= "0" && e <= "9" || e === "-")) break;
925
+ this.pos++;
926
+ }
927
+ this.pos > n && (this.col += this.pos - n, r += this.input.slice(n, this.pos));
928
+ let i = this._ch();
929
+ if (i === "\"" && this._fail(`"${r}" prefix requires single quotes or backticks, not double quotes`, e, t), i === "'") switch (r) {
930
+ case "h": {
931
+ let { value: n, elided: r } = this._readHexByteContentElisionAware(i);
932
+ return {
933
+ type: r ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
934
+ value: n,
935
+ line: e,
936
+ col: t
937
+ };
938
+ }
939
+ case "b64": return {
940
+ type: "BYTES_B64",
941
+ value: this._readByteContent(i),
942
+ line: e,
943
+ col: t
944
+ };
945
+ default: return {
946
+ type: "APP_STRING",
947
+ appPrefix: r,
948
+ value: this._readStringContent(i),
949
+ line: e,
950
+ col: t
951
+ };
952
+ }
953
+ if (i === "`") {
954
+ let n = this._readRawStringContent();
955
+ switch (r) {
956
+ case "h": {
957
+ let { value: r, elided: i } = this._processRawHexContent(n, e, t);
958
+ return {
959
+ type: i ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
960
+ value: r,
961
+ line: e,
962
+ col: t
963
+ };
964
+ }
965
+ case "b64": return {
966
+ type: "BYTES_B64",
967
+ value: this._processRawB64Content(n, e, t),
968
+ line: e,
969
+ col: t
970
+ };
971
+ default: return {
972
+ type: "APP_STRING",
973
+ appPrefix: r,
974
+ value: n,
975
+ line: e,
976
+ col: t
977
+ };
978
+ }
979
+ }
980
+ if (i === "<" && (this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), {
981
+ type: "APP_SEQUENCE",
982
+ appPrefix: r,
983
+ value: "",
984
+ line: e,
985
+ col: t
986
+ };
987
+ }
988
+ }
989
+ this._fail(`unknown identifier ${JSON.stringify(r)}`, e, t);
990
+ }
991
+ };
992
+ //#endregion
993
+ export { e as n, a as t };
994
+
995
+ //# sourceMappingURL=tokenizer-C597LW89.js.map