@pyreon/code 0.5.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.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/lib/analysis/index.js.html +5406 -0
  3. package/lib/dist-B5vB-rif.js +3904 -0
  4. package/lib/dist-B5vB-rif.js.map +1 -0
  5. package/lib/dist-BAfzu5eu.js +1428 -0
  6. package/lib/dist-BAfzu5eu.js.map +1 -0
  7. package/lib/dist-BLlV_D16.js +1166 -0
  8. package/lib/dist-BLlV_D16.js.map +1 -0
  9. package/lib/dist-BNmKLTu8.js +373 -0
  10. package/lib/dist-BNmKLTu8.js.map +1 -0
  11. package/lib/dist-BZtTlC1J.js +692 -0
  12. package/lib/dist-BZtTlC1J.js.map +1 -0
  13. package/lib/dist-CTDqGIAf.js +856 -0
  14. package/lib/dist-CTDqGIAf.js.map +1 -0
  15. package/lib/dist-CTPisNZp.js +83 -0
  16. package/lib/dist-CTPisNZp.js.map +1 -0
  17. package/lib/dist-Ce2tvOxv.js +379 -0
  18. package/lib/dist-Ce2tvOxv.js.map +1 -0
  19. package/lib/dist-CttF0OTv.js +465 -0
  20. package/lib/dist-CttF0OTv.js.map +1 -0
  21. package/lib/dist-DS2tluW9.js +818 -0
  22. package/lib/dist-DS2tluW9.js.map +1 -0
  23. package/lib/dist-DUNx9ldu.js +460 -0
  24. package/lib/dist-DUNx9ldu.js.map +1 -0
  25. package/lib/dist-Dej_yf3k.js +473 -0
  26. package/lib/dist-Dej_yf3k.js.map +1 -0
  27. package/lib/dist-DshStUxU.js +283 -0
  28. package/lib/dist-DshStUxU.js.map +1 -0
  29. package/lib/dist-qTrOe7xY.js +461 -0
  30. package/lib/dist-qTrOe7xY.js.map +1 -0
  31. package/lib/dist-v09vikKr.js +2421 -0
  32. package/lib/dist-v09vikKr.js.map +1 -0
  33. package/lib/index.js +915 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/types/dist.d.ts +798 -0
  36. package/lib/types/dist.d.ts.map +1 -0
  37. package/lib/types/dist10.d.ts +67 -0
  38. package/lib/types/dist10.d.ts.map +1 -0
  39. package/lib/types/dist11.d.ts +126 -0
  40. package/lib/types/dist11.d.ts.map +1 -0
  41. package/lib/types/dist12.d.ts +21 -0
  42. package/lib/types/dist12.d.ts.map +1 -0
  43. package/lib/types/dist13.d.ts +404 -0
  44. package/lib/types/dist13.d.ts.map +1 -0
  45. package/lib/types/dist14.d.ts +292 -0
  46. package/lib/types/dist14.d.ts.map +1 -0
  47. package/lib/types/dist15.d.ts +132 -0
  48. package/lib/types/dist15.d.ts.map +1 -0
  49. package/lib/types/dist2.d.ts +15 -0
  50. package/lib/types/dist2.d.ts.map +1 -0
  51. package/lib/types/dist3.d.ts +106 -0
  52. package/lib/types/dist3.d.ts.map +1 -0
  53. package/lib/types/dist4.d.ts +67 -0
  54. package/lib/types/dist4.d.ts.map +1 -0
  55. package/lib/types/dist5.d.ts +95 -0
  56. package/lib/types/dist5.d.ts.map +1 -0
  57. package/lib/types/dist6.d.ts +330 -0
  58. package/lib/types/dist6.d.ts.map +1 -0
  59. package/lib/types/dist7.d.ts +15 -0
  60. package/lib/types/dist7.d.ts.map +1 -0
  61. package/lib/types/dist8.d.ts +15 -0
  62. package/lib/types/dist8.d.ts.map +1 -0
  63. package/lib/types/dist9.d.ts +635 -0
  64. package/lib/types/dist9.d.ts.map +1 -0
  65. package/lib/types/index.d.ts +852 -0
  66. package/lib/types/index.d.ts.map +1 -0
  67. package/lib/types/index2.d.ts +347 -0
  68. package/lib/types/index2.d.ts.map +1 -0
  69. package/package.json +79 -0
  70. package/src/components/code-editor.tsx +42 -0
  71. package/src/components/diff-editor.tsx +97 -0
  72. package/src/components/tabbed-editor.tsx +86 -0
  73. package/src/editor.ts +652 -0
  74. package/src/index.ts +52 -0
  75. package/src/languages.ts +77 -0
  76. package/src/minimap.ts +160 -0
  77. package/src/tabbed-editor.ts +231 -0
  78. package/src/tests/code.test.ts +505 -0
  79. package/src/themes.ts +87 -0
  80. package/src/types.ts +253 -0
@@ -0,0 +1,3904 @@
1
+ //#region ../../node_modules/.bun/@lezer+common@1.5.1/node_modules/@lezer/common/dist/index.js
2
+ /**
3
+ The default maximum length of a `TreeBuffer` node.
4
+ */
5
+ const DefaultBufferLength = 1024;
6
+ let nextPropID = 0;
7
+ var Range = class {
8
+ constructor(from, to) {
9
+ this.from = from;
10
+ this.to = to;
11
+ }
12
+ };
13
+ /**
14
+ Each [node type](#common.NodeType) or [individual tree](#common.Tree)
15
+ can have metadata associated with it in props. Instances of this
16
+ class represent prop names.
17
+ */
18
+ var NodeProp = class {
19
+ /**
20
+ Create a new node prop type.
21
+ */
22
+ constructor(config = {}) {
23
+ this.id = nextPropID++;
24
+ this.perNode = !!config.perNode;
25
+ this.deserialize = config.deserialize || (() => {
26
+ throw new Error("This node type doesn't define a deserialize function");
27
+ });
28
+ this.combine = config.combine || null;
29
+ }
30
+ /**
31
+ This is meant to be used with
32
+ [`NodeSet.extend`](#common.NodeSet.extend) or
33
+ [`LRParser.configure`](#lr.ParserConfig.props) to compute
34
+ prop values for each node type in the set. Takes a [match
35
+ object](#common.NodeType^match) or function that returns undefined
36
+ if the node type doesn't get this prop, and the prop's value if
37
+ it does.
38
+ */
39
+ add(match) {
40
+ if (this.perNode) throw new RangeError("Can't add per-node props to node types");
41
+ if (typeof match != "function") match = NodeType.match(match);
42
+ return (type) => {
43
+ let result = match(type);
44
+ return result === void 0 ? null : [this, result];
45
+ };
46
+ }
47
+ };
48
+ /**
49
+ Prop that is used to describe matching delimiters. For opening
50
+ delimiters, this holds an array of node names (written as a
51
+ space-separated string when declaring this prop in a grammar)
52
+ for the node types of closing delimiters that match it.
53
+ */
54
+ NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
55
+ /**
56
+ The inverse of [`closedBy`](#common.NodeProp^closedBy). This is
57
+ attached to closing delimiters, holding an array of node names
58
+ of types of matching opening delimiters.
59
+ */
60
+ NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
61
+ /**
62
+ Used to assign node types to groups (for example, all node
63
+ types that represent an expression could be tagged with an
64
+ `"Expression"` group).
65
+ */
66
+ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
67
+ /**
68
+ Attached to nodes to indicate these should be
69
+ [displayed](https://codemirror.net/docs/ref/#language.syntaxTree)
70
+ in a bidirectional text isolate, so that direction-neutral
71
+ characters on their sides don't incorrectly get associated with
72
+ surrounding text. You'll generally want to set this for nodes
73
+ that contain arbitrary text, like strings and comments, and for
74
+ nodes that appear _inside_ arbitrary text, like HTML tags. When
75
+ not given a value, in a grammar declaration, defaults to
76
+ `"auto"`.
77
+ */
78
+ NodeProp.isolate = new NodeProp({ deserialize: (value) => {
79
+ if (value && value != "rtl" && value != "ltr" && value != "auto") throw new RangeError("Invalid value for isolate: " + value);
80
+ return value || "auto";
81
+ } });
82
+ /**
83
+ The hash of the [context](#lr.ContextTracker.constructor)
84
+ that the node was parsed in, if any. Used to limit reuse of
85
+ contextual nodes.
86
+ */
87
+ NodeProp.contextHash = new NodeProp({ perNode: true });
88
+ /**
89
+ The distance beyond the end of the node that the tokenizer
90
+ looked ahead for any of the tokens inside the node. (The LR
91
+ parser only stores this when it is larger than 25, for
92
+ efficiency reasons.)
93
+ */
94
+ NodeProp.lookAhead = new NodeProp({ perNode: true });
95
+ /**
96
+ This per-node prop is used to replace a given node, or part of a
97
+ node, with another tree. This is useful to include trees from
98
+ different languages in mixed-language parsers.
99
+ */
100
+ NodeProp.mounted = new NodeProp({ perNode: true });
101
+ /**
102
+ A mounted tree, which can be [stored](#common.NodeProp^mounted) on
103
+ a tree node to indicate that parts of its content are
104
+ represented by another tree.
105
+ */
106
+ var MountedTree = class {
107
+ constructor(tree, overlay, parser, bracketed = false) {
108
+ this.tree = tree;
109
+ this.overlay = overlay;
110
+ this.parser = parser;
111
+ this.bracketed = bracketed;
112
+ }
113
+ /**
114
+ @internal
115
+ */
116
+ static get(tree) {
117
+ return tree && tree.props && tree.props[NodeProp.mounted.id];
118
+ }
119
+ };
120
+ const noProps = Object.create(null);
121
+ /**
122
+ Each node in a syntax tree has a node type associated with it.
123
+ */
124
+ var NodeType = class NodeType {
125
+ /**
126
+ @internal
127
+ */
128
+ constructor(name, props, id, flags = 0) {
129
+ this.name = name;
130
+ this.props = props;
131
+ this.id = id;
132
+ this.flags = flags;
133
+ }
134
+ /**
135
+ Define a node type.
136
+ */
137
+ static define(spec) {
138
+ let props = spec.props && spec.props.length ? Object.create(null) : noProps;
139
+ let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
140
+ let type = new NodeType(spec.name || "", props, spec.id, flags);
141
+ if (spec.props) for (let src of spec.props) {
142
+ if (!Array.isArray(src)) src = src(type);
143
+ if (src) {
144
+ if (src[0].perNode) throw new RangeError("Can't store a per-node prop on a node type");
145
+ props[src[0].id] = src[1];
146
+ }
147
+ }
148
+ return type;
149
+ }
150
+ /**
151
+ Retrieves a node prop for this type. Will return `undefined` if
152
+ the prop isn't present on this node.
153
+ */
154
+ prop(prop) {
155
+ return this.props[prop.id];
156
+ }
157
+ /**
158
+ True when this is the top node of a grammar.
159
+ */
160
+ get isTop() {
161
+ return (this.flags & 1) > 0;
162
+ }
163
+ /**
164
+ True when this node is produced by a skip rule.
165
+ */
166
+ get isSkipped() {
167
+ return (this.flags & 2) > 0;
168
+ }
169
+ /**
170
+ Indicates whether this is an error node.
171
+ */
172
+ get isError() {
173
+ return (this.flags & 4) > 0;
174
+ }
175
+ /**
176
+ When true, this node type doesn't correspond to a user-declared
177
+ named node, for example because it is used to cache repetition.
178
+ */
179
+ get isAnonymous() {
180
+ return (this.flags & 8) > 0;
181
+ }
182
+ /**
183
+ Returns true when this node's name or one of its
184
+ [groups](#common.NodeProp^group) matches the given string.
185
+ */
186
+ is(name) {
187
+ if (typeof name == "string") {
188
+ if (this.name == name) return true;
189
+ let group = this.prop(NodeProp.group);
190
+ return group ? group.indexOf(name) > -1 : false;
191
+ }
192
+ return this.id == name;
193
+ }
194
+ /**
195
+ Create a function from node types to arbitrary values by
196
+ specifying an object whose property names are node or
197
+ [group](#common.NodeProp^group) names. Often useful with
198
+ [`NodeProp.add`](#common.NodeProp.add). You can put multiple
199
+ names, separated by spaces, in a single property name to map
200
+ multiple node names to a single value.
201
+ */
202
+ static match(map) {
203
+ let direct = Object.create(null);
204
+ for (let prop in map) for (let name of prop.split(" ")) direct[name] = map[prop];
205
+ return (node) => {
206
+ for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
207
+ let found = direct[i < 0 ? node.name : groups[i]];
208
+ if (found) return found;
209
+ }
210
+ };
211
+ }
212
+ };
213
+ /**
214
+ An empty dummy node type to use when no actual type is available.
215
+ */
216
+ NodeType.none = new NodeType("", Object.create(null), 0, 8);
217
+ /**
218
+ A node set holds a collection of node types. It is used to
219
+ compactly represent trees by storing their type ids, rather than a
220
+ full pointer to the type object, in a numeric array. Each parser
221
+ [has](#lr.LRParser.nodeSet) a node set, and [tree
222
+ buffers](#common.TreeBuffer) can only store collections of nodes
223
+ from the same set. A set can have a maximum of 2**16 (65536) node
224
+ types in it, so that the ids fit into 16-bit typed array slots.
225
+ */
226
+ var NodeSet = class NodeSet {
227
+ /**
228
+ Create a set with the given types. The `id` property of each
229
+ type should correspond to its position within the array.
230
+ */
231
+ constructor(types) {
232
+ this.types = types;
233
+ for (let i = 0; i < types.length; i++) if (types[i].id != i) throw new RangeError("Node type ids should correspond to array positions when creating a node set");
234
+ }
235
+ /**
236
+ Create a copy of this set with some node properties added. The
237
+ arguments to this method can be created with
238
+ [`NodeProp.add`](#common.NodeProp.add).
239
+ */
240
+ extend(...props) {
241
+ let newTypes = [];
242
+ for (let type of this.types) {
243
+ let newProps = null;
244
+ for (let source of props) {
245
+ let add = source(type);
246
+ if (add) {
247
+ if (!newProps) newProps = Object.assign({}, type.props);
248
+ let value = add[1], prop = add[0];
249
+ if (prop.combine && prop.id in newProps) value = prop.combine(newProps[prop.id], value);
250
+ newProps[prop.id] = value;
251
+ }
252
+ }
253
+ newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
254
+ }
255
+ return new NodeSet(newTypes);
256
+ }
257
+ };
258
+ const CachedNode = /* @__PURE__ */ new WeakMap(), CachedInnerNode = /* @__PURE__ */ new WeakMap();
259
+ /**
260
+ Options that control iteration. Can be combined with the `|`
261
+ operator to enable multiple ones.
262
+ */
263
+ var IterMode;
264
+ (function(IterMode) {
265
+ /**
266
+ When enabled, iteration will only visit [`Tree`](#common.Tree)
267
+ objects, not nodes packed into
268
+ [`TreeBuffer`](#common.TreeBuffer)s.
269
+ */
270
+ IterMode[IterMode["ExcludeBuffers"] = 1] = "ExcludeBuffers";
271
+ /**
272
+ Enable this to make iteration include anonymous nodes (such as
273
+ the nodes that wrap repeated grammar constructs into a balanced
274
+ tree).
275
+ */
276
+ IterMode[IterMode["IncludeAnonymous"] = 2] = "IncludeAnonymous";
277
+ /**
278
+ By default, regular [mounted](#common.NodeProp^mounted) nodes
279
+ replace their base node in iteration. Enable this to ignore them
280
+ instead.
281
+ */
282
+ IterMode[IterMode["IgnoreMounts"] = 4] = "IgnoreMounts";
283
+ /**
284
+ This option only applies in
285
+ [`enter`](#common.SyntaxNode.enter)-style methods. It tells the
286
+ library to not enter mounted overlays if one covers the given
287
+ position.
288
+ */
289
+ IterMode[IterMode["IgnoreOverlays"] = 8] = "IgnoreOverlays";
290
+ /**
291
+ When set, positions on the boundary of a mounted overlay tree
292
+ that has its [`bracketed`](#common.NestedParse.bracketed) flag
293
+ set will enter that tree regardless of side. Only supported in
294
+ [`enter`](#common.SyntaxNode.enter), not in cursors.
295
+ */
296
+ IterMode[IterMode["EnterBracketed"] = 16] = "EnterBracketed";
297
+ })(IterMode || (IterMode = {}));
298
+ /**
299
+ A piece of syntax tree. There are two ways to approach these
300
+ trees: the way they are actually stored in memory, and the
301
+ convenient way.
302
+
303
+ Syntax trees are stored as a tree of `Tree` and `TreeBuffer`
304
+ objects. By packing detail information into `TreeBuffer` leaf
305
+ nodes, the representation is made a lot more memory-efficient.
306
+
307
+ However, when you want to actually work with tree nodes, this
308
+ representation is very awkward, so most client code will want to
309
+ use the [`TreeCursor`](#common.TreeCursor) or
310
+ [`SyntaxNode`](#common.SyntaxNode) interface instead, which provides
311
+ a view on some part of this data structure, and can be used to
312
+ move around to adjacent nodes.
313
+ */
314
+ var Tree = class Tree {
315
+ /**
316
+ Construct a new tree. See also [`Tree.build`](#common.Tree^build).
317
+ */
318
+ constructor(type, children, positions, length, props) {
319
+ this.type = type;
320
+ this.children = children;
321
+ this.positions = positions;
322
+ this.length = length;
323
+ /**
324
+ @internal
325
+ */
326
+ this.props = null;
327
+ if (props && props.length) {
328
+ this.props = Object.create(null);
329
+ for (let [prop, value] of props) this.props[typeof prop == "number" ? prop : prop.id] = value;
330
+ }
331
+ }
332
+ /**
333
+ @internal
334
+ */
335
+ toString() {
336
+ let mounted = MountedTree.get(this);
337
+ if (mounted && !mounted.overlay) return mounted.tree.toString();
338
+ let children = "";
339
+ for (let ch of this.children) {
340
+ let str = ch.toString();
341
+ if (str) {
342
+ if (children) children += ",";
343
+ children += str;
344
+ }
345
+ }
346
+ return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
347
+ }
348
+ /**
349
+ Get a [tree cursor](#common.TreeCursor) positioned at the top of
350
+ the tree. Mode can be used to [control](#common.IterMode) which
351
+ nodes the cursor visits.
352
+ */
353
+ cursor(mode = 0) {
354
+ return new TreeCursor(this.topNode, mode);
355
+ }
356
+ /**
357
+ Get a [tree cursor](#common.TreeCursor) pointing into this tree
358
+ at the given position and side (see
359
+ [`moveTo`](#common.TreeCursor.moveTo).
360
+ */
361
+ cursorAt(pos, side = 0, mode = 0) {
362
+ let cursor = new TreeCursor(CachedNode.get(this) || this.topNode);
363
+ cursor.moveTo(pos, side);
364
+ CachedNode.set(this, cursor._tree);
365
+ return cursor;
366
+ }
367
+ /**
368
+ Get a [syntax node](#common.SyntaxNode) object for the top of the
369
+ tree.
370
+ */
371
+ get topNode() {
372
+ return new TreeNode(this, 0, 0, null);
373
+ }
374
+ /**
375
+ Get the [syntax node](#common.SyntaxNode) at the given position.
376
+ If `side` is -1, this will move into nodes that end at the
377
+ position. If 1, it'll move into nodes that start at the
378
+ position. With 0, it'll only enter nodes that cover the position
379
+ from both sides.
380
+
381
+ Note that this will not enter
382
+ [overlays](#common.MountedTree.overlay), and you often want
383
+ [`resolveInner`](#common.Tree.resolveInner) instead.
384
+ */
385
+ resolve(pos, side = 0) {
386
+ let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
387
+ CachedNode.set(this, node);
388
+ return node;
389
+ }
390
+ /**
391
+ Like [`resolve`](#common.Tree.resolve), but will enter
392
+ [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
393
+ pointing into the innermost overlaid tree at the given position
394
+ (with parent links going through all parent structure, including
395
+ the host trees).
396
+ */
397
+ resolveInner(pos, side = 0) {
398
+ let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
399
+ CachedInnerNode.set(this, node);
400
+ return node;
401
+ }
402
+ /**
403
+ In some situations, it can be useful to iterate through all
404
+ nodes around a position, including those in overlays that don't
405
+ directly cover the position. This method gives you an iterator
406
+ that will produce all nodes, from small to big, around the given
407
+ position.
408
+ */
409
+ resolveStack(pos, side = 0) {
410
+ return stackIterator(this, pos, side);
411
+ }
412
+ /**
413
+ Iterate over the tree and its children, calling `enter` for any
414
+ node that touches the `from`/`to` region (if given) before
415
+ running over such a node's children, and `leave` (if given) when
416
+ leaving the node. When `enter` returns `false`, that node will
417
+ not have its children iterated over (or `leave` called).
418
+ */
419
+ iterate(spec) {
420
+ let { enter, leave, from = 0, to = this.length } = spec;
421
+ let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
422
+ for (let c = this.cursor(mode | IterMode.IncludeAnonymous);;) {
423
+ let entered = false;
424
+ if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
425
+ if (c.firstChild()) continue;
426
+ entered = true;
427
+ }
428
+ for (;;) {
429
+ if (entered && leave && (anon || !c.type.isAnonymous)) leave(c);
430
+ if (c.nextSibling()) break;
431
+ if (!c.parent()) return;
432
+ entered = true;
433
+ }
434
+ }
435
+ }
436
+ /**
437
+ Get the value of the given [node prop](#common.NodeProp) for this
438
+ node. Works with both per-node and per-type props.
439
+ */
440
+ prop(prop) {
441
+ return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
442
+ }
443
+ /**
444
+ Returns the node's [per-node props](#common.NodeProp.perNode) in a
445
+ format that can be passed to the [`Tree`](#common.Tree)
446
+ constructor.
447
+ */
448
+ get propValues() {
449
+ let result = [];
450
+ if (this.props) for (let id in this.props) result.push([+id, this.props[id]]);
451
+ return result;
452
+ }
453
+ /**
454
+ Balance the direct children of this tree, producing a copy of
455
+ which may have children grouped into subtrees with type
456
+ [`NodeType.none`](#common.NodeType^none).
457
+ */
458
+ balance(config = {}) {
459
+ return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
460
+ }
461
+ /**
462
+ Build a tree from a postfix-ordered buffer of node information,
463
+ or a cursor over such a buffer.
464
+ */
465
+ static build(data) {
466
+ return buildTree(data);
467
+ }
468
+ };
469
+ /**
470
+ The empty tree
471
+ */
472
+ Tree.empty = new Tree(NodeType.none, [], [], 0);
473
+ var FlatBufferCursor = class FlatBufferCursor {
474
+ constructor(buffer, index) {
475
+ this.buffer = buffer;
476
+ this.index = index;
477
+ }
478
+ get id() {
479
+ return this.buffer[this.index - 4];
480
+ }
481
+ get start() {
482
+ return this.buffer[this.index - 3];
483
+ }
484
+ get end() {
485
+ return this.buffer[this.index - 2];
486
+ }
487
+ get size() {
488
+ return this.buffer[this.index - 1];
489
+ }
490
+ get pos() {
491
+ return this.index;
492
+ }
493
+ next() {
494
+ this.index -= 4;
495
+ }
496
+ fork() {
497
+ return new FlatBufferCursor(this.buffer, this.index);
498
+ }
499
+ };
500
+ /**
501
+ Tree buffers contain (type, start, end, endIndex) quads for each
502
+ node. In such a buffer, nodes are stored in prefix order (parents
503
+ before children, with the endIndex of the parent indicating which
504
+ children belong to it).
505
+ */
506
+ var TreeBuffer = class TreeBuffer {
507
+ /**
508
+ Create a tree buffer.
509
+ */
510
+ constructor(buffer, length, set) {
511
+ this.buffer = buffer;
512
+ this.length = length;
513
+ this.set = set;
514
+ }
515
+ /**
516
+ @internal
517
+ */
518
+ get type() {
519
+ return NodeType.none;
520
+ }
521
+ /**
522
+ @internal
523
+ */
524
+ toString() {
525
+ let result = [];
526
+ for (let index = 0; index < this.buffer.length;) {
527
+ result.push(this.childString(index));
528
+ index = this.buffer[index + 3];
529
+ }
530
+ return result.join(",");
531
+ }
532
+ /**
533
+ @internal
534
+ */
535
+ childString(index) {
536
+ let id = this.buffer[index], endIndex = this.buffer[index + 3];
537
+ let type = this.set.types[id], result = type.name;
538
+ if (/\W/.test(result) && !type.isError) result = JSON.stringify(result);
539
+ index += 4;
540
+ if (endIndex == index) return result;
541
+ let children = [];
542
+ while (index < endIndex) {
543
+ children.push(this.childString(index));
544
+ index = this.buffer[index + 3];
545
+ }
546
+ return result + "(" + children.join(",") + ")";
547
+ }
548
+ /**
549
+ @internal
550
+ */
551
+ findChild(startIndex, endIndex, dir, pos, side) {
552
+ let { buffer } = this, pick = -1;
553
+ for (let i = startIndex; i != endIndex; i = buffer[i + 3]) if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
554
+ pick = i;
555
+ if (dir > 0) break;
556
+ }
557
+ return pick;
558
+ }
559
+ /**
560
+ @internal
561
+ */
562
+ slice(startI, endI, from) {
563
+ let b = this.buffer;
564
+ let copy = new Uint16Array(endI - startI), len = 0;
565
+ for (let i = startI, j = 0; i < endI;) {
566
+ copy[j++] = b[i++];
567
+ copy[j++] = b[i++] - from;
568
+ let to = copy[j++] = b[i++] - from;
569
+ copy[j++] = b[i++] - startI;
570
+ len = Math.max(len, to);
571
+ }
572
+ return new TreeBuffer(copy, len, this.set);
573
+ }
574
+ };
575
+ function checkSide(side, pos, from, to) {
576
+ switch (side) {
577
+ case -2: return from < pos;
578
+ case -1: return to >= pos && from < pos;
579
+ case 0: return from < pos && to > pos;
580
+ case 1: return from <= pos && to > pos;
581
+ case 2: return to > pos;
582
+ case 4: return true;
583
+ }
584
+ }
585
+ function resolveNode(node, pos, side, overlays) {
586
+ var _a;
587
+ while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
588
+ let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
589
+ if (!parent) return node;
590
+ node = parent;
591
+ }
592
+ let mode = overlays ? 0 : IterMode.IgnoreOverlays;
593
+ if (overlays) {
594
+ 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;
595
+ }
596
+ for (;;) {
597
+ let inner = node.enter(pos, side, mode);
598
+ if (!inner) return node;
599
+ node = inner;
600
+ }
601
+ }
602
+ var BaseNode = class {
603
+ cursor(mode = 0) {
604
+ return new TreeCursor(this, mode);
605
+ }
606
+ getChild(type, before = null, after = null) {
607
+ let r = getChildren(this, type, before, after);
608
+ return r.length ? r[0] : null;
609
+ }
610
+ getChildren(type, before = null, after = null) {
611
+ return getChildren(this, type, before, after);
612
+ }
613
+ resolve(pos, side = 0) {
614
+ return resolveNode(this, pos, side, false);
615
+ }
616
+ resolveInner(pos, side = 0) {
617
+ return resolveNode(this, pos, side, true);
618
+ }
619
+ matchContext(context) {
620
+ return matchNodeContext(this.parent, context);
621
+ }
622
+ enterUnfinishedNodesBefore(pos) {
623
+ let scan = this.childBefore(pos), node = this;
624
+ while (scan) {
625
+ let last = scan.lastChild;
626
+ if (!last || last.to != scan.to) break;
627
+ if (last.type.isError && last.from == last.to) {
628
+ node = scan;
629
+ scan = last.prevSibling;
630
+ } else scan = last;
631
+ }
632
+ return node;
633
+ }
634
+ get node() {
635
+ return this;
636
+ }
637
+ get next() {
638
+ return this.parent;
639
+ }
640
+ };
641
+ var TreeNode = class TreeNode extends BaseNode {
642
+ constructor(_tree, from, index, _parent) {
643
+ super();
644
+ this._tree = _tree;
645
+ this.from = from;
646
+ this.index = index;
647
+ this._parent = _parent;
648
+ }
649
+ get type() {
650
+ return this._tree.type;
651
+ }
652
+ get name() {
653
+ return this._tree.type.name;
654
+ }
655
+ get to() {
656
+ return this.from + this._tree.length;
657
+ }
658
+ nextChild(i, dir, pos, side, mode = 0) {
659
+ for (let parent = this;;) {
660
+ for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
661
+ let next = children[i], start = positions[i] + parent.from, mounted;
662
+ if (!(mode & IterMode.EnterBracketed && next instanceof Tree && (mounted = MountedTree.get(next)) && !mounted.overlay && mounted.bracketed && pos >= start && pos <= start + next.length) && !checkSide(side, pos, start, start + next.length)) continue;
663
+ if (next instanceof TreeBuffer) {
664
+ if (mode & IterMode.ExcludeBuffers) continue;
665
+ let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
666
+ if (index > -1) return new BufferNode(new BufferContext(parent, next, i, start), null, index);
667
+ } else if (mode & IterMode.IncludeAnonymous || !next.type.isAnonymous || hasChild(next)) {
668
+ let mounted;
669
+ if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay) return new TreeNode(mounted.tree, start, i, parent);
670
+ let inner = new TreeNode(next, start, i, parent);
671
+ return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side, mode);
672
+ }
673
+ }
674
+ if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous) return null;
675
+ if (parent.index >= 0) i = parent.index + dir;
676
+ else i = dir < 0 ? -1 : parent._parent._tree.children.length;
677
+ parent = parent._parent;
678
+ if (!parent) return null;
679
+ }
680
+ }
681
+ get firstChild() {
682
+ return this.nextChild(0, 1, 0, 4);
683
+ }
684
+ get lastChild() {
685
+ return this.nextChild(this._tree.children.length - 1, -1, 0, 4);
686
+ }
687
+ childAfter(pos) {
688
+ return this.nextChild(0, 1, pos, 2);
689
+ }
690
+ childBefore(pos) {
691
+ return this.nextChild(this._tree.children.length - 1, -1, pos, -2);
692
+ }
693
+ prop(prop) {
694
+ return this._tree.prop(prop);
695
+ }
696
+ enter(pos, side, mode = 0) {
697
+ let mounted;
698
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) {
699
+ let rPos = pos - this.from, enterBracketed = mode & IterMode.EnterBracketed && mounted.bracketed;
700
+ for (let { from, to } of mounted.overlay) if ((side > 0 || enterBracketed ? from <= rPos : from < rPos) && (side < 0 || enterBracketed ? to >= rPos : to > rPos)) return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
701
+ }
702
+ return this.nextChild(0, 1, pos, side, mode);
703
+ }
704
+ nextSignificantParent() {
705
+ let val = this;
706
+ while (val.type.isAnonymous && val._parent) val = val._parent;
707
+ return val;
708
+ }
709
+ get parent() {
710
+ return this._parent ? this._parent.nextSignificantParent() : null;
711
+ }
712
+ get nextSibling() {
713
+ return this._parent && this.index >= 0 ? this._parent.nextChild(this.index + 1, 1, 0, 4) : null;
714
+ }
715
+ get prevSibling() {
716
+ return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4) : null;
717
+ }
718
+ get tree() {
719
+ return this._tree;
720
+ }
721
+ toTree() {
722
+ return this._tree;
723
+ }
724
+ /**
725
+ @internal
726
+ */
727
+ toString() {
728
+ return this._tree.toString();
729
+ }
730
+ };
731
+ function getChildren(node, type, before, after) {
732
+ let cur = node.cursor(), result = [];
733
+ if (!cur.firstChild()) return result;
734
+ if (before != null) for (let found = false; !found;) {
735
+ found = cur.type.is(before);
736
+ if (!cur.nextSibling()) return result;
737
+ }
738
+ for (;;) {
739
+ if (after != null && cur.type.is(after)) return result;
740
+ if (cur.type.is(type)) result.push(cur.node);
741
+ if (!cur.nextSibling()) return after == null ? result : [];
742
+ }
743
+ }
744
+ function matchNodeContext(node, context, i = context.length - 1) {
745
+ for (let p = node; i >= 0; p = p.parent) {
746
+ if (!p) return false;
747
+ if (!p.type.isAnonymous) {
748
+ if (context[i] && context[i] != p.name) return false;
749
+ i--;
750
+ }
751
+ }
752
+ return true;
753
+ }
754
+ var BufferContext = class {
755
+ constructor(parent, buffer, index, start) {
756
+ this.parent = parent;
757
+ this.buffer = buffer;
758
+ this.index = index;
759
+ this.start = start;
760
+ }
761
+ };
762
+ var BufferNode = class BufferNode extends BaseNode {
763
+ get name() {
764
+ return this.type.name;
765
+ }
766
+ get from() {
767
+ return this.context.start + this.context.buffer.buffer[this.index + 1];
768
+ }
769
+ get to() {
770
+ return this.context.start + this.context.buffer.buffer[this.index + 2];
771
+ }
772
+ constructor(context, _parent, index) {
773
+ super();
774
+ this.context = context;
775
+ this._parent = _parent;
776
+ this.index = index;
777
+ this.type = context.buffer.set.types[context.buffer.buffer[index]];
778
+ }
779
+ child(dir, pos, side) {
780
+ let { buffer } = this.context;
781
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
782
+ return index < 0 ? null : new BufferNode(this.context, this, index);
783
+ }
784
+ get firstChild() {
785
+ return this.child(1, 0, 4);
786
+ }
787
+ get lastChild() {
788
+ return this.child(-1, 0, 4);
789
+ }
790
+ childAfter(pos) {
791
+ return this.child(1, pos, 2);
792
+ }
793
+ childBefore(pos) {
794
+ return this.child(-1, pos, -2);
795
+ }
796
+ prop(prop) {
797
+ return this.type.prop(prop);
798
+ }
799
+ enter(pos, side, mode = 0) {
800
+ if (mode & IterMode.ExcludeBuffers) return null;
801
+ let { buffer } = this.context;
802
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
803
+ return index < 0 ? null : new BufferNode(this.context, this, index);
804
+ }
805
+ get parent() {
806
+ return this._parent || this.context.parent.nextSignificantParent();
807
+ }
808
+ externalSibling(dir) {
809
+ return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, 0, 4);
810
+ }
811
+ get nextSibling() {
812
+ let { buffer } = this.context;
813
+ let after = buffer.buffer[this.index + 3];
814
+ if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length)) return new BufferNode(this.context, this._parent, after);
815
+ return this.externalSibling(1);
816
+ }
817
+ get prevSibling() {
818
+ let { buffer } = this.context;
819
+ let parentStart = this._parent ? this._parent.index + 4 : 0;
820
+ if (this.index == parentStart) return this.externalSibling(-1);
821
+ return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4));
822
+ }
823
+ get tree() {
824
+ return null;
825
+ }
826
+ toTree() {
827
+ let children = [], positions = [];
828
+ let { buffer } = this.context;
829
+ let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
830
+ if (endI > startI) {
831
+ let from = buffer.buffer[this.index + 1];
832
+ children.push(buffer.slice(startI, endI, from));
833
+ positions.push(0);
834
+ }
835
+ return new Tree(this.type, children, positions, this.to - this.from);
836
+ }
837
+ /**
838
+ @internal
839
+ */
840
+ toString() {
841
+ return this.context.buffer.childString(this.index);
842
+ }
843
+ };
844
+ function iterStack(heads) {
845
+ if (!heads.length) return null;
846
+ let pick = 0, picked = heads[0];
847
+ for (let i = 1; i < heads.length; i++) {
848
+ let node = heads[i];
849
+ if (node.from > picked.from || node.to < picked.to) {
850
+ picked = node;
851
+ pick = i;
852
+ }
853
+ }
854
+ let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
855
+ let newHeads = heads.slice();
856
+ if (next) newHeads[pick] = next;
857
+ else newHeads.splice(pick, 1);
858
+ return new StackIterator(newHeads, picked);
859
+ }
860
+ var StackIterator = class {
861
+ constructor(heads, node) {
862
+ this.heads = heads;
863
+ this.node = node;
864
+ }
865
+ get next() {
866
+ return iterStack(this.heads);
867
+ }
868
+ };
869
+ function stackIterator(tree, pos, side) {
870
+ let inner = tree.resolveInner(pos, side), layers = null;
871
+ for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) if (scan.index < 0) {
872
+ let parent = scan.parent;
873
+ (layers || (layers = [inner])).push(parent.resolve(pos, side));
874
+ scan = parent;
875
+ } else {
876
+ let mount = MountedTree.get(scan.tree);
877
+ if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
878
+ let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, -1, scan);
879
+ (layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
880
+ }
881
+ }
882
+ return layers ? iterStack(layers) : inner;
883
+ }
884
+ /**
885
+ A tree cursor object focuses on a given node in a syntax tree, and
886
+ allows you to move to adjacent nodes.
887
+ */
888
+ var TreeCursor = class {
889
+ /**
890
+ Shorthand for `.type.name`.
891
+ */
892
+ get name() {
893
+ return this.type.name;
894
+ }
895
+ /**
896
+ @internal
897
+ */
898
+ constructor(node, mode = 0) {
899
+ /**
900
+ @internal
901
+ */
902
+ this.buffer = null;
903
+ this.stack = [];
904
+ /**
905
+ @internal
906
+ */
907
+ this.index = 0;
908
+ this.bufferNode = null;
909
+ this.mode = mode & ~IterMode.EnterBracketed;
910
+ if (node instanceof TreeNode) this.yieldNode(node);
911
+ else {
912
+ this._tree = node.context.parent;
913
+ this.buffer = node.context;
914
+ for (let n = node._parent; n; n = n._parent) this.stack.unshift(n.index);
915
+ this.bufferNode = node;
916
+ this.yieldBuf(node.index);
917
+ }
918
+ }
919
+ yieldNode(node) {
920
+ if (!node) return false;
921
+ this._tree = node;
922
+ this.type = node.type;
923
+ this.from = node.from;
924
+ this.to = node.to;
925
+ return true;
926
+ }
927
+ yieldBuf(index, type) {
928
+ this.index = index;
929
+ let { start, buffer } = this.buffer;
930
+ this.type = type || buffer.set.types[buffer.buffer[index]];
931
+ this.from = start + buffer.buffer[index + 1];
932
+ this.to = start + buffer.buffer[index + 2];
933
+ return true;
934
+ }
935
+ /**
936
+ @internal
937
+ */
938
+ yield(node) {
939
+ if (!node) return false;
940
+ if (node instanceof TreeNode) {
941
+ this.buffer = null;
942
+ return this.yieldNode(node);
943
+ }
944
+ this.buffer = node.context;
945
+ return this.yieldBuf(node.index, node.type);
946
+ }
947
+ /**
948
+ @internal
949
+ */
950
+ toString() {
951
+ return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
952
+ }
953
+ /**
954
+ @internal
955
+ */
956
+ enterChild(dir, pos, side) {
957
+ if (!this.buffer) return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
958
+ let { buffer } = this.buffer;
959
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
960
+ if (index < 0) return false;
961
+ this.stack.push(this.index);
962
+ return this.yieldBuf(index);
963
+ }
964
+ /**
965
+ Move the cursor to this node's first child. When this returns
966
+ false, the node has no child, and the cursor has not been moved.
967
+ */
968
+ firstChild() {
969
+ return this.enterChild(1, 0, 4);
970
+ }
971
+ /**
972
+ Move the cursor to this node's last child.
973
+ */
974
+ lastChild() {
975
+ return this.enterChild(-1, 0, 4);
976
+ }
977
+ /**
978
+ Move the cursor to the first child that ends after `pos`.
979
+ */
980
+ childAfter(pos) {
981
+ return this.enterChild(1, pos, 2);
982
+ }
983
+ /**
984
+ Move to the last child that starts before `pos`.
985
+ */
986
+ childBefore(pos) {
987
+ return this.enterChild(-1, pos, -2);
988
+ }
989
+ /**
990
+ Move the cursor to the child around `pos`. If side is -1 the
991
+ child may end at that position, when 1 it may start there. This
992
+ will also enter [overlaid](#common.MountedTree.overlay)
993
+ [mounted](#common.NodeProp^mounted) trees unless `overlays` is
994
+ set to false.
995
+ */
996
+ enter(pos, side, mode = this.mode) {
997
+ if (!this.buffer) return this.yield(this._tree.enter(pos, side, mode));
998
+ return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
999
+ }
1000
+ /**
1001
+ Move to the node's parent node, if this isn't the top node.
1002
+ */
1003
+ parent() {
1004
+ if (!this.buffer) return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
1005
+ if (this.stack.length) return this.yieldBuf(this.stack.pop());
1006
+ let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
1007
+ this.buffer = null;
1008
+ return this.yieldNode(parent);
1009
+ }
1010
+ /**
1011
+ @internal
1012
+ */
1013
+ sibling(dir) {
1014
+ if (!this.buffer) return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
1015
+ let { buffer } = this.buffer, d = this.stack.length - 1;
1016
+ if (dir < 0) {
1017
+ let parentStart = d < 0 ? 0 : this.stack[d] + 4;
1018
+ if (this.index != parentStart) return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, 0, 4));
1019
+ } else {
1020
+ let after = buffer.buffer[this.index + 3];
1021
+ if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3])) return this.yieldBuf(after);
1022
+ }
1023
+ return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
1024
+ }
1025
+ /**
1026
+ Move to this node's next sibling, if any.
1027
+ */
1028
+ nextSibling() {
1029
+ return this.sibling(1);
1030
+ }
1031
+ /**
1032
+ Move to this node's previous sibling, if any.
1033
+ */
1034
+ prevSibling() {
1035
+ return this.sibling(-1);
1036
+ }
1037
+ atLastNode(dir) {
1038
+ let index, parent, { buffer } = this;
1039
+ if (buffer) {
1040
+ if (dir > 0) {
1041
+ if (this.index < buffer.buffer.buffer.length) return false;
1042
+ } else for (let i = 0; i < this.index; i++) if (buffer.buffer.buffer[i + 3] < this.index) return false;
1043
+ ({index, parent} = buffer);
1044
+ } else ({index, _parent: parent} = this._tree);
1045
+ for (; parent; {index, _parent: parent} = parent) if (index > -1) for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
1046
+ let child = parent._tree.children[i];
1047
+ if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child)) return false;
1048
+ }
1049
+ return true;
1050
+ }
1051
+ move(dir, enter) {
1052
+ if (enter && this.enterChild(dir, 0, 4)) return true;
1053
+ for (;;) {
1054
+ if (this.sibling(dir)) return true;
1055
+ if (this.atLastNode(dir) || !this.parent()) return false;
1056
+ }
1057
+ }
1058
+ /**
1059
+ Move to the next node in a
1060
+ [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1061
+ traversal, going from a node to its first child or, if the
1062
+ current node is empty or `enter` is false, its next sibling or
1063
+ the next sibling of the first parent node that has one.
1064
+ */
1065
+ next(enter = true) {
1066
+ return this.move(1, enter);
1067
+ }
1068
+ /**
1069
+ Move to the next node in a last-to-first pre-order traversal. A
1070
+ node is followed by its last child or, if it has none, its
1071
+ previous sibling or the previous sibling of the first parent
1072
+ node that has one.
1073
+ */
1074
+ prev(enter = true) {
1075
+ return this.move(-1, enter);
1076
+ }
1077
+ /**
1078
+ Move the cursor to the innermost node that covers `pos`. If
1079
+ `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1080
+ it will enter nodes that start at `pos`.
1081
+ */
1082
+ moveTo(pos, side = 0) {
1083
+ while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos)) if (!this.parent()) break;
1084
+ while (this.enterChild(1, pos, side));
1085
+ return this;
1086
+ }
1087
+ /**
1088
+ Get a [syntax node](#common.SyntaxNode) at the cursor's current
1089
+ position.
1090
+ */
1091
+ get node() {
1092
+ if (!this.buffer) return this._tree;
1093
+ let cache = this.bufferNode, result = null, depth = 0;
1094
+ if (cache && cache.context == this.buffer) scan: for (let index = this.index, d = this.stack.length; d >= 0;) {
1095
+ for (let c = cache; c; c = c._parent) if (c.index == index) {
1096
+ if (index == this.index) return c;
1097
+ result = c;
1098
+ depth = d + 1;
1099
+ break scan;
1100
+ }
1101
+ index = this.stack[--d];
1102
+ }
1103
+ for (let i = depth; i < this.stack.length; i++) result = new BufferNode(this.buffer, result, this.stack[i]);
1104
+ return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1105
+ }
1106
+ /**
1107
+ Get the [tree](#common.Tree) that represents the current node, if
1108
+ any. Will return null when the node is in a [tree
1109
+ buffer](#common.TreeBuffer).
1110
+ */
1111
+ get tree() {
1112
+ return this.buffer ? null : this._tree._tree;
1113
+ }
1114
+ /**
1115
+ Iterate over the current node and all its descendants, calling
1116
+ `enter` when entering a node and `leave`, if given, when leaving
1117
+ one. When `enter` returns `false`, any children of that node are
1118
+ skipped, and `leave` isn't called for it.
1119
+ */
1120
+ iterate(enter, leave) {
1121
+ for (let depth = 0;;) {
1122
+ let mustLeave = false;
1123
+ if (this.type.isAnonymous || enter(this) !== false) {
1124
+ if (this.firstChild()) {
1125
+ depth++;
1126
+ continue;
1127
+ }
1128
+ if (!this.type.isAnonymous) mustLeave = true;
1129
+ }
1130
+ for (;;) {
1131
+ if (mustLeave && leave) leave(this);
1132
+ mustLeave = this.type.isAnonymous;
1133
+ if (!depth) return;
1134
+ if (this.nextSibling()) break;
1135
+ this.parent();
1136
+ depth--;
1137
+ mustLeave = true;
1138
+ }
1139
+ }
1140
+ }
1141
+ /**
1142
+ Test whether the current node matches a given context—a sequence
1143
+ of direct parent node names. Empty strings in the context array
1144
+ are treated as wildcards.
1145
+ */
1146
+ matchContext(context) {
1147
+ if (!this.buffer) return matchNodeContext(this.node.parent, context);
1148
+ let { buffer } = this.buffer, { types } = buffer.set;
1149
+ for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
1150
+ if (d < 0) return matchNodeContext(this._tree, context, i);
1151
+ let type = types[buffer.buffer[this.stack[d]]];
1152
+ if (!type.isAnonymous) {
1153
+ if (context[i] && context[i] != type.name) return false;
1154
+ i--;
1155
+ }
1156
+ }
1157
+ return true;
1158
+ }
1159
+ };
1160
+ function hasChild(tree) {
1161
+ return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
1162
+ }
1163
+ function buildTree(data) {
1164
+ var _a;
1165
+ let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
1166
+ let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
1167
+ let types = nodeSet.types;
1168
+ let contextHash = 0, lookAhead = 0;
1169
+ function takeNode(parentStart, minPos, children, positions, inRepeat, depth) {
1170
+ let { id, start, end, size } = cursor;
1171
+ let lookAheadAtStart = lookAhead, contextAtStart = contextHash;
1172
+ if (size < 0) {
1173
+ cursor.next();
1174
+ if (size == -1) {
1175
+ let node = reused[id];
1176
+ children.push(node);
1177
+ positions.push(start - parentStart);
1178
+ return;
1179
+ } else if (size == -3) {
1180
+ contextHash = id;
1181
+ return;
1182
+ } else if (size == -4) {
1183
+ lookAhead = id;
1184
+ return;
1185
+ } else throw new RangeError(`Unrecognized record size: ${size}`);
1186
+ }
1187
+ let type = types[id], node, buffer;
1188
+ let startPos = start - parentStart;
1189
+ if (end - start <= maxBufferLength && (buffer = findBufferSize(cursor.pos - minPos, inRepeat))) {
1190
+ let data = new Uint16Array(buffer.size - buffer.skip);
1191
+ let endPos = cursor.pos - buffer.size, index = data.length;
1192
+ while (cursor.pos > endPos) index = copyToBuffer(buffer.start, data, index);
1193
+ node = new TreeBuffer(data, end - buffer.start, nodeSet);
1194
+ startPos = buffer.start - parentStart;
1195
+ } else {
1196
+ let endPos = cursor.pos - size;
1197
+ cursor.next();
1198
+ let localChildren = [], localPositions = [];
1199
+ let localInRepeat = id >= minRepeatType ? id : -1;
1200
+ let lastGroup = 0, lastEnd = end;
1201
+ while (cursor.pos > endPos) if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
1202
+ if (cursor.end <= lastEnd - maxBufferLength) {
1203
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
1204
+ lastGroup = localChildren.length;
1205
+ lastEnd = cursor.end;
1206
+ }
1207
+ cursor.next();
1208
+ } else if (depth > 2500) takeFlatNode(start, endPos, localChildren, localPositions);
1209
+ else takeNode(start, endPos, localChildren, localPositions, localInRepeat, depth + 1);
1210
+ if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length) makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart, contextAtStart);
1211
+ localChildren.reverse();
1212
+ localPositions.reverse();
1213
+ if (localInRepeat > -1 && lastGroup > 0) {
1214
+ let make = makeBalanced(type, contextAtStart);
1215
+ node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
1216
+ } else node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end, contextAtStart);
1217
+ }
1218
+ children.push(node);
1219
+ positions.push(startPos);
1220
+ }
1221
+ function takeFlatNode(parentStart, minPos, children, positions) {
1222
+ let nodes = [];
1223
+ let nodeCount = 0, stopAt = -1;
1224
+ while (cursor.pos > minPos) {
1225
+ let { id, start, end, size } = cursor;
1226
+ if (size > 4) cursor.next();
1227
+ else if (stopAt > -1 && start < stopAt) break;
1228
+ else {
1229
+ if (stopAt < 0) stopAt = end - maxBufferLength;
1230
+ nodes.push(id, start, end);
1231
+ nodeCount++;
1232
+ cursor.next();
1233
+ }
1234
+ }
1235
+ if (nodeCount) {
1236
+ let buffer = new Uint16Array(nodeCount * 4);
1237
+ let start = nodes[nodes.length - 2];
1238
+ for (let i = nodes.length - 3, j = 0; i >= 0; i -= 3) {
1239
+ buffer[j++] = nodes[i];
1240
+ buffer[j++] = nodes[i + 1] - start;
1241
+ buffer[j++] = nodes[i + 2] - start;
1242
+ buffer[j++] = j;
1243
+ }
1244
+ children.push(new TreeBuffer(buffer, nodes[2] - start, nodeSet));
1245
+ positions.push(start - parentStart);
1246
+ }
1247
+ }
1248
+ function makeBalanced(type, contextHash) {
1249
+ return (children, positions, length) => {
1250
+ let lookAhead = 0, lastI = children.length - 1, last, lookAheadProp;
1251
+ if (lastI >= 0 && (last = children[lastI]) instanceof Tree) {
1252
+ if (!lastI && last.type == type && last.length == length) return last;
1253
+ if (lookAheadProp = last.prop(NodeProp.lookAhead)) lookAhead = positions[lastI] + last.length + lookAheadProp;
1254
+ }
1255
+ return makeTree(type, children, positions, length, lookAhead, contextHash);
1256
+ };
1257
+ }
1258
+ function makeRepeatLeaf(children, positions, base, i, from, to, type, lookAhead, contextHash) {
1259
+ let localChildren = [], localPositions = [];
1260
+ while (children.length > i) {
1261
+ localChildren.push(children.pop());
1262
+ localPositions.push(positions.pop() + base - from);
1263
+ }
1264
+ children.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead - to, contextHash));
1265
+ positions.push(from - base);
1266
+ }
1267
+ function makeTree(type, children, positions, length, lookAhead, contextHash, props) {
1268
+ if (contextHash) {
1269
+ let pair = [NodeProp.contextHash, contextHash];
1270
+ props = props ? [pair].concat(props) : [pair];
1271
+ }
1272
+ if (lookAhead > 25) {
1273
+ let pair = [NodeProp.lookAhead, lookAhead];
1274
+ props = props ? [pair].concat(props) : [pair];
1275
+ }
1276
+ return new Tree(type, children, positions, length, props);
1277
+ }
1278
+ function findBufferSize(maxSize, inRepeat) {
1279
+ let fork = cursor.fork();
1280
+ let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
1281
+ let result = {
1282
+ size: 0,
1283
+ start: 0,
1284
+ skip: 0
1285
+ };
1286
+ scan: for (let minPos = fork.pos - maxSize; fork.pos > minPos;) {
1287
+ let nodeSize = fork.size;
1288
+ if (fork.id == inRepeat && nodeSize >= 0) {
1289
+ result.size = size;
1290
+ result.start = start;
1291
+ result.skip = skip;
1292
+ skip += 4;
1293
+ size += 4;
1294
+ fork.next();
1295
+ continue;
1296
+ }
1297
+ let startPos = fork.pos - nodeSize;
1298
+ if (nodeSize < 0 || startPos < minPos || fork.start < minStart) break;
1299
+ let localSkipped = fork.id >= minRepeatType ? 4 : 0;
1300
+ let nodeStart = fork.start;
1301
+ fork.next();
1302
+ while (fork.pos > startPos) {
1303
+ if (fork.size < 0) if (fork.size == -3 || fork.size == -4) localSkipped += 4;
1304
+ else break scan;
1305
+ else if (fork.id >= minRepeatType) localSkipped += 4;
1306
+ fork.next();
1307
+ }
1308
+ start = nodeStart;
1309
+ size += nodeSize;
1310
+ skip += localSkipped;
1311
+ }
1312
+ if (inRepeat < 0 || size == maxSize) {
1313
+ result.size = size;
1314
+ result.start = start;
1315
+ result.skip = skip;
1316
+ }
1317
+ return result.size > 4 ? result : void 0;
1318
+ }
1319
+ function copyToBuffer(bufferStart, buffer, index) {
1320
+ let { id, start, end, size } = cursor;
1321
+ cursor.next();
1322
+ if (size >= 0 && id < minRepeatType) {
1323
+ let startIndex = index;
1324
+ if (size > 4) {
1325
+ let endPos = cursor.pos - (size - 4);
1326
+ while (cursor.pos > endPos) index = copyToBuffer(bufferStart, buffer, index);
1327
+ }
1328
+ buffer[--index] = startIndex;
1329
+ buffer[--index] = end - bufferStart;
1330
+ buffer[--index] = start - bufferStart;
1331
+ buffer[--index] = id;
1332
+ } else if (size == -3) contextHash = id;
1333
+ else if (size == -4) lookAhead = id;
1334
+ return index;
1335
+ }
1336
+ let children = [], positions = [];
1337
+ while (cursor.pos > 0) takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1, 0);
1338
+ let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
1339
+ return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
1340
+ }
1341
+ const nodeSizeCache = /* @__PURE__ */ new WeakMap();
1342
+ function nodeSize(balanceType, node) {
1343
+ if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType) return 1;
1344
+ let size = nodeSizeCache.get(node);
1345
+ if (size == null) {
1346
+ size = 1;
1347
+ for (let child of node.children) {
1348
+ if (child.type != balanceType || !(child instanceof Tree)) {
1349
+ size = 1;
1350
+ break;
1351
+ }
1352
+ size += nodeSize(balanceType, child);
1353
+ }
1354
+ nodeSizeCache.set(node, size);
1355
+ }
1356
+ return size;
1357
+ }
1358
+ function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
1359
+ let total = 0;
1360
+ for (let i = from; i < to; i++) total += nodeSize(balanceType, children[i]);
1361
+ let maxChild = Math.ceil(total * 1.5 / 8);
1362
+ let localChildren = [], localPositions = [];
1363
+ function divide(children, positions, from, to, offset) {
1364
+ for (let i = from; i < to;) {
1365
+ let groupFrom = i, groupStart = positions[i], groupSize = nodeSize(balanceType, children[i]);
1366
+ i++;
1367
+ for (; i < to; i++) {
1368
+ let nextSize = nodeSize(balanceType, children[i]);
1369
+ if (groupSize + nextSize >= maxChild) break;
1370
+ groupSize += nextSize;
1371
+ }
1372
+ if (i == groupFrom + 1) {
1373
+ if (groupSize > maxChild) {
1374
+ let only = children[groupFrom];
1375
+ divide(only.children, only.positions, 0, only.children.length, positions[groupFrom] + offset);
1376
+ continue;
1377
+ }
1378
+ localChildren.push(children[groupFrom]);
1379
+ } else {
1380
+ let length = positions[i - 1] + children[i - 1].length - groupStart;
1381
+ localChildren.push(balanceRange(balanceType, children, positions, groupFrom, i, groupStart, length, null, mkTree));
1382
+ }
1383
+ localPositions.push(groupStart + offset - start);
1384
+ }
1385
+ }
1386
+ divide(children, positions, from, to, 0);
1387
+ return (mkTop || mkTree)(localChildren, localPositions, length);
1388
+ }
1389
+ /**
1390
+ Provides a way to associate values with pieces of trees. As long
1391
+ as that part of the tree is reused, the associated values can be
1392
+ retrieved from an updated tree.
1393
+ */
1394
+ var NodeWeakMap = class {
1395
+ constructor() {
1396
+ this.map = /* @__PURE__ */ new WeakMap();
1397
+ }
1398
+ setBuffer(buffer, index, value) {
1399
+ let inner = this.map.get(buffer);
1400
+ if (!inner) this.map.set(buffer, inner = /* @__PURE__ */ new Map());
1401
+ inner.set(index, value);
1402
+ }
1403
+ getBuffer(buffer, index) {
1404
+ let inner = this.map.get(buffer);
1405
+ return inner && inner.get(index);
1406
+ }
1407
+ /**
1408
+ Set the value for this syntax node.
1409
+ */
1410
+ set(node, value) {
1411
+ if (node instanceof BufferNode) this.setBuffer(node.context.buffer, node.index, value);
1412
+ else if (node instanceof TreeNode) this.map.set(node.tree, value);
1413
+ }
1414
+ /**
1415
+ Retrieve value for this syntax node, if it exists in the map.
1416
+ */
1417
+ get(node) {
1418
+ return node instanceof BufferNode ? this.getBuffer(node.context.buffer, node.index) : node instanceof TreeNode ? this.map.get(node.tree) : void 0;
1419
+ }
1420
+ /**
1421
+ Set the value for the node that a cursor currently points to.
1422
+ */
1423
+ cursorSet(cursor, value) {
1424
+ if (cursor.buffer) this.setBuffer(cursor.buffer.buffer, cursor.index, value);
1425
+ else this.map.set(cursor.tree, value);
1426
+ }
1427
+ /**
1428
+ Retrieve the value for the node that a cursor currently points
1429
+ to.
1430
+ */
1431
+ cursorGet(cursor) {
1432
+ return cursor.buffer ? this.getBuffer(cursor.buffer.buffer, cursor.index) : this.map.get(cursor.tree);
1433
+ }
1434
+ };
1435
+ /**
1436
+ Tree fragments are used during [incremental
1437
+ parsing](#common.Parser.startParse) to track parts of old trees
1438
+ that can be reused in a new parse. An array of fragments is used
1439
+ to track regions of an old tree whose nodes might be reused in new
1440
+ parses. Use the static
1441
+ [`applyChanges`](#common.TreeFragment^applyChanges) method to
1442
+ update fragments for document changes.
1443
+ */
1444
+ var TreeFragment = class TreeFragment {
1445
+ /**
1446
+ Construct a tree fragment. You'll usually want to use
1447
+ [`addTree`](#common.TreeFragment^addTree) and
1448
+ [`applyChanges`](#common.TreeFragment^applyChanges) instead of
1449
+ calling this directly.
1450
+ */
1451
+ constructor(from, to, tree, offset, openStart = false, openEnd = false) {
1452
+ this.from = from;
1453
+ this.to = to;
1454
+ this.tree = tree;
1455
+ this.offset = offset;
1456
+ this.open = (openStart ? 1 : 0) | (openEnd ? 2 : 0);
1457
+ }
1458
+ /**
1459
+ Whether the start of the fragment represents the start of a
1460
+ parse, or the end of a change. (In the second case, it may not
1461
+ be safe to reuse some nodes at the start, depending on the
1462
+ parsing algorithm.)
1463
+ */
1464
+ get openStart() {
1465
+ return (this.open & 1) > 0;
1466
+ }
1467
+ /**
1468
+ Whether the end of the fragment represents the end of a
1469
+ full-document parse, or the start of a change.
1470
+ */
1471
+ get openEnd() {
1472
+ return (this.open & 2) > 0;
1473
+ }
1474
+ /**
1475
+ Create a set of fragments from a freshly parsed tree, or update
1476
+ an existing set of fragments by replacing the ones that overlap
1477
+ with a tree with content from the new tree. When `partial` is
1478
+ true, the parse is treated as incomplete, and the resulting
1479
+ fragment has [`openEnd`](#common.TreeFragment.openEnd) set to
1480
+ true.
1481
+ */
1482
+ static addTree(tree, fragments = [], partial = false) {
1483
+ let result = [new TreeFragment(0, tree.length, tree, 0, false, partial)];
1484
+ for (let f of fragments) if (f.to > tree.length) result.push(f);
1485
+ return result;
1486
+ }
1487
+ /**
1488
+ Apply a set of edits to an array of fragments, removing or
1489
+ splitting fragments as necessary to remove edited ranges, and
1490
+ adjusting offsets for fragments that moved.
1491
+ */
1492
+ static applyChanges(fragments, changes, minGap = 128) {
1493
+ if (!changes.length) return fragments;
1494
+ let result = [];
1495
+ let fI = 1, nextF = fragments.length ? fragments[0] : null;
1496
+ for (let cI = 0, pos = 0, off = 0;; cI++) {
1497
+ let nextC = cI < changes.length ? changes[cI] : null;
1498
+ let nextPos = nextC ? nextC.fromA : 1e9;
1499
+ if (nextPos - pos >= minGap) while (nextF && nextF.from < nextPos) {
1500
+ let cut = nextF;
1501
+ if (pos >= cut.from || nextPos <= cut.to || off) {
1502
+ let fFrom = Math.max(cut.from, pos) - off, fTo = Math.min(cut.to, nextPos) - off;
1503
+ cut = fFrom >= fTo ? null : new TreeFragment(fFrom, fTo, cut.tree, cut.offset + off, cI > 0, !!nextC);
1504
+ }
1505
+ if (cut) result.push(cut);
1506
+ if (nextF.to > nextPos) break;
1507
+ nextF = fI < fragments.length ? fragments[fI++] : null;
1508
+ }
1509
+ if (!nextC) break;
1510
+ pos = nextC.toA;
1511
+ off = nextC.toA - nextC.toB;
1512
+ }
1513
+ return result;
1514
+ }
1515
+ };
1516
+ /**
1517
+ A superclass that parsers should extend.
1518
+ */
1519
+ var Parser = class {
1520
+ /**
1521
+ Start a parse, returning a [partial parse](#common.PartialParse)
1522
+ object. [`fragments`](#common.TreeFragment) can be passed in to
1523
+ make the parse incremental.
1524
+
1525
+ By default, the entire input is parsed. You can pass `ranges`,
1526
+ which should be a sorted array of non-empty, non-overlapping
1527
+ ranges, to parse only those ranges. The tree returned in that
1528
+ case will start at `ranges[0].from`.
1529
+ */
1530
+ startParse(input, fragments, ranges) {
1531
+ if (typeof input == "string") input = new StringInput(input);
1532
+ ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
1533
+ return this.createParse(input, fragments || [], ranges);
1534
+ }
1535
+ /**
1536
+ Run a full parse, returning the resulting tree.
1537
+ */
1538
+ parse(input, fragments, ranges) {
1539
+ let parse = this.startParse(input, fragments, ranges);
1540
+ for (;;) {
1541
+ let done = parse.advance();
1542
+ if (done) return done;
1543
+ }
1544
+ }
1545
+ };
1546
+ var StringInput = class {
1547
+ constructor(string) {
1548
+ this.string = string;
1549
+ }
1550
+ get length() {
1551
+ return this.string.length;
1552
+ }
1553
+ chunk(from) {
1554
+ return this.string.slice(from);
1555
+ }
1556
+ get lineChunks() {
1557
+ return false;
1558
+ }
1559
+ read(from, to) {
1560
+ return this.string.slice(from, to);
1561
+ }
1562
+ };
1563
+ /**
1564
+ Create a parse wrapper that, after the inner parse completes,
1565
+ scans its tree for mixed language regions with the `nest`
1566
+ function, runs the resulting [inner parses](#common.NestedParse),
1567
+ and then [mounts](#common.NodeProp^mounted) their results onto the
1568
+ tree.
1569
+ */
1570
+ function parseMixed(nest) {
1571
+ return (parse, input, fragments, ranges) => new MixedParse(parse, nest, input, fragments, ranges);
1572
+ }
1573
+ var InnerParse = class {
1574
+ constructor(parser, parse, overlay, bracketed, target, from) {
1575
+ this.parser = parser;
1576
+ this.parse = parse;
1577
+ this.overlay = overlay;
1578
+ this.bracketed = bracketed;
1579
+ this.target = target;
1580
+ this.from = from;
1581
+ }
1582
+ };
1583
+ function checkRanges(ranges) {
1584
+ if (!ranges.length || ranges.some((r) => r.from >= r.to)) throw new RangeError("Invalid inner parse ranges given: " + JSON.stringify(ranges));
1585
+ }
1586
+ var ActiveOverlay = class {
1587
+ constructor(parser, predicate, mounts, index, start, bracketed, target, prev) {
1588
+ this.parser = parser;
1589
+ this.predicate = predicate;
1590
+ this.mounts = mounts;
1591
+ this.index = index;
1592
+ this.start = start;
1593
+ this.bracketed = bracketed;
1594
+ this.target = target;
1595
+ this.prev = prev;
1596
+ this.depth = 0;
1597
+ this.ranges = [];
1598
+ }
1599
+ };
1600
+ const stoppedInner = new NodeProp({ perNode: true });
1601
+ var MixedParse = class {
1602
+ constructor(base, nest, input, fragments, ranges) {
1603
+ this.nest = nest;
1604
+ this.input = input;
1605
+ this.fragments = fragments;
1606
+ this.ranges = ranges;
1607
+ this.inner = [];
1608
+ this.innerDone = 0;
1609
+ this.baseTree = null;
1610
+ this.stoppedAt = null;
1611
+ this.baseParse = base;
1612
+ }
1613
+ advance() {
1614
+ if (this.baseParse) {
1615
+ let done = this.baseParse.advance();
1616
+ if (!done) return null;
1617
+ this.baseParse = null;
1618
+ this.baseTree = done;
1619
+ this.startInner();
1620
+ if (this.stoppedAt != null) for (let inner of this.inner) inner.parse.stopAt(this.stoppedAt);
1621
+ }
1622
+ if (this.innerDone == this.inner.length) {
1623
+ let result = this.baseTree;
1624
+ if (this.stoppedAt != null) result = new Tree(result.type, result.children, result.positions, result.length, result.propValues.concat([[stoppedInner, this.stoppedAt]]));
1625
+ return result;
1626
+ }
1627
+ let inner = this.inner[this.innerDone], done = inner.parse.advance();
1628
+ if (done) {
1629
+ this.innerDone++;
1630
+ let props = Object.assign(Object.create(null), inner.target.props);
1631
+ props[NodeProp.mounted.id] = new MountedTree(done, inner.overlay, inner.parser, inner.bracketed);
1632
+ inner.target.props = props;
1633
+ }
1634
+ return null;
1635
+ }
1636
+ get parsedPos() {
1637
+ if (this.baseParse) return 0;
1638
+ let pos = this.input.length;
1639
+ for (let i = this.innerDone; i < this.inner.length; i++) if (this.inner[i].from < pos) pos = Math.min(pos, this.inner[i].parse.parsedPos);
1640
+ return pos;
1641
+ }
1642
+ stopAt(pos) {
1643
+ this.stoppedAt = pos;
1644
+ if (this.baseParse) this.baseParse.stopAt(pos);
1645
+ else for (let i = this.innerDone; i < this.inner.length; i++) this.inner[i].parse.stopAt(pos);
1646
+ }
1647
+ startInner() {
1648
+ let fragmentCursor = new FragmentCursor$1(this.fragments);
1649
+ let overlay = null;
1650
+ let covered = null;
1651
+ let cursor = new TreeCursor(new TreeNode(this.baseTree, this.ranges[0].from, 0, null), IterMode.IncludeAnonymous | IterMode.IgnoreMounts);
1652
+ scan: for (let nest, isCovered;;) {
1653
+ let enter = true, range;
1654
+ if (this.stoppedAt != null && cursor.from >= this.stoppedAt) enter = false;
1655
+ else if (fragmentCursor.hasNode(cursor)) {
1656
+ if (overlay) {
1657
+ let match = overlay.mounts.find((m) => m.frag.from <= cursor.from && m.frag.to >= cursor.to && m.mount.overlay);
1658
+ if (match) for (let r of match.mount.overlay) {
1659
+ let from = r.from + match.pos, to = r.to + match.pos;
1660
+ if (from >= cursor.from && to <= cursor.to && !overlay.ranges.some((r) => r.from < to && r.to > from)) overlay.ranges.push({
1661
+ from,
1662
+ to
1663
+ });
1664
+ }
1665
+ }
1666
+ enter = false;
1667
+ } else if (covered && (isCovered = checkCover(covered.ranges, cursor.from, cursor.to))) enter = isCovered != 2;
1668
+ else if (!cursor.type.isAnonymous && (nest = this.nest(cursor, this.input)) && (cursor.from < cursor.to || !nest.overlay)) {
1669
+ if (!cursor.tree) {
1670
+ materialize(cursor);
1671
+ if (overlay) overlay.depth++;
1672
+ if (covered) covered.depth++;
1673
+ }
1674
+ let oldMounts = fragmentCursor.findMounts(cursor.from, nest.parser);
1675
+ if (typeof nest.overlay == "function") overlay = new ActiveOverlay(nest.parser, nest.overlay, oldMounts, this.inner.length, cursor.from, !!nest.bracketed, cursor.tree, overlay);
1676
+ else {
1677
+ let ranges = punchRanges(this.ranges, nest.overlay || (cursor.from < cursor.to ? [new Range(cursor.from, cursor.to)] : []));
1678
+ if (ranges.length) checkRanges(ranges);
1679
+ if (ranges.length || !nest.overlay) this.inner.push(new InnerParse(nest.parser, ranges.length ? nest.parser.startParse(this.input, enterFragments(oldMounts, ranges), ranges) : nest.parser.startParse(""), nest.overlay ? nest.overlay.map((r) => new Range(r.from - cursor.from, r.to - cursor.from)) : null, !!nest.bracketed, cursor.tree, ranges.length ? ranges[0].from : cursor.from));
1680
+ if (!nest.overlay) enter = false;
1681
+ else if (ranges.length) covered = {
1682
+ ranges,
1683
+ depth: 0,
1684
+ prev: covered
1685
+ };
1686
+ }
1687
+ } else if (overlay && (range = overlay.predicate(cursor))) {
1688
+ if (range === true) range = new Range(cursor.from, cursor.to);
1689
+ if (range.from < range.to) {
1690
+ let last = overlay.ranges.length - 1;
1691
+ if (last >= 0 && overlay.ranges[last].to == range.from) overlay.ranges[last] = {
1692
+ from: overlay.ranges[last].from,
1693
+ to: range.to
1694
+ };
1695
+ else overlay.ranges.push(range);
1696
+ }
1697
+ }
1698
+ if (enter && cursor.firstChild()) {
1699
+ if (overlay) overlay.depth++;
1700
+ if (covered) covered.depth++;
1701
+ } else for (;;) {
1702
+ if (cursor.nextSibling()) break;
1703
+ if (!cursor.parent()) break scan;
1704
+ if (overlay && !--overlay.depth) {
1705
+ let ranges = punchRanges(this.ranges, overlay.ranges);
1706
+ if (ranges.length) {
1707
+ checkRanges(ranges);
1708
+ 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.bracketed, overlay.target, ranges[0].from));
1709
+ }
1710
+ overlay = overlay.prev;
1711
+ }
1712
+ if (covered && !--covered.depth) covered = covered.prev;
1713
+ }
1714
+ }
1715
+ }
1716
+ };
1717
+ function checkCover(covered, from, to) {
1718
+ for (let range of covered) {
1719
+ if (range.from >= to) break;
1720
+ if (range.to > from) return range.from <= from && range.to >= to ? 2 : 1;
1721
+ }
1722
+ return 0;
1723
+ }
1724
+ function sliceBuf(buf, startI, endI, nodes, positions, off) {
1725
+ if (startI < endI) {
1726
+ let from = buf.buffer[startI + 1];
1727
+ nodes.push(buf.slice(startI, endI, from));
1728
+ positions.push(from - off);
1729
+ }
1730
+ }
1731
+ function materialize(cursor) {
1732
+ let { node } = cursor, stack = [];
1733
+ let buffer = node.context.buffer;
1734
+ do {
1735
+ stack.push(cursor.index);
1736
+ cursor.parent();
1737
+ } while (!cursor.tree);
1738
+ let base = cursor.tree, i = base.children.indexOf(buffer);
1739
+ let buf = base.children[i], b = buf.buffer, newStack = [i];
1740
+ function split(startI, endI, type, innerOffset, length, stackPos) {
1741
+ let targetI = stack[stackPos];
1742
+ let children = [], positions = [];
1743
+ sliceBuf(buf, startI, targetI, children, positions, innerOffset);
1744
+ let from = b[targetI + 1], to = b[targetI + 2];
1745
+ newStack.push(children.length);
1746
+ let child = stackPos ? split(targetI + 4, b[targetI + 3], buf.set.types[b[targetI]], from, to - from, stackPos - 1) : node.toTree();
1747
+ children.push(child);
1748
+ positions.push(from - innerOffset);
1749
+ sliceBuf(buf, b[targetI + 3], endI, children, positions, innerOffset);
1750
+ return new Tree(type, children, positions, length);
1751
+ }
1752
+ base.children[i] = split(0, b.length, NodeType.none, 0, buf.length, stack.length - 1);
1753
+ for (let index of newStack) {
1754
+ let tree = cursor.tree.children[index], pos = cursor.tree.positions[index];
1755
+ cursor.yield(new TreeNode(tree, pos + cursor.from, index, cursor._tree));
1756
+ }
1757
+ }
1758
+ var StructureCursor = class {
1759
+ constructor(root, offset) {
1760
+ this.offset = offset;
1761
+ this.done = false;
1762
+ this.cursor = root.cursor(IterMode.IncludeAnonymous | IterMode.IgnoreMounts);
1763
+ }
1764
+ moveTo(pos) {
1765
+ let { cursor } = this, p = pos - this.offset;
1766
+ while (!this.done && cursor.from < p) if (cursor.to >= pos && cursor.enter(p, 1, IterMode.IgnoreOverlays | IterMode.ExcludeBuffers));
1767
+ else if (!cursor.next(false)) this.done = true;
1768
+ }
1769
+ hasNode(cursor) {
1770
+ this.moveTo(cursor.from);
1771
+ if (!this.done && this.cursor.from + this.offset == cursor.from && this.cursor.tree) for (let tree = this.cursor.tree;;) {
1772
+ if (tree == cursor.tree) return true;
1773
+ if (tree.children.length && tree.positions[0] == 0 && tree.children[0] instanceof Tree) tree = tree.children[0];
1774
+ else break;
1775
+ }
1776
+ return false;
1777
+ }
1778
+ };
1779
+ var FragmentCursor$1 = class {
1780
+ constructor(fragments) {
1781
+ var _a;
1782
+ this.fragments = fragments;
1783
+ this.curTo = 0;
1784
+ this.fragI = 0;
1785
+ if (fragments.length) {
1786
+ let first = this.curFrag = fragments[0];
1787
+ this.curTo = (_a = first.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : first.to;
1788
+ this.inner = new StructureCursor(first.tree, -first.offset);
1789
+ } else this.curFrag = this.inner = null;
1790
+ }
1791
+ hasNode(node) {
1792
+ while (this.curFrag && node.from >= this.curTo) this.nextFrag();
1793
+ return this.curFrag && this.curFrag.from <= node.from && this.curTo >= node.to && this.inner.hasNode(node);
1794
+ }
1795
+ nextFrag() {
1796
+ var _a;
1797
+ this.fragI++;
1798
+ if (this.fragI == this.fragments.length) this.curFrag = this.inner = null;
1799
+ else {
1800
+ let frag = this.curFrag = this.fragments[this.fragI];
1801
+ this.curTo = (_a = frag.tree.prop(stoppedInner)) !== null && _a !== void 0 ? _a : frag.to;
1802
+ this.inner = new StructureCursor(frag.tree, -frag.offset);
1803
+ }
1804
+ }
1805
+ findMounts(pos, parser) {
1806
+ var _a;
1807
+ let result = [];
1808
+ if (this.inner) {
1809
+ this.inner.cursor.moveTo(pos, 1);
1810
+ for (let pos = this.inner.cursor.node; pos; pos = pos.parent) {
1811
+ let mount = (_a = pos.tree) === null || _a === void 0 ? void 0 : _a.prop(NodeProp.mounted);
1812
+ if (mount && mount.parser == parser) for (let i = this.fragI; i < this.fragments.length; i++) {
1813
+ let frag = this.fragments[i];
1814
+ if (frag.from >= pos.to) break;
1815
+ if (frag.tree == this.curFrag.tree) result.push({
1816
+ frag,
1817
+ pos: pos.from - frag.offset,
1818
+ mount
1819
+ });
1820
+ }
1821
+ }
1822
+ }
1823
+ return result;
1824
+ }
1825
+ };
1826
+ function punchRanges(outer, ranges) {
1827
+ let copy = null, current = ranges;
1828
+ for (let i = 1, j = 0; i < outer.length; i++) {
1829
+ let gapFrom = outer[i - 1].to, gapTo = outer[i].from;
1830
+ for (; j < current.length; j++) {
1831
+ let r = current[j];
1832
+ if (r.from >= gapTo) break;
1833
+ if (r.to <= gapFrom) continue;
1834
+ if (!copy) current = copy = ranges.slice();
1835
+ if (r.from < gapFrom) {
1836
+ copy[j] = new Range(r.from, gapFrom);
1837
+ if (r.to > gapTo) copy.splice(j + 1, 0, new Range(gapTo, r.to));
1838
+ } else if (r.to > gapTo) copy[j--] = new Range(gapTo, r.to);
1839
+ else copy.splice(j--, 1);
1840
+ }
1841
+ }
1842
+ return current;
1843
+ }
1844
+ function findCoverChanges(a, b, from, to) {
1845
+ let iA = 0, iB = 0, inA = false, inB = false, pos = -1e9;
1846
+ let result = [];
1847
+ for (;;) {
1848
+ let nextA = iA == a.length ? 1e9 : inA ? a[iA].to : a[iA].from;
1849
+ let nextB = iB == b.length ? 1e9 : inB ? b[iB].to : b[iB].from;
1850
+ if (inA != inB) {
1851
+ let start = Math.max(pos, from), end = Math.min(nextA, nextB, to);
1852
+ if (start < end) result.push(new Range(start, end));
1853
+ }
1854
+ pos = Math.min(nextA, nextB);
1855
+ if (pos == 1e9) break;
1856
+ if (nextA == pos) if (!inA) inA = true;
1857
+ else {
1858
+ inA = false;
1859
+ iA++;
1860
+ }
1861
+ if (nextB == pos) if (!inB) inB = true;
1862
+ else {
1863
+ inB = false;
1864
+ iB++;
1865
+ }
1866
+ }
1867
+ return result;
1868
+ }
1869
+ function enterFragments(mounts, ranges) {
1870
+ let result = [];
1871
+ for (let { pos, mount, frag } of mounts) {
1872
+ let startPos = pos + (mount.overlay ? mount.overlay[0].from : 0), endPos = startPos + mount.tree.length;
1873
+ let from = Math.max(frag.from, startPos), to = Math.min(frag.to, endPos);
1874
+ if (mount.overlay) {
1875
+ let changes = findCoverChanges(ranges, mount.overlay.map((r) => new Range(r.from + pos, r.to + pos)), from, to);
1876
+ for (let i = 0, pos = from;; i++) {
1877
+ let last = i == changes.length, end = last ? to : changes[i].from;
1878
+ if (end > pos) result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
1879
+ if (last) break;
1880
+ pos = changes[i].to;
1881
+ }
1882
+ } else result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
1883
+ }
1884
+ return result;
1885
+ }
1886
+
1887
+ //#endregion
1888
+ //#region ../../node_modules/.bun/@lezer+lr@1.4.8/node_modules/@lezer/lr/dist/index.js
1889
+ /**
1890
+ A parse stack. These are used internally by the parser to track
1891
+ parsing progress. They also provide some properties and methods
1892
+ that external code such as a tokenizer can use to get information
1893
+ about the parse state.
1894
+ */
1895
+ var Stack = class Stack {
1896
+ /**
1897
+ @internal
1898
+ */
1899
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
1900
+ this.p = p;
1901
+ this.stack = stack;
1902
+ this.state = state;
1903
+ this.reducePos = reducePos;
1904
+ this.pos = pos;
1905
+ this.score = score;
1906
+ this.buffer = buffer;
1907
+ this.bufferBase = bufferBase;
1908
+ this.curContext = curContext;
1909
+ this.lookAhead = lookAhead;
1910
+ this.parent = parent;
1911
+ }
1912
+ /**
1913
+ @internal
1914
+ */
1915
+ toString() {
1916
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
1917
+ }
1918
+ /**
1919
+ @internal
1920
+ */
1921
+ static start(p, state, pos = 0) {
1922
+ let cx = p.parser.context;
1923
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
1924
+ }
1925
+ /**
1926
+ The stack's current [context](#lr.ContextTracker) value, if
1927
+ any. Its type will depend on the context tracker's type
1928
+ parameter, or it will be `null` if there is no context
1929
+ tracker.
1930
+ */
1931
+ get context() {
1932
+ return this.curContext ? this.curContext.context : null;
1933
+ }
1934
+ /**
1935
+ @internal
1936
+ */
1937
+ pushState(state, start) {
1938
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
1939
+ this.state = state;
1940
+ }
1941
+ /**
1942
+ @internal
1943
+ */
1944
+ reduce(action) {
1945
+ var _a;
1946
+ let depth = action >> 19, type = action & 65535;
1947
+ let { parser } = this.p;
1948
+ let lookaheadRecord = this.reducePos < this.pos - 25 && this.setLookAhead(this.pos);
1949
+ let dPrec = parser.dynamicPrecedence(type);
1950
+ if (dPrec) this.score += dPrec;
1951
+ if (depth == 0) {
1952
+ this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
1953
+ if (type < parser.minRepeatTerm) this.storeNode(type, this.reducePos, this.reducePos, lookaheadRecord ? 8 : 4, true);
1954
+ this.reduceContext(type, this.reducePos);
1955
+ return;
1956
+ }
1957
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
1958
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
1959
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
1960
+ if (start == this.p.lastBigReductionStart) {
1961
+ this.p.bigReductionCount++;
1962
+ this.p.lastBigReductionSize = size;
1963
+ } else if (this.p.lastBigReductionSize < size) {
1964
+ this.p.bigReductionCount = 1;
1965
+ this.p.lastBigReductionStart = start;
1966
+ this.p.lastBigReductionSize = size;
1967
+ }
1968
+ }
1969
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
1970
+ if (type < parser.minRepeatTerm || action & 131072) {
1971
+ let pos = parser.stateFlag(this.state, 1) ? this.pos : this.reducePos;
1972
+ this.storeNode(type, start, pos, count + 4, true);
1973
+ }
1974
+ if (action & 262144) this.state = this.stack[base];
1975
+ else {
1976
+ let baseStateID = this.stack[base - 3];
1977
+ this.state = parser.getGoto(baseStateID, type, true);
1978
+ }
1979
+ while (this.stack.length > base) this.stack.pop();
1980
+ this.reduceContext(type, start);
1981
+ }
1982
+ /**
1983
+ @internal
1984
+ */
1985
+ storeNode(term, start, end, size = 4, mustSink = false) {
1986
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
1987
+ let cur = this, top = this.buffer.length;
1988
+ if (top == 0 && cur.parent) {
1989
+ top = cur.bufferBase - cur.parent.bufferBase;
1990
+ cur = cur.parent;
1991
+ }
1992
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
1993
+ if (start == end) return;
1994
+ if (cur.buffer[top - 2] >= start) {
1995
+ cur.buffer[top - 2] = end;
1996
+ return;
1997
+ }
1998
+ }
1999
+ }
2000
+ if (!mustSink || this.pos == end) this.buffer.push(term, start, end, size);
2001
+ else {
2002
+ let index = this.buffer.length;
2003
+ if (index > 0 && (this.buffer[index - 4] != 0 || this.buffer[index - 1] < 0)) {
2004
+ let mustMove = false;
2005
+ for (let scan = index; scan > 0 && this.buffer[scan - 2] > end; scan -= 4) if (this.buffer[scan - 1] >= 0) {
2006
+ mustMove = true;
2007
+ break;
2008
+ }
2009
+ if (mustMove) while (index > 0 && this.buffer[index - 2] > end) {
2010
+ this.buffer[index] = this.buffer[index - 4];
2011
+ this.buffer[index + 1] = this.buffer[index - 3];
2012
+ this.buffer[index + 2] = this.buffer[index - 2];
2013
+ this.buffer[index + 3] = this.buffer[index - 1];
2014
+ index -= 4;
2015
+ if (size > 4) size -= 4;
2016
+ }
2017
+ }
2018
+ this.buffer[index] = term;
2019
+ this.buffer[index + 1] = start;
2020
+ this.buffer[index + 2] = end;
2021
+ this.buffer[index + 3] = size;
2022
+ }
2023
+ }
2024
+ /**
2025
+ @internal
2026
+ */
2027
+ shift(action, type, start, end) {
2028
+ if (action & 131072) this.pushState(action & 65535, this.pos);
2029
+ else if ((action & 262144) == 0) {
2030
+ let nextState = action, { parser } = this.p;
2031
+ this.pos = end;
2032
+ let skipped = parser.stateFlag(nextState, 1);
2033
+ if (!skipped && (end > start || type <= parser.maxNode)) this.reducePos = end;
2034
+ this.pushState(nextState, skipped ? start : Math.min(start, this.reducePos));
2035
+ this.shiftContext(type, start);
2036
+ if (type <= parser.maxNode) this.buffer.push(type, start, end, 4);
2037
+ } else {
2038
+ this.pos = end;
2039
+ this.shiftContext(type, start);
2040
+ if (type <= this.p.parser.maxNode) this.buffer.push(type, start, end, 4);
2041
+ }
2042
+ }
2043
+ /**
2044
+ @internal
2045
+ */
2046
+ apply(action, next, nextStart, nextEnd) {
2047
+ if (action & 65536) this.reduce(action);
2048
+ else this.shift(action, next, nextStart, nextEnd);
2049
+ }
2050
+ /**
2051
+ @internal
2052
+ */
2053
+ useNode(value, next) {
2054
+ let index = this.p.reused.length - 1;
2055
+ if (index < 0 || this.p.reused[index] != value) {
2056
+ this.p.reused.push(value);
2057
+ index++;
2058
+ }
2059
+ let start = this.pos;
2060
+ this.reducePos = this.pos = start + value.length;
2061
+ this.pushState(next, start);
2062
+ this.buffer.push(index, start, this.reducePos, -1);
2063
+ if (this.curContext) this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
2064
+ }
2065
+ /**
2066
+ @internal
2067
+ */
2068
+ split() {
2069
+ let parent = this;
2070
+ let off = parent.buffer.length;
2071
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos) off -= 4;
2072
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
2073
+ while (parent && base == parent.bufferBase) parent = parent.parent;
2074
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
2075
+ }
2076
+ /**
2077
+ @internal
2078
+ */
2079
+ recoverByDelete(next, nextEnd) {
2080
+ let isNode = next <= this.p.parser.maxNode;
2081
+ if (isNode) this.storeNode(next, this.pos, nextEnd, 4);
2082
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
2083
+ this.pos = this.reducePos = nextEnd;
2084
+ this.score -= 190;
2085
+ }
2086
+ /**
2087
+ Check if the given term would be able to be shifted (optionally
2088
+ after some reductions) on this stack. This can be useful for
2089
+ external tokenizers that want to make sure they only provide a
2090
+ given token when it applies.
2091
+ */
2092
+ canShift(term) {
2093
+ for (let sim = new SimulatedStack(this);;) {
2094
+ let action = this.p.parser.stateSlot(sim.state, 4) || this.p.parser.hasAction(sim.state, term);
2095
+ if (action == 0) return false;
2096
+ if ((action & 65536) == 0) return true;
2097
+ sim.reduce(action);
2098
+ }
2099
+ }
2100
+ /**
2101
+ @internal
2102
+ */
2103
+ recoverByInsert(next) {
2104
+ if (this.stack.length >= 300) return [];
2105
+ let nextStates = this.p.parser.nextStates(this.state);
2106
+ if (nextStates.length > 8 || this.stack.length >= 120) {
2107
+ let best = [];
2108
+ for (let i = 0, s; i < nextStates.length; i += 2) if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next)) best.push(nextStates[i], s);
2109
+ if (this.stack.length < 120) for (let i = 0; best.length < 8 && i < nextStates.length; i += 2) {
2110
+ let s = nextStates[i + 1];
2111
+ if (!best.some((v, i) => i & 1 && v == s)) best.push(nextStates[i], s);
2112
+ }
2113
+ nextStates = best;
2114
+ }
2115
+ let result = [];
2116
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
2117
+ let s = nextStates[i + 1];
2118
+ if (s == this.state) continue;
2119
+ let stack = this.split();
2120
+ stack.pushState(s, this.pos);
2121
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
2122
+ stack.shiftContext(nextStates[i], this.pos);
2123
+ stack.reducePos = this.pos;
2124
+ stack.score -= 200;
2125
+ result.push(stack);
2126
+ }
2127
+ return result;
2128
+ }
2129
+ /**
2130
+ @internal
2131
+ */
2132
+ forceReduce() {
2133
+ let { parser } = this.p;
2134
+ let reduce = parser.stateSlot(this.state, 5);
2135
+ if ((reduce & 65536) == 0) return false;
2136
+ if (!parser.validAction(this.state, reduce)) {
2137
+ let depth = reduce >> 19, term = reduce & 65535;
2138
+ let target = this.stack.length - depth * 3;
2139
+ if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) {
2140
+ let backup = this.findForcedReduction();
2141
+ if (backup == null) return false;
2142
+ reduce = backup;
2143
+ }
2144
+ this.storeNode(0, this.pos, this.pos, 4, true);
2145
+ this.score -= 100;
2146
+ }
2147
+ this.reducePos = this.pos;
2148
+ this.reduce(reduce);
2149
+ return true;
2150
+ }
2151
+ /**
2152
+ Try to scan through the automaton to find some kind of reduction
2153
+ that can be applied. Used when the regular ForcedReduce field
2154
+ isn't a valid action. @internal
2155
+ */
2156
+ findForcedReduction() {
2157
+ let { parser } = this.p, seen = [];
2158
+ let explore = (state, depth) => {
2159
+ if (seen.includes(state)) return;
2160
+ seen.push(state);
2161
+ return parser.allActions(state, (action) => {
2162
+ if (action & 393216);
2163
+ else if (action & 65536) {
2164
+ let rDepth = (action >> 19) - depth;
2165
+ if (rDepth > 1) {
2166
+ let term = action & 65535, target = this.stack.length - rDepth * 3;
2167
+ if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0) return rDepth << 19 | 65536 | term;
2168
+ }
2169
+ } else {
2170
+ let found = explore(action, depth + 1);
2171
+ if (found != null) return found;
2172
+ }
2173
+ });
2174
+ };
2175
+ return explore(this.state, 0);
2176
+ }
2177
+ /**
2178
+ @internal
2179
+ */
2180
+ forceAll() {
2181
+ while (!this.p.parser.stateFlag(this.state, 2)) if (!this.forceReduce()) {
2182
+ this.storeNode(0, this.pos, this.pos, 4, true);
2183
+ break;
2184
+ }
2185
+ return this;
2186
+ }
2187
+ /**
2188
+ Check whether this state has no further actions (assumed to be a direct descendant of the
2189
+ top state, since any other states must be able to continue
2190
+ somehow). @internal
2191
+ */
2192
+ get deadEnd() {
2193
+ if (this.stack.length != 3) return false;
2194
+ let { parser } = this.p;
2195
+ return parser.data[parser.stateSlot(this.state, 1)] == 65535 && !parser.stateSlot(this.state, 4);
2196
+ }
2197
+ /**
2198
+ Restart the stack (put it back in its start state). Only safe
2199
+ when this.stack.length == 3 (state is directly below the top
2200
+ state). @internal
2201
+ */
2202
+ restart() {
2203
+ this.storeNode(0, this.pos, this.pos, 4, true);
2204
+ this.state = this.stack[0];
2205
+ this.stack.length = 0;
2206
+ }
2207
+ /**
2208
+ @internal
2209
+ */
2210
+ sameState(other) {
2211
+ if (this.state != other.state || this.stack.length != other.stack.length) return false;
2212
+ for (let i = 0; i < this.stack.length; i += 3) if (this.stack[i] != other.stack[i]) return false;
2213
+ return true;
2214
+ }
2215
+ /**
2216
+ Get the parser used by this stack.
2217
+ */
2218
+ get parser() {
2219
+ return this.p.parser;
2220
+ }
2221
+ /**
2222
+ Test whether a given dialect (by numeric ID, as exported from
2223
+ the terms file) is enabled.
2224
+ */
2225
+ dialectEnabled(dialectID) {
2226
+ return this.p.parser.dialect.flags[dialectID];
2227
+ }
2228
+ shiftContext(term, start) {
2229
+ if (this.curContext) this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
2230
+ }
2231
+ reduceContext(term, start) {
2232
+ if (this.curContext) this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
2233
+ }
2234
+ /**
2235
+ @internal
2236
+ */
2237
+ emitContext() {
2238
+ let last = this.buffer.length - 1;
2239
+ if (last < 0 || this.buffer[last] != -3) this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
2240
+ }
2241
+ /**
2242
+ @internal
2243
+ */
2244
+ emitLookAhead() {
2245
+ let last = this.buffer.length - 1;
2246
+ if (last < 0 || this.buffer[last] != -4) this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
2247
+ }
2248
+ updateContext(context) {
2249
+ if (context != this.curContext.context) {
2250
+ let newCx = new StackContext(this.curContext.tracker, context);
2251
+ if (newCx.hash != this.curContext.hash) this.emitContext();
2252
+ this.curContext = newCx;
2253
+ }
2254
+ }
2255
+ /**
2256
+ @internal
2257
+ */
2258
+ setLookAhead(lookAhead) {
2259
+ if (lookAhead <= this.lookAhead) return false;
2260
+ this.emitLookAhead();
2261
+ this.lookAhead = lookAhead;
2262
+ return true;
2263
+ }
2264
+ /**
2265
+ @internal
2266
+ */
2267
+ close() {
2268
+ if (this.curContext && this.curContext.tracker.strict) this.emitContext();
2269
+ if (this.lookAhead > 0) this.emitLookAhead();
2270
+ }
2271
+ };
2272
+ var StackContext = class {
2273
+ constructor(tracker, context) {
2274
+ this.tracker = tracker;
2275
+ this.context = context;
2276
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
2277
+ }
2278
+ };
2279
+ var SimulatedStack = class {
2280
+ constructor(start) {
2281
+ this.start = start;
2282
+ this.state = start.state;
2283
+ this.stack = start.stack;
2284
+ this.base = this.stack.length;
2285
+ }
2286
+ reduce(action) {
2287
+ let term = action & 65535, depth = action >> 19;
2288
+ if (depth == 0) {
2289
+ if (this.stack == this.start.stack) this.stack = this.stack.slice();
2290
+ this.stack.push(this.state, 0, 0);
2291
+ this.base += 3;
2292
+ } else this.base -= (depth - 1) * 3;
2293
+ this.state = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
2294
+ }
2295
+ };
2296
+ var StackBufferCursor = class StackBufferCursor {
2297
+ constructor(stack, pos, index) {
2298
+ this.stack = stack;
2299
+ this.pos = pos;
2300
+ this.index = index;
2301
+ this.buffer = stack.buffer;
2302
+ if (this.index == 0) this.maybeNext();
2303
+ }
2304
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
2305
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
2306
+ }
2307
+ maybeNext() {
2308
+ let next = this.stack.parent;
2309
+ if (next != null) {
2310
+ this.index = this.stack.bufferBase - next.bufferBase;
2311
+ this.stack = next;
2312
+ this.buffer = next.buffer;
2313
+ }
2314
+ }
2315
+ get id() {
2316
+ return this.buffer[this.index - 4];
2317
+ }
2318
+ get start() {
2319
+ return this.buffer[this.index - 3];
2320
+ }
2321
+ get end() {
2322
+ return this.buffer[this.index - 2];
2323
+ }
2324
+ get size() {
2325
+ return this.buffer[this.index - 1];
2326
+ }
2327
+ next() {
2328
+ this.index -= 4;
2329
+ this.pos -= 4;
2330
+ if (this.index == 0) this.maybeNext();
2331
+ }
2332
+ fork() {
2333
+ return new StackBufferCursor(this.stack, this.pos, this.index);
2334
+ }
2335
+ };
2336
+ function decodeArray(input, Type = Uint16Array) {
2337
+ if (typeof input != "string") return input;
2338
+ let array = null;
2339
+ for (let pos = 0, out = 0; pos < input.length;) {
2340
+ let value = 0;
2341
+ for (;;) {
2342
+ let next = input.charCodeAt(pos++), stop = false;
2343
+ if (next == 126) {
2344
+ value = 65535;
2345
+ break;
2346
+ }
2347
+ if (next >= 92) next--;
2348
+ if (next >= 34) next--;
2349
+ let digit = next - 32;
2350
+ if (digit >= 46) {
2351
+ digit -= 46;
2352
+ stop = true;
2353
+ }
2354
+ value += digit;
2355
+ if (stop) break;
2356
+ value *= 46;
2357
+ }
2358
+ if (array) array[out++] = value;
2359
+ else array = new Type(value);
2360
+ }
2361
+ return array;
2362
+ }
2363
+ var CachedToken = class {
2364
+ constructor() {
2365
+ this.start = -1;
2366
+ this.value = -1;
2367
+ this.end = -1;
2368
+ this.extended = -1;
2369
+ this.lookAhead = 0;
2370
+ this.mask = 0;
2371
+ this.context = 0;
2372
+ }
2373
+ };
2374
+ const nullToken = new CachedToken();
2375
+ /**
2376
+ [Tokenizers](#lr.ExternalTokenizer) interact with the input
2377
+ through this interface. It presents the input as a stream of
2378
+ characters, tracking lookahead and hiding the complexity of
2379
+ [ranges](#common.Parser.parse^ranges) from tokenizer code.
2380
+ */
2381
+ var InputStream = class {
2382
+ /**
2383
+ @internal
2384
+ */
2385
+ constructor(input, ranges) {
2386
+ this.input = input;
2387
+ this.ranges = ranges;
2388
+ /**
2389
+ @internal
2390
+ */
2391
+ this.chunk = "";
2392
+ /**
2393
+ @internal
2394
+ */
2395
+ this.chunkOff = 0;
2396
+ /**
2397
+ Backup chunk
2398
+ */
2399
+ this.chunk2 = "";
2400
+ this.chunk2Pos = 0;
2401
+ /**
2402
+ The character code of the next code unit in the input, or -1
2403
+ when the stream is at the end of the input.
2404
+ */
2405
+ this.next = -1;
2406
+ /**
2407
+ @internal
2408
+ */
2409
+ this.token = nullToken;
2410
+ this.rangeIndex = 0;
2411
+ this.pos = this.chunkPos = ranges[0].from;
2412
+ this.range = ranges[0];
2413
+ this.end = ranges[ranges.length - 1].to;
2414
+ this.readNext();
2415
+ }
2416
+ /**
2417
+ @internal
2418
+ */
2419
+ resolveOffset(offset, assoc) {
2420
+ let range = this.range, index = this.rangeIndex;
2421
+ let pos = this.pos + offset;
2422
+ while (pos < range.from) {
2423
+ if (!index) return null;
2424
+ let next = this.ranges[--index];
2425
+ pos -= range.from - next.to;
2426
+ range = next;
2427
+ }
2428
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
2429
+ if (index == this.ranges.length - 1) return null;
2430
+ let next = this.ranges[++index];
2431
+ pos += next.from - range.to;
2432
+ range = next;
2433
+ }
2434
+ return pos;
2435
+ }
2436
+ /**
2437
+ @internal
2438
+ */
2439
+ clipPos(pos) {
2440
+ if (pos >= this.range.from && pos < this.range.to) return pos;
2441
+ for (let range of this.ranges) if (range.to > pos) return Math.max(pos, range.from);
2442
+ return this.end;
2443
+ }
2444
+ /**
2445
+ Look at a code unit near the stream position. `.peek(0)` equals
2446
+ `.next`, `.peek(-1)` gives you the previous character, and so
2447
+ on.
2448
+
2449
+ Note that looking around during tokenizing creates dependencies
2450
+ on potentially far-away content, which may reduce the
2451
+ effectiveness incremental parsing—when looking forward—or even
2452
+ cause invalid reparses when looking backward more than 25 code
2453
+ units, since the library does not track lookbehind.
2454
+ */
2455
+ peek(offset) {
2456
+ let idx = this.chunkOff + offset, pos, result;
2457
+ if (idx >= 0 && idx < this.chunk.length) {
2458
+ pos = this.pos + offset;
2459
+ result = this.chunk.charCodeAt(idx);
2460
+ } else {
2461
+ let resolved = this.resolveOffset(offset, 1);
2462
+ if (resolved == null) return -1;
2463
+ pos = resolved;
2464
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
2465
+ else {
2466
+ let i = this.rangeIndex, range = this.range;
2467
+ while (range.to <= pos) range = this.ranges[++i];
2468
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
2469
+ if (pos + this.chunk2.length > range.to) this.chunk2 = this.chunk2.slice(0, range.to - pos);
2470
+ result = this.chunk2.charCodeAt(0);
2471
+ }
2472
+ }
2473
+ if (pos >= this.token.lookAhead) this.token.lookAhead = pos + 1;
2474
+ return result;
2475
+ }
2476
+ /**
2477
+ Accept a token. By default, the end of the token is set to the
2478
+ current stream position, but you can pass an offset (relative to
2479
+ the stream position) to change that.
2480
+ */
2481
+ acceptToken(token, endOffset = 0) {
2482
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2483
+ if (end == null || end < this.token.start) throw new RangeError("Token end out of bounds");
2484
+ this.token.value = token;
2485
+ this.token.end = end;
2486
+ }
2487
+ /**
2488
+ Accept a token ending at a specific given position.
2489
+ */
2490
+ acceptTokenTo(token, endPos) {
2491
+ this.token.value = token;
2492
+ this.token.end = endPos;
2493
+ }
2494
+ getChunk() {
2495
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2496
+ let { chunk, chunkPos } = this;
2497
+ this.chunk = this.chunk2;
2498
+ this.chunkPos = this.chunk2Pos;
2499
+ this.chunk2 = chunk;
2500
+ this.chunk2Pos = chunkPos;
2501
+ this.chunkOff = this.pos - this.chunkPos;
2502
+ } else {
2503
+ this.chunk2 = this.chunk;
2504
+ this.chunk2Pos = this.chunkPos;
2505
+ let nextChunk = this.input.chunk(this.pos);
2506
+ this.chunk = this.pos + nextChunk.length > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2507
+ this.chunkPos = this.pos;
2508
+ this.chunkOff = 0;
2509
+ }
2510
+ }
2511
+ readNext() {
2512
+ if (this.chunkOff >= this.chunk.length) {
2513
+ this.getChunk();
2514
+ if (this.chunkOff == this.chunk.length) return this.next = -1;
2515
+ }
2516
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
2517
+ }
2518
+ /**
2519
+ Move the stream forward N (defaults to 1) code units. Returns
2520
+ the new value of [`next`](#lr.InputStream.next).
2521
+ */
2522
+ advance(n = 1) {
2523
+ this.chunkOff += n;
2524
+ while (this.pos + n >= this.range.to) {
2525
+ if (this.rangeIndex == this.ranges.length - 1) return this.setDone();
2526
+ n -= this.range.to - this.pos;
2527
+ this.range = this.ranges[++this.rangeIndex];
2528
+ this.pos = this.range.from;
2529
+ }
2530
+ this.pos += n;
2531
+ if (this.pos >= this.token.lookAhead) this.token.lookAhead = this.pos + 1;
2532
+ return this.readNext();
2533
+ }
2534
+ setDone() {
2535
+ this.pos = this.chunkPos = this.end;
2536
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2537
+ this.chunk = "";
2538
+ return this.next = -1;
2539
+ }
2540
+ /**
2541
+ @internal
2542
+ */
2543
+ reset(pos, token) {
2544
+ if (token) {
2545
+ this.token = token;
2546
+ token.start = pos;
2547
+ token.lookAhead = pos + 1;
2548
+ token.value = token.extended = -1;
2549
+ } else this.token = nullToken;
2550
+ if (this.pos != pos) {
2551
+ this.pos = pos;
2552
+ if (pos == this.end) {
2553
+ this.setDone();
2554
+ return this;
2555
+ }
2556
+ while (pos < this.range.from) this.range = this.ranges[--this.rangeIndex];
2557
+ while (pos >= this.range.to) this.range = this.ranges[++this.rangeIndex];
2558
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) this.chunkOff = pos - this.chunkPos;
2559
+ else {
2560
+ this.chunk = "";
2561
+ this.chunkOff = 0;
2562
+ }
2563
+ this.readNext();
2564
+ }
2565
+ return this;
2566
+ }
2567
+ /**
2568
+ @internal
2569
+ */
2570
+ read(from, to) {
2571
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length) return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
2572
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length) return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
2573
+ if (from >= this.range.from && to <= this.range.to) return this.input.read(from, to);
2574
+ let result = "";
2575
+ for (let r of this.ranges) {
2576
+ if (r.from >= to) break;
2577
+ if (r.to > from) result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
2578
+ }
2579
+ return result;
2580
+ }
2581
+ };
2582
+ /**
2583
+ @internal
2584
+ */
2585
+ var TokenGroup = class {
2586
+ constructor(data, id) {
2587
+ this.data = data;
2588
+ this.id = id;
2589
+ }
2590
+ token(input, stack) {
2591
+ let { parser } = stack.p;
2592
+ readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable);
2593
+ }
2594
+ };
2595
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2596
+ /**
2597
+ @hide
2598
+ */
2599
+ var LocalTokenGroup = class {
2600
+ constructor(data, precTable, elseToken) {
2601
+ this.precTable = precTable;
2602
+ this.elseToken = elseToken;
2603
+ this.data = typeof data == "string" ? decodeArray(data) : data;
2604
+ }
2605
+ token(input, stack) {
2606
+ let start = input.pos, skipped = 0;
2607
+ for (;;) {
2608
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
2609
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
2610
+ if (input.token.value > -1) break;
2611
+ if (this.elseToken == null) return;
2612
+ if (!atEof) skipped++;
2613
+ if (nextPos == null) break;
2614
+ input.reset(nextPos, input.token);
2615
+ }
2616
+ if (skipped) {
2617
+ input.reset(start, input.token);
2618
+ input.acceptToken(this.elseToken, skipped);
2619
+ }
2620
+ }
2621
+ };
2622
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2623
+ /**
2624
+ `@external tokens` declarations in the grammar should resolve to
2625
+ an instance of this class.
2626
+ */
2627
+ var ExternalTokenizer = class {
2628
+ /**
2629
+ Create a tokenizer. The first argument is the function that,
2630
+ given an input stream, scans for the types of tokens it
2631
+ recognizes at the stream's position, and calls
2632
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
2633
+ one.
2634
+ */
2635
+ constructor(token, options = {}) {
2636
+ this.token = token;
2637
+ this.contextual = !!options.contextual;
2638
+ this.fallback = !!options.fallback;
2639
+ this.extend = !!options.extend;
2640
+ }
2641
+ };
2642
+ function readToken(data, input, stack, group, precTable, precOffset) {
2643
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
2644
+ scan: for (;;) {
2645
+ if ((groupMask & data[state]) == 0) break;
2646
+ let accEnd = data[state + 1];
2647
+ for (let i = state + 3; i < accEnd; i += 2) if ((data[i + 1] & groupMask) > 0) {
2648
+ let term = data[i];
2649
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
2650
+ input.acceptToken(term);
2651
+ break;
2652
+ }
2653
+ }
2654
+ let next = input.next, low = 0, high = data[state + 2];
2655
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
2656
+ state = data[accEnd + high * 3 - 1];
2657
+ continue scan;
2658
+ }
2659
+ for (; low < high;) {
2660
+ let mid = low + high >> 1;
2661
+ let index = accEnd + mid + (mid << 1);
2662
+ let from = data[index], to = data[index + 1] || 65536;
2663
+ if (next < from) high = mid;
2664
+ else if (next >= to) low = mid + 1;
2665
+ else {
2666
+ state = data[index + 2];
2667
+ input.advance();
2668
+ continue scan;
2669
+ }
2670
+ }
2671
+ break;
2672
+ }
2673
+ }
2674
+ function findOffset(data, start, term) {
2675
+ for (let i = start, next; (next = data[i]) != 65535; i++) if (next == term) return i - start;
2676
+ return -1;
2677
+ }
2678
+ function overrides(token, prev, tableData, tableOffset) {
2679
+ let iPrev = findOffset(tableData, tableOffset, prev);
2680
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
2681
+ }
2682
+ const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
2683
+ let stackIDs = null;
2684
+ function cutAt(tree, pos, side) {
2685
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
2686
+ cursor.moveTo(pos);
2687
+ for (;;) if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos))) for (;;) {
2688
+ 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));
2689
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling()) break;
2690
+ if (!cursor.parent()) return side < 0 ? 0 : tree.length;
2691
+ }
2692
+ }
2693
+ var FragmentCursor = class {
2694
+ constructor(fragments, nodeSet) {
2695
+ this.fragments = fragments;
2696
+ this.nodeSet = nodeSet;
2697
+ this.i = 0;
2698
+ this.fragment = null;
2699
+ this.safeFrom = -1;
2700
+ this.safeTo = -1;
2701
+ this.trees = [];
2702
+ this.start = [];
2703
+ this.index = [];
2704
+ this.nextFragment();
2705
+ }
2706
+ nextFragment() {
2707
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
2708
+ if (fr) {
2709
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
2710
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
2711
+ while (this.trees.length) {
2712
+ this.trees.pop();
2713
+ this.start.pop();
2714
+ this.index.pop();
2715
+ }
2716
+ this.trees.push(fr.tree);
2717
+ this.start.push(-fr.offset);
2718
+ this.index.push(0);
2719
+ this.nextStart = this.safeFrom;
2720
+ } else this.nextStart = 1e9;
2721
+ }
2722
+ nodeAt(pos) {
2723
+ if (pos < this.nextStart) return null;
2724
+ while (this.fragment && this.safeTo <= pos) this.nextFragment();
2725
+ if (!this.fragment) return null;
2726
+ for (;;) {
2727
+ let last = this.trees.length - 1;
2728
+ if (last < 0) {
2729
+ this.nextFragment();
2730
+ return null;
2731
+ }
2732
+ let top = this.trees[last], index = this.index[last];
2733
+ if (index == top.children.length) {
2734
+ this.trees.pop();
2735
+ this.start.pop();
2736
+ this.index.pop();
2737
+ continue;
2738
+ }
2739
+ let next = top.children[index];
2740
+ let start = this.start[last] + top.positions[index];
2741
+ if (start > pos) {
2742
+ this.nextStart = start;
2743
+ return null;
2744
+ }
2745
+ if (next instanceof Tree) {
2746
+ if (start == pos) {
2747
+ if (start < this.safeFrom) return null;
2748
+ let end = start + next.length;
2749
+ if (end <= this.safeTo) {
2750
+ let lookAhead = next.prop(NodeProp.lookAhead);
2751
+ if (!lookAhead || end + lookAhead < this.fragment.to) return next;
2752
+ }
2753
+ }
2754
+ this.index[last]++;
2755
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
2756
+ this.trees.push(next);
2757
+ this.start.push(start);
2758
+ this.index.push(0);
2759
+ }
2760
+ } else {
2761
+ this.index[last]++;
2762
+ this.nextStart = start + next.length;
2763
+ }
2764
+ }
2765
+ }
2766
+ };
2767
+ var TokenCache = class {
2768
+ constructor(parser, stream) {
2769
+ this.stream = stream;
2770
+ this.tokens = [];
2771
+ this.mainToken = null;
2772
+ this.actions = [];
2773
+ this.tokens = parser.tokenizers.map((_) => new CachedToken());
2774
+ }
2775
+ getActions(stack) {
2776
+ let actionIndex = 0;
2777
+ let main = null;
2778
+ let { parser } = stack.p, { tokenizers } = parser;
2779
+ let mask = parser.stateSlot(stack.state, 3);
2780
+ let context = stack.curContext ? stack.curContext.hash : 0;
2781
+ let lookAhead = 0;
2782
+ for (let i = 0; i < tokenizers.length; i++) {
2783
+ if ((1 << i & mask) == 0) continue;
2784
+ let tokenizer = tokenizers[i], token = this.tokens[i];
2785
+ if (main && !tokenizer.fallback) continue;
2786
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
2787
+ this.updateCachedToken(token, tokenizer, stack);
2788
+ token.mask = mask;
2789
+ token.context = context;
2790
+ }
2791
+ if (token.lookAhead > token.end + 25) lookAhead = Math.max(token.lookAhead, lookAhead);
2792
+ if (token.value != 0) {
2793
+ let startIndex = actionIndex;
2794
+ if (token.extended > -1) actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
2795
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
2796
+ if (!tokenizer.extend) {
2797
+ main = token;
2798
+ if (actionIndex > startIndex) break;
2799
+ }
2800
+ }
2801
+ }
2802
+ while (this.actions.length > actionIndex) this.actions.pop();
2803
+ if (lookAhead) stack.setLookAhead(lookAhead);
2804
+ if (!main && stack.pos == this.stream.end) {
2805
+ main = new CachedToken();
2806
+ main.value = stack.p.parser.eofTerm;
2807
+ main.start = main.end = stack.pos;
2808
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
2809
+ }
2810
+ this.mainToken = main;
2811
+ return this.actions;
2812
+ }
2813
+ getMainToken(stack) {
2814
+ if (this.mainToken) return this.mainToken;
2815
+ let main = new CachedToken(), { pos, p } = stack;
2816
+ main.start = pos;
2817
+ main.end = Math.min(pos + 1, p.stream.end);
2818
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
2819
+ return main;
2820
+ }
2821
+ updateCachedToken(token, tokenizer, stack) {
2822
+ let start = this.stream.clipPos(stack.pos);
2823
+ tokenizer.token(this.stream.reset(start, token), stack);
2824
+ if (token.value > -1) {
2825
+ let { parser } = stack.p;
2826
+ for (let i = 0; i < parser.specialized.length; i++) if (parser.specialized[i] == token.value) {
2827
+ let result = parser.specializers[i](this.stream.read(token.start, token.end), stack);
2828
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
2829
+ if ((result & 1) == 0) token.value = result >> 1;
2830
+ else token.extended = result >> 1;
2831
+ break;
2832
+ }
2833
+ }
2834
+ } else {
2835
+ token.value = 0;
2836
+ token.end = this.stream.clipPos(start + 1);
2837
+ }
2838
+ }
2839
+ putAction(action, token, end, index) {
2840
+ for (let i = 0; i < index; i += 3) if (this.actions[i] == action) return index;
2841
+ this.actions[index++] = action;
2842
+ this.actions[index++] = token;
2843
+ this.actions[index++] = end;
2844
+ return index;
2845
+ }
2846
+ addActions(stack, token, end, index) {
2847
+ let { state } = stack, { parser } = stack.p, { data } = parser;
2848
+ for (let set = 0; set < 2; set++) for (let i = parser.stateSlot(state, set ? 2 : 1);; i += 3) {
2849
+ if (data[i] == 65535) if (data[i + 1] == 1) i = pair(data, i + 2);
2850
+ else {
2851
+ if (index == 0 && data[i + 1] == 2) index = this.putAction(pair(data, i + 2), token, end, index);
2852
+ break;
2853
+ }
2854
+ if (data[i] == token) index = this.putAction(pair(data, i + 1), token, end, index);
2855
+ }
2856
+ return index;
2857
+ }
2858
+ };
2859
+ var Parse = class {
2860
+ constructor(parser, input, fragments, ranges) {
2861
+ this.parser = parser;
2862
+ this.input = input;
2863
+ this.ranges = ranges;
2864
+ this.recovering = 0;
2865
+ this.nextStackID = 9812;
2866
+ this.minStackPos = 0;
2867
+ this.reused = [];
2868
+ this.stoppedAt = null;
2869
+ this.lastBigReductionStart = -1;
2870
+ this.lastBigReductionSize = 0;
2871
+ this.bigReductionCount = 0;
2872
+ this.stream = new InputStream(input, ranges);
2873
+ this.tokens = new TokenCache(parser, this.stream);
2874
+ this.topTerm = parser.top[1];
2875
+ let { from } = ranges[0];
2876
+ this.stacks = [Stack.start(this, parser.top[0], from)];
2877
+ this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 ? new FragmentCursor(fragments, parser.nodeSet) : null;
2878
+ }
2879
+ get parsedPos() {
2880
+ return this.minStackPos;
2881
+ }
2882
+ advance() {
2883
+ let stacks = this.stacks, pos = this.minStackPos;
2884
+ let newStacks = this.stacks = [];
2885
+ let stopped, stoppedTokens;
2886
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
2887
+ let [s] = stacks;
2888
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart);
2889
+ this.bigReductionCount = this.lastBigReductionSize = 0;
2890
+ }
2891
+ for (let i = 0; i < stacks.length; i++) {
2892
+ let stack = stacks[i];
2893
+ for (;;) {
2894
+ this.tokens.mainToken = null;
2895
+ if (stack.pos > pos) newStacks.push(stack);
2896
+ else if (this.advanceStack(stack, newStacks, stacks)) continue;
2897
+ else {
2898
+ if (!stopped) {
2899
+ stopped = [];
2900
+ stoppedTokens = [];
2901
+ }
2902
+ stopped.push(stack);
2903
+ let tok = this.tokens.getMainToken(stack);
2904
+ stoppedTokens.push(tok.value, tok.end);
2905
+ }
2906
+ break;
2907
+ }
2908
+ }
2909
+ if (!newStacks.length) {
2910
+ let finished = stopped && findFinished(stopped);
2911
+ if (finished) {
2912
+ if (verbose) console.log("Finish with " + this.stackID(finished));
2913
+ return this.stackToTree(finished);
2914
+ }
2915
+ if (this.parser.strict) {
2916
+ if (verbose && stopped) console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
2917
+ throw new SyntaxError("No parse at " + pos);
2918
+ }
2919
+ if (!this.recovering) this.recovering = 5;
2920
+ }
2921
+ if (this.recovering && stopped) {
2922
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
2923
+ if (finished) {
2924
+ if (verbose) console.log("Force-finish " + this.stackID(finished));
2925
+ return this.stackToTree(finished.forceAll());
2926
+ }
2927
+ }
2928
+ if (this.recovering) {
2929
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
2930
+ if (newStacks.length > maxRemaining) {
2931
+ newStacks.sort((a, b) => b.score - a.score);
2932
+ while (newStacks.length > maxRemaining) newStacks.pop();
2933
+ }
2934
+ if (newStacks.some((s) => s.reducePos > pos)) this.recovering--;
2935
+ } else if (newStacks.length > 1) {
2936
+ outer: for (let i = 0; i < newStacks.length - 1; i++) {
2937
+ let stack = newStacks[i];
2938
+ for (let j = i + 1; j < newStacks.length; j++) {
2939
+ let other = newStacks[j];
2940
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) newStacks.splice(j--, 1);
2941
+ else {
2942
+ newStacks.splice(i--, 1);
2943
+ continue outer;
2944
+ }
2945
+ }
2946
+ }
2947
+ if (newStacks.length > 12) {
2948
+ newStacks.sort((a, b) => b.score - a.score);
2949
+ newStacks.splice(12, newStacks.length - 12);
2950
+ }
2951
+ }
2952
+ this.minStackPos = newStacks[0].pos;
2953
+ for (let i = 1; i < newStacks.length; i++) if (newStacks[i].pos < this.minStackPos) this.minStackPos = newStacks[i].pos;
2954
+ return null;
2955
+ }
2956
+ stopAt(pos) {
2957
+ if (this.stoppedAt != null && this.stoppedAt < pos) throw new RangeError("Can't move stoppedAt forward");
2958
+ this.stoppedAt = pos;
2959
+ }
2960
+ advanceStack(stack, stacks, split) {
2961
+ let start = stack.pos, { parser } = this;
2962
+ let base = verbose ? this.stackID(stack) + " -> " : "";
2963
+ if (this.stoppedAt != null && start > this.stoppedAt) return stack.forceReduce() ? stack : null;
2964
+ if (this.fragments) {
2965
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
2966
+ for (let cached = this.fragments.nodeAt(start); cached;) {
2967
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
2968
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
2969
+ stack.useNode(cached, match);
2970
+ if (verbose) console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
2971
+ return true;
2972
+ }
2973
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0) break;
2974
+ let inner = cached.children[0];
2975
+ if (inner instanceof Tree && cached.positions[0] == 0) cached = inner;
2976
+ else break;
2977
+ }
2978
+ }
2979
+ let defaultReduce = parser.stateSlot(stack.state, 4);
2980
+ if (defaultReduce > 0) {
2981
+ stack.reduce(defaultReduce);
2982
+ if (verbose) console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535)})`);
2983
+ return true;
2984
+ }
2985
+ if (stack.stack.length >= 8400) while (stack.stack.length > 6e3 && stack.forceReduce());
2986
+ let actions = this.tokens.getActions(stack);
2987
+ for (let i = 0; i < actions.length;) {
2988
+ let action = actions[i++], term = actions[i++], end = actions[i++];
2989
+ let last = i == actions.length || !split;
2990
+ let localStack = last ? stack : stack.split();
2991
+ let main = this.tokens.mainToken;
2992
+ localStack.apply(action, term, main ? main.start : localStack.pos, end);
2993
+ if (verbose) console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser.getName(action & 65535)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
2994
+ if (last) return true;
2995
+ else if (localStack.pos > start) stacks.push(localStack);
2996
+ else split.push(localStack);
2997
+ }
2998
+ return false;
2999
+ }
3000
+ advanceFully(stack, newStacks) {
3001
+ let pos = stack.pos;
3002
+ for (;;) {
3003
+ if (!this.advanceStack(stack, null, null)) return false;
3004
+ if (stack.pos > pos) {
3005
+ pushStackDedup(stack, newStacks);
3006
+ return true;
3007
+ }
3008
+ }
3009
+ }
3010
+ runRecovery(stacks, tokens, newStacks) {
3011
+ let finished = null, restarted = false;
3012
+ for (let i = 0; i < stacks.length; i++) {
3013
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
3014
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3015
+ if (stack.deadEnd) {
3016
+ if (restarted) continue;
3017
+ restarted = true;
3018
+ stack.restart();
3019
+ if (verbose) console.log(base + this.stackID(stack) + " (restarted)");
3020
+ if (this.advanceFully(stack, newStacks)) continue;
3021
+ }
3022
+ let force = stack.split(), forceBase = base;
3023
+ for (let j = 0; j < 10 && force.forceReduce(); j++) {
3024
+ if (verbose) console.log(forceBase + this.stackID(force) + " (via force-reduce)");
3025
+ if (this.advanceFully(force, newStacks)) break;
3026
+ if (verbose) forceBase = this.stackID(force) + " -> ";
3027
+ }
3028
+ for (let insert of stack.recoverByInsert(token)) {
3029
+ if (verbose) console.log(base + this.stackID(insert) + " (via recover-insert)");
3030
+ this.advanceFully(insert, newStacks);
3031
+ }
3032
+ if (this.stream.end > stack.pos) {
3033
+ if (tokenEnd == stack.pos) {
3034
+ tokenEnd++;
3035
+ token = 0;
3036
+ }
3037
+ stack.recoverByDelete(token, tokenEnd);
3038
+ if (verbose) console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
3039
+ pushStackDedup(stack, newStacks);
3040
+ } else if (!finished || finished.score < force.score) finished = force;
3041
+ }
3042
+ return finished;
3043
+ }
3044
+ stackToTree(stack) {
3045
+ stack.close();
3046
+ return Tree.build({
3047
+ buffer: StackBufferCursor.create(stack),
3048
+ nodeSet: this.parser.nodeSet,
3049
+ topID: this.topTerm,
3050
+ maxBufferLength: this.parser.bufferLength,
3051
+ reused: this.reused,
3052
+ start: this.ranges[0].from,
3053
+ length: stack.pos - this.ranges[0].from,
3054
+ minRepeatType: this.parser.minRepeatTerm
3055
+ });
3056
+ }
3057
+ stackID(stack) {
3058
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
3059
+ if (!id) stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
3060
+ return id + stack;
3061
+ }
3062
+ };
3063
+ function pushStackDedup(stack, newStacks) {
3064
+ for (let i = 0; i < newStacks.length; i++) {
3065
+ let other = newStacks[i];
3066
+ if (other.pos == stack.pos && other.sameState(stack)) {
3067
+ if (newStacks[i].score < stack.score) newStacks[i] = stack;
3068
+ return;
3069
+ }
3070
+ }
3071
+ newStacks.push(stack);
3072
+ }
3073
+ var Dialect = class {
3074
+ constructor(source, flags, disabled) {
3075
+ this.source = source;
3076
+ this.flags = flags;
3077
+ this.disabled = disabled;
3078
+ }
3079
+ allows(term) {
3080
+ return !this.disabled || this.disabled[term] == 0;
3081
+ }
3082
+ };
3083
+ const id = (x) => x;
3084
+ /**
3085
+ Context trackers are used to track stateful context (such as
3086
+ indentation in the Python grammar, or parent elements in the XML
3087
+ grammar) needed by external tokenizers. You declare them in a
3088
+ grammar file as `@context exportName from "module"`.
3089
+
3090
+ Context values should be immutable, and can be updated (replaced)
3091
+ on shift or reduce actions.
3092
+
3093
+ The export used in a `@context` declaration should be of this
3094
+ type.
3095
+ */
3096
+ var ContextTracker = class {
3097
+ /**
3098
+ Define a context tracker.
3099
+ */
3100
+ constructor(spec) {
3101
+ this.start = spec.start;
3102
+ this.shift = spec.shift || id;
3103
+ this.reduce = spec.reduce || id;
3104
+ this.reuse = spec.reuse || id;
3105
+ this.hash = spec.hash || (() => 0);
3106
+ this.strict = spec.strict !== false;
3107
+ }
3108
+ };
3109
+ /**
3110
+ Holds the parse tables for a given grammar, as generated by
3111
+ `lezer-generator`, and provides [methods](#common.Parser) to parse
3112
+ content with.
3113
+ */
3114
+ var LRParser = class LRParser extends Parser {
3115
+ /**
3116
+ @internal
3117
+ */
3118
+ constructor(spec) {
3119
+ super();
3120
+ /**
3121
+ @internal
3122
+ */
3123
+ this.wrappers = [];
3124
+ if (spec.version != 14) throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (14)`);
3125
+ let nodeNames = spec.nodeNames.split(" ");
3126
+ this.minRepeatTerm = nodeNames.length;
3127
+ for (let i = 0; i < spec.repeatNodeCount; i++) nodeNames.push("");
3128
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
3129
+ let nodeProps = [];
3130
+ for (let i = 0; i < nodeNames.length; i++) nodeProps.push([]);
3131
+ function setProp(nodeID, prop, value) {
3132
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
3133
+ }
3134
+ if (spec.nodeProps) for (let propSpec of spec.nodeProps) {
3135
+ let prop = propSpec[0];
3136
+ if (typeof prop == "string") prop = NodeProp[prop];
3137
+ for (let i = 1; i < propSpec.length;) {
3138
+ let next = propSpec[i++];
3139
+ if (next >= 0) setProp(next, prop, propSpec[i++]);
3140
+ else {
3141
+ let value = propSpec[i + -next];
3142
+ for (let j = -next; j > 0; j--) setProp(propSpec[i++], prop, value);
3143
+ i++;
3144
+ }
3145
+ }
3146
+ }
3147
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
3148
+ name: i >= this.minRepeatTerm ? void 0 : name,
3149
+ id: i,
3150
+ props: nodeProps[i],
3151
+ top: topTerms.indexOf(i) > -1,
3152
+ error: i == 0,
3153
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
3154
+ })));
3155
+ if (spec.propSources) this.nodeSet = this.nodeSet.extend(...spec.propSources);
3156
+ this.strict = false;
3157
+ this.bufferLength = DefaultBufferLength;
3158
+ let tokenArray = decodeArray(spec.tokenData);
3159
+ this.context = spec.context;
3160
+ this.specializerSpecs = spec.specialized || [];
3161
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
3162
+ for (let i = 0; i < this.specializerSpecs.length; i++) this.specialized[i] = this.specializerSpecs[i].term;
3163
+ this.specializers = this.specializerSpecs.map(getSpecializer);
3164
+ this.states = decodeArray(spec.states, Uint32Array);
3165
+ this.data = decodeArray(spec.stateData);
3166
+ this.goto = decodeArray(spec.goto);
3167
+ this.maxTerm = spec.maxTerm;
3168
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
3169
+ this.topRules = spec.topRules;
3170
+ this.dialects = spec.dialects || {};
3171
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
3172
+ this.tokenPrecTable = spec.tokenPrec;
3173
+ this.termNames = spec.termNames || null;
3174
+ this.maxNode = this.nodeSet.types.length - 1;
3175
+ this.dialect = this.parseDialect();
3176
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
3177
+ }
3178
+ createParse(input, fragments, ranges) {
3179
+ let parse = new Parse(this, input, fragments, ranges);
3180
+ for (let w of this.wrappers) parse = w(parse, input, fragments, ranges);
3181
+ return parse;
3182
+ }
3183
+ /**
3184
+ Get a goto table entry @internal
3185
+ */
3186
+ getGoto(state, term, loose = false) {
3187
+ let table = this.goto;
3188
+ if (term >= table[0]) return -1;
3189
+ for (let pos = table[term + 1];;) {
3190
+ let groupTag = table[pos++], last = groupTag & 1;
3191
+ let target = table[pos++];
3192
+ if (last && loose) return target;
3193
+ for (let end = pos + (groupTag >> 1); pos < end; pos++) if (table[pos] == state) return target;
3194
+ if (last) return -1;
3195
+ }
3196
+ }
3197
+ /**
3198
+ Check if this state has an action for a given terminal @internal
3199
+ */
3200
+ hasAction(state, terminal) {
3201
+ let data = this.data;
3202
+ for (let set = 0; set < 2; set++) for (let i = this.stateSlot(state, set ? 2 : 1), next;; i += 3) {
3203
+ if ((next = data[i]) == 65535) if (data[i + 1] == 1) next = data[i = pair(data, i + 2)];
3204
+ else if (data[i + 1] == 2) return pair(data, i + 2);
3205
+ else break;
3206
+ if (next == terminal || next == 0) return pair(data, i + 1);
3207
+ }
3208
+ return 0;
3209
+ }
3210
+ /**
3211
+ @internal
3212
+ */
3213
+ stateSlot(state, slot) {
3214
+ return this.states[state * 6 + slot];
3215
+ }
3216
+ /**
3217
+ @internal
3218
+ */
3219
+ stateFlag(state, flag) {
3220
+ return (this.stateSlot(state, 0) & flag) > 0;
3221
+ }
3222
+ /**
3223
+ @internal
3224
+ */
3225
+ validAction(state, action) {
3226
+ return !!this.allActions(state, (a) => a == action ? true : null);
3227
+ }
3228
+ /**
3229
+ @internal
3230
+ */
3231
+ allActions(state, action) {
3232
+ let deflt = this.stateSlot(state, 4);
3233
+ let result = deflt ? action(deflt) : void 0;
3234
+ for (let i = this.stateSlot(state, 1); result == null; i += 3) {
3235
+ if (this.data[i] == 65535) if (this.data[i + 1] == 1) i = pair(this.data, i + 2);
3236
+ else break;
3237
+ result = action(pair(this.data, i + 1));
3238
+ }
3239
+ return result;
3240
+ }
3241
+ /**
3242
+ Get the states that can follow this one through shift actions or
3243
+ goto jumps. @internal
3244
+ */
3245
+ nextStates(state) {
3246
+ let result = [];
3247
+ for (let i = this.stateSlot(state, 1);; i += 3) {
3248
+ if (this.data[i] == 65535) if (this.data[i + 1] == 1) i = pair(this.data, i + 2);
3249
+ else break;
3250
+ if ((this.data[i + 2] & 1) == 0) {
3251
+ let value = this.data[i + 1];
3252
+ if (!result.some((v, i) => i & 1 && v == value)) result.push(this.data[i], value);
3253
+ }
3254
+ }
3255
+ return result;
3256
+ }
3257
+ /**
3258
+ Configure the parser. Returns a new parser instance that has the
3259
+ given settings modified. Settings not provided in `config` are
3260
+ kept from the original parser.
3261
+ */
3262
+ configure(config) {
3263
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
3264
+ if (config.props) copy.nodeSet = this.nodeSet.extend(...config.props);
3265
+ if (config.top) {
3266
+ let info = this.topRules[config.top];
3267
+ if (!info) throw new RangeError(`Invalid top rule name ${config.top}`);
3268
+ copy.top = info;
3269
+ }
3270
+ if (config.tokenizers) copy.tokenizers = this.tokenizers.map((t) => {
3271
+ let found = config.tokenizers.find((r) => r.from == t);
3272
+ return found ? found.to : t;
3273
+ });
3274
+ if (config.specializers) {
3275
+ copy.specializers = this.specializers.slice();
3276
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
3277
+ let found = config.specializers.find((r) => r.from == s.external);
3278
+ if (!found) return s;
3279
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
3280
+ copy.specializers[i] = getSpecializer(spec);
3281
+ return spec;
3282
+ });
3283
+ }
3284
+ if (config.contextTracker) copy.context = config.contextTracker;
3285
+ if (config.dialect) copy.dialect = this.parseDialect(config.dialect);
3286
+ if (config.strict != null) copy.strict = config.strict;
3287
+ if (config.wrap) copy.wrappers = copy.wrappers.concat(config.wrap);
3288
+ if (config.bufferLength != null) copy.bufferLength = config.bufferLength;
3289
+ return copy;
3290
+ }
3291
+ /**
3292
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
3293
+ are registered for this parser.
3294
+ */
3295
+ hasWrappers() {
3296
+ return this.wrappers.length > 0;
3297
+ }
3298
+ /**
3299
+ Returns the name associated with a given term. This will only
3300
+ work for all terms when the parser was generated with the
3301
+ `--names` option. By default, only the names of tagged terms are
3302
+ stored.
3303
+ */
3304
+ getName(term) {
3305
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
3306
+ }
3307
+ /**
3308
+ The eof term id is always allocated directly after the node
3309
+ types. @internal
3310
+ */
3311
+ get eofTerm() {
3312
+ return this.maxNode + 1;
3313
+ }
3314
+ /**
3315
+ The type of top node produced by the parser.
3316
+ */
3317
+ get topNode() {
3318
+ return this.nodeSet.types[this.top[1]];
3319
+ }
3320
+ /**
3321
+ @internal
3322
+ */
3323
+ dynamicPrecedence(term) {
3324
+ let prec = this.dynamicPrecedences;
3325
+ return prec == null ? 0 : prec[term] || 0;
3326
+ }
3327
+ /**
3328
+ @internal
3329
+ */
3330
+ parseDialect(dialect) {
3331
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
3332
+ if (dialect) for (let part of dialect.split(" ")) {
3333
+ let id = values.indexOf(part);
3334
+ if (id >= 0) flags[id] = true;
3335
+ }
3336
+ let disabled = null;
3337
+ for (let i = 0; i < values.length; i++) if (!flags[i]) for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535;) (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
3338
+ return new Dialect(dialect, flags, disabled);
3339
+ }
3340
+ /**
3341
+ Used by the output of the parser generator. Not available to
3342
+ user code. @hide
3343
+ */
3344
+ static deserialize(spec) {
3345
+ return new LRParser(spec);
3346
+ }
3347
+ };
3348
+ function pair(data, off) {
3349
+ return data[off] | data[off + 1] << 16;
3350
+ }
3351
+ function findFinished(stacks) {
3352
+ let best = null;
3353
+ for (let stack of stacks) {
3354
+ let stopped = stack.p.stoppedAt;
3355
+ 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;
3356
+ }
3357
+ return best;
3358
+ }
3359
+ function getSpecializer(spec) {
3360
+ if (spec.external) {
3361
+ let mask = spec.extend ? 1 : 0;
3362
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
3363
+ }
3364
+ return spec.get;
3365
+ }
3366
+
3367
+ //#endregion
3368
+ //#region ../../node_modules/.bun/@lezer+highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js
3369
+ let nextTagID = 0;
3370
+ /**
3371
+ Highlighting tags are markers that denote a highlighting category.
3372
+ They are [associated](#highlight.styleTags) with parts of a syntax
3373
+ tree by a language mode, and then mapped to an actual CSS style by
3374
+ a [highlighter](#highlight.Highlighter).
3375
+
3376
+ Because syntax tree node types and highlight styles have to be
3377
+ able to talk the same language, CodeMirror uses a mostly _closed_
3378
+ [vocabulary](#highlight.tags) of syntax tags (as opposed to
3379
+ traditional open string-based systems, which make it hard for
3380
+ highlighting themes to cover all the tokens produced by the
3381
+ various languages).
3382
+
3383
+ It _is_ possible to [define](#highlight.Tag^define) your own
3384
+ highlighting tags for system-internal use (where you control both
3385
+ the language package and the highlighter), but such tags will not
3386
+ be picked up by regular highlighters (though you can derive them
3387
+ from standard tags to allow highlighters to fall back to those).
3388
+ */
3389
+ var Tag = class Tag {
3390
+ /**
3391
+ @internal
3392
+ */
3393
+ constructor(name, set, base, modified) {
3394
+ this.name = name;
3395
+ this.set = set;
3396
+ this.base = base;
3397
+ this.modified = modified;
3398
+ /**
3399
+ @internal
3400
+ */
3401
+ this.id = nextTagID++;
3402
+ }
3403
+ toString() {
3404
+ let { name } = this;
3405
+ for (let mod of this.modified) if (mod.name) name = `${mod.name}(${name})`;
3406
+ return name;
3407
+ }
3408
+ static define(nameOrParent, parent) {
3409
+ let name = typeof nameOrParent == "string" ? nameOrParent : "?";
3410
+ if (nameOrParent instanceof Tag) parent = nameOrParent;
3411
+ if (parent === null || parent === void 0 ? void 0 : parent.base) throw new Error("Can not derive from a modified tag");
3412
+ let tag = new Tag(name, [], null, []);
3413
+ tag.set.push(tag);
3414
+ if (parent) for (let t of parent.set) tag.set.push(t);
3415
+ return tag;
3416
+ }
3417
+ /**
3418
+ Define a tag _modifier_, which is a function that, given a tag,
3419
+ will return a tag that is a subtag of the original. Applying the
3420
+ same modifier to a twice tag will return the same value (`m1(t1)
3421
+ == m1(t1)`) and applying multiple modifiers will, regardless or
3422
+ order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
3423
+
3424
+ When multiple modifiers are applied to a given base tag, each
3425
+ smaller set of modifiers is registered as a parent, so that for
3426
+ example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
3427
+ `m1(m3(t1)`, and so on.
3428
+ */
3429
+ static defineModifier(name) {
3430
+ let mod = new Modifier(name);
3431
+ return (tag) => {
3432
+ if (tag.modified.indexOf(mod) > -1) return tag;
3433
+ return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id));
3434
+ };
3435
+ }
3436
+ };
3437
+ let nextModifierID = 0;
3438
+ var Modifier = class Modifier {
3439
+ constructor(name) {
3440
+ this.name = name;
3441
+ this.instances = [];
3442
+ this.id = nextModifierID++;
3443
+ }
3444
+ static get(base, mods) {
3445
+ if (!mods.length) return base;
3446
+ let exists = mods[0].instances.find((t) => t.base == base && sameArray(mods, t.modified));
3447
+ if (exists) return exists;
3448
+ let set = [], tag = new Tag(base.name, set, base, mods);
3449
+ for (let m of mods) m.instances.push(tag);
3450
+ let configs = powerSet(mods);
3451
+ for (let parent of base.set) if (!parent.modified.length) for (let config of configs) set.push(Modifier.get(parent, config));
3452
+ return tag;
3453
+ }
3454
+ };
3455
+ function sameArray(a, b) {
3456
+ return a.length == b.length && a.every((x, i) => x == b[i]);
3457
+ }
3458
+ function powerSet(array) {
3459
+ let sets = [[]];
3460
+ 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]));
3461
+ return sets.sort((a, b) => b.length - a.length);
3462
+ }
3463
+ /**
3464
+ This function is used to add a set of tags to a language syntax
3465
+ via [`NodeSet.extend`](#common.NodeSet.extend) or
3466
+ [`LRParser.configure`](#lr.LRParser.configure).
3467
+
3468
+ The argument object maps node selectors to [highlighting
3469
+ tags](#highlight.Tag) or arrays of tags.
3470
+
3471
+ Node selectors may hold one or more (space-separated) node paths.
3472
+ Such a path can be a [node name](#common.NodeType.name), or
3473
+ multiple node names (or `*` wildcards) separated by slash
3474
+ characters, as in `"Block/Declaration/VariableName"`. Such a path
3475
+ matches the final node but only if its direct parent nodes are the
3476
+ other nodes mentioned. A `*` in such a path matches any parent,
3477
+ but only a single level—wildcards that match multiple parents
3478
+ aren't supported, both for efficiency reasons and because Lezer
3479
+ trees make it rather hard to reason about what they would match.)
3480
+
3481
+ A path can be ended with `/...` to indicate that the tag assigned
3482
+ to the node should also apply to all child nodes, even if they
3483
+ match their own style (by default, only the innermost style is
3484
+ used).
3485
+
3486
+ When a path ends in `!`, as in `Attribute!`, no further matching
3487
+ happens for the node's child nodes, and the entire node gets the
3488
+ given style.
3489
+
3490
+ In this notation, node names that contain `/`, `!`, `*`, or `...`
3491
+ must be quoted as JSON strings.
3492
+
3493
+ For example:
3494
+
3495
+ ```javascript
3496
+ parser.configure({props: [
3497
+ styleTags({
3498
+ // Style Number and BigNumber nodes
3499
+ "Number BigNumber": tags.number,
3500
+ // Style Escape nodes whose parent is String
3501
+ "String/Escape": tags.escape,
3502
+ // Style anything inside Attributes nodes
3503
+ "Attributes!": tags.meta,
3504
+ // Add a style to all content inside Italic nodes
3505
+ "Italic/...": tags.emphasis,
3506
+ // Style InvalidString nodes as both `string` and `invalid`
3507
+ "InvalidString": [tags.string, tags.invalid],
3508
+ // Style the node named "/" as punctuation
3509
+ '"/"': tags.punctuation
3510
+ })
3511
+ ]})
3512
+ ```
3513
+ */
3514
+ function styleTags(spec) {
3515
+ let byName = Object.create(null);
3516
+ for (let prop in spec) {
3517
+ let tags = spec[prop];
3518
+ if (!Array.isArray(tags)) tags = [tags];
3519
+ for (let part of prop.split(" ")) if (part) {
3520
+ let pieces = [], mode = 2, rest = part;
3521
+ for (let pos = 0;;) {
3522
+ if (rest == "..." && pos > 0 && pos + 3 == part.length) {
3523
+ mode = 1;
3524
+ break;
3525
+ }
3526
+ let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
3527
+ if (!m) throw new RangeError("Invalid path: " + part);
3528
+ pieces.push(m[0] == "*" ? "" : m[0][0] == "\"" ? JSON.parse(m[0]) : m[0]);
3529
+ pos += m[0].length;
3530
+ if (pos == part.length) break;
3531
+ let next = part[pos++];
3532
+ if (pos == part.length && next == "!") {
3533
+ mode = 0;
3534
+ break;
3535
+ }
3536
+ if (next != "/") throw new RangeError("Invalid path: " + part);
3537
+ rest = part.slice(pos);
3538
+ }
3539
+ let last = pieces.length - 1, inner = pieces[last];
3540
+ if (!inner) throw new RangeError("Invalid path: " + part);
3541
+ byName[inner] = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null).sort(byName[inner]);
3542
+ }
3543
+ }
3544
+ return ruleNodeProp.add(byName);
3545
+ }
3546
+ const ruleNodeProp = new NodeProp({ combine(a, b) {
3547
+ let cur, root, take;
3548
+ while (a || b) {
3549
+ if (!a || b && a.depth >= b.depth) {
3550
+ take = b;
3551
+ b = b.next;
3552
+ } else {
3553
+ take = a;
3554
+ a = a.next;
3555
+ }
3556
+ if (cur && cur.mode == take.mode && !take.context && !cur.context) continue;
3557
+ let copy = new Rule(take.tags, take.mode, take.context);
3558
+ if (cur) cur.next = copy;
3559
+ else root = copy;
3560
+ cur = copy;
3561
+ }
3562
+ return root;
3563
+ } });
3564
+ var Rule = class {
3565
+ constructor(tags, mode, context, next) {
3566
+ this.tags = tags;
3567
+ this.mode = mode;
3568
+ this.context = context;
3569
+ this.next = next;
3570
+ }
3571
+ get opaque() {
3572
+ return this.mode == 0;
3573
+ }
3574
+ get inherit() {
3575
+ return this.mode == 1;
3576
+ }
3577
+ sort(other) {
3578
+ if (!other || other.depth < this.depth) {
3579
+ this.next = other;
3580
+ return this;
3581
+ }
3582
+ other.next = this.sort(other.next);
3583
+ return other;
3584
+ }
3585
+ get depth() {
3586
+ return this.context ? this.context.length : 0;
3587
+ }
3588
+ };
3589
+ Rule.empty = new Rule([], 2, null);
3590
+ /**
3591
+ Define a [highlighter](#highlight.Highlighter) from an array of
3592
+ tag/class pairs. Classes associated with more specific tags will
3593
+ take precedence.
3594
+ */
3595
+ function tagHighlighter(tags, options) {
3596
+ let map = Object.create(null);
3597
+ for (let style of tags) if (!Array.isArray(style.tag)) map[style.tag.id] = style.class;
3598
+ else for (let tag of style.tag) map[tag.id] = style.class;
3599
+ let { scope, all = null } = options || {};
3600
+ return {
3601
+ style: (tags) => {
3602
+ let cls = all;
3603
+ for (let tag of tags) for (let sub of tag.set) {
3604
+ let tagClass = map[sub.id];
3605
+ if (tagClass) {
3606
+ cls = cls ? cls + " " + tagClass : tagClass;
3607
+ break;
3608
+ }
3609
+ }
3610
+ return cls;
3611
+ },
3612
+ scope
3613
+ };
3614
+ }
3615
+ const t = Tag.define;
3616
+ const comment = t(), name = t(), typeName = t(name), propertyName = t(name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
3617
+ /**
3618
+ The default set of highlighting [tags](#highlight.Tag).
3619
+
3620
+ This collection is heavily biased towards programming languages,
3621
+ and necessarily incomplete. A full ontology of syntactic
3622
+ constructs would fill a stack of books, and be impractical to
3623
+ write themes for. So try to make do with this set. If all else
3624
+ fails, [open an
3625
+ issue](https://github.com/codemirror/codemirror.next) to propose a
3626
+ new tag, or [define](#highlight.Tag^define) a local custom tag for
3627
+ your use case.
3628
+
3629
+ Note that it is not obligatory to always attach the most specific
3630
+ tag possible to an element—if your grammar can't easily
3631
+ distinguish a certain type of element (such as a local variable),
3632
+ it is okay to style it as its more general variant (a variable).
3633
+
3634
+ For tags that extend some parent tag, the documentation links to
3635
+ the parent.
3636
+ */
3637
+ const tags = {
3638
+ comment,
3639
+ lineComment: t(comment),
3640
+ blockComment: t(comment),
3641
+ docComment: t(comment),
3642
+ name,
3643
+ variableName: t(name),
3644
+ typeName,
3645
+ tagName: t(typeName),
3646
+ propertyName,
3647
+ attributeName: t(propertyName),
3648
+ className: t(name),
3649
+ labelName: t(name),
3650
+ namespace: t(name),
3651
+ macroName: t(name),
3652
+ literal,
3653
+ string,
3654
+ docString: t(string),
3655
+ character: t(string),
3656
+ attributeValue: t(string),
3657
+ number,
3658
+ integer: t(number),
3659
+ float: t(number),
3660
+ bool: t(literal),
3661
+ regexp: t(literal),
3662
+ escape: t(literal),
3663
+ color: t(literal),
3664
+ url: t(literal),
3665
+ keyword,
3666
+ self: t(keyword),
3667
+ null: t(keyword),
3668
+ atom: t(keyword),
3669
+ unit: t(keyword),
3670
+ modifier: t(keyword),
3671
+ operatorKeyword: t(keyword),
3672
+ controlKeyword: t(keyword),
3673
+ definitionKeyword: t(keyword),
3674
+ moduleKeyword: t(keyword),
3675
+ operator,
3676
+ derefOperator: t(operator),
3677
+ arithmeticOperator: t(operator),
3678
+ logicOperator: t(operator),
3679
+ bitwiseOperator: t(operator),
3680
+ compareOperator: t(operator),
3681
+ updateOperator: t(operator),
3682
+ definitionOperator: t(operator),
3683
+ typeOperator: t(operator),
3684
+ controlOperator: t(operator),
3685
+ punctuation,
3686
+ separator: t(punctuation),
3687
+ bracket,
3688
+ angleBracket: t(bracket),
3689
+ squareBracket: t(bracket),
3690
+ paren: t(bracket),
3691
+ brace: t(bracket),
3692
+ content,
3693
+ heading,
3694
+ heading1: t(heading),
3695
+ heading2: t(heading),
3696
+ heading3: t(heading),
3697
+ heading4: t(heading),
3698
+ heading5: t(heading),
3699
+ heading6: t(heading),
3700
+ contentSeparator: t(content),
3701
+ list: t(content),
3702
+ quote: t(content),
3703
+ emphasis: t(content),
3704
+ strong: t(content),
3705
+ link: t(content),
3706
+ monospace: t(content),
3707
+ strikethrough: t(content),
3708
+ inserted: t(),
3709
+ deleted: t(),
3710
+ changed: t(),
3711
+ invalid: t(),
3712
+ meta,
3713
+ documentMeta: t(meta),
3714
+ annotation: t(meta),
3715
+ processingInstruction: t(meta),
3716
+ definition: Tag.defineModifier("definition"),
3717
+ constant: Tag.defineModifier("constant"),
3718
+ function: Tag.defineModifier("function"),
3719
+ standard: Tag.defineModifier("standard"),
3720
+ local: Tag.defineModifier("local"),
3721
+ special: Tag.defineModifier("special")
3722
+ };
3723
+ for (let name in tags) {
3724
+ let val = tags[name];
3725
+ if (val instanceof Tag) val.name = name;
3726
+ }
3727
+ /**
3728
+ This is a highlighter that adds stable, predictable classes to
3729
+ tokens, for styling with external CSS.
3730
+
3731
+ The following tags are mapped to their name prefixed with `"tok-"`
3732
+ (for example `"tok-comment"`):
3733
+
3734
+ * [`link`](#highlight.tags.link)
3735
+ * [`heading`](#highlight.tags.heading)
3736
+ * [`emphasis`](#highlight.tags.emphasis)
3737
+ * [`strong`](#highlight.tags.strong)
3738
+ * [`keyword`](#highlight.tags.keyword)
3739
+ * [`atom`](#highlight.tags.atom)
3740
+ * [`bool`](#highlight.tags.bool)
3741
+ * [`url`](#highlight.tags.url)
3742
+ * [`labelName`](#highlight.tags.labelName)
3743
+ * [`inserted`](#highlight.tags.inserted)
3744
+ * [`deleted`](#highlight.tags.deleted)
3745
+ * [`literal`](#highlight.tags.literal)
3746
+ * [`string`](#highlight.tags.string)
3747
+ * [`number`](#highlight.tags.number)
3748
+ * [`variableName`](#highlight.tags.variableName)
3749
+ * [`typeName`](#highlight.tags.typeName)
3750
+ * [`namespace`](#highlight.tags.namespace)
3751
+ * [`className`](#highlight.tags.className)
3752
+ * [`macroName`](#highlight.tags.macroName)
3753
+ * [`propertyName`](#highlight.tags.propertyName)
3754
+ * [`operator`](#highlight.tags.operator)
3755
+ * [`comment`](#highlight.tags.comment)
3756
+ * [`meta`](#highlight.tags.meta)
3757
+ * [`punctuation`](#highlight.tags.punctuation)
3758
+ * [`invalid`](#highlight.tags.invalid)
3759
+
3760
+ In addition, these mappings are provided:
3761
+
3762
+ * [`regexp`](#highlight.tags.regexp),
3763
+ [`escape`](#highlight.tags.escape), and
3764
+ [`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
3765
+ are mapped to `"tok-string2"`
3766
+ * [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
3767
+ to `"tok-variableName2"`
3768
+ * [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
3769
+ to `"tok-variableName tok-local"`
3770
+ * [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
3771
+ to `"tok-variableName tok-definition"`
3772
+ * [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
3773
+ to `"tok-propertyName tok-definition"`
3774
+ */
3775
+ const classHighlighter = tagHighlighter([
3776
+ {
3777
+ tag: tags.link,
3778
+ class: "tok-link"
3779
+ },
3780
+ {
3781
+ tag: tags.heading,
3782
+ class: "tok-heading"
3783
+ },
3784
+ {
3785
+ tag: tags.emphasis,
3786
+ class: "tok-emphasis"
3787
+ },
3788
+ {
3789
+ tag: tags.strong,
3790
+ class: "tok-strong"
3791
+ },
3792
+ {
3793
+ tag: tags.keyword,
3794
+ class: "tok-keyword"
3795
+ },
3796
+ {
3797
+ tag: tags.atom,
3798
+ class: "tok-atom"
3799
+ },
3800
+ {
3801
+ tag: tags.bool,
3802
+ class: "tok-bool"
3803
+ },
3804
+ {
3805
+ tag: tags.url,
3806
+ class: "tok-url"
3807
+ },
3808
+ {
3809
+ tag: tags.labelName,
3810
+ class: "tok-labelName"
3811
+ },
3812
+ {
3813
+ tag: tags.inserted,
3814
+ class: "tok-inserted"
3815
+ },
3816
+ {
3817
+ tag: tags.deleted,
3818
+ class: "tok-deleted"
3819
+ },
3820
+ {
3821
+ tag: tags.literal,
3822
+ class: "tok-literal"
3823
+ },
3824
+ {
3825
+ tag: tags.string,
3826
+ class: "tok-string"
3827
+ },
3828
+ {
3829
+ tag: tags.number,
3830
+ class: "tok-number"
3831
+ },
3832
+ {
3833
+ tag: [
3834
+ tags.regexp,
3835
+ tags.escape,
3836
+ tags.special(tags.string)
3837
+ ],
3838
+ class: "tok-string2"
3839
+ },
3840
+ {
3841
+ tag: tags.variableName,
3842
+ class: "tok-variableName"
3843
+ },
3844
+ {
3845
+ tag: tags.local(tags.variableName),
3846
+ class: "tok-variableName tok-local"
3847
+ },
3848
+ {
3849
+ tag: tags.definition(tags.variableName),
3850
+ class: "tok-variableName tok-definition"
3851
+ },
3852
+ {
3853
+ tag: tags.special(tags.variableName),
3854
+ class: "tok-variableName2"
3855
+ },
3856
+ {
3857
+ tag: tags.definition(tags.propertyName),
3858
+ class: "tok-propertyName tok-definition"
3859
+ },
3860
+ {
3861
+ tag: tags.typeName,
3862
+ class: "tok-typeName"
3863
+ },
3864
+ {
3865
+ tag: tags.namespace,
3866
+ class: "tok-namespace"
3867
+ },
3868
+ {
3869
+ tag: tags.className,
3870
+ class: "tok-className"
3871
+ },
3872
+ {
3873
+ tag: tags.macroName,
3874
+ class: "tok-macroName"
3875
+ },
3876
+ {
3877
+ tag: tags.propertyName,
3878
+ class: "tok-propertyName"
3879
+ },
3880
+ {
3881
+ tag: tags.operator,
3882
+ class: "tok-operator"
3883
+ },
3884
+ {
3885
+ tag: tags.comment,
3886
+ class: "tok-comment"
3887
+ },
3888
+ {
3889
+ tag: tags.meta,
3890
+ class: "tok-meta"
3891
+ },
3892
+ {
3893
+ tag: tags.invalid,
3894
+ class: "tok-invalid"
3895
+ },
3896
+ {
3897
+ tag: tags.punctuation,
3898
+ class: "tok-punctuation"
3899
+ }
3900
+ ]);
3901
+
3902
+ //#endregion
3903
+ 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 };
3904
+ //# sourceMappingURL=dist-B5vB-rif.js.map