@veltra/desktop 1.2.16 → 1.2.18

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 (72) hide show
  1. package/dist/components/action/action-group.vue.d.ts +2 -2
  2. package/dist/components/action/action.vue.d.ts +1 -1
  3. package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
  4. package/dist/components/cascade/cascade.vue.d.ts +3 -3
  5. package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
  6. package/dist/components/checkbox-group/checkbox-group.vue.d.ts +2 -2
  7. package/dist/components/code-editor/basic-setup.js +7 -7
  8. package/dist/components/code-editor/code-editor.js +15 -10
  9. package/dist/components/code-editor/code-editor.js.map +1 -1
  10. package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
  11. package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
  12. package/dist/components/empty/empty.vue.d.ts +1 -1
  13. package/dist/components/file-picker/file-picker.vue.d.ts +1 -1
  14. package/dist/components/input/input.vue.d.ts +2 -2
  15. package/dist/components/multi-select/multi-select.vue.d.ts +3 -3
  16. package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +3 -3
  17. package/dist/components/number-input/number-input.vue.d.ts +2 -2
  18. package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
  19. package/dist/components/password-input/password-input.vue.d.ts +1 -1
  20. package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
  21. package/dist/components/radio-group/radio-group.vue.d.ts +2 -2
  22. package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
  23. package/dist/components/select/select.vue.d.ts +2 -2
  24. package/dist/components/textarea/textarea.vue.d.ts +2 -2
  25. package/dist/components/tip/tip.vue.d.ts +1 -1
  26. package/dist/components/tree-select/tree-select.vue.d.ts +3 -3
  27. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js +1750 -0
  28. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  29. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js +1719 -0
  30. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  31. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js +51 -0
  32. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js.map +1 -0
  33. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js +378 -0
  34. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  35. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js +31 -0
  36. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js.map +1 -0
  37. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js +601 -0
  38. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js.map +1 -0
  39. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js +1767 -0
  40. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js.map +1 -0
  41. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js +569 -0
  42. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  43. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js +1142 -0
  44. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js.map +1 -0
  45. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js +3372 -0
  46. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js.map +1 -0
  47. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js +165 -0
  48. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js.map +1 -0
  49. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js +9770 -0
  50. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js.map +1 -0
  51. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js +1567 -0
  52. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js.map +1 -0
  53. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js +864 -0
  54. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js.map +1 -0
  55. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js +235 -0
  56. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js.map +1 -0
  57. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js +470 -0
  58. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  59. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js +55 -0
  60. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js.map +1 -0
  61. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js +1485 -0
  62. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js.map +1 -0
  63. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js +73 -0
  64. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js.map +1 -0
  65. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js +26 -0
  66. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js.map +1 -0
  67. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js +95 -0
  68. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js.map +1 -0
  69. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js +104 -0
  70. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js.map +1 -0
  71. package/package.json +20 -18
  72. package/src/components/code-editor/code-editor.vue +12 -7
@@ -0,0 +1,1485 @@
1
+ import { DefaultBufferLength, IterMode, NodeProp, NodeSet, NodeType, Parser, Tree } from "../../../../../@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js";
2
+ //#region ../../node_modules/.bun/@lezer+lr@1.4.10/node_modules/@lezer/lr/dist/index.js
3
+ /**
4
+ A parse stack. These are used internally by the parser to track
5
+ parsing progress. They also provide some properties and methods
6
+ that external code such as a tokenizer can use to get information
7
+ about the parse state.
8
+ */
9
+ var Stack = class Stack {
10
+ /**
11
+ @internal
12
+ */
13
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
14
+ this.p = p;
15
+ this.stack = stack;
16
+ this.state = state;
17
+ this.reducePos = reducePos;
18
+ this.pos = pos;
19
+ this.score = score;
20
+ this.buffer = buffer;
21
+ this.bufferBase = bufferBase;
22
+ this.curContext = curContext;
23
+ this.lookAhead = lookAhead;
24
+ this.parent = parent;
25
+ }
26
+ /**
27
+ @internal
28
+ */
29
+ toString() {
30
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
31
+ }
32
+ /**
33
+ @internal
34
+ */
35
+ static start(p, state, pos = 0) {
36
+ let cx = p.parser.context;
37
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
38
+ }
39
+ /**
40
+ The stack's current [context](#lr.ContextTracker) value, if
41
+ any. Its type will depend on the context tracker's type
42
+ parameter, or it will be `null` if there is no context
43
+ tracker.
44
+ */
45
+ get context() {
46
+ return this.curContext ? this.curContext.context : null;
47
+ }
48
+ /**
49
+ @internal
50
+ */
51
+ pushState(state, start) {
52
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
53
+ this.state = state;
54
+ }
55
+ /**
56
+ @internal
57
+ */
58
+ reduce(action) {
59
+ var _a;
60
+ let depth = action >> 19, type = action & 65535;
61
+ let { parser } = this.p;
62
+ let lookaheadRecord = this.reducePos < this.pos - 25 && this.setLookAhead(this.pos);
63
+ let dPrec = parser.dynamicPrecedence(type);
64
+ if (dPrec) this.score += dPrec;
65
+ if (depth == 0) {
66
+ if (type < parser.minRepeatTerm && this.reducePos < this.pos) this.reducePos = this.pos;
67
+ this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
68
+ if (type < parser.minRepeatTerm) this.storeNode(type, this.reducePos, this.reducePos, lookaheadRecord ? 8 : 4, true);
69
+ this.reduceContext(type, this.reducePos);
70
+ return;
71
+ }
72
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
73
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from;
74
+ if (type < parser.minRepeatTerm && start == this.reducePos && this.reducePos < this.pos) this.reducePos = this.pos;
75
+ let 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(this.state, 1) ? this.pos : this.reducePos;
89
+ this.storeNode(type, start, pos, count + 4, true);
90
+ }
91
+ if (action & 262144) this.state = this.stack[base];
92
+ else {
93
+ let baseStateID = this.stack[base - 3];
94
+ this.state = parser.getGoto(baseStateID, type, true);
95
+ }
96
+ while (this.stack.length > base) this.stack.pop();
97
+ this.reduceContext(type, start);
98
+ }
99
+ /**
100
+ @internal
101
+ */
102
+ storeNode(term, start, end, size = 4, mustSink = false) {
103
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
104
+ let top = this.buffer.length;
105
+ if (top > 0 && this.buffer[top - 4] == 0 && this.buffer[top - 1] > -1) {
106
+ if (start == end) return;
107
+ if (this.buffer[top - 2] >= start) {
108
+ this.buffer[top - 2] = end;
109
+ return;
110
+ }
111
+ }
112
+ }
113
+ if (!mustSink || this.pos == end) this.buffer.push(term, start, end, size);
114
+ else {
115
+ let index = this.buffer.length;
116
+ if (index > 0 && (this.buffer[index - 4] != 0 || this.buffer[index - 1] < 0)) {
117
+ let mustMove = false;
118
+ for (let scan = index; scan > 0 && this.buffer[scan - 2] > end; scan -= 4) if (this.buffer[scan - 1] >= 0) {
119
+ mustMove = true;
120
+ break;
121
+ }
122
+ if (mustMove) while (index > 0 && this.buffer[index - 2] > end) {
123
+ this.buffer[index] = this.buffer[index - 4];
124
+ this.buffer[index + 1] = this.buffer[index - 3];
125
+ this.buffer[index + 2] = this.buffer[index - 2];
126
+ this.buffer[index + 3] = this.buffer[index - 1];
127
+ index -= 4;
128
+ if (size > 4) size -= 4;
129
+ }
130
+ }
131
+ this.buffer[index] = term;
132
+ this.buffer[index + 1] = start;
133
+ this.buffer[index + 2] = end;
134
+ this.buffer[index + 3] = size;
135
+ }
136
+ }
137
+ /**
138
+ @internal
139
+ */
140
+ shift(action, type, start, end) {
141
+ if (action & 131072) this.pushState(action & 65535, this.pos);
142
+ else if ((action & 262144) == 0) {
143
+ let nextState = action, { parser } = this.p;
144
+ this.pos = end;
145
+ let skipped = parser.stateFlag(nextState, 1);
146
+ if (!skipped && (end > start || type <= parser.maxNode)) this.reducePos = end;
147
+ this.pushState(nextState, skipped ? start : Math.min(start, this.reducePos));
148
+ this.shiftContext(type, start);
149
+ if (type <= parser.maxNode) this.buffer.push(type, start, end, 4);
150
+ } else {
151
+ this.pos = end;
152
+ this.shiftContext(type, start);
153
+ if (type <= this.p.parser.maxNode) this.buffer.push(type, start, end, 4);
154
+ }
155
+ }
156
+ /**
157
+ @internal
158
+ */
159
+ apply(action, next, nextStart, nextEnd) {
160
+ if (action & 65536) this.reduce(action);
161
+ else this.shift(action, next, nextStart, nextEnd);
162
+ }
163
+ /**
164
+ @internal
165
+ */
166
+ useNode(value, next) {
167
+ let index = this.p.reused.length - 1;
168
+ if (index < 0 || this.p.reused[index] != value) {
169
+ this.p.reused.push(value);
170
+ index++;
171
+ }
172
+ let start = this.pos;
173
+ this.reducePos = this.pos = start + value.length;
174
+ this.pushState(next, start);
175
+ this.buffer.push(index, start, this.reducePos, -1);
176
+ if (this.curContext) this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
177
+ }
178
+ /**
179
+ @internal
180
+ */
181
+ split() {
182
+ let parent = this;
183
+ let off = parent.buffer.length;
184
+ if (off && parent.buffer[off - 4] == 0) off -= 4;
185
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos) off -= 4;
186
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
187
+ while (parent && base == parent.bufferBase) parent = parent.parent;
188
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
189
+ }
190
+ /**
191
+ @internal
192
+ */
193
+ recoverByDelete(next, nextEnd) {
194
+ let isNode = next <= this.p.parser.maxNode;
195
+ if (isNode) this.storeNode(next, this.pos, nextEnd, 4);
196
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
197
+ this.pos = this.reducePos = nextEnd;
198
+ this.score -= 190;
199
+ }
200
+ /**
201
+ Check if the given term would be able to be shifted (optionally
202
+ after some reductions) on this stack. This can be useful for
203
+ external tokenizers that want to make sure they only provide a
204
+ given token when it applies.
205
+ */
206
+ canShift(term) {
207
+ for (let sim = new SimulatedStack(this);;) {
208
+ let action = this.p.parser.stateSlot(sim.state, 4) || this.p.parser.hasAction(sim.state, term);
209
+ if (action == 0) return false;
210
+ if ((action & 65536) == 0) return true;
211
+ sim.reduce(action);
212
+ }
213
+ }
214
+ /**
215
+ @internal
216
+ */
217
+ recoverByInsert(next) {
218
+ if (this.stack.length >= 300) return [];
219
+ let nextStates = this.p.parser.nextStates(this.state);
220
+ if (nextStates.length > 8 || this.stack.length >= 120) {
221
+ let best = [];
222
+ for (let i = 0, s; i < nextStates.length; i += 2) if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next)) best.push(nextStates[i], s);
223
+ if (this.stack.length < 120) for (let i = 0; best.length < 8 && i < nextStates.length; i += 2) {
224
+ let s = nextStates[i + 1];
225
+ if (!best.some((v, i) => i & 1 && v == s)) best.push(nextStates[i], s);
226
+ }
227
+ nextStates = best;
228
+ }
229
+ let result = [];
230
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
231
+ let s = nextStates[i + 1];
232
+ if (s == this.state) continue;
233
+ let stack = this.split();
234
+ stack.pushState(s, this.pos);
235
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
236
+ stack.shiftContext(nextStates[i], this.pos);
237
+ stack.reducePos = this.pos;
238
+ stack.score -= 200;
239
+ result.push(stack);
240
+ }
241
+ return result;
242
+ }
243
+ /**
244
+ @internal
245
+ */
246
+ forceReduce() {
247
+ let { parser } = this.p;
248
+ let reduce = parser.stateSlot(this.state, 5);
249
+ if ((reduce & 65536) == 0) return false;
250
+ if (!parser.validAction(this.state, reduce)) {
251
+ let depth = reduce >> 19, term = reduce & 65535;
252
+ let target = this.stack.length - depth * 3;
253
+ if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) {
254
+ let backup = this.findForcedReduction();
255
+ if (backup == null) return false;
256
+ reduce = backup;
257
+ }
258
+ this.storeNode(0, this.pos, this.pos, 4, true);
259
+ this.score -= 100;
260
+ }
261
+ this.reducePos = this.pos;
262
+ this.reduce(reduce);
263
+ return true;
264
+ }
265
+ /**
266
+ Try to scan through the automaton to find some kind of reduction
267
+ that can be applied. Used when the regular ForcedReduce field
268
+ isn't a valid action. @internal
269
+ */
270
+ findForcedReduction() {
271
+ let { parser } = this.p, seen = [];
272
+ let explore = (state, depth) => {
273
+ if (seen.includes(state)) return;
274
+ seen.push(state);
275
+ return parser.allActions(state, (action) => {
276
+ if (action & 393216);
277
+ else if (action & 65536) {
278
+ let rDepth = (action >> 19) - depth;
279
+ if (rDepth > 1) {
280
+ let term = action & 65535, target = this.stack.length - rDepth * 3;
281
+ if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0) return rDepth << 19 | 65536 | term;
282
+ }
283
+ } else {
284
+ let found = explore(action, depth + 1);
285
+ if (found != null) return found;
286
+ }
287
+ });
288
+ };
289
+ return explore(this.state, 0);
290
+ }
291
+ /**
292
+ @internal
293
+ */
294
+ forceAll() {
295
+ while (!this.p.parser.stateFlag(this.state, 2)) if (!this.forceReduce()) {
296
+ this.storeNode(0, this.pos, this.pos, 4, true);
297
+ break;
298
+ }
299
+ return this;
300
+ }
301
+ /**
302
+ Check whether this state has no further actions (assumed to be a direct descendant of the
303
+ top state, since any other states must be able to continue
304
+ somehow). @internal
305
+ */
306
+ get deadEnd() {
307
+ if (this.stack.length != 3) return false;
308
+ let { parser } = this.p;
309
+ return parser.data[parser.stateSlot(this.state, 1)] == 65535 && !parser.stateSlot(this.state, 4);
310
+ }
311
+ /**
312
+ Restart the stack (put it back in its start state). Only safe
313
+ when this.stack.length == 3 (state is directly below the top
314
+ state). @internal
315
+ */
316
+ restart() {
317
+ this.storeNode(0, this.pos, this.pos, 4, true);
318
+ this.state = this.stack[0];
319
+ this.stack.length = 0;
320
+ }
321
+ /**
322
+ @internal
323
+ */
324
+ sameState(other) {
325
+ if (this.state != other.state || this.stack.length != other.stack.length) return false;
326
+ for (let i = 0; i < this.stack.length; i += 3) if (this.stack[i] != other.stack[i]) return false;
327
+ return true;
328
+ }
329
+ /**
330
+ Get the parser used by this stack.
331
+ */
332
+ get parser() {
333
+ return this.p.parser;
334
+ }
335
+ /**
336
+ Test whether a given dialect (by numeric ID, as exported from
337
+ the terms file) is enabled.
338
+ */
339
+ dialectEnabled(dialectID) {
340
+ return this.p.parser.dialect.flags[dialectID];
341
+ }
342
+ shiftContext(term, start) {
343
+ if (this.curContext) this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
344
+ }
345
+ reduceContext(term, start) {
346
+ if (this.curContext) this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
347
+ }
348
+ /**
349
+ @internal
350
+ */
351
+ emitContext() {
352
+ let last = this.buffer.length - 1;
353
+ if (last < 0 || this.buffer[last] != -3) this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
354
+ }
355
+ /**
356
+ @internal
357
+ */
358
+ emitLookAhead() {
359
+ let last = this.buffer.length - 1;
360
+ if (last < 0 || this.buffer[last] != -4) this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
361
+ }
362
+ updateContext(context) {
363
+ if (context != this.curContext.context) {
364
+ let newCx = new StackContext(this.curContext.tracker, context);
365
+ if (newCx.hash != this.curContext.hash) this.emitContext();
366
+ this.curContext = newCx;
367
+ }
368
+ }
369
+ /**
370
+ @internal
371
+ */
372
+ setLookAhead(lookAhead) {
373
+ if (lookAhead <= this.lookAhead) return false;
374
+ this.emitLookAhead();
375
+ this.lookAhead = lookAhead;
376
+ return true;
377
+ }
378
+ /**
379
+ @internal
380
+ */
381
+ close() {
382
+ if (this.curContext && this.curContext.tracker.strict) this.emitContext();
383
+ if (this.lookAhead > 0) this.emitLookAhead();
384
+ }
385
+ };
386
+ var StackContext = class {
387
+ constructor(tracker, context) {
388
+ this.tracker = tracker;
389
+ this.context = context;
390
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
391
+ }
392
+ };
393
+ var SimulatedStack = class {
394
+ constructor(start) {
395
+ this.start = start;
396
+ this.state = start.state;
397
+ this.stack = start.stack;
398
+ this.base = this.stack.length;
399
+ }
400
+ reduce(action) {
401
+ let term = action & 65535, depth = action >> 19;
402
+ if (depth == 0) {
403
+ if (this.stack == this.start.stack) this.stack = this.stack.slice();
404
+ this.stack.push(this.state, 0, 0);
405
+ this.base += 3;
406
+ } else this.base -= (depth - 1) * 3;
407
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
408
+ this.state = goto;
409
+ }
410
+ };
411
+ var StackBufferCursor = class StackBufferCursor {
412
+ constructor(stack, pos, index) {
413
+ this.stack = stack;
414
+ this.pos = pos;
415
+ this.index = index;
416
+ this.buffer = stack.buffer;
417
+ if (this.index == 0) this.maybeNext();
418
+ }
419
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
420
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
421
+ }
422
+ maybeNext() {
423
+ let next = this.stack.parent;
424
+ if (next != null) {
425
+ this.index = this.stack.bufferBase - next.bufferBase;
426
+ this.stack = next;
427
+ this.buffer = next.buffer;
428
+ }
429
+ }
430
+ get id() {
431
+ return this.buffer[this.index - 4];
432
+ }
433
+ get start() {
434
+ return this.buffer[this.index - 3];
435
+ }
436
+ get end() {
437
+ return this.buffer[this.index - 2];
438
+ }
439
+ get size() {
440
+ return this.buffer[this.index - 1];
441
+ }
442
+ next() {
443
+ this.index -= 4;
444
+ this.pos -= 4;
445
+ if (this.index == 0) this.maybeNext();
446
+ }
447
+ fork() {
448
+ return new StackBufferCursor(this.stack, this.pos, this.index);
449
+ }
450
+ };
451
+ function decodeArray(input, Type = Uint16Array) {
452
+ if (typeof input != "string") return input;
453
+ let array = null;
454
+ for (let pos = 0, out = 0; pos < input.length;) {
455
+ let value = 0;
456
+ for (;;) {
457
+ let next = input.charCodeAt(pos++), stop = false;
458
+ if (next == 126) {
459
+ value = 65535;
460
+ break;
461
+ }
462
+ if (next >= 92) next--;
463
+ if (next >= 34) next--;
464
+ let digit = next - 32;
465
+ if (digit >= 46) {
466
+ digit -= 46;
467
+ stop = true;
468
+ }
469
+ value += digit;
470
+ if (stop) break;
471
+ value *= 46;
472
+ }
473
+ if (array) array[out++] = value;
474
+ else array = new Type(value);
475
+ }
476
+ return array;
477
+ }
478
+ var CachedToken = class {
479
+ constructor() {
480
+ this.start = -1;
481
+ this.value = -1;
482
+ this.end = -1;
483
+ this.extended = -1;
484
+ this.lookAhead = 0;
485
+ this.mask = 0;
486
+ this.context = 0;
487
+ }
488
+ };
489
+ const nullToken = new CachedToken();
490
+ /**
491
+ [Tokenizers](#lr.ExternalTokenizer) interact with the input
492
+ through this interface. It presents the input as a stream of
493
+ characters, tracking lookahead and hiding the complexity of
494
+ [ranges](#common.Parser.parse^ranges) from tokenizer code.
495
+ */
496
+ var InputStream = class {
497
+ /**
498
+ @internal
499
+ */
500
+ constructor(input, ranges) {
501
+ this.input = input;
502
+ this.ranges = ranges;
503
+ /**
504
+ @internal
505
+ */
506
+ this.chunk = "";
507
+ /**
508
+ @internal
509
+ */
510
+ this.chunkOff = 0;
511
+ /**
512
+ Backup chunk
513
+ */
514
+ this.chunk2 = "";
515
+ this.chunk2Pos = 0;
516
+ /**
517
+ The character code of the next code unit in the input, or -1
518
+ when the stream is at the end of the input.
519
+ */
520
+ this.next = -1;
521
+ /**
522
+ @internal
523
+ */
524
+ this.token = nullToken;
525
+ this.rangeIndex = 0;
526
+ this.pos = this.chunkPos = ranges[0].from;
527
+ this.range = ranges[0];
528
+ this.end = ranges[ranges.length - 1].to;
529
+ this.readNext();
530
+ }
531
+ /**
532
+ @internal
533
+ */
534
+ resolveOffset(offset, assoc) {
535
+ let range = this.range, index = this.rangeIndex;
536
+ let pos = this.pos + offset;
537
+ while (pos < range.from) {
538
+ if (!index) return null;
539
+ let next = this.ranges[--index];
540
+ pos -= range.from - next.to;
541
+ range = next;
542
+ }
543
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
544
+ if (index == this.ranges.length - 1) return null;
545
+ let next = this.ranges[++index];
546
+ pos += next.from - range.to;
547
+ range = next;
548
+ }
549
+ return pos;
550
+ }
551
+ /**
552
+ @internal
553
+ */
554
+ clipPos(pos) {
555
+ if (pos >= this.range.from && pos < this.range.to) return pos;
556
+ for (let range of this.ranges) if (range.to > pos) return Math.max(pos, range.from);
557
+ return this.end;
558
+ }
559
+ /**
560
+ Look at a code unit near the stream position. `.peek(0)` equals
561
+ `.next`, `.peek(-1)` gives you the previous character, and so
562
+ on.
563
+
564
+ Note that looking around during tokenizing creates dependencies
565
+ on potentially far-away content, which may reduce the
566
+ effectiveness incremental parsing—when looking forward—or even
567
+ cause invalid reparses when looking backward more than 25 code
568
+ units, since the library does not track lookbehind.
569
+ */
570
+ peek(offset) {
571
+ let idx = this.chunkOff + offset, pos, result;
572
+ if (idx >= 0 && idx < this.chunk.length) {
573
+ pos = this.pos + offset;
574
+ result = this.chunk.charCodeAt(idx);
575
+ } else {
576
+ let resolved = this.resolveOffset(offset, 1);
577
+ if (resolved == null) return -1;
578
+ pos = resolved;
579
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
580
+ else {
581
+ let i = this.rangeIndex, range = this.range;
582
+ while (range.to <= pos) range = this.ranges[++i];
583
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
584
+ if (pos + this.chunk2.length > range.to) this.chunk2 = this.chunk2.slice(0, range.to - pos);
585
+ result = this.chunk2.charCodeAt(0);
586
+ }
587
+ }
588
+ if (pos >= this.token.lookAhead) this.token.lookAhead = pos + 1;
589
+ return result;
590
+ }
591
+ /**
592
+ Accept a token. By default, the end of the token is set to the
593
+ current stream position, but you can pass an offset (relative to
594
+ the stream position) to change that.
595
+ */
596
+ acceptToken(token, endOffset = 0) {
597
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
598
+ if (end == null || end < this.token.start) throw new RangeError("Token end out of bounds");
599
+ this.token.value = token;
600
+ this.token.end = end;
601
+ }
602
+ /**
603
+ Accept a token ending at a specific given position.
604
+ */
605
+ acceptTokenTo(token, endPos) {
606
+ this.token.value = token;
607
+ this.token.end = endPos;
608
+ }
609
+ getChunk() {
610
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
611
+ let { chunk, chunkPos } = this;
612
+ this.chunk = this.chunk2;
613
+ this.chunkPos = this.chunk2Pos;
614
+ this.chunk2 = chunk;
615
+ this.chunk2Pos = chunkPos;
616
+ this.chunkOff = this.pos - this.chunkPos;
617
+ } else {
618
+ this.chunk2 = this.chunk;
619
+ this.chunk2Pos = this.chunkPos;
620
+ let nextChunk = this.input.chunk(this.pos);
621
+ let end = this.pos + nextChunk.length;
622
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
623
+ this.chunkPos = this.pos;
624
+ this.chunkOff = 0;
625
+ }
626
+ }
627
+ readNext() {
628
+ if (this.chunkOff >= this.chunk.length) {
629
+ this.getChunk();
630
+ if (this.chunkOff == this.chunk.length) return this.next = -1;
631
+ }
632
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
633
+ }
634
+ /**
635
+ Move the stream forward N (defaults to 1) code units. Returns
636
+ the new value of [`next`](#lr.InputStream.next).
637
+ */
638
+ advance(n = 1) {
639
+ this.chunkOff += n;
640
+ while (this.pos + n >= this.range.to) {
641
+ if (this.rangeIndex == this.ranges.length - 1) return this.setDone();
642
+ n -= this.range.to - this.pos;
643
+ this.range = this.ranges[++this.rangeIndex];
644
+ this.pos = this.range.from;
645
+ }
646
+ this.pos += n;
647
+ if (this.pos >= this.token.lookAhead) this.token.lookAhead = this.pos + 1;
648
+ return this.readNext();
649
+ }
650
+ setDone() {
651
+ this.pos = this.chunkPos = this.end;
652
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
653
+ this.chunk = "";
654
+ return this.next = -1;
655
+ }
656
+ /**
657
+ @internal
658
+ */
659
+ reset(pos, token) {
660
+ if (token) {
661
+ this.token = token;
662
+ token.start = pos;
663
+ token.lookAhead = pos + 1;
664
+ token.value = token.extended = -1;
665
+ } else this.token = nullToken;
666
+ if (this.pos != pos) {
667
+ this.pos = pos;
668
+ if (pos == this.end) {
669
+ this.setDone();
670
+ return this;
671
+ }
672
+ while (pos < this.range.from) this.range = this.ranges[--this.rangeIndex];
673
+ while (pos >= this.range.to) this.range = this.ranges[++this.rangeIndex];
674
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) this.chunkOff = pos - this.chunkPos;
675
+ else {
676
+ this.chunk = "";
677
+ this.chunkOff = 0;
678
+ }
679
+ this.readNext();
680
+ }
681
+ return this;
682
+ }
683
+ /**
684
+ @internal
685
+ */
686
+ read(from, to) {
687
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length) return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
688
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length) return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
689
+ if (from >= this.range.from && to <= this.range.to) return this.input.read(from, to);
690
+ let result = "";
691
+ for (let r of this.ranges) {
692
+ if (r.from >= to) break;
693
+ if (r.to > from) result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
694
+ }
695
+ return result;
696
+ }
697
+ };
698
+ /**
699
+ @internal
700
+ */
701
+ var TokenGroup = class {
702
+ constructor(data, id) {
703
+ this.data = data;
704
+ this.id = id;
705
+ }
706
+ token(input, stack) {
707
+ let { parser } = stack.p;
708
+ readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable);
709
+ }
710
+ };
711
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
712
+ /**
713
+ @hide
714
+ */
715
+ var LocalTokenGroup = class {
716
+ constructor(data, precTable, elseToken) {
717
+ this.precTable = precTable;
718
+ this.elseToken = elseToken;
719
+ this.data = typeof data == "string" ? decodeArray(data) : data;
720
+ }
721
+ token(input, stack) {
722
+ let start = input.pos, skipped = 0;
723
+ for (;;) {
724
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
725
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
726
+ if (input.token.value > -1) break;
727
+ if (this.elseToken == null) return;
728
+ if (!atEof) skipped++;
729
+ if (nextPos == null) break;
730
+ input.reset(nextPos, input.token);
731
+ }
732
+ if (skipped) {
733
+ input.reset(start, input.token);
734
+ input.acceptToken(this.elseToken, skipped);
735
+ }
736
+ }
737
+ };
738
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
739
+ /**
740
+ `@external tokens` declarations in the grammar should resolve to
741
+ an instance of this class.
742
+ */
743
+ var ExternalTokenizer = class {
744
+ /**
745
+ Create a tokenizer. The first argument is the function that,
746
+ given an input stream, scans for the types of tokens it
747
+ recognizes at the stream's position, and calls
748
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
749
+ one.
750
+ */
751
+ constructor(token, options = {}) {
752
+ this.token = token;
753
+ this.contextual = !!options.contextual;
754
+ this.fallback = !!options.fallback;
755
+ this.extend = !!options.extend;
756
+ }
757
+ };
758
+ function readToken(data, input, stack, group, precTable, precOffset) {
759
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
760
+ scan: for (;;) {
761
+ if ((groupMask & data[state]) == 0) break;
762
+ let accEnd = data[state + 1];
763
+ for (let i = state + 3; i < accEnd; i += 2) if ((data[i + 1] & groupMask) > 0) {
764
+ let term = data[i];
765
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
766
+ input.acceptToken(term);
767
+ break;
768
+ }
769
+ }
770
+ let next = input.next, low = 0, high = data[state + 2];
771
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
772
+ state = data[accEnd + high * 3 - 1];
773
+ continue scan;
774
+ }
775
+ for (; low < high;) {
776
+ let mid = low + high >> 1;
777
+ let index = accEnd + mid + (mid << 1);
778
+ let from = data[index], to = data[index + 1] || 65536;
779
+ if (next < from) high = mid;
780
+ else if (next >= to) low = mid + 1;
781
+ else {
782
+ state = data[index + 2];
783
+ input.advance();
784
+ continue scan;
785
+ }
786
+ }
787
+ break;
788
+ }
789
+ }
790
+ function findOffset(data, start, term) {
791
+ for (let i = start, next; (next = data[i]) != 65535; i++) if (next == term) return i - start;
792
+ return -1;
793
+ }
794
+ function overrides(token, prev, tableData, tableOffset) {
795
+ let iPrev = findOffset(tableData, tableOffset, prev);
796
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
797
+ }
798
+ const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
799
+ let stackIDs = null;
800
+ function cutAt(tree, pos, side) {
801
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
802
+ cursor.moveTo(pos);
803
+ for (;;) if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos))) for (;;) {
804
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError) return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 25)) : Math.min(tree.length, Math.max(cursor.from + 1, pos + 25));
805
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling()) break;
806
+ if (!cursor.parent()) return side < 0 ? 0 : tree.length;
807
+ }
808
+ }
809
+ var FragmentCursor = class {
810
+ constructor(fragments, nodeSet) {
811
+ this.fragments = fragments;
812
+ this.nodeSet = nodeSet;
813
+ this.i = 0;
814
+ this.fragment = null;
815
+ this.safeFrom = -1;
816
+ this.safeTo = -1;
817
+ this.trees = [];
818
+ this.start = [];
819
+ this.index = [];
820
+ this.nextFragment();
821
+ }
822
+ nextFragment() {
823
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
824
+ if (fr) {
825
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
826
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
827
+ while (this.trees.length) {
828
+ this.trees.pop();
829
+ this.start.pop();
830
+ this.index.pop();
831
+ }
832
+ this.trees.push(fr.tree);
833
+ this.start.push(-fr.offset);
834
+ this.index.push(0);
835
+ this.nextStart = this.safeFrom;
836
+ } else this.nextStart = 1e9;
837
+ }
838
+ nodeAt(pos) {
839
+ if (pos < this.nextStart) return null;
840
+ while (this.fragment && this.safeTo <= pos) this.nextFragment();
841
+ if (!this.fragment) return null;
842
+ for (;;) {
843
+ let last = this.trees.length - 1;
844
+ if (last < 0) {
845
+ this.nextFragment();
846
+ return null;
847
+ }
848
+ let top = this.trees[last], index = this.index[last];
849
+ if (index == top.children.length) {
850
+ this.trees.pop();
851
+ this.start.pop();
852
+ this.index.pop();
853
+ continue;
854
+ }
855
+ let next = top.children[index];
856
+ let start = this.start[last] + top.positions[index];
857
+ if (start > pos) {
858
+ this.nextStart = start;
859
+ return null;
860
+ }
861
+ if (next instanceof Tree) {
862
+ if (start == pos) {
863
+ if (start < this.safeFrom) return null;
864
+ let end = start + next.length;
865
+ if (end <= this.safeTo) {
866
+ let lookAhead = next.prop(NodeProp.lookAhead);
867
+ if (!lookAhead || end + lookAhead < this.fragment.to) return next;
868
+ }
869
+ }
870
+ this.index[last]++;
871
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
872
+ this.trees.push(next);
873
+ this.start.push(start);
874
+ this.index.push(0);
875
+ }
876
+ } else {
877
+ this.index[last]++;
878
+ this.nextStart = start + next.length;
879
+ }
880
+ }
881
+ }
882
+ };
883
+ var TokenCache = class {
884
+ constructor(parser, stream) {
885
+ this.stream = stream;
886
+ this.tokens = [];
887
+ this.mainToken = null;
888
+ this.actions = [];
889
+ this.tokens = parser.tokenizers.map((_) => new CachedToken());
890
+ }
891
+ getActions(stack) {
892
+ let actionIndex = 0;
893
+ let main = null;
894
+ let { parser } = stack.p, { tokenizers } = parser;
895
+ let mask = parser.stateSlot(stack.state, 3);
896
+ let context = stack.curContext ? stack.curContext.hash : 0;
897
+ let lookAhead = 0;
898
+ for (let i = 0; i < tokenizers.length; i++) {
899
+ if ((1 << i & mask) == 0) continue;
900
+ let tokenizer = tokenizers[i], token = this.tokens[i];
901
+ if (main && !tokenizer.fallback) continue;
902
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
903
+ this.updateCachedToken(token, tokenizer, stack);
904
+ token.mask = mask;
905
+ token.context = context;
906
+ }
907
+ if (token.lookAhead > token.end + 25) lookAhead = Math.max(token.lookAhead, lookAhead);
908
+ if (token.value != 0) {
909
+ let startIndex = actionIndex;
910
+ if (token.extended > -1) actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
911
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
912
+ if (!tokenizer.extend) {
913
+ main = token;
914
+ if (actionIndex > startIndex) break;
915
+ }
916
+ }
917
+ }
918
+ while (this.actions.length > actionIndex) this.actions.pop();
919
+ if (lookAhead) stack.setLookAhead(lookAhead);
920
+ if (!main && stack.pos == this.stream.end) {
921
+ main = new CachedToken();
922
+ main.value = stack.p.parser.eofTerm;
923
+ main.start = main.end = stack.pos;
924
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
925
+ }
926
+ this.mainToken = main;
927
+ return this.actions;
928
+ }
929
+ getMainToken(stack) {
930
+ if (this.mainToken) return this.mainToken;
931
+ let main = new CachedToken(), { pos, p } = stack;
932
+ main.start = pos;
933
+ main.end = Math.min(pos + 1, p.stream.end);
934
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
935
+ return main;
936
+ }
937
+ updateCachedToken(token, tokenizer, stack) {
938
+ let start = this.stream.clipPos(stack.pos);
939
+ tokenizer.token(this.stream.reset(start, token), stack);
940
+ if (token.value > -1) {
941
+ let { parser } = stack.p;
942
+ for (let i = 0; i < parser.specialized.length; i++) if (parser.specialized[i] == token.value) {
943
+ let result = parser.specializers[i](this.stream.read(token.start, token.end), stack);
944
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
945
+ if ((result & 1) == 0) token.value = result >> 1;
946
+ else token.extended = result >> 1;
947
+ break;
948
+ }
949
+ }
950
+ } else {
951
+ token.value = 0;
952
+ token.end = this.stream.clipPos(start + 1);
953
+ }
954
+ }
955
+ putAction(action, token, end, index) {
956
+ for (let i = 0; i < index; i += 3) if (this.actions[i] == action) return index;
957
+ this.actions[index++] = action;
958
+ this.actions[index++] = token;
959
+ this.actions[index++] = end;
960
+ return index;
961
+ }
962
+ addActions(stack, token, end, index) {
963
+ let { state } = stack, { parser } = stack.p, { data } = parser;
964
+ for (let set = 0; set < 2; set++) for (let i = parser.stateSlot(state, set ? 2 : 1);; i += 3) {
965
+ if (data[i] == 65535) if (data[i + 1] == 1) i = pair(data, i + 2);
966
+ else {
967
+ if (index == 0 && data[i + 1] == 2) index = this.putAction(pair(data, i + 2), token, end, index);
968
+ break;
969
+ }
970
+ if (data[i] == token) index = this.putAction(pair(data, i + 1), token, end, index);
971
+ }
972
+ return index;
973
+ }
974
+ };
975
+ var Parse = class {
976
+ constructor(parser, input, fragments, ranges) {
977
+ this.parser = parser;
978
+ this.input = input;
979
+ this.ranges = ranges;
980
+ this.recovering = 0;
981
+ this.nextStackID = 9812;
982
+ this.minStackPos = 0;
983
+ this.reused = [];
984
+ this.stoppedAt = null;
985
+ this.lastBigReductionStart = -1;
986
+ this.lastBigReductionSize = 0;
987
+ this.bigReductionCount = 0;
988
+ this.stream = new InputStream(input, ranges);
989
+ this.tokens = new TokenCache(parser, this.stream);
990
+ this.topTerm = parser.top[1];
991
+ let { from } = ranges[0];
992
+ this.stacks = [Stack.start(this, parser.top[0], from)];
993
+ this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 ? new FragmentCursor(fragments, parser.nodeSet) : null;
994
+ }
995
+ get parsedPos() {
996
+ return this.minStackPos;
997
+ }
998
+ advance() {
999
+ let stacks = this.stacks, pos = this.minStackPos;
1000
+ let newStacks = this.stacks = [];
1001
+ let stopped, stoppedTokens;
1002
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
1003
+ let [s] = stacks;
1004
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart);
1005
+ this.bigReductionCount = this.lastBigReductionSize = 0;
1006
+ }
1007
+ for (let i = 0; i < stacks.length; i++) {
1008
+ let stack = stacks[i];
1009
+ for (;;) {
1010
+ this.tokens.mainToken = null;
1011
+ if (stack.pos > pos) newStacks.push(stack);
1012
+ else if (this.advanceStack(stack, newStacks, stacks)) continue;
1013
+ else {
1014
+ if (!stopped) {
1015
+ stopped = [];
1016
+ stoppedTokens = [];
1017
+ }
1018
+ stopped.push(stack);
1019
+ let tok = this.tokens.getMainToken(stack);
1020
+ stoppedTokens.push(tok.value, tok.end);
1021
+ }
1022
+ break;
1023
+ }
1024
+ }
1025
+ if (!newStacks.length) {
1026
+ let finished = stopped && findFinished(stopped);
1027
+ if (finished) {
1028
+ if (verbose) console.log("Finish with " + this.stackID(finished));
1029
+ return this.stackToTree(finished);
1030
+ }
1031
+ if (this.parser.strict) {
1032
+ if (verbose && stopped) console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
1033
+ throw new SyntaxError("No parse at " + pos);
1034
+ }
1035
+ if (!this.recovering) this.recovering = 5;
1036
+ }
1037
+ if (this.recovering && stopped) {
1038
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
1039
+ if (finished) {
1040
+ if (verbose) console.log("Force-finish " + this.stackID(finished));
1041
+ return this.stackToTree(finished.forceAll());
1042
+ }
1043
+ }
1044
+ if (this.recovering) {
1045
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
1046
+ if (newStacks.length > maxRemaining) {
1047
+ newStacks.sort((a, b) => b.score - a.score);
1048
+ while (newStacks.length > maxRemaining) newStacks.pop();
1049
+ }
1050
+ if (newStacks.some((s) => s.reducePos > pos)) this.recovering--;
1051
+ } else if (newStacks.length > 1) {
1052
+ outer: for (let i = 0; i < newStacks.length - 1; i++) {
1053
+ let stack = newStacks[i];
1054
+ for (let j = i + 1; j < newStacks.length; j++) {
1055
+ let other = newStacks[j];
1056
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) newStacks.splice(j--, 1);
1057
+ else {
1058
+ newStacks.splice(i--, 1);
1059
+ continue outer;
1060
+ }
1061
+ }
1062
+ }
1063
+ if (newStacks.length > 12) {
1064
+ newStacks.sort((a, b) => b.score - a.score);
1065
+ newStacks.splice(12, newStacks.length - 12);
1066
+ }
1067
+ }
1068
+ this.minStackPos = newStacks[0].pos;
1069
+ for (let i = 1; i < newStacks.length; i++) if (newStacks[i].pos < this.minStackPos) this.minStackPos = newStacks[i].pos;
1070
+ return null;
1071
+ }
1072
+ stopAt(pos) {
1073
+ if (this.stoppedAt != null && this.stoppedAt < pos) throw new RangeError("Can't move stoppedAt forward");
1074
+ this.stoppedAt = pos;
1075
+ }
1076
+ advanceStack(stack, stacks, split) {
1077
+ let start = stack.pos, { parser } = this;
1078
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1079
+ if (this.stoppedAt != null && start > this.stoppedAt) return stack.forceReduce() ? stack : null;
1080
+ if (this.fragments) {
1081
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
1082
+ for (let cached = this.fragments.nodeAt(start); cached;) {
1083
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
1084
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
1085
+ stack.useNode(cached, match);
1086
+ if (verbose) console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
1087
+ return true;
1088
+ }
1089
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0) break;
1090
+ let inner = cached.children[0];
1091
+ if (inner instanceof Tree && cached.positions[0] == 0) cached = inner;
1092
+ else break;
1093
+ }
1094
+ }
1095
+ let defaultReduce = parser.stateSlot(stack.state, 4);
1096
+ if (defaultReduce > 0) {
1097
+ stack.reduce(defaultReduce);
1098
+ if (verbose) console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535)})`);
1099
+ return true;
1100
+ }
1101
+ if (stack.stack.length >= 8400) while (stack.stack.length > 6e3 && stack.forceReduce());
1102
+ let actions = this.tokens.getActions(stack);
1103
+ for (let i = 0; i < actions.length;) {
1104
+ let action = actions[i++], term = actions[i++], end = actions[i++];
1105
+ let last = i == actions.length || !split;
1106
+ let localStack = last ? stack : stack.split();
1107
+ let main = this.tokens.mainToken;
1108
+ localStack.apply(action, term, main ? main.start : localStack.pos, end);
1109
+ if (verbose) console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser.getName(action & 65535)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
1110
+ if (last) return true;
1111
+ else if (localStack.pos > start) stacks.push(localStack);
1112
+ else split.push(localStack);
1113
+ }
1114
+ return false;
1115
+ }
1116
+ advanceFully(stack, newStacks) {
1117
+ let pos = stack.pos;
1118
+ for (;;) {
1119
+ if (!this.advanceStack(stack, null, null)) return false;
1120
+ if (stack.pos > pos) {
1121
+ pushStackDedup(stack, newStacks);
1122
+ return true;
1123
+ }
1124
+ }
1125
+ }
1126
+ runRecovery(stacks, tokens, newStacks) {
1127
+ let finished = null, restarted = false;
1128
+ for (let i = 0; i < stacks.length; i++) {
1129
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
1130
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1131
+ if (stack.deadEnd) {
1132
+ if (restarted) continue;
1133
+ restarted = true;
1134
+ stack.restart();
1135
+ if (verbose) console.log(base + this.stackID(stack) + " (restarted)");
1136
+ if (this.advanceFully(stack, newStacks)) continue;
1137
+ }
1138
+ let force = stack.split(), forceBase = base;
1139
+ for (let j = 0; j < 10 && force.forceReduce(); j++) {
1140
+ if (verbose) console.log(forceBase + this.stackID(force) + " (via force-reduce)");
1141
+ if (this.advanceFully(force, newStacks)) break;
1142
+ if (verbose) forceBase = this.stackID(force) + " -> ";
1143
+ }
1144
+ for (let insert of stack.recoverByInsert(token)) {
1145
+ if (verbose) console.log(base + this.stackID(insert) + " (via recover-insert)");
1146
+ this.advanceFully(insert, newStacks);
1147
+ }
1148
+ if (this.stream.end > stack.pos) {
1149
+ if (tokenEnd == stack.pos) {
1150
+ tokenEnd++;
1151
+ token = 0;
1152
+ }
1153
+ stack.recoverByDelete(token, tokenEnd);
1154
+ if (verbose) console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
1155
+ pushStackDedup(stack, newStacks);
1156
+ } else if (!finished || finished.score < force.score) finished = force;
1157
+ }
1158
+ return finished;
1159
+ }
1160
+ stackToTree(stack) {
1161
+ stack.close();
1162
+ return Tree.build({
1163
+ buffer: StackBufferCursor.create(stack),
1164
+ nodeSet: this.parser.nodeSet,
1165
+ topID: this.topTerm,
1166
+ maxBufferLength: this.parser.bufferLength,
1167
+ reused: this.reused,
1168
+ start: this.ranges[0].from,
1169
+ length: stack.pos - this.ranges[0].from,
1170
+ minRepeatType: this.parser.minRepeatTerm
1171
+ });
1172
+ }
1173
+ stackID(stack) {
1174
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
1175
+ if (!id) stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
1176
+ return id + stack;
1177
+ }
1178
+ };
1179
+ function pushStackDedup(stack, newStacks) {
1180
+ for (let i = 0; i < newStacks.length; i++) {
1181
+ let other = newStacks[i];
1182
+ if (other.pos == stack.pos && other.sameState(stack)) {
1183
+ if (newStacks[i].score < stack.score) newStacks[i] = stack;
1184
+ return;
1185
+ }
1186
+ }
1187
+ newStacks.push(stack);
1188
+ }
1189
+ var Dialect = class {
1190
+ constructor(source, flags, disabled) {
1191
+ this.source = source;
1192
+ this.flags = flags;
1193
+ this.disabled = disabled;
1194
+ }
1195
+ allows(term) {
1196
+ return !this.disabled || this.disabled[term] == 0;
1197
+ }
1198
+ };
1199
+ const id = (x) => x;
1200
+ /**
1201
+ Context trackers are used to track stateful context (such as
1202
+ indentation in the Python grammar, or parent elements in the XML
1203
+ grammar) needed by external tokenizers. You declare them in a
1204
+ grammar file as `@context exportName from "module"`.
1205
+
1206
+ Context values should be immutable, and can be updated (replaced)
1207
+ on shift or reduce actions.
1208
+
1209
+ The export used in a `@context` declaration should be of this
1210
+ type.
1211
+ */
1212
+ var ContextTracker = class {
1213
+ /**
1214
+ Define a context tracker.
1215
+ */
1216
+ constructor(spec) {
1217
+ this.start = spec.start;
1218
+ this.shift = spec.shift || id;
1219
+ this.reduce = spec.reduce || id;
1220
+ this.reuse = spec.reuse || id;
1221
+ this.hash = spec.hash || (() => 0);
1222
+ this.strict = spec.strict !== false;
1223
+ }
1224
+ };
1225
+ /**
1226
+ Holds the parse tables for a given grammar, as generated by
1227
+ `lezer-generator`, and provides [methods](#common.Parser) to parse
1228
+ content with.
1229
+ */
1230
+ var LRParser = class LRParser extends Parser {
1231
+ /**
1232
+ @internal
1233
+ */
1234
+ constructor(spec) {
1235
+ super();
1236
+ /**
1237
+ @internal
1238
+ */
1239
+ this.wrappers = [];
1240
+ if (spec.version != 14) throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (14)`);
1241
+ let nodeNames = spec.nodeNames.split(" ");
1242
+ this.minRepeatTerm = nodeNames.length;
1243
+ for (let i = 0; i < spec.repeatNodeCount; i++) nodeNames.push("");
1244
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
1245
+ let nodeProps = [];
1246
+ for (let i = 0; i < nodeNames.length; i++) nodeProps.push([]);
1247
+ function setProp(nodeID, prop, value) {
1248
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
1249
+ }
1250
+ if (spec.nodeProps) for (let propSpec of spec.nodeProps) {
1251
+ let prop = propSpec[0];
1252
+ if (typeof prop == "string") prop = NodeProp[prop];
1253
+ for (let i = 1; i < propSpec.length;) {
1254
+ let next = propSpec[i++];
1255
+ if (next >= 0) setProp(next, prop, propSpec[i++]);
1256
+ else {
1257
+ let value = propSpec[i + -next];
1258
+ for (let j = -next; j > 0; j--) setProp(propSpec[i++], prop, value);
1259
+ i++;
1260
+ }
1261
+ }
1262
+ }
1263
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
1264
+ name: i >= this.minRepeatTerm ? void 0 : name,
1265
+ id: i,
1266
+ props: nodeProps[i],
1267
+ top: topTerms.indexOf(i) > -1,
1268
+ error: i == 0,
1269
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
1270
+ })));
1271
+ if (spec.propSources) this.nodeSet = this.nodeSet.extend(...spec.propSources);
1272
+ this.strict = false;
1273
+ this.bufferLength = DefaultBufferLength;
1274
+ let tokenArray = decodeArray(spec.tokenData);
1275
+ this.context = spec.context;
1276
+ this.specializerSpecs = spec.specialized || [];
1277
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
1278
+ for (let i = 0; i < this.specializerSpecs.length; i++) this.specialized[i] = this.specializerSpecs[i].term;
1279
+ this.specializers = this.specializerSpecs.map(getSpecializer);
1280
+ this.states = decodeArray(spec.states, Uint32Array);
1281
+ this.data = decodeArray(spec.stateData);
1282
+ this.goto = decodeArray(spec.goto);
1283
+ this.maxTerm = spec.maxTerm;
1284
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
1285
+ this.topRules = spec.topRules;
1286
+ this.dialects = spec.dialects || {};
1287
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
1288
+ this.tokenPrecTable = spec.tokenPrec;
1289
+ this.termNames = spec.termNames || null;
1290
+ this.maxNode = this.nodeSet.types.length - 1;
1291
+ this.dialect = this.parseDialect();
1292
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
1293
+ }
1294
+ createParse(input, fragments, ranges) {
1295
+ let parse = new Parse(this, input, fragments, ranges);
1296
+ for (let w of this.wrappers) parse = w(parse, input, fragments, ranges);
1297
+ return parse;
1298
+ }
1299
+ /**
1300
+ Get a goto table entry @internal
1301
+ */
1302
+ getGoto(state, term, loose = false) {
1303
+ let table = this.goto;
1304
+ if (term >= table[0]) return -1;
1305
+ for (let pos = table[term + 1];;) {
1306
+ let groupTag = table[pos++], last = groupTag & 1;
1307
+ let target = table[pos++];
1308
+ if (last && loose) return target;
1309
+ for (let end = pos + (groupTag >> 1); pos < end; pos++) if (table[pos] == state) return target;
1310
+ if (last) return -1;
1311
+ }
1312
+ }
1313
+ /**
1314
+ Check if this state has an action for a given terminal @internal
1315
+ */
1316
+ hasAction(state, terminal) {
1317
+ let data = this.data;
1318
+ for (let set = 0; set < 2; set++) for (let i = this.stateSlot(state, set ? 2 : 1), next;; i += 3) {
1319
+ if ((next = data[i]) == 65535) if (data[i + 1] == 1) next = data[i = pair(data, i + 2)];
1320
+ else if (data[i + 1] == 2) return pair(data, i + 2);
1321
+ else break;
1322
+ if (next == terminal || next == 0) return pair(data, i + 1);
1323
+ }
1324
+ return 0;
1325
+ }
1326
+ /**
1327
+ @internal
1328
+ */
1329
+ stateSlot(state, slot) {
1330
+ return this.states[state * 6 + slot];
1331
+ }
1332
+ /**
1333
+ @internal
1334
+ */
1335
+ stateFlag(state, flag) {
1336
+ return (this.stateSlot(state, 0) & flag) > 0;
1337
+ }
1338
+ /**
1339
+ @internal
1340
+ */
1341
+ validAction(state, action) {
1342
+ return !!this.allActions(state, (a) => a == action ? true : null);
1343
+ }
1344
+ /**
1345
+ @internal
1346
+ */
1347
+ allActions(state, action) {
1348
+ let deflt = this.stateSlot(state, 4);
1349
+ let result = deflt ? action(deflt) : void 0;
1350
+ for (let i = this.stateSlot(state, 1); result == null; i += 3) {
1351
+ if (this.data[i] == 65535) if (this.data[i + 1] == 1) i = pair(this.data, i + 2);
1352
+ else break;
1353
+ result = action(pair(this.data, i + 1));
1354
+ }
1355
+ return result;
1356
+ }
1357
+ /**
1358
+ Get the states that can follow this one through shift actions or
1359
+ goto jumps. @internal
1360
+ */
1361
+ nextStates(state) {
1362
+ let result = [];
1363
+ for (let i = this.stateSlot(state, 1);; i += 3) {
1364
+ if (this.data[i] == 65535) if (this.data[i + 1] == 1) i = pair(this.data, i + 2);
1365
+ else break;
1366
+ if ((this.data[i + 2] & 1) == 0) {
1367
+ let value = this.data[i + 1];
1368
+ if (!result.some((v, i) => i & 1 && v == value)) result.push(this.data[i], value);
1369
+ }
1370
+ }
1371
+ return result;
1372
+ }
1373
+ /**
1374
+ Configure the parser. Returns a new parser instance that has the
1375
+ given settings modified. Settings not provided in `config` are
1376
+ kept from the original parser.
1377
+ */
1378
+ configure(config) {
1379
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
1380
+ if (config.props) copy.nodeSet = this.nodeSet.extend(...config.props);
1381
+ if (config.top) {
1382
+ let info = this.topRules[config.top];
1383
+ if (!info) throw new RangeError(`Invalid top rule name ${config.top}`);
1384
+ copy.top = info;
1385
+ }
1386
+ if (config.tokenizers) copy.tokenizers = this.tokenizers.map((t) => {
1387
+ let found = config.tokenizers.find((r) => r.from == t);
1388
+ return found ? found.to : t;
1389
+ });
1390
+ if (config.specializers) {
1391
+ copy.specializers = this.specializers.slice();
1392
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
1393
+ let found = config.specializers.find((r) => r.from == s.external);
1394
+ if (!found) return s;
1395
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
1396
+ copy.specializers[i] = getSpecializer(spec);
1397
+ return spec;
1398
+ });
1399
+ }
1400
+ if (config.contextTracker) copy.context = config.contextTracker;
1401
+ if (config.dialect) copy.dialect = this.parseDialect(config.dialect);
1402
+ if (config.strict != null) copy.strict = config.strict;
1403
+ if (config.wrap) copy.wrappers = copy.wrappers.concat(config.wrap);
1404
+ if (config.bufferLength != null) copy.bufferLength = config.bufferLength;
1405
+ return copy;
1406
+ }
1407
+ /**
1408
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1409
+ are registered for this parser.
1410
+ */
1411
+ hasWrappers() {
1412
+ return this.wrappers.length > 0;
1413
+ }
1414
+ /**
1415
+ Returns the name associated with a given term. This will only
1416
+ work for all terms when the parser was generated with the
1417
+ `--names` option. By default, only the names of tagged terms are
1418
+ stored.
1419
+ */
1420
+ getName(term) {
1421
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
1422
+ }
1423
+ /**
1424
+ The eof term id is always allocated directly after the node
1425
+ types. @internal
1426
+ */
1427
+ get eofTerm() {
1428
+ return this.maxNode + 1;
1429
+ }
1430
+ /**
1431
+ The type of top node produced by the parser.
1432
+ */
1433
+ get topNode() {
1434
+ return this.nodeSet.types[this.top[1]];
1435
+ }
1436
+ /**
1437
+ @internal
1438
+ */
1439
+ dynamicPrecedence(term) {
1440
+ let prec = this.dynamicPrecedences;
1441
+ return prec == null ? 0 : prec[term] || 0;
1442
+ }
1443
+ /**
1444
+ @internal
1445
+ */
1446
+ parseDialect(dialect) {
1447
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
1448
+ if (dialect) for (let part of dialect.split(" ")) {
1449
+ let id = values.indexOf(part);
1450
+ if (id >= 0) flags[id] = true;
1451
+ }
1452
+ let disabled = null;
1453
+ for (let i = 0; i < values.length; i++) if (!flags[i]) for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535;) (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
1454
+ return new Dialect(dialect, flags, disabled);
1455
+ }
1456
+ /**
1457
+ Used by the output of the parser generator. Not available to
1458
+ user code. @hide
1459
+ */
1460
+ static deserialize(spec) {
1461
+ return new LRParser(spec);
1462
+ }
1463
+ };
1464
+ function pair(data, off) {
1465
+ return data[off] | data[off + 1] << 16;
1466
+ }
1467
+ function findFinished(stacks) {
1468
+ let best = null;
1469
+ for (let stack of stacks) {
1470
+ let stopped = stack.p.stoppedAt;
1471
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(stack.state, 2) && (!best || best.score < stack.score)) best = stack;
1472
+ }
1473
+ return best;
1474
+ }
1475
+ function getSpecializer(spec) {
1476
+ if (spec.external) {
1477
+ let mask = spec.extend ? 1 : 0;
1478
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
1479
+ }
1480
+ return spec.get;
1481
+ }
1482
+ //#endregion
1483
+ export { ContextTracker, ExternalTokenizer, LRParser, LocalTokenGroup };
1484
+
1485
+ //# sourceMappingURL=index.js.map