@lezer/common 1.2.3 → 1.3.0
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 +14 -3
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +14 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ class NodeProp {
|
|
|
26
26
|
this.deserialize = config.deserialize || (() => {
|
|
27
27
|
throw new Error("This node type doesn't define a deserialize function");
|
|
28
28
|
});
|
|
29
|
+
this.combine = config.combine || null;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
This is meant to be used with
|
|
@@ -290,7 +291,10 @@ class NodeSet {
|
|
|
290
291
|
if (add) {
|
|
291
292
|
if (!newProps)
|
|
292
293
|
newProps = Object.assign({}, type.props);
|
|
293
|
-
|
|
294
|
+
let value = add[1], prop = add[0];
|
|
295
|
+
if (prop.combine && prop.id in newProps)
|
|
296
|
+
value = prop.combine(newProps[prop.id], value);
|
|
297
|
+
newProps[prop.id] = value;
|
|
294
298
|
}
|
|
295
299
|
}
|
|
296
300
|
newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
|
|
@@ -1273,7 +1277,7 @@ function buildTree(data) {
|
|
|
1273
1277
|
function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
|
|
1274
1278
|
let { id, start, end, size } = cursor;
|
|
1275
1279
|
let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
|
|
1276
|
-
|
|
1280
|
+
if (size < 0) {
|
|
1277
1281
|
cursor.next();
|
|
1278
1282
|
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
1279
1283
|
let node = reused[id];
|
|
@@ -1878,8 +1882,15 @@ class MixedParse {
|
|
|
1878
1882
|
}
|
|
1879
1883
|
else if (!cursor.type.isAnonymous && (nest = this.nest(cursor, this.input)) &&
|
|
1880
1884
|
(cursor.from < cursor.to || !nest.overlay)) {
|
|
1881
|
-
if (!cursor.tree)
|
|
1885
|
+
if (!cursor.tree) {
|
|
1882
1886
|
materialize(cursor);
|
|
1887
|
+
// materialize create one more level of nesting
|
|
1888
|
+
// we need to add depth to active overlay for going backwards
|
|
1889
|
+
if (overlay)
|
|
1890
|
+
overlay.depth++;
|
|
1891
|
+
if (covered)
|
|
1892
|
+
covered.depth++;
|
|
1893
|
+
}
|
|
1883
1894
|
let oldMounts = fragmentCursor.findMounts(cursor.from, nest.parser);
|
|
1884
1895
|
if (typeof nest.overlay == "function") {
|
|
1885
1896
|
overlay = new ActiveOverlay(nest.parser, nest.overlay, oldMounts, this.inner.length, cursor.from, cursor.tree, overlay);
|
package/dist/index.d.cts
CHANGED
|
@@ -244,6 +244,13 @@ declare class NodeProp<T> {
|
|
|
244
244
|
*/
|
|
245
245
|
deserialize?: (str: string) => T;
|
|
246
246
|
/**
|
|
247
|
+
If configuring another value for this prop when it already
|
|
248
|
+
exists on a node should combine the old and new values, rather
|
|
249
|
+
than overwrite the old value, you can pass a function that
|
|
250
|
+
does the combining here.
|
|
251
|
+
*/
|
|
252
|
+
combine?: (a: T, b: T) => T;
|
|
253
|
+
/**
|
|
247
254
|
By default, node props are stored in the [node
|
|
248
255
|
type](#common.NodeType). It can sometimes be useful to directly
|
|
249
256
|
store information (usually related to the parsing algorithm)
|
|
@@ -1134,4 +1141,4 @@ tree.
|
|
|
1134
1141
|
*/
|
|
1135
1142
|
declare function parseMixed(nest: (node: SyntaxNodeRef, input: Input) => NestedParse | null): ParseWrapper;
|
|
1136
1143
|
|
|
1137
|
-
export { BufferCursor, ChangedRange, DefaultBufferLength, Input, IterMode, MountedTree, NestedParse, NodeIterator, NodeProp, NodePropSource, NodeSet, NodeType, NodeWeakMap, ParseWrapper, Parser, PartialParse, SyntaxNode, SyntaxNodeRef, Tree, TreeBuffer, TreeCursor, TreeFragment, parseMixed };
|
|
1144
|
+
export { type BufferCursor, type ChangedRange, DefaultBufferLength, type Input, IterMode, MountedTree, type NestedParse, type NodeIterator, NodeProp, type NodePropSource, NodeSet, NodeType, NodeWeakMap, type ParseWrapper, Parser, type PartialParse, type SyntaxNode, type SyntaxNodeRef, Tree, TreeBuffer, TreeCursor, TreeFragment, parseMixed };
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,13 @@ declare class NodeProp<T> {
|
|
|
244
244
|
*/
|
|
245
245
|
deserialize?: (str: string) => T;
|
|
246
246
|
/**
|
|
247
|
+
If configuring another value for this prop when it already
|
|
248
|
+
exists on a node should combine the old and new values, rather
|
|
249
|
+
than overwrite the old value, you can pass a function that
|
|
250
|
+
does the combining here.
|
|
251
|
+
*/
|
|
252
|
+
combine?: (a: T, b: T) => T;
|
|
253
|
+
/**
|
|
247
254
|
By default, node props are stored in the [node
|
|
248
255
|
type](#common.NodeType). It can sometimes be useful to directly
|
|
249
256
|
store information (usually related to the parsing algorithm)
|
|
@@ -1134,4 +1141,4 @@ tree.
|
|
|
1134
1141
|
*/
|
|
1135
1142
|
declare function parseMixed(nest: (node: SyntaxNodeRef, input: Input) => NestedParse | null): ParseWrapper;
|
|
1136
1143
|
|
|
1137
|
-
export { BufferCursor, ChangedRange, DefaultBufferLength, Input, IterMode, MountedTree, NestedParse, NodeIterator, NodeProp, NodePropSource, NodeSet, NodeType, NodeWeakMap, ParseWrapper, Parser, PartialParse, SyntaxNode, SyntaxNodeRef, Tree, TreeBuffer, TreeCursor, TreeFragment, parseMixed };
|
|
1144
|
+
export { type BufferCursor, type ChangedRange, DefaultBufferLength, type Input, IterMode, MountedTree, type NestedParse, type NodeIterator, NodeProp, type NodePropSource, NodeSet, NodeType, NodeWeakMap, type ParseWrapper, Parser, type PartialParse, type SyntaxNode, type SyntaxNodeRef, Tree, TreeBuffer, TreeCursor, TreeFragment, parseMixed };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ class NodeProp {
|
|
|
24
24
|
this.deserialize = config.deserialize || (() => {
|
|
25
25
|
throw new Error("This node type doesn't define a deserialize function");
|
|
26
26
|
});
|
|
27
|
+
this.combine = config.combine || null;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
This is meant to be used with
|
|
@@ -288,7 +289,10 @@ class NodeSet {
|
|
|
288
289
|
if (add) {
|
|
289
290
|
if (!newProps)
|
|
290
291
|
newProps = Object.assign({}, type.props);
|
|
291
|
-
|
|
292
|
+
let value = add[1], prop = add[0];
|
|
293
|
+
if (prop.combine && prop.id in newProps)
|
|
294
|
+
value = prop.combine(newProps[prop.id], value);
|
|
295
|
+
newProps[prop.id] = value;
|
|
292
296
|
}
|
|
293
297
|
}
|
|
294
298
|
newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
|
|
@@ -1271,7 +1275,7 @@ function buildTree(data) {
|
|
|
1271
1275
|
function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
|
|
1272
1276
|
let { id, start, end, size } = cursor;
|
|
1273
1277
|
let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
|
|
1274
|
-
|
|
1278
|
+
if (size < 0) {
|
|
1275
1279
|
cursor.next();
|
|
1276
1280
|
if (size == -1 /* SpecialRecord.Reuse */) {
|
|
1277
1281
|
let node = reused[id];
|
|
@@ -1876,8 +1880,15 @@ class MixedParse {
|
|
|
1876
1880
|
}
|
|
1877
1881
|
else if (!cursor.type.isAnonymous && (nest = this.nest(cursor, this.input)) &&
|
|
1878
1882
|
(cursor.from < cursor.to || !nest.overlay)) {
|
|
1879
|
-
if (!cursor.tree)
|
|
1883
|
+
if (!cursor.tree) {
|
|
1880
1884
|
materialize(cursor);
|
|
1885
|
+
// materialize create one more level of nesting
|
|
1886
|
+
// we need to add depth to active overlay for going backwards
|
|
1887
|
+
if (overlay)
|
|
1888
|
+
overlay.depth++;
|
|
1889
|
+
if (covered)
|
|
1890
|
+
covered.depth++;
|
|
1891
|
+
}
|
|
1881
1892
|
let oldMounts = fragmentCursor.findMounts(cursor.from, nest.parser);
|
|
1882
1893
|
if (typeof nest.overlay == "function") {
|
|
1883
1894
|
overlay = new ActiveOverlay(nest.parser, nest.overlay, oldMounts, this.inner.length, cursor.from, cursor.tree, overlay);
|