@lezer/common 1.2.1 → 1.2.3
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 +24 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -19
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -692,7 +692,7 @@ class BaseNode {
|
|
|
692
692
|
return resolveNode(this, pos, side, true);
|
|
693
693
|
}
|
|
694
694
|
matchContext(context) {
|
|
695
|
-
return matchNodeContext(this, context);
|
|
695
|
+
return matchNodeContext(this.parent, context);
|
|
696
696
|
}
|
|
697
697
|
enterUnfinishedNodesBefore(pos) {
|
|
698
698
|
let scan = this.childBefore(pos), node = this;
|
|
@@ -817,7 +817,7 @@ function getChildren(node, type, before, after) {
|
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
819
|
function matchNodeContext(node, context, i = context.length - 1) {
|
|
820
|
-
for (let p = node
|
|
820
|
+
for (let p = node; i >= 0; p = p.parent) {
|
|
821
821
|
if (!p)
|
|
822
822
|
return false;
|
|
823
823
|
if (!p.type.isAnonymous) {
|
|
@@ -1153,7 +1153,7 @@ class TreeCursor {
|
|
|
1153
1153
|
*/
|
|
1154
1154
|
next(enter = true) { return this.move(1, enter); }
|
|
1155
1155
|
/**
|
|
1156
|
-
Move to the next node in a last-to-first pre-order
|
|
1156
|
+
Move to the next node in a last-to-first pre-order traversal. A
|
|
1157
1157
|
node is followed by its last child or, if it has none, its
|
|
1158
1158
|
previous sibling or the previous sibling of the first parent
|
|
1159
1159
|
node that has one.
|
|
@@ -1229,10 +1229,10 @@ class TreeCursor {
|
|
|
1229
1229
|
if (mustLeave && leave)
|
|
1230
1230
|
leave(this);
|
|
1231
1231
|
mustLeave = this.type.isAnonymous;
|
|
1232
|
-
if (this.nextSibling())
|
|
1233
|
-
break;
|
|
1234
1232
|
if (!depth)
|
|
1235
1233
|
return;
|
|
1234
|
+
if (this.nextSibling())
|
|
1235
|
+
break;
|
|
1236
1236
|
this.parent();
|
|
1237
1237
|
depth--;
|
|
1238
1238
|
mustLeave = true;
|
|
@@ -1246,11 +1246,11 @@ class TreeCursor {
|
|
|
1246
1246
|
*/
|
|
1247
1247
|
matchContext(context) {
|
|
1248
1248
|
if (!this.buffer)
|
|
1249
|
-
return matchNodeContext(this.node, context);
|
|
1249
|
+
return matchNodeContext(this.node.parent, context);
|
|
1250
1250
|
let { buffer } = this.buffer, { types } = buffer.set;
|
|
1251
1251
|
for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
|
|
1252
1252
|
if (d < 0)
|
|
1253
|
-
return matchNodeContext(this.
|
|
1253
|
+
return matchNodeContext(this._tree, context, i);
|
|
1254
1254
|
let type = types[buffer.buffer[this.stack[d]]];
|
|
1255
1255
|
if (!type.isAnonymous) {
|
|
1256
1256
|
if (context[i] && context[i] != type.name)
|
|
@@ -1272,7 +1272,7 @@ function buildTree(data) {
|
|
|
1272
1272
|
let contextHash = 0, lookAhead = 0;
|
|
1273
1273
|
function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
|
|
1274
1274
|
let { id, start, end, size } = cursor;
|
|
1275
|
-
let lookAheadAtStart = lookAhead;
|
|
1275
|
+
let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
|
|
1276
1276
|
while (size < 0) {
|
|
1277
1277
|
cursor.next();
|
|
1278
1278
|
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
@@ -1313,7 +1313,7 @@ function buildTree(data) {
|
|
|
1313
1313
|
while (cursor.pos > endPos) {
|
|
1314
1314
|
if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
|
|
1315
1315
|
if (cursor.end <= lastEnd - maxBufferLength) {
|
|
1316
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1316
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
1317
1317
|
lastGroup = localChildren.length;
|
|
1318
1318
|
lastEnd = cursor.end;
|
|
1319
1319
|
}
|
|
@@ -1327,15 +1327,15 @@ function buildTree(data) {
|
|
|
1327
1327
|
}
|
|
1328
1328
|
}
|
|
1329
1329
|
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
|
|
1330
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1330
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
1331
1331
|
localChildren.reverse();
|
|
1332
1332
|
localPositions.reverse();
|
|
1333
1333
|
if (localInRepeat > -1 && lastGroup > 0) {
|
|
1334
|
-
let make = makeBalanced(type);
|
|
1334
|
+
let make = makeBalanced(type, contextAtStart);
|
|
1335
1335
|
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
|
|
1336
1336
|
}
|
|
1337
1337
|
else {
|
|
1338
|
-
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
|
|
1338
|
+
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end, contextAtStart);
|
|
1339
1339
|
}
|
|
1340
1340
|
}
|
|
1341
1341
|
children.push(node);
|
|
@@ -1373,7 +1373,7 @@ function buildTree(data) {
|
|
|
1373
1373
|
positions.push(start - parentStart);
|
|
1374
1374
|
}
|
|
1375
1375
|
}
|
|
1376
|
-
function makeBalanced(type) {
|
|
1376
|
+
function makeBalanced(type, contextHash) {
|
|
1377
1377
|
return (children, positions, length) => {
|
|
1378
1378
|
let lookAhead = 0, lastI = children.length - 1, last, lookAheadProp;
|
|
1379
1379
|
if (lastI >= 0 && (last = children[lastI]) instanceof Tree) {
|
|
@@ -1382,19 +1382,19 @@ function buildTree(data) {
|
|
|
1382
1382
|
if (lookAheadProp = last.prop(NodeProp.lookAhead))
|
|
1383
1383
|
lookAhead = positions[lastI] + last.length + lookAheadProp;
|
|
1384
1384
|
}
|
|
1385
|
-
return makeTree(type, children, positions, length, lookAhead);
|
|
1385
|
+
return makeTree(type, children, positions, length, lookAhead, contextHash);
|
|
1386
1386
|
};
|
|
1387
1387
|
}
|
|
1388
|
-
function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead) {
|
|
1388
|
+
function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead, contextHash) {
|
|
1389
1389
|
let localChildren = [], localPositions = [];
|
|
1390
1390
|
while (children.length > i) {
|
|
1391
1391
|
localChildren.push(children.pop());
|
|
1392
1392
|
localPositions.push(positions.pop() + base - from);
|
|
1393
1393
|
}
|
|
1394
|
-
children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to));
|
|
1394
|
+
children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to, contextHash));
|
|
1395
1395
|
positions.push(from - base);
|
|
1396
1396
|
}
|
|
1397
|
-
function makeTree(type, children, positions, length, lookAhead
|
|
1397
|
+
function makeTree(type, children, positions, length, lookAhead, contextHash, props) {
|
|
1398
1398
|
if (contextHash) {
|
|
1399
1399
|
let pair = [NodeProp.contextHash, contextHash];
|
|
1400
1400
|
props = props ? [pair].concat(props) : [pair];
|
|
@@ -1901,8 +1901,13 @@ class MixedParse {
|
|
|
1901
1901
|
else if (overlay && (range = overlay.predicate(cursor))) {
|
|
1902
1902
|
if (range === true)
|
|
1903
1903
|
range = new Range(cursor.from, cursor.to);
|
|
1904
|
-
if (range.from < range.to)
|
|
1905
|
-
overlay.ranges.
|
|
1904
|
+
if (range.from < range.to) {
|
|
1905
|
+
let last = overlay.ranges.length - 1;
|
|
1906
|
+
if (last >= 0 && overlay.ranges[last].to == range.from)
|
|
1907
|
+
overlay.ranges[last] = { from: overlay.ranges[last].from, to: range.to };
|
|
1908
|
+
else
|
|
1909
|
+
overlay.ranges.push(range);
|
|
1910
|
+
}
|
|
1906
1911
|
}
|
|
1907
1912
|
if (enter && cursor.firstChild()) {
|
|
1908
1913
|
if (overlay)
|
package/dist/index.d.cts
CHANGED
|
@@ -1024,7 +1024,7 @@ declare class TreeCursor implements SyntaxNodeRef {
|
|
|
1024
1024
|
*/
|
|
1025
1025
|
next(enter?: boolean): boolean;
|
|
1026
1026
|
/**
|
|
1027
|
-
Move to the next node in a last-to-first pre-order
|
|
1027
|
+
Move to the next node in a last-to-first pre-order traversal. A
|
|
1028
1028
|
node is followed by its last child or, if it has none, its
|
|
1029
1029
|
previous sibling or the previous sibling of the first parent
|
|
1030
1030
|
node that has one.
|
package/dist/index.d.ts
CHANGED
|
@@ -1024,7 +1024,7 @@ declare class TreeCursor implements SyntaxNodeRef {
|
|
|
1024
1024
|
*/
|
|
1025
1025
|
next(enter?: boolean): boolean;
|
|
1026
1026
|
/**
|
|
1027
|
-
Move to the next node in a last-to-first pre-order
|
|
1027
|
+
Move to the next node in a last-to-first pre-order traversal. A
|
|
1028
1028
|
node is followed by its last child or, if it has none, its
|
|
1029
1029
|
previous sibling or the previous sibling of the first parent
|
|
1030
1030
|
node that has one.
|
package/dist/index.js
CHANGED
|
@@ -690,7 +690,7 @@ class BaseNode {
|
|
|
690
690
|
return resolveNode(this, pos, side, true);
|
|
691
691
|
}
|
|
692
692
|
matchContext(context) {
|
|
693
|
-
return matchNodeContext(this, context);
|
|
693
|
+
return matchNodeContext(this.parent, context);
|
|
694
694
|
}
|
|
695
695
|
enterUnfinishedNodesBefore(pos) {
|
|
696
696
|
let scan = this.childBefore(pos), node = this;
|
|
@@ -815,7 +815,7 @@ function getChildren(node, type, before, after) {
|
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
817
|
function matchNodeContext(node, context, i = context.length - 1) {
|
|
818
|
-
for (let p = node
|
|
818
|
+
for (let p = node; i >= 0; p = p.parent) {
|
|
819
819
|
if (!p)
|
|
820
820
|
return false;
|
|
821
821
|
if (!p.type.isAnonymous) {
|
|
@@ -1151,7 +1151,7 @@ class TreeCursor {
|
|
|
1151
1151
|
*/
|
|
1152
1152
|
next(enter = true) { return this.move(1, enter); }
|
|
1153
1153
|
/**
|
|
1154
|
-
Move to the next node in a last-to-first pre-order
|
|
1154
|
+
Move to the next node in a last-to-first pre-order traversal. A
|
|
1155
1155
|
node is followed by its last child or, if it has none, its
|
|
1156
1156
|
previous sibling or the previous sibling of the first parent
|
|
1157
1157
|
node that has one.
|
|
@@ -1227,10 +1227,10 @@ class TreeCursor {
|
|
|
1227
1227
|
if (mustLeave && leave)
|
|
1228
1228
|
leave(this);
|
|
1229
1229
|
mustLeave = this.type.isAnonymous;
|
|
1230
|
-
if (this.nextSibling())
|
|
1231
|
-
break;
|
|
1232
1230
|
if (!depth)
|
|
1233
1231
|
return;
|
|
1232
|
+
if (this.nextSibling())
|
|
1233
|
+
break;
|
|
1234
1234
|
this.parent();
|
|
1235
1235
|
depth--;
|
|
1236
1236
|
mustLeave = true;
|
|
@@ -1244,11 +1244,11 @@ class TreeCursor {
|
|
|
1244
1244
|
*/
|
|
1245
1245
|
matchContext(context) {
|
|
1246
1246
|
if (!this.buffer)
|
|
1247
|
-
return matchNodeContext(this.node, context);
|
|
1247
|
+
return matchNodeContext(this.node.parent, context);
|
|
1248
1248
|
let { buffer } = this.buffer, { types } = buffer.set;
|
|
1249
1249
|
for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
|
|
1250
1250
|
if (d < 0)
|
|
1251
|
-
return matchNodeContext(this.
|
|
1251
|
+
return matchNodeContext(this._tree, context, i);
|
|
1252
1252
|
let type = types[buffer.buffer[this.stack[d]]];
|
|
1253
1253
|
if (!type.isAnonymous) {
|
|
1254
1254
|
if (context[i] && context[i] != type.name)
|
|
@@ -1270,7 +1270,7 @@ function buildTree(data) {
|
|
|
1270
1270
|
let contextHash = 0, lookAhead = 0;
|
|
1271
1271
|
function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
|
|
1272
1272
|
let { id, start, end, size } = cursor;
|
|
1273
|
-
let lookAheadAtStart = lookAhead;
|
|
1273
|
+
let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
|
|
1274
1274
|
while (size < 0) {
|
|
1275
1275
|
cursor.next();
|
|
1276
1276
|
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
@@ -1311,7 +1311,7 @@ function buildTree(data) {
|
|
|
1311
1311
|
while (cursor.pos > endPos) {
|
|
1312
1312
|
if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
|
|
1313
1313
|
if (cursor.end <= lastEnd - maxBufferLength) {
|
|
1314
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1314
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
1315
1315
|
lastGroup = localChildren.length;
|
|
1316
1316
|
lastEnd = cursor.end;
|
|
1317
1317
|
}
|
|
@@ -1325,15 +1325,15 @@ function buildTree(data) {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
}
|
|
1327
1327
|
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
|
|
1328
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
|
|
1328
|
+
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
1329
1329
|
localChildren.reverse();
|
|
1330
1330
|
localPositions.reverse();
|
|
1331
1331
|
if (localInRepeat > -1 && lastGroup > 0) {
|
|
1332
|
-
let make = makeBalanced(type);
|
|
1332
|
+
let make = makeBalanced(type, contextAtStart);
|
|
1333
1333
|
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
|
|
1334
1334
|
}
|
|
1335
1335
|
else {
|
|
1336
|
-
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
|
|
1336
|
+
node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end, contextAtStart);
|
|
1337
1337
|
}
|
|
1338
1338
|
}
|
|
1339
1339
|
children.push(node);
|
|
@@ -1371,7 +1371,7 @@ function buildTree(data) {
|
|
|
1371
1371
|
positions.push(start - parentStart);
|
|
1372
1372
|
}
|
|
1373
1373
|
}
|
|
1374
|
-
function makeBalanced(type) {
|
|
1374
|
+
function makeBalanced(type, contextHash) {
|
|
1375
1375
|
return (children, positions, length) => {
|
|
1376
1376
|
let lookAhead = 0, lastI = children.length - 1, last, lookAheadProp;
|
|
1377
1377
|
if (lastI >= 0 && (last = children[lastI]) instanceof Tree) {
|
|
@@ -1380,19 +1380,19 @@ function buildTree(data) {
|
|
|
1380
1380
|
if (lookAheadProp = last.prop(NodeProp.lookAhead))
|
|
1381
1381
|
lookAhead = positions[lastI] + last.length + lookAheadProp;
|
|
1382
1382
|
}
|
|
1383
|
-
return makeTree(type, children, positions, length, lookAhead);
|
|
1383
|
+
return makeTree(type, children, positions, length, lookAhead, contextHash);
|
|
1384
1384
|
};
|
|
1385
1385
|
}
|
|
1386
|
-
function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead) {
|
|
1386
|
+
function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead, contextHash) {
|
|
1387
1387
|
let localChildren = [], localPositions = [];
|
|
1388
1388
|
while (children.length > i) {
|
|
1389
1389
|
localChildren.push(children.pop());
|
|
1390
1390
|
localPositions.push(positions.pop() + base - from);
|
|
1391
1391
|
}
|
|
1392
|
-
children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to));
|
|
1392
|
+
children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to, contextHash));
|
|
1393
1393
|
positions.push(from - base);
|
|
1394
1394
|
}
|
|
1395
|
-
function makeTree(type, children, positions, length, lookAhead
|
|
1395
|
+
function makeTree(type, children, positions, length, lookAhead, contextHash, props) {
|
|
1396
1396
|
if (contextHash) {
|
|
1397
1397
|
let pair = [NodeProp.contextHash, contextHash];
|
|
1398
1398
|
props = props ? [pair].concat(props) : [pair];
|
|
@@ -1899,8 +1899,13 @@ class MixedParse {
|
|
|
1899
1899
|
else if (overlay && (range = overlay.predicate(cursor))) {
|
|
1900
1900
|
if (range === true)
|
|
1901
1901
|
range = new Range(cursor.from, cursor.to);
|
|
1902
|
-
if (range.from < range.to)
|
|
1903
|
-
overlay.ranges.
|
|
1902
|
+
if (range.from < range.to) {
|
|
1903
|
+
let last = overlay.ranges.length - 1;
|
|
1904
|
+
if (last >= 0 && overlay.ranges[last].to == range.from)
|
|
1905
|
+
overlay.ranges[last] = { from: overlay.ranges[last].from, to: range.to };
|
|
1906
|
+
else
|
|
1907
|
+
overlay.ranges.push(range);
|
|
1908
|
+
}
|
|
1904
1909
|
}
|
|
1905
1910
|
if (enter && cursor.firstChild()) {
|
|
1906
1911
|
if (overlay)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lezer/common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Syntax tree data structure and parser interfaces for the lezer parser",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"ist": "^1.1.1",
|
|
17
17
|
"@marijn/buildtool": "^0.1.5",
|
|
18
18
|
"@types/mocha": "^5.2.6",
|
|
19
|
-
"mocha": "^10.2.0"
|
|
19
|
+
"mocha": "^10.2.0",
|
|
20
|
+
"ts-node": "^10.9.2"
|
|
20
21
|
},
|
|
21
22
|
"files": ["dist"],
|
|
22
23
|
"repository": {
|