@hpcc-js/observablehq-compiler 3.4.0 → 3.5.1

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.
Files changed (60) hide show
  1. package/dist/dot-DK4iDc2-.js +40 -0
  2. package/dist/dot-DK4iDc2-.js.map +1 -0
  3. package/dist/duckdb-DkM9_nXT.js +298 -0
  4. package/dist/duckdb-DkM9_nXT.js.map +1 -0
  5. package/dist/highlight-Bv8PkwN-.js +2402 -0
  6. package/dist/highlight-Bv8PkwN-.js.map +1 -0
  7. package/dist/index-B7vRtYlU.js +1807 -0
  8. package/dist/index-B7vRtYlU.js.map +1 -0
  9. package/dist/index-COHaJzee.js +260 -0
  10. package/dist/index-COHaJzee.js.map +1 -0
  11. package/dist/index-CP3HrqN0.js +1815 -0
  12. package/dist/index-CP3HrqN0.js.map +1 -0
  13. package/dist/index-D3TL70UM.js +163 -0
  14. package/dist/index-D3TL70UM.js.map +1 -0
  15. package/dist/index-DNwLE6Kk.js +198 -0
  16. package/dist/index-DNwLE6Kk.js.map +1 -0
  17. package/dist/index.js +4381 -4944
  18. package/dist/index.js.map +1 -1
  19. package/dist/inputs-CsCXZHQ8.js +3 -0
  20. package/dist/inputs-CsCXZHQ8.js.map +1 -0
  21. package/dist/leaflet-CkvVhxBL.js +9 -0
  22. package/dist/leaflet-CkvVhxBL.js.map +1 -0
  23. package/dist/mapboxgl-C0i2HzjJ.js +9 -0
  24. package/dist/mapboxgl-C0i2HzjJ.js.map +1 -0
  25. package/dist/md-Bxvu6Hld.js +7603 -0
  26. package/dist/md-Bxvu6Hld.js.map +1 -0
  27. package/dist/mermaid-CFg6sgdO.js +17 -0
  28. package/dist/mermaid-CFg6sgdO.js.map +1 -0
  29. package/dist/node/index.cjs +10 -6
  30. package/dist/node/index.cjs.map +4 -4
  31. package/dist/node/index.js +8 -4
  32. package/dist/node/index.js.map +4 -4
  33. package/dist/runtime.js +2501 -0
  34. package/dist/runtime.js.map +1 -0
  35. package/dist/tex-ayRXOMLZ.js +24 -0
  36. package/dist/tex-ayRXOMLZ.js.map +1 -0
  37. package/dist/vega-lite-CESXoehe.js +8 -0
  38. package/dist/vega-lite-CESXoehe.js.map +1 -0
  39. package/package.json +12 -10
  40. package/src/__package__.ts +2 -2
  41. package/src/compiler.ts +2 -16
  42. package/src/cst.ts +1 -2
  43. package/src/index.ts +2 -3
  44. package/src/kit/compiler.ts +41 -0
  45. package/src/kit/index.ts +3 -0
  46. package/src/kit/runtime.ts +57 -0
  47. package/src/kit/util.ts +157 -0
  48. package/src/util.ts +1 -134
  49. package/types/compiler.d.ts +1 -3
  50. package/types/index.d.ts +2 -2
  51. package/types/kit/compiler.d.ts +6 -0
  52. package/types/kit/index.d.ts +3 -0
  53. package/types/kit/runtime.d.ts +13 -0
  54. package/types/kit/util.d.ts +52 -0
  55. package/types/util.d.ts +1 -49
  56. package/dist/index.umd.cjs +0 -5
  57. package/dist/index.umd.cjs.map +0 -1
  58. package/dist/node/index.css +0 -2
  59. package/dist/node/index.css.map +0 -7
  60. package/src/index.css +0 -460
@@ -0,0 +1,1807 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { P as Parser, N as NodeSet, a as NodeType, D as DefaultBufferLength, b as NodeProp, T as Tree, I as IterMode } from "./highlight-Bv8PkwN-.js";
4
+ const _Stack = class _Stack {
5
+ /**
6
+ @internal
7
+ */
8
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
9
+ this.p = p;
10
+ this.stack = stack;
11
+ this.state = state;
12
+ this.reducePos = reducePos;
13
+ this.pos = pos;
14
+ this.score = score;
15
+ this.buffer = buffer;
16
+ this.bufferBase = bufferBase;
17
+ this.curContext = curContext;
18
+ this.lookAhead = lookAhead;
19
+ this.parent = parent;
20
+ }
21
+ /**
22
+ @internal
23
+ */
24
+ toString() {
25
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
26
+ }
27
+ // Start an empty stack
28
+ /**
29
+ @internal
30
+ */
31
+ static start(p, state, pos = 0) {
32
+ let cx = p.parser.context;
33
+ return new _Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
34
+ }
35
+ /**
36
+ The stack's current [context](#lr.ContextTracker) value, if
37
+ any. Its type will depend on the context tracker's type
38
+ parameter, or it will be `null` if there is no context
39
+ tracker.
40
+ */
41
+ get context() {
42
+ return this.curContext ? this.curContext.context : null;
43
+ }
44
+ // Push a state onto the stack, tracking its start position as well
45
+ // as the buffer base at that point.
46
+ /**
47
+ @internal
48
+ */
49
+ pushState(state, start) {
50
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
51
+ this.state = state;
52
+ }
53
+ // Apply a reduce action
54
+ /**
55
+ @internal
56
+ */
57
+ reduce(action) {
58
+ var _a;
59
+ let depth = action >> 19, type = action & 65535;
60
+ let { parser } = this.p;
61
+ let lookaheadRecord = this.reducePos < this.pos - 25;
62
+ if (lookaheadRecord)
63
+ this.setLookAhead(this.pos);
64
+ let dPrec = parser.dynamicPrecedence(type);
65
+ if (dPrec)
66
+ this.score += dPrec;
67
+ if (depth == 0) {
68
+ this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
69
+ if (type < parser.minRepeatTerm)
70
+ this.storeNode(type, this.reducePos, this.reducePos, lookaheadRecord ? 8 : 4, true);
71
+ this.reduceContext(type, this.reducePos);
72
+ return;
73
+ }
74
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
75
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
76
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
77
+ if (start == this.p.lastBigReductionStart) {
78
+ this.p.bigReductionCount++;
79
+ this.p.lastBigReductionSize = size;
80
+ } else if (this.p.lastBigReductionSize < size) {
81
+ this.p.bigReductionCount = 1;
82
+ this.p.lastBigReductionStart = start;
83
+ this.p.lastBigReductionSize = size;
84
+ }
85
+ }
86
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
87
+ if (type < parser.minRepeatTerm || action & 131072) {
88
+ let pos = parser.stateFlag(
89
+ this.state,
90
+ 1
91
+ /* StateFlag.Skipped */
92
+ ) ? this.pos : this.reducePos;
93
+ this.storeNode(type, start, pos, count + 4, true);
94
+ }
95
+ if (action & 262144) {
96
+ this.state = this.stack[base];
97
+ } else {
98
+ let baseStateID = this.stack[base - 3];
99
+ this.state = parser.getGoto(baseStateID, type, true);
100
+ }
101
+ while (this.stack.length > base)
102
+ this.stack.pop();
103
+ this.reduceContext(type, start);
104
+ }
105
+ // Shift a value into the buffer
106
+ /**
107
+ @internal
108
+ */
109
+ storeNode(term, start, end, size = 4, mustSink = false) {
110
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
111
+ let cur = this, top = this.buffer.length;
112
+ if (top == 0 && cur.parent) {
113
+ top = cur.bufferBase - cur.parent.bufferBase;
114
+ cur = cur.parent;
115
+ }
116
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
117
+ if (start == end)
118
+ return;
119
+ if (cur.buffer[top - 2] >= start) {
120
+ cur.buffer[top - 2] = end;
121
+ return;
122
+ }
123
+ }
124
+ }
125
+ if (!mustSink || this.pos == end) {
126
+ this.buffer.push(term, start, end, size);
127
+ } else {
128
+ let index = this.buffer.length;
129
+ if (index > 0 && this.buffer[index - 4] != 0) {
130
+ let mustMove = false;
131
+ for (let scan = index; scan > 0 && this.buffer[scan - 2] > end; scan -= 4) {
132
+ if (this.buffer[scan - 1] >= 0) {
133
+ mustMove = true;
134
+ break;
135
+ }
136
+ }
137
+ if (mustMove)
138
+ while (index > 0 && this.buffer[index - 2] > end) {
139
+ this.buffer[index] = this.buffer[index - 4];
140
+ this.buffer[index + 1] = this.buffer[index - 3];
141
+ this.buffer[index + 2] = this.buffer[index - 2];
142
+ this.buffer[index + 3] = this.buffer[index - 1];
143
+ index -= 4;
144
+ if (size > 4)
145
+ size -= 4;
146
+ }
147
+ }
148
+ this.buffer[index] = term;
149
+ this.buffer[index + 1] = start;
150
+ this.buffer[index + 2] = end;
151
+ this.buffer[index + 3] = size;
152
+ }
153
+ }
154
+ // Apply a shift action
155
+ /**
156
+ @internal
157
+ */
158
+ shift(action, type, start, end) {
159
+ if (action & 131072) {
160
+ this.pushState(action & 65535, this.pos);
161
+ } else if ((action & 262144) == 0) {
162
+ let nextState = action, { parser } = this.p;
163
+ if (end > this.pos || type <= parser.maxNode) {
164
+ this.pos = end;
165
+ if (!parser.stateFlag(
166
+ nextState,
167
+ 1
168
+ /* StateFlag.Skipped */
169
+ ))
170
+ this.reducePos = end;
171
+ }
172
+ this.pushState(nextState, start);
173
+ this.shiftContext(type, start);
174
+ if (type <= parser.maxNode)
175
+ this.buffer.push(type, start, end, 4);
176
+ } else {
177
+ this.pos = end;
178
+ this.shiftContext(type, start);
179
+ if (type <= this.p.parser.maxNode)
180
+ this.buffer.push(type, start, end, 4);
181
+ }
182
+ }
183
+ // Apply an action
184
+ /**
185
+ @internal
186
+ */
187
+ apply(action, next, nextStart, nextEnd) {
188
+ if (action & 65536)
189
+ this.reduce(action);
190
+ else
191
+ this.shift(action, next, nextStart, nextEnd);
192
+ }
193
+ // Add a prebuilt (reused) node into the buffer.
194
+ /**
195
+ @internal
196
+ */
197
+ useNode(value, next) {
198
+ let index = this.p.reused.length - 1;
199
+ if (index < 0 || this.p.reused[index] != value) {
200
+ this.p.reused.push(value);
201
+ index++;
202
+ }
203
+ let start = this.pos;
204
+ this.reducePos = this.pos = start + value.length;
205
+ this.pushState(next, start);
206
+ this.buffer.push(
207
+ index,
208
+ start,
209
+ this.reducePos,
210
+ -1
211
+ /* size == -1 means this is a reused value */
212
+ );
213
+ if (this.curContext)
214
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
215
+ }
216
+ // Split the stack. Due to the buffer sharing and the fact
217
+ // that `this.stack` tends to stay quite shallow, this isn't very
218
+ // expensive.
219
+ /**
220
+ @internal
221
+ */
222
+ split() {
223
+ let parent = this;
224
+ let off = parent.buffer.length;
225
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
226
+ off -= 4;
227
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
228
+ while (parent && base == parent.bufferBase)
229
+ parent = parent.parent;
230
+ return new _Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
231
+ }
232
+ // Try to recover from an error by 'deleting' (ignoring) one token.
233
+ /**
234
+ @internal
235
+ */
236
+ recoverByDelete(next, nextEnd) {
237
+ let isNode = next <= this.p.parser.maxNode;
238
+ if (isNode)
239
+ this.storeNode(next, this.pos, nextEnd, 4);
240
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
241
+ this.pos = this.reducePos = nextEnd;
242
+ this.score -= 190;
243
+ }
244
+ /**
245
+ Check if the given term would be able to be shifted (optionally
246
+ after some reductions) on this stack. This can be useful for
247
+ external tokenizers that want to make sure they only provide a
248
+ given token when it applies.
249
+ */
250
+ canShift(term) {
251
+ for (let sim = new SimulatedStack(this); ; ) {
252
+ let action = this.p.parser.stateSlot(
253
+ sim.state,
254
+ 4
255
+ /* ParseState.DefaultReduce */
256
+ ) || this.p.parser.hasAction(sim.state, term);
257
+ if (action == 0)
258
+ return false;
259
+ if ((action & 65536) == 0)
260
+ return true;
261
+ sim.reduce(action);
262
+ }
263
+ }
264
+ // Apply up to Recover.MaxNext recovery actions that conceptually
265
+ // inserts some missing token or rule.
266
+ /**
267
+ @internal
268
+ */
269
+ recoverByInsert(next) {
270
+ if (this.stack.length >= 300)
271
+ return [];
272
+ let nextStates = this.p.parser.nextStates(this.state);
273
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
274
+ let best = [];
275
+ for (let i = 0, s; i < nextStates.length; i += 2) {
276
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
277
+ best.push(nextStates[i], s);
278
+ }
279
+ if (this.stack.length < 120)
280
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
281
+ let s = nextStates[i + 1];
282
+ if (!best.some((v, i2) => i2 & 1 && v == s))
283
+ best.push(nextStates[i], s);
284
+ }
285
+ nextStates = best;
286
+ }
287
+ let result = [];
288
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
289
+ let s = nextStates[i + 1];
290
+ if (s == this.state)
291
+ continue;
292
+ let stack = this.split();
293
+ stack.pushState(s, this.pos);
294
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
295
+ stack.shiftContext(nextStates[i], this.pos);
296
+ stack.reducePos = this.pos;
297
+ stack.score -= 200;
298
+ result.push(stack);
299
+ }
300
+ return result;
301
+ }
302
+ // Force a reduce, if possible. Return false if that can't
303
+ // be done.
304
+ /**
305
+ @internal
306
+ */
307
+ forceReduce() {
308
+ let { parser } = this.p;
309
+ let reduce = parser.stateSlot(
310
+ this.state,
311
+ 5
312
+ /* ParseState.ForcedReduce */
313
+ );
314
+ if ((reduce & 65536) == 0)
315
+ return false;
316
+ if (!parser.validAction(this.state, reduce)) {
317
+ let depth = reduce >> 19, term = reduce & 65535;
318
+ let target = this.stack.length - depth * 3;
319
+ if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) {
320
+ let backup = this.findForcedReduction();
321
+ if (backup == null)
322
+ return false;
323
+ reduce = backup;
324
+ }
325
+ this.storeNode(0, this.pos, this.pos, 4, true);
326
+ this.score -= 100;
327
+ }
328
+ this.reducePos = this.pos;
329
+ this.reduce(reduce);
330
+ return true;
331
+ }
332
+ /**
333
+ Try to scan through the automaton to find some kind of reduction
334
+ that can be applied. Used when the regular ForcedReduce field
335
+ isn't a valid action. @internal
336
+ */
337
+ findForcedReduction() {
338
+ let { parser } = this.p, seen = [];
339
+ let explore = /* @__PURE__ */ __name((state, depth) => {
340
+ if (seen.includes(state))
341
+ return;
342
+ seen.push(state);
343
+ return parser.allActions(state, (action) => {
344
+ if (action & (262144 | 131072)) ;
345
+ else if (action & 65536) {
346
+ let rDepth = (action >> 19) - depth;
347
+ if (rDepth > 1) {
348
+ let term = action & 65535, target = this.stack.length - rDepth * 3;
349
+ if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0)
350
+ return rDepth << 19 | 65536 | term;
351
+ }
352
+ } else {
353
+ let found = explore(action, depth + 1);
354
+ if (found != null)
355
+ return found;
356
+ }
357
+ });
358
+ }, "explore");
359
+ return explore(this.state, 0);
360
+ }
361
+ /**
362
+ @internal
363
+ */
364
+ forceAll() {
365
+ while (!this.p.parser.stateFlag(
366
+ this.state,
367
+ 2
368
+ /* StateFlag.Accepting */
369
+ )) {
370
+ if (!this.forceReduce()) {
371
+ this.storeNode(0, this.pos, this.pos, 4, true);
372
+ break;
373
+ }
374
+ }
375
+ return this;
376
+ }
377
+ /**
378
+ Check whether this state has no further actions (assumed to be a direct descendant of the
379
+ top state, since any other states must be able to continue
380
+ somehow). @internal
381
+ */
382
+ get deadEnd() {
383
+ if (this.stack.length != 3)
384
+ return false;
385
+ let { parser } = this.p;
386
+ return parser.data[parser.stateSlot(
387
+ this.state,
388
+ 1
389
+ /* ParseState.Actions */
390
+ )] == 65535 && !parser.stateSlot(
391
+ this.state,
392
+ 4
393
+ /* ParseState.DefaultReduce */
394
+ );
395
+ }
396
+ /**
397
+ Restart the stack (put it back in its start state). Only safe
398
+ when this.stack.length == 3 (state is directly below the top
399
+ state). @internal
400
+ */
401
+ restart() {
402
+ this.storeNode(0, this.pos, this.pos, 4, true);
403
+ this.state = this.stack[0];
404
+ this.stack.length = 0;
405
+ }
406
+ /**
407
+ @internal
408
+ */
409
+ sameState(other) {
410
+ if (this.state != other.state || this.stack.length != other.stack.length)
411
+ return false;
412
+ for (let i = 0; i < this.stack.length; i += 3)
413
+ if (this.stack[i] != other.stack[i])
414
+ return false;
415
+ return true;
416
+ }
417
+ /**
418
+ Get the parser used by this stack.
419
+ */
420
+ get parser() {
421
+ return this.p.parser;
422
+ }
423
+ /**
424
+ Test whether a given dialect (by numeric ID, as exported from
425
+ the terms file) is enabled.
426
+ */
427
+ dialectEnabled(dialectID) {
428
+ return this.p.parser.dialect.flags[dialectID];
429
+ }
430
+ shiftContext(term, start) {
431
+ if (this.curContext)
432
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
433
+ }
434
+ reduceContext(term, start) {
435
+ if (this.curContext)
436
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
437
+ }
438
+ /**
439
+ @internal
440
+ */
441
+ emitContext() {
442
+ let last = this.buffer.length - 1;
443
+ if (last < 0 || this.buffer[last] != -3)
444
+ this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
445
+ }
446
+ /**
447
+ @internal
448
+ */
449
+ emitLookAhead() {
450
+ let last = this.buffer.length - 1;
451
+ if (last < 0 || this.buffer[last] != -4)
452
+ this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
453
+ }
454
+ updateContext(context) {
455
+ if (context != this.curContext.context) {
456
+ let newCx = new StackContext(this.curContext.tracker, context);
457
+ if (newCx.hash != this.curContext.hash)
458
+ this.emitContext();
459
+ this.curContext = newCx;
460
+ }
461
+ }
462
+ /**
463
+ @internal
464
+ */
465
+ setLookAhead(lookAhead) {
466
+ if (lookAhead > this.lookAhead) {
467
+ this.emitLookAhead();
468
+ this.lookAhead = lookAhead;
469
+ }
470
+ }
471
+ /**
472
+ @internal
473
+ */
474
+ close() {
475
+ if (this.curContext && this.curContext.tracker.strict)
476
+ this.emitContext();
477
+ if (this.lookAhead > 0)
478
+ this.emitLookAhead();
479
+ }
480
+ };
481
+ __name(_Stack, "Stack");
482
+ let Stack = _Stack;
483
+ const _StackContext = class _StackContext {
484
+ constructor(tracker, context) {
485
+ this.tracker = tracker;
486
+ this.context = context;
487
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
488
+ }
489
+ };
490
+ __name(_StackContext, "StackContext");
491
+ let StackContext = _StackContext;
492
+ const _SimulatedStack = class _SimulatedStack {
493
+ constructor(start) {
494
+ this.start = start;
495
+ this.state = start.state;
496
+ this.stack = start.stack;
497
+ this.base = this.stack.length;
498
+ }
499
+ reduce(action) {
500
+ let term = action & 65535, depth = action >> 19;
501
+ if (depth == 0) {
502
+ if (this.stack == this.start.stack)
503
+ this.stack = this.stack.slice();
504
+ this.stack.push(this.state, 0, 0);
505
+ this.base += 3;
506
+ } else {
507
+ this.base -= (depth - 1) * 3;
508
+ }
509
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
510
+ this.state = goto;
511
+ }
512
+ };
513
+ __name(_SimulatedStack, "SimulatedStack");
514
+ let SimulatedStack = _SimulatedStack;
515
+ const _StackBufferCursor = class _StackBufferCursor {
516
+ constructor(stack, pos, index) {
517
+ this.stack = stack;
518
+ this.pos = pos;
519
+ this.index = index;
520
+ this.buffer = stack.buffer;
521
+ if (this.index == 0)
522
+ this.maybeNext();
523
+ }
524
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
525
+ return new _StackBufferCursor(stack, pos, pos - stack.bufferBase);
526
+ }
527
+ maybeNext() {
528
+ let next = this.stack.parent;
529
+ if (next != null) {
530
+ this.index = this.stack.bufferBase - next.bufferBase;
531
+ this.stack = next;
532
+ this.buffer = next.buffer;
533
+ }
534
+ }
535
+ get id() {
536
+ return this.buffer[this.index - 4];
537
+ }
538
+ get start() {
539
+ return this.buffer[this.index - 3];
540
+ }
541
+ get end() {
542
+ return this.buffer[this.index - 2];
543
+ }
544
+ get size() {
545
+ return this.buffer[this.index - 1];
546
+ }
547
+ next() {
548
+ this.index -= 4;
549
+ this.pos -= 4;
550
+ if (this.index == 0)
551
+ this.maybeNext();
552
+ }
553
+ fork() {
554
+ return new _StackBufferCursor(this.stack, this.pos, this.index);
555
+ }
556
+ };
557
+ __name(_StackBufferCursor, "StackBufferCursor");
558
+ let StackBufferCursor = _StackBufferCursor;
559
+ function decodeArray(input, Type = Uint16Array) {
560
+ if (typeof input != "string")
561
+ return input;
562
+ let array = null;
563
+ for (let pos = 0, out = 0; pos < input.length; ) {
564
+ let value = 0;
565
+ for (; ; ) {
566
+ let next = input.charCodeAt(pos++), stop = false;
567
+ if (next == 126) {
568
+ value = 65535;
569
+ break;
570
+ }
571
+ if (next >= 92)
572
+ next--;
573
+ if (next >= 34)
574
+ next--;
575
+ let digit = next - 32;
576
+ if (digit >= 46) {
577
+ digit -= 46;
578
+ stop = true;
579
+ }
580
+ value += digit;
581
+ if (stop)
582
+ break;
583
+ value *= 46;
584
+ }
585
+ if (array)
586
+ array[out++] = value;
587
+ else
588
+ array = new Type(value);
589
+ }
590
+ return array;
591
+ }
592
+ __name(decodeArray, "decodeArray");
593
+ const _CachedToken = class _CachedToken {
594
+ constructor() {
595
+ this.start = -1;
596
+ this.value = -1;
597
+ this.end = -1;
598
+ this.extended = -1;
599
+ this.lookAhead = 0;
600
+ this.mask = 0;
601
+ this.context = 0;
602
+ }
603
+ };
604
+ __name(_CachedToken, "CachedToken");
605
+ let CachedToken = _CachedToken;
606
+ const nullToken = new CachedToken();
607
+ const _InputStream = class _InputStream {
608
+ /**
609
+ @internal
610
+ */
611
+ constructor(input, ranges) {
612
+ this.input = input;
613
+ this.ranges = ranges;
614
+ this.chunk = "";
615
+ this.chunkOff = 0;
616
+ this.chunk2 = "";
617
+ this.chunk2Pos = 0;
618
+ this.next = -1;
619
+ this.token = nullToken;
620
+ this.rangeIndex = 0;
621
+ this.pos = this.chunkPos = ranges[0].from;
622
+ this.range = ranges[0];
623
+ this.end = ranges[ranges.length - 1].to;
624
+ this.readNext();
625
+ }
626
+ /**
627
+ @internal
628
+ */
629
+ resolveOffset(offset, assoc) {
630
+ let range = this.range, index = this.rangeIndex;
631
+ let pos = this.pos + offset;
632
+ while (pos < range.from) {
633
+ if (!index)
634
+ return null;
635
+ let next = this.ranges[--index];
636
+ pos -= range.from - next.to;
637
+ range = next;
638
+ }
639
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
640
+ if (index == this.ranges.length - 1)
641
+ return null;
642
+ let next = this.ranges[++index];
643
+ pos += next.from - range.to;
644
+ range = next;
645
+ }
646
+ return pos;
647
+ }
648
+ /**
649
+ @internal
650
+ */
651
+ clipPos(pos) {
652
+ if (pos >= this.range.from && pos < this.range.to)
653
+ return pos;
654
+ for (let range of this.ranges)
655
+ if (range.to > pos)
656
+ return Math.max(pos, range.from);
657
+ return this.end;
658
+ }
659
+ /**
660
+ Look at a code unit near the stream position. `.peek(0)` equals
661
+ `.next`, `.peek(-1)` gives you the previous character, and so
662
+ on.
663
+
664
+ Note that looking around during tokenizing creates dependencies
665
+ on potentially far-away content, which may reduce the
666
+ effectiveness incremental parsing—when looking forward—or even
667
+ cause invalid reparses when looking backward more than 25 code
668
+ units, since the library does not track lookbehind.
669
+ */
670
+ peek(offset) {
671
+ let idx = this.chunkOff + offset, pos, result;
672
+ if (idx >= 0 && idx < this.chunk.length) {
673
+ pos = this.pos + offset;
674
+ result = this.chunk.charCodeAt(idx);
675
+ } else {
676
+ let resolved = this.resolveOffset(offset, 1);
677
+ if (resolved == null)
678
+ return -1;
679
+ pos = resolved;
680
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
681
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
682
+ } else {
683
+ let i = this.rangeIndex, range = this.range;
684
+ while (range.to <= pos)
685
+ range = this.ranges[++i];
686
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
687
+ if (pos + this.chunk2.length > range.to)
688
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
689
+ result = this.chunk2.charCodeAt(0);
690
+ }
691
+ }
692
+ if (pos >= this.token.lookAhead)
693
+ this.token.lookAhead = pos + 1;
694
+ return result;
695
+ }
696
+ /**
697
+ Accept a token. By default, the end of the token is set to the
698
+ current stream position, but you can pass an offset (relative to
699
+ the stream position) to change that.
700
+ */
701
+ acceptToken(token, endOffset = 0) {
702
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
703
+ if (end == null || end < this.token.start)
704
+ throw new RangeError("Token end out of bounds");
705
+ this.token.value = token;
706
+ this.token.end = end;
707
+ }
708
+ /**
709
+ Accept a token ending at a specific given position.
710
+ */
711
+ acceptTokenTo(token, endPos) {
712
+ this.token.value = token;
713
+ this.token.end = endPos;
714
+ }
715
+ getChunk() {
716
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
717
+ let { chunk, chunkPos } = this;
718
+ this.chunk = this.chunk2;
719
+ this.chunkPos = this.chunk2Pos;
720
+ this.chunk2 = chunk;
721
+ this.chunk2Pos = chunkPos;
722
+ this.chunkOff = this.pos - this.chunkPos;
723
+ } else {
724
+ this.chunk2 = this.chunk;
725
+ this.chunk2Pos = this.chunkPos;
726
+ let nextChunk = this.input.chunk(this.pos);
727
+ let end = this.pos + nextChunk.length;
728
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
729
+ this.chunkPos = this.pos;
730
+ this.chunkOff = 0;
731
+ }
732
+ }
733
+ readNext() {
734
+ if (this.chunkOff >= this.chunk.length) {
735
+ this.getChunk();
736
+ if (this.chunkOff == this.chunk.length)
737
+ return this.next = -1;
738
+ }
739
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
740
+ }
741
+ /**
742
+ Move the stream forward N (defaults to 1) code units. Returns
743
+ the new value of [`next`](#lr.InputStream.next).
744
+ */
745
+ advance(n = 1) {
746
+ this.chunkOff += n;
747
+ while (this.pos + n >= this.range.to) {
748
+ if (this.rangeIndex == this.ranges.length - 1)
749
+ return this.setDone();
750
+ n -= this.range.to - this.pos;
751
+ this.range = this.ranges[++this.rangeIndex];
752
+ this.pos = this.range.from;
753
+ }
754
+ this.pos += n;
755
+ if (this.pos >= this.token.lookAhead)
756
+ this.token.lookAhead = this.pos + 1;
757
+ return this.readNext();
758
+ }
759
+ setDone() {
760
+ this.pos = this.chunkPos = this.end;
761
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
762
+ this.chunk = "";
763
+ return this.next = -1;
764
+ }
765
+ /**
766
+ @internal
767
+ */
768
+ reset(pos, token) {
769
+ if (token) {
770
+ this.token = token;
771
+ token.start = pos;
772
+ token.lookAhead = pos + 1;
773
+ token.value = token.extended = -1;
774
+ } else {
775
+ this.token = nullToken;
776
+ }
777
+ if (this.pos != pos) {
778
+ this.pos = pos;
779
+ if (pos == this.end) {
780
+ this.setDone();
781
+ return this;
782
+ }
783
+ while (pos < this.range.from)
784
+ this.range = this.ranges[--this.rangeIndex];
785
+ while (pos >= this.range.to)
786
+ this.range = this.ranges[++this.rangeIndex];
787
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
788
+ this.chunkOff = pos - this.chunkPos;
789
+ } else {
790
+ this.chunk = "";
791
+ this.chunkOff = 0;
792
+ }
793
+ this.readNext();
794
+ }
795
+ return this;
796
+ }
797
+ /**
798
+ @internal
799
+ */
800
+ read(from, to) {
801
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
802
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
803
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
804
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
805
+ if (from >= this.range.from && to <= this.range.to)
806
+ return this.input.read(from, to);
807
+ let result = "";
808
+ for (let r of this.ranges) {
809
+ if (r.from >= to)
810
+ break;
811
+ if (r.to > from)
812
+ result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
813
+ }
814
+ return result;
815
+ }
816
+ };
817
+ __name(_InputStream, "InputStream");
818
+ let InputStream = _InputStream;
819
+ const _TokenGroup = class _TokenGroup {
820
+ constructor(data, id2) {
821
+ this.data = data;
822
+ this.id = id2;
823
+ }
824
+ token(input, stack) {
825
+ let { parser } = stack.p;
826
+ readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable);
827
+ }
828
+ };
829
+ __name(_TokenGroup, "TokenGroup");
830
+ let TokenGroup = _TokenGroup;
831
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
832
+ const _LocalTokenGroup = class _LocalTokenGroup {
833
+ constructor(data, precTable, elseToken) {
834
+ this.precTable = precTable;
835
+ this.elseToken = elseToken;
836
+ this.data = typeof data == "string" ? decodeArray(data) : data;
837
+ }
838
+ token(input, stack) {
839
+ let start = input.pos, skipped = 0;
840
+ for (; ; ) {
841
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
842
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
843
+ if (input.token.value > -1)
844
+ break;
845
+ if (this.elseToken == null)
846
+ return;
847
+ if (!atEof)
848
+ skipped++;
849
+ if (nextPos == null)
850
+ break;
851
+ input.reset(nextPos, input.token);
852
+ }
853
+ if (skipped) {
854
+ input.reset(start, input.token);
855
+ input.acceptToken(this.elseToken, skipped);
856
+ }
857
+ }
858
+ };
859
+ __name(_LocalTokenGroup, "LocalTokenGroup");
860
+ let LocalTokenGroup = _LocalTokenGroup;
861
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
862
+ const _ExternalTokenizer = class _ExternalTokenizer {
863
+ /**
864
+ Create a tokenizer. The first argument is the function that,
865
+ given an input stream, scans for the types of tokens it
866
+ recognizes at the stream's position, and calls
867
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
868
+ one.
869
+ */
870
+ constructor(token, options = {}) {
871
+ this.token = token;
872
+ this.contextual = !!options.contextual;
873
+ this.fallback = !!options.fallback;
874
+ this.extend = !!options.extend;
875
+ }
876
+ };
877
+ __name(_ExternalTokenizer, "ExternalTokenizer");
878
+ let ExternalTokenizer = _ExternalTokenizer;
879
+ function readToken(data, input, stack, group, precTable, precOffset) {
880
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
881
+ scan: for (; ; ) {
882
+ if ((groupMask & data[state]) == 0)
883
+ break;
884
+ let accEnd = data[state + 1];
885
+ for (let i = state + 3; i < accEnd; i += 2)
886
+ if ((data[i + 1] & groupMask) > 0) {
887
+ let term = data[i];
888
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
889
+ input.acceptToken(term);
890
+ break;
891
+ }
892
+ }
893
+ let next = input.next, low = 0, high = data[state + 2];
894
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
895
+ state = data[accEnd + high * 3 - 1];
896
+ continue scan;
897
+ }
898
+ for (; low < high; ) {
899
+ let mid = low + high >> 1;
900
+ let index = accEnd + mid + (mid << 1);
901
+ let from = data[index], to = data[index + 1] || 65536;
902
+ if (next < from)
903
+ high = mid;
904
+ else if (next >= to)
905
+ low = mid + 1;
906
+ else {
907
+ state = data[index + 2];
908
+ input.advance();
909
+ continue scan;
910
+ }
911
+ }
912
+ break;
913
+ }
914
+ }
915
+ __name(readToken, "readToken");
916
+ function findOffset(data, start, term) {
917
+ for (let i = start, next; (next = data[i]) != 65535; i++)
918
+ if (next == term)
919
+ return i - start;
920
+ return -1;
921
+ }
922
+ __name(findOffset, "findOffset");
923
+ function overrides(token, prev, tableData, tableOffset) {
924
+ let iPrev = findOffset(tableData, tableOffset, prev);
925
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
926
+ }
927
+ __name(overrides, "overrides");
928
+ const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
929
+ let stackIDs = null;
930
+ function cutAt(tree, pos, side) {
931
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
932
+ cursor.moveTo(pos);
933
+ for (; ; ) {
934
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
935
+ for (; ; ) {
936
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
937
+ return side < 0 ? Math.max(0, Math.min(
938
+ cursor.to - 1,
939
+ pos - 25
940
+ /* Lookahead.Margin */
941
+ )) : Math.min(tree.length, Math.max(
942
+ cursor.from + 1,
943
+ pos + 25
944
+ /* Lookahead.Margin */
945
+ ));
946
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
947
+ break;
948
+ if (!cursor.parent())
949
+ return side < 0 ? 0 : tree.length;
950
+ }
951
+ }
952
+ }
953
+ __name(cutAt, "cutAt");
954
+ const _FragmentCursor = class _FragmentCursor {
955
+ constructor(fragments, nodeSet) {
956
+ this.fragments = fragments;
957
+ this.nodeSet = nodeSet;
958
+ this.i = 0;
959
+ this.fragment = null;
960
+ this.safeFrom = -1;
961
+ this.safeTo = -1;
962
+ this.trees = [];
963
+ this.start = [];
964
+ this.index = [];
965
+ this.nextFragment();
966
+ }
967
+ nextFragment() {
968
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
969
+ if (fr) {
970
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
971
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
972
+ while (this.trees.length) {
973
+ this.trees.pop();
974
+ this.start.pop();
975
+ this.index.pop();
976
+ }
977
+ this.trees.push(fr.tree);
978
+ this.start.push(-fr.offset);
979
+ this.index.push(0);
980
+ this.nextStart = this.safeFrom;
981
+ } else {
982
+ this.nextStart = 1e9;
983
+ }
984
+ }
985
+ // `pos` must be >= any previously given `pos` for this cursor
986
+ nodeAt(pos) {
987
+ if (pos < this.nextStart)
988
+ return null;
989
+ while (this.fragment && this.safeTo <= pos)
990
+ this.nextFragment();
991
+ if (!this.fragment)
992
+ return null;
993
+ for (; ; ) {
994
+ let last = this.trees.length - 1;
995
+ if (last < 0) {
996
+ this.nextFragment();
997
+ return null;
998
+ }
999
+ let top = this.trees[last], index = this.index[last];
1000
+ if (index == top.children.length) {
1001
+ this.trees.pop();
1002
+ this.start.pop();
1003
+ this.index.pop();
1004
+ continue;
1005
+ }
1006
+ let next = top.children[index];
1007
+ let start = this.start[last] + top.positions[index];
1008
+ if (start > pos) {
1009
+ this.nextStart = start;
1010
+ return null;
1011
+ }
1012
+ if (next instanceof Tree) {
1013
+ if (start == pos) {
1014
+ if (start < this.safeFrom)
1015
+ return null;
1016
+ let end = start + next.length;
1017
+ if (end <= this.safeTo) {
1018
+ let lookAhead = next.prop(NodeProp.lookAhead);
1019
+ if (!lookAhead || end + lookAhead < this.fragment.to)
1020
+ return next;
1021
+ }
1022
+ }
1023
+ this.index[last]++;
1024
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
1025
+ this.trees.push(next);
1026
+ this.start.push(start);
1027
+ this.index.push(0);
1028
+ }
1029
+ } else {
1030
+ this.index[last]++;
1031
+ this.nextStart = start + next.length;
1032
+ }
1033
+ }
1034
+ }
1035
+ };
1036
+ __name(_FragmentCursor, "FragmentCursor");
1037
+ let FragmentCursor = _FragmentCursor;
1038
+ const _TokenCache = class _TokenCache {
1039
+ constructor(parser, stream) {
1040
+ this.stream = stream;
1041
+ this.tokens = [];
1042
+ this.mainToken = null;
1043
+ this.actions = [];
1044
+ this.tokens = parser.tokenizers.map((_) => new CachedToken());
1045
+ }
1046
+ getActions(stack) {
1047
+ let actionIndex = 0;
1048
+ let main = null;
1049
+ let { parser } = stack.p, { tokenizers } = parser;
1050
+ let mask = parser.stateSlot(
1051
+ stack.state,
1052
+ 3
1053
+ /* ParseState.TokenizerMask */
1054
+ );
1055
+ let context = stack.curContext ? stack.curContext.hash : 0;
1056
+ let lookAhead = 0;
1057
+ for (let i = 0; i < tokenizers.length; i++) {
1058
+ if ((1 << i & mask) == 0)
1059
+ continue;
1060
+ let tokenizer = tokenizers[i], token = this.tokens[i];
1061
+ if (main && !tokenizer.fallback)
1062
+ continue;
1063
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
1064
+ this.updateCachedToken(token, tokenizer, stack);
1065
+ token.mask = mask;
1066
+ token.context = context;
1067
+ }
1068
+ if (token.lookAhead > token.end + 25)
1069
+ lookAhead = Math.max(token.lookAhead, lookAhead);
1070
+ if (token.value != 0) {
1071
+ let startIndex = actionIndex;
1072
+ if (token.extended > -1)
1073
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
1074
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
1075
+ if (!tokenizer.extend) {
1076
+ main = token;
1077
+ if (actionIndex > startIndex)
1078
+ break;
1079
+ }
1080
+ }
1081
+ }
1082
+ while (this.actions.length > actionIndex)
1083
+ this.actions.pop();
1084
+ if (lookAhead)
1085
+ stack.setLookAhead(lookAhead);
1086
+ if (!main && stack.pos == this.stream.end) {
1087
+ main = new CachedToken();
1088
+ main.value = stack.p.parser.eofTerm;
1089
+ main.start = main.end = stack.pos;
1090
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
1091
+ }
1092
+ this.mainToken = main;
1093
+ return this.actions;
1094
+ }
1095
+ getMainToken(stack) {
1096
+ if (this.mainToken)
1097
+ return this.mainToken;
1098
+ let main = new CachedToken(), { pos, p } = stack;
1099
+ main.start = pos;
1100
+ main.end = Math.min(pos + 1, p.stream.end);
1101
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
1102
+ return main;
1103
+ }
1104
+ updateCachedToken(token, tokenizer, stack) {
1105
+ let start = this.stream.clipPos(stack.pos);
1106
+ tokenizer.token(this.stream.reset(start, token), stack);
1107
+ if (token.value > -1) {
1108
+ let { parser } = stack.p;
1109
+ for (let i = 0; i < parser.specialized.length; i++)
1110
+ if (parser.specialized[i] == token.value) {
1111
+ let result = parser.specializers[i](this.stream.read(token.start, token.end), stack);
1112
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
1113
+ if ((result & 1) == 0)
1114
+ token.value = result >> 1;
1115
+ else
1116
+ token.extended = result >> 1;
1117
+ break;
1118
+ }
1119
+ }
1120
+ } else {
1121
+ token.value = 0;
1122
+ token.end = this.stream.clipPos(start + 1);
1123
+ }
1124
+ }
1125
+ putAction(action, token, end, index) {
1126
+ for (let i = 0; i < index; i += 3)
1127
+ if (this.actions[i] == action)
1128
+ return index;
1129
+ this.actions[index++] = action;
1130
+ this.actions[index++] = token;
1131
+ this.actions[index++] = end;
1132
+ return index;
1133
+ }
1134
+ addActions(stack, token, end, index) {
1135
+ let { state } = stack, { parser } = stack.p, { data } = parser;
1136
+ for (let set = 0; set < 2; set++) {
1137
+ for (let i = parser.stateSlot(
1138
+ state,
1139
+ set ? 2 : 1
1140
+ /* ParseState.Actions */
1141
+ ); ; i += 3) {
1142
+ if (data[i] == 65535) {
1143
+ if (data[i + 1] == 1) {
1144
+ i = pair(data, i + 2);
1145
+ } else {
1146
+ if (index == 0 && data[i + 1] == 2)
1147
+ index = this.putAction(pair(data, i + 2), token, end, index);
1148
+ break;
1149
+ }
1150
+ }
1151
+ if (data[i] == token)
1152
+ index = this.putAction(pair(data, i + 1), token, end, index);
1153
+ }
1154
+ }
1155
+ return index;
1156
+ }
1157
+ };
1158
+ __name(_TokenCache, "TokenCache");
1159
+ let TokenCache = _TokenCache;
1160
+ const _Parse = class _Parse {
1161
+ constructor(parser, input, fragments, ranges) {
1162
+ this.parser = parser;
1163
+ this.input = input;
1164
+ this.ranges = ranges;
1165
+ this.recovering = 0;
1166
+ this.nextStackID = 9812;
1167
+ this.minStackPos = 0;
1168
+ this.reused = [];
1169
+ this.stoppedAt = null;
1170
+ this.lastBigReductionStart = -1;
1171
+ this.lastBigReductionSize = 0;
1172
+ this.bigReductionCount = 0;
1173
+ this.stream = new InputStream(input, ranges);
1174
+ this.tokens = new TokenCache(parser, this.stream);
1175
+ this.topTerm = parser.top[1];
1176
+ let { from } = ranges[0];
1177
+ this.stacks = [Stack.start(this, parser.top[0], from)];
1178
+ this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 ? new FragmentCursor(fragments, parser.nodeSet) : null;
1179
+ }
1180
+ get parsedPos() {
1181
+ return this.minStackPos;
1182
+ }
1183
+ // Move the parser forward. This will process all parse stacks at
1184
+ // `this.pos` and try to advance them to a further position. If no
1185
+ // stack for such a position is found, it'll start error-recovery.
1186
+ //
1187
+ // When the parse is finished, this will return a syntax tree. When
1188
+ // not, it returns `null`.
1189
+ advance() {
1190
+ let stacks = this.stacks, pos = this.minStackPos;
1191
+ let newStacks = this.stacks = [];
1192
+ let stopped, stoppedTokens;
1193
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
1194
+ let [s] = stacks;
1195
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
1196
+ }
1197
+ this.bigReductionCount = this.lastBigReductionSize = 0;
1198
+ }
1199
+ for (let i = 0; i < stacks.length; i++) {
1200
+ let stack = stacks[i];
1201
+ for (; ; ) {
1202
+ this.tokens.mainToken = null;
1203
+ if (stack.pos > pos) {
1204
+ newStacks.push(stack);
1205
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
1206
+ continue;
1207
+ } else {
1208
+ if (!stopped) {
1209
+ stopped = [];
1210
+ stoppedTokens = [];
1211
+ }
1212
+ stopped.push(stack);
1213
+ let tok = this.tokens.getMainToken(stack);
1214
+ stoppedTokens.push(tok.value, tok.end);
1215
+ }
1216
+ break;
1217
+ }
1218
+ }
1219
+ if (!newStacks.length) {
1220
+ let finished = stopped && findFinished(stopped);
1221
+ if (finished) {
1222
+ if (verbose)
1223
+ console.log("Finish with " + this.stackID(finished));
1224
+ return this.stackToTree(finished);
1225
+ }
1226
+ if (this.parser.strict) {
1227
+ if (verbose && stopped)
1228
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
1229
+ throw new SyntaxError("No parse at " + pos);
1230
+ }
1231
+ if (!this.recovering)
1232
+ this.recovering = 5;
1233
+ }
1234
+ if (this.recovering && stopped) {
1235
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
1236
+ if (finished) {
1237
+ if (verbose)
1238
+ console.log("Force-finish " + this.stackID(finished));
1239
+ return this.stackToTree(finished.forceAll());
1240
+ }
1241
+ }
1242
+ if (this.recovering) {
1243
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
1244
+ if (newStacks.length > maxRemaining) {
1245
+ newStacks.sort((a, b) => b.score - a.score);
1246
+ while (newStacks.length > maxRemaining)
1247
+ newStacks.pop();
1248
+ }
1249
+ if (newStacks.some((s) => s.reducePos > pos))
1250
+ this.recovering--;
1251
+ } else if (newStacks.length > 1) {
1252
+ outer: for (let i = 0; i < newStacks.length - 1; i++) {
1253
+ let stack = newStacks[i];
1254
+ for (let j = i + 1; j < newStacks.length; j++) {
1255
+ let other = newStacks[j];
1256
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
1257
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
1258
+ newStacks.splice(j--, 1);
1259
+ } else {
1260
+ newStacks.splice(i--, 1);
1261
+ continue outer;
1262
+ }
1263
+ }
1264
+ }
1265
+ }
1266
+ if (newStacks.length > 12)
1267
+ newStacks.splice(
1268
+ 12,
1269
+ newStacks.length - 12
1270
+ /* Rec.MaxStackCount */
1271
+ );
1272
+ }
1273
+ this.minStackPos = newStacks[0].pos;
1274
+ for (let i = 1; i < newStacks.length; i++)
1275
+ if (newStacks[i].pos < this.minStackPos)
1276
+ this.minStackPos = newStacks[i].pos;
1277
+ return null;
1278
+ }
1279
+ stopAt(pos) {
1280
+ if (this.stoppedAt != null && this.stoppedAt < pos)
1281
+ throw new RangeError("Can't move stoppedAt forward");
1282
+ this.stoppedAt = pos;
1283
+ }
1284
+ // Returns an updated version of the given stack, or null if the
1285
+ // stack can't advance normally. When `split` and `stacks` are
1286
+ // given, stacks split off by ambiguous operations will be pushed to
1287
+ // `split`, or added to `stacks` if they move `pos` forward.
1288
+ advanceStack(stack, stacks, split) {
1289
+ let start = stack.pos, { parser } = this;
1290
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1291
+ if (this.stoppedAt != null && start > this.stoppedAt)
1292
+ return stack.forceReduce() ? stack : null;
1293
+ if (this.fragments) {
1294
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
1295
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
1296
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
1297
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
1298
+ stack.useNode(cached, match);
1299
+ if (verbose)
1300
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
1301
+ return true;
1302
+ }
1303
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
1304
+ break;
1305
+ let inner = cached.children[0];
1306
+ if (inner instanceof Tree && cached.positions[0] == 0)
1307
+ cached = inner;
1308
+ else
1309
+ break;
1310
+ }
1311
+ }
1312
+ let defaultReduce = parser.stateSlot(
1313
+ stack.state,
1314
+ 4
1315
+ /* ParseState.DefaultReduce */
1316
+ );
1317
+ if (defaultReduce > 0) {
1318
+ stack.reduce(defaultReduce);
1319
+ if (verbose)
1320
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(
1321
+ defaultReduce & 65535
1322
+ /* Action.ValueMask */
1323
+ )})`);
1324
+ return true;
1325
+ }
1326
+ if (stack.stack.length >= 8400) {
1327
+ while (stack.stack.length > 6e3 && stack.forceReduce()) {
1328
+ }
1329
+ }
1330
+ let actions = this.tokens.getActions(stack);
1331
+ for (let i = 0; i < actions.length; ) {
1332
+ let action = actions[i++], term = actions[i++], end = actions[i++];
1333
+ let last = i == actions.length || !split;
1334
+ let localStack = last ? stack : stack.split();
1335
+ let main = this.tokens.mainToken;
1336
+ localStack.apply(action, term, main ? main.start : localStack.pos, end);
1337
+ if (verbose)
1338
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser.getName(
1339
+ action & 65535
1340
+ /* Action.ValueMask */
1341
+ )}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
1342
+ if (last)
1343
+ return true;
1344
+ else if (localStack.pos > start)
1345
+ stacks.push(localStack);
1346
+ else
1347
+ split.push(localStack);
1348
+ }
1349
+ return false;
1350
+ }
1351
+ // Advance a given stack forward as far as it will go. Returns the
1352
+ // (possibly updated) stack if it got stuck, or null if it moved
1353
+ // forward and was given to `pushStackDedup`.
1354
+ advanceFully(stack, newStacks) {
1355
+ let pos = stack.pos;
1356
+ for (; ; ) {
1357
+ if (!this.advanceStack(stack, null, null))
1358
+ return false;
1359
+ if (stack.pos > pos) {
1360
+ pushStackDedup(stack, newStacks);
1361
+ return true;
1362
+ }
1363
+ }
1364
+ }
1365
+ runRecovery(stacks, tokens, newStacks) {
1366
+ let finished = null, restarted = false;
1367
+ for (let i = 0; i < stacks.length; i++) {
1368
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
1369
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1370
+ if (stack.deadEnd) {
1371
+ if (restarted)
1372
+ continue;
1373
+ restarted = true;
1374
+ stack.restart();
1375
+ if (verbose)
1376
+ console.log(base + this.stackID(stack) + " (restarted)");
1377
+ let done = this.advanceFully(stack, newStacks);
1378
+ if (done)
1379
+ continue;
1380
+ }
1381
+ let force = stack.split(), forceBase = base;
1382
+ for (let j = 0; force.forceReduce() && j < 10; j++) {
1383
+ if (verbose)
1384
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
1385
+ let done = this.advanceFully(force, newStacks);
1386
+ if (done)
1387
+ break;
1388
+ if (verbose)
1389
+ forceBase = this.stackID(force) + " -> ";
1390
+ }
1391
+ for (let insert of stack.recoverByInsert(token)) {
1392
+ if (verbose)
1393
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
1394
+ this.advanceFully(insert, newStacks);
1395
+ }
1396
+ if (this.stream.end > stack.pos) {
1397
+ if (tokenEnd == stack.pos) {
1398
+ tokenEnd++;
1399
+ token = 0;
1400
+ }
1401
+ stack.recoverByDelete(token, tokenEnd);
1402
+ if (verbose)
1403
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
1404
+ pushStackDedup(stack, newStacks);
1405
+ } else if (!finished || finished.score < stack.score) {
1406
+ finished = stack;
1407
+ }
1408
+ }
1409
+ return finished;
1410
+ }
1411
+ // Convert the stack's buffer to a syntax tree.
1412
+ stackToTree(stack) {
1413
+ stack.close();
1414
+ return Tree.build({
1415
+ buffer: StackBufferCursor.create(stack),
1416
+ nodeSet: this.parser.nodeSet,
1417
+ topID: this.topTerm,
1418
+ maxBufferLength: this.parser.bufferLength,
1419
+ reused: this.reused,
1420
+ start: this.ranges[0].from,
1421
+ length: stack.pos - this.ranges[0].from,
1422
+ minRepeatType: this.parser.minRepeatTerm
1423
+ });
1424
+ }
1425
+ stackID(stack) {
1426
+ let id2 = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
1427
+ if (!id2)
1428
+ stackIDs.set(stack, id2 = String.fromCodePoint(this.nextStackID++));
1429
+ return id2 + stack;
1430
+ }
1431
+ };
1432
+ __name(_Parse, "Parse");
1433
+ let Parse = _Parse;
1434
+ function pushStackDedup(stack, newStacks) {
1435
+ for (let i = 0; i < newStacks.length; i++) {
1436
+ let other = newStacks[i];
1437
+ if (other.pos == stack.pos && other.sameState(stack)) {
1438
+ if (newStacks[i].score < stack.score)
1439
+ newStacks[i] = stack;
1440
+ return;
1441
+ }
1442
+ }
1443
+ newStacks.push(stack);
1444
+ }
1445
+ __name(pushStackDedup, "pushStackDedup");
1446
+ const _Dialect = class _Dialect {
1447
+ constructor(source, flags, disabled) {
1448
+ this.source = source;
1449
+ this.flags = flags;
1450
+ this.disabled = disabled;
1451
+ }
1452
+ allows(term) {
1453
+ return !this.disabled || this.disabled[term] == 0;
1454
+ }
1455
+ };
1456
+ __name(_Dialect, "Dialect");
1457
+ let Dialect = _Dialect;
1458
+ const id = /* @__PURE__ */ __name((x) => x, "id");
1459
+ const _ContextTracker = class _ContextTracker {
1460
+ /**
1461
+ Define a context tracker.
1462
+ */
1463
+ constructor(spec) {
1464
+ this.start = spec.start;
1465
+ this.shift = spec.shift || id;
1466
+ this.reduce = spec.reduce || id;
1467
+ this.reuse = spec.reuse || id;
1468
+ this.hash = spec.hash || (() => 0);
1469
+ this.strict = spec.strict !== false;
1470
+ }
1471
+ };
1472
+ __name(_ContextTracker, "ContextTracker");
1473
+ let ContextTracker = _ContextTracker;
1474
+ const _LRParser = class _LRParser extends Parser {
1475
+ /**
1476
+ @internal
1477
+ */
1478
+ constructor(spec) {
1479
+ super();
1480
+ this.wrappers = [];
1481
+ if (spec.version != 14)
1482
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
1483
+ let nodeNames = spec.nodeNames.split(" ");
1484
+ this.minRepeatTerm = nodeNames.length;
1485
+ for (let i = 0; i < spec.repeatNodeCount; i++)
1486
+ nodeNames.push("");
1487
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
1488
+ let nodeProps = [];
1489
+ for (let i = 0; i < nodeNames.length; i++)
1490
+ nodeProps.push([]);
1491
+ function setProp(nodeID, prop, value) {
1492
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
1493
+ }
1494
+ __name(setProp, "setProp");
1495
+ if (spec.nodeProps)
1496
+ for (let propSpec of spec.nodeProps) {
1497
+ let prop = propSpec[0];
1498
+ if (typeof prop == "string")
1499
+ prop = NodeProp[prop];
1500
+ for (let i = 1; i < propSpec.length; ) {
1501
+ let next = propSpec[i++];
1502
+ if (next >= 0) {
1503
+ setProp(next, prop, propSpec[i++]);
1504
+ } else {
1505
+ let value = propSpec[i + -next];
1506
+ for (let j = -next; j > 0; j--)
1507
+ setProp(propSpec[i++], prop, value);
1508
+ i++;
1509
+ }
1510
+ }
1511
+ }
1512
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
1513
+ name: i >= this.minRepeatTerm ? void 0 : name,
1514
+ id: i,
1515
+ props: nodeProps[i],
1516
+ top: topTerms.indexOf(i) > -1,
1517
+ error: i == 0,
1518
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
1519
+ })));
1520
+ if (spec.propSources)
1521
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
1522
+ this.strict = false;
1523
+ this.bufferLength = DefaultBufferLength;
1524
+ let tokenArray = decodeArray(spec.tokenData);
1525
+ this.context = spec.context;
1526
+ this.specializerSpecs = spec.specialized || [];
1527
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
1528
+ for (let i = 0; i < this.specializerSpecs.length; i++)
1529
+ this.specialized[i] = this.specializerSpecs[i].term;
1530
+ this.specializers = this.specializerSpecs.map(getSpecializer);
1531
+ this.states = decodeArray(spec.states, Uint32Array);
1532
+ this.data = decodeArray(spec.stateData);
1533
+ this.goto = decodeArray(spec.goto);
1534
+ this.maxTerm = spec.maxTerm;
1535
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
1536
+ this.topRules = spec.topRules;
1537
+ this.dialects = spec.dialects || {};
1538
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
1539
+ this.tokenPrecTable = spec.tokenPrec;
1540
+ this.termNames = spec.termNames || null;
1541
+ this.maxNode = this.nodeSet.types.length - 1;
1542
+ this.dialect = this.parseDialect();
1543
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
1544
+ }
1545
+ createParse(input, fragments, ranges) {
1546
+ let parse = new Parse(this, input, fragments, ranges);
1547
+ for (let w of this.wrappers)
1548
+ parse = w(parse, input, fragments, ranges);
1549
+ return parse;
1550
+ }
1551
+ /**
1552
+ Get a goto table entry @internal
1553
+ */
1554
+ getGoto(state, term, loose = false) {
1555
+ let table = this.goto;
1556
+ if (term >= table[0])
1557
+ return -1;
1558
+ for (let pos = table[term + 1]; ; ) {
1559
+ let groupTag = table[pos++], last = groupTag & 1;
1560
+ let target = table[pos++];
1561
+ if (last && loose)
1562
+ return target;
1563
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
1564
+ if (table[pos] == state)
1565
+ return target;
1566
+ if (last)
1567
+ return -1;
1568
+ }
1569
+ }
1570
+ /**
1571
+ Check if this state has an action for a given terminal @internal
1572
+ */
1573
+ hasAction(state, terminal) {
1574
+ let data = this.data;
1575
+ for (let set = 0; set < 2; set++) {
1576
+ for (let i = this.stateSlot(
1577
+ state,
1578
+ set ? 2 : 1
1579
+ /* ParseState.Actions */
1580
+ ), next; ; i += 3) {
1581
+ if ((next = data[i]) == 65535) {
1582
+ if (data[i + 1] == 1)
1583
+ next = data[i = pair(data, i + 2)];
1584
+ else if (data[i + 1] == 2)
1585
+ return pair(data, i + 2);
1586
+ else
1587
+ break;
1588
+ }
1589
+ if (next == terminal || next == 0)
1590
+ return pair(data, i + 1);
1591
+ }
1592
+ }
1593
+ return 0;
1594
+ }
1595
+ /**
1596
+ @internal
1597
+ */
1598
+ stateSlot(state, slot) {
1599
+ return this.states[state * 6 + slot];
1600
+ }
1601
+ /**
1602
+ @internal
1603
+ */
1604
+ stateFlag(state, flag) {
1605
+ return (this.stateSlot(
1606
+ state,
1607
+ 0
1608
+ /* ParseState.Flags */
1609
+ ) & flag) > 0;
1610
+ }
1611
+ /**
1612
+ @internal
1613
+ */
1614
+ validAction(state, action) {
1615
+ return !!this.allActions(state, (a) => a == action ? true : null);
1616
+ }
1617
+ /**
1618
+ @internal
1619
+ */
1620
+ allActions(state, action) {
1621
+ let deflt = this.stateSlot(
1622
+ state,
1623
+ 4
1624
+ /* ParseState.DefaultReduce */
1625
+ );
1626
+ let result = deflt ? action(deflt) : void 0;
1627
+ for (let i = this.stateSlot(
1628
+ state,
1629
+ 1
1630
+ /* ParseState.Actions */
1631
+ ); result == null; i += 3) {
1632
+ if (this.data[i] == 65535) {
1633
+ if (this.data[i + 1] == 1)
1634
+ i = pair(this.data, i + 2);
1635
+ else
1636
+ break;
1637
+ }
1638
+ result = action(pair(this.data, i + 1));
1639
+ }
1640
+ return result;
1641
+ }
1642
+ /**
1643
+ Get the states that can follow this one through shift actions or
1644
+ goto jumps. @internal
1645
+ */
1646
+ nextStates(state) {
1647
+ let result = [];
1648
+ for (let i = this.stateSlot(
1649
+ state,
1650
+ 1
1651
+ /* ParseState.Actions */
1652
+ ); ; i += 3) {
1653
+ if (this.data[i] == 65535) {
1654
+ if (this.data[i + 1] == 1)
1655
+ i = pair(this.data, i + 2);
1656
+ else
1657
+ break;
1658
+ }
1659
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
1660
+ let value = this.data[i + 1];
1661
+ if (!result.some((v, i2) => i2 & 1 && v == value))
1662
+ result.push(this.data[i], value);
1663
+ }
1664
+ }
1665
+ return result;
1666
+ }
1667
+ /**
1668
+ Configure the parser. Returns a new parser instance that has the
1669
+ given settings modified. Settings not provided in `config` are
1670
+ kept from the original parser.
1671
+ */
1672
+ configure(config) {
1673
+ let copy = Object.assign(Object.create(_LRParser.prototype), this);
1674
+ if (config.props)
1675
+ copy.nodeSet = this.nodeSet.extend(...config.props);
1676
+ if (config.top) {
1677
+ let info = this.topRules[config.top];
1678
+ if (!info)
1679
+ throw new RangeError(`Invalid top rule name ${config.top}`);
1680
+ copy.top = info;
1681
+ }
1682
+ if (config.tokenizers)
1683
+ copy.tokenizers = this.tokenizers.map((t) => {
1684
+ let found = config.tokenizers.find((r) => r.from == t);
1685
+ return found ? found.to : t;
1686
+ });
1687
+ if (config.specializers) {
1688
+ copy.specializers = this.specializers.slice();
1689
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
1690
+ let found = config.specializers.find((r) => r.from == s.external);
1691
+ if (!found)
1692
+ return s;
1693
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
1694
+ copy.specializers[i] = getSpecializer(spec);
1695
+ return spec;
1696
+ });
1697
+ }
1698
+ if (config.contextTracker)
1699
+ copy.context = config.contextTracker;
1700
+ if (config.dialect)
1701
+ copy.dialect = this.parseDialect(config.dialect);
1702
+ if (config.strict != null)
1703
+ copy.strict = config.strict;
1704
+ if (config.wrap)
1705
+ copy.wrappers = copy.wrappers.concat(config.wrap);
1706
+ if (config.bufferLength != null)
1707
+ copy.bufferLength = config.bufferLength;
1708
+ return copy;
1709
+ }
1710
+ /**
1711
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1712
+ are registered for this parser.
1713
+ */
1714
+ hasWrappers() {
1715
+ return this.wrappers.length > 0;
1716
+ }
1717
+ /**
1718
+ Returns the name associated with a given term. This will only
1719
+ work for all terms when the parser was generated with the
1720
+ `--names` option. By default, only the names of tagged terms are
1721
+ stored.
1722
+ */
1723
+ getName(term) {
1724
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
1725
+ }
1726
+ /**
1727
+ The eof term id is always allocated directly after the node
1728
+ types. @internal
1729
+ */
1730
+ get eofTerm() {
1731
+ return this.maxNode + 1;
1732
+ }
1733
+ /**
1734
+ The type of top node produced by the parser.
1735
+ */
1736
+ get topNode() {
1737
+ return this.nodeSet.types[this.top[1]];
1738
+ }
1739
+ /**
1740
+ @internal
1741
+ */
1742
+ dynamicPrecedence(term) {
1743
+ let prec = this.dynamicPrecedences;
1744
+ return prec == null ? 0 : prec[term] || 0;
1745
+ }
1746
+ /**
1747
+ @internal
1748
+ */
1749
+ parseDialect(dialect) {
1750
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
1751
+ if (dialect)
1752
+ for (let part of dialect.split(" ")) {
1753
+ let id2 = values.indexOf(part);
1754
+ if (id2 >= 0)
1755
+ flags[id2] = true;
1756
+ }
1757
+ let disabled = null;
1758
+ for (let i = 0; i < values.length; i++)
1759
+ if (!flags[i]) {
1760
+ for (let j = this.dialects[values[i]], id2; (id2 = this.data[j++]) != 65535; )
1761
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id2] = 1;
1762
+ }
1763
+ return new Dialect(dialect, flags, disabled);
1764
+ }
1765
+ /**
1766
+ Used by the output of the parser generator. Not available to
1767
+ user code. @hide
1768
+ */
1769
+ static deserialize(spec) {
1770
+ return new _LRParser(spec);
1771
+ }
1772
+ };
1773
+ __name(_LRParser, "LRParser");
1774
+ let LRParser = _LRParser;
1775
+ function pair(data, off) {
1776
+ return data[off] | data[off + 1] << 16;
1777
+ }
1778
+ __name(pair, "pair");
1779
+ function findFinished(stacks) {
1780
+ let best = null;
1781
+ for (let stack of stacks) {
1782
+ let stopped = stack.p.stoppedAt;
1783
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
1784
+ stack.state,
1785
+ 2
1786
+ /* StateFlag.Accepting */
1787
+ ) && (!best || best.score < stack.score))
1788
+ best = stack;
1789
+ }
1790
+ return best;
1791
+ }
1792
+ __name(findFinished, "findFinished");
1793
+ function getSpecializer(spec) {
1794
+ if (spec.external) {
1795
+ let mask = spec.extend ? 1 : 0;
1796
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
1797
+ }
1798
+ return spec.get;
1799
+ }
1800
+ __name(getSpecializer, "getSpecializer");
1801
+ export {
1802
+ ContextTracker as C,
1803
+ ExternalTokenizer as E,
1804
+ LRParser as L,
1805
+ LocalTokenGroup as a
1806
+ };
1807
+ //# sourceMappingURL=index-B7vRtYlU.js.map