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