vuefinder 4.3.0 → 4.4.0

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