@pyreon/code 0.6.0 → 0.8.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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +326 -831
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/editor.ts +2 -2
- package/src/tabbed-editor.ts +6 -2
- package/lib/types/dist.d.ts +0 -798
- package/lib/types/dist.d.ts.map +0 -1
- package/lib/types/dist10.d.ts +0 -67
- package/lib/types/dist10.d.ts.map +0 -1
- package/lib/types/dist11.d.ts +0 -126
- package/lib/types/dist11.d.ts.map +0 -1
- package/lib/types/dist12.d.ts +0 -21
- package/lib/types/dist12.d.ts.map +0 -1
- package/lib/types/dist13.d.ts +0 -404
- package/lib/types/dist13.d.ts.map +0 -1
- package/lib/types/dist14.d.ts +0 -292
- package/lib/types/dist14.d.ts.map +0 -1
- package/lib/types/dist15.d.ts +0 -132
- package/lib/types/dist15.d.ts.map +0 -1
- package/lib/types/dist2.d.ts +0 -15
- package/lib/types/dist2.d.ts.map +0 -1
- package/lib/types/dist3.d.ts +0 -106
- package/lib/types/dist3.d.ts.map +0 -1
- package/lib/types/dist4.d.ts +0 -67
- package/lib/types/dist4.d.ts.map +0 -1
- package/lib/types/dist5.d.ts +0 -95
- package/lib/types/dist5.d.ts.map +0 -1
- package/lib/types/dist6.d.ts +0 -330
- package/lib/types/dist6.d.ts.map +0 -1
- package/lib/types/dist7.d.ts +0 -15
- package/lib/types/dist7.d.ts.map +0 -1
- package/lib/types/dist8.d.ts +0 -15
- package/lib/types/dist8.d.ts.map +0 -1
- package/lib/types/dist9.d.ts +0 -635
- package/lib/types/dist9.d.ts.map +0 -1
- package/lib/types/index2.d.ts +0 -347
- package/lib/types/index2.d.ts.map +0 -1
package/lib/types/dist.d.ts
DELETED
|
@@ -1,798 +0,0 @@
|
|
|
1
|
-
function checkSide(side, pos, from, to) {
|
|
2
|
-
switch (side) {
|
|
3
|
-
case -2:
|
|
4
|
-
return from < pos;
|
|
5
|
-
case -1:
|
|
6
|
-
return to >= pos && from < pos;
|
|
7
|
-
case 0:
|
|
8
|
-
return from < pos && to > pos;
|
|
9
|
-
case 1:
|
|
10
|
-
return from <= pos && to > pos;
|
|
11
|
-
case 2:
|
|
12
|
-
return to > pos;
|
|
13
|
-
case 4:
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function resolveNode(node, pos, side, overlays) {
|
|
18
|
-
var _a;
|
|
19
|
-
while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
|
|
20
|
-
let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
|
|
21
|
-
if (!parent) return node;
|
|
22
|
-
node = parent;
|
|
23
|
-
}
|
|
24
|
-
let mode = overlays ? 0 : IterMode.IgnoreOverlays;
|
|
25
|
-
if (overlays) {
|
|
26
|
-
for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from) node = parent;
|
|
27
|
-
}
|
|
28
|
-
for (;;) {
|
|
29
|
-
let inner = node.enter(pos, side, mode);
|
|
30
|
-
if (!inner) return node;
|
|
31
|
-
node = inner;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function getChildren(node, type, before, after) {
|
|
35
|
-
let cur = node.cursor(),
|
|
36
|
-
result = [];
|
|
37
|
-
if (!cur.firstChild()) return result;
|
|
38
|
-
if (before != null) for (let found = false; !found;) {
|
|
39
|
-
found = cur.type.is(before);
|
|
40
|
-
if (!cur.nextSibling()) return result;
|
|
41
|
-
}
|
|
42
|
-
for (;;) {
|
|
43
|
-
if (after != null && cur.type.is(after)) return result;
|
|
44
|
-
if (cur.type.is(type)) result.push(cur.node);
|
|
45
|
-
if (!cur.nextSibling()) return after == null ? result : [];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function matchNodeContext(node, context, i = context.length - 1) {
|
|
49
|
-
for (let p = node; i >= 0; p = p.parent) {
|
|
50
|
-
if (!p) return false;
|
|
51
|
-
if (!p.type.isAnonymous) {
|
|
52
|
-
if (context[i] && context[i] != p.name) return false;
|
|
53
|
-
i--;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
function iterStack(heads) {
|
|
59
|
-
if (!heads.length) return null;
|
|
60
|
-
let pick = 0,
|
|
61
|
-
picked = heads[0];
|
|
62
|
-
for (let i = 1; i < heads.length; i++) {
|
|
63
|
-
let node = heads[i];
|
|
64
|
-
if (node.from > picked.from || node.to < picked.to) {
|
|
65
|
-
picked = node;
|
|
66
|
-
pick = i;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
|
|
70
|
-
let newHeads = heads.slice();
|
|
71
|
-
if (next) newHeads[pick] = next;else newHeads.splice(pick, 1);
|
|
72
|
-
return new StackIterator(newHeads, picked);
|
|
73
|
-
}
|
|
74
|
-
function stackIterator(tree, pos, side) {
|
|
75
|
-
let inner = tree.resolveInner(pos, side),
|
|
76
|
-
layers = null;
|
|
77
|
-
for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) if (scan.index < 0) {
|
|
78
|
-
let parent = scan.parent;
|
|
79
|
-
(layers || (layers = [inner])).push(parent.resolve(pos, side));
|
|
80
|
-
scan = parent;
|
|
81
|
-
} else {
|
|
82
|
-
let mount = MountedTree.get(scan.tree);
|
|
83
|
-
if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
|
|
84
|
-
let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, -1, scan);
|
|
85
|
-
(layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return layers ? iterStack(layers) : inner;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
A tree cursor object focuses on a given node in a syntax tree, and
|
|
92
|
-
allows you to move to adjacent nodes.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
function hasChild(tree) {
|
|
96
|
-
return tree.children.some(ch => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
|
|
97
|
-
}
|
|
98
|
-
function buildTree(data) {
|
|
99
|
-
var _a;
|
|
100
|
-
let {
|
|
101
|
-
buffer,
|
|
102
|
-
nodeSet,
|
|
103
|
-
maxBufferLength = DefaultBufferLength,
|
|
104
|
-
reused = [],
|
|
105
|
-
minRepeatType = nodeSet.types.length
|
|
106
|
-
} = data;
|
|
107
|
-
let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
|
|
108
|
-
let types = nodeSet.types;
|
|
109
|
-
let contextHash = 0,
|
|
110
|
-
lookAhead = 0;
|
|
111
|
-
function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
|
|
112
|
-
let {
|
|
113
|
-
id,
|
|
114
|
-
start,
|
|
115
|
-
end,
|
|
116
|
-
size
|
|
117
|
-
} = cursor;
|
|
118
|
-
let lookAheadAtStart = lookAhead,
|
|
119
|
-
contextAtStart = contextHash;
|
|
120
|
-
if (size < 0) {
|
|
121
|
-
cursor.next();
|
|
122
|
-
if (size == -1) {
|
|
123
|
-
let node = reused[id];
|
|
124
|
-
children.push(node);
|
|
125
|
-
positions.push(start - parentStart);
|
|
126
|
-
return;
|
|
127
|
-
} else if (size == -3) {
|
|
128
|
-
contextHash = id;
|
|
129
|
-
return;
|
|
130
|
-
} else if (size == -4) {
|
|
131
|
-
lookAhead = id;
|
|
132
|
-
return;
|
|
133
|
-
} else throw new RangeError(`Unrecognized record size: ${size}`);
|
|
134
|
-
}
|
|
135
|
-
let type = types[id],
|
|
136
|
-
node,
|
|
137
|
-
buffer;
|
|
138
|
-
let startPos = start - parentStart;
|
|
139
|
-
if (end - start <= maxBufferLength && (buffer = findBufferSize(cursor.pos - minPos, inRepeat))) {
|
|
140
|
-
let data = new Uint16Array(buffer.size - buffer.skip);
|
|
141
|
-
let endPos = cursor.pos - buffer.size,
|
|
142
|
-
index = data.length;
|
|
143
|
-
while (cursor.pos > endPos) index = copyToBuffer(buffer.start, data, index);
|
|
144
|
-
node = new TreeBuffer(data, end - buffer.start, nodeSet);
|
|
145
|
-
startPos = buffer.start - parentStart;
|
|
146
|
-
} else {
|
|
147
|
-
let endPos = cursor.pos - size;
|
|
148
|
-
cursor.next();
|
|
149
|
-
let localChildren = [],
|
|
150
|
-
localPositions = [];
|
|
151
|
-
let localInRepeat = id >= minRepeatType ? id : -1;
|
|
152
|
-
let lastGroup = 0,
|
|
153
|
-
lastEnd = end;
|
|
154
|
-
while (cursor.pos > endPos) if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
|
|
155
|
-
if (cursor.end <= lastEnd - maxBufferLength) {
|
|
156
|
-
makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
157
|
-
lastGroup = localChildren.length;
|
|
158
|
-
lastEnd = cursor.end;
|
|
159
|
-
}
|
|
160
|
-
cursor.next();
|
|
161
|
-
} else if (depth > 2500) takeFlatNode(start, endPos, localChildren, localPositions);else takeNode(start, endPos, localChildren, localPositions, localInRepeat, depth + 1);
|
|
162
|
-
if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length) makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
|
|
163
|
-
localChildren.reverse();
|
|
164
|
-
localPositions.reverse();
|
|
165
|
-
if (localInRepeat > -1 && lastGroup > 0) {
|
|
166
|
-
let make = makeBalanced(type, contextAtStart);
|
|
167
|
-
node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
|
|
168
|
-
} else node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end, contextAtStart);
|
|
169
|
-
}
|
|
170
|
-
children.push(node);
|
|
171
|
-
positions.push(startPos);
|
|
172
|
-
}
|
|
173
|
-
function takeFlatNode(parentStart, minPos, children, positions) {
|
|
174
|
-
let nodes = [];
|
|
175
|
-
let nodeCount = 0,
|
|
176
|
-
stopAt = -1;
|
|
177
|
-
while (cursor.pos > minPos) {
|
|
178
|
-
let {
|
|
179
|
-
id,
|
|
180
|
-
start,
|
|
181
|
-
end,
|
|
182
|
-
size
|
|
183
|
-
} = cursor;
|
|
184
|
-
if (size > 4) cursor.next();else if (stopAt > -1 && start < stopAt) break;else {
|
|
185
|
-
if (stopAt < 0) stopAt = end - maxBufferLength;
|
|
186
|
-
nodes.push(id, start, end);
|
|
187
|
-
nodeCount++;
|
|
188
|
-
cursor.next();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (nodeCount) {
|
|
192
|
-
let buffer = new Uint16Array(nodeCount * 4);
|
|
193
|
-
let start = nodes[nodes.length - 2];
|
|
194
|
-
for (let i = nodes.length - 3, j = 0; i >= 0; i -= 3) {
|
|
195
|
-
buffer[j++] = nodes[i];
|
|
196
|
-
buffer[j++] = nodes[i + 1] - start;
|
|
197
|
-
buffer[j++] = nodes[i + 2] - start;
|
|
198
|
-
buffer[j++] = j;
|
|
199
|
-
}
|
|
200
|
-
children.push(new TreeBuffer(buffer, nodes[2] - start, nodeSet));
|
|
201
|
-
positions.push(start - parentStart);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function makeBalanced(type, contextHash) {
|
|
205
|
-
return (children, positions, length) => {
|
|
206
|
-
let lookAhead = 0,
|
|
207
|
-
lastI = children.length - 1,
|
|
208
|
-
last,
|
|
209
|
-
lookAheadProp;
|
|
210
|
-
if (lastI >= 0 && (last = children[lastI]) instanceof Tree) {
|
|
211
|
-
if (!lastI && last.type == type && last.length == length) return last;
|
|
212
|
-
if (lookAheadProp = last.prop(NodeProp.lookAhead)) lookAhead = positions[lastI] + last.length + lookAheadProp;
|
|
213
|
-
}
|
|
214
|
-
return makeTree(type, children, positions, length, lookAhead, contextHash);
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead, contextHash) {
|
|
218
|
-
let localChildren = [],
|
|
219
|
-
localPositions = [];
|
|
220
|
-
while (children.length > i) {
|
|
221
|
-
localChildren.push(children.pop());
|
|
222
|
-
localPositions.push(positions.pop() + base - from);
|
|
223
|
-
}
|
|
224
|
-
children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to, contextHash));
|
|
225
|
-
positions.push(from - base);
|
|
226
|
-
}
|
|
227
|
-
function makeTree(type, children, positions, length, lookAhead, contextHash, props) {
|
|
228
|
-
if (contextHash) {
|
|
229
|
-
let pair = [NodeProp.contextHash, contextHash];
|
|
230
|
-
props = props ? [pair].concat(props) : [pair];
|
|
231
|
-
}
|
|
232
|
-
if (lookAhead > 25) {
|
|
233
|
-
let pair = [NodeProp.lookAhead, lookAhead];
|
|
234
|
-
props = props ? [pair].concat(props) : [pair];
|
|
235
|
-
}
|
|
236
|
-
return new Tree(type, children, positions, length, props);
|
|
237
|
-
}
|
|
238
|
-
function findBufferSize(maxSize, inRepeat) {
|
|
239
|
-
let fork = cursor.fork();
|
|
240
|
-
let size = 0,
|
|
241
|
-
start = 0,
|
|
242
|
-
skip = 0,
|
|
243
|
-
minStart = fork.end - maxBufferLength;
|
|
244
|
-
let result = {
|
|
245
|
-
size: 0,
|
|
246
|
-
start: 0,
|
|
247
|
-
skip: 0
|
|
248
|
-
};
|
|
249
|
-
scan: for (let minPos = fork.pos - maxSize; fork.pos > minPos;) {
|
|
250
|
-
let nodeSize = fork.size;
|
|
251
|
-
if (fork.id == inRepeat && nodeSize >= 0) {
|
|
252
|
-
result.size = size;
|
|
253
|
-
result.start = start;
|
|
254
|
-
result.skip = skip;
|
|
255
|
-
skip += 4;
|
|
256
|
-
size += 4;
|
|
257
|
-
fork.next();
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
let startPos = fork.pos - nodeSize;
|
|
261
|
-
if (nodeSize < 0 || startPos < minPos || fork.start < minStart) break;
|
|
262
|
-
let localSkipped = fork.id >= minRepeatType ? 4 : 0;
|
|
263
|
-
let nodeStart = fork.start;
|
|
264
|
-
fork.next();
|
|
265
|
-
while (fork.pos > startPos) {
|
|
266
|
-
if (fork.size < 0) {
|
|
267
|
-
if (fork.size == -3 || fork.size == -4) localSkipped += 4;else break scan;
|
|
268
|
-
} else if (fork.id >= minRepeatType) localSkipped += 4;
|
|
269
|
-
fork.next();
|
|
270
|
-
}
|
|
271
|
-
start = nodeStart;
|
|
272
|
-
size += nodeSize;
|
|
273
|
-
skip += localSkipped;
|
|
274
|
-
}
|
|
275
|
-
if (inRepeat < 0 || size == maxSize) {
|
|
276
|
-
result.size = size;
|
|
277
|
-
result.start = start;
|
|
278
|
-
result.skip = skip;
|
|
279
|
-
}
|
|
280
|
-
return result.size > 4 ? result : void 0;
|
|
281
|
-
}
|
|
282
|
-
function copyToBuffer(bufferStart, buffer, index) {
|
|
283
|
-
let {
|
|
284
|
-
id,
|
|
285
|
-
start,
|
|
286
|
-
end,
|
|
287
|
-
size
|
|
288
|
-
} = cursor;
|
|
289
|
-
cursor.next();
|
|
290
|
-
if (size >= 0 && id < minRepeatType) {
|
|
291
|
-
let startIndex = index;
|
|
292
|
-
if (size > 4) {
|
|
293
|
-
let endPos = cursor.pos - (size - 4);
|
|
294
|
-
while (cursor.pos > endPos) index = copyToBuffer(bufferStart, buffer, index);
|
|
295
|
-
}
|
|
296
|
-
buffer[--index] = startIndex;
|
|
297
|
-
buffer[--index] = end - bufferStart;
|
|
298
|
-
buffer[--index] = start - bufferStart;
|
|
299
|
-
buffer[--index] = id;
|
|
300
|
-
} else if (size == -3) contextHash = id;else if (size == -4) lookAhead = id;
|
|
301
|
-
return index;
|
|
302
|
-
}
|
|
303
|
-
let children = [],
|
|
304
|
-
positions = [];
|
|
305
|
-
while (cursor.pos > 0) takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1, 0);
|
|
306
|
-
let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
|
|
307
|
-
return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
|
|
308
|
-
}
|
|
309
|
-
function nodeSize(balanceType, node) {
|
|
310
|
-
if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType) return 1;
|
|
311
|
-
let size = nodeSizeCache.get(node);
|
|
312
|
-
if (size == null) {
|
|
313
|
-
size = 1;
|
|
314
|
-
for (let child of node.children) {
|
|
315
|
-
if (child.type != balanceType || !(child instanceof Tree)) {
|
|
316
|
-
size = 1;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
size += nodeSize(balanceType, child);
|
|
320
|
-
}
|
|
321
|
-
nodeSizeCache.set(node, size);
|
|
322
|
-
}
|
|
323
|
-
return size;
|
|
324
|
-
}
|
|
325
|
-
function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
|
|
326
|
-
let total = 0;
|
|
327
|
-
for (let i = from; i < to; i++) total += nodeSize(balanceType, children[i]);
|
|
328
|
-
let maxChild = Math.ceil(total * 1.5 / 8);
|
|
329
|
-
let localChildren = [],
|
|
330
|
-
localPositions = [];
|
|
331
|
-
function divide(children, positions, from, to, offset) {
|
|
332
|
-
for (let i = from; i < to;) {
|
|
333
|
-
let groupFrom = i,
|
|
334
|
-
groupStart = positions[i],
|
|
335
|
-
groupSize = nodeSize(balanceType, children[i]);
|
|
336
|
-
i++;
|
|
337
|
-
for (; i < to; i++) {
|
|
338
|
-
let nextSize = nodeSize(balanceType, children[i]);
|
|
339
|
-
if (groupSize + nextSize >= maxChild) break;
|
|
340
|
-
groupSize += nextSize;
|
|
341
|
-
}
|
|
342
|
-
if (i == groupFrom + 1) {
|
|
343
|
-
if (groupSize > maxChild) {
|
|
344
|
-
let only = children[groupFrom];
|
|
345
|
-
divide(only.children, only.positions, 0, only.children.length, positions[groupFrom] + offset);
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
localChildren.push(children[groupFrom]);
|
|
349
|
-
} else {
|
|
350
|
-
let length = positions[i - 1] + children[i - 1].length - groupStart;
|
|
351
|
-
localChildren.push(balanceRange(balanceType, children, positions, groupFrom, i, groupStart, length, null, mkTree));
|
|
352
|
-
}
|
|
353
|
-
localPositions.push(groupStart + offset - start);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
divide(children, positions, from, to, 0);
|
|
357
|
-
return (mkTop || mkTree)(localChildren, localPositions, length);
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
Provides a way to associate values with pieces of trees. As long
|
|
361
|
-
as that part of the tree is reused, the associated values can be
|
|
362
|
-
retrieved from an updated tree.
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
Create a parse wrapper that, after the inner parse completes,
|
|
367
|
-
scans its tree for mixed language regions with the `nest`
|
|
368
|
-
function, runs the resulting [inner parses](#common.NestedParse),
|
|
369
|
-
and then [mounts](#common.NodeProp^mounted) their results onto the
|
|
370
|
-
tree.
|
|
371
|
-
*/
|
|
372
|
-
function parseMixed(nest) {
|
|
373
|
-
return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
|
|
374
|
-
}
|
|
375
|
-
function checkRanges(ranges) {
|
|
376
|
-
if (!ranges.length || ranges.some(r => r.from >= r.to)) throw new RangeError("Invalid inner parse ranges given: " + JSON.stringify(ranges));
|
|
377
|
-
}
|
|
378
|
-
function checkCover(covered, from, to) {
|
|
379
|
-
for (let range of covered) {
|
|
380
|
-
if (range.from >= to) break;
|
|
381
|
-
if (range.to > from) return range.from <= from && range.to >= to ? 2 : 1;
|
|
382
|
-
}
|
|
383
|
-
return 0;
|
|
384
|
-
}
|
|
385
|
-
function sliceBuf(buf, startI, endI, nodes, positions, off) {
|
|
386
|
-
if (startI < endI) {
|
|
387
|
-
let from = buf.buffer[startI + 1];
|
|
388
|
-
nodes.push(buf.slice(startI, endI, from));
|
|
389
|
-
positions.push(from - off);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function materialize(cursor) {
|
|
393
|
-
let {
|
|
394
|
-
node
|
|
395
|
-
} = cursor,
|
|
396
|
-
stack = [];
|
|
397
|
-
let buffer = node.context.buffer;
|
|
398
|
-
do {
|
|
399
|
-
stack.push(cursor.index);
|
|
400
|
-
cursor.parent();
|
|
401
|
-
} while (!cursor.tree);
|
|
402
|
-
let base = cursor.tree,
|
|
403
|
-
i = base.children.indexOf(buffer);
|
|
404
|
-
let buf = base.children[i],
|
|
405
|
-
b = buf.buffer,
|
|
406
|
-
newStack = [i];
|
|
407
|
-
function split(startI, endI, type, innerOffset, length, stackPos) {
|
|
408
|
-
let targetI = stack[stackPos];
|
|
409
|
-
let children = [],
|
|
410
|
-
positions = [];
|
|
411
|
-
sliceBuf(buf, startI, targetI, children, positions, innerOffset);
|
|
412
|
-
let from = b[targetI + 1],
|
|
413
|
-
to = b[targetI + 2];
|
|
414
|
-
newStack.push(children.length);
|
|
415
|
-
let child = stackPos ? split(targetI + 4, b[targetI + 3], buf.set.types[b[targetI]], from, to - from, stackPos - 1) : node.toTree();
|
|
416
|
-
children.push(child);
|
|
417
|
-
positions.push(from - innerOffset);
|
|
418
|
-
sliceBuf(buf, b[targetI + 3], endI, children, positions, innerOffset);
|
|
419
|
-
return new Tree(type, children, positions, length);
|
|
420
|
-
}
|
|
421
|
-
base.children[i] = split(0, b.length, NodeType.none, 0, buf.length, stack.length - 1);
|
|
422
|
-
for (let index of newStack) {
|
|
423
|
-
let tree = cursor.tree.children[index],
|
|
424
|
-
pos = cursor.tree.positions[index];
|
|
425
|
-
cursor.yield(new TreeNode(tree, pos + cursor.from, index, cursor._tree));
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
function punchRanges(outer, ranges) {
|
|
429
|
-
let copy = null,
|
|
430
|
-
current = ranges;
|
|
431
|
-
for (let i = 1, j = 0; i < outer.length; i++) {
|
|
432
|
-
let gapFrom = outer[i - 1].to,
|
|
433
|
-
gapTo = outer[i].from;
|
|
434
|
-
for (; j < current.length; j++) {
|
|
435
|
-
let r = current[j];
|
|
436
|
-
if (r.from >= gapTo) break;
|
|
437
|
-
if (r.to <= gapFrom) continue;
|
|
438
|
-
if (!copy) current = copy = ranges.slice();
|
|
439
|
-
if (r.from < gapFrom) {
|
|
440
|
-
copy[j] = new Range(r.from, gapFrom);
|
|
441
|
-
if (r.to > gapTo) copy.splice(j + 1, 0, new Range(gapTo, r.to));
|
|
442
|
-
} else if (r.to > gapTo) copy[j--] = new Range(gapTo, r.to);else copy.splice(j--, 1);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return current;
|
|
446
|
-
}
|
|
447
|
-
function findCoverChanges(a, b, from, to) {
|
|
448
|
-
let iA = 0,
|
|
449
|
-
iB = 0,
|
|
450
|
-
inA = false,
|
|
451
|
-
inB = false,
|
|
452
|
-
pos = -1e9;
|
|
453
|
-
let result = [];
|
|
454
|
-
for (;;) {
|
|
455
|
-
let nextA = iA == a.length ? 1e9 : inA ? a[iA].to : a[iA].from;
|
|
456
|
-
let nextB = iB == b.length ? 1e9 : inB ? b[iB].to : b[iB].from;
|
|
457
|
-
if (inA != inB) {
|
|
458
|
-
let start = Math.max(pos, from),
|
|
459
|
-
end = Math.min(nextA, nextB, to);
|
|
460
|
-
if (start < end) result.push(new Range(start, end));
|
|
461
|
-
}
|
|
462
|
-
pos = Math.min(nextA, nextB);
|
|
463
|
-
if (pos == 1e9) break;
|
|
464
|
-
if (nextA == pos) if (!inA) inA = true;else {
|
|
465
|
-
inA = false;
|
|
466
|
-
iA++;
|
|
467
|
-
}
|
|
468
|
-
if (nextB == pos) if (!inB) inB = true;else {
|
|
469
|
-
inB = false;
|
|
470
|
-
iB++;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return result;
|
|
474
|
-
}
|
|
475
|
-
function enterFragments(mounts, ranges) {
|
|
476
|
-
let result = [];
|
|
477
|
-
for (let {
|
|
478
|
-
pos,
|
|
479
|
-
mount,
|
|
480
|
-
frag
|
|
481
|
-
} of mounts) {
|
|
482
|
-
let startPos = pos + (mount.overlay ? mount.overlay[0].from : 0),
|
|
483
|
-
endPos = startPos + mount.tree.length;
|
|
484
|
-
let from = Math.max(frag.from, startPos),
|
|
485
|
-
to = Math.min(frag.to, endPos);
|
|
486
|
-
if (mount.overlay) {
|
|
487
|
-
let changes = findCoverChanges(ranges, mount.overlay.map(r => new Range(r.from + pos, r.to + pos)), from, to);
|
|
488
|
-
for (let i = 0, pos = from;; i++) {
|
|
489
|
-
let last = i == changes.length,
|
|
490
|
-
end = last ? to : changes[i].from;
|
|
491
|
-
if (end > pos) result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
492
|
-
if (last) break;
|
|
493
|
-
pos = changes[i].to;
|
|
494
|
-
}
|
|
495
|
-
} else result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
496
|
-
}
|
|
497
|
-
return result;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
//#endregion
|
|
501
|
-
//#region ../../node_modules/.bun/@lezer+lr@1.4.8/node_modules/@lezer/lr/dist/index.js
|
|
502
|
-
/**
|
|
503
|
-
A parse stack. These are used internally by the parser to track
|
|
504
|
-
parsing progress. They also provide some properties and methods
|
|
505
|
-
that external code such as a tokenizer can use to get information
|
|
506
|
-
about the parse state.
|
|
507
|
-
*/
|
|
508
|
-
|
|
509
|
-
function decodeArray(input, Type = Uint16Array) {
|
|
510
|
-
if (typeof input != "string") return input;
|
|
511
|
-
let array = null;
|
|
512
|
-
for (let pos = 0, out = 0; pos < input.length;) {
|
|
513
|
-
let value = 0;
|
|
514
|
-
for (;;) {
|
|
515
|
-
let next = input.charCodeAt(pos++),
|
|
516
|
-
stop = false;
|
|
517
|
-
if (next == 126) {
|
|
518
|
-
value = 65535;
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
if (next >= 92) next--;
|
|
522
|
-
if (next >= 34) next--;
|
|
523
|
-
let digit = next - 32;
|
|
524
|
-
if (digit >= 46) {
|
|
525
|
-
digit -= 46;
|
|
526
|
-
stop = true;
|
|
527
|
-
}
|
|
528
|
-
value += digit;
|
|
529
|
-
if (stop) break;
|
|
530
|
-
value *= 46;
|
|
531
|
-
}
|
|
532
|
-
if (array) array[out++] = value;else array = new Type(value);
|
|
533
|
-
}
|
|
534
|
-
return array;
|
|
535
|
-
}
|
|
536
|
-
function readToken(data, input, stack, group, precTable, precOffset) {
|
|
537
|
-
let state = 0,
|
|
538
|
-
groupMask = 1 << group,
|
|
539
|
-
{
|
|
540
|
-
dialect
|
|
541
|
-
} = stack.p.parser;
|
|
542
|
-
scan: for (;;) {
|
|
543
|
-
if ((groupMask & data[state]) == 0) break;
|
|
544
|
-
let accEnd = data[state + 1];
|
|
545
|
-
for (let i = state + 3; i < accEnd; i += 2) if ((data[i + 1] & groupMask) > 0) {
|
|
546
|
-
let term = data[i];
|
|
547
|
-
if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
|
|
548
|
-
input.acceptToken(term);
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
let next = input.next,
|
|
553
|
-
low = 0,
|
|
554
|
-
high = data[state + 2];
|
|
555
|
-
if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
|
|
556
|
-
state = data[accEnd + high * 3 - 1];
|
|
557
|
-
continue scan;
|
|
558
|
-
}
|
|
559
|
-
for (; low < high;) {
|
|
560
|
-
let mid = low + high >> 1;
|
|
561
|
-
let index = accEnd + mid + (mid << 1);
|
|
562
|
-
let from = data[index],
|
|
563
|
-
to = data[index + 1] || 65536;
|
|
564
|
-
if (next < from) high = mid;else if (next >= to) low = mid + 1;else {
|
|
565
|
-
state = data[index + 2];
|
|
566
|
-
input.advance();
|
|
567
|
-
continue scan;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
function findOffset(data, start, term) {
|
|
574
|
-
for (let i = start, next; (next = data[i]) != 65535; i++) if (next == term) return i - start;
|
|
575
|
-
return -1;
|
|
576
|
-
}
|
|
577
|
-
function overrides(token, prev, tableData, tableOffset) {
|
|
578
|
-
let iPrev = findOffset(tableData, tableOffset, prev);
|
|
579
|
-
return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
|
|
580
|
-
}
|
|
581
|
-
function cutAt(tree, pos, side) {
|
|
582
|
-
let cursor = tree.cursor(IterMode.IncludeAnonymous);
|
|
583
|
-
cursor.moveTo(pos);
|
|
584
|
-
for (;;) if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos))) for (;;) {
|
|
585
|
-
if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError) return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 25)) : Math.min(tree.length, Math.max(cursor.from + 1, pos + 25));
|
|
586
|
-
if (side < 0 ? cursor.prevSibling() : cursor.nextSibling()) break;
|
|
587
|
-
if (!cursor.parent()) return side < 0 ? 0 : tree.length;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
function pushStackDedup(stack, newStacks) {
|
|
591
|
-
for (let i = 0; i < newStacks.length; i++) {
|
|
592
|
-
let other = newStacks[i];
|
|
593
|
-
if (other.pos == stack.pos && other.sameState(stack)) {
|
|
594
|
-
if (newStacks[i].score < stack.score) newStacks[i] = stack;
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
newStacks.push(stack);
|
|
599
|
-
}
|
|
600
|
-
function pair(data, off) {
|
|
601
|
-
return data[off] | data[off + 1] << 16;
|
|
602
|
-
}
|
|
603
|
-
function findFinished(stacks) {
|
|
604
|
-
let best = null;
|
|
605
|
-
for (let stack of stacks) {
|
|
606
|
-
let stopped = stack.p.stoppedAt;
|
|
607
|
-
if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(stack.state, 2) && (!best || best.score < stack.score)) best = stack;
|
|
608
|
-
}
|
|
609
|
-
return best;
|
|
610
|
-
}
|
|
611
|
-
function getSpecializer(spec) {
|
|
612
|
-
if (spec.external) {
|
|
613
|
-
let mask = spec.extend ? 1 : 0;
|
|
614
|
-
return (value, stack) => spec.external(value, stack) << 1 | mask;
|
|
615
|
-
}
|
|
616
|
-
return spec.get;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
//#endregion
|
|
620
|
-
//#region ../../node_modules/.bun/@lezer+highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js
|
|
621
|
-
|
|
622
|
-
function sameArray(a, b) {
|
|
623
|
-
return a.length == b.length && a.every((x, i) => x == b[i]);
|
|
624
|
-
}
|
|
625
|
-
function powerSet(array) {
|
|
626
|
-
let sets = [[]];
|
|
627
|
-
for (let i = 0; i < array.length; i++) for (let j = 0, e = sets.length; j < e; j++) sets.push(sets[j].concat(array[i]));
|
|
628
|
-
return sets.sort((a, b) => b.length - a.length);
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
This function is used to add a set of tags to a language syntax
|
|
632
|
-
via [`NodeSet.extend`](#common.NodeSet.extend) or
|
|
633
|
-
[`LRParser.configure`](#lr.LRParser.configure).
|
|
634
|
-
|
|
635
|
-
The argument object maps node selectors to [highlighting
|
|
636
|
-
tags](#highlight.Tag) or arrays of tags.
|
|
637
|
-
|
|
638
|
-
Node selectors may hold one or more (space-separated) node paths.
|
|
639
|
-
Such a path can be a [node name](#common.NodeType.name), or
|
|
640
|
-
multiple node names (or `*` wildcards) separated by slash
|
|
641
|
-
characters, as in `"Block/Declaration/VariableName"`. Such a path
|
|
642
|
-
matches the final node but only if its direct parent nodes are the
|
|
643
|
-
other nodes mentioned. A `*` in such a path matches any parent,
|
|
644
|
-
but only a single level—wildcards that match multiple parents
|
|
645
|
-
aren't supported, both for efficiency reasons and because Lezer
|
|
646
|
-
trees make it rather hard to reason about what they would match.)
|
|
647
|
-
|
|
648
|
-
A path can be ended with `/...` to indicate that the tag assigned
|
|
649
|
-
to the node should also apply to all child nodes, even if they
|
|
650
|
-
match their own style (by default, only the innermost style is
|
|
651
|
-
used).
|
|
652
|
-
|
|
653
|
-
When a path ends in `!`, as in `Attribute!`, no further matching
|
|
654
|
-
happens for the node's child nodes, and the entire node gets the
|
|
655
|
-
given style.
|
|
656
|
-
|
|
657
|
-
In this notation, node names that contain `/`, `!`, `*`, or `...`
|
|
658
|
-
must be quoted as JSON strings.
|
|
659
|
-
|
|
660
|
-
For example:
|
|
661
|
-
|
|
662
|
-
```javascript
|
|
663
|
-
parser.configure({props: [
|
|
664
|
-
styleTags({
|
|
665
|
-
// Style Number and BigNumber nodes
|
|
666
|
-
"Number BigNumber": tags.number,
|
|
667
|
-
// Style Escape nodes whose parent is String
|
|
668
|
-
"String/Escape": tags.escape,
|
|
669
|
-
// Style anything inside Attributes nodes
|
|
670
|
-
"Attributes!": tags.meta,
|
|
671
|
-
// Add a style to all content inside Italic nodes
|
|
672
|
-
"Italic/...": tags.emphasis,
|
|
673
|
-
// Style InvalidString nodes as both `string` and `invalid`
|
|
674
|
-
"InvalidString": [tags.string, tags.invalid],
|
|
675
|
-
// Style the node named "/" as punctuation
|
|
676
|
-
'"/"': tags.punctuation
|
|
677
|
-
})
|
|
678
|
-
]})
|
|
679
|
-
```
|
|
680
|
-
*/
|
|
681
|
-
function styleTags(spec) {
|
|
682
|
-
let byName = Object.create(null);
|
|
683
|
-
for (let prop in spec) {
|
|
684
|
-
let tags = spec[prop];
|
|
685
|
-
if (!Array.isArray(tags)) tags = [tags];
|
|
686
|
-
for (let part of prop.split(" ")) if (part) {
|
|
687
|
-
let pieces = [],
|
|
688
|
-
mode = 2,
|
|
689
|
-
rest = part;
|
|
690
|
-
for (let pos = 0;;) {
|
|
691
|
-
if (rest == "..." && pos > 0 && pos + 3 == part.length) {
|
|
692
|
-
mode = 1;
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
|
|
696
|
-
if (!m) throw new RangeError("Invalid path: " + part);
|
|
697
|
-
pieces.push(m[0] == "*" ? "" : m[0][0] == "\"" ? JSON.parse(m[0]) : m[0]);
|
|
698
|
-
pos += m[0].length;
|
|
699
|
-
if (pos == part.length) break;
|
|
700
|
-
let next = part[pos++];
|
|
701
|
-
if (pos == part.length && next == "!") {
|
|
702
|
-
mode = 0;
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
if (next != "/") throw new RangeError("Invalid path: " + part);
|
|
706
|
-
rest = part.slice(pos);
|
|
707
|
-
}
|
|
708
|
-
let last = pieces.length - 1,
|
|
709
|
-
inner = pieces[last];
|
|
710
|
-
if (!inner) throw new RangeError("Invalid path: " + part);
|
|
711
|
-
byName[inner] = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null).sort(byName[inner]);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
return ruleNodeProp.add(byName);
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
Define a [highlighter](#highlight.Highlighter) from an array of
|
|
718
|
-
tag/class pairs. Classes associated with more specific tags will
|
|
719
|
-
take precedence.
|
|
720
|
-
*/
|
|
721
|
-
function tagHighlighter(tags, options) {
|
|
722
|
-
let map = Object.create(null);
|
|
723
|
-
for (let style of tags) if (!Array.isArray(style.tag)) map[style.tag.id] = style.class;else for (let tag of style.tag) map[tag.id] = style.class;
|
|
724
|
-
let {
|
|
725
|
-
scope,
|
|
726
|
-
all = null
|
|
727
|
-
} = options || {};
|
|
728
|
-
return {
|
|
729
|
-
style: tags => {
|
|
730
|
-
let cls = all;
|
|
731
|
-
for (let tag of tags) for (let sub of tag.set) {
|
|
732
|
-
let tagClass = map[sub.id];
|
|
733
|
-
if (tagClass) {
|
|
734
|
-
cls = cls ? cls + " " + tagClass : tagClass;
|
|
735
|
-
break;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return cls;
|
|
739
|
-
},
|
|
740
|
-
scope
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
for (let name in tags) {
|
|
744
|
-
let val = tags[name];
|
|
745
|
-
if (val instanceof Tag) val.name = name;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
This is a highlighter that adds stable, predictable classes to
|
|
749
|
-
tokens, for styling with external CSS.
|
|
750
|
-
|
|
751
|
-
The following tags are mapped to their name prefixed with `"tok-"`
|
|
752
|
-
(for example `"tok-comment"`):
|
|
753
|
-
|
|
754
|
-
* [`link`](#highlight.tags.link)
|
|
755
|
-
* [`heading`](#highlight.tags.heading)
|
|
756
|
-
* [`emphasis`](#highlight.tags.emphasis)
|
|
757
|
-
* [`strong`](#highlight.tags.strong)
|
|
758
|
-
* [`keyword`](#highlight.tags.keyword)
|
|
759
|
-
* [`atom`](#highlight.tags.atom)
|
|
760
|
-
* [`bool`](#highlight.tags.bool)
|
|
761
|
-
* [`url`](#highlight.tags.url)
|
|
762
|
-
* [`labelName`](#highlight.tags.labelName)
|
|
763
|
-
* [`inserted`](#highlight.tags.inserted)
|
|
764
|
-
* [`deleted`](#highlight.tags.deleted)
|
|
765
|
-
* [`literal`](#highlight.tags.literal)
|
|
766
|
-
* [`string`](#highlight.tags.string)
|
|
767
|
-
* [`number`](#highlight.tags.number)
|
|
768
|
-
* [`variableName`](#highlight.tags.variableName)
|
|
769
|
-
* [`typeName`](#highlight.tags.typeName)
|
|
770
|
-
* [`namespace`](#highlight.tags.namespace)
|
|
771
|
-
* [`className`](#highlight.tags.className)
|
|
772
|
-
* [`macroName`](#highlight.tags.macroName)
|
|
773
|
-
* [`propertyName`](#highlight.tags.propertyName)
|
|
774
|
-
* [`operator`](#highlight.tags.operator)
|
|
775
|
-
* [`comment`](#highlight.tags.comment)
|
|
776
|
-
* [`meta`](#highlight.tags.meta)
|
|
777
|
-
* [`punctuation`](#highlight.tags.punctuation)
|
|
778
|
-
* [`invalid`](#highlight.tags.invalid)
|
|
779
|
-
|
|
780
|
-
In addition, these mappings are provided:
|
|
781
|
-
|
|
782
|
-
* [`regexp`](#highlight.tags.regexp),
|
|
783
|
-
[`escape`](#highlight.tags.escape), and
|
|
784
|
-
[`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
|
|
785
|
-
are mapped to `"tok-string2"`
|
|
786
|
-
* [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
|
|
787
|
-
to `"tok-variableName2"`
|
|
788
|
-
* [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
|
|
789
|
-
to `"tok-variableName tok-local"`
|
|
790
|
-
* [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
|
|
791
|
-
to `"tok-variableName tok-definition"`
|
|
792
|
-
* [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
|
|
793
|
-
to `"tok-propertyName tok-definition"`
|
|
794
|
-
*/
|
|
795
|
-
|
|
796
|
-
//#endregion
|
|
797
|
-
export { ExternalTokenizer as a, IterMode as c, NodeType as d, NodeWeakMap as f, parseMixed as h, ContextTracker as i, NodeProp as l, Tree as m, styleTags as n, LRParser as o, Parser as p, tags as r, LocalTokenGroup as s, Tag as t, NodeSet as u };
|
|
798
|
-
//# sourceMappingURL=dist.d.ts.map
|