claude-maestro 0.1.16

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