@aiao/code-editor-vue 0.0.7

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,1305 @@
1
+ import { P as L, o as M, p as $, D as E, q as y, T as S, I as j } from "./index-3d5LPf68.js";
2
+ class v {
3
+ /**
4
+ @internal
5
+ */
6
+ constructor(t, e, s, i, h, r, n, o, a, u = 0, f) {
7
+ this.p = t, this.stack = e, this.state = s, this.reducePos = i, this.pos = h, this.score = r, this.buffer = n, this.bufferBase = o, this.curContext = a, this.lookAhead = u, this.parent = f;
8
+ }
9
+ /**
10
+ @internal
11
+ */
12
+ toString() {
13
+ return `[${this.stack.filter((t, e) => e % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
14
+ }
15
+ // Start an empty stack
16
+ /**
17
+ @internal
18
+ */
19
+ static start(t, e, s = 0) {
20
+ let i = t.parser.context;
21
+ return new v(t, [], e, s, s, 0, [], 0, i ? new N(i, i.start) : null, 0, null);
22
+ }
23
+ /**
24
+ The stack's current [context](#lr.ContextTracker) value, if
25
+ any. Its type will depend on the context tracker's type
26
+ parameter, or it will be `null` if there is no context
27
+ tracker.
28
+ */
29
+ get context() {
30
+ return this.curContext ? this.curContext.context : null;
31
+ }
32
+ // Push a state onto the stack, tracking its start position as well
33
+ // as the buffer base at that point.
34
+ /**
35
+ @internal
36
+ */
37
+ pushState(t, e) {
38
+ this.stack.push(this.state, e, this.bufferBase + this.buffer.length), this.state = t;
39
+ }
40
+ // Apply a reduce action
41
+ /**
42
+ @internal
43
+ */
44
+ reduce(t) {
45
+ var e;
46
+ let s = t >> 19, i = t & 65535, { parser: h } = this.p, r = this.reducePos < this.pos - 25 && this.setLookAhead(this.pos), n = h.dynamicPrecedence(i);
47
+ if (n && (this.score += n), s == 0) {
48
+ this.pushState(h.getGoto(this.state, i, !0), this.reducePos), i < h.minRepeatTerm && this.storeNode(i, this.reducePos, this.reducePos, r ? 8 : 4, !0), this.reduceContext(i, this.reducePos);
49
+ return;
50
+ }
51
+ let o = this.stack.length - (s - 1) * 3 - (t & 262144 ? 6 : 0), a = o ? this.stack[o - 2] : this.p.ranges[0].from, u = this.reducePos - a;
52
+ u >= 2e3 && !(!((e = this.p.parser.nodeSet.types[i]) === null || e === void 0) && e.isAnonymous) && (a == this.p.lastBigReductionStart ? (this.p.bigReductionCount++, this.p.lastBigReductionSize = u) : this.p.lastBigReductionSize < u && (this.p.bigReductionCount = 1, this.p.lastBigReductionStart = a, this.p.lastBigReductionSize = u));
53
+ let f = o ? this.stack[o - 1] : 0, p = this.bufferBase + this.buffer.length - f;
54
+ if (i < h.minRepeatTerm || t & 131072) {
55
+ let c = h.stateFlag(
56
+ this.state,
57
+ 1
58
+ /* StateFlag.Skipped */
59
+ ) ? this.pos : this.reducePos;
60
+ this.storeNode(i, a, c, p + 4, !0);
61
+ }
62
+ if (t & 262144)
63
+ this.state = this.stack[o];
64
+ else {
65
+ let c = this.stack[o - 3];
66
+ this.state = h.getGoto(c, i, !0);
67
+ }
68
+ for (; this.stack.length > o; )
69
+ this.stack.pop();
70
+ this.reduceContext(i, a);
71
+ }
72
+ // Shift a value into the buffer
73
+ /**
74
+ @internal
75
+ */
76
+ storeNode(t, e, s, i = 4, h = !1) {
77
+ if (t == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
78
+ let r = this, n = this.buffer.length;
79
+ if (n == 0 && r.parent && (n = r.bufferBase - r.parent.bufferBase, r = r.parent), n > 0 && r.buffer[n - 4] == 0 && r.buffer[n - 1] > -1) {
80
+ if (e == s)
81
+ return;
82
+ if (r.buffer[n - 2] >= e) {
83
+ r.buffer[n - 2] = s;
84
+ return;
85
+ }
86
+ }
87
+ }
88
+ if (!h || this.pos == s)
89
+ this.buffer.push(t, e, s, i);
90
+ else {
91
+ let r = this.buffer.length;
92
+ if (r > 0 && (this.buffer[r - 4] != 0 || this.buffer[r - 1] < 0)) {
93
+ let n = !1;
94
+ for (let o = r; o > 0 && this.buffer[o - 2] > s; o -= 4)
95
+ if (this.buffer[o - 1] >= 0) {
96
+ n = !0;
97
+ break;
98
+ }
99
+ if (n)
100
+ for (; r > 0 && this.buffer[r - 2] > s; )
101
+ this.buffer[r] = this.buffer[r - 4], this.buffer[r + 1] = this.buffer[r - 3], this.buffer[r + 2] = this.buffer[r - 2], this.buffer[r + 3] = this.buffer[r - 1], r -= 4, i > 4 && (i -= 4);
102
+ }
103
+ this.buffer[r] = t, this.buffer[r + 1] = e, this.buffer[r + 2] = s, this.buffer[r + 3] = i;
104
+ }
105
+ }
106
+ // Apply a shift action
107
+ /**
108
+ @internal
109
+ */
110
+ shift(t, e, s, i) {
111
+ if (t & 131072)
112
+ this.pushState(t & 65535, this.pos);
113
+ else if ((t & 262144) == 0) {
114
+ let h = t, { parser: r } = this.p;
115
+ (i > this.pos || e <= r.maxNode) && (this.pos = i, r.stateFlag(
116
+ h,
117
+ 1
118
+ /* StateFlag.Skipped */
119
+ ) || (this.reducePos = i)), this.pushState(h, s), this.shiftContext(e, s), e <= r.maxNode && this.buffer.push(e, s, i, 4);
120
+ } else
121
+ this.pos = i, this.shiftContext(e, s), e <= this.p.parser.maxNode && this.buffer.push(e, s, i, 4);
122
+ }
123
+ // Apply an action
124
+ /**
125
+ @internal
126
+ */
127
+ apply(t, e, s, i) {
128
+ t & 65536 ? this.reduce(t) : this.shift(t, e, s, i);
129
+ }
130
+ // Add a prebuilt (reused) node into the buffer.
131
+ /**
132
+ @internal
133
+ */
134
+ useNode(t, e) {
135
+ let s = this.p.reused.length - 1;
136
+ (s < 0 || this.p.reused[s] != t) && (this.p.reused.push(t), s++);
137
+ let i = this.pos;
138
+ this.reducePos = this.pos = i + t.length, this.pushState(e, i), this.buffer.push(
139
+ s,
140
+ i,
141
+ this.reducePos,
142
+ -1
143
+ /* size == -1 means this is a reused value */
144
+ ), this.curContext && this.updateContext(this.curContext.tracker.reuse(this.curContext.context, t, this, this.p.stream.reset(this.pos - t.length)));
145
+ }
146
+ // Split the stack. Due to the buffer sharing and the fact
147
+ // that `this.stack` tends to stay quite shallow, this isn't very
148
+ // expensive.
149
+ /**
150
+ @internal
151
+ */
152
+ split() {
153
+ let t = this, e = t.buffer.length;
154
+ for (; e > 0 && t.buffer[e - 2] > t.reducePos; )
155
+ e -= 4;
156
+ let s = t.buffer.slice(e), i = t.bufferBase + e;
157
+ for (; t && i == t.bufferBase; )
158
+ t = t.parent;
159
+ return new v(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, s, i, this.curContext, this.lookAhead, t);
160
+ }
161
+ // Try to recover from an error by 'deleting' (ignoring) one token.
162
+ /**
163
+ @internal
164
+ */
165
+ recoverByDelete(t, e) {
166
+ let s = t <= this.p.parser.maxNode;
167
+ s && this.storeNode(t, this.pos, e, 4), this.storeNode(0, this.pos, e, s ? 8 : 4), this.pos = this.reducePos = e, this.score -= 190;
168
+ }
169
+ /**
170
+ Check if the given term would be able to be shifted (optionally
171
+ after some reductions) on this stack. This can be useful for
172
+ external tokenizers that want to make sure they only provide a
173
+ given token when it applies.
174
+ */
175
+ canShift(t) {
176
+ for (let e = new G(this); ; ) {
177
+ let s = this.p.parser.stateSlot(
178
+ e.state,
179
+ 4
180
+ /* ParseState.DefaultReduce */
181
+ ) || this.p.parser.hasAction(e.state, t);
182
+ if (s == 0)
183
+ return !1;
184
+ if ((s & 65536) == 0)
185
+ return !0;
186
+ e.reduce(s);
187
+ }
188
+ }
189
+ // Apply up to Recover.MaxNext recovery actions that conceptually
190
+ // inserts some missing token or rule.
191
+ /**
192
+ @internal
193
+ */
194
+ recoverByInsert(t) {
195
+ if (this.stack.length >= 300)
196
+ return [];
197
+ let e = this.p.parser.nextStates(this.state);
198
+ if (e.length > 8 || this.stack.length >= 120) {
199
+ let i = [];
200
+ for (let h = 0, r; h < e.length; h += 2)
201
+ (r = e[h + 1]) != this.state && this.p.parser.hasAction(r, t) && i.push(e[h], r);
202
+ if (this.stack.length < 120)
203
+ for (let h = 0; i.length < 8 && h < e.length; h += 2) {
204
+ let r = e[h + 1];
205
+ i.some((n, o) => o & 1 && n == r) || i.push(e[h], r);
206
+ }
207
+ e = i;
208
+ }
209
+ let s = [];
210
+ for (let i = 0; i < e.length && s.length < 4; i += 2) {
211
+ let h = e[i + 1];
212
+ if (h == this.state)
213
+ continue;
214
+ let r = this.split();
215
+ r.pushState(h, this.pos), r.storeNode(0, r.pos, r.pos, 4, !0), r.shiftContext(e[i], this.pos), r.reducePos = this.pos, r.score -= 200, s.push(r);
216
+ }
217
+ return s;
218
+ }
219
+ // Force a reduce, if possible. Return false if that can't
220
+ // be done.
221
+ /**
222
+ @internal
223
+ */
224
+ forceReduce() {
225
+ let { parser: t } = this.p, e = t.stateSlot(
226
+ this.state,
227
+ 5
228
+ /* ParseState.ForcedReduce */
229
+ );
230
+ if ((e & 65536) == 0)
231
+ return !1;
232
+ if (!t.validAction(this.state, e)) {
233
+ let s = e >> 19, i = e & 65535, h = this.stack.length - s * 3;
234
+ if (h < 0 || t.getGoto(this.stack[h], i, !1) < 0) {
235
+ let r = this.findForcedReduction();
236
+ if (r == null)
237
+ return !1;
238
+ e = r;
239
+ }
240
+ this.storeNode(0, this.pos, this.pos, 4, !0), this.score -= 100;
241
+ }
242
+ return this.reducePos = this.pos, this.reduce(e), !0;
243
+ }
244
+ /**
245
+ Try to scan through the automaton to find some kind of reduction
246
+ that can be applied. Used when the regular ForcedReduce field
247
+ isn't a valid action. @internal
248
+ */
249
+ findForcedReduction() {
250
+ let { parser: t } = this.p, e = [], s = (i, h) => {
251
+ if (!e.includes(i))
252
+ return e.push(i), t.allActions(i, (r) => {
253
+ if (!(r & 393216)) if (r & 65536) {
254
+ let n = (r >> 19) - h;
255
+ if (n > 1) {
256
+ let o = r & 65535, a = this.stack.length - n * 3;
257
+ if (a >= 0 && t.getGoto(this.stack[a], o, !1) >= 0)
258
+ return n << 19 | 65536 | o;
259
+ }
260
+ } else {
261
+ let n = s(r, h + 1);
262
+ if (n != null)
263
+ return n;
264
+ }
265
+ });
266
+ };
267
+ return s(this.state, 0);
268
+ }
269
+ /**
270
+ @internal
271
+ */
272
+ forceAll() {
273
+ for (; !this.p.parser.stateFlag(
274
+ this.state,
275
+ 2
276
+ /* StateFlag.Accepting */
277
+ ); )
278
+ if (!this.forceReduce()) {
279
+ this.storeNode(0, this.pos, this.pos, 4, !0);
280
+ break;
281
+ }
282
+ return this;
283
+ }
284
+ /**
285
+ Check whether this state has no further actions (assumed to be a direct descendant of the
286
+ top state, since any other states must be able to continue
287
+ somehow). @internal
288
+ */
289
+ get deadEnd() {
290
+ if (this.stack.length != 3)
291
+ return !1;
292
+ let { parser: t } = this.p;
293
+ return t.data[t.stateSlot(
294
+ this.state,
295
+ 1
296
+ /* ParseState.Actions */
297
+ )] == 65535 && !t.stateSlot(
298
+ this.state,
299
+ 4
300
+ /* ParseState.DefaultReduce */
301
+ );
302
+ }
303
+ /**
304
+ Restart the stack (put it back in its start state). Only safe
305
+ when this.stack.length == 3 (state is directly below the top
306
+ state). @internal
307
+ */
308
+ restart() {
309
+ this.storeNode(0, this.pos, this.pos, 4, !0), this.state = this.stack[0], this.stack.length = 0;
310
+ }
311
+ /**
312
+ @internal
313
+ */
314
+ sameState(t) {
315
+ if (this.state != t.state || this.stack.length != t.stack.length)
316
+ return !1;
317
+ for (let e = 0; e < this.stack.length; e += 3)
318
+ if (this.stack[e] != t.stack[e])
319
+ return !1;
320
+ return !0;
321
+ }
322
+ /**
323
+ Get the parser used by this stack.
324
+ */
325
+ get parser() {
326
+ return this.p.parser;
327
+ }
328
+ /**
329
+ Test whether a given dialect (by numeric ID, as exported from
330
+ the terms file) is enabled.
331
+ */
332
+ dialectEnabled(t) {
333
+ return this.p.parser.dialect.flags[t];
334
+ }
335
+ shiftContext(t, e) {
336
+ this.curContext && this.updateContext(this.curContext.tracker.shift(this.curContext.context, t, this, this.p.stream.reset(e)));
337
+ }
338
+ reduceContext(t, e) {
339
+ this.curContext && this.updateContext(this.curContext.tracker.reduce(this.curContext.context, t, this, this.p.stream.reset(e)));
340
+ }
341
+ /**
342
+ @internal
343
+ */
344
+ emitContext() {
345
+ let t = this.buffer.length - 1;
346
+ (t < 0 || this.buffer[t] != -3) && this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
347
+ }
348
+ /**
349
+ @internal
350
+ */
351
+ emitLookAhead() {
352
+ let t = this.buffer.length - 1;
353
+ (t < 0 || this.buffer[t] != -4) && this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
354
+ }
355
+ updateContext(t) {
356
+ if (t != this.curContext.context) {
357
+ let e = new N(this.curContext.tracker, t);
358
+ e.hash != this.curContext.hash && this.emitContext(), this.curContext = e;
359
+ }
360
+ }
361
+ /**
362
+ @internal
363
+ */
364
+ setLookAhead(t) {
365
+ return t <= this.lookAhead ? !1 : (this.emitLookAhead(), this.lookAhead = t, !0);
366
+ }
367
+ /**
368
+ @internal
369
+ */
370
+ close() {
371
+ this.curContext && this.curContext.tracker.strict && this.emitContext(), this.lookAhead > 0 && this.emitLookAhead();
372
+ }
373
+ }
374
+ class N {
375
+ constructor(t, e) {
376
+ this.tracker = t, this.context = e, this.hash = t.strict ? t.hash(e) : 0;
377
+ }
378
+ }
379
+ class G {
380
+ constructor(t) {
381
+ this.start = t, this.state = t.state, this.stack = t.stack, this.base = this.stack.length;
382
+ }
383
+ reduce(t) {
384
+ let e = t & 65535, s = t >> 19;
385
+ s == 0 ? (this.stack == this.start.stack && (this.stack = this.stack.slice()), this.stack.push(this.state, 0, 0), this.base += 3) : this.base -= (s - 1) * 3;
386
+ let i = this.start.p.parser.getGoto(this.stack[this.base - 3], e, !0);
387
+ this.state = i;
388
+ }
389
+ }
390
+ class A {
391
+ constructor(t, e, s) {
392
+ this.stack = t, this.pos = e, this.index = s, this.buffer = t.buffer, this.index == 0 && this.maybeNext();
393
+ }
394
+ static create(t, e = t.bufferBase + t.buffer.length) {
395
+ return new A(t, e, e - t.bufferBase);
396
+ }
397
+ maybeNext() {
398
+ let t = this.stack.parent;
399
+ t != null && (this.index = this.stack.bufferBase - t.bufferBase, this.stack = t, this.buffer = t.buffer);
400
+ }
401
+ get id() {
402
+ return this.buffer[this.index - 4];
403
+ }
404
+ get start() {
405
+ return this.buffer[this.index - 3];
406
+ }
407
+ get end() {
408
+ return this.buffer[this.index - 2];
409
+ }
410
+ get size() {
411
+ return this.buffer[this.index - 1];
412
+ }
413
+ next() {
414
+ this.index -= 4, this.pos -= 4, this.index == 0 && this.maybeNext();
415
+ }
416
+ fork() {
417
+ return new A(this.stack, this.pos, this.index);
418
+ }
419
+ }
420
+ function x(l, t = Uint16Array) {
421
+ if (typeof l != "string")
422
+ return l;
423
+ let e = null;
424
+ for (let s = 0, i = 0; s < l.length; ) {
425
+ let h = 0;
426
+ for (; ; ) {
427
+ let r = l.charCodeAt(s++), n = !1;
428
+ if (r == 126) {
429
+ h = 65535;
430
+ break;
431
+ }
432
+ r >= 92 && r--, r >= 34 && r--;
433
+ let o = r - 32;
434
+ if (o >= 46 && (o -= 46, n = !0), h += o, n)
435
+ break;
436
+ h *= 46;
437
+ }
438
+ e ? e[i++] = h : e = new t(h);
439
+ }
440
+ return e;
441
+ }
442
+ class P {
443
+ constructor() {
444
+ this.start = -1, this.value = -1, this.end = -1, this.extended = -1, this.lookAhead = 0, this.mask = 0, this.context = 0;
445
+ }
446
+ }
447
+ const R = new P();
448
+ class U {
449
+ /**
450
+ @internal
451
+ */
452
+ constructor(t, e) {
453
+ this.input = t, this.ranges = e, this.chunk = "", this.chunkOff = 0, this.chunk2 = "", this.chunk2Pos = 0, this.next = -1, this.token = R, this.rangeIndex = 0, this.pos = this.chunkPos = e[0].from, this.range = e[0], this.end = e[e.length - 1].to, this.readNext();
454
+ }
455
+ /**
456
+ @internal
457
+ */
458
+ resolveOffset(t, e) {
459
+ let s = this.range, i = this.rangeIndex, h = this.pos + t;
460
+ for (; h < s.from; ) {
461
+ if (!i)
462
+ return null;
463
+ let r = this.ranges[--i];
464
+ h -= s.from - r.to, s = r;
465
+ }
466
+ for (; e < 0 ? h > s.to : h >= s.to; ) {
467
+ if (i == this.ranges.length - 1)
468
+ return null;
469
+ let r = this.ranges[++i];
470
+ h += r.from - s.to, s = r;
471
+ }
472
+ return h;
473
+ }
474
+ /**
475
+ @internal
476
+ */
477
+ clipPos(t) {
478
+ if (t >= this.range.from && t < this.range.to)
479
+ return t;
480
+ for (let e of this.ranges)
481
+ if (e.to > t)
482
+ return Math.max(t, e.from);
483
+ return this.end;
484
+ }
485
+ /**
486
+ Look at a code unit near the stream position. `.peek(0)` equals
487
+ `.next`, `.peek(-1)` gives you the previous character, and so
488
+ on.
489
+
490
+ Note that looking around during tokenizing creates dependencies
491
+ on potentially far-away content, which may reduce the
492
+ effectiveness incremental parsing—when looking forward—or even
493
+ cause invalid reparses when looking backward more than 25 code
494
+ units, since the library does not track lookbehind.
495
+ */
496
+ peek(t) {
497
+ let e = this.chunkOff + t, s, i;
498
+ if (e >= 0 && e < this.chunk.length)
499
+ s = this.pos + t, i = this.chunk.charCodeAt(e);
500
+ else {
501
+ let h = this.resolveOffset(t, 1);
502
+ if (h == null)
503
+ return -1;
504
+ if (s = h, s >= this.chunk2Pos && s < this.chunk2Pos + this.chunk2.length)
505
+ i = this.chunk2.charCodeAt(s - this.chunk2Pos);
506
+ else {
507
+ let r = this.rangeIndex, n = this.range;
508
+ for (; n.to <= s; )
509
+ n = this.ranges[++r];
510
+ this.chunk2 = this.input.chunk(this.chunk2Pos = s), s + this.chunk2.length > n.to && (this.chunk2 = this.chunk2.slice(0, n.to - s)), i = this.chunk2.charCodeAt(0);
511
+ }
512
+ }
513
+ return s >= this.token.lookAhead && (this.token.lookAhead = s + 1), i;
514
+ }
515
+ /**
516
+ Accept a token. By default, the end of the token is set to the
517
+ current stream position, but you can pass an offset (relative to
518
+ the stream position) to change that.
519
+ */
520
+ acceptToken(t, e = 0) {
521
+ let s = e ? this.resolveOffset(e, -1) : this.pos;
522
+ if (s == null || s < this.token.start)
523
+ throw new RangeError("Token end out of bounds");
524
+ this.token.value = t, this.token.end = s;
525
+ }
526
+ /**
527
+ Accept a token ending at a specific given position.
528
+ */
529
+ acceptTokenTo(t, e) {
530
+ this.token.value = t, this.token.end = e;
531
+ }
532
+ getChunk() {
533
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
534
+ let { chunk: t, chunkPos: e } = this;
535
+ this.chunk = this.chunk2, this.chunkPos = this.chunk2Pos, this.chunk2 = t, this.chunk2Pos = e, this.chunkOff = this.pos - this.chunkPos;
536
+ } else {
537
+ this.chunk2 = this.chunk, this.chunk2Pos = this.chunkPos;
538
+ let t = this.input.chunk(this.pos), e = this.pos + t.length;
539
+ this.chunk = e > this.range.to ? t.slice(0, this.range.to - this.pos) : t, this.chunkPos = this.pos, this.chunkOff = 0;
540
+ }
541
+ }
542
+ readNext() {
543
+ return this.chunkOff >= this.chunk.length && (this.getChunk(), this.chunkOff == this.chunk.length) ? this.next = -1 : this.next = this.chunk.charCodeAt(this.chunkOff);
544
+ }
545
+ /**
546
+ Move the stream forward N (defaults to 1) code units. Returns
547
+ the new value of [`next`](#lr.InputStream.next).
548
+ */
549
+ advance(t = 1) {
550
+ for (this.chunkOff += t; this.pos + t >= this.range.to; ) {
551
+ if (this.rangeIndex == this.ranges.length - 1)
552
+ return this.setDone();
553
+ t -= this.range.to - this.pos, this.range = this.ranges[++this.rangeIndex], this.pos = this.range.from;
554
+ }
555
+ return this.pos += t, this.pos >= this.token.lookAhead && (this.token.lookAhead = this.pos + 1), this.readNext();
556
+ }
557
+ setDone() {
558
+ return this.pos = this.chunkPos = this.end, this.range = this.ranges[this.rangeIndex = this.ranges.length - 1], this.chunk = "", this.next = -1;
559
+ }
560
+ /**
561
+ @internal
562
+ */
563
+ reset(t, e) {
564
+ if (e ? (this.token = e, e.start = t, e.lookAhead = t + 1, e.value = e.extended = -1) : this.token = R, this.pos != t) {
565
+ if (this.pos = t, t == this.end)
566
+ return this.setDone(), this;
567
+ for (; t < this.range.from; )
568
+ this.range = this.ranges[--this.rangeIndex];
569
+ for (; t >= this.range.to; )
570
+ this.range = this.ranges[++this.rangeIndex];
571
+ t >= this.chunkPos && t < this.chunkPos + this.chunk.length ? this.chunkOff = t - this.chunkPos : (this.chunk = "", this.chunkOff = 0), this.readNext();
572
+ }
573
+ return this;
574
+ }
575
+ /**
576
+ @internal
577
+ */
578
+ read(t, e) {
579
+ if (t >= this.chunkPos && e <= this.chunkPos + this.chunk.length)
580
+ return this.chunk.slice(t - this.chunkPos, e - this.chunkPos);
581
+ if (t >= this.chunk2Pos && e <= this.chunk2Pos + this.chunk2.length)
582
+ return this.chunk2.slice(t - this.chunk2Pos, e - this.chunk2Pos);
583
+ if (t >= this.range.from && e <= this.range.to)
584
+ return this.input.read(t, e);
585
+ let s = "";
586
+ for (let i of this.ranges) {
587
+ if (i.from >= e)
588
+ break;
589
+ i.to > t && (s += this.input.read(Math.max(i.from, t), Math.min(i.to, e)));
590
+ }
591
+ return s;
592
+ }
593
+ }
594
+ class m {
595
+ constructor(t, e) {
596
+ this.data = t, this.id = e;
597
+ }
598
+ token(t, e) {
599
+ let { parser: s } = e.p;
600
+ F(this.data, t, e, this.id, s.data, s.tokenPrecTable);
601
+ }
602
+ }
603
+ m.prototype.contextual = m.prototype.fallback = m.prototype.extend = !1;
604
+ class H {
605
+ constructor(t, e, s) {
606
+ this.precTable = e, this.elseToken = s, this.data = typeof t == "string" ? x(t) : t;
607
+ }
608
+ token(t, e) {
609
+ let s = t.pos, i = 0;
610
+ for (; ; ) {
611
+ let h = t.next < 0, r = t.resolveOffset(1, 1);
612
+ if (F(this.data, t, e, 0, this.data, this.precTable), t.token.value > -1)
613
+ break;
614
+ if (this.elseToken == null)
615
+ return;
616
+ if (h || i++, r == null)
617
+ break;
618
+ t.reset(r, t.token);
619
+ }
620
+ i && (t.reset(s, t.token), t.acceptToken(this.elseToken, i));
621
+ }
622
+ }
623
+ H.prototype.contextual = m.prototype.fallback = m.prototype.extend = !1;
624
+ class Y {
625
+ /**
626
+ Create a tokenizer. The first argument is the function that,
627
+ given an input stream, scans for the types of tokens it
628
+ recognizes at the stream's position, and calls
629
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
630
+ one.
631
+ */
632
+ constructor(t, e = {}) {
633
+ this.token = t, this.contextual = !!e.contextual, this.fallback = !!e.fallback, this.extend = !!e.extend;
634
+ }
635
+ }
636
+ function F(l, t, e, s, i, h) {
637
+ let r = 0, n = 1 << s, { dialect: o } = e.p.parser;
638
+ t: for (; (n & l[r]) != 0; ) {
639
+ let a = l[r + 1];
640
+ for (let c = r + 3; c < a; c += 2)
641
+ if ((l[c + 1] & n) > 0) {
642
+ let d = l[c];
643
+ if (o.allows(d) && (t.token.value == -1 || t.token.value == d || W(d, t.token.value, i, h))) {
644
+ t.acceptToken(d);
645
+ break;
646
+ }
647
+ }
648
+ let u = t.next, f = 0, p = l[r + 2];
649
+ if (t.next < 0 && p > f && l[a + p * 3 - 3] == 65535) {
650
+ r = l[a + p * 3 - 1];
651
+ continue t;
652
+ }
653
+ for (; f < p; ) {
654
+ let c = f + p >> 1, d = a + c + (c << 1), b = l[d], O = l[d + 1] || 65536;
655
+ if (u < b)
656
+ p = c;
657
+ else if (u >= O)
658
+ f = c + 1;
659
+ else {
660
+ r = l[d + 2], t.advance();
661
+ continue t;
662
+ }
663
+ }
664
+ break;
665
+ }
666
+ }
667
+ function z(l, t, e) {
668
+ for (let s = t, i; (i = l[s]) != 65535; s++)
669
+ if (i == e)
670
+ return s - t;
671
+ return -1;
672
+ }
673
+ function W(l, t, e, s) {
674
+ let i = z(e, s, t);
675
+ return i < 0 || z(e, s, l) < i;
676
+ }
677
+ const g = typeof process < "u" && process.env && /\bparse\b/.test(process.env.LOG);
678
+ let T = null;
679
+ function I(l, t, e) {
680
+ let s = l.cursor(j.IncludeAnonymous);
681
+ for (s.moveTo(t); ; )
682
+ if (!(e < 0 ? s.childBefore(t) : s.childAfter(t)))
683
+ for (; ; ) {
684
+ if ((e < 0 ? s.to < t : s.from > t) && !s.type.isError)
685
+ return e < 0 ? Math.max(0, Math.min(
686
+ s.to - 1,
687
+ t - 25
688
+ /* Lookahead.Margin */
689
+ )) : Math.min(l.length, Math.max(
690
+ s.from + 1,
691
+ t + 25
692
+ /* Lookahead.Margin */
693
+ ));
694
+ if (e < 0 ? s.prevSibling() : s.nextSibling())
695
+ break;
696
+ if (!s.parent())
697
+ return e < 0 ? 0 : l.length;
698
+ }
699
+ }
700
+ class q {
701
+ constructor(t, e) {
702
+ this.fragments = t, this.nodeSet = e, this.i = 0, this.fragment = null, this.safeFrom = -1, this.safeTo = -1, this.trees = [], this.start = [], this.index = [], this.nextFragment();
703
+ }
704
+ nextFragment() {
705
+ let t = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
706
+ if (t) {
707
+ for (this.safeFrom = t.openStart ? I(t.tree, t.from + t.offset, 1) - t.offset : t.from, this.safeTo = t.openEnd ? I(t.tree, t.to + t.offset, -1) - t.offset : t.to; this.trees.length; )
708
+ this.trees.pop(), this.start.pop(), this.index.pop();
709
+ this.trees.push(t.tree), this.start.push(-t.offset), this.index.push(0), this.nextStart = this.safeFrom;
710
+ } else
711
+ this.nextStart = 1e9;
712
+ }
713
+ // `pos` must be >= any previously given `pos` for this cursor
714
+ nodeAt(t) {
715
+ if (t < this.nextStart)
716
+ return null;
717
+ for (; this.fragment && this.safeTo <= t; )
718
+ this.nextFragment();
719
+ if (!this.fragment)
720
+ return null;
721
+ for (; ; ) {
722
+ let e = this.trees.length - 1;
723
+ if (e < 0)
724
+ return this.nextFragment(), null;
725
+ let s = this.trees[e], i = this.index[e];
726
+ if (i == s.children.length) {
727
+ this.trees.pop(), this.start.pop(), this.index.pop();
728
+ continue;
729
+ }
730
+ let h = s.children[i], r = this.start[e] + s.positions[i];
731
+ if (r > t)
732
+ return this.nextStart = r, null;
733
+ if (h instanceof S) {
734
+ if (r == t) {
735
+ if (r < this.safeFrom)
736
+ return null;
737
+ let n = r + h.length;
738
+ if (n <= this.safeTo) {
739
+ let o = h.prop(y.lookAhead);
740
+ if (!o || n + o < this.fragment.to)
741
+ return h;
742
+ }
743
+ }
744
+ this.index[e]++, r + h.length >= Math.max(this.safeFrom, t) && (this.trees.push(h), this.start.push(r), this.index.push(0));
745
+ } else
746
+ this.index[e]++, this.nextStart = r + h.length;
747
+ }
748
+ }
749
+ }
750
+ class J {
751
+ constructor(t, e) {
752
+ this.stream = e, this.tokens = [], this.mainToken = null, this.actions = [], this.tokens = t.tokenizers.map((s) => new P());
753
+ }
754
+ getActions(t) {
755
+ let e = 0, s = null, { parser: i } = t.p, { tokenizers: h } = i, r = i.stateSlot(
756
+ t.state,
757
+ 3
758
+ /* ParseState.TokenizerMask */
759
+ ), n = t.curContext ? t.curContext.hash : 0, o = 0;
760
+ for (let a = 0; a < h.length; a++) {
761
+ if ((1 << a & r) == 0)
762
+ continue;
763
+ let u = h[a], f = this.tokens[a];
764
+ if (!(s && !u.fallback) && ((u.contextual || f.start != t.pos || f.mask != r || f.context != n) && (this.updateCachedToken(f, u, t), f.mask = r, f.context = n), f.lookAhead > f.end + 25 && (o = Math.max(f.lookAhead, o)), f.value != 0)) {
765
+ let p = e;
766
+ if (f.extended > -1 && (e = this.addActions(t, f.extended, f.end, e)), e = this.addActions(t, f.value, f.end, e), !u.extend && (s = f, e > p))
767
+ break;
768
+ }
769
+ }
770
+ for (; this.actions.length > e; )
771
+ this.actions.pop();
772
+ return o && t.setLookAhead(o), !s && t.pos == this.stream.end && (s = new P(), s.value = t.p.parser.eofTerm, s.start = s.end = t.pos, e = this.addActions(t, s.value, s.end, e)), this.mainToken = s, this.actions;
773
+ }
774
+ getMainToken(t) {
775
+ if (this.mainToken)
776
+ return this.mainToken;
777
+ let e = new P(), { pos: s, p: i } = t;
778
+ return e.start = s, e.end = Math.min(s + 1, i.stream.end), e.value = s == i.stream.end ? i.parser.eofTerm : 0, e;
779
+ }
780
+ updateCachedToken(t, e, s) {
781
+ let i = this.stream.clipPos(s.pos);
782
+ if (e.token(this.stream.reset(i, t), s), t.value > -1) {
783
+ let { parser: h } = s.p;
784
+ for (let r = 0; r < h.specialized.length; r++)
785
+ if (h.specialized[r] == t.value) {
786
+ let n = h.specializers[r](this.stream.read(t.start, t.end), s);
787
+ if (n >= 0 && s.p.parser.dialect.allows(n >> 1)) {
788
+ (n & 1) == 0 ? t.value = n >> 1 : t.extended = n >> 1;
789
+ break;
790
+ }
791
+ }
792
+ } else
793
+ t.value = 0, t.end = this.stream.clipPos(i + 1);
794
+ }
795
+ putAction(t, e, s, i) {
796
+ for (let h = 0; h < i; h += 3)
797
+ if (this.actions[h] == t)
798
+ return i;
799
+ return this.actions[i++] = t, this.actions[i++] = e, this.actions[i++] = s, i;
800
+ }
801
+ addActions(t, e, s, i) {
802
+ let { state: h } = t, { parser: r } = t.p, { data: n } = r;
803
+ for (let o = 0; o < 2; o++)
804
+ for (let a = r.stateSlot(
805
+ h,
806
+ o ? 2 : 1
807
+ /* ParseState.Actions */
808
+ ); ; a += 3) {
809
+ if (n[a] == 65535)
810
+ if (n[a + 1] == 1)
811
+ a = k(n, a + 2);
812
+ else {
813
+ i == 0 && n[a + 1] == 2 && (i = this.putAction(k(n, a + 2), e, s, i));
814
+ break;
815
+ }
816
+ n[a] == e && (i = this.putAction(k(n, a + 1), e, s, i));
817
+ }
818
+ return i;
819
+ }
820
+ }
821
+ class K {
822
+ constructor(t, e, s, i) {
823
+ this.parser = t, this.input = e, this.ranges = i, this.recovering = 0, this.nextStackID = 9812, this.minStackPos = 0, this.reused = [], this.stoppedAt = null, this.lastBigReductionStart = -1, this.lastBigReductionSize = 0, this.bigReductionCount = 0, this.stream = new U(e, i), this.tokens = new J(t, this.stream), this.topTerm = t.top[1];
824
+ let { from: h } = i[0];
825
+ this.stacks = [v.start(this, t.top[0], h)], this.fragments = s.length && this.stream.end - h > t.bufferLength * 4 ? new q(s, t.nodeSet) : null;
826
+ }
827
+ get parsedPos() {
828
+ return this.minStackPos;
829
+ }
830
+ // Move the parser forward. This will process all parse stacks at
831
+ // `this.pos` and try to advance them to a further position. If no
832
+ // stack for such a position is found, it'll start error-recovery.
833
+ //
834
+ // When the parse is finished, this will return a syntax tree. When
835
+ // not, it returns `null`.
836
+ advance() {
837
+ let t = this.stacks, e = this.minStackPos, s = this.stacks = [], i, h;
838
+ if (this.bigReductionCount > 300 && t.length == 1) {
839
+ let [r] = t;
840
+ for (; r.forceReduce() && r.stack.length && r.stack[r.stack.length - 2] >= this.lastBigReductionStart; )
841
+ ;
842
+ this.bigReductionCount = this.lastBigReductionSize = 0;
843
+ }
844
+ for (let r = 0; r < t.length; r++) {
845
+ let n = t[r];
846
+ for (; ; ) {
847
+ if (this.tokens.mainToken = null, n.pos > e)
848
+ s.push(n);
849
+ else {
850
+ if (this.advanceStack(n, s, t))
851
+ continue;
852
+ {
853
+ i || (i = [], h = []), i.push(n);
854
+ let o = this.tokens.getMainToken(n);
855
+ h.push(o.value, o.end);
856
+ }
857
+ }
858
+ break;
859
+ }
860
+ }
861
+ if (!s.length) {
862
+ let r = i && V(i);
863
+ if (r)
864
+ return g && console.log("Finish with " + this.stackID(r)), this.stackToTree(r);
865
+ if (this.parser.strict)
866
+ throw g && i && console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none")), new SyntaxError("No parse at " + e);
867
+ this.recovering || (this.recovering = 5);
868
+ }
869
+ if (this.recovering && i) {
870
+ let r = this.stoppedAt != null && i[0].pos > this.stoppedAt ? i[0] : this.runRecovery(i, h, s);
871
+ if (r)
872
+ return g && console.log("Force-finish " + this.stackID(r)), this.stackToTree(r.forceAll());
873
+ }
874
+ if (this.recovering) {
875
+ let r = this.recovering == 1 ? 1 : this.recovering * 3;
876
+ if (s.length > r)
877
+ for (s.sort((n, o) => o.score - n.score); s.length > r; )
878
+ s.pop();
879
+ s.some((n) => n.reducePos > e) && this.recovering--;
880
+ } else if (s.length > 1) {
881
+ t: for (let r = 0; r < s.length - 1; r++) {
882
+ let n = s[r];
883
+ for (let o = r + 1; o < s.length; o++) {
884
+ let a = s[o];
885
+ if (n.sameState(a) || n.buffer.length > 500 && a.buffer.length > 500)
886
+ if ((n.score - a.score || n.buffer.length - a.buffer.length) > 0)
887
+ s.splice(o--, 1);
888
+ else {
889
+ s.splice(r--, 1);
890
+ continue t;
891
+ }
892
+ }
893
+ }
894
+ s.length > 12 && (s.sort((r, n) => n.score - r.score), s.splice(
895
+ 12,
896
+ s.length - 12
897
+ /* Rec.MaxStackCount */
898
+ ));
899
+ }
900
+ this.minStackPos = s[0].pos;
901
+ for (let r = 1; r < s.length; r++)
902
+ s[r].pos < this.minStackPos && (this.minStackPos = s[r].pos);
903
+ return null;
904
+ }
905
+ stopAt(t) {
906
+ if (this.stoppedAt != null && this.stoppedAt < t)
907
+ throw new RangeError("Can't move stoppedAt forward");
908
+ this.stoppedAt = t;
909
+ }
910
+ // Returns an updated version of the given stack, or null if the
911
+ // stack can't advance normally. When `split` and `stacks` are
912
+ // given, stacks split off by ambiguous operations will be pushed to
913
+ // `split`, or added to `stacks` if they move `pos` forward.
914
+ advanceStack(t, e, s) {
915
+ let i = t.pos, { parser: h } = this, r = g ? this.stackID(t) + " -> " : "";
916
+ if (this.stoppedAt != null && i > this.stoppedAt)
917
+ return t.forceReduce() ? t : null;
918
+ if (this.fragments) {
919
+ let a = t.curContext && t.curContext.tracker.strict, u = a ? t.curContext.hash : 0;
920
+ for (let f = this.fragments.nodeAt(i); f; ) {
921
+ let p = this.parser.nodeSet.types[f.type.id] == f.type ? h.getGoto(t.state, f.type.id) : -1;
922
+ if (p > -1 && f.length && (!a || (f.prop(y.contextHash) || 0) == u))
923
+ return t.useNode(f, p), g && console.log(r + this.stackID(t) + ` (via reuse of ${h.getName(f.type.id)})`), !0;
924
+ if (!(f instanceof S) || f.children.length == 0 || f.positions[0] > 0)
925
+ break;
926
+ let c = f.children[0];
927
+ if (c instanceof S && f.positions[0] == 0)
928
+ f = c;
929
+ else
930
+ break;
931
+ }
932
+ }
933
+ let n = h.stateSlot(
934
+ t.state,
935
+ 4
936
+ /* ParseState.DefaultReduce */
937
+ );
938
+ if (n > 0)
939
+ return t.reduce(n), g && console.log(r + this.stackID(t) + ` (via always-reduce ${h.getName(
940
+ n & 65535
941
+ /* Action.ValueMask */
942
+ )})`), !0;
943
+ if (t.stack.length >= 8400)
944
+ for (; t.stack.length > 6e3 && t.forceReduce(); )
945
+ ;
946
+ let o = this.tokens.getActions(t);
947
+ for (let a = 0; a < o.length; ) {
948
+ let u = o[a++], f = o[a++], p = o[a++], c = a == o.length || !s, d = c ? t : t.split(), b = this.tokens.mainToken;
949
+ if (d.apply(u, f, b ? b.start : d.pos, p), g && console.log(r + this.stackID(d) + ` (via ${(u & 65536) == 0 ? "shift" : `reduce of ${h.getName(
950
+ u & 65535
951
+ /* Action.ValueMask */
952
+ )}`} for ${h.getName(f)} @ ${i}${d == t ? "" : ", split"})`), c)
953
+ return !0;
954
+ d.pos > i ? e.push(d) : s.push(d);
955
+ }
956
+ return !1;
957
+ }
958
+ // Advance a given stack forward as far as it will go. Returns the
959
+ // (possibly updated) stack if it got stuck, or null if it moved
960
+ // forward and was given to `pushStackDedup`.
961
+ advanceFully(t, e) {
962
+ let s = t.pos;
963
+ for (; ; ) {
964
+ if (!this.advanceStack(t, null, null))
965
+ return !1;
966
+ if (t.pos > s)
967
+ return D(t, e), !0;
968
+ }
969
+ }
970
+ runRecovery(t, e, s) {
971
+ let i = null, h = !1;
972
+ for (let r = 0; r < t.length; r++) {
973
+ let n = t[r], o = e[r << 1], a = e[(r << 1) + 1], u = g ? this.stackID(n) + " -> " : "";
974
+ if (n.deadEnd && (h || (h = !0, n.restart(), g && console.log(u + this.stackID(n) + " (restarted)"), this.advanceFully(n, s))))
975
+ continue;
976
+ let f = n.split(), p = u;
977
+ for (let c = 0; c < 10 && f.forceReduce() && (g && console.log(p + this.stackID(f) + " (via force-reduce)"), !this.advanceFully(f, s)); c++)
978
+ g && (p = this.stackID(f) + " -> ");
979
+ for (let c of n.recoverByInsert(o))
980
+ g && console.log(u + this.stackID(c) + " (via recover-insert)"), this.advanceFully(c, s);
981
+ this.stream.end > n.pos ? (a == n.pos && (a++, o = 0), n.recoverByDelete(o, a), g && console.log(u + this.stackID(n) + ` (via recover-delete ${this.parser.getName(o)})`), D(n, s)) : (!i || i.score < n.score) && (i = n);
982
+ }
983
+ return i;
984
+ }
985
+ // Convert the stack's buffer to a syntax tree.
986
+ stackToTree(t) {
987
+ return t.close(), S.build({
988
+ buffer: A.create(t),
989
+ nodeSet: this.parser.nodeSet,
990
+ topID: this.topTerm,
991
+ maxBufferLength: this.parser.bufferLength,
992
+ reused: this.reused,
993
+ start: this.ranges[0].from,
994
+ length: t.pos - this.ranges[0].from,
995
+ minRepeatType: this.parser.minRepeatTerm
996
+ });
997
+ }
998
+ stackID(t) {
999
+ let e = (T || (T = /* @__PURE__ */ new WeakMap())).get(t);
1000
+ return e || T.set(t, e = String.fromCodePoint(this.nextStackID++)), e + t;
1001
+ }
1002
+ }
1003
+ function D(l, t) {
1004
+ for (let e = 0; e < t.length; e++) {
1005
+ let s = t[e];
1006
+ if (s.pos == l.pos && s.sameState(l)) {
1007
+ t[e].score < l.score && (t[e] = l);
1008
+ return;
1009
+ }
1010
+ }
1011
+ t.push(l);
1012
+ }
1013
+ class Q {
1014
+ constructor(t, e, s) {
1015
+ this.source = t, this.flags = e, this.disabled = s;
1016
+ }
1017
+ allows(t) {
1018
+ return !this.disabled || this.disabled[t] == 0;
1019
+ }
1020
+ }
1021
+ const C = (l) => l;
1022
+ class Z {
1023
+ /**
1024
+ Define a context tracker.
1025
+ */
1026
+ constructor(t) {
1027
+ this.start = t.start, this.shift = t.shift || C, this.reduce = t.reduce || C, this.reuse = t.reuse || C, this.hash = t.hash || (() => 0), this.strict = t.strict !== !1;
1028
+ }
1029
+ }
1030
+ class w extends L {
1031
+ /**
1032
+ @internal
1033
+ */
1034
+ constructor(t) {
1035
+ if (super(), this.wrappers = [], t.version != 14)
1036
+ throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);
1037
+ let e = t.nodeNames.split(" ");
1038
+ this.minRepeatTerm = e.length;
1039
+ for (let n = 0; n < t.repeatNodeCount; n++)
1040
+ e.push("");
1041
+ let s = Object.keys(t.topRules).map((n) => t.topRules[n][1]), i = [];
1042
+ for (let n = 0; n < e.length; n++)
1043
+ i.push([]);
1044
+ function h(n, o, a) {
1045
+ i[n].push([o, o.deserialize(String(a))]);
1046
+ }
1047
+ if (t.nodeProps)
1048
+ for (let n of t.nodeProps) {
1049
+ let o = n[0];
1050
+ typeof o == "string" && (o = y[o]);
1051
+ for (let a = 1; a < n.length; ) {
1052
+ let u = n[a++];
1053
+ if (u >= 0)
1054
+ h(u, o, n[a++]);
1055
+ else {
1056
+ let f = n[a + -u];
1057
+ for (let p = -u; p > 0; p--)
1058
+ h(n[a++], o, f);
1059
+ a++;
1060
+ }
1061
+ }
1062
+ }
1063
+ this.nodeSet = new M(e.map((n, o) => $.define({
1064
+ name: o >= this.minRepeatTerm ? void 0 : n,
1065
+ id: o,
1066
+ props: i[o],
1067
+ top: s.indexOf(o) > -1,
1068
+ error: o == 0,
1069
+ skipped: t.skippedNodes && t.skippedNodes.indexOf(o) > -1
1070
+ }))), t.propSources && (this.nodeSet = this.nodeSet.extend(...t.propSources)), this.strict = !1, this.bufferLength = E;
1071
+ let r = x(t.tokenData);
1072
+ this.context = t.context, this.specializerSpecs = t.specialized || [], this.specialized = new Uint16Array(this.specializerSpecs.length);
1073
+ for (let n = 0; n < this.specializerSpecs.length; n++)
1074
+ this.specialized[n] = this.specializerSpecs[n].term;
1075
+ this.specializers = this.specializerSpecs.map(B), this.states = x(t.states, Uint32Array), this.data = x(t.stateData), this.goto = x(t.goto), this.maxTerm = t.maxTerm, this.tokenizers = t.tokenizers.map((n) => typeof n == "number" ? new m(r, n) : n), this.topRules = t.topRules, this.dialects = t.dialects || {}, this.dynamicPrecedences = t.dynamicPrecedences || null, this.tokenPrecTable = t.tokenPrec, this.termNames = t.termNames || null, this.maxNode = this.nodeSet.types.length - 1, this.dialect = this.parseDialect(), this.top = this.topRules[Object.keys(this.topRules)[0]];
1076
+ }
1077
+ createParse(t, e, s) {
1078
+ let i = new K(this, t, e, s);
1079
+ for (let h of this.wrappers)
1080
+ i = h(i, t, e, s);
1081
+ return i;
1082
+ }
1083
+ /**
1084
+ Get a goto table entry @internal
1085
+ */
1086
+ getGoto(t, e, s = !1) {
1087
+ let i = this.goto;
1088
+ if (e >= i[0])
1089
+ return -1;
1090
+ for (let h = i[e + 1]; ; ) {
1091
+ let r = i[h++], n = r & 1, o = i[h++];
1092
+ if (n && s)
1093
+ return o;
1094
+ for (let a = h + (r >> 1); h < a; h++)
1095
+ if (i[h] == t)
1096
+ return o;
1097
+ if (n)
1098
+ return -1;
1099
+ }
1100
+ }
1101
+ /**
1102
+ Check if this state has an action for a given terminal @internal
1103
+ */
1104
+ hasAction(t, e) {
1105
+ let s = this.data;
1106
+ for (let i = 0; i < 2; i++)
1107
+ for (let h = this.stateSlot(
1108
+ t,
1109
+ i ? 2 : 1
1110
+ /* ParseState.Actions */
1111
+ ), r; ; h += 3) {
1112
+ if ((r = s[h]) == 65535)
1113
+ if (s[h + 1] == 1)
1114
+ r = s[h = k(s, h + 2)];
1115
+ else {
1116
+ if (s[h + 1] == 2)
1117
+ return k(s, h + 2);
1118
+ break;
1119
+ }
1120
+ if (r == e || r == 0)
1121
+ return k(s, h + 1);
1122
+ }
1123
+ return 0;
1124
+ }
1125
+ /**
1126
+ @internal
1127
+ */
1128
+ stateSlot(t, e) {
1129
+ return this.states[t * 6 + e];
1130
+ }
1131
+ /**
1132
+ @internal
1133
+ */
1134
+ stateFlag(t, e) {
1135
+ return (this.stateSlot(
1136
+ t,
1137
+ 0
1138
+ /* ParseState.Flags */
1139
+ ) & e) > 0;
1140
+ }
1141
+ /**
1142
+ @internal
1143
+ */
1144
+ validAction(t, e) {
1145
+ return !!this.allActions(t, (s) => s == e ? !0 : null);
1146
+ }
1147
+ /**
1148
+ @internal
1149
+ */
1150
+ allActions(t, e) {
1151
+ let s = this.stateSlot(
1152
+ t,
1153
+ 4
1154
+ /* ParseState.DefaultReduce */
1155
+ ), i = s ? e(s) : void 0;
1156
+ for (let h = this.stateSlot(
1157
+ t,
1158
+ 1
1159
+ /* ParseState.Actions */
1160
+ ); i == null; h += 3) {
1161
+ if (this.data[h] == 65535)
1162
+ if (this.data[h + 1] == 1)
1163
+ h = k(this.data, h + 2);
1164
+ else
1165
+ break;
1166
+ i = e(k(this.data, h + 1));
1167
+ }
1168
+ return i;
1169
+ }
1170
+ /**
1171
+ Get the states that can follow this one through shift actions or
1172
+ goto jumps. @internal
1173
+ */
1174
+ nextStates(t) {
1175
+ let e = [];
1176
+ for (let s = this.stateSlot(
1177
+ t,
1178
+ 1
1179
+ /* ParseState.Actions */
1180
+ ); ; s += 3) {
1181
+ if (this.data[s] == 65535)
1182
+ if (this.data[s + 1] == 1)
1183
+ s = k(this.data, s + 2);
1184
+ else
1185
+ break;
1186
+ if ((this.data[s + 2] & 1) == 0) {
1187
+ let i = this.data[s + 1];
1188
+ e.some((h, r) => r & 1 && h == i) || e.push(this.data[s], i);
1189
+ }
1190
+ }
1191
+ return e;
1192
+ }
1193
+ /**
1194
+ Configure the parser. Returns a new parser instance that has the
1195
+ given settings modified. Settings not provided in `config` are
1196
+ kept from the original parser.
1197
+ */
1198
+ configure(t) {
1199
+ let e = Object.assign(Object.create(w.prototype), this);
1200
+ if (t.props && (e.nodeSet = this.nodeSet.extend(...t.props)), t.top) {
1201
+ let s = this.topRules[t.top];
1202
+ if (!s)
1203
+ throw new RangeError(`Invalid top rule name ${t.top}`);
1204
+ e.top = s;
1205
+ }
1206
+ return t.tokenizers && (e.tokenizers = this.tokenizers.map((s) => {
1207
+ let i = t.tokenizers.find((h) => h.from == s);
1208
+ return i ? i.to : s;
1209
+ })), t.specializers && (e.specializers = this.specializers.slice(), e.specializerSpecs = this.specializerSpecs.map((s, i) => {
1210
+ let h = t.specializers.find((n) => n.from == s.external);
1211
+ if (!h)
1212
+ return s;
1213
+ let r = Object.assign(Object.assign({}, s), { external: h.to });
1214
+ return e.specializers[i] = B(r), r;
1215
+ })), t.contextTracker && (e.context = t.contextTracker), t.dialect && (e.dialect = this.parseDialect(t.dialect)), t.strict != null && (e.strict = t.strict), t.wrap && (e.wrappers = e.wrappers.concat(t.wrap)), t.bufferLength != null && (e.bufferLength = t.bufferLength), e;
1216
+ }
1217
+ /**
1218
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1219
+ are registered for this parser.
1220
+ */
1221
+ hasWrappers() {
1222
+ return this.wrappers.length > 0;
1223
+ }
1224
+ /**
1225
+ Returns the name associated with a given term. This will only
1226
+ work for all terms when the parser was generated with the
1227
+ `--names` option. By default, only the names of tagged terms are
1228
+ stored.
1229
+ */
1230
+ getName(t) {
1231
+ return this.termNames ? this.termNames[t] : String(t <= this.maxNode && this.nodeSet.types[t].name || t);
1232
+ }
1233
+ /**
1234
+ The eof term id is always allocated directly after the node
1235
+ types. @internal
1236
+ */
1237
+ get eofTerm() {
1238
+ return this.maxNode + 1;
1239
+ }
1240
+ /**
1241
+ The type of top node produced by the parser.
1242
+ */
1243
+ get topNode() {
1244
+ return this.nodeSet.types[this.top[1]];
1245
+ }
1246
+ /**
1247
+ @internal
1248
+ */
1249
+ dynamicPrecedence(t) {
1250
+ let e = this.dynamicPrecedences;
1251
+ return e == null ? 0 : e[t] || 0;
1252
+ }
1253
+ /**
1254
+ @internal
1255
+ */
1256
+ parseDialect(t) {
1257
+ let e = Object.keys(this.dialects), s = e.map(() => !1);
1258
+ if (t)
1259
+ for (let h of t.split(" ")) {
1260
+ let r = e.indexOf(h);
1261
+ r >= 0 && (s[r] = !0);
1262
+ }
1263
+ let i = null;
1264
+ for (let h = 0; h < e.length; h++)
1265
+ if (!s[h])
1266
+ for (let r = this.dialects[e[h]], n; (n = this.data[r++]) != 65535; )
1267
+ (i || (i = new Uint8Array(this.maxTerm + 1)))[n] = 1;
1268
+ return new Q(t, s, i);
1269
+ }
1270
+ /**
1271
+ Used by the output of the parser generator. Not available to
1272
+ user code. @hide
1273
+ */
1274
+ static deserialize(t) {
1275
+ return new w(t);
1276
+ }
1277
+ }
1278
+ function k(l, t) {
1279
+ return l[t] | l[t + 1] << 16;
1280
+ }
1281
+ function V(l) {
1282
+ let t = null;
1283
+ for (let e of l) {
1284
+ let s = e.p.stoppedAt;
1285
+ (e.pos == e.p.stream.end || s != null && e.pos > s) && e.p.parser.stateFlag(
1286
+ e.state,
1287
+ 2
1288
+ /* StateFlag.Accepting */
1289
+ ) && (!t || t.score < e.score) && (t = e);
1290
+ }
1291
+ return t;
1292
+ }
1293
+ function B(l) {
1294
+ if (l.external) {
1295
+ let t = l.extend ? 1 : 0;
1296
+ return (e, s) => l.external(e, s) << 1 | t;
1297
+ }
1298
+ return l.get;
1299
+ }
1300
+ export {
1301
+ Z as C,
1302
+ Y as E,
1303
+ w as L,
1304
+ H as a
1305
+ };