@lezer/common 1.0.0 → 1.0.2
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/dist/index.cjs +68 -63
- package/dist/index.js +68 -63
- package/dist/parse.d.ts +1 -1
- package/dist/tree.d.ts +2 -2
- package/package.json +2 -2
- package/dist/index.es.js +0 -1816
package/dist/index.js
CHANGED
|
@@ -112,8 +112,8 @@ class NodeType {
|
|
|
112
112
|
/// Define a node type.
|
|
113
113
|
static define(spec) {
|
|
114
114
|
let props = spec.props && spec.props.length ? Object.create(null) : noProps;
|
|
115
|
-
let flags = (spec.top ? 1 /* Top */ : 0) | (spec.skipped ? 2 /* Skipped */ : 0) |
|
|
116
|
-
(spec.error ? 4 /* Error */ : 0) | (spec.name == null ? 8 /* Anonymous */ : 0);
|
|
115
|
+
let flags = (spec.top ? 1 /* NodeFlag.Top */ : 0) | (spec.skipped ? 2 /* NodeFlag.Skipped */ : 0) |
|
|
116
|
+
(spec.error ? 4 /* NodeFlag.Error */ : 0) | (spec.name == null ? 8 /* NodeFlag.Anonymous */ : 0);
|
|
117
117
|
let type = new NodeType(spec.name || "", props, spec.id, flags);
|
|
118
118
|
if (spec.props)
|
|
119
119
|
for (let src of spec.props) {
|
|
@@ -131,14 +131,14 @@ class NodeType {
|
|
|
131
131
|
/// the prop isn't present on this node.
|
|
132
132
|
prop(prop) { return this.props[prop.id]; }
|
|
133
133
|
/// True when this is the top node of a grammar.
|
|
134
|
-
get isTop() { return (this.flags & 1 /* Top */) > 0; }
|
|
134
|
+
get isTop() { return (this.flags & 1 /* NodeFlag.Top */) > 0; }
|
|
135
135
|
/// True when this node is produced by a skip rule.
|
|
136
|
-
get isSkipped() { return (this.flags & 2 /* Skipped */) > 0; }
|
|
136
|
+
get isSkipped() { return (this.flags & 2 /* NodeFlag.Skipped */) > 0; }
|
|
137
137
|
/// Indicates whether this is an error node.
|
|
138
|
-
get isError() { return (this.flags & 4 /* Error */) > 0; }
|
|
138
|
+
get isError() { return (this.flags & 4 /* NodeFlag.Error */) > 0; }
|
|
139
139
|
/// When true, this node type doesn't correspond to a user-declared
|
|
140
140
|
/// named node, for example because it is used to cache repetition.
|
|
141
|
-
get isAnonymous() { return (this.flags & 8 /* Anonymous */) > 0; }
|
|
141
|
+
get isAnonymous() { return (this.flags & 8 /* NodeFlag.Anonymous */) > 0; }
|
|
142
142
|
/// Returns true when this node's name or one of its
|
|
143
143
|
/// [groups](#common.NodeProp^group) matches the given string.
|
|
144
144
|
is(name) {
|
|
@@ -171,7 +171,7 @@ class NodeType {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
/// An empty dummy node type to use when no actual type is available.
|
|
174
|
-
NodeType.none = new NodeType("", Object.create(null), 0, 8 /* Anonymous */);
|
|
174
|
+
NodeType.none = new NodeType("", Object.create(null), 0, 8 /* NodeFlag.Anonymous */);
|
|
175
175
|
/// A node set holds a collection of node types. It is used to
|
|
176
176
|
/// compactly represent trees by storing their type ids, rather than a
|
|
177
177
|
/// full pointer to the type object, in a numeric array. Each parser
|
|
@@ -317,6 +317,10 @@ class Tree {
|
|
|
317
317
|
/// position. If 1, it'll move into nodes that start at the
|
|
318
318
|
/// position. With 0, it'll only enter nodes that cover the position
|
|
319
319
|
/// from both sides.
|
|
320
|
+
///
|
|
321
|
+
/// Note that this will not enter
|
|
322
|
+
/// [overlays](#common.MountedTree.overlay), and you often want
|
|
323
|
+
/// [`resolveInner`](#common.Tree.resolveInner) instead.
|
|
320
324
|
resolve(pos, side = 0) {
|
|
321
325
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
322
326
|
CachedNode.set(this, node);
|
|
@@ -376,7 +380,7 @@ class Tree {
|
|
|
376
380
|
/// which may have children grouped into subtrees with type
|
|
377
381
|
/// [`NodeType.none`](#common.NodeType^none).
|
|
378
382
|
balance(config = {}) {
|
|
379
|
-
return this.children.length <= 8 /* BranchFactor */ ? this :
|
|
383
|
+
return this.children.length <= 8 /* Balance.BranchFactor */ ? this :
|
|
380
384
|
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)));
|
|
381
385
|
}
|
|
382
386
|
/// Build a tree from a postfix-ordered buffer of node information,
|
|
@@ -455,26 +459,27 @@ class TreeBuffer {
|
|
|
455
459
|
return pick;
|
|
456
460
|
}
|
|
457
461
|
/// @internal
|
|
458
|
-
slice(startI, endI, from
|
|
462
|
+
slice(startI, endI, from) {
|
|
459
463
|
let b = this.buffer;
|
|
460
|
-
let copy = new Uint16Array(endI - startI);
|
|
464
|
+
let copy = new Uint16Array(endI - startI), len = 0;
|
|
461
465
|
for (let i = startI, j = 0; i < endI;) {
|
|
462
466
|
copy[j++] = b[i++];
|
|
463
467
|
copy[j++] = b[i++] - from;
|
|
464
|
-
copy[j++] = b[i++] - from;
|
|
468
|
+
let to = copy[j++] = b[i++] - from;
|
|
465
469
|
copy[j++] = b[i++] - startI;
|
|
470
|
+
len = Math.max(len, to);
|
|
466
471
|
}
|
|
467
|
-
return new TreeBuffer(copy,
|
|
472
|
+
return new TreeBuffer(copy, len, this.set);
|
|
468
473
|
}
|
|
469
474
|
}
|
|
470
475
|
function checkSide(side, pos, from, to) {
|
|
471
476
|
switch (side) {
|
|
472
|
-
case -2 /* Before */: return from < pos;
|
|
473
|
-
case -1 /* AtOrBefore */: return to >= pos && from < pos;
|
|
474
|
-
case 0 /* Around */: return from < pos && to > pos;
|
|
475
|
-
case 1 /* AtOrAfter */: return from <= pos && to > pos;
|
|
476
|
-
case 2 /* After */: return to > pos;
|
|
477
|
-
case 4 /* DontCare */: return true;
|
|
477
|
+
case -2 /* Side.Before */: return from < pos;
|
|
478
|
+
case -1 /* Side.AtOrBefore */: return to >= pos && from < pos;
|
|
479
|
+
case 0 /* Side.Around */: return from < pos && to > pos;
|
|
480
|
+
case 1 /* Side.AtOrAfter */: return from <= pos && to > pos;
|
|
481
|
+
case 2 /* Side.After */: return to > pos;
|
|
482
|
+
case 4 /* Side.DontCare */: return true;
|
|
478
483
|
}
|
|
479
484
|
}
|
|
480
485
|
function enterUnfinishedNodesBefore(node, pos) {
|
|
@@ -564,10 +569,10 @@ class TreeNode {
|
|
|
564
569
|
return null;
|
|
565
570
|
}
|
|
566
571
|
}
|
|
567
|
-
get firstChild() { return this.nextChild(0, 1, 0, 4 /* DontCare */); }
|
|
568
|
-
get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* DontCare */); }
|
|
569
|
-
childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* After */); }
|
|
570
|
-
childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Before */); }
|
|
572
|
+
get firstChild() { return this.nextChild(0, 1, 0, 4 /* Side.DontCare */); }
|
|
573
|
+
get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* Side.DontCare */); }
|
|
574
|
+
childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* Side.After */); }
|
|
575
|
+
childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Side.Before */); }
|
|
571
576
|
enter(pos, side, mode = 0) {
|
|
572
577
|
let mounted;
|
|
573
578
|
if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
|
|
@@ -590,10 +595,10 @@ class TreeNode {
|
|
|
590
595
|
return this._parent ? this._parent.nextSignificantParent() : null;
|
|
591
596
|
}
|
|
592
597
|
get nextSibling() {
|
|
593
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index + 1, 1, 0, 4 /* DontCare */) : null;
|
|
598
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index + 1, 1, 0, 4 /* Side.DontCare */) : null;
|
|
594
599
|
}
|
|
595
600
|
get prevSibling() {
|
|
596
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4 /* DontCare */) : null;
|
|
601
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4 /* Side.DontCare */) : null;
|
|
597
602
|
}
|
|
598
603
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
599
604
|
get tree() { return this._tree; }
|
|
@@ -655,24 +660,24 @@ class BufferContext {
|
|
|
655
660
|
}
|
|
656
661
|
}
|
|
657
662
|
class BufferNode {
|
|
663
|
+
get name() { return this.type.name; }
|
|
664
|
+
get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
|
|
665
|
+
get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
|
|
658
666
|
constructor(context, _parent, index) {
|
|
659
667
|
this.context = context;
|
|
660
668
|
this._parent = _parent;
|
|
661
669
|
this.index = index;
|
|
662
670
|
this.type = context.buffer.set.types[context.buffer.buffer[index]];
|
|
663
671
|
}
|
|
664
|
-
get name() { return this.type.name; }
|
|
665
|
-
get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
|
|
666
|
-
get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
|
|
667
672
|
child(dir, pos, side) {
|
|
668
673
|
let { buffer } = this.context;
|
|
669
674
|
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
|
|
670
675
|
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
671
676
|
}
|
|
672
|
-
get firstChild() { return this.child(1, 0, 4 /* DontCare */); }
|
|
673
|
-
get lastChild() { return this.child(-1, 0, 4 /* DontCare */); }
|
|
674
|
-
childAfter(pos) { return this.child(1, pos, 2 /* After */); }
|
|
675
|
-
childBefore(pos) { return this.child(-1, pos, -2 /* Before */); }
|
|
677
|
+
get firstChild() { return this.child(1, 0, 4 /* Side.DontCare */); }
|
|
678
|
+
get lastChild() { return this.child(-1, 0, 4 /* Side.DontCare */); }
|
|
679
|
+
childAfter(pos) { return this.child(1, pos, 2 /* Side.After */); }
|
|
680
|
+
childBefore(pos) { return this.child(-1, pos, -2 /* Side.Before */); }
|
|
676
681
|
enter(pos, side, mode = 0) {
|
|
677
682
|
if (mode & IterMode.ExcludeBuffers)
|
|
678
683
|
return null;
|
|
@@ -684,7 +689,7 @@ class BufferNode {
|
|
|
684
689
|
return this._parent || this.context.parent.nextSignificantParent();
|
|
685
690
|
}
|
|
686
691
|
externalSibling(dir) {
|
|
687
|
-
return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, 0, 4 /* DontCare */);
|
|
692
|
+
return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, 0, 4 /* Side.DontCare */);
|
|
688
693
|
}
|
|
689
694
|
get nextSibling() {
|
|
690
695
|
let { buffer } = this.context;
|
|
@@ -698,7 +703,7 @@ class BufferNode {
|
|
|
698
703
|
let parentStart = this._parent ? this._parent.index + 4 : 0;
|
|
699
704
|
if (this.index == parentStart)
|
|
700
705
|
return this.externalSibling(-1);
|
|
701
|
-
return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4 /* DontCare */));
|
|
706
|
+
return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4 /* Side.DontCare */));
|
|
702
707
|
}
|
|
703
708
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
704
709
|
get tree() { return null; }
|
|
@@ -707,8 +712,8 @@ class BufferNode {
|
|
|
707
712
|
let { buffer } = this.context;
|
|
708
713
|
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
|
|
709
714
|
if (endI > startI) {
|
|
710
|
-
let from = buffer.buffer[this.index + 1]
|
|
711
|
-
children.push(buffer.slice(startI, endI, from
|
|
715
|
+
let from = buffer.buffer[this.index + 1];
|
|
716
|
+
children.push(buffer.slice(startI, endI, from));
|
|
712
717
|
positions.push(0);
|
|
713
718
|
}
|
|
714
719
|
return new Tree(this.type, children, positions, this.to - this.from);
|
|
@@ -735,6 +740,8 @@ class BufferNode {
|
|
|
735
740
|
/// A tree cursor object focuses on a given node in a syntax tree, and
|
|
736
741
|
/// allows you to move to adjacent nodes.
|
|
737
742
|
class TreeCursor {
|
|
743
|
+
/// Shorthand for `.type.name`.
|
|
744
|
+
get name() { return this.type.name; }
|
|
738
745
|
/// @internal
|
|
739
746
|
constructor(node,
|
|
740
747
|
/// @internal
|
|
@@ -758,8 +765,6 @@ class TreeCursor {
|
|
|
758
765
|
this.yieldBuf(node.index);
|
|
759
766
|
}
|
|
760
767
|
}
|
|
761
|
-
/// Shorthand for `.type.name`.
|
|
762
|
-
get name() { return this.type.name; }
|
|
763
768
|
yieldNode(node) {
|
|
764
769
|
if (!node)
|
|
765
770
|
return false;
|
|
@@ -804,13 +809,13 @@ class TreeCursor {
|
|
|
804
809
|
}
|
|
805
810
|
/// Move the cursor to this node's first child. When this returns
|
|
806
811
|
/// false, the node has no child, and the cursor has not been moved.
|
|
807
|
-
firstChild() { return this.enterChild(1, 0, 4 /* DontCare */); }
|
|
812
|
+
firstChild() { return this.enterChild(1, 0, 4 /* Side.DontCare */); }
|
|
808
813
|
/// Move the cursor to this node's last child.
|
|
809
|
-
lastChild() { return this.enterChild(-1, 0, 4 /* DontCare */); }
|
|
814
|
+
lastChild() { return this.enterChild(-1, 0, 4 /* Side.DontCare */); }
|
|
810
815
|
/// Move the cursor to the first child that ends after `pos`.
|
|
811
|
-
childAfter(pos) { return this.enterChild(1, pos, 2 /* After */); }
|
|
816
|
+
childAfter(pos) { return this.enterChild(1, pos, 2 /* Side.After */); }
|
|
812
817
|
/// Move to the last child that starts before `pos`.
|
|
813
|
-
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Before */); }
|
|
818
|
+
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Side.Before */); }
|
|
814
819
|
/// Move the cursor to the child around `pos`. If side is -1 the
|
|
815
820
|
/// child may end at that position, when 1 it may start there. This
|
|
816
821
|
/// will also enter [overlaid](#common.MountedTree.overlay)
|
|
@@ -836,19 +841,19 @@ class TreeCursor {
|
|
|
836
841
|
if (!this.buffer)
|
|
837
842
|
return !this._tree._parent ? false
|
|
838
843
|
: this.yield(this._tree.index < 0 ? null
|
|
839
|
-
: this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4 /* DontCare */, this.mode));
|
|
844
|
+
: this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4 /* Side.DontCare */, this.mode));
|
|
840
845
|
let { buffer } = this.buffer, d = this.stack.length - 1;
|
|
841
846
|
if (dir < 0) {
|
|
842
847
|
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
|
|
843
848
|
if (this.index != parentStart)
|
|
844
|
-
return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, 0, 4 /* DontCare */));
|
|
849
|
+
return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, 0, 4 /* Side.DontCare */));
|
|
845
850
|
}
|
|
846
851
|
else {
|
|
847
852
|
let after = buffer.buffer[this.index + 3];
|
|
848
853
|
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
|
|
849
854
|
return this.yieldBuf(after);
|
|
850
855
|
}
|
|
851
|
-
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4 /* DontCare */, this.mode)) : false;
|
|
856
|
+
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4 /* Side.DontCare */, this.mode)) : false;
|
|
852
857
|
}
|
|
853
858
|
/// Move to this node's next sibling, if any.
|
|
854
859
|
nextSibling() { return this.sibling(1); }
|
|
@@ -885,7 +890,7 @@ class TreeCursor {
|
|
|
885
890
|
return true;
|
|
886
891
|
}
|
|
887
892
|
move(dir, enter) {
|
|
888
|
-
if (enter && this.enterChild(dir, 0, 4 /* DontCare */))
|
|
893
|
+
if (enter && this.enterChild(dir, 0, 4 /* Side.DontCare */))
|
|
889
894
|
return true;
|
|
890
895
|
for (;;) {
|
|
891
896
|
if (this.sibling(dir))
|
|
@@ -895,7 +900,7 @@ class TreeCursor {
|
|
|
895
900
|
}
|
|
896
901
|
}
|
|
897
902
|
/// Move to the next node in a
|
|
898
|
-
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-
|
|
903
|
+
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
899
904
|
/// traversal, going from a node to its first child or, if the
|
|
900
905
|
/// current node is empty or `enter` is false, its next sibling or
|
|
901
906
|
/// the next sibling of the first parent node that has one.
|
|
@@ -1011,17 +1016,17 @@ function buildTree(data) {
|
|
|
1011
1016
|
let lookAheadAtStart = lookAhead;
|
|
1012
1017
|
while (size < 0) {
|
|
1013
1018
|
cursor.next();
|
|
1014
|
-
if (size == -1 /* Reuse */) {
|
|
1019
|
+
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
1015
1020
|
let node = reused[id];
|
|
1016
1021
|
children.push(node);
|
|
1017
1022
|
positions.push(start - parentStart);
|
|
1018
1023
|
return;
|
|
1019
1024
|
}
|
|
1020
|
-
else if (size == -3 /* ContextChange */) { // Context change
|
|
1025
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) { // Context change
|
|
1021
1026
|
contextHash = id;
|
|
1022
1027
|
return;
|
|
1023
1028
|
}
|
|
1024
|
-
else if (size == -4 /* LookAhead */) {
|
|
1029
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1025
1030
|
lookAhead = id;
|
|
1026
1031
|
return;
|
|
1027
1032
|
}
|
|
@@ -1138,7 +1143,7 @@ function buildTree(data) {
|
|
|
1138
1143
|
fork.next();
|
|
1139
1144
|
while (fork.pos > startPos) {
|
|
1140
1145
|
if (fork.size < 0) {
|
|
1141
|
-
if (fork.size == -3 /* ContextChange */)
|
|
1146
|
+
if (fork.size == -3 /* SpecialRecord.ContextChange */)
|
|
1142
1147
|
localSkipped += 4;
|
|
1143
1148
|
else
|
|
1144
1149
|
break scan;
|
|
@@ -1174,10 +1179,10 @@ function buildTree(data) {
|
|
|
1174
1179
|
buffer[--index] = start - bufferStart;
|
|
1175
1180
|
buffer[--index] = id;
|
|
1176
1181
|
}
|
|
1177
|
-
else if (size == -3 /* ContextChange */) {
|
|
1182
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) {
|
|
1178
1183
|
contextHash = id;
|
|
1179
1184
|
}
|
|
1180
|
-
else if (size == -4 /* LookAhead */) {
|
|
1185
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1181
1186
|
lookAhead = id;
|
|
1182
1187
|
}
|
|
1183
1188
|
return index;
|
|
@@ -1224,7 +1229,7 @@ mkTree) {
|
|
|
1224
1229
|
let total = 0;
|
|
1225
1230
|
for (let i = from; i < to; i++)
|
|
1226
1231
|
total += nodeSize(balanceType, children[i]);
|
|
1227
|
-
let maxChild = Math.ceil((total * 1.5) / 8 /* BranchFactor */);
|
|
1232
|
+
let maxChild = Math.ceil((total * 1.5) / 8 /* Balance.BranchFactor */);
|
|
1228
1233
|
let localChildren = [], localPositions = [];
|
|
1229
1234
|
function divide(children, positions, from, to, offset) {
|
|
1230
1235
|
for (let i = from; i < to;) {
|
|
@@ -1327,16 +1332,16 @@ class TreeFragment {
|
|
|
1327
1332
|
this.to = to;
|
|
1328
1333
|
this.tree = tree;
|
|
1329
1334
|
this.offset = offset;
|
|
1330
|
-
this.open = (openStart ? 1 /* Start */ : 0) | (openEnd ? 2 /* End */ : 0);
|
|
1335
|
+
this.open = (openStart ? 1 /* Open.Start */ : 0) | (openEnd ? 2 /* Open.End */ : 0);
|
|
1331
1336
|
}
|
|
1332
1337
|
/// Whether the start of the fragment represents the start of a
|
|
1333
1338
|
/// parse, or the end of a change. (In the second case, it may not
|
|
1334
1339
|
/// be safe to reuse some nodes at the start, depending on the
|
|
1335
1340
|
/// parsing algorithm.)
|
|
1336
|
-
get openStart() { return (this.open & 1 /* Start */) > 0; }
|
|
1341
|
+
get openStart() { return (this.open & 1 /* Open.Start */) > 0; }
|
|
1337
1342
|
/// Whether the end of the fragment represents the end of a
|
|
1338
1343
|
/// full-document parse, or the start of a change.
|
|
1339
|
-
get openEnd() { return (this.open & 2 /* End */) > 0; }
|
|
1344
|
+
get openEnd() { return (this.open & 2 /* Open.End */) > 0; }
|
|
1340
1345
|
/// Create a set of fragments from a freshly parsed tree, or update
|
|
1341
1346
|
/// an existing set of fragments by replacing the ones that overlap
|
|
1342
1347
|
/// with a tree with content from the new tree. When `partial` is
|
|
@@ -1530,7 +1535,7 @@ class MixedParse {
|
|
|
1530
1535
|
enter = false;
|
|
1531
1536
|
}
|
|
1532
1537
|
else if (covered && (isCovered = checkCover(covered.ranges, cursor.from, cursor.to))) {
|
|
1533
|
-
enter = isCovered != 2 /* Full */;
|
|
1538
|
+
enter = isCovered != 2 /* Cover.Full */;
|
|
1534
1539
|
}
|
|
1535
1540
|
else if (!cursor.type.isAnonymous && cursor.from < cursor.to && (nest = this.nest(cursor, this.input))) {
|
|
1536
1541
|
if (!cursor.tree)
|
|
@@ -1585,16 +1590,16 @@ function checkCover(covered, from, to) {
|
|
|
1585
1590
|
if (range.from >= to)
|
|
1586
1591
|
break;
|
|
1587
1592
|
if (range.to > from)
|
|
1588
|
-
return range.from <= from && range.to >= to ? 2 /* Full */ : 1 /* Partial */;
|
|
1593
|
+
return range.from <= from && range.to >= to ? 2 /* Cover.Full */ : 1 /* Cover.Partial */;
|
|
1589
1594
|
}
|
|
1590
|
-
return 0 /* None */;
|
|
1595
|
+
return 0 /* Cover.None */;
|
|
1591
1596
|
}
|
|
1592
1597
|
// Take a piece of buffer and convert it into a stand-alone
|
|
1593
1598
|
// TreeBuffer.
|
|
1594
1599
|
function sliceBuf(buf, startI, endI, nodes, positions, off) {
|
|
1595
1600
|
if (startI < endI) {
|
|
1596
|
-
let from = buf.buffer[startI + 1]
|
|
1597
|
-
nodes.push(buf.slice(startI, endI, from
|
|
1601
|
+
let from = buf.buffer[startI + 1];
|
|
1602
|
+
nodes.push(buf.slice(startI, endI, from));
|
|
1598
1603
|
positions.push(from - off);
|
|
1599
1604
|
}
|
|
1600
1605
|
}
|
|
@@ -1799,14 +1804,14 @@ function enterFragments(mounts, ranges) {
|
|
|
1799
1804
|
for (let i = 0, pos = from;; i++) {
|
|
1800
1805
|
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
1801
1806
|
if (end > pos)
|
|
1802
|
-
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos, frag.to <= end));
|
|
1807
|
+
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
1803
1808
|
if (last)
|
|
1804
1809
|
break;
|
|
1805
1810
|
pos = changes[i].to;
|
|
1806
1811
|
}
|
|
1807
1812
|
}
|
|
1808
1813
|
else {
|
|
1809
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos, frag.to <= endPos));
|
|
1814
|
+
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
1810
1815
|
}
|
|
1811
1816
|
}
|
|
1812
1817
|
return result;
|
package/dist/parse.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface Input {
|
|
|
42
42
|
readonly lineChunks: boolean;
|
|
43
43
|
read(from: number, to: number): string;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type ParseWrapper = (inner: PartialParse, input: Input, fragments: readonly TreeFragment[], ranges: readonly {
|
|
46
46
|
from: number;
|
|
47
47
|
to: number;
|
|
48
48
|
}[]) => PartialParse;
|
package/dist/tree.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class MountedTree {
|
|
|
34
34
|
to: number;
|
|
35
35
|
}[] | null, parser: Parser);
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export type NodePropSource = (type: NodeType) => null | [NodeProp<any>, any];
|
|
38
38
|
export declare class NodeType {
|
|
39
39
|
readonly name: string;
|
|
40
40
|
readonly id: number;
|
|
@@ -94,7 +94,7 @@ export declare class Tree {
|
|
|
94
94
|
}): Tree;
|
|
95
95
|
static build(data: BuildData): Tree;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
type BuildData = {
|
|
98
98
|
buffer: BufferCursor | readonly number[];
|
|
99
99
|
nodeSet: NodeSet;
|
|
100
100
|
topID: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lezer/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Syntax tree data structure and parser interfaces for the lezer parser",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"rollup": "^2.52.2",
|
|
18
18
|
"@rollup/plugin-commonjs": "^15.1.0",
|
|
19
19
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
20
|
-
"rollup-plugin-typescript2": "^0.
|
|
20
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
21
21
|
"typescript": "^4.3.4",
|
|
22
22
|
"@types/mocha": "^5.2.6",
|
|
23
23
|
"ts-node": "^10.0.0",
|