@lezer/common 0.16.0 → 1.0.1
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 +15 -12
- package/dist/index.js +15 -12
- package/dist/tree.d.ts +5 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
// FIXME profile adding a per-Tree TreeNode cache, validating it by
|
|
6
6
|
// parent pointer
|
|
7
|
-
/// The default maximum length of a `TreeBuffer` node
|
|
7
|
+
/// The default maximum length of a `TreeBuffer` node.
|
|
8
8
|
const DefaultBufferLength = 1024;
|
|
9
9
|
let nextPropID = 0;
|
|
10
10
|
class Range {
|
|
@@ -67,7 +67,7 @@ NodeProp.contextHash = new NodeProp({ perNode: true });
|
|
|
67
67
|
NodeProp.lookAhead = new NodeProp({ perNode: true });
|
|
68
68
|
/// This per-node prop is used to replace a given node, or part of a
|
|
69
69
|
/// node, with another tree. This is useful to include trees from
|
|
70
|
-
/// different languages.
|
|
70
|
+
/// different languages in mixed-language parsers.
|
|
71
71
|
NodeProp.mounted = new NodeProp({ perNode: true });
|
|
72
72
|
/// A mounted tree, which can be [stored](#common.NodeProp^mounted) on
|
|
73
73
|
/// a tree node to indicate that parts of its content are
|
|
@@ -113,6 +113,7 @@ class NodeType {
|
|
|
113
113
|
this.id = id;
|
|
114
114
|
this.flags = flags;
|
|
115
115
|
}
|
|
116
|
+
/// Define a node type.
|
|
116
117
|
static define(spec) {
|
|
117
118
|
let props = spec.props && spec.props.length ? Object.create(null) : noProps;
|
|
118
119
|
let flags = (spec.top ? 1 /* Top */ : 0) | (spec.skipped ? 2 /* Skipped */ : 0) |
|
|
@@ -194,7 +195,7 @@ class NodeSet {
|
|
|
194
195
|
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
|
|
195
196
|
}
|
|
196
197
|
/// Create a copy of this set with some node properties added. The
|
|
197
|
-
/// arguments to this method
|
|
198
|
+
/// arguments to this method can be created with
|
|
198
199
|
/// [`NodeProp.add`](#common.NodeProp.add).
|
|
199
200
|
extend(...props) {
|
|
200
201
|
let newTypes = [];
|
|
@@ -320,6 +321,10 @@ class Tree {
|
|
|
320
321
|
/// position. If 1, it'll move into nodes that start at the
|
|
321
322
|
/// position. With 0, it'll only enter nodes that cover the position
|
|
322
323
|
/// from both sides.
|
|
324
|
+
///
|
|
325
|
+
/// Note that this will not enter
|
|
326
|
+
/// [overlays](#common.MountedTree.overlay), and you often want
|
|
327
|
+
/// [`resolveInner`](#common.Tree.resolveInner) instead.
|
|
323
328
|
resolve(pos, side = 0) {
|
|
324
329
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
325
330
|
CachedNode.set(this, node);
|
|
@@ -404,7 +409,7 @@ class FlatBufferCursor {
|
|
|
404
409
|
/// Tree buffers contain (type, start, end, endIndex) quads for each
|
|
405
410
|
/// node. In such a buffer, nodes are stored in prefix order (parents
|
|
406
411
|
/// before children, with the endIndex of the parent indicating which
|
|
407
|
-
/// children belong to it)
|
|
412
|
+
/// children belong to it).
|
|
408
413
|
class TreeBuffer {
|
|
409
414
|
/// Create a tree buffer.
|
|
410
415
|
constructor(
|
|
@@ -1308,7 +1313,10 @@ class NodeWeakMap {
|
|
|
1308
1313
|
/// [`applyChanges`](#common.TreeFragment^applyChanges) method to
|
|
1309
1314
|
/// update fragments for document changes.
|
|
1310
1315
|
class TreeFragment {
|
|
1311
|
-
/// Construct a tree fragment.
|
|
1316
|
+
/// Construct a tree fragment. You'll usually want to use
|
|
1317
|
+
/// [`addTree`](#common.TreeFragment^addTree) and
|
|
1318
|
+
/// [`applyChanges`](#common.TreeFragment^applyChanges) instead of
|
|
1319
|
+
/// calling this directly.
|
|
1312
1320
|
constructor(
|
|
1313
1321
|
/// The start of the unchanged range pointed to by this fragment.
|
|
1314
1322
|
/// This refers to an offset in the _updated_ document (as opposed
|
|
@@ -1423,11 +1431,6 @@ class StringInput {
|
|
|
1423
1431
|
/// function, runs the resulting [inner parses](#common.NestedParse),
|
|
1424
1432
|
/// and then [mounts](#common.NodeProp^mounted) their results onto the
|
|
1425
1433
|
/// tree.
|
|
1426
|
-
///
|
|
1427
|
-
/// The nesting function is passed a cursor to provide context for a
|
|
1428
|
-
/// node, but _should not_ move that cursor, only inspect its
|
|
1429
|
-
/// properties and optionally access its
|
|
1430
|
-
/// [node object](#common.TreeCursor.node).
|
|
1431
1434
|
function parseMixed(nest) {
|
|
1432
1435
|
return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
|
|
1433
1436
|
}
|
|
@@ -1804,14 +1807,14 @@ function enterFragments(mounts, ranges) {
|
|
|
1804
1807
|
for (let i = 0, pos = from;; i++) {
|
|
1805
1808
|
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
1806
1809
|
if (end > pos)
|
|
1807
|
-
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos, frag.to <= end));
|
|
1810
|
+
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
1808
1811
|
if (last)
|
|
1809
1812
|
break;
|
|
1810
1813
|
pos = changes[i].to;
|
|
1811
1814
|
}
|
|
1812
1815
|
}
|
|
1813
1816
|
else {
|
|
1814
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos, frag.to <= endPos));
|
|
1817
|
+
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
1815
1818
|
}
|
|
1816
1819
|
}
|
|
1817
1820
|
return result;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// FIXME profile adding a per-Tree TreeNode cache, validating it by
|
|
2
2
|
// parent pointer
|
|
3
|
-
/// The default maximum length of a `TreeBuffer` node
|
|
3
|
+
/// The default maximum length of a `TreeBuffer` node.
|
|
4
4
|
const DefaultBufferLength = 1024;
|
|
5
5
|
let nextPropID = 0;
|
|
6
6
|
class Range {
|
|
@@ -63,7 +63,7 @@ NodeProp.contextHash = new NodeProp({ perNode: true });
|
|
|
63
63
|
NodeProp.lookAhead = new NodeProp({ perNode: true });
|
|
64
64
|
/// This per-node prop is used to replace a given node, or part of a
|
|
65
65
|
/// node, with another tree. This is useful to include trees from
|
|
66
|
-
/// different languages.
|
|
66
|
+
/// different languages in mixed-language parsers.
|
|
67
67
|
NodeProp.mounted = new NodeProp({ perNode: true });
|
|
68
68
|
/// A mounted tree, which can be [stored](#common.NodeProp^mounted) on
|
|
69
69
|
/// a tree node to indicate that parts of its content are
|
|
@@ -109,6 +109,7 @@ class NodeType {
|
|
|
109
109
|
this.id = id;
|
|
110
110
|
this.flags = flags;
|
|
111
111
|
}
|
|
112
|
+
/// Define a node type.
|
|
112
113
|
static define(spec) {
|
|
113
114
|
let props = spec.props && spec.props.length ? Object.create(null) : noProps;
|
|
114
115
|
let flags = (spec.top ? 1 /* Top */ : 0) | (spec.skipped ? 2 /* Skipped */ : 0) |
|
|
@@ -190,7 +191,7 @@ class NodeSet {
|
|
|
190
191
|
throw new RangeError("Node type ids should correspond to array positions when creating a node set");
|
|
191
192
|
}
|
|
192
193
|
/// Create a copy of this set with some node properties added. The
|
|
193
|
-
/// arguments to this method
|
|
194
|
+
/// arguments to this method can be created with
|
|
194
195
|
/// [`NodeProp.add`](#common.NodeProp.add).
|
|
195
196
|
extend(...props) {
|
|
196
197
|
let newTypes = [];
|
|
@@ -316,6 +317,10 @@ class Tree {
|
|
|
316
317
|
/// position. If 1, it'll move into nodes that start at the
|
|
317
318
|
/// position. With 0, it'll only enter nodes that cover the position
|
|
318
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.
|
|
319
324
|
resolve(pos, side = 0) {
|
|
320
325
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
321
326
|
CachedNode.set(this, node);
|
|
@@ -400,7 +405,7 @@ class FlatBufferCursor {
|
|
|
400
405
|
/// Tree buffers contain (type, start, end, endIndex) quads for each
|
|
401
406
|
/// node. In such a buffer, nodes are stored in prefix order (parents
|
|
402
407
|
/// before children, with the endIndex of the parent indicating which
|
|
403
|
-
/// children belong to it)
|
|
408
|
+
/// children belong to it).
|
|
404
409
|
class TreeBuffer {
|
|
405
410
|
/// Create a tree buffer.
|
|
406
411
|
constructor(
|
|
@@ -1304,7 +1309,10 @@ class NodeWeakMap {
|
|
|
1304
1309
|
/// [`applyChanges`](#common.TreeFragment^applyChanges) method to
|
|
1305
1310
|
/// update fragments for document changes.
|
|
1306
1311
|
class TreeFragment {
|
|
1307
|
-
/// Construct a tree fragment.
|
|
1312
|
+
/// Construct a tree fragment. You'll usually want to use
|
|
1313
|
+
/// [`addTree`](#common.TreeFragment^addTree) and
|
|
1314
|
+
/// [`applyChanges`](#common.TreeFragment^applyChanges) instead of
|
|
1315
|
+
/// calling this directly.
|
|
1308
1316
|
constructor(
|
|
1309
1317
|
/// The start of the unchanged range pointed to by this fragment.
|
|
1310
1318
|
/// This refers to an offset in the _updated_ document (as opposed
|
|
@@ -1419,11 +1427,6 @@ class StringInput {
|
|
|
1419
1427
|
/// function, runs the resulting [inner parses](#common.NestedParse),
|
|
1420
1428
|
/// and then [mounts](#common.NodeProp^mounted) their results onto the
|
|
1421
1429
|
/// tree.
|
|
1422
|
-
///
|
|
1423
|
-
/// The nesting function is passed a cursor to provide context for a
|
|
1424
|
-
/// node, but _should not_ move that cursor, only inspect its
|
|
1425
|
-
/// properties and optionally access its
|
|
1426
|
-
/// [node object](#common.TreeCursor.node).
|
|
1427
1430
|
function parseMixed(nest) {
|
|
1428
1431
|
return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
|
|
1429
1432
|
}
|
|
@@ -1800,14 +1803,14 @@ function enterFragments(mounts, ranges) {
|
|
|
1800
1803
|
for (let i = 0, pos = from;; i++) {
|
|
1801
1804
|
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
1802
1805
|
if (end > pos)
|
|
1803
|
-
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos, frag.to <= end));
|
|
1806
|
+
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
1804
1807
|
if (last)
|
|
1805
1808
|
break;
|
|
1806
1809
|
pos = changes[i].to;
|
|
1807
1810
|
}
|
|
1808
1811
|
}
|
|
1809
1812
|
else {
|
|
1810
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos, frag.to <= endPos));
|
|
1813
|
+
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
1811
1814
|
}
|
|
1812
1815
|
}
|
|
1813
1816
|
return result;
|
package/dist/tree.d.ts
CHANGED
|
@@ -127,6 +127,7 @@ export interface SyntaxNodeRef {
|
|
|
127
127
|
readonly name: string;
|
|
128
128
|
readonly tree: Tree | null;
|
|
129
129
|
readonly node: SyntaxNode;
|
|
130
|
+
matchContext(context: readonly string[]): boolean;
|
|
130
131
|
}
|
|
131
132
|
export interface SyntaxNode extends SyntaxNodeRef {
|
|
132
133
|
parent: SyntaxNode | null;
|
|
@@ -170,9 +171,9 @@ export declare class TreeNode implements SyntaxNode {
|
|
|
170
171
|
childBefore(pos: number): TreeNode | BufferNode;
|
|
171
172
|
enter(pos: number, side: -1 | 0 | 1, mode?: number): TreeNode | BufferNode;
|
|
172
173
|
nextSignificantParent(): TreeNode;
|
|
173
|
-
get parent(): TreeNode;
|
|
174
|
-
get nextSibling():
|
|
175
|
-
get prevSibling():
|
|
174
|
+
get parent(): TreeNode | null;
|
|
175
|
+
get nextSibling(): SyntaxNode | null;
|
|
176
|
+
get prevSibling(): SyntaxNode | null;
|
|
176
177
|
cursor(mode?: IterMode): TreeCursor;
|
|
177
178
|
get tree(): Tree;
|
|
178
179
|
toTree(): Tree;
|
|
@@ -206,7 +207,7 @@ declare class BufferNode implements SyntaxNode {
|
|
|
206
207
|
childAfter(pos: number): BufferNode;
|
|
207
208
|
childBefore(pos: number): BufferNode;
|
|
208
209
|
enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): BufferNode;
|
|
209
|
-
get parent():
|
|
210
|
+
get parent(): SyntaxNode | null;
|
|
210
211
|
externalSibling(dir: 1 | -1): TreeNode | BufferNode;
|
|
211
212
|
get nextSibling(): SyntaxNode | null;
|
|
212
213
|
get prevSibling(): SyntaxNode | null;
|