@lezer/common 1.0.1 → 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 +62 -61
- package/dist/index.js +62 -61
- package/dist/parse.d.ts +1 -1
- package/dist/tree.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -116,8 +116,8 @@ class NodeType {
|
|
|
116
116
|
/// Define a node type.
|
|
117
117
|
static define(spec) {
|
|
118
118
|
let props = spec.props && spec.props.length ? Object.create(null) : noProps;
|
|
119
|
-
let flags = (spec.top ? 1 /* Top */ : 0) | (spec.skipped ? 2 /* Skipped */ : 0) |
|
|
120
|
-
(spec.error ? 4 /* Error */ : 0) | (spec.name == null ? 8 /* Anonymous */ : 0);
|
|
119
|
+
let flags = (spec.top ? 1 /* NodeFlag.Top */ : 0) | (spec.skipped ? 2 /* NodeFlag.Skipped */ : 0) |
|
|
120
|
+
(spec.error ? 4 /* NodeFlag.Error */ : 0) | (spec.name == null ? 8 /* NodeFlag.Anonymous */ : 0);
|
|
121
121
|
let type = new NodeType(spec.name || "", props, spec.id, flags);
|
|
122
122
|
if (spec.props)
|
|
123
123
|
for (let src of spec.props) {
|
|
@@ -135,14 +135,14 @@ class NodeType {
|
|
|
135
135
|
/// the prop isn't present on this node.
|
|
136
136
|
prop(prop) { return this.props[prop.id]; }
|
|
137
137
|
/// True when this is the top node of a grammar.
|
|
138
|
-
get isTop() { return (this.flags & 1 /* Top */) > 0; }
|
|
138
|
+
get isTop() { return (this.flags & 1 /* NodeFlag.Top */) > 0; }
|
|
139
139
|
/// True when this node is produced by a skip rule.
|
|
140
|
-
get isSkipped() { return (this.flags & 2 /* Skipped */) > 0; }
|
|
140
|
+
get isSkipped() { return (this.flags & 2 /* NodeFlag.Skipped */) > 0; }
|
|
141
141
|
/// Indicates whether this is an error node.
|
|
142
|
-
get isError() { return (this.flags & 4 /* Error */) > 0; }
|
|
142
|
+
get isError() { return (this.flags & 4 /* NodeFlag.Error */) > 0; }
|
|
143
143
|
/// When true, this node type doesn't correspond to a user-declared
|
|
144
144
|
/// named node, for example because it is used to cache repetition.
|
|
145
|
-
get isAnonymous() { return (this.flags & 8 /* Anonymous */) > 0; }
|
|
145
|
+
get isAnonymous() { return (this.flags & 8 /* NodeFlag.Anonymous */) > 0; }
|
|
146
146
|
/// Returns true when this node's name or one of its
|
|
147
147
|
/// [groups](#common.NodeProp^group) matches the given string.
|
|
148
148
|
is(name) {
|
|
@@ -175,7 +175,7 @@ class NodeType {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
/// An empty dummy node type to use when no actual type is available.
|
|
178
|
-
NodeType.none = new NodeType("", Object.create(null), 0, 8 /* Anonymous */);
|
|
178
|
+
NodeType.none = new NodeType("", Object.create(null), 0, 8 /* NodeFlag.Anonymous */);
|
|
179
179
|
/// A node set holds a collection of node types. It is used to
|
|
180
180
|
/// compactly represent trees by storing their type ids, rather than a
|
|
181
181
|
/// full pointer to the type object, in a numeric array. Each parser
|
|
@@ -384,7 +384,7 @@ class Tree {
|
|
|
384
384
|
/// which may have children grouped into subtrees with type
|
|
385
385
|
/// [`NodeType.none`](#common.NodeType^none).
|
|
386
386
|
balance(config = {}) {
|
|
387
|
-
return this.children.length <= 8 /* BranchFactor */ ? this :
|
|
387
|
+
return this.children.length <= 8 /* Balance.BranchFactor */ ? this :
|
|
388
388
|
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)));
|
|
389
389
|
}
|
|
390
390
|
/// Build a tree from a postfix-ordered buffer of node information,
|
|
@@ -463,26 +463,27 @@ class TreeBuffer {
|
|
|
463
463
|
return pick;
|
|
464
464
|
}
|
|
465
465
|
/// @internal
|
|
466
|
-
slice(startI, endI, from
|
|
466
|
+
slice(startI, endI, from) {
|
|
467
467
|
let b = this.buffer;
|
|
468
|
-
let copy = new Uint16Array(endI - startI);
|
|
468
|
+
let copy = new Uint16Array(endI - startI), len = 0;
|
|
469
469
|
for (let i = startI, j = 0; i < endI;) {
|
|
470
470
|
copy[j++] = b[i++];
|
|
471
471
|
copy[j++] = b[i++] - from;
|
|
472
|
-
copy[j++] = b[i++] - from;
|
|
472
|
+
let to = copy[j++] = b[i++] - from;
|
|
473
473
|
copy[j++] = b[i++] - startI;
|
|
474
|
+
len = Math.max(len, to);
|
|
474
475
|
}
|
|
475
|
-
return new TreeBuffer(copy,
|
|
476
|
+
return new TreeBuffer(copy, len, this.set);
|
|
476
477
|
}
|
|
477
478
|
}
|
|
478
479
|
function checkSide(side, pos, from, to) {
|
|
479
480
|
switch (side) {
|
|
480
|
-
case -2 /* Before */: return from < pos;
|
|
481
|
-
case -1 /* AtOrBefore */: return to >= pos && from < pos;
|
|
482
|
-
case 0 /* Around */: return from < pos && to > pos;
|
|
483
|
-
case 1 /* AtOrAfter */: return from <= pos && to > pos;
|
|
484
|
-
case 2 /* After */: return to > pos;
|
|
485
|
-
case 4 /* DontCare */: return true;
|
|
481
|
+
case -2 /* Side.Before */: return from < pos;
|
|
482
|
+
case -1 /* Side.AtOrBefore */: return to >= pos && from < pos;
|
|
483
|
+
case 0 /* Side.Around */: return from < pos && to > pos;
|
|
484
|
+
case 1 /* Side.AtOrAfter */: return from <= pos && to > pos;
|
|
485
|
+
case 2 /* Side.After */: return to > pos;
|
|
486
|
+
case 4 /* Side.DontCare */: return true;
|
|
486
487
|
}
|
|
487
488
|
}
|
|
488
489
|
function enterUnfinishedNodesBefore(node, pos) {
|
|
@@ -572,10 +573,10 @@ class TreeNode {
|
|
|
572
573
|
return null;
|
|
573
574
|
}
|
|
574
575
|
}
|
|
575
|
-
get firstChild() { return this.nextChild(0, 1, 0, 4 /* DontCare */); }
|
|
576
|
-
get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* DontCare */); }
|
|
577
|
-
childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* After */); }
|
|
578
|
-
childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Before */); }
|
|
576
|
+
get firstChild() { return this.nextChild(0, 1, 0, 4 /* Side.DontCare */); }
|
|
577
|
+
get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* Side.DontCare */); }
|
|
578
|
+
childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* Side.After */); }
|
|
579
|
+
childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Side.Before */); }
|
|
579
580
|
enter(pos, side, mode = 0) {
|
|
580
581
|
let mounted;
|
|
581
582
|
if (!(mode & exports.IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
|
|
@@ -598,10 +599,10 @@ class TreeNode {
|
|
|
598
599
|
return this._parent ? this._parent.nextSignificantParent() : null;
|
|
599
600
|
}
|
|
600
601
|
get nextSibling() {
|
|
601
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index + 1, 1, 0, 4 /* DontCare */) : null;
|
|
602
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index + 1, 1, 0, 4 /* Side.DontCare */) : null;
|
|
602
603
|
}
|
|
603
604
|
get prevSibling() {
|
|
604
|
-
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4 /* DontCare */) : null;
|
|
605
|
+
return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4 /* Side.DontCare */) : null;
|
|
605
606
|
}
|
|
606
607
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
607
608
|
get tree() { return this._tree; }
|
|
@@ -663,24 +664,24 @@ class BufferContext {
|
|
|
663
664
|
}
|
|
664
665
|
}
|
|
665
666
|
class BufferNode {
|
|
667
|
+
get name() { return this.type.name; }
|
|
668
|
+
get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
|
|
669
|
+
get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
|
|
666
670
|
constructor(context, _parent, index) {
|
|
667
671
|
this.context = context;
|
|
668
672
|
this._parent = _parent;
|
|
669
673
|
this.index = index;
|
|
670
674
|
this.type = context.buffer.set.types[context.buffer.buffer[index]];
|
|
671
675
|
}
|
|
672
|
-
get name() { return this.type.name; }
|
|
673
|
-
get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
|
|
674
|
-
get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
|
|
675
676
|
child(dir, pos, side) {
|
|
676
677
|
let { buffer } = this.context;
|
|
677
678
|
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
|
|
678
679
|
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
679
680
|
}
|
|
680
|
-
get firstChild() { return this.child(1, 0, 4 /* DontCare */); }
|
|
681
|
-
get lastChild() { return this.child(-1, 0, 4 /* DontCare */); }
|
|
682
|
-
childAfter(pos) { return this.child(1, pos, 2 /* After */); }
|
|
683
|
-
childBefore(pos) { return this.child(-1, pos, -2 /* Before */); }
|
|
681
|
+
get firstChild() { return this.child(1, 0, 4 /* Side.DontCare */); }
|
|
682
|
+
get lastChild() { return this.child(-1, 0, 4 /* Side.DontCare */); }
|
|
683
|
+
childAfter(pos) { return this.child(1, pos, 2 /* Side.After */); }
|
|
684
|
+
childBefore(pos) { return this.child(-1, pos, -2 /* Side.Before */); }
|
|
684
685
|
enter(pos, side, mode = 0) {
|
|
685
686
|
if (mode & exports.IterMode.ExcludeBuffers)
|
|
686
687
|
return null;
|
|
@@ -692,7 +693,7 @@ class BufferNode {
|
|
|
692
693
|
return this._parent || this.context.parent.nextSignificantParent();
|
|
693
694
|
}
|
|
694
695
|
externalSibling(dir) {
|
|
695
|
-
return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, 0, 4 /* DontCare */);
|
|
696
|
+
return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, 0, 4 /* Side.DontCare */);
|
|
696
697
|
}
|
|
697
698
|
get nextSibling() {
|
|
698
699
|
let { buffer } = this.context;
|
|
@@ -706,7 +707,7 @@ class BufferNode {
|
|
|
706
707
|
let parentStart = this._parent ? this._parent.index + 4 : 0;
|
|
707
708
|
if (this.index == parentStart)
|
|
708
709
|
return this.externalSibling(-1);
|
|
709
|
-
return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4 /* DontCare */));
|
|
710
|
+
return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4 /* Side.DontCare */));
|
|
710
711
|
}
|
|
711
712
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
712
713
|
get tree() { return null; }
|
|
@@ -715,8 +716,8 @@ class BufferNode {
|
|
|
715
716
|
let { buffer } = this.context;
|
|
716
717
|
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
|
|
717
718
|
if (endI > startI) {
|
|
718
|
-
let from = buffer.buffer[this.index + 1]
|
|
719
|
-
children.push(buffer.slice(startI, endI, from
|
|
719
|
+
let from = buffer.buffer[this.index + 1];
|
|
720
|
+
children.push(buffer.slice(startI, endI, from));
|
|
720
721
|
positions.push(0);
|
|
721
722
|
}
|
|
722
723
|
return new Tree(this.type, children, positions, this.to - this.from);
|
|
@@ -743,6 +744,8 @@ class BufferNode {
|
|
|
743
744
|
/// A tree cursor object focuses on a given node in a syntax tree, and
|
|
744
745
|
/// allows you to move to adjacent nodes.
|
|
745
746
|
class TreeCursor {
|
|
747
|
+
/// Shorthand for `.type.name`.
|
|
748
|
+
get name() { return this.type.name; }
|
|
746
749
|
/// @internal
|
|
747
750
|
constructor(node,
|
|
748
751
|
/// @internal
|
|
@@ -766,8 +769,6 @@ class TreeCursor {
|
|
|
766
769
|
this.yieldBuf(node.index);
|
|
767
770
|
}
|
|
768
771
|
}
|
|
769
|
-
/// Shorthand for `.type.name`.
|
|
770
|
-
get name() { return this.type.name; }
|
|
771
772
|
yieldNode(node) {
|
|
772
773
|
if (!node)
|
|
773
774
|
return false;
|
|
@@ -812,13 +813,13 @@ class TreeCursor {
|
|
|
812
813
|
}
|
|
813
814
|
/// Move the cursor to this node's first child. When this returns
|
|
814
815
|
/// false, the node has no child, and the cursor has not been moved.
|
|
815
|
-
firstChild() { return this.enterChild(1, 0, 4 /* DontCare */); }
|
|
816
|
+
firstChild() { return this.enterChild(1, 0, 4 /* Side.DontCare */); }
|
|
816
817
|
/// Move the cursor to this node's last child.
|
|
817
|
-
lastChild() { return this.enterChild(-1, 0, 4 /* DontCare */); }
|
|
818
|
+
lastChild() { return this.enterChild(-1, 0, 4 /* Side.DontCare */); }
|
|
818
819
|
/// Move the cursor to the first child that ends after `pos`.
|
|
819
|
-
childAfter(pos) { return this.enterChild(1, pos, 2 /* After */); }
|
|
820
|
+
childAfter(pos) { return this.enterChild(1, pos, 2 /* Side.After */); }
|
|
820
821
|
/// Move to the last child that starts before `pos`.
|
|
821
|
-
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Before */); }
|
|
822
|
+
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Side.Before */); }
|
|
822
823
|
/// Move the cursor to the child around `pos`. If side is -1 the
|
|
823
824
|
/// child may end at that position, when 1 it may start there. This
|
|
824
825
|
/// will also enter [overlaid](#common.MountedTree.overlay)
|
|
@@ -844,19 +845,19 @@ class TreeCursor {
|
|
|
844
845
|
if (!this.buffer)
|
|
845
846
|
return !this._tree._parent ? false
|
|
846
847
|
: this.yield(this._tree.index < 0 ? null
|
|
847
|
-
: this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4 /* DontCare */, this.mode));
|
|
848
|
+
: this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4 /* Side.DontCare */, this.mode));
|
|
848
849
|
let { buffer } = this.buffer, d = this.stack.length - 1;
|
|
849
850
|
if (dir < 0) {
|
|
850
851
|
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
|
|
851
852
|
if (this.index != parentStart)
|
|
852
|
-
return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, 0, 4 /* DontCare */));
|
|
853
|
+
return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, 0, 4 /* Side.DontCare */));
|
|
853
854
|
}
|
|
854
855
|
else {
|
|
855
856
|
let after = buffer.buffer[this.index + 3];
|
|
856
857
|
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
|
|
857
858
|
return this.yieldBuf(after);
|
|
858
859
|
}
|
|
859
|
-
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4 /* DontCare */, this.mode)) : false;
|
|
860
|
+
return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4 /* Side.DontCare */, this.mode)) : false;
|
|
860
861
|
}
|
|
861
862
|
/// Move to this node's next sibling, if any.
|
|
862
863
|
nextSibling() { return this.sibling(1); }
|
|
@@ -893,7 +894,7 @@ class TreeCursor {
|
|
|
893
894
|
return true;
|
|
894
895
|
}
|
|
895
896
|
move(dir, enter) {
|
|
896
|
-
if (enter && this.enterChild(dir, 0, 4 /* DontCare */))
|
|
897
|
+
if (enter && this.enterChild(dir, 0, 4 /* Side.DontCare */))
|
|
897
898
|
return true;
|
|
898
899
|
for (;;) {
|
|
899
900
|
if (this.sibling(dir))
|
|
@@ -903,7 +904,7 @@ class TreeCursor {
|
|
|
903
904
|
}
|
|
904
905
|
}
|
|
905
906
|
/// Move to the next node in a
|
|
906
|
-
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-
|
|
907
|
+
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
907
908
|
/// traversal, going from a node to its first child or, if the
|
|
908
909
|
/// current node is empty or `enter` is false, its next sibling or
|
|
909
910
|
/// the next sibling of the first parent node that has one.
|
|
@@ -1019,17 +1020,17 @@ function buildTree(data) {
|
|
|
1019
1020
|
let lookAheadAtStart = lookAhead;
|
|
1020
1021
|
while (size < 0) {
|
|
1021
1022
|
cursor.next();
|
|
1022
|
-
if (size == -1 /* Reuse */) {
|
|
1023
|
+
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
1023
1024
|
let node = reused[id];
|
|
1024
1025
|
children.push(node);
|
|
1025
1026
|
positions.push(start - parentStart);
|
|
1026
1027
|
return;
|
|
1027
1028
|
}
|
|
1028
|
-
else if (size == -3 /* ContextChange */) { // Context change
|
|
1029
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) { // Context change
|
|
1029
1030
|
contextHash = id;
|
|
1030
1031
|
return;
|
|
1031
1032
|
}
|
|
1032
|
-
else if (size == -4 /* LookAhead */) {
|
|
1033
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1033
1034
|
lookAhead = id;
|
|
1034
1035
|
return;
|
|
1035
1036
|
}
|
|
@@ -1146,7 +1147,7 @@ function buildTree(data) {
|
|
|
1146
1147
|
fork.next();
|
|
1147
1148
|
while (fork.pos > startPos) {
|
|
1148
1149
|
if (fork.size < 0) {
|
|
1149
|
-
if (fork.size == -3 /* ContextChange */)
|
|
1150
|
+
if (fork.size == -3 /* SpecialRecord.ContextChange */)
|
|
1150
1151
|
localSkipped += 4;
|
|
1151
1152
|
else
|
|
1152
1153
|
break scan;
|
|
@@ -1182,10 +1183,10 @@ function buildTree(data) {
|
|
|
1182
1183
|
buffer[--index] = start - bufferStart;
|
|
1183
1184
|
buffer[--index] = id;
|
|
1184
1185
|
}
|
|
1185
|
-
else if (size == -3 /* ContextChange */) {
|
|
1186
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) {
|
|
1186
1187
|
contextHash = id;
|
|
1187
1188
|
}
|
|
1188
|
-
else if (size == -4 /* LookAhead */) {
|
|
1189
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1189
1190
|
lookAhead = id;
|
|
1190
1191
|
}
|
|
1191
1192
|
return index;
|
|
@@ -1232,7 +1233,7 @@ mkTree) {
|
|
|
1232
1233
|
let total = 0;
|
|
1233
1234
|
for (let i = from; i < to; i++)
|
|
1234
1235
|
total += nodeSize(balanceType, children[i]);
|
|
1235
|
-
let maxChild = Math.ceil((total * 1.5) / 8 /* BranchFactor */);
|
|
1236
|
+
let maxChild = Math.ceil((total * 1.5) / 8 /* Balance.BranchFactor */);
|
|
1236
1237
|
let localChildren = [], localPositions = [];
|
|
1237
1238
|
function divide(children, positions, from, to, offset) {
|
|
1238
1239
|
for (let i = from; i < to;) {
|
|
@@ -1335,16 +1336,16 @@ class TreeFragment {
|
|
|
1335
1336
|
this.to = to;
|
|
1336
1337
|
this.tree = tree;
|
|
1337
1338
|
this.offset = offset;
|
|
1338
|
-
this.open = (openStart ? 1 /* Start */ : 0) | (openEnd ? 2 /* End */ : 0);
|
|
1339
|
+
this.open = (openStart ? 1 /* Open.Start */ : 0) | (openEnd ? 2 /* Open.End */ : 0);
|
|
1339
1340
|
}
|
|
1340
1341
|
/// Whether the start of the fragment represents the start of a
|
|
1341
1342
|
/// parse, or the end of a change. (In the second case, it may not
|
|
1342
1343
|
/// be safe to reuse some nodes at the start, depending on the
|
|
1343
1344
|
/// parsing algorithm.)
|
|
1344
|
-
get openStart() { return (this.open & 1 /* Start */) > 0; }
|
|
1345
|
+
get openStart() { return (this.open & 1 /* Open.Start */) > 0; }
|
|
1345
1346
|
/// Whether the end of the fragment represents the end of a
|
|
1346
1347
|
/// full-document parse, or the start of a change.
|
|
1347
|
-
get openEnd() { return (this.open & 2 /* End */) > 0; }
|
|
1348
|
+
get openEnd() { return (this.open & 2 /* Open.End */) > 0; }
|
|
1348
1349
|
/// Create a set of fragments from a freshly parsed tree, or update
|
|
1349
1350
|
/// an existing set of fragments by replacing the ones that overlap
|
|
1350
1351
|
/// with a tree with content from the new tree. When `partial` is
|
|
@@ -1538,7 +1539,7 @@ class MixedParse {
|
|
|
1538
1539
|
enter = false;
|
|
1539
1540
|
}
|
|
1540
1541
|
else if (covered && (isCovered = checkCover(covered.ranges, cursor.from, cursor.to))) {
|
|
1541
|
-
enter = isCovered != 2 /* Full */;
|
|
1542
|
+
enter = isCovered != 2 /* Cover.Full */;
|
|
1542
1543
|
}
|
|
1543
1544
|
else if (!cursor.type.isAnonymous && cursor.from < cursor.to && (nest = this.nest(cursor, this.input))) {
|
|
1544
1545
|
if (!cursor.tree)
|
|
@@ -1593,16 +1594,16 @@ function checkCover(covered, from, to) {
|
|
|
1593
1594
|
if (range.from >= to)
|
|
1594
1595
|
break;
|
|
1595
1596
|
if (range.to > from)
|
|
1596
|
-
return range.from <= from && range.to >= to ? 2 /* Full */ : 1 /* Partial */;
|
|
1597
|
+
return range.from <= from && range.to >= to ? 2 /* Cover.Full */ : 1 /* Cover.Partial */;
|
|
1597
1598
|
}
|
|
1598
|
-
return 0 /* None */;
|
|
1599
|
+
return 0 /* Cover.None */;
|
|
1599
1600
|
}
|
|
1600
1601
|
// Take a piece of buffer and convert it into a stand-alone
|
|
1601
1602
|
// TreeBuffer.
|
|
1602
1603
|
function sliceBuf(buf, startI, endI, nodes, positions, off) {
|
|
1603
1604
|
if (startI < endI) {
|
|
1604
|
-
let from = buf.buffer[startI + 1]
|
|
1605
|
-
nodes.push(buf.slice(startI, endI, from
|
|
1605
|
+
let from = buf.buffer[startI + 1];
|
|
1606
|
+
nodes.push(buf.slice(startI, endI, from));
|
|
1606
1607
|
positions.push(from - off);
|
|
1607
1608
|
}
|
|
1608
1609
|
}
|
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
|
|
@@ -380,7 +380,7 @@ class Tree {
|
|
|
380
380
|
/// which may have children grouped into subtrees with type
|
|
381
381
|
/// [`NodeType.none`](#common.NodeType^none).
|
|
382
382
|
balance(config = {}) {
|
|
383
|
-
return this.children.length <= 8 /* BranchFactor */ ? this :
|
|
383
|
+
return this.children.length <= 8 /* Balance.BranchFactor */ ? this :
|
|
384
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)));
|
|
385
385
|
}
|
|
386
386
|
/// Build a tree from a postfix-ordered buffer of node information,
|
|
@@ -459,26 +459,27 @@ class TreeBuffer {
|
|
|
459
459
|
return pick;
|
|
460
460
|
}
|
|
461
461
|
/// @internal
|
|
462
|
-
slice(startI, endI, from
|
|
462
|
+
slice(startI, endI, from) {
|
|
463
463
|
let b = this.buffer;
|
|
464
|
-
let copy = new Uint16Array(endI - startI);
|
|
464
|
+
let copy = new Uint16Array(endI - startI), len = 0;
|
|
465
465
|
for (let i = startI, j = 0; i < endI;) {
|
|
466
466
|
copy[j++] = b[i++];
|
|
467
467
|
copy[j++] = b[i++] - from;
|
|
468
|
-
copy[j++] = b[i++] - from;
|
|
468
|
+
let to = copy[j++] = b[i++] - from;
|
|
469
469
|
copy[j++] = b[i++] - startI;
|
|
470
|
+
len = Math.max(len, to);
|
|
470
471
|
}
|
|
471
|
-
return new TreeBuffer(copy,
|
|
472
|
+
return new TreeBuffer(copy, len, this.set);
|
|
472
473
|
}
|
|
473
474
|
}
|
|
474
475
|
function checkSide(side, pos, from, to) {
|
|
475
476
|
switch (side) {
|
|
476
|
-
case -2 /* Before */: return from < pos;
|
|
477
|
-
case -1 /* AtOrBefore */: return to >= pos && from < pos;
|
|
478
|
-
case 0 /* Around */: return from < pos && to > pos;
|
|
479
|
-
case 1 /* AtOrAfter */: return from <= pos && to > pos;
|
|
480
|
-
case 2 /* After */: return to > pos;
|
|
481
|
-
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;
|
|
482
483
|
}
|
|
483
484
|
}
|
|
484
485
|
function enterUnfinishedNodesBefore(node, pos) {
|
|
@@ -568,10 +569,10 @@ class TreeNode {
|
|
|
568
569
|
return null;
|
|
569
570
|
}
|
|
570
571
|
}
|
|
571
|
-
get firstChild() { return this.nextChild(0, 1, 0, 4 /* DontCare */); }
|
|
572
|
-
get lastChild() { return this.nextChild(this._tree.children.length - 1, -1, 0, 4 /* DontCare */); }
|
|
573
|
-
childAfter(pos) { return this.nextChild(0, 1, pos, 2 /* After */); }
|
|
574
|
-
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 */); }
|
|
575
576
|
enter(pos, side, mode = 0) {
|
|
576
577
|
let mounted;
|
|
577
578
|
if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
|
|
@@ -594,10 +595,10 @@ class TreeNode {
|
|
|
594
595
|
return this._parent ? this._parent.nextSignificantParent() : null;
|
|
595
596
|
}
|
|
596
597
|
get nextSibling() {
|
|
597
|
-
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;
|
|
598
599
|
}
|
|
599
600
|
get prevSibling() {
|
|
600
|
-
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;
|
|
601
602
|
}
|
|
602
603
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
603
604
|
get tree() { return this._tree; }
|
|
@@ -659,24 +660,24 @@ class BufferContext {
|
|
|
659
660
|
}
|
|
660
661
|
}
|
|
661
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]; }
|
|
662
666
|
constructor(context, _parent, index) {
|
|
663
667
|
this.context = context;
|
|
664
668
|
this._parent = _parent;
|
|
665
669
|
this.index = index;
|
|
666
670
|
this.type = context.buffer.set.types[context.buffer.buffer[index]];
|
|
667
671
|
}
|
|
668
|
-
get name() { return this.type.name; }
|
|
669
|
-
get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
|
|
670
|
-
get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
|
|
671
672
|
child(dir, pos, side) {
|
|
672
673
|
let { buffer } = this.context;
|
|
673
674
|
let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
|
|
674
675
|
return index < 0 ? null : new BufferNode(this.context, this, index);
|
|
675
676
|
}
|
|
676
|
-
get firstChild() { return this.child(1, 0, 4 /* DontCare */); }
|
|
677
|
-
get lastChild() { return this.child(-1, 0, 4 /* DontCare */); }
|
|
678
|
-
childAfter(pos) { return this.child(1, pos, 2 /* After */); }
|
|
679
|
-
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 */); }
|
|
680
681
|
enter(pos, side, mode = 0) {
|
|
681
682
|
if (mode & IterMode.ExcludeBuffers)
|
|
682
683
|
return null;
|
|
@@ -688,7 +689,7 @@ class BufferNode {
|
|
|
688
689
|
return this._parent || this.context.parent.nextSignificantParent();
|
|
689
690
|
}
|
|
690
691
|
externalSibling(dir) {
|
|
691
|
-
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 */);
|
|
692
693
|
}
|
|
693
694
|
get nextSibling() {
|
|
694
695
|
let { buffer } = this.context;
|
|
@@ -702,7 +703,7 @@ class BufferNode {
|
|
|
702
703
|
let parentStart = this._parent ? this._parent.index + 4 : 0;
|
|
703
704
|
if (this.index == parentStart)
|
|
704
705
|
return this.externalSibling(-1);
|
|
705
|
-
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 */));
|
|
706
707
|
}
|
|
707
708
|
cursor(mode = 0) { return new TreeCursor(this, mode); }
|
|
708
709
|
get tree() { return null; }
|
|
@@ -711,8 +712,8 @@ class BufferNode {
|
|
|
711
712
|
let { buffer } = this.context;
|
|
712
713
|
let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
|
|
713
714
|
if (endI > startI) {
|
|
714
|
-
let from = buffer.buffer[this.index + 1]
|
|
715
|
-
children.push(buffer.slice(startI, endI, from
|
|
715
|
+
let from = buffer.buffer[this.index + 1];
|
|
716
|
+
children.push(buffer.slice(startI, endI, from));
|
|
716
717
|
positions.push(0);
|
|
717
718
|
}
|
|
718
719
|
return new Tree(this.type, children, positions, this.to - this.from);
|
|
@@ -739,6 +740,8 @@ class BufferNode {
|
|
|
739
740
|
/// A tree cursor object focuses on a given node in a syntax tree, and
|
|
740
741
|
/// allows you to move to adjacent nodes.
|
|
741
742
|
class TreeCursor {
|
|
743
|
+
/// Shorthand for `.type.name`.
|
|
744
|
+
get name() { return this.type.name; }
|
|
742
745
|
/// @internal
|
|
743
746
|
constructor(node,
|
|
744
747
|
/// @internal
|
|
@@ -762,8 +765,6 @@ class TreeCursor {
|
|
|
762
765
|
this.yieldBuf(node.index);
|
|
763
766
|
}
|
|
764
767
|
}
|
|
765
|
-
/// Shorthand for `.type.name`.
|
|
766
|
-
get name() { return this.type.name; }
|
|
767
768
|
yieldNode(node) {
|
|
768
769
|
if (!node)
|
|
769
770
|
return false;
|
|
@@ -808,13 +809,13 @@ class TreeCursor {
|
|
|
808
809
|
}
|
|
809
810
|
/// Move the cursor to this node's first child. When this returns
|
|
810
811
|
/// false, the node has no child, and the cursor has not been moved.
|
|
811
|
-
firstChild() { return this.enterChild(1, 0, 4 /* DontCare */); }
|
|
812
|
+
firstChild() { return this.enterChild(1, 0, 4 /* Side.DontCare */); }
|
|
812
813
|
/// Move the cursor to this node's last child.
|
|
813
|
-
lastChild() { return this.enterChild(-1, 0, 4 /* DontCare */); }
|
|
814
|
+
lastChild() { return this.enterChild(-1, 0, 4 /* Side.DontCare */); }
|
|
814
815
|
/// Move the cursor to the first child that ends after `pos`.
|
|
815
|
-
childAfter(pos) { return this.enterChild(1, pos, 2 /* After */); }
|
|
816
|
+
childAfter(pos) { return this.enterChild(1, pos, 2 /* Side.After */); }
|
|
816
817
|
/// Move to the last child that starts before `pos`.
|
|
817
|
-
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Before */); }
|
|
818
|
+
childBefore(pos) { return this.enterChild(-1, pos, -2 /* Side.Before */); }
|
|
818
819
|
/// Move the cursor to the child around `pos`. If side is -1 the
|
|
819
820
|
/// child may end at that position, when 1 it may start there. This
|
|
820
821
|
/// will also enter [overlaid](#common.MountedTree.overlay)
|
|
@@ -840,19 +841,19 @@ class TreeCursor {
|
|
|
840
841
|
if (!this.buffer)
|
|
841
842
|
return !this._tree._parent ? false
|
|
842
843
|
: this.yield(this._tree.index < 0 ? null
|
|
843
|
-
: 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));
|
|
844
845
|
let { buffer } = this.buffer, d = this.stack.length - 1;
|
|
845
846
|
if (dir < 0) {
|
|
846
847
|
let parentStart = d < 0 ? 0 : this.stack[d] + 4;
|
|
847
848
|
if (this.index != parentStart)
|
|
848
|
-
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 */));
|
|
849
850
|
}
|
|
850
851
|
else {
|
|
851
852
|
let after = buffer.buffer[this.index + 3];
|
|
852
853
|
if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
|
|
853
854
|
return this.yieldBuf(after);
|
|
854
855
|
}
|
|
855
|
-
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;
|
|
856
857
|
}
|
|
857
858
|
/// Move to this node's next sibling, if any.
|
|
858
859
|
nextSibling() { return this.sibling(1); }
|
|
@@ -889,7 +890,7 @@ class TreeCursor {
|
|
|
889
890
|
return true;
|
|
890
891
|
}
|
|
891
892
|
move(dir, enter) {
|
|
892
|
-
if (enter && this.enterChild(dir, 0, 4 /* DontCare */))
|
|
893
|
+
if (enter && this.enterChild(dir, 0, 4 /* Side.DontCare */))
|
|
893
894
|
return true;
|
|
894
895
|
for (;;) {
|
|
895
896
|
if (this.sibling(dir))
|
|
@@ -899,7 +900,7 @@ class TreeCursor {
|
|
|
899
900
|
}
|
|
900
901
|
}
|
|
901
902
|
/// Move to the next node in a
|
|
902
|
-
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-
|
|
903
|
+
/// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
|
|
903
904
|
/// traversal, going from a node to its first child or, if the
|
|
904
905
|
/// current node is empty or `enter` is false, its next sibling or
|
|
905
906
|
/// the next sibling of the first parent node that has one.
|
|
@@ -1015,17 +1016,17 @@ function buildTree(data) {
|
|
|
1015
1016
|
let lookAheadAtStart = lookAhead;
|
|
1016
1017
|
while (size < 0) {
|
|
1017
1018
|
cursor.next();
|
|
1018
|
-
if (size == -1 /* Reuse */) {
|
|
1019
|
+
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
1019
1020
|
let node = reused[id];
|
|
1020
1021
|
children.push(node);
|
|
1021
1022
|
positions.push(start - parentStart);
|
|
1022
1023
|
return;
|
|
1023
1024
|
}
|
|
1024
|
-
else if (size == -3 /* ContextChange */) { // Context change
|
|
1025
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) { // Context change
|
|
1025
1026
|
contextHash = id;
|
|
1026
1027
|
return;
|
|
1027
1028
|
}
|
|
1028
|
-
else if (size == -4 /* LookAhead */) {
|
|
1029
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1029
1030
|
lookAhead = id;
|
|
1030
1031
|
return;
|
|
1031
1032
|
}
|
|
@@ -1142,7 +1143,7 @@ function buildTree(data) {
|
|
|
1142
1143
|
fork.next();
|
|
1143
1144
|
while (fork.pos > startPos) {
|
|
1144
1145
|
if (fork.size < 0) {
|
|
1145
|
-
if (fork.size == -3 /* ContextChange */)
|
|
1146
|
+
if (fork.size == -3 /* SpecialRecord.ContextChange */)
|
|
1146
1147
|
localSkipped += 4;
|
|
1147
1148
|
else
|
|
1148
1149
|
break scan;
|
|
@@ -1178,10 +1179,10 @@ function buildTree(data) {
|
|
|
1178
1179
|
buffer[--index] = start - bufferStart;
|
|
1179
1180
|
buffer[--index] = id;
|
|
1180
1181
|
}
|
|
1181
|
-
else if (size == -3 /* ContextChange */) {
|
|
1182
|
+
else if (size == -3 /* SpecialRecord.ContextChange */) {
|
|
1182
1183
|
contextHash = id;
|
|
1183
1184
|
}
|
|
1184
|
-
else if (size == -4 /* LookAhead */) {
|
|
1185
|
+
else if (size == -4 /* SpecialRecord.LookAhead */) {
|
|
1185
1186
|
lookAhead = id;
|
|
1186
1187
|
}
|
|
1187
1188
|
return index;
|
|
@@ -1228,7 +1229,7 @@ mkTree) {
|
|
|
1228
1229
|
let total = 0;
|
|
1229
1230
|
for (let i = from; i < to; i++)
|
|
1230
1231
|
total += nodeSize(balanceType, children[i]);
|
|
1231
|
-
let maxChild = Math.ceil((total * 1.5) / 8 /* BranchFactor */);
|
|
1232
|
+
let maxChild = Math.ceil((total * 1.5) / 8 /* Balance.BranchFactor */);
|
|
1232
1233
|
let localChildren = [], localPositions = [];
|
|
1233
1234
|
function divide(children, positions, from, to, offset) {
|
|
1234
1235
|
for (let i = from; i < to;) {
|
|
@@ -1331,16 +1332,16 @@ class TreeFragment {
|
|
|
1331
1332
|
this.to = to;
|
|
1332
1333
|
this.tree = tree;
|
|
1333
1334
|
this.offset = offset;
|
|
1334
|
-
this.open = (openStart ? 1 /* Start */ : 0) | (openEnd ? 2 /* End */ : 0);
|
|
1335
|
+
this.open = (openStart ? 1 /* Open.Start */ : 0) | (openEnd ? 2 /* Open.End */ : 0);
|
|
1335
1336
|
}
|
|
1336
1337
|
/// Whether the start of the fragment represents the start of a
|
|
1337
1338
|
/// parse, or the end of a change. (In the second case, it may not
|
|
1338
1339
|
/// be safe to reuse some nodes at the start, depending on the
|
|
1339
1340
|
/// parsing algorithm.)
|
|
1340
|
-
get openStart() { return (this.open & 1 /* Start */) > 0; }
|
|
1341
|
+
get openStart() { return (this.open & 1 /* Open.Start */) > 0; }
|
|
1341
1342
|
/// Whether the end of the fragment represents the end of a
|
|
1342
1343
|
/// full-document parse, or the start of a change.
|
|
1343
|
-
get openEnd() { return (this.open & 2 /* End */) > 0; }
|
|
1344
|
+
get openEnd() { return (this.open & 2 /* Open.End */) > 0; }
|
|
1344
1345
|
/// Create a set of fragments from a freshly parsed tree, or update
|
|
1345
1346
|
/// an existing set of fragments by replacing the ones that overlap
|
|
1346
1347
|
/// with a tree with content from the new tree. When `partial` is
|
|
@@ -1534,7 +1535,7 @@ class MixedParse {
|
|
|
1534
1535
|
enter = false;
|
|
1535
1536
|
}
|
|
1536
1537
|
else if (covered && (isCovered = checkCover(covered.ranges, cursor.from, cursor.to))) {
|
|
1537
|
-
enter = isCovered != 2 /* Full */;
|
|
1538
|
+
enter = isCovered != 2 /* Cover.Full */;
|
|
1538
1539
|
}
|
|
1539
1540
|
else if (!cursor.type.isAnonymous && cursor.from < cursor.to && (nest = this.nest(cursor, this.input))) {
|
|
1540
1541
|
if (!cursor.tree)
|
|
@@ -1589,16 +1590,16 @@ function checkCover(covered, from, to) {
|
|
|
1589
1590
|
if (range.from >= to)
|
|
1590
1591
|
break;
|
|
1591
1592
|
if (range.to > from)
|
|
1592
|
-
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 */;
|
|
1593
1594
|
}
|
|
1594
|
-
return 0 /* None */;
|
|
1595
|
+
return 0 /* Cover.None */;
|
|
1595
1596
|
}
|
|
1596
1597
|
// Take a piece of buffer and convert it into a stand-alone
|
|
1597
1598
|
// TreeBuffer.
|
|
1598
1599
|
function sliceBuf(buf, startI, endI, nodes, positions, off) {
|
|
1599
1600
|
if (startI < endI) {
|
|
1600
|
-
let from = buf.buffer[startI + 1]
|
|
1601
|
-
nodes.push(buf.slice(startI, endI, from
|
|
1601
|
+
let from = buf.buffer[startI + 1];
|
|
1602
|
+
nodes.push(buf.slice(startI, endI, from));
|
|
1602
1603
|
positions.push(from - off);
|
|
1603
1604
|
}
|
|
1604
1605
|
}
|
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",
|