@apipass/design-system 3.3.0 → 4.0.0

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