@lezer/common 0.15.8 → 0.15.9

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 CHANGED
@@ -286,7 +286,8 @@ class Tree {
286
286
  }
287
287
  /// Get a [tree cursor](#common.TreeCursor) that, unlike regular
288
288
  /// cursors, doesn't skip through
289
- /// [anonymous](#common.NodeType.isAnonymous) nodes.
289
+ /// [anonymous](#common.NodeType.isAnonymous) nodes and doesn't
290
+ /// automatically enter mounted nodes.
290
291
  fullCursor() {
291
292
  return new TreeCursor(this.topNode, 1 /* Full */);
292
293
  }
@@ -508,7 +509,7 @@ class TreeNode {
508
509
  }
509
510
  else if ((mode & 1 /* Full */) || (!next.type.isAnonymous || hasChild(next))) {
510
511
  let mounted;
511
- if (next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
512
+ if (!(mode & 1 /* Full */) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
512
513
  return new TreeNode(mounted.tree, start, i, parent);
513
514
  let inner = new TreeNode(next, start, i, parent);
514
515
  return (mode & 1 /* Full */) || !inner.type.isAnonymous ? inner
@@ -756,7 +757,7 @@ class TreeCursor {
756
757
  /// set to false.
757
758
  enter(pos, side, overlays = true, buffers = true) {
758
759
  if (!this.buffer)
759
- return this.yield(this._tree.enter(pos, side, overlays, buffers));
760
+ return this.yield(this._tree.enter(pos, side, overlays && !(this.mode & 1 /* Full */), buffers));
760
761
  return buffers ? this.enterChild(1, pos, side) : false;
761
762
  }
762
763
  /// Move to the node's parent node, if this isn't the top node.
@@ -1274,11 +1275,12 @@ function parseMixed(nest) {
1274
1275
  return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
1275
1276
  }
1276
1277
  class InnerParse {
1277
- constructor(parser, parse, overlay, target) {
1278
+ constructor(parser, parse, overlay, target, ranges) {
1278
1279
  this.parser = parser;
1279
1280
  this.parse = parse;
1280
1281
  this.overlay = overlay;
1281
1282
  this.target = target;
1283
+ this.ranges = ranges;
1282
1284
  }
1283
1285
  }
1284
1286
  class ActiveOverlay {
@@ -1294,6 +1296,7 @@ class ActiveOverlay {
1294
1296
  this.ranges = [];
1295
1297
  }
1296
1298
  }
1299
+ const stoppedInner = new NodeProp({ perNode: true });
1297
1300
  class MixedParse {
1298
1301
  constructor(base, nest, input, fragments, ranges) {
1299
1302
  this.nest = nest;
@@ -1315,8 +1318,12 @@ class MixedParse {
1315
1318
  this.baseTree = done;
1316
1319
  this.startInner();
1317
1320
  }
1318
- if (this.innerDone == this.inner.length)
1319
- return this.baseTree;
1321
+ if (this.innerDone == this.inner.length) {
1322
+ let result = this.baseTree;
1323
+ if (this.stoppedAt != null)
1324
+ result = new Tree(result.type, result.children, result.positions, result.length, result.propValues.concat([[stoppedInner, this.stoppedAt]]));
1325
+ return result;
1326
+ }
1320
1327
  let inner = this.inner[this.innerDone], done = inner.parse.advance();
1321
1328
  if (done) {
1322
1329
  this.innerDone++;
@@ -1333,8 +1340,12 @@ class MixedParse {
1333
1340
  get parsedPos() {
1334
1341
  if (this.baseParse)
1335
1342
  return 0;
1336
- let next = this.inner[this.innerDone];
1337
- return next ? next.parse.parsedPos : this.input.length;
1343
+ let pos = this.input.length;
1344
+ for (let i = this.innerDone; i < this.inner.length; i++) {
1345
+ if (this.inner[i].ranges[0].from < pos)
1346
+ pos = Math.min(pos, this.inner[i].parse.parsedPos);
1347
+ }
1348
+ return pos;
1338
1349
  }
1339
1350
  stopAt(pos) {
1340
1351
  this.stoppedAt = pos;
@@ -1376,7 +1387,7 @@ class MixedParse {
1376
1387
  else {
1377
1388
  let ranges = punchRanges(this.ranges, nest.overlay || [new Range(cursor.from, cursor.to)]);
1378
1389
  if (ranges.length)
1379
- this.inner.push(new InnerParse(nest.parser, nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges), nest.overlay ? nest.overlay.map(r => new Range(r.from - cursor.from, r.to - cursor.from)) : null, cursor.tree));
1390
+ this.inner.push(new InnerParse(nest.parser, nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges), nest.overlay ? nest.overlay.map(r => new Range(r.from - cursor.from, r.to - cursor.from)) : null, cursor.tree, ranges));
1380
1391
  if (!nest.overlay)
1381
1392
  enter = false;
1382
1393
  else if (ranges.length)
@@ -1404,7 +1415,7 @@ class MixedParse {
1404
1415
  if (overlay && !--overlay.depth) {
1405
1416
  let ranges = punchRanges(this.ranges, overlay.ranges);
1406
1417
  if (ranges.length)
1407
- this.inner.splice(overlay.index, 0, new InnerParse(overlay.parser, overlay.parser.startParse(this.input, enterFragments(overlay.mounts, ranges), ranges), overlay.ranges.map(r => new Range(r.from - overlay.start, r.to - overlay.start)), overlay.target));
1418
+ this.inner.splice(overlay.index, 0, new InnerParse(overlay.parser, overlay.parser.startParse(this.input, enterFragments(overlay.mounts, ranges), ranges), overlay.ranges.map(r => new Range(r.from - overlay.start, r.to - overlay.start)), overlay.target, ranges));
1408
1419
  overlay = overlay.prev;
1409
1420
  }
1410
1421
  if (covered && !--covered.depth)
@@ -1504,10 +1515,13 @@ class StructureCursor {
1504
1515
  }
1505
1516
  class FragmentCursor {
1506
1517
  constructor(fragments) {
1518
+ var _a;
1507
1519
  this.fragments = fragments;
1520
+ this.curTo = 0;
1508
1521
  this.fragI = 0;
1509
1522
  if (fragments.length) {
1510
1523
  let first = this.curFrag = fragments[0];
1524
+ this.curTo = (_a = first.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : first.to;
1511
1525
  this.inner = new StructureCursor(first.tree, -first.offset);
1512
1526
  }
1513
1527
  else {
@@ -1515,17 +1529,19 @@ class FragmentCursor {
1515
1529
  }
1516
1530
  }
1517
1531
  hasNode(node) {
1518
- while (this.curFrag && node.from >= this.curFrag.to)
1532
+ while (this.curFrag && node.from >= this.curTo)
1519
1533
  this.nextFrag();
1520
- return this.curFrag && this.curFrag.from <= node.from && this.curFrag.to >= node.to && this.inner.hasNode(node);
1534
+ return this.curFrag && this.curFrag.from <= node.from && this.curTo >= node.to && this.inner.hasNode(node);
1521
1535
  }
1522
1536
  nextFrag() {
1537
+ var _a;
1523
1538
  this.fragI++;
1524
1539
  if (this.fragI == this.fragments.length) {
1525
1540
  this.curFrag = this.inner = null;
1526
1541
  }
1527
1542
  else {
1528
1543
  let frag = this.curFrag = this.fragments[this.fragI];
1544
+ this.curTo = (_a = frag.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : frag.to;
1529
1545
  this.inner = new StructureCursor(frag.tree, -frag.offset);
1530
1546
  }
1531
1547
  }
package/dist/index.js CHANGED
@@ -282,7 +282,8 @@ class Tree {
282
282
  }
283
283
  /// Get a [tree cursor](#common.TreeCursor) that, unlike regular
284
284
  /// cursors, doesn't skip through
285
- /// [anonymous](#common.NodeType.isAnonymous) nodes.
285
+ /// [anonymous](#common.NodeType.isAnonymous) nodes and doesn't
286
+ /// automatically enter mounted nodes.
286
287
  fullCursor() {
287
288
  return new TreeCursor(this.topNode, 1 /* Full */);
288
289
  }
@@ -504,7 +505,7 @@ class TreeNode {
504
505
  }
505
506
  else if ((mode & 1 /* Full */) || (!next.type.isAnonymous || hasChild(next))) {
506
507
  let mounted;
507
- if (next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
508
+ if (!(mode & 1 /* Full */) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
508
509
  return new TreeNode(mounted.tree, start, i, parent);
509
510
  let inner = new TreeNode(next, start, i, parent);
510
511
  return (mode & 1 /* Full */) || !inner.type.isAnonymous ? inner
@@ -752,7 +753,7 @@ class TreeCursor {
752
753
  /// set to false.
753
754
  enter(pos, side, overlays = true, buffers = true) {
754
755
  if (!this.buffer)
755
- return this.yield(this._tree.enter(pos, side, overlays, buffers));
756
+ return this.yield(this._tree.enter(pos, side, overlays && !(this.mode & 1 /* Full */), buffers));
756
757
  return buffers ? this.enterChild(1, pos, side) : false;
757
758
  }
758
759
  /// Move to the node's parent node, if this isn't the top node.
@@ -1270,11 +1271,12 @@ function parseMixed(nest) {
1270
1271
  return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
1271
1272
  }
1272
1273
  class InnerParse {
1273
- constructor(parser, parse, overlay, target) {
1274
+ constructor(parser, parse, overlay, target, ranges) {
1274
1275
  this.parser = parser;
1275
1276
  this.parse = parse;
1276
1277
  this.overlay = overlay;
1277
1278
  this.target = target;
1279
+ this.ranges = ranges;
1278
1280
  }
1279
1281
  }
1280
1282
  class ActiveOverlay {
@@ -1290,6 +1292,7 @@ class ActiveOverlay {
1290
1292
  this.ranges = [];
1291
1293
  }
1292
1294
  }
1295
+ const stoppedInner = new NodeProp({ perNode: true });
1293
1296
  class MixedParse {
1294
1297
  constructor(base, nest, input, fragments, ranges) {
1295
1298
  this.nest = nest;
@@ -1311,8 +1314,12 @@ class MixedParse {
1311
1314
  this.baseTree = done;
1312
1315
  this.startInner();
1313
1316
  }
1314
- if (this.innerDone == this.inner.length)
1315
- return this.baseTree;
1317
+ if (this.innerDone == this.inner.length) {
1318
+ let result = this.baseTree;
1319
+ if (this.stoppedAt != null)
1320
+ result = new Tree(result.type, result.children, result.positions, result.length, result.propValues.concat([[stoppedInner, this.stoppedAt]]));
1321
+ return result;
1322
+ }
1316
1323
  let inner = this.inner[this.innerDone], done = inner.parse.advance();
1317
1324
  if (done) {
1318
1325
  this.innerDone++;
@@ -1329,8 +1336,12 @@ class MixedParse {
1329
1336
  get parsedPos() {
1330
1337
  if (this.baseParse)
1331
1338
  return 0;
1332
- let next = this.inner[this.innerDone];
1333
- return next ? next.parse.parsedPos : this.input.length;
1339
+ let pos = this.input.length;
1340
+ for (let i = this.innerDone; i < this.inner.length; i++) {
1341
+ if (this.inner[i].ranges[0].from < pos)
1342
+ pos = Math.min(pos, this.inner[i].parse.parsedPos);
1343
+ }
1344
+ return pos;
1334
1345
  }
1335
1346
  stopAt(pos) {
1336
1347
  this.stoppedAt = pos;
@@ -1372,7 +1383,7 @@ class MixedParse {
1372
1383
  else {
1373
1384
  let ranges = punchRanges(this.ranges, nest.overlay || [new Range(cursor.from, cursor.to)]);
1374
1385
  if (ranges.length)
1375
- this.inner.push(new InnerParse(nest.parser, nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges), nest.overlay ? nest.overlay.map(r => new Range(r.from - cursor.from, r.to - cursor.from)) : null, cursor.tree));
1386
+ this.inner.push(new InnerParse(nest.parser, nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges), nest.overlay ? nest.overlay.map(r => new Range(r.from - cursor.from, r.to - cursor.from)) : null, cursor.tree, ranges));
1376
1387
  if (!nest.overlay)
1377
1388
  enter = false;
1378
1389
  else if (ranges.length)
@@ -1400,7 +1411,7 @@ class MixedParse {
1400
1411
  if (overlay && !--overlay.depth) {
1401
1412
  let ranges = punchRanges(this.ranges, overlay.ranges);
1402
1413
  if (ranges.length)
1403
- this.inner.splice(overlay.index, 0, new InnerParse(overlay.parser, overlay.parser.startParse(this.input, enterFragments(overlay.mounts, ranges), ranges), overlay.ranges.map(r => new Range(r.from - overlay.start, r.to - overlay.start)), overlay.target));
1414
+ this.inner.splice(overlay.index, 0, new InnerParse(overlay.parser, overlay.parser.startParse(this.input, enterFragments(overlay.mounts, ranges), ranges), overlay.ranges.map(r => new Range(r.from - overlay.start, r.to - overlay.start)), overlay.target, ranges));
1404
1415
  overlay = overlay.prev;
1405
1416
  }
1406
1417
  if (covered && !--covered.depth)
@@ -1500,10 +1511,13 @@ class StructureCursor {
1500
1511
  }
1501
1512
  class FragmentCursor {
1502
1513
  constructor(fragments) {
1514
+ var _a;
1503
1515
  this.fragments = fragments;
1516
+ this.curTo = 0;
1504
1517
  this.fragI = 0;
1505
1518
  if (fragments.length) {
1506
1519
  let first = this.curFrag = fragments[0];
1520
+ this.curTo = (_a = first.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : first.to;
1507
1521
  this.inner = new StructureCursor(first.tree, -first.offset);
1508
1522
  }
1509
1523
  else {
@@ -1511,17 +1525,19 @@ class FragmentCursor {
1511
1525
  }
1512
1526
  }
1513
1527
  hasNode(node) {
1514
- while (this.curFrag && node.from >= this.curFrag.to)
1528
+ while (this.curFrag && node.from >= this.curTo)
1515
1529
  this.nextFrag();
1516
- return this.curFrag && this.curFrag.from <= node.from && this.curFrag.to >= node.to && this.inner.hasNode(node);
1530
+ return this.curFrag && this.curFrag.from <= node.from && this.curTo >= node.to && this.inner.hasNode(node);
1517
1531
  }
1518
1532
  nextFrag() {
1533
+ var _a;
1519
1534
  this.fragI++;
1520
1535
  if (this.fragI == this.fragments.length) {
1521
1536
  this.curFrag = this.inner = null;
1522
1537
  }
1523
1538
  else {
1524
1539
  let frag = this.curFrag = this.fragments[this.fragI];
1540
+ this.curTo = (_a = frag.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : frag.to;
1525
1541
  this.inner = new StructureCursor(frag.tree, -frag.offset);
1526
1542
  }
1527
1543
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lezer/common",
3
- "version": "0.15.8",
3
+ "version": "0.15.9",
4
4
  "description": "Syntax tree data structure and parser interfaces for the lezer parser",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "module",