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