@vuu-ui/vuu-datatable 0.8.17-debug → 0.8.18-debug

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.
package/esm/index.js CHANGED
@@ -1,7 +1,34 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+ var __privateWrapper = (obj, member, setter, getter) => ({
20
+ set _(value) {
21
+ __privateSet(obj, member, value, setter);
22
+ },
23
+ get _() {
24
+ return __privateGet(obj, member, getter);
25
+ }
26
+ });
27
+
1
28
  // src/filter-table/FilterTable.tsx
2
29
  import { FilterBar } from "@vuu-ui/vuu-filters";
3
30
  import { Table } from "@vuu-ui/vuu-table";
4
- import cx from "classnames";
31
+ import cx from "clsx";
5
32
  import { jsx, jsxs } from "react/jsx-runtime";
6
33
  var classBase = "vuuFilterTable";
7
34
  var FilterTable = ({
@@ -17,7 +44,3409 @@ var FilterTable = ({
17
44
 
18
45
  // src/json-table/JsonTable.tsx
19
46
  import { Table as Table2 } from "@vuu-ui/vuu-table";
20
- import { JsonDataSource } from "@vuu-ui/vuu-data";
47
+
48
+ // ../../node_modules/@lezer/common/dist/index.js
49
+ var DefaultBufferLength = 1024;
50
+ var nextPropID = 0;
51
+ var Range = class {
52
+ constructor(from, to) {
53
+ this.from = from;
54
+ this.to = to;
55
+ }
56
+ };
57
+ var NodeProp = class {
58
+ /// Create a new node prop type.
59
+ constructor(config = {}) {
60
+ this.id = nextPropID++;
61
+ this.perNode = !!config.perNode;
62
+ this.deserialize = config.deserialize || (() => {
63
+ throw new Error("This node type doesn't define a deserialize function");
64
+ });
65
+ }
66
+ /// This is meant to be used with
67
+ /// [`NodeSet.extend`](#common.NodeSet.extend) or
68
+ /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
69
+ /// prop values for each node type in the set. Takes a [match
70
+ /// object](#common.NodeType^match) or function that returns undefined
71
+ /// if the node type doesn't get this prop, and the prop's value if
72
+ /// it does.
73
+ add(match) {
74
+ if (this.perNode)
75
+ throw new RangeError("Can't add per-node props to node types");
76
+ if (typeof match != "function")
77
+ match = NodeType.match(match);
78
+ return (type) => {
79
+ let result = match(type);
80
+ return result === void 0 ? null : [this, result];
81
+ };
82
+ }
83
+ };
84
+ NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
85
+ NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
86
+ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
87
+ NodeProp.contextHash = new NodeProp({ perNode: true });
88
+ NodeProp.lookAhead = new NodeProp({ perNode: true });
89
+ NodeProp.mounted = new NodeProp({ perNode: true });
90
+ var noProps = /* @__PURE__ */ Object.create(null);
91
+ var NodeType = class _NodeType {
92
+ /// @internal
93
+ constructor(name, props, id, flags = 0) {
94
+ this.name = name;
95
+ this.props = props;
96
+ this.id = id;
97
+ this.flags = flags;
98
+ }
99
+ /// Define a node type.
100
+ static define(spec) {
101
+ let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
102
+ let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
103
+ let type = new _NodeType(spec.name || "", props, spec.id, flags);
104
+ if (spec.props)
105
+ for (let src of spec.props) {
106
+ if (!Array.isArray(src))
107
+ src = src(type);
108
+ if (src) {
109
+ if (src[0].perNode)
110
+ throw new RangeError("Can't store a per-node prop on a node type");
111
+ props[src[0].id] = src[1];
112
+ }
113
+ }
114
+ return type;
115
+ }
116
+ /// Retrieves a node prop for this type. Will return `undefined` if
117
+ /// the prop isn't present on this node.
118
+ prop(prop) {
119
+ return this.props[prop.id];
120
+ }
121
+ /// True when this is the top node of a grammar.
122
+ get isTop() {
123
+ return (this.flags & 1) > 0;
124
+ }
125
+ /// True when this node is produced by a skip rule.
126
+ get isSkipped() {
127
+ return (this.flags & 2) > 0;
128
+ }
129
+ /// Indicates whether this is an error node.
130
+ get isError() {
131
+ return (this.flags & 4) > 0;
132
+ }
133
+ /// When true, this node type doesn't correspond to a user-declared
134
+ /// named node, for example because it is used to cache repetition.
135
+ get isAnonymous() {
136
+ return (this.flags & 8) > 0;
137
+ }
138
+ /// Returns true when this node's name or one of its
139
+ /// [groups](#common.NodeProp^group) matches the given string.
140
+ is(name) {
141
+ if (typeof name == "string") {
142
+ if (this.name == name)
143
+ return true;
144
+ let group = this.prop(NodeProp.group);
145
+ return group ? group.indexOf(name) > -1 : false;
146
+ }
147
+ return this.id == name;
148
+ }
149
+ /// Create a function from node types to arbitrary values by
150
+ /// specifying an object whose property names are node or
151
+ /// [group](#common.NodeProp^group) names. Often useful with
152
+ /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
153
+ /// names, separated by spaces, in a single property name to map
154
+ /// multiple node names to a single value.
155
+ static match(map) {
156
+ let direct = /* @__PURE__ */ Object.create(null);
157
+ for (let prop in map)
158
+ for (let name of prop.split(" "))
159
+ direct[name] = map[prop];
160
+ return (node) => {
161
+ for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
162
+ let found = direct[i < 0 ? node.name : groups[i]];
163
+ if (found)
164
+ return found;
165
+ }
166
+ };
167
+ }
168
+ };
169
+ NodeType.none = new NodeType(
170
+ "",
171
+ /* @__PURE__ */ Object.create(null),
172
+ 0,
173
+ 8
174
+ /* NodeFlag.Anonymous */
175
+ );
176
+ var NodeSet = class _NodeSet {
177
+ /// Create a set with the given types. The `id` property of each
178
+ /// type should correspond to its position within the array.
179
+ constructor(types) {
180
+ this.types = types;
181
+ for (let i = 0; i < types.length; i++)
182
+ if (types[i].id != i)
183
+ throw new RangeError("Node type ids should correspond to array positions when creating a node set");
184
+ }
185
+ /// Create a copy of this set with some node properties added. The
186
+ /// arguments to this method can be created with
187
+ /// [`NodeProp.add`](#common.NodeProp.add).
188
+ extend(...props) {
189
+ let newTypes = [];
190
+ for (let type of this.types) {
191
+ let newProps = null;
192
+ for (let source of props) {
193
+ let add = source(type);
194
+ if (add) {
195
+ if (!newProps)
196
+ newProps = Object.assign({}, type.props);
197
+ newProps[add[0].id] = add[1];
198
+ }
199
+ }
200
+ newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
201
+ }
202
+ return new _NodeSet(newTypes);
203
+ }
204
+ };
205
+ var CachedNode = /* @__PURE__ */ new WeakMap();
206
+ var CachedInnerNode = /* @__PURE__ */ new WeakMap();
207
+ var IterMode;
208
+ (function(IterMode2) {
209
+ IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
210
+ IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
211
+ IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
212
+ IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
213
+ })(IterMode || (IterMode = {}));
214
+ var Tree = class _Tree {
215
+ /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
216
+ constructor(type, children, positions, length, props) {
217
+ this.type = type;
218
+ this.children = children;
219
+ this.positions = positions;
220
+ this.length = length;
221
+ this.props = null;
222
+ if (props && props.length) {
223
+ this.props = /* @__PURE__ */ Object.create(null);
224
+ for (let [prop, value] of props)
225
+ this.props[typeof prop == "number" ? prop : prop.id] = value;
226
+ }
227
+ }
228
+ /// @internal
229
+ toString() {
230
+ let mounted = this.prop(NodeProp.mounted);
231
+ if (mounted && !mounted.overlay)
232
+ return mounted.tree.toString();
233
+ let children = "";
234
+ for (let ch of this.children) {
235
+ let str = ch.toString();
236
+ if (str) {
237
+ if (children)
238
+ children += ",";
239
+ children += str;
240
+ }
241
+ }
242
+ return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
243
+ }
244
+ /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
245
+ /// the tree. Mode can be used to [control](#common.IterMode) which
246
+ /// nodes the cursor visits.
247
+ cursor(mode = 0) {
248
+ return new TreeCursor(this.topNode, mode);
249
+ }
250
+ /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
251
+ /// at the given position and side (see
252
+ /// [`moveTo`](#common.TreeCursor.moveTo).
253
+ cursorAt(pos, side = 0, mode = 0) {
254
+ let scope = CachedNode.get(this) || this.topNode;
255
+ let cursor = new TreeCursor(scope);
256
+ cursor.moveTo(pos, side);
257
+ CachedNode.set(this, cursor._tree);
258
+ return cursor;
259
+ }
260
+ /// Get a [syntax node](#common.SyntaxNode) object for the top of the
261
+ /// tree.
262
+ get topNode() {
263
+ return new TreeNode(this, 0, 0, null);
264
+ }
265
+ /// Get the [syntax node](#common.SyntaxNode) at the given position.
266
+ /// If `side` is -1, this will move into nodes that end at the
267
+ /// position. If 1, it'll move into nodes that start at the
268
+ /// position. With 0, it'll only enter nodes that cover the position
269
+ /// from both sides.
270
+ ///
271
+ /// Note that this will not enter
272
+ /// [overlays](#common.MountedTree.overlay), and you often want
273
+ /// [`resolveInner`](#common.Tree.resolveInner) instead.
274
+ resolve(pos, side = 0) {
275
+ let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
276
+ CachedNode.set(this, node);
277
+ return node;
278
+ }
279
+ /// Like [`resolve`](#common.Tree.resolve), but will enter
280
+ /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
281
+ /// pointing into the innermost overlaid tree at the given position
282
+ /// (with parent links going through all parent structure, including
283
+ /// the host trees).
284
+ resolveInner(pos, side = 0) {
285
+ let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
286
+ CachedInnerNode.set(this, node);
287
+ return node;
288
+ }
289
+ /// Iterate over the tree and its children, calling `enter` for any
290
+ /// node that touches the `from`/`to` region (if given) before
291
+ /// running over such a node's children, and `leave` (if given) when
292
+ /// leaving the node. When `enter` returns `false`, that node will
293
+ /// not have its children iterated over (or `leave` called).
294
+ iterate(spec) {
295
+ let { enter, leave, from = 0, to = this.length } = spec;
296
+ let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
297
+ for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
298
+ let entered = false;
299
+ if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
300
+ if (c.firstChild())
301
+ continue;
302
+ entered = true;
303
+ }
304
+ for (; ; ) {
305
+ if (entered && leave && (anon || !c.type.isAnonymous))
306
+ leave(c);
307
+ if (c.nextSibling())
308
+ break;
309
+ if (!c.parent())
310
+ return;
311
+ entered = true;
312
+ }
313
+ }
314
+ }
315
+ /// Get the value of the given [node prop](#common.NodeProp) for this
316
+ /// node. Works with both per-node and per-type props.
317
+ prop(prop) {
318
+ return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
319
+ }
320
+ /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
321
+ /// format that can be passed to the [`Tree`](#common.Tree)
322
+ /// constructor.
323
+ get propValues() {
324
+ let result = [];
325
+ if (this.props)
326
+ for (let id in this.props)
327
+ result.push([+id, this.props[id]]);
328
+ return result;
329
+ }
330
+ /// Balance the direct children of this tree, producing a copy of
331
+ /// which may have children grouped into subtrees with type
332
+ /// [`NodeType.none`](#common.NodeType^none).
333
+ balance(config = {}) {
334
+ return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new _Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new _Tree(NodeType.none, children, positions, length)));
335
+ }
336
+ /// Build a tree from a postfix-ordered buffer of node information,
337
+ /// or a cursor over such a buffer.
338
+ static build(data) {
339
+ return buildTree(data);
340
+ }
341
+ };
342
+ Tree.empty = new Tree(NodeType.none, [], [], 0);
343
+ var FlatBufferCursor = class _FlatBufferCursor {
344
+ constructor(buffer, index) {
345
+ this.buffer = buffer;
346
+ this.index = index;
347
+ }
348
+ get id() {
349
+ return this.buffer[this.index - 4];
350
+ }
351
+ get start() {
352
+ return this.buffer[this.index - 3];
353
+ }
354
+ get end() {
355
+ return this.buffer[this.index - 2];
356
+ }
357
+ get size() {
358
+ return this.buffer[this.index - 1];
359
+ }
360
+ get pos() {
361
+ return this.index;
362
+ }
363
+ next() {
364
+ this.index -= 4;
365
+ }
366
+ fork() {
367
+ return new _FlatBufferCursor(this.buffer, this.index);
368
+ }
369
+ };
370
+ var TreeBuffer = class _TreeBuffer {
371
+ /// Create a tree buffer.
372
+ constructor(buffer, length, set) {
373
+ this.buffer = buffer;
374
+ this.length = length;
375
+ this.set = set;
376
+ }
377
+ /// @internal
378
+ get type() {
379
+ return NodeType.none;
380
+ }
381
+ /// @internal
382
+ toString() {
383
+ let result = [];
384
+ for (let index = 0; index < this.buffer.length; ) {
385
+ result.push(this.childString(index));
386
+ index = this.buffer[index + 3];
387
+ }
388
+ return result.join(",");
389
+ }
390
+ /// @internal
391
+ childString(index) {
392
+ let id = this.buffer[index], endIndex = this.buffer[index + 3];
393
+ let type = this.set.types[id], result = type.name;
394
+ if (/\W/.test(result) && !type.isError)
395
+ result = JSON.stringify(result);
396
+ index += 4;
397
+ if (endIndex == index)
398
+ return result;
399
+ let children = [];
400
+ while (index < endIndex) {
401
+ children.push(this.childString(index));
402
+ index = this.buffer[index + 3];
403
+ }
404
+ return result + "(" + children.join(",") + ")";
405
+ }
406
+ /// @internal
407
+ findChild(startIndex, endIndex, dir, pos, side) {
408
+ let { buffer } = this, pick = -1;
409
+ for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
410
+ if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
411
+ pick = i;
412
+ if (dir > 0)
413
+ break;
414
+ }
415
+ }
416
+ return pick;
417
+ }
418
+ /// @internal
419
+ slice(startI, endI, from) {
420
+ let b = this.buffer;
421
+ let copy = new Uint16Array(endI - startI), len = 0;
422
+ for (let i = startI, j = 0; i < endI; ) {
423
+ copy[j++] = b[i++];
424
+ copy[j++] = b[i++] - from;
425
+ let to = copy[j++] = b[i++] - from;
426
+ copy[j++] = b[i++] - startI;
427
+ len = Math.max(len, to);
428
+ }
429
+ return new _TreeBuffer(copy, len, this.set);
430
+ }
431
+ };
432
+ function checkSide(side, pos, from, to) {
433
+ switch (side) {
434
+ case -2:
435
+ return from < pos;
436
+ case -1:
437
+ return to >= pos && from < pos;
438
+ case 0:
439
+ return from < pos && to > pos;
440
+ case 1:
441
+ return from <= pos && to > pos;
442
+ case 2:
443
+ return to > pos;
444
+ case 4:
445
+ return true;
446
+ }
447
+ }
448
+ function enterUnfinishedNodesBefore(node, pos) {
449
+ let scan = node.childBefore(pos);
450
+ while (scan) {
451
+ let last = scan.lastChild;
452
+ if (!last || last.to != scan.to)
453
+ break;
454
+ if (last.type.isError && last.from == last.to) {
455
+ node = scan;
456
+ scan = last.prevSibling;
457
+ } else {
458
+ scan = last;
459
+ }
460
+ }
461
+ return node;
462
+ }
463
+ function resolveNode(node, pos, side, overlays) {
464
+ var _a;
465
+ while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
466
+ let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
467
+ if (!parent)
468
+ return node;
469
+ node = parent;
470
+ }
471
+ let mode = overlays ? 0 : IterMode.IgnoreOverlays;
472
+ if (overlays)
473
+ for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
474
+ if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
475
+ node = parent;
476
+ }
477
+ for (; ; ) {
478
+ let inner = node.enter(pos, side, mode);
479
+ if (!inner)
480
+ return node;
481
+ node = inner;
482
+ }
483
+ }
484
+ var TreeNode = class _TreeNode {
485
+ constructor(_tree, from, index, _parent) {
486
+ this._tree = _tree;
487
+ this.from = from;
488
+ this.index = index;
489
+ this._parent = _parent;
490
+ }
491
+ get type() {
492
+ return this._tree.type;
493
+ }
494
+ get name() {
495
+ return this._tree.type.name;
496
+ }
497
+ get to() {
498
+ return this.from + this._tree.length;
499
+ }
500
+ nextChild(i, dir, pos, side, mode = 0) {
501
+ for (let parent = this; ; ) {
502
+ for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
503
+ let next = children[i], start = positions[i] + parent.from;
504
+ if (!checkSide(side, pos, start, start + next.length))
505
+ continue;
506
+ if (next instanceof TreeBuffer) {
507
+ if (mode & IterMode.ExcludeBuffers)
508
+ continue;
509
+ let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
510
+ if (index > -1)
511
+ return new BufferNode(new BufferContext(parent, next, i, start), null, index);
512
+ } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
513
+ let mounted;
514
+ if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
515
+ return new _TreeNode(mounted.tree, start, i, parent);
516
+ let inner = new _TreeNode(next, start, i, parent);
517
+ return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
518
+ }
519
+ }
520
+ if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
521
+ return null;
522
+ if (parent.index >= 0)
523
+ i = parent.index + dir;
524
+ else
525
+ i = dir < 0 ? -1 : parent._parent._tree.children.length;
526
+ parent = parent._parent;
527
+ if (!parent)
528
+ return null;
529
+ }
530
+ }
531
+ get firstChild() {
532
+ return this.nextChild(
533
+ 0,
534
+ 1,
535
+ 0,
536
+ 4
537
+ /* Side.DontCare */
538
+ );
539
+ }
540
+ get lastChild() {
541
+ return this.nextChild(
542
+ this._tree.children.length - 1,
543
+ -1,
544
+ 0,
545
+ 4
546
+ /* Side.DontCare */
547
+ );
548
+ }
549
+ childAfter(pos) {
550
+ return this.nextChild(
551
+ 0,
552
+ 1,
553
+ pos,
554
+ 2
555
+ /* Side.After */
556
+ );
557
+ }
558
+ childBefore(pos) {
559
+ return this.nextChild(
560
+ this._tree.children.length - 1,
561
+ -1,
562
+ pos,
563
+ -2
564
+ /* Side.Before */
565
+ );
566
+ }
567
+ enter(pos, side, mode = 0) {
568
+ let mounted;
569
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
570
+ let rPos = pos - this.from;
571
+ for (let { from, to } of mounted.overlay) {
572
+ if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
573
+ return new _TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
574
+ }
575
+ }
576
+ return this.nextChild(0, 1, pos, side, mode);
577
+ }
578
+ nextSignificantParent() {
579
+ let val = this;
580
+ while (val.type.isAnonymous && val._parent)
581
+ val = val._parent;
582
+ return val;
583
+ }
584
+ get parent() {
585
+ return this._parent ? this._parent.nextSignificantParent() : null;
586
+ }
587
+ get nextSibling() {
588
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
589
+ this.index + 1,
590
+ 1,
591
+ 0,
592
+ 4
593
+ /* Side.DontCare */
594
+ ) : null;
595
+ }
596
+ get prevSibling() {
597
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
598
+ this.index - 1,
599
+ -1,
600
+ 0,
601
+ 4
602
+ /* Side.DontCare */
603
+ ) : null;
604
+ }
605
+ cursor(mode = 0) {
606
+ return new TreeCursor(this, mode);
607
+ }
608
+ get tree() {
609
+ return this._tree;
610
+ }
611
+ toTree() {
612
+ return this._tree;
613
+ }
614
+ resolve(pos, side = 0) {
615
+ return resolveNode(this, pos, side, false);
616
+ }
617
+ resolveInner(pos, side = 0) {
618
+ return resolveNode(this, pos, side, true);
619
+ }
620
+ enterUnfinishedNodesBefore(pos) {
621
+ return enterUnfinishedNodesBefore(this, pos);
622
+ }
623
+ getChild(type, before = null, after = null) {
624
+ let r = getChildren(this, type, before, after);
625
+ return r.length ? r[0] : null;
626
+ }
627
+ getChildren(type, before = null, after = null) {
628
+ return getChildren(this, type, before, after);
629
+ }
630
+ /// @internal
631
+ toString() {
632
+ return this._tree.toString();
633
+ }
634
+ get node() {
635
+ return this;
636
+ }
637
+ matchContext(context) {
638
+ return matchNodeContext(this, context);
639
+ }
640
+ };
641
+ function getChildren(node, type, before, after) {
642
+ let cur = node.cursor(), result = [];
643
+ if (!cur.firstChild())
644
+ return result;
645
+ if (before != null) {
646
+ while (!cur.type.is(before))
647
+ if (!cur.nextSibling())
648
+ return result;
649
+ }
650
+ for (; ; ) {
651
+ if (after != null && cur.type.is(after))
652
+ return result;
653
+ if (cur.type.is(type))
654
+ result.push(cur.node);
655
+ if (!cur.nextSibling())
656
+ return after == null ? result : [];
657
+ }
658
+ }
659
+ function matchNodeContext(node, context, i = context.length - 1) {
660
+ for (let p = node.parent; i >= 0; p = p.parent) {
661
+ if (!p)
662
+ return false;
663
+ if (!p.type.isAnonymous) {
664
+ if (context[i] && context[i] != p.name)
665
+ return false;
666
+ i--;
667
+ }
668
+ }
669
+ return true;
670
+ }
671
+ var BufferContext = class {
672
+ constructor(parent, buffer, index, start) {
673
+ this.parent = parent;
674
+ this.buffer = buffer;
675
+ this.index = index;
676
+ this.start = start;
677
+ }
678
+ };
679
+ var BufferNode = class _BufferNode {
680
+ get name() {
681
+ return this.type.name;
682
+ }
683
+ get from() {
684
+ return this.context.start + this.context.buffer.buffer[this.index + 1];
685
+ }
686
+ get to() {
687
+ return this.context.start + this.context.buffer.buffer[this.index + 2];
688
+ }
689
+ constructor(context, _parent, index) {
690
+ this.context = context;
691
+ this._parent = _parent;
692
+ this.index = index;
693
+ this.type = context.buffer.set.types[context.buffer.buffer[index]];
694
+ }
695
+ child(dir, pos, side) {
696
+ let { buffer } = this.context;
697
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
698
+ return index < 0 ? null : new _BufferNode(this.context, this, index);
699
+ }
700
+ get firstChild() {
701
+ return this.child(
702
+ 1,
703
+ 0,
704
+ 4
705
+ /* Side.DontCare */
706
+ );
707
+ }
708
+ get lastChild() {
709
+ return this.child(
710
+ -1,
711
+ 0,
712
+ 4
713
+ /* Side.DontCare */
714
+ );
715
+ }
716
+ childAfter(pos) {
717
+ return this.child(
718
+ 1,
719
+ pos,
720
+ 2
721
+ /* Side.After */
722
+ );
723
+ }
724
+ childBefore(pos) {
725
+ return this.child(
726
+ -1,
727
+ pos,
728
+ -2
729
+ /* Side.Before */
730
+ );
731
+ }
732
+ enter(pos, side, mode = 0) {
733
+ if (mode & IterMode.ExcludeBuffers)
734
+ return null;
735
+ let { buffer } = this.context;
736
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
737
+ return index < 0 ? null : new _BufferNode(this.context, this, index);
738
+ }
739
+ get parent() {
740
+ return this._parent || this.context.parent.nextSignificantParent();
741
+ }
742
+ externalSibling(dir) {
743
+ return this._parent ? null : this.context.parent.nextChild(
744
+ this.context.index + dir,
745
+ dir,
746
+ 0,
747
+ 4
748
+ /* Side.DontCare */
749
+ );
750
+ }
751
+ get nextSibling() {
752
+ let { buffer } = this.context;
753
+ let after = buffer.buffer[this.index + 3];
754
+ if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
755
+ return new _BufferNode(this.context, this._parent, after);
756
+ return this.externalSibling(1);
757
+ }
758
+ get prevSibling() {
759
+ let { buffer } = this.context;
760
+ let parentStart = this._parent ? this._parent.index + 4 : 0;
761
+ if (this.index == parentStart)
762
+ return this.externalSibling(-1);
763
+ return new _BufferNode(this.context, this._parent, buffer.findChild(
764
+ parentStart,
765
+ this.index,
766
+ -1,
767
+ 0,
768
+ 4
769
+ /* Side.DontCare */
770
+ ));
771
+ }
772
+ cursor(mode = 0) {
773
+ return new TreeCursor(this, mode);
774
+ }
775
+ get tree() {
776
+ return null;
777
+ }
778
+ toTree() {
779
+ let children = [], positions = [];
780
+ let { buffer } = this.context;
781
+ let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
782
+ if (endI > startI) {
783
+ let from = buffer.buffer[this.index + 1];
784
+ children.push(buffer.slice(startI, endI, from));
785
+ positions.push(0);
786
+ }
787
+ return new Tree(this.type, children, positions, this.to - this.from);
788
+ }
789
+ resolve(pos, side = 0) {
790
+ return resolveNode(this, pos, side, false);
791
+ }
792
+ resolveInner(pos, side = 0) {
793
+ return resolveNode(this, pos, side, true);
794
+ }
795
+ enterUnfinishedNodesBefore(pos) {
796
+ return enterUnfinishedNodesBefore(this, pos);
797
+ }
798
+ /// @internal
799
+ toString() {
800
+ return this.context.buffer.childString(this.index);
801
+ }
802
+ getChild(type, before = null, after = null) {
803
+ let r = getChildren(this, type, before, after);
804
+ return r.length ? r[0] : null;
805
+ }
806
+ getChildren(type, before = null, after = null) {
807
+ return getChildren(this, type, before, after);
808
+ }
809
+ get node() {
810
+ return this;
811
+ }
812
+ matchContext(context) {
813
+ return matchNodeContext(this, context);
814
+ }
815
+ };
816
+ var TreeCursor = class {
817
+ /// Shorthand for `.type.name`.
818
+ get name() {
819
+ return this.type.name;
820
+ }
821
+ /// @internal
822
+ constructor(node, mode = 0) {
823
+ this.mode = mode;
824
+ this.buffer = null;
825
+ this.stack = [];
826
+ this.index = 0;
827
+ this.bufferNode = null;
828
+ if (node instanceof TreeNode) {
829
+ this.yieldNode(node);
830
+ } else {
831
+ this._tree = node.context.parent;
832
+ this.buffer = node.context;
833
+ for (let n = node._parent; n; n = n._parent)
834
+ this.stack.unshift(n.index);
835
+ this.bufferNode = node;
836
+ this.yieldBuf(node.index);
837
+ }
838
+ }
839
+ yieldNode(node) {
840
+ if (!node)
841
+ return false;
842
+ this._tree = node;
843
+ this.type = node.type;
844
+ this.from = node.from;
845
+ this.to = node.to;
846
+ return true;
847
+ }
848
+ yieldBuf(index, type) {
849
+ this.index = index;
850
+ let { start, buffer } = this.buffer;
851
+ this.type = type || buffer.set.types[buffer.buffer[index]];
852
+ this.from = start + buffer.buffer[index + 1];
853
+ this.to = start + buffer.buffer[index + 2];
854
+ return true;
855
+ }
856
+ yield(node) {
857
+ if (!node)
858
+ return false;
859
+ if (node instanceof TreeNode) {
860
+ this.buffer = null;
861
+ return this.yieldNode(node);
862
+ }
863
+ this.buffer = node.context;
864
+ return this.yieldBuf(node.index, node.type);
865
+ }
866
+ /// @internal
867
+ toString() {
868
+ return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
869
+ }
870
+ /// @internal
871
+ enterChild(dir, pos, side) {
872
+ if (!this.buffer)
873
+ return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
874
+ let { buffer } = this.buffer;
875
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
876
+ if (index < 0)
877
+ return false;
878
+ this.stack.push(this.index);
879
+ return this.yieldBuf(index);
880
+ }
881
+ /// Move the cursor to this node's first child. When this returns
882
+ /// false, the node has no child, and the cursor has not been moved.
883
+ firstChild() {
884
+ return this.enterChild(
885
+ 1,
886
+ 0,
887
+ 4
888
+ /* Side.DontCare */
889
+ );
890
+ }
891
+ /// Move the cursor to this node's last child.
892
+ lastChild() {
893
+ return this.enterChild(
894
+ -1,
895
+ 0,
896
+ 4
897
+ /* Side.DontCare */
898
+ );
899
+ }
900
+ /// Move the cursor to the first child that ends after `pos`.
901
+ childAfter(pos) {
902
+ return this.enterChild(
903
+ 1,
904
+ pos,
905
+ 2
906
+ /* Side.After */
907
+ );
908
+ }
909
+ /// Move to the last child that starts before `pos`.
910
+ childBefore(pos) {
911
+ return this.enterChild(
912
+ -1,
913
+ pos,
914
+ -2
915
+ /* Side.Before */
916
+ );
917
+ }
918
+ /// Move the cursor to the child around `pos`. If side is -1 the
919
+ /// child may end at that position, when 1 it may start there. This
920
+ /// will also enter [overlaid](#common.MountedTree.overlay)
921
+ /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
922
+ /// set to false.
923
+ enter(pos, side, mode = this.mode) {
924
+ if (!this.buffer)
925
+ return this.yield(this._tree.enter(pos, side, mode));
926
+ return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
927
+ }
928
+ /// Move to the node's parent node, if this isn't the top node.
929
+ parent() {
930
+ if (!this.buffer)
931
+ return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
932
+ if (this.stack.length)
933
+ return this.yieldBuf(this.stack.pop());
934
+ let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
935
+ this.buffer = null;
936
+ return this.yieldNode(parent);
937
+ }
938
+ /// @internal
939
+ sibling(dir) {
940
+ if (!this.buffer)
941
+ return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
942
+ let { buffer } = this.buffer, d = this.stack.length - 1;
943
+ if (dir < 0) {
944
+ let parentStart = d < 0 ? 0 : this.stack[d] + 4;
945
+ if (this.index != parentStart)
946
+ return this.yieldBuf(buffer.findChild(
947
+ parentStart,
948
+ this.index,
949
+ -1,
950
+ 0,
951
+ 4
952
+ /* Side.DontCare */
953
+ ));
954
+ } else {
955
+ let after = buffer.buffer[this.index + 3];
956
+ if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
957
+ return this.yieldBuf(after);
958
+ }
959
+ return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
960
+ }
961
+ /// Move to this node's next sibling, if any.
962
+ nextSibling() {
963
+ return this.sibling(1);
964
+ }
965
+ /// Move to this node's previous sibling, if any.
966
+ prevSibling() {
967
+ return this.sibling(-1);
968
+ }
969
+ atLastNode(dir) {
970
+ let index, parent, { buffer } = this;
971
+ if (buffer) {
972
+ if (dir > 0) {
973
+ if (this.index < buffer.buffer.buffer.length)
974
+ return false;
975
+ } else {
976
+ for (let i = 0; i < this.index; i++)
977
+ if (buffer.buffer.buffer[i + 3] < this.index)
978
+ return false;
979
+ }
980
+ ({ index, parent } = buffer);
981
+ } else {
982
+ ({ index, _parent: parent } = this._tree);
983
+ }
984
+ for (; parent; { index, _parent: parent } = parent) {
985
+ if (index > -1)
986
+ for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
987
+ let child = parent._tree.children[i];
988
+ if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
989
+ return false;
990
+ }
991
+ }
992
+ return true;
993
+ }
994
+ move(dir, enter) {
995
+ if (enter && this.enterChild(
996
+ dir,
997
+ 0,
998
+ 4
999
+ /* Side.DontCare */
1000
+ ))
1001
+ return true;
1002
+ for (; ; ) {
1003
+ if (this.sibling(dir))
1004
+ return true;
1005
+ if (this.atLastNode(dir) || !this.parent())
1006
+ return false;
1007
+ }
1008
+ }
1009
+ /// Move to the next node in a
1010
+ /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1011
+ /// traversal, going from a node to its first child or, if the
1012
+ /// current node is empty or `enter` is false, its next sibling or
1013
+ /// the next sibling of the first parent node that has one.
1014
+ next(enter = true) {
1015
+ return this.move(1, enter);
1016
+ }
1017
+ /// Move to the next node in a last-to-first pre-order traveral. A
1018
+ /// node is followed by its last child or, if it has none, its
1019
+ /// previous sibling or the previous sibling of the first parent
1020
+ /// node that has one.
1021
+ prev(enter = true) {
1022
+ return this.move(-1, enter);
1023
+ }
1024
+ /// Move the cursor to the innermost node that covers `pos`. If
1025
+ /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1026
+ /// it will enter nodes that start at `pos`.
1027
+ moveTo(pos, side = 0) {
1028
+ while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
1029
+ if (!this.parent())
1030
+ break;
1031
+ while (this.enterChild(1, pos, side)) {
1032
+ }
1033
+ return this;
1034
+ }
1035
+ /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
1036
+ /// position.
1037
+ get node() {
1038
+ if (!this.buffer)
1039
+ return this._tree;
1040
+ let cache = this.bufferNode, result = null, depth = 0;
1041
+ if (cache && cache.context == this.buffer) {
1042
+ scan:
1043
+ for (let index = this.index, d = this.stack.length; d >= 0; ) {
1044
+ for (let c = cache; c; c = c._parent)
1045
+ if (c.index == index) {
1046
+ if (index == this.index)
1047
+ return c;
1048
+ result = c;
1049
+ depth = d + 1;
1050
+ break scan;
1051
+ }
1052
+ index = this.stack[--d];
1053
+ }
1054
+ }
1055
+ for (let i = depth; i < this.stack.length; i++)
1056
+ result = new BufferNode(this.buffer, result, this.stack[i]);
1057
+ return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1058
+ }
1059
+ /// Get the [tree](#common.Tree) that represents the current node, if
1060
+ /// any. Will return null when the node is in a [tree
1061
+ /// buffer](#common.TreeBuffer).
1062
+ get tree() {
1063
+ return this.buffer ? null : this._tree._tree;
1064
+ }
1065
+ /// Iterate over the current node and all its descendants, calling
1066
+ /// `enter` when entering a node and `leave`, if given, when leaving
1067
+ /// one. When `enter` returns `false`, any children of that node are
1068
+ /// skipped, and `leave` isn't called for it.
1069
+ iterate(enter, leave) {
1070
+ for (let depth = 0; ; ) {
1071
+ let mustLeave = false;
1072
+ if (this.type.isAnonymous || enter(this) !== false) {
1073
+ if (this.firstChild()) {
1074
+ depth++;
1075
+ continue;
1076
+ }
1077
+ if (!this.type.isAnonymous)
1078
+ mustLeave = true;
1079
+ }
1080
+ for (; ; ) {
1081
+ if (mustLeave && leave)
1082
+ leave(this);
1083
+ mustLeave = this.type.isAnonymous;
1084
+ if (this.nextSibling())
1085
+ break;
1086
+ if (!depth)
1087
+ return;
1088
+ this.parent();
1089
+ depth--;
1090
+ mustLeave = true;
1091
+ }
1092
+ }
1093
+ }
1094
+ /// Test whether the current node matches a given context—a sequence
1095
+ /// of direct parent node names. Empty strings in the context array
1096
+ /// are treated as wildcards.
1097
+ matchContext(context) {
1098
+ if (!this.buffer)
1099
+ return matchNodeContext(this.node, context);
1100
+ let { buffer } = this.buffer, { types } = buffer.set;
1101
+ for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
1102
+ if (d < 0)
1103
+ return matchNodeContext(this.node, context, i);
1104
+ let type = types[buffer.buffer[this.stack[d]]];
1105
+ if (!type.isAnonymous) {
1106
+ if (context[i] && context[i] != type.name)
1107
+ return false;
1108
+ i--;
1109
+ }
1110
+ }
1111
+ return true;
1112
+ }
1113
+ };
1114
+ function hasChild(tree) {
1115
+ return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
1116
+ }
1117
+ function buildTree(data) {
1118
+ var _a;
1119
+ let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
1120
+ let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
1121
+ let types = nodeSet.types;
1122
+ let contextHash = 0, lookAhead = 0;
1123
+ function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
1124
+ let { id, start, end, size } = cursor;
1125
+ let lookAheadAtStart = lookAhead;
1126
+ while (size < 0) {
1127
+ cursor.next();
1128
+ if (size == -1) {
1129
+ let node2 = reused[id];
1130
+ children2.push(node2);
1131
+ positions2.push(start - parentStart);
1132
+ return;
1133
+ } else if (size == -3) {
1134
+ contextHash = id;
1135
+ return;
1136
+ } else if (size == -4) {
1137
+ lookAhead = id;
1138
+ return;
1139
+ } else {
1140
+ throw new RangeError(`Unrecognized record size: ${size}`);
1141
+ }
1142
+ }
1143
+ let type = types[id], node, buffer2;
1144
+ let startPos = start - parentStart;
1145
+ if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
1146
+ let data2 = new Uint16Array(buffer2.size - buffer2.skip);
1147
+ let endPos = cursor.pos - buffer2.size, index = data2.length;
1148
+ while (cursor.pos > endPos)
1149
+ index = copyToBuffer(buffer2.start, data2, index);
1150
+ node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
1151
+ startPos = buffer2.start - parentStart;
1152
+ } else {
1153
+ let endPos = cursor.pos - size;
1154
+ cursor.next();
1155
+ let localChildren = [], localPositions = [];
1156
+ let localInRepeat = id >= minRepeatType ? id : -1;
1157
+ let lastGroup = 0, lastEnd = end;
1158
+ while (cursor.pos > endPos) {
1159
+ if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
1160
+ if (cursor.end <= lastEnd - maxBufferLength) {
1161
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
1162
+ lastGroup = localChildren.length;
1163
+ lastEnd = cursor.end;
1164
+ }
1165
+ cursor.next();
1166
+ } else {
1167
+ takeNode(start, endPos, localChildren, localPositions, localInRepeat);
1168
+ }
1169
+ }
1170
+ if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
1171
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
1172
+ localChildren.reverse();
1173
+ localPositions.reverse();
1174
+ if (localInRepeat > -1 && lastGroup > 0) {
1175
+ let make = makeBalanced(type);
1176
+ node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
1177
+ } else {
1178
+ node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
1179
+ }
1180
+ }
1181
+ children2.push(node);
1182
+ positions2.push(startPos);
1183
+ }
1184
+ function makeBalanced(type) {
1185
+ return (children2, positions2, length2) => {
1186
+ let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
1187
+ if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
1188
+ if (!lastI && last.type == type && last.length == length2)
1189
+ return last;
1190
+ if (lookAheadProp = last.prop(NodeProp.lookAhead))
1191
+ lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
1192
+ }
1193
+ return makeTree(type, children2, positions2, length2, lookAhead2);
1194
+ };
1195
+ }
1196
+ function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
1197
+ let localChildren = [], localPositions = [];
1198
+ while (children2.length > i) {
1199
+ localChildren.push(children2.pop());
1200
+ localPositions.push(positions2.pop() + base - from);
1201
+ }
1202
+ children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
1203
+ positions2.push(from - base);
1204
+ }
1205
+ function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
1206
+ if (contextHash) {
1207
+ let pair2 = [NodeProp.contextHash, contextHash];
1208
+ props = props ? [pair2].concat(props) : [pair2];
1209
+ }
1210
+ if (lookAhead2 > 25) {
1211
+ let pair2 = [NodeProp.lookAhead, lookAhead2];
1212
+ props = props ? [pair2].concat(props) : [pair2];
1213
+ }
1214
+ return new Tree(type, children2, positions2, length2, props);
1215
+ }
1216
+ function findBufferSize(maxSize, inRepeat) {
1217
+ let fork = cursor.fork();
1218
+ let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
1219
+ let result = { size: 0, start: 0, skip: 0 };
1220
+ scan:
1221
+ for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
1222
+ let nodeSize2 = fork.size;
1223
+ if (fork.id == inRepeat && nodeSize2 >= 0) {
1224
+ result.size = size;
1225
+ result.start = start;
1226
+ result.skip = skip;
1227
+ skip += 4;
1228
+ size += 4;
1229
+ fork.next();
1230
+ continue;
1231
+ }
1232
+ let startPos = fork.pos - nodeSize2;
1233
+ if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
1234
+ break;
1235
+ let localSkipped = fork.id >= minRepeatType ? 4 : 0;
1236
+ let nodeStart = fork.start;
1237
+ fork.next();
1238
+ while (fork.pos > startPos) {
1239
+ if (fork.size < 0) {
1240
+ if (fork.size == -3)
1241
+ localSkipped += 4;
1242
+ else
1243
+ break scan;
1244
+ } else if (fork.id >= minRepeatType) {
1245
+ localSkipped += 4;
1246
+ }
1247
+ fork.next();
1248
+ }
1249
+ start = nodeStart;
1250
+ size += nodeSize2;
1251
+ skip += localSkipped;
1252
+ }
1253
+ if (inRepeat < 0 || size == maxSize) {
1254
+ result.size = size;
1255
+ result.start = start;
1256
+ result.skip = skip;
1257
+ }
1258
+ return result.size > 4 ? result : void 0;
1259
+ }
1260
+ function copyToBuffer(bufferStart, buffer2, index) {
1261
+ let { id, start, end, size } = cursor;
1262
+ cursor.next();
1263
+ if (size >= 0 && id < minRepeatType) {
1264
+ let startIndex = index;
1265
+ if (size > 4) {
1266
+ let endPos = cursor.pos - (size - 4);
1267
+ while (cursor.pos > endPos)
1268
+ index = copyToBuffer(bufferStart, buffer2, index);
1269
+ }
1270
+ buffer2[--index] = startIndex;
1271
+ buffer2[--index] = end - bufferStart;
1272
+ buffer2[--index] = start - bufferStart;
1273
+ buffer2[--index] = id;
1274
+ } else if (size == -3) {
1275
+ contextHash = id;
1276
+ } else if (size == -4) {
1277
+ lookAhead = id;
1278
+ }
1279
+ return index;
1280
+ }
1281
+ let children = [], positions = [];
1282
+ while (cursor.pos > 0)
1283
+ takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
1284
+ let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
1285
+ return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
1286
+ }
1287
+ var nodeSizeCache = /* @__PURE__ */ new WeakMap();
1288
+ function nodeSize(balanceType, node) {
1289
+ if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
1290
+ return 1;
1291
+ let size = nodeSizeCache.get(node);
1292
+ if (size == null) {
1293
+ size = 1;
1294
+ for (let child of node.children) {
1295
+ if (child.type != balanceType || !(child instanceof Tree)) {
1296
+ size = 1;
1297
+ break;
1298
+ }
1299
+ size += nodeSize(balanceType, child);
1300
+ }
1301
+ nodeSizeCache.set(node, size);
1302
+ }
1303
+ return size;
1304
+ }
1305
+ function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
1306
+ let total = 0;
1307
+ for (let i = from; i < to; i++)
1308
+ total += nodeSize(balanceType, children[i]);
1309
+ let maxChild = Math.ceil(
1310
+ total * 1.5 / 8
1311
+ /* Balance.BranchFactor */
1312
+ );
1313
+ let localChildren = [], localPositions = [];
1314
+ function divide(children2, positions2, from2, to2, offset) {
1315
+ for (let i = from2; i < to2; ) {
1316
+ let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
1317
+ i++;
1318
+ for (; i < to2; i++) {
1319
+ let nextSize = nodeSize(balanceType, children2[i]);
1320
+ if (groupSize + nextSize >= maxChild)
1321
+ break;
1322
+ groupSize += nextSize;
1323
+ }
1324
+ if (i == groupFrom + 1) {
1325
+ if (groupSize > maxChild) {
1326
+ let only = children2[groupFrom];
1327
+ divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
1328
+ continue;
1329
+ }
1330
+ localChildren.push(children2[groupFrom]);
1331
+ } else {
1332
+ let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
1333
+ localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
1334
+ }
1335
+ localPositions.push(groupStart + offset - start);
1336
+ }
1337
+ }
1338
+ divide(children, positions, from, to, 0);
1339
+ return (mkTop || mkTree)(localChildren, localPositions, length);
1340
+ }
1341
+ var Parser = class {
1342
+ /// Start a parse, returning a [partial parse](#common.PartialParse)
1343
+ /// object. [`fragments`](#common.TreeFragment) can be passed in to
1344
+ /// make the parse incremental.
1345
+ ///
1346
+ /// By default, the entire input is parsed. You can pass `ranges`,
1347
+ /// which should be a sorted array of non-empty, non-overlapping
1348
+ /// ranges, to parse only those ranges. The tree returned in that
1349
+ /// case will start at `ranges[0].from`.
1350
+ startParse(input, fragments, ranges) {
1351
+ if (typeof input == "string")
1352
+ input = new StringInput(input);
1353
+ ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
1354
+ return this.createParse(input, fragments || [], ranges);
1355
+ }
1356
+ /// Run a full parse, returning the resulting tree.
1357
+ parse(input, fragments, ranges) {
1358
+ let parse = this.startParse(input, fragments, ranges);
1359
+ for (; ; ) {
1360
+ let done = parse.advance();
1361
+ if (done)
1362
+ return done;
1363
+ }
1364
+ }
1365
+ };
1366
+ var StringInput = class {
1367
+ constructor(string) {
1368
+ this.string = string;
1369
+ }
1370
+ get length() {
1371
+ return this.string.length;
1372
+ }
1373
+ chunk(from) {
1374
+ return this.string.slice(from);
1375
+ }
1376
+ get lineChunks() {
1377
+ return false;
1378
+ }
1379
+ read(from, to) {
1380
+ return this.string.slice(from, to);
1381
+ }
1382
+ };
1383
+ var stoppedInner = new NodeProp({ perNode: true });
1384
+
1385
+ // ../../node_modules/@lezer/lr/dist/index.js
1386
+ var Stack = class _Stack {
1387
+ /// @internal
1388
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
1389
+ this.p = p;
1390
+ this.stack = stack;
1391
+ this.state = state;
1392
+ this.reducePos = reducePos;
1393
+ this.pos = pos;
1394
+ this.score = score;
1395
+ this.buffer = buffer;
1396
+ this.bufferBase = bufferBase;
1397
+ this.curContext = curContext;
1398
+ this.lookAhead = lookAhead;
1399
+ this.parent = parent;
1400
+ }
1401
+ /// @internal
1402
+ toString() {
1403
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
1404
+ }
1405
+ // Start an empty stack
1406
+ /// @internal
1407
+ static start(p, state, pos = 0) {
1408
+ let cx2 = p.parser.context;
1409
+ return new _Stack(p, [], state, pos, pos, 0, [], 0, cx2 ? new StackContext(cx2, cx2.start) : null, 0, null);
1410
+ }
1411
+ /// The stack's current [context](#lr.ContextTracker) value, if
1412
+ /// any. Its type will depend on the context tracker's type
1413
+ /// parameter, or it will be `null` if there is no context
1414
+ /// tracker.
1415
+ get context() {
1416
+ return this.curContext ? this.curContext.context : null;
1417
+ }
1418
+ // Push a state onto the stack, tracking its start position as well
1419
+ // as the buffer base at that point.
1420
+ /// @internal
1421
+ pushState(state, start) {
1422
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
1423
+ this.state = state;
1424
+ }
1425
+ // Apply a reduce action
1426
+ /// @internal
1427
+ reduce(action) {
1428
+ var _a;
1429
+ let depth = action >> 19, type = action & 65535;
1430
+ let { parser: parser2 } = this.p;
1431
+ let dPrec = parser2.dynamicPrecedence(type);
1432
+ if (dPrec)
1433
+ this.score += dPrec;
1434
+ if (depth == 0) {
1435
+ this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
1436
+ if (type < parser2.minRepeatTerm)
1437
+ this.storeNode(type, this.reducePos, this.reducePos, 4, true);
1438
+ this.reduceContext(type, this.reducePos);
1439
+ return;
1440
+ }
1441
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
1442
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
1443
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
1444
+ if (start == this.p.lastBigReductionStart) {
1445
+ this.p.bigReductionCount++;
1446
+ this.p.lastBigReductionSize = size;
1447
+ } else if (this.p.lastBigReductionSize < size) {
1448
+ this.p.bigReductionCount = 1;
1449
+ this.p.lastBigReductionStart = start;
1450
+ this.p.lastBigReductionSize = size;
1451
+ }
1452
+ }
1453
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
1454
+ if (type < parser2.minRepeatTerm || action & 131072) {
1455
+ let pos = parser2.stateFlag(
1456
+ this.state,
1457
+ 1
1458
+ /* StateFlag.Skipped */
1459
+ ) ? this.pos : this.reducePos;
1460
+ this.storeNode(type, start, pos, count + 4, true);
1461
+ }
1462
+ if (action & 262144) {
1463
+ this.state = this.stack[base];
1464
+ } else {
1465
+ let baseStateID = this.stack[base - 3];
1466
+ this.state = parser2.getGoto(baseStateID, type, true);
1467
+ }
1468
+ while (this.stack.length > base)
1469
+ this.stack.pop();
1470
+ this.reduceContext(type, start);
1471
+ }
1472
+ // Shift a value into the buffer
1473
+ /// @internal
1474
+ storeNode(term, start, end, size = 4, isReduce = false) {
1475
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
1476
+ let cur = this, top = this.buffer.length;
1477
+ if (top == 0 && cur.parent) {
1478
+ top = cur.bufferBase - cur.parent.bufferBase;
1479
+ cur = cur.parent;
1480
+ }
1481
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
1482
+ if (start == end)
1483
+ return;
1484
+ if (cur.buffer[top - 2] >= start) {
1485
+ cur.buffer[top - 2] = end;
1486
+ return;
1487
+ }
1488
+ }
1489
+ }
1490
+ if (!isReduce || this.pos == end) {
1491
+ this.buffer.push(term, start, end, size);
1492
+ } else {
1493
+ let index = this.buffer.length;
1494
+ if (index > 0 && this.buffer[index - 4] != 0)
1495
+ while (index > 0 && this.buffer[index - 2] > end) {
1496
+ this.buffer[index] = this.buffer[index - 4];
1497
+ this.buffer[index + 1] = this.buffer[index - 3];
1498
+ this.buffer[index + 2] = this.buffer[index - 2];
1499
+ this.buffer[index + 3] = this.buffer[index - 1];
1500
+ index -= 4;
1501
+ if (size > 4)
1502
+ size -= 4;
1503
+ }
1504
+ this.buffer[index] = term;
1505
+ this.buffer[index + 1] = start;
1506
+ this.buffer[index + 2] = end;
1507
+ this.buffer[index + 3] = size;
1508
+ }
1509
+ }
1510
+ // Apply a shift action
1511
+ /// @internal
1512
+ shift(action, next, nextEnd) {
1513
+ let start = this.pos;
1514
+ if (action & 131072) {
1515
+ this.pushState(action & 65535, this.pos);
1516
+ } else if ((action & 262144) == 0) {
1517
+ let nextState = action, { parser: parser2 } = this.p;
1518
+ if (nextEnd > this.pos || next <= parser2.maxNode) {
1519
+ this.pos = nextEnd;
1520
+ if (!parser2.stateFlag(
1521
+ nextState,
1522
+ 1
1523
+ /* StateFlag.Skipped */
1524
+ ))
1525
+ this.reducePos = nextEnd;
1526
+ }
1527
+ this.pushState(nextState, start);
1528
+ this.shiftContext(next, start);
1529
+ if (next <= parser2.maxNode)
1530
+ this.buffer.push(next, start, nextEnd, 4);
1531
+ } else {
1532
+ this.pos = nextEnd;
1533
+ this.shiftContext(next, start);
1534
+ if (next <= this.p.parser.maxNode)
1535
+ this.buffer.push(next, start, nextEnd, 4);
1536
+ }
1537
+ }
1538
+ // Apply an action
1539
+ /// @internal
1540
+ apply(action, next, nextEnd) {
1541
+ if (action & 65536)
1542
+ this.reduce(action);
1543
+ else
1544
+ this.shift(action, next, nextEnd);
1545
+ }
1546
+ // Add a prebuilt (reused) node into the buffer.
1547
+ /// @internal
1548
+ useNode(value, next) {
1549
+ let index = this.p.reused.length - 1;
1550
+ if (index < 0 || this.p.reused[index] != value) {
1551
+ this.p.reused.push(value);
1552
+ index++;
1553
+ }
1554
+ let start = this.pos;
1555
+ this.reducePos = this.pos = start + value.length;
1556
+ this.pushState(next, start);
1557
+ this.buffer.push(
1558
+ index,
1559
+ start,
1560
+ this.reducePos,
1561
+ -1
1562
+ /* size == -1 means this is a reused value */
1563
+ );
1564
+ if (this.curContext)
1565
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
1566
+ }
1567
+ // Split the stack. Due to the buffer sharing and the fact
1568
+ // that `this.stack` tends to stay quite shallow, this isn't very
1569
+ // expensive.
1570
+ /// @internal
1571
+ split() {
1572
+ let parent = this;
1573
+ let off = parent.buffer.length;
1574
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
1575
+ off -= 4;
1576
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
1577
+ while (parent && base == parent.bufferBase)
1578
+ parent = parent.parent;
1579
+ return new _Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
1580
+ }
1581
+ // Try to recover from an error by 'deleting' (ignoring) one token.
1582
+ /// @internal
1583
+ recoverByDelete(next, nextEnd) {
1584
+ let isNode = next <= this.p.parser.maxNode;
1585
+ if (isNode)
1586
+ this.storeNode(next, this.pos, nextEnd, 4);
1587
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
1588
+ this.pos = this.reducePos = nextEnd;
1589
+ this.score -= 190;
1590
+ }
1591
+ /// Check if the given term would be able to be shifted (optionally
1592
+ /// after some reductions) on this stack. This can be useful for
1593
+ /// external tokenizers that want to make sure they only provide a
1594
+ /// given token when it applies.
1595
+ canShift(term) {
1596
+ for (let sim = new SimulatedStack(this); ; ) {
1597
+ let action = this.p.parser.stateSlot(
1598
+ sim.state,
1599
+ 4
1600
+ /* ParseState.DefaultReduce */
1601
+ ) || this.p.parser.hasAction(sim.state, term);
1602
+ if (action == 0)
1603
+ return false;
1604
+ if ((action & 65536) == 0)
1605
+ return true;
1606
+ sim.reduce(action);
1607
+ }
1608
+ }
1609
+ // Apply up to Recover.MaxNext recovery actions that conceptually
1610
+ // inserts some missing token or rule.
1611
+ /// @internal
1612
+ recoverByInsert(next) {
1613
+ if (this.stack.length >= 300)
1614
+ return [];
1615
+ let nextStates = this.p.parser.nextStates(this.state);
1616
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
1617
+ let best = [];
1618
+ for (let i = 0, s; i < nextStates.length; i += 2) {
1619
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
1620
+ best.push(nextStates[i], s);
1621
+ }
1622
+ if (this.stack.length < 120)
1623
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
1624
+ let s = nextStates[i + 1];
1625
+ if (!best.some((v, i2) => i2 & 1 && v == s))
1626
+ best.push(nextStates[i], s);
1627
+ }
1628
+ nextStates = best;
1629
+ }
1630
+ let result = [];
1631
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
1632
+ let s = nextStates[i + 1];
1633
+ if (s == this.state)
1634
+ continue;
1635
+ let stack = this.split();
1636
+ stack.pushState(s, this.pos);
1637
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
1638
+ stack.shiftContext(nextStates[i], this.pos);
1639
+ stack.score -= 200;
1640
+ result.push(stack);
1641
+ }
1642
+ return result;
1643
+ }
1644
+ // Force a reduce, if possible. Return false if that can't
1645
+ // be done.
1646
+ /// @internal
1647
+ forceReduce() {
1648
+ let { parser: parser2 } = this.p;
1649
+ let reduce = parser2.stateSlot(
1650
+ this.state,
1651
+ 5
1652
+ /* ParseState.ForcedReduce */
1653
+ );
1654
+ if ((reduce & 65536) == 0)
1655
+ return false;
1656
+ if (!parser2.validAction(this.state, reduce)) {
1657
+ let depth = reduce >> 19, term = reduce & 65535;
1658
+ let target = this.stack.length - depth * 3;
1659
+ if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0) {
1660
+ let backup = this.findForcedReduction();
1661
+ if (backup == null)
1662
+ return false;
1663
+ reduce = backup;
1664
+ }
1665
+ this.storeNode(0, this.pos, this.pos, 4, true);
1666
+ this.score -= 100;
1667
+ }
1668
+ this.reducePos = this.pos;
1669
+ this.reduce(reduce);
1670
+ return true;
1671
+ }
1672
+ /// Try to scan through the automaton to find some kind of reduction
1673
+ /// that can be applied. Used when the regular ForcedReduce field
1674
+ /// isn't a valid action. @internal
1675
+ findForcedReduction() {
1676
+ let { parser: parser2 } = this.p, seen = [];
1677
+ let explore = (state, depth) => {
1678
+ if (seen.includes(state))
1679
+ return;
1680
+ seen.push(state);
1681
+ return parser2.allActions(state, (action) => {
1682
+ if (action & (262144 | 131072))
1683
+ ;
1684
+ else if (action & 65536) {
1685
+ let rDepth = (action >> 19) - depth;
1686
+ if (rDepth > 1) {
1687
+ let term = action & 65535, target = this.stack.length - rDepth * 3;
1688
+ if (target >= 0 && parser2.getGoto(this.stack[target], term, false) >= 0)
1689
+ return rDepth << 19 | 65536 | term;
1690
+ }
1691
+ } else {
1692
+ let found = explore(action, depth + 1);
1693
+ if (found != null)
1694
+ return found;
1695
+ }
1696
+ });
1697
+ };
1698
+ return explore(this.state, 0);
1699
+ }
1700
+ /// @internal
1701
+ forceAll() {
1702
+ while (!this.p.parser.stateFlag(
1703
+ this.state,
1704
+ 2
1705
+ /* StateFlag.Accepting */
1706
+ )) {
1707
+ if (!this.forceReduce()) {
1708
+ this.storeNode(0, this.pos, this.pos, 4, true);
1709
+ break;
1710
+ }
1711
+ }
1712
+ return this;
1713
+ }
1714
+ /// Check whether this state has no further actions (assumed to be a direct descendant of the
1715
+ /// top state, since any other states must be able to continue
1716
+ /// somehow). @internal
1717
+ get deadEnd() {
1718
+ if (this.stack.length != 3)
1719
+ return false;
1720
+ let { parser: parser2 } = this.p;
1721
+ return parser2.data[parser2.stateSlot(
1722
+ this.state,
1723
+ 1
1724
+ /* ParseState.Actions */
1725
+ )] == 65535 && !parser2.stateSlot(
1726
+ this.state,
1727
+ 4
1728
+ /* ParseState.DefaultReduce */
1729
+ );
1730
+ }
1731
+ /// Restart the stack (put it back in its start state). Only safe
1732
+ /// when this.stack.length == 3 (state is directly below the top
1733
+ /// state). @internal
1734
+ restart() {
1735
+ this.state = this.stack[0];
1736
+ this.stack.length = 0;
1737
+ }
1738
+ /// @internal
1739
+ sameState(other) {
1740
+ if (this.state != other.state || this.stack.length != other.stack.length)
1741
+ return false;
1742
+ for (let i = 0; i < this.stack.length; i += 3)
1743
+ if (this.stack[i] != other.stack[i])
1744
+ return false;
1745
+ return true;
1746
+ }
1747
+ /// Get the parser used by this stack.
1748
+ get parser() {
1749
+ return this.p.parser;
1750
+ }
1751
+ /// Test whether a given dialect (by numeric ID, as exported from
1752
+ /// the terms file) is enabled.
1753
+ dialectEnabled(dialectID) {
1754
+ return this.p.parser.dialect.flags[dialectID];
1755
+ }
1756
+ shiftContext(term, start) {
1757
+ if (this.curContext)
1758
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
1759
+ }
1760
+ reduceContext(term, start) {
1761
+ if (this.curContext)
1762
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
1763
+ }
1764
+ /// @internal
1765
+ emitContext() {
1766
+ let last = this.buffer.length - 1;
1767
+ if (last < 0 || this.buffer[last] != -3)
1768
+ this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
1769
+ }
1770
+ /// @internal
1771
+ emitLookAhead() {
1772
+ let last = this.buffer.length - 1;
1773
+ if (last < 0 || this.buffer[last] != -4)
1774
+ this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
1775
+ }
1776
+ updateContext(context) {
1777
+ if (context != this.curContext.context) {
1778
+ let newCx = new StackContext(this.curContext.tracker, context);
1779
+ if (newCx.hash != this.curContext.hash)
1780
+ this.emitContext();
1781
+ this.curContext = newCx;
1782
+ }
1783
+ }
1784
+ /// @internal
1785
+ setLookAhead(lookAhead) {
1786
+ if (lookAhead > this.lookAhead) {
1787
+ this.emitLookAhead();
1788
+ this.lookAhead = lookAhead;
1789
+ }
1790
+ }
1791
+ /// @internal
1792
+ close() {
1793
+ if (this.curContext && this.curContext.tracker.strict)
1794
+ this.emitContext();
1795
+ if (this.lookAhead > 0)
1796
+ this.emitLookAhead();
1797
+ }
1798
+ };
1799
+ var StackContext = class {
1800
+ constructor(tracker, context) {
1801
+ this.tracker = tracker;
1802
+ this.context = context;
1803
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
1804
+ }
1805
+ };
1806
+ var Recover;
1807
+ (function(Recover2) {
1808
+ Recover2[Recover2["Insert"] = 200] = "Insert";
1809
+ Recover2[Recover2["Delete"] = 190] = "Delete";
1810
+ Recover2[Recover2["Reduce"] = 100] = "Reduce";
1811
+ Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
1812
+ Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
1813
+ Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
1814
+ Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
1815
+ })(Recover || (Recover = {}));
1816
+ var SimulatedStack = class {
1817
+ constructor(start) {
1818
+ this.start = start;
1819
+ this.state = start.state;
1820
+ this.stack = start.stack;
1821
+ this.base = this.stack.length;
1822
+ }
1823
+ reduce(action) {
1824
+ let term = action & 65535, depth = action >> 19;
1825
+ if (depth == 0) {
1826
+ if (this.stack == this.start.stack)
1827
+ this.stack = this.stack.slice();
1828
+ this.stack.push(this.state, 0, 0);
1829
+ this.base += 3;
1830
+ } else {
1831
+ this.base -= (depth - 1) * 3;
1832
+ }
1833
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
1834
+ this.state = goto;
1835
+ }
1836
+ };
1837
+ var StackBufferCursor = class _StackBufferCursor {
1838
+ constructor(stack, pos, index) {
1839
+ this.stack = stack;
1840
+ this.pos = pos;
1841
+ this.index = index;
1842
+ this.buffer = stack.buffer;
1843
+ if (this.index == 0)
1844
+ this.maybeNext();
1845
+ }
1846
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
1847
+ return new _StackBufferCursor(stack, pos, pos - stack.bufferBase);
1848
+ }
1849
+ maybeNext() {
1850
+ let next = this.stack.parent;
1851
+ if (next != null) {
1852
+ this.index = this.stack.bufferBase - next.bufferBase;
1853
+ this.stack = next;
1854
+ this.buffer = next.buffer;
1855
+ }
1856
+ }
1857
+ get id() {
1858
+ return this.buffer[this.index - 4];
1859
+ }
1860
+ get start() {
1861
+ return this.buffer[this.index - 3];
1862
+ }
1863
+ get end() {
1864
+ return this.buffer[this.index - 2];
1865
+ }
1866
+ get size() {
1867
+ return this.buffer[this.index - 1];
1868
+ }
1869
+ next() {
1870
+ this.index -= 4;
1871
+ this.pos -= 4;
1872
+ if (this.index == 0)
1873
+ this.maybeNext();
1874
+ }
1875
+ fork() {
1876
+ return new _StackBufferCursor(this.stack, this.pos, this.index);
1877
+ }
1878
+ };
1879
+ function decodeArray(input, Type = Uint16Array) {
1880
+ if (typeof input != "string")
1881
+ return input;
1882
+ let array = null;
1883
+ for (let pos = 0, out = 0; pos < input.length; ) {
1884
+ let value = 0;
1885
+ for (; ; ) {
1886
+ let next = input.charCodeAt(pos++), stop = false;
1887
+ if (next == 126) {
1888
+ value = 65535;
1889
+ break;
1890
+ }
1891
+ if (next >= 92)
1892
+ next--;
1893
+ if (next >= 34)
1894
+ next--;
1895
+ let digit = next - 32;
1896
+ if (digit >= 46) {
1897
+ digit -= 46;
1898
+ stop = true;
1899
+ }
1900
+ value += digit;
1901
+ if (stop)
1902
+ break;
1903
+ value *= 46;
1904
+ }
1905
+ if (array)
1906
+ array[out++] = value;
1907
+ else
1908
+ array = new Type(value);
1909
+ }
1910
+ return array;
1911
+ }
1912
+ var CachedToken = class {
1913
+ constructor() {
1914
+ this.start = -1;
1915
+ this.value = -1;
1916
+ this.end = -1;
1917
+ this.extended = -1;
1918
+ this.lookAhead = 0;
1919
+ this.mask = 0;
1920
+ this.context = 0;
1921
+ }
1922
+ };
1923
+ var nullToken = new CachedToken();
1924
+ var InputStream = class {
1925
+ /// @internal
1926
+ constructor(input, ranges) {
1927
+ this.input = input;
1928
+ this.ranges = ranges;
1929
+ this.chunk = "";
1930
+ this.chunkOff = 0;
1931
+ this.chunk2 = "";
1932
+ this.chunk2Pos = 0;
1933
+ this.next = -1;
1934
+ this.token = nullToken;
1935
+ this.rangeIndex = 0;
1936
+ this.pos = this.chunkPos = ranges[0].from;
1937
+ this.range = ranges[0];
1938
+ this.end = ranges[ranges.length - 1].to;
1939
+ this.readNext();
1940
+ }
1941
+ /// @internal
1942
+ resolveOffset(offset, assoc) {
1943
+ let range = this.range, index = this.rangeIndex;
1944
+ let pos = this.pos + offset;
1945
+ while (pos < range.from) {
1946
+ if (!index)
1947
+ return null;
1948
+ let next = this.ranges[--index];
1949
+ pos -= range.from - next.to;
1950
+ range = next;
1951
+ }
1952
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
1953
+ if (index == this.ranges.length - 1)
1954
+ return null;
1955
+ let next = this.ranges[++index];
1956
+ pos += next.from - range.to;
1957
+ range = next;
1958
+ }
1959
+ return pos;
1960
+ }
1961
+ /// @internal
1962
+ clipPos(pos) {
1963
+ if (pos >= this.range.from && pos < this.range.to)
1964
+ return pos;
1965
+ for (let range of this.ranges)
1966
+ if (range.to > pos)
1967
+ return Math.max(pos, range.from);
1968
+ return this.end;
1969
+ }
1970
+ /// Look at a code unit near the stream position. `.peek(0)` equals
1971
+ /// `.next`, `.peek(-1)` gives you the previous character, and so
1972
+ /// on.
1973
+ ///
1974
+ /// Note that looking around during tokenizing creates dependencies
1975
+ /// on potentially far-away content, which may reduce the
1976
+ /// effectiveness incremental parsing—when looking forward—or even
1977
+ /// cause invalid reparses when looking backward more than 25 code
1978
+ /// units, since the library does not track lookbehind.
1979
+ peek(offset) {
1980
+ let idx = this.chunkOff + offset, pos, result;
1981
+ if (idx >= 0 && idx < this.chunk.length) {
1982
+ pos = this.pos + offset;
1983
+ result = this.chunk.charCodeAt(idx);
1984
+ } else {
1985
+ let resolved = this.resolveOffset(offset, 1);
1986
+ if (resolved == null)
1987
+ return -1;
1988
+ pos = resolved;
1989
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
1990
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
1991
+ } else {
1992
+ let i = this.rangeIndex, range = this.range;
1993
+ while (range.to <= pos)
1994
+ range = this.ranges[++i];
1995
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
1996
+ if (pos + this.chunk2.length > range.to)
1997
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
1998
+ result = this.chunk2.charCodeAt(0);
1999
+ }
2000
+ }
2001
+ if (pos >= this.token.lookAhead)
2002
+ this.token.lookAhead = pos + 1;
2003
+ return result;
2004
+ }
2005
+ /// Accept a token. By default, the end of the token is set to the
2006
+ /// current stream position, but you can pass an offset (relative to
2007
+ /// the stream position) to change that.
2008
+ acceptToken(token, endOffset = 0) {
2009
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2010
+ if (end == null || end < this.token.start)
2011
+ throw new RangeError("Token end out of bounds");
2012
+ this.token.value = token;
2013
+ this.token.end = end;
2014
+ }
2015
+ getChunk() {
2016
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2017
+ let { chunk, chunkPos } = this;
2018
+ this.chunk = this.chunk2;
2019
+ this.chunkPos = this.chunk2Pos;
2020
+ this.chunk2 = chunk;
2021
+ this.chunk2Pos = chunkPos;
2022
+ this.chunkOff = this.pos - this.chunkPos;
2023
+ } else {
2024
+ this.chunk2 = this.chunk;
2025
+ this.chunk2Pos = this.chunkPos;
2026
+ let nextChunk = this.input.chunk(this.pos);
2027
+ let end = this.pos + nextChunk.length;
2028
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2029
+ this.chunkPos = this.pos;
2030
+ this.chunkOff = 0;
2031
+ }
2032
+ }
2033
+ readNext() {
2034
+ if (this.chunkOff >= this.chunk.length) {
2035
+ this.getChunk();
2036
+ if (this.chunkOff == this.chunk.length)
2037
+ return this.next = -1;
2038
+ }
2039
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
2040
+ }
2041
+ /// Move the stream forward N (defaults to 1) code units. Returns
2042
+ /// the new value of [`next`](#lr.InputStream.next).
2043
+ advance(n = 1) {
2044
+ this.chunkOff += n;
2045
+ while (this.pos + n >= this.range.to) {
2046
+ if (this.rangeIndex == this.ranges.length - 1)
2047
+ return this.setDone();
2048
+ n -= this.range.to - this.pos;
2049
+ this.range = this.ranges[++this.rangeIndex];
2050
+ this.pos = this.range.from;
2051
+ }
2052
+ this.pos += n;
2053
+ if (this.pos >= this.token.lookAhead)
2054
+ this.token.lookAhead = this.pos + 1;
2055
+ return this.readNext();
2056
+ }
2057
+ setDone() {
2058
+ this.pos = this.chunkPos = this.end;
2059
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2060
+ this.chunk = "";
2061
+ return this.next = -1;
2062
+ }
2063
+ /// @internal
2064
+ reset(pos, token) {
2065
+ if (token) {
2066
+ this.token = token;
2067
+ token.start = pos;
2068
+ token.lookAhead = pos + 1;
2069
+ token.value = token.extended = -1;
2070
+ } else {
2071
+ this.token = nullToken;
2072
+ }
2073
+ if (this.pos != pos) {
2074
+ this.pos = pos;
2075
+ if (pos == this.end) {
2076
+ this.setDone();
2077
+ return this;
2078
+ }
2079
+ while (pos < this.range.from)
2080
+ this.range = this.ranges[--this.rangeIndex];
2081
+ while (pos >= this.range.to)
2082
+ this.range = this.ranges[++this.rangeIndex];
2083
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
2084
+ this.chunkOff = pos - this.chunkPos;
2085
+ } else {
2086
+ this.chunk = "";
2087
+ this.chunkOff = 0;
2088
+ }
2089
+ this.readNext();
2090
+ }
2091
+ return this;
2092
+ }
2093
+ /// @internal
2094
+ read(from, to) {
2095
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
2096
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
2097
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
2098
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
2099
+ if (from >= this.range.from && to <= this.range.to)
2100
+ return this.input.read(from, to);
2101
+ let result = "";
2102
+ for (let r of this.ranges) {
2103
+ if (r.from >= to)
2104
+ break;
2105
+ if (r.to > from)
2106
+ result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
2107
+ }
2108
+ return result;
2109
+ }
2110
+ };
2111
+ var TokenGroup = class {
2112
+ constructor(data, id) {
2113
+ this.data = data;
2114
+ this.id = id;
2115
+ }
2116
+ token(input, stack) {
2117
+ let { parser: parser2 } = stack.p;
2118
+ readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
2119
+ }
2120
+ };
2121
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2122
+ var LocalTokenGroup = class {
2123
+ constructor(data, precTable, elseToken) {
2124
+ this.precTable = precTable;
2125
+ this.elseToken = elseToken;
2126
+ this.data = typeof data == "string" ? decodeArray(data) : data;
2127
+ }
2128
+ token(input, stack) {
2129
+ let start = input.pos, skipped = 0;
2130
+ for (; ; ) {
2131
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
2132
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
2133
+ if (input.token.value > -1)
2134
+ break;
2135
+ if (this.elseToken == null)
2136
+ return;
2137
+ if (!atEof)
2138
+ skipped++;
2139
+ if (nextPos == null)
2140
+ break;
2141
+ input.reset(nextPos, input.token);
2142
+ }
2143
+ if (skipped) {
2144
+ input.reset(start, input.token);
2145
+ input.acceptToken(this.elseToken, skipped);
2146
+ }
2147
+ }
2148
+ };
2149
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2150
+ function readToken(data, input, stack, group, precTable, precOffset) {
2151
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
2152
+ scan:
2153
+ for (; ; ) {
2154
+ if ((groupMask & data[state]) == 0)
2155
+ break;
2156
+ let accEnd = data[state + 1];
2157
+ for (let i = state + 3; i < accEnd; i += 2)
2158
+ if ((data[i + 1] & groupMask) > 0) {
2159
+ let term = data[i];
2160
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
2161
+ input.acceptToken(term);
2162
+ break;
2163
+ }
2164
+ }
2165
+ let next = input.next, low = 0, high = data[state + 2];
2166
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
2167
+ state = data[accEnd + high * 3 - 1];
2168
+ continue scan;
2169
+ }
2170
+ for (; low < high; ) {
2171
+ let mid = low + high >> 1;
2172
+ let index = accEnd + mid + (mid << 1);
2173
+ let from = data[index], to = data[index + 1] || 65536;
2174
+ if (next < from)
2175
+ high = mid;
2176
+ else if (next >= to)
2177
+ low = mid + 1;
2178
+ else {
2179
+ state = data[index + 2];
2180
+ input.advance();
2181
+ continue scan;
2182
+ }
2183
+ }
2184
+ break;
2185
+ }
2186
+ }
2187
+ function findOffset(data, start, term) {
2188
+ for (let i = start, next; (next = data[i]) != 65535; i++)
2189
+ if (next == term)
2190
+ return i - start;
2191
+ return -1;
2192
+ }
2193
+ function overrides(token, prev, tableData, tableOffset) {
2194
+ let iPrev = findOffset(tableData, tableOffset, prev);
2195
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
2196
+ }
2197
+ var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
2198
+ var stackIDs = null;
2199
+ var Safety;
2200
+ (function(Safety2) {
2201
+ Safety2[Safety2["Margin"] = 25] = "Margin";
2202
+ })(Safety || (Safety = {}));
2203
+ function cutAt(tree, pos, side) {
2204
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
2205
+ cursor.moveTo(pos);
2206
+ for (; ; ) {
2207
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
2208
+ for (; ; ) {
2209
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
2210
+ return side < 0 ? Math.max(0, Math.min(
2211
+ cursor.to - 1,
2212
+ pos - 25
2213
+ /* Safety.Margin */
2214
+ )) : Math.min(tree.length, Math.max(
2215
+ cursor.from + 1,
2216
+ pos + 25
2217
+ /* Safety.Margin */
2218
+ ));
2219
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
2220
+ break;
2221
+ if (!cursor.parent())
2222
+ return side < 0 ? 0 : tree.length;
2223
+ }
2224
+ }
2225
+ }
2226
+ var FragmentCursor = class {
2227
+ constructor(fragments, nodeSet) {
2228
+ this.fragments = fragments;
2229
+ this.nodeSet = nodeSet;
2230
+ this.i = 0;
2231
+ this.fragment = null;
2232
+ this.safeFrom = -1;
2233
+ this.safeTo = -1;
2234
+ this.trees = [];
2235
+ this.start = [];
2236
+ this.index = [];
2237
+ this.nextFragment();
2238
+ }
2239
+ nextFragment() {
2240
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
2241
+ if (fr) {
2242
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
2243
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
2244
+ while (this.trees.length) {
2245
+ this.trees.pop();
2246
+ this.start.pop();
2247
+ this.index.pop();
2248
+ }
2249
+ this.trees.push(fr.tree);
2250
+ this.start.push(-fr.offset);
2251
+ this.index.push(0);
2252
+ this.nextStart = this.safeFrom;
2253
+ } else {
2254
+ this.nextStart = 1e9;
2255
+ }
2256
+ }
2257
+ // `pos` must be >= any previously given `pos` for this cursor
2258
+ nodeAt(pos) {
2259
+ if (pos < this.nextStart)
2260
+ return null;
2261
+ while (this.fragment && this.safeTo <= pos)
2262
+ this.nextFragment();
2263
+ if (!this.fragment)
2264
+ return null;
2265
+ for (; ; ) {
2266
+ let last = this.trees.length - 1;
2267
+ if (last < 0) {
2268
+ this.nextFragment();
2269
+ return null;
2270
+ }
2271
+ let top = this.trees[last], index = this.index[last];
2272
+ if (index == top.children.length) {
2273
+ this.trees.pop();
2274
+ this.start.pop();
2275
+ this.index.pop();
2276
+ continue;
2277
+ }
2278
+ let next = top.children[index];
2279
+ let start = this.start[last] + top.positions[index];
2280
+ if (start > pos) {
2281
+ this.nextStart = start;
2282
+ return null;
2283
+ }
2284
+ if (next instanceof Tree) {
2285
+ if (start == pos) {
2286
+ if (start < this.safeFrom)
2287
+ return null;
2288
+ let end = start + next.length;
2289
+ if (end <= this.safeTo) {
2290
+ let lookAhead = next.prop(NodeProp.lookAhead);
2291
+ if (!lookAhead || end + lookAhead < this.fragment.to)
2292
+ return next;
2293
+ }
2294
+ }
2295
+ this.index[last]++;
2296
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
2297
+ this.trees.push(next);
2298
+ this.start.push(start);
2299
+ this.index.push(0);
2300
+ }
2301
+ } else {
2302
+ this.index[last]++;
2303
+ this.nextStart = start + next.length;
2304
+ }
2305
+ }
2306
+ }
2307
+ };
2308
+ var TokenCache = class {
2309
+ constructor(parser2, stream) {
2310
+ this.stream = stream;
2311
+ this.tokens = [];
2312
+ this.mainToken = null;
2313
+ this.actions = [];
2314
+ this.tokens = parser2.tokenizers.map((_) => new CachedToken());
2315
+ }
2316
+ getActions(stack) {
2317
+ let actionIndex = 0;
2318
+ let main = null;
2319
+ let { parser: parser2 } = stack.p, { tokenizers } = parser2;
2320
+ let mask = parser2.stateSlot(
2321
+ stack.state,
2322
+ 3
2323
+ /* ParseState.TokenizerMask */
2324
+ );
2325
+ let context = stack.curContext ? stack.curContext.hash : 0;
2326
+ let lookAhead = 0;
2327
+ for (let i = 0; i < tokenizers.length; i++) {
2328
+ if ((1 << i & mask) == 0)
2329
+ continue;
2330
+ let tokenizer = tokenizers[i], token = this.tokens[i];
2331
+ if (main && !tokenizer.fallback)
2332
+ continue;
2333
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
2334
+ this.updateCachedToken(token, tokenizer, stack);
2335
+ token.mask = mask;
2336
+ token.context = context;
2337
+ }
2338
+ if (token.lookAhead > token.end + 25)
2339
+ lookAhead = Math.max(token.lookAhead, lookAhead);
2340
+ if (token.value != 0) {
2341
+ let startIndex = actionIndex;
2342
+ if (token.extended > -1)
2343
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
2344
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
2345
+ if (!tokenizer.extend) {
2346
+ main = token;
2347
+ if (actionIndex > startIndex)
2348
+ break;
2349
+ }
2350
+ }
2351
+ }
2352
+ while (this.actions.length > actionIndex)
2353
+ this.actions.pop();
2354
+ if (lookAhead)
2355
+ stack.setLookAhead(lookAhead);
2356
+ if (!main && stack.pos == this.stream.end) {
2357
+ main = new CachedToken();
2358
+ main.value = stack.p.parser.eofTerm;
2359
+ main.start = main.end = stack.pos;
2360
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
2361
+ }
2362
+ this.mainToken = main;
2363
+ return this.actions;
2364
+ }
2365
+ getMainToken(stack) {
2366
+ if (this.mainToken)
2367
+ return this.mainToken;
2368
+ let main = new CachedToken(), { pos, p } = stack;
2369
+ main.start = pos;
2370
+ main.end = Math.min(pos + 1, p.stream.end);
2371
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
2372
+ return main;
2373
+ }
2374
+ updateCachedToken(token, tokenizer, stack) {
2375
+ let start = this.stream.clipPos(stack.pos);
2376
+ tokenizer.token(this.stream.reset(start, token), stack);
2377
+ if (token.value > -1) {
2378
+ let { parser: parser2 } = stack.p;
2379
+ for (let i = 0; i < parser2.specialized.length; i++)
2380
+ if (parser2.specialized[i] == token.value) {
2381
+ let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
2382
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
2383
+ if ((result & 1) == 0)
2384
+ token.value = result >> 1;
2385
+ else
2386
+ token.extended = result >> 1;
2387
+ break;
2388
+ }
2389
+ }
2390
+ } else {
2391
+ token.value = 0;
2392
+ token.end = this.stream.clipPos(start + 1);
2393
+ }
2394
+ }
2395
+ putAction(action, token, end, index) {
2396
+ for (let i = 0; i < index; i += 3)
2397
+ if (this.actions[i] == action)
2398
+ return index;
2399
+ this.actions[index++] = action;
2400
+ this.actions[index++] = token;
2401
+ this.actions[index++] = end;
2402
+ return index;
2403
+ }
2404
+ addActions(stack, token, end, index) {
2405
+ let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
2406
+ for (let set = 0; set < 2; set++) {
2407
+ for (let i = parser2.stateSlot(
2408
+ state,
2409
+ set ? 2 : 1
2410
+ /* ParseState.Actions */
2411
+ ); ; i += 3) {
2412
+ if (data[i] == 65535) {
2413
+ if (data[i + 1] == 1) {
2414
+ i = pair(data, i + 2);
2415
+ } else {
2416
+ if (index == 0 && data[i + 1] == 2)
2417
+ index = this.putAction(pair(data, i + 2), token, end, index);
2418
+ break;
2419
+ }
2420
+ }
2421
+ if (data[i] == token)
2422
+ index = this.putAction(pair(data, i + 1), token, end, index);
2423
+ }
2424
+ }
2425
+ return index;
2426
+ }
2427
+ };
2428
+ var Rec;
2429
+ (function(Rec2) {
2430
+ Rec2[Rec2["Distance"] = 5] = "Distance";
2431
+ Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
2432
+ Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
2433
+ Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
2434
+ Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
2435
+ Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
2436
+ Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
2437
+ Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
2438
+ })(Rec || (Rec = {}));
2439
+ var Parse = class {
2440
+ constructor(parser2, input, fragments, ranges) {
2441
+ this.parser = parser2;
2442
+ this.input = input;
2443
+ this.ranges = ranges;
2444
+ this.recovering = 0;
2445
+ this.nextStackID = 9812;
2446
+ this.minStackPos = 0;
2447
+ this.reused = [];
2448
+ this.stoppedAt = null;
2449
+ this.lastBigReductionStart = -1;
2450
+ this.lastBigReductionSize = 0;
2451
+ this.bigReductionCount = 0;
2452
+ this.stream = new InputStream(input, ranges);
2453
+ this.tokens = new TokenCache(parser2, this.stream);
2454
+ this.topTerm = parser2.top[1];
2455
+ let { from } = ranges[0];
2456
+ this.stacks = [Stack.start(this, parser2.top[0], from)];
2457
+ this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
2458
+ }
2459
+ get parsedPos() {
2460
+ return this.minStackPos;
2461
+ }
2462
+ // Move the parser forward. This will process all parse stacks at
2463
+ // `this.pos` and try to advance them to a further position. If no
2464
+ // stack for such a position is found, it'll start error-recovery.
2465
+ //
2466
+ // When the parse is finished, this will return a syntax tree. When
2467
+ // not, it returns `null`.
2468
+ advance() {
2469
+ let stacks = this.stacks, pos = this.minStackPos;
2470
+ let newStacks = this.stacks = [];
2471
+ let stopped, stoppedTokens;
2472
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
2473
+ let [s] = stacks;
2474
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
2475
+ }
2476
+ this.bigReductionCount = this.lastBigReductionSize = 0;
2477
+ }
2478
+ for (let i = 0; i < stacks.length; i++) {
2479
+ let stack = stacks[i];
2480
+ for (; ; ) {
2481
+ this.tokens.mainToken = null;
2482
+ if (stack.pos > pos) {
2483
+ newStacks.push(stack);
2484
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
2485
+ continue;
2486
+ } else {
2487
+ if (!stopped) {
2488
+ stopped = [];
2489
+ stoppedTokens = [];
2490
+ }
2491
+ stopped.push(stack);
2492
+ let tok = this.tokens.getMainToken(stack);
2493
+ stoppedTokens.push(tok.value, tok.end);
2494
+ }
2495
+ break;
2496
+ }
2497
+ }
2498
+ if (!newStacks.length) {
2499
+ let finished = stopped && findFinished(stopped);
2500
+ if (finished)
2501
+ return this.stackToTree(finished);
2502
+ if (this.parser.strict) {
2503
+ if (verbose && stopped)
2504
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
2505
+ throw new SyntaxError("No parse at " + pos);
2506
+ }
2507
+ if (!this.recovering)
2508
+ this.recovering = 5;
2509
+ }
2510
+ if (this.recovering && stopped) {
2511
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
2512
+ if (finished)
2513
+ return this.stackToTree(finished.forceAll());
2514
+ }
2515
+ if (this.recovering) {
2516
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
2517
+ if (newStacks.length > maxRemaining) {
2518
+ newStacks.sort((a, b) => b.score - a.score);
2519
+ while (newStacks.length > maxRemaining)
2520
+ newStacks.pop();
2521
+ }
2522
+ if (newStacks.some((s) => s.reducePos > pos))
2523
+ this.recovering--;
2524
+ } else if (newStacks.length > 1) {
2525
+ outer:
2526
+ for (let i = 0; i < newStacks.length - 1; i++) {
2527
+ let stack = newStacks[i];
2528
+ for (let j = i + 1; j < newStacks.length; j++) {
2529
+ let other = newStacks[j];
2530
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
2531
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
2532
+ newStacks.splice(j--, 1);
2533
+ } else {
2534
+ newStacks.splice(i--, 1);
2535
+ continue outer;
2536
+ }
2537
+ }
2538
+ }
2539
+ }
2540
+ if (newStacks.length > 12)
2541
+ newStacks.splice(
2542
+ 12,
2543
+ newStacks.length - 12
2544
+ /* Rec.MaxStackCount */
2545
+ );
2546
+ }
2547
+ this.minStackPos = newStacks[0].pos;
2548
+ for (let i = 1; i < newStacks.length; i++)
2549
+ if (newStacks[i].pos < this.minStackPos)
2550
+ this.minStackPos = newStacks[i].pos;
2551
+ return null;
2552
+ }
2553
+ stopAt(pos) {
2554
+ if (this.stoppedAt != null && this.stoppedAt < pos)
2555
+ throw new RangeError("Can't move stoppedAt forward");
2556
+ this.stoppedAt = pos;
2557
+ }
2558
+ // Returns an updated version of the given stack, or null if the
2559
+ // stack can't advance normally. When `split` and `stacks` are
2560
+ // given, stacks split off by ambiguous operations will be pushed to
2561
+ // `split`, or added to `stacks` if they move `pos` forward.
2562
+ advanceStack(stack, stacks, split) {
2563
+ let start = stack.pos, { parser: parser2 } = this;
2564
+ let base = verbose ? this.stackID(stack) + " -> " : "";
2565
+ if (this.stoppedAt != null && start > this.stoppedAt)
2566
+ return stack.forceReduce() ? stack : null;
2567
+ if (this.fragments) {
2568
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
2569
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
2570
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
2571
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
2572
+ stack.useNode(cached, match);
2573
+ if (verbose)
2574
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
2575
+ return true;
2576
+ }
2577
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
2578
+ break;
2579
+ let inner = cached.children[0];
2580
+ if (inner instanceof Tree && cached.positions[0] == 0)
2581
+ cached = inner;
2582
+ else
2583
+ break;
2584
+ }
2585
+ }
2586
+ let defaultReduce = parser2.stateSlot(
2587
+ stack.state,
2588
+ 4
2589
+ /* ParseState.DefaultReduce */
2590
+ );
2591
+ if (defaultReduce > 0) {
2592
+ stack.reduce(defaultReduce);
2593
+ if (verbose)
2594
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
2595
+ defaultReduce & 65535
2596
+ /* Action.ValueMask */
2597
+ )})`);
2598
+ return true;
2599
+ }
2600
+ if (stack.stack.length >= 15e3) {
2601
+ while (stack.stack.length > 9e3 && stack.forceReduce()) {
2602
+ }
2603
+ }
2604
+ let actions = this.tokens.getActions(stack);
2605
+ for (let i = 0; i < actions.length; ) {
2606
+ let action = actions[i++], term = actions[i++], end = actions[i++];
2607
+ let last = i == actions.length || !split;
2608
+ let localStack = last ? stack : stack.split();
2609
+ localStack.apply(action, term, end);
2610
+ if (verbose)
2611
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
2612
+ action & 65535
2613
+ /* Action.ValueMask */
2614
+ )}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
2615
+ if (last)
2616
+ return true;
2617
+ else if (localStack.pos > start)
2618
+ stacks.push(localStack);
2619
+ else
2620
+ split.push(localStack);
2621
+ }
2622
+ return false;
2623
+ }
2624
+ // Advance a given stack forward as far as it will go. Returns the
2625
+ // (possibly updated) stack if it got stuck, or null if it moved
2626
+ // forward and was given to `pushStackDedup`.
2627
+ advanceFully(stack, newStacks) {
2628
+ let pos = stack.pos;
2629
+ for (; ; ) {
2630
+ if (!this.advanceStack(stack, null, null))
2631
+ return false;
2632
+ if (stack.pos > pos) {
2633
+ pushStackDedup(stack, newStacks);
2634
+ return true;
2635
+ }
2636
+ }
2637
+ }
2638
+ runRecovery(stacks, tokens, newStacks) {
2639
+ let finished = null, restarted = false;
2640
+ for (let i = 0; i < stacks.length; i++) {
2641
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
2642
+ let base = verbose ? this.stackID(stack) + " -> " : "";
2643
+ if (stack.deadEnd) {
2644
+ if (restarted)
2645
+ continue;
2646
+ restarted = true;
2647
+ stack.restart();
2648
+ if (verbose)
2649
+ console.log(base + this.stackID(stack) + " (restarted)");
2650
+ let done = this.advanceFully(stack, newStacks);
2651
+ if (done)
2652
+ continue;
2653
+ }
2654
+ let force = stack.split(), forceBase = base;
2655
+ for (let j = 0; force.forceReduce() && j < 10; j++) {
2656
+ if (verbose)
2657
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
2658
+ let done = this.advanceFully(force, newStacks);
2659
+ if (done)
2660
+ break;
2661
+ if (verbose)
2662
+ forceBase = this.stackID(force) + " -> ";
2663
+ }
2664
+ for (let insert of stack.recoverByInsert(token)) {
2665
+ if (verbose)
2666
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
2667
+ this.advanceFully(insert, newStacks);
2668
+ }
2669
+ if (this.stream.end > stack.pos) {
2670
+ if (tokenEnd == stack.pos) {
2671
+ tokenEnd++;
2672
+ token = 0;
2673
+ }
2674
+ stack.recoverByDelete(token, tokenEnd);
2675
+ if (verbose)
2676
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
2677
+ pushStackDedup(stack, newStacks);
2678
+ } else if (!finished || finished.score < stack.score) {
2679
+ finished = stack;
2680
+ }
2681
+ }
2682
+ return finished;
2683
+ }
2684
+ // Convert the stack's buffer to a syntax tree.
2685
+ stackToTree(stack) {
2686
+ stack.close();
2687
+ return Tree.build({
2688
+ buffer: StackBufferCursor.create(stack),
2689
+ nodeSet: this.parser.nodeSet,
2690
+ topID: this.topTerm,
2691
+ maxBufferLength: this.parser.bufferLength,
2692
+ reused: this.reused,
2693
+ start: this.ranges[0].from,
2694
+ length: stack.pos - this.ranges[0].from,
2695
+ minRepeatType: this.parser.minRepeatTerm
2696
+ });
2697
+ }
2698
+ stackID(stack) {
2699
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
2700
+ if (!id)
2701
+ stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
2702
+ return id + stack;
2703
+ }
2704
+ };
2705
+ function pushStackDedup(stack, newStacks) {
2706
+ for (let i = 0; i < newStacks.length; i++) {
2707
+ let other = newStacks[i];
2708
+ if (other.pos == stack.pos && other.sameState(stack)) {
2709
+ if (newStacks[i].score < stack.score)
2710
+ newStacks[i] = stack;
2711
+ return;
2712
+ }
2713
+ }
2714
+ newStacks.push(stack);
2715
+ }
2716
+ var Dialect = class {
2717
+ constructor(source, flags, disabled) {
2718
+ this.source = source;
2719
+ this.flags = flags;
2720
+ this.disabled = disabled;
2721
+ }
2722
+ allows(term) {
2723
+ return !this.disabled || this.disabled[term] == 0;
2724
+ }
2725
+ };
2726
+ var LRParser = class _LRParser extends Parser {
2727
+ /// @internal
2728
+ constructor(spec) {
2729
+ super();
2730
+ this.wrappers = [];
2731
+ if (spec.version != 14)
2732
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
2733
+ let nodeNames = spec.nodeNames.split(" ");
2734
+ this.minRepeatTerm = nodeNames.length;
2735
+ for (let i = 0; i < spec.repeatNodeCount; i++)
2736
+ nodeNames.push("");
2737
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
2738
+ let nodeProps = [];
2739
+ for (let i = 0; i < nodeNames.length; i++)
2740
+ nodeProps.push([]);
2741
+ function setProp(nodeID, prop, value) {
2742
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
2743
+ }
2744
+ if (spec.nodeProps)
2745
+ for (let propSpec of spec.nodeProps) {
2746
+ let prop = propSpec[0];
2747
+ if (typeof prop == "string")
2748
+ prop = NodeProp[prop];
2749
+ for (let i = 1; i < propSpec.length; ) {
2750
+ let next = propSpec[i++];
2751
+ if (next >= 0) {
2752
+ setProp(next, prop, propSpec[i++]);
2753
+ } else {
2754
+ let value = propSpec[i + -next];
2755
+ for (let j = -next; j > 0; j--)
2756
+ setProp(propSpec[i++], prop, value);
2757
+ i++;
2758
+ }
2759
+ }
2760
+ }
2761
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
2762
+ name: i >= this.minRepeatTerm ? void 0 : name,
2763
+ id: i,
2764
+ props: nodeProps[i],
2765
+ top: topTerms.indexOf(i) > -1,
2766
+ error: i == 0,
2767
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
2768
+ })));
2769
+ if (spec.propSources)
2770
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
2771
+ this.strict = false;
2772
+ this.bufferLength = DefaultBufferLength;
2773
+ let tokenArray = decodeArray(spec.tokenData);
2774
+ this.context = spec.context;
2775
+ this.specializerSpecs = spec.specialized || [];
2776
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
2777
+ for (let i = 0; i < this.specializerSpecs.length; i++)
2778
+ this.specialized[i] = this.specializerSpecs[i].term;
2779
+ this.specializers = this.specializerSpecs.map(getSpecializer);
2780
+ this.states = decodeArray(spec.states, Uint32Array);
2781
+ this.data = decodeArray(spec.stateData);
2782
+ this.goto = decodeArray(spec.goto);
2783
+ this.maxTerm = spec.maxTerm;
2784
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
2785
+ this.topRules = spec.topRules;
2786
+ this.dialects = spec.dialects || {};
2787
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
2788
+ this.tokenPrecTable = spec.tokenPrec;
2789
+ this.termNames = spec.termNames || null;
2790
+ this.maxNode = this.nodeSet.types.length - 1;
2791
+ this.dialect = this.parseDialect();
2792
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
2793
+ }
2794
+ createParse(input, fragments, ranges) {
2795
+ let parse = new Parse(this, input, fragments, ranges);
2796
+ for (let w of this.wrappers)
2797
+ parse = w(parse, input, fragments, ranges);
2798
+ return parse;
2799
+ }
2800
+ /// Get a goto table entry @internal
2801
+ getGoto(state, term, loose = false) {
2802
+ let table = this.goto;
2803
+ if (term >= table[0])
2804
+ return -1;
2805
+ for (let pos = table[term + 1]; ; ) {
2806
+ let groupTag = table[pos++], last = groupTag & 1;
2807
+ let target = table[pos++];
2808
+ if (last && loose)
2809
+ return target;
2810
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
2811
+ if (table[pos] == state)
2812
+ return target;
2813
+ if (last)
2814
+ return -1;
2815
+ }
2816
+ }
2817
+ /// Check if this state has an action for a given terminal @internal
2818
+ hasAction(state, terminal) {
2819
+ let data = this.data;
2820
+ for (let set = 0; set < 2; set++) {
2821
+ for (let i = this.stateSlot(
2822
+ state,
2823
+ set ? 2 : 1
2824
+ /* ParseState.Actions */
2825
+ ), next; ; i += 3) {
2826
+ if ((next = data[i]) == 65535) {
2827
+ if (data[i + 1] == 1)
2828
+ next = data[i = pair(data, i + 2)];
2829
+ else if (data[i + 1] == 2)
2830
+ return pair(data, i + 2);
2831
+ else
2832
+ break;
2833
+ }
2834
+ if (next == terminal || next == 0)
2835
+ return pair(data, i + 1);
2836
+ }
2837
+ }
2838
+ return 0;
2839
+ }
2840
+ /// @internal
2841
+ stateSlot(state, slot) {
2842
+ return this.states[state * 6 + slot];
2843
+ }
2844
+ /// @internal
2845
+ stateFlag(state, flag) {
2846
+ return (this.stateSlot(
2847
+ state,
2848
+ 0
2849
+ /* ParseState.Flags */
2850
+ ) & flag) > 0;
2851
+ }
2852
+ /// @internal
2853
+ validAction(state, action) {
2854
+ return !!this.allActions(state, (a) => a == action ? true : null);
2855
+ }
2856
+ /// @internal
2857
+ allActions(state, action) {
2858
+ let deflt = this.stateSlot(
2859
+ state,
2860
+ 4
2861
+ /* ParseState.DefaultReduce */
2862
+ );
2863
+ let result = deflt ? action(deflt) : void 0;
2864
+ for (let i = this.stateSlot(
2865
+ state,
2866
+ 1
2867
+ /* ParseState.Actions */
2868
+ ); result == null; i += 3) {
2869
+ if (this.data[i] == 65535) {
2870
+ if (this.data[i + 1] == 1)
2871
+ i = pair(this.data, i + 2);
2872
+ else
2873
+ break;
2874
+ }
2875
+ result = action(pair(this.data, i + 1));
2876
+ }
2877
+ return result;
2878
+ }
2879
+ /// Get the states that can follow this one through shift actions or
2880
+ /// goto jumps. @internal
2881
+ nextStates(state) {
2882
+ let result = [];
2883
+ for (let i = this.stateSlot(
2884
+ state,
2885
+ 1
2886
+ /* ParseState.Actions */
2887
+ ); ; i += 3) {
2888
+ if (this.data[i] == 65535) {
2889
+ if (this.data[i + 1] == 1)
2890
+ i = pair(this.data, i + 2);
2891
+ else
2892
+ break;
2893
+ }
2894
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
2895
+ let value = this.data[i + 1];
2896
+ if (!result.some((v, i2) => i2 & 1 && v == value))
2897
+ result.push(this.data[i], value);
2898
+ }
2899
+ }
2900
+ return result;
2901
+ }
2902
+ /// Configure the parser. Returns a new parser instance that has the
2903
+ /// given settings modified. Settings not provided in `config` are
2904
+ /// kept from the original parser.
2905
+ configure(config) {
2906
+ let copy = Object.assign(Object.create(_LRParser.prototype), this);
2907
+ if (config.props)
2908
+ copy.nodeSet = this.nodeSet.extend(...config.props);
2909
+ if (config.top) {
2910
+ let info = this.topRules[config.top];
2911
+ if (!info)
2912
+ throw new RangeError(`Invalid top rule name ${config.top}`);
2913
+ copy.top = info;
2914
+ }
2915
+ if (config.tokenizers)
2916
+ copy.tokenizers = this.tokenizers.map((t) => {
2917
+ let found = config.tokenizers.find((r) => r.from == t);
2918
+ return found ? found.to : t;
2919
+ });
2920
+ if (config.specializers) {
2921
+ copy.specializers = this.specializers.slice();
2922
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
2923
+ let found = config.specializers.find((r) => r.from == s.external);
2924
+ if (!found)
2925
+ return s;
2926
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
2927
+ copy.specializers[i] = getSpecializer(spec);
2928
+ return spec;
2929
+ });
2930
+ }
2931
+ if (config.contextTracker)
2932
+ copy.context = config.contextTracker;
2933
+ if (config.dialect)
2934
+ copy.dialect = this.parseDialect(config.dialect);
2935
+ if (config.strict != null)
2936
+ copy.strict = config.strict;
2937
+ if (config.wrap)
2938
+ copy.wrappers = copy.wrappers.concat(config.wrap);
2939
+ if (config.bufferLength != null)
2940
+ copy.bufferLength = config.bufferLength;
2941
+ return copy;
2942
+ }
2943
+ /// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
2944
+ /// are registered for this parser.
2945
+ hasWrappers() {
2946
+ return this.wrappers.length > 0;
2947
+ }
2948
+ /// Returns the name associated with a given term. This will only
2949
+ /// work for all terms when the parser was generated with the
2950
+ /// `--names` option. By default, only the names of tagged terms are
2951
+ /// stored.
2952
+ getName(term) {
2953
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
2954
+ }
2955
+ /// The eof term id is always allocated directly after the node
2956
+ /// types. @internal
2957
+ get eofTerm() {
2958
+ return this.maxNode + 1;
2959
+ }
2960
+ /// The type of top node produced by the parser.
2961
+ get topNode() {
2962
+ return this.nodeSet.types[this.top[1]];
2963
+ }
2964
+ /// @internal
2965
+ dynamicPrecedence(term) {
2966
+ let prec = this.dynamicPrecedences;
2967
+ return prec == null ? 0 : prec[term] || 0;
2968
+ }
2969
+ /// @internal
2970
+ parseDialect(dialect) {
2971
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
2972
+ if (dialect)
2973
+ for (let part of dialect.split(" ")) {
2974
+ let id = values.indexOf(part);
2975
+ if (id >= 0)
2976
+ flags[id] = true;
2977
+ }
2978
+ let disabled = null;
2979
+ for (let i = 0; i < values.length; i++)
2980
+ if (!flags[i]) {
2981
+ for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
2982
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
2983
+ }
2984
+ return new Dialect(dialect, flags, disabled);
2985
+ }
2986
+ /// Used by the output of the parser generator. Not available to
2987
+ /// user code. @hide
2988
+ static deserialize(spec) {
2989
+ return new _LRParser(spec);
2990
+ }
2991
+ };
2992
+ function pair(data, off) {
2993
+ return data[off] | data[off + 1] << 16;
2994
+ }
2995
+ function findFinished(stacks) {
2996
+ let best = null;
2997
+ for (let stack of stacks) {
2998
+ let stopped = stack.p.stoppedAt;
2999
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
3000
+ stack.state,
3001
+ 2
3002
+ /* StateFlag.Accepting */
3003
+ ) && (!best || best.score < stack.score))
3004
+ best = stack;
3005
+ }
3006
+ return best;
3007
+ }
3008
+ function getSpecializer(spec) {
3009
+ if (spec.external) {
3010
+ let mask = spec.extend ? 1 : 0;
3011
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
3012
+ }
3013
+ return spec.get;
3014
+ }
3015
+
3016
+ // ../vuu-filter-parser/src/generated/filter-parser.js
3017
+ var parser = LRParser.deserialize({
3018
+ version: 14,
3019
+ states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
3020
+ stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
3021
+ goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
3022
+ nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
3023
+ maxTerm: 39,
3024
+ skippedNodes: [0],
3025
+ repeatNodeCount: 1,
3026
+ tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
3027
+ tokenizers: [0, 1],
3028
+ topRules: { "Filter": [0, 1] },
3029
+ tokenPrec: 0
3030
+ });
3031
+
3032
+ // ../vuu-filter-parser/src/FilterTreeWalker.ts
3033
+ import {
3034
+ isMultiClauseFilter,
3035
+ isMultiValueFilter,
3036
+ isSingleValueFilter
3037
+ } from "@vuu-ui/vuu-utils";
3038
+
3039
+ // ../vuu-filter-parser/src/FilterParser.ts
3040
+ var strictParser = parser.configure({ strict: true });
3041
+
3042
+ // ../vuu-data-local/src/array-data-source/array-data-source.ts
3043
+ import {
3044
+ buildColumnMap,
3045
+ configChanged,
3046
+ EventEmitter,
3047
+ getAddedItems,
3048
+ getMissingItems,
3049
+ groupByChanged,
3050
+ hasFilter,
3051
+ hasGroupBy,
3052
+ hasSort,
3053
+ KeySet as KeySet2,
3054
+ logger,
3055
+ metadataKeys as metadataKeys3,
3056
+ NULL_RANGE,
3057
+ rangeNewItems,
3058
+ resetRange,
3059
+ uuid,
3060
+ vanillaConfig,
3061
+ withConfigDefaults
3062
+ } from "@vuu-ui/vuu-utils";
3063
+
3064
+ // ../vuu-data-local/src/array-data-source/array-data-utils.ts
3065
+ import {
3066
+ getSelectionStatus,
3067
+ metadataKeys
3068
+ } from "@vuu-ui/vuu-utils";
3069
+ var { RENDER_IDX, SELECTED } = metadataKeys;
3070
+
3071
+ // ../vuu-data-local/src/array-data-source/group-utils.ts
3072
+ import { metadataKeys as metadataKeys2 } from "@vuu-ui/vuu-utils";
3073
+ var { DEPTH, IS_EXPANDED, KEY } = metadataKeys2;
3074
+
3075
+ // ../vuu-data-local/src/array-data-source/array-data-source.ts
3076
+ var { KEY: KEY2 } = metadataKeys3;
3077
+ var { debug } = logger("ArrayDataSource");
3078
+
3079
+ // ../vuu-data-local/src/json-data-source/json-data-source.ts
3080
+ import {
3081
+ EventEmitter as EventEmitter2,
3082
+ isSelected,
3083
+ jsonToDataSourceRows,
3084
+ KeySet as KeySet3,
3085
+ metadataKeys as metadataKeys4,
3086
+ uuid as uuid2,
3087
+ vanillaConfig as vanillaConfig2
3088
+ } from "@vuu-ui/vuu-utils";
3089
+ var NULL_SCHEMA = { columns: [], key: "", table: { module: "", table: "" } };
3090
+ var { DEPTH: DEPTH2, IDX, IS_EXPANDED: IS_EXPANDED2, IS_LEAF, KEY: KEY3, SELECTED: SELECTED2 } = metadataKeys4;
3091
+ var toClientRow2 = (row, keys) => {
3092
+ const [rowIndex] = row;
3093
+ const clientRow = row.slice();
3094
+ clientRow[1] = keys.keyFor(rowIndex);
3095
+ return clientRow;
3096
+ };
3097
+ var _aggregations, _config, _data, _filter, _groupBy, _range, _selectedRowsCount, _size, _sort, _status, _title;
3098
+ var JsonDataSource = class extends EventEmitter2 {
3099
+ constructor({
3100
+ aggregations,
3101
+ data,
3102
+ filter,
3103
+ groupBy,
3104
+ sort,
3105
+ title,
3106
+ viewport
3107
+ }) {
3108
+ super();
3109
+ this.expandedRows = /* @__PURE__ */ new Set();
3110
+ this.visibleRows = [];
3111
+ __privateAdd(this, _aggregations, []);
3112
+ __privateAdd(this, _config, vanillaConfig2);
3113
+ __privateAdd(this, _data, void 0);
3114
+ __privateAdd(this, _filter, { filter: "" });
3115
+ __privateAdd(this, _groupBy, []);
3116
+ __privateAdd(this, _range, { from: 0, to: 0 });
3117
+ __privateAdd(this, _selectedRowsCount, 0);
3118
+ __privateAdd(this, _size, 0);
3119
+ __privateAdd(this, _sort, { sortDefs: [] });
3120
+ __privateAdd(this, _status, "initialising");
3121
+ __privateAdd(this, _title, void 0);
3122
+ this.keys = new KeySet3(__privateGet(this, _range));
3123
+ if (!data) {
3124
+ throw Error("JsonDataSource constructor called without data");
3125
+ }
3126
+ [this.columnDescriptors, __privateWrapper(this, _data)._] = jsonToDataSourceRows(data);
3127
+ this.visibleRows = __privateGet(this, _data).filter((row) => row[DEPTH2] === 0).map(
3128
+ (row, index) => [index, index].concat(row.slice(2))
3129
+ );
3130
+ this.viewport = viewport || uuid2();
3131
+ if (aggregations) {
3132
+ __privateSet(this, _aggregations, aggregations);
3133
+ }
3134
+ if (this.columnDescriptors) {
3135
+ __privateSet(this, _config, {
3136
+ ...__privateGet(this, _config),
3137
+ columns: this.columnDescriptors.map((c) => c.name)
3138
+ });
3139
+ }
3140
+ if (filter) {
3141
+ __privateSet(this, _filter, filter);
3142
+ }
3143
+ if (groupBy) {
3144
+ __privateSet(this, _groupBy, groupBy);
3145
+ }
3146
+ if (sort) {
3147
+ __privateSet(this, _sort, sort);
3148
+ }
3149
+ __privateSet(this, _title, title);
3150
+ }
3151
+ async subscribe({
3152
+ viewport = ((_a) => (_a = this.viewport) != null ? _a : uuid2())(),
3153
+ columns,
3154
+ aggregations,
3155
+ range,
3156
+ sort,
3157
+ groupBy,
3158
+ filter
3159
+ }, callback) {
3160
+ var _a2;
3161
+ this.clientCallback = callback;
3162
+ if (aggregations) {
3163
+ __privateSet(this, _aggregations, aggregations);
3164
+ }
3165
+ if (columns) {
3166
+ __privateSet(this, _config, {
3167
+ ...__privateGet(this, _config),
3168
+ columns
3169
+ });
3170
+ }
3171
+ if (filter) {
3172
+ __privateSet(this, _filter, filter);
3173
+ }
3174
+ if (groupBy) {
3175
+ __privateSet(this, _groupBy, groupBy);
3176
+ }
3177
+ if (range) {
3178
+ __privateSet(this, _range, range);
3179
+ }
3180
+ if (sort) {
3181
+ __privateSet(this, _sort, sort);
3182
+ }
3183
+ if (__privateGet(this, _status) !== "initialising") {
3184
+ return;
3185
+ }
3186
+ this.viewport = viewport;
3187
+ __privateSet(this, _status, "subscribed");
3188
+ (_a2 = this.clientCallback) == null ? void 0 : _a2.call(this, {
3189
+ aggregations: __privateGet(this, _aggregations),
3190
+ type: "subscribed",
3191
+ clientViewportId: this.viewport,
3192
+ columns: __privateGet(this, _config).columns,
3193
+ filter: __privateGet(this, _filter),
3194
+ groupBy: __privateGet(this, _groupBy),
3195
+ range: __privateGet(this, _range),
3196
+ sort: __privateGet(this, _sort),
3197
+ tableSchema: NULL_SCHEMA
3198
+ });
3199
+ this.clientCallback({
3200
+ clientViewportId: this.viewport,
3201
+ mode: "size-only",
3202
+ type: "viewport-update",
3203
+ size: this.visibleRows.length
3204
+ });
3205
+ }
3206
+ unsubscribe() {
3207
+ console.log("noop");
3208
+ }
3209
+ suspend() {
3210
+ console.log("noop");
3211
+ return this;
3212
+ }
3213
+ resume() {
3214
+ console.log("noop");
3215
+ return this;
3216
+ }
3217
+ disable() {
3218
+ console.log("noop");
3219
+ return this;
3220
+ }
3221
+ enable() {
3222
+ console.log("noop");
3223
+ return this;
3224
+ }
3225
+ set data(data) {
3226
+ console.log(`set JsonDataSource data`);
3227
+ [this.columnDescriptors, __privateWrapper(this, _data)._] = jsonToDataSourceRows(data);
3228
+ this.visibleRows = __privateGet(this, _data).filter((row) => row[DEPTH2] === 0).map(
3229
+ (row, index) => [index, index].concat(row.slice(2))
3230
+ );
3231
+ requestAnimationFrame(() => {
3232
+ this.sendRowsToClient();
3233
+ });
3234
+ }
3235
+ select(selected) {
3236
+ var _a;
3237
+ const updatedRows = [];
3238
+ for (const row of __privateGet(this, _data)) {
3239
+ const { [IDX]: rowIndex, [SELECTED2]: sel } = row;
3240
+ const wasSelected = sel === 1;
3241
+ const nowSelected = isSelected(selected, rowIndex);
3242
+ if (nowSelected !== wasSelected) {
3243
+ const selectedRow = row.slice();
3244
+ selectedRow[SELECTED2] = nowSelected ? 1 : 0;
3245
+ __privateGet(this, _data)[rowIndex] = selectedRow;
3246
+ updatedRows.push(selectedRow);
3247
+ }
3248
+ }
3249
+ if (updatedRows.length > 0) {
3250
+ (_a = this.clientCallback) == null ? void 0 : _a.call(this, {
3251
+ clientViewportId: this.viewport,
3252
+ mode: "update",
3253
+ type: "viewport-update",
3254
+ rows: updatedRows
3255
+ });
3256
+ }
3257
+ }
3258
+ openTreeNode(key) {
3259
+ var _a;
3260
+ this.expandedRows.add(key);
3261
+ this.visibleRows = getVisibleRows(__privateGet(this, _data), this.expandedRows);
3262
+ const { from, to } = __privateGet(this, _range);
3263
+ (_a = this.clientCallback) == null ? void 0 : _a.call(this, {
3264
+ clientViewportId: this.viewport,
3265
+ mode: "batch",
3266
+ rows: this.visibleRows.slice(from, to).map((row) => toClientRow2(row, this.keys)),
3267
+ size: this.visibleRows.length,
3268
+ type: "viewport-update"
3269
+ });
3270
+ }
3271
+ closeTreeNode(key, cascade = false) {
3272
+ this.expandedRows.delete(key);
3273
+ if (cascade) {
3274
+ for (const rowKey of this.expandedRows.keys()) {
3275
+ if (rowKey.startsWith(key)) {
3276
+ this.expandedRows.delete(rowKey);
3277
+ }
3278
+ }
3279
+ }
3280
+ this.visibleRows = getVisibleRows(__privateGet(this, _data), this.expandedRows);
3281
+ this.sendRowsToClient();
3282
+ }
3283
+ get status() {
3284
+ return __privateGet(this, _status);
3285
+ }
3286
+ get config() {
3287
+ return __privateGet(this, _config);
3288
+ }
3289
+ applyConfig() {
3290
+ return true;
3291
+ }
3292
+ get selectedRowsCount() {
3293
+ return __privateGet(this, _selectedRowsCount);
3294
+ }
3295
+ get size() {
3296
+ return __privateGet(this, _size);
3297
+ }
3298
+ get range() {
3299
+ return __privateGet(this, _range);
3300
+ }
3301
+ set range(range) {
3302
+ __privateSet(this, _range, range);
3303
+ this.keys.reset(range);
3304
+ requestAnimationFrame(() => {
3305
+ this.sendRowsToClient();
3306
+ });
3307
+ }
3308
+ sendRowsToClient() {
3309
+ var _a;
3310
+ const { from, to } = __privateGet(this, _range);
3311
+ (_a = this.clientCallback) == null ? void 0 : _a.call(this, {
3312
+ clientViewportId: this.viewport,
3313
+ mode: "batch",
3314
+ rows: this.visibleRows.slice(from, to).map((row) => toClientRow2(row, this.keys)),
3315
+ size: this.visibleRows.length,
3316
+ type: "viewport-update"
3317
+ });
3318
+ }
3319
+ get columns() {
3320
+ return __privateGet(this, _config).columns;
3321
+ }
3322
+ set columns(columns) {
3323
+ __privateSet(this, _config, {
3324
+ ...__privateGet(this, _config),
3325
+ columns
3326
+ });
3327
+ }
3328
+ get aggregations() {
3329
+ return __privateGet(this, _aggregations);
3330
+ }
3331
+ set aggregations(aggregations) {
3332
+ __privateSet(this, _aggregations, aggregations);
3333
+ }
3334
+ get sort() {
3335
+ return __privateGet(this, _sort);
3336
+ }
3337
+ set sort(sort) {
3338
+ __privateSet(this, _sort, sort);
3339
+ }
3340
+ get filter() {
3341
+ return __privateGet(this, _filter);
3342
+ }
3343
+ set filter(filter) {
3344
+ __privateSet(this, _filter, filter);
3345
+ }
3346
+ get groupBy() {
3347
+ return __privateGet(this, _groupBy);
3348
+ }
3349
+ set groupBy(groupBy) {
3350
+ __privateSet(this, _groupBy, groupBy);
3351
+ }
3352
+ get title() {
3353
+ return __privateGet(this, _title);
3354
+ }
3355
+ set title(title) {
3356
+ __privateSet(this, _title, title);
3357
+ }
3358
+ createLink({
3359
+ parentVpId,
3360
+ link: { fromColumn, toColumn }
3361
+ }) {
3362
+ console.log("create link", {
3363
+ parentVpId,
3364
+ fromColumn,
3365
+ toColumn
3366
+ });
3367
+ }
3368
+ removeLink() {
3369
+ console.log("remove link");
3370
+ }
3371
+ async menuRpcCall(rpcRequest) {
3372
+ console.log("rmenuRpcCall", {
3373
+ rpcRequest
3374
+ });
3375
+ return void 0;
3376
+ }
3377
+ applyEdit(row, columnName, value) {
3378
+ console.log(
3379
+ `ArrayDataSource applyEdit ${row.join(",")} ${columnName} ${value}`
3380
+ );
3381
+ return Promise.resolve(true);
3382
+ }
3383
+ getChildRows(rowKey) {
3384
+ const parentRow = __privateGet(this, _data).find((row) => row[KEY3] === rowKey);
3385
+ if (parentRow) {
3386
+ const { [IDX]: parentIdx, [DEPTH2]: parentDepth } = parentRow;
3387
+ let rowIdx = parentIdx + 1;
3388
+ const childRows = [];
3389
+ do {
3390
+ const { [DEPTH2]: depth } = __privateGet(this, _data)[rowIdx];
3391
+ if (depth === parentDepth + 1) {
3392
+ childRows.push(__privateGet(this, _data)[rowIdx]);
3393
+ } else if (depth <= parentDepth) {
3394
+ break;
3395
+ }
3396
+ rowIdx += 1;
3397
+ } while (rowIdx < __privateGet(this, _data).length);
3398
+ return childRows;
3399
+ } else {
3400
+ console.warn(
3401
+ `JsonDataSource getChildRows row not found for key ${rowKey}`
3402
+ );
3403
+ }
3404
+ return [];
3405
+ }
3406
+ getRowsAtDepth(depth, visibleOnly = true) {
3407
+ const rows = visibleOnly ? this.visibleRows : __privateGet(this, _data);
3408
+ return rows.filter((row) => row[DEPTH2] === depth);
3409
+ }
3410
+ };
3411
+ _aggregations = new WeakMap();
3412
+ _config = new WeakMap();
3413
+ _data = new WeakMap();
3414
+ _filter = new WeakMap();
3415
+ _groupBy = new WeakMap();
3416
+ _range = new WeakMap();
3417
+ _selectedRowsCount = new WeakMap();
3418
+ _size = new WeakMap();
3419
+ _sort = new WeakMap();
3420
+ _status = new WeakMap();
3421
+ _title = new WeakMap();
3422
+ function getVisibleRows(rows, expandedKeys) {
3423
+ const visibleRows = [];
3424
+ const index = { value: 0 };
3425
+ for (let i = 0; i < rows.length; i++) {
3426
+ const row = rows[i];
3427
+ const { [DEPTH2]: depth, [KEY3]: key, [IS_LEAF]: isLeaf } = row;
3428
+ const isExpanded = expandedKeys.has(key);
3429
+ visibleRows.push(cloneRow(row, index, isExpanded));
3430
+ if (!isLeaf && !isExpanded) {
3431
+ do {
3432
+ i += 1;
3433
+ } while (i < rows.length - 1 && rows[i + 1][DEPTH2] > depth);
3434
+ }
3435
+ }
3436
+ return visibleRows;
3437
+ }
3438
+ var cloneRow = (row, index, isExpanded) => {
3439
+ const dolly = row.slice();
3440
+ dolly[0] = index.value;
3441
+ dolly[1] = index.value;
3442
+ if (isExpanded) {
3443
+ dolly[IS_EXPANDED2] = true;
3444
+ }
3445
+ index.value += 1;
3446
+ return dolly;
3447
+ };
3448
+
3449
+ // src/json-table/JsonTable.tsx
21
3450
  import { useEffect, useMemo, useRef } from "react";
22
3451
  import { jsx as jsx2 } from "react/jsx-runtime";
23
3452
  var JsonTable = ({