@exercism/codemirror-lang-wren 0.7.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,2418 +2,33 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var lr = require('@lezer/lr');
5
6
  var language = require('@codemirror/language');
6
- var highlight = require('@codemirror/highlight');
7
+ var highlight = require('@lezer/highlight');
7
8
  var autocomplete = require('@codemirror/autocomplete');
8
9
 
9
- /// The default maximum length of a `TreeBuffer` node.
10
- const DefaultBufferLength = 1024;
11
- let nextPropID = 0;
12
- const CachedNode = new WeakMap();
13
- /// Each [node type](#tree.NodeType) can have metadata associated with
14
- /// it in props. Instances of this class represent prop names.
15
- class NodeProp {
16
- /// Create a new node prop type. You can optionally pass a
17
- /// `deserialize` function.
18
- constructor({ deserialize } = {}) {
19
- this.id = nextPropID++;
20
- this.deserialize = deserialize || (() => {
21
- throw new Error("This node type doesn't define a deserialize function");
22
- });
23
- }
24
- /// Create a string-valued node prop whose deserialize function is
25
- /// the identity function.
26
- static string() { return new NodeProp({ deserialize: str => str }); }
27
- /// Create a number-valued node prop whose deserialize function is
28
- /// just `Number`.
29
- static number() { return new NodeProp({ deserialize: Number }); }
30
- /// Creates a boolean-valued node prop whose deserialize function
31
- /// returns true for any input.
32
- static flag() { return new NodeProp({ deserialize: () => true }); }
33
- /// Store a value for this prop in the given object. This can be
34
- /// useful when building up a prop object to pass to the
35
- /// [`NodeType`](#tree.NodeType) constructor. Returns its first
36
- /// argument.
37
- set(propObj, value) {
38
- propObj[this.id] = value;
39
- return propObj;
40
- }
41
- /// This is meant to be used with
42
- /// [`NodeSet.extend`](#tree.NodeSet.extend) or
43
- /// [`Parser.withProps`](#lezer.Parser.withProps) to compute prop
44
- /// values for each node type in the set. Takes a [match
45
- /// object](#tree.NodeType^match) or function that returns undefined
46
- /// if the node type doesn't get this prop, and the prop's value if
47
- /// it does.
48
- add(match) {
49
- if (typeof match != "function")
50
- match = NodeType.match(match);
51
- return (type) => {
52
- let result = match(type);
53
- return result === undefined ? null : [this, result];
54
- };
55
- }
56
- }
57
- /// Prop that is used to describe matching delimiters. For opening
58
- /// delimiters, this holds an array of node names (written as a
59
- /// space-separated string when declaring this prop in a grammar)
60
- /// for the node types of closing delimiters that match it.
61
- NodeProp.closedBy = new NodeProp({ deserialize: str => str.split(" ") });
62
- /// The inverse of [`openedBy`](#tree.NodeProp^closedBy). This is
63
- /// attached to closing delimiters, holding an array of node names
64
- /// of types of matching opening delimiters.
65
- NodeProp.openedBy = new NodeProp({ deserialize: str => str.split(" ") });
66
- /// Used to assign node types to groups (for example, all node
67
- /// types that represent an expression could be tagged with an
68
- /// `"Expression"` group).
69
- NodeProp.group = new NodeProp({ deserialize: str => str.split(" ") });
70
- const noProps = Object.create(null);
71
- /// Each node in a syntax tree has a node type associated with it.
72
- class NodeType {
73
- /// @internal
74
- constructor(
75
- /// The name of the node type. Not necessarily unique, but if the
76
- /// grammar was written properly, different node types with the
77
- /// same name within a node set should play the same semantic
78
- /// role.
79
- name,
80
- /// @internal
81
- props,
82
- /// The id of this node in its set. Corresponds to the term ids
83
- /// used in the parser.
84
- id,
85
- /// @internal
86
- flags = 0) {
87
- this.name = name;
88
- this.props = props;
89
- this.id = id;
90
- this.flags = flags;
91
- }
92
- static define(spec) {
93
- let props = spec.props && spec.props.length ? Object.create(null) : noProps;
94
- let flags = (spec.top ? 1 /* Top */ : 0) | (spec.skipped ? 2 /* Skipped */ : 0) |
95
- (spec.error ? 4 /* Error */ : 0) | (spec.name == null ? 8 /* Anonymous */ : 0);
96
- let type = new NodeType(spec.name || "", props, spec.id, flags);
97
- if (spec.props)
98
- for (let src of spec.props) {
99
- if (!Array.isArray(src))
100
- src = src(type);
101
- if (src)
102
- src[0].set(props, src[1]);
103
- }
104
- return type;
105
- }
106
- /// Retrieves a node prop for this type. Will return `undefined` if
107
- /// the prop isn't present on this node.
108
- prop(prop) { return this.props[prop.id]; }
109
- /// True when this is the top node of a grammar.
110
- get isTop() { return (this.flags & 1 /* Top */) > 0; }
111
- /// True when this node is produced by a skip rule.
112
- get isSkipped() { return (this.flags & 2 /* Skipped */) > 0; }
113
- /// Indicates whether this is an error node.
114
- get isError() { return (this.flags & 4 /* Error */) > 0; }
115
- /// When true, this node type doesn't correspond to a user-declared
116
- /// named node, for example because it is used to cache repetition.
117
- get isAnonymous() { return (this.flags & 8 /* Anonymous */) > 0; }
118
- /// Returns true when this node's name or one of its
119
- /// [groups](#tree.NodeProp^group) matches the given string.
120
- is(name) {
121
- if (typeof name == 'string') {
122
- if (this.name == name)
123
- return true;
124
- let group = this.prop(NodeProp.group);
125
- return group ? group.indexOf(name) > -1 : false;
126
- }
127
- return this.id == name;
128
- }
129
- /// Create a function from node types to arbitrary values by
130
- /// specifying an object whose property names are node or
131
- /// [group](#tree.NodeProp^group) names. Often useful with
132
- /// [`NodeProp.add`](#tree.NodeProp.add). You can put multiple
133
- /// names, separated by spaces, in a single property name to map
134
- /// multiple node names to a single value.
135
- static match(map) {
136
- let direct = Object.create(null);
137
- for (let prop in map)
138
- for (let name of prop.split(" "))
139
- direct[name] = map[prop];
140
- return (node) => {
141
- for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
142
- let found = direct[i < 0 ? node.name : groups[i]];
143
- if (found)
144
- return found;
145
- }
146
- };
147
- }
148
- }
149
- /// An empty dummy node type to use when no actual type is available.
150
- NodeType.none = new NodeType("", Object.create(null), 0, 8 /* Anonymous */);
151
- /// A node set holds a collection of node types. It is used to
152
- /// compactly represent trees by storing their type ids, rather than a
153
- /// full pointer to the type object, in a number array. Each parser
154
- /// [has](#lezer.Parser.nodeSet) a node set, and [tree
155
- /// buffers](#tree.TreeBuffer) can only store collections of nodes
156
- /// from the same set. A set can have a maximum of 2**16 (65536)
157
- /// node types in it, so that the ids fit into 16-bit typed array
158
- /// slots.
159
- class NodeSet {
160
- /// Create a set with the given types. The `id` property of each
161
- /// type should correspond to its position within the array.
162
- constructor(
163
- /// The node types in this set, by id.
164
- types) {
165
- this.types = types;
166
- for (let i = 0; i < types.length; i++)
167
- if (types[i].id != i)
168
- throw new RangeError("Node type ids should correspond to array positions when creating a node set");
169
- }
170
- /// Create a copy of this set with some node properties added. The
171
- /// arguments to this method should be created with
172
- /// [`NodeProp.add`](#tree.NodeProp.add).
173
- extend(...props) {
174
- let newTypes = [];
175
- for (let type of this.types) {
176
- let newProps = null;
177
- for (let source of props) {
178
- let add = source(type);
179
- if (add) {
180
- if (!newProps)
181
- newProps = Object.assign({}, type.props);
182
- add[0].set(newProps, add[1]);
183
- }
184
- }
185
- newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
186
- }
187
- return new NodeSet(newTypes);
188
- }
189
- }
190
- /// A piece of syntax tree. There are two ways to approach these
191
- /// trees: the way they are actually stored in memory, and the
192
- /// convenient way.
193
- ///
194
- /// Syntax trees are stored as a tree of `Tree` and `TreeBuffer`
195
- /// objects. By packing detail information into `TreeBuffer` leaf
196
- /// nodes, the representation is made a lot more memory-efficient.
197
- ///
198
- /// However, when you want to actually work with tree nodes, this
199
- /// representation is very awkward, so most client code will want to
200
- /// use the `TreeCursor` interface instead, which provides a view on
201
- /// some part of this data structure, and can be used to move around
202
- /// to adjacent nodes.
203
- class Tree {
204
- /// Construct a new tree. You usually want to go through
205
- /// [`Tree.build`](#tree.Tree^build) instead.
206
- constructor(type,
207
- /// The tree's child nodes. Children small enough to fit in a
208
- /// `TreeBuffer will be represented as such, other children can be
209
- /// further `Tree` instances with their own internal structure.
210
- children,
211
- /// The positions (offsets relative to the start of this tree) of
212
- /// the children.
213
- positions,
214
- /// The total length of this tree
215
- length) {
216
- this.type = type;
217
- this.children = children;
218
- this.positions = positions;
219
- this.length = length;
220
- }
221
- /// @internal
222
- toString() {
223
- let children = this.children.map(c => c.toString()).join();
224
- return !this.type.name ? children :
225
- (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) +
226
- (children.length ? "(" + children + ")" : "");
227
- }
228
- /// Get a [tree cursor](#tree.TreeCursor) rooted at this tree. When
229
- /// `pos` is given, the cursor is [moved](#tree.TreeCursor.moveTo)
230
- /// to the given position and side.
231
- cursor(pos, side = 0) {
232
- let scope = (pos != null && CachedNode.get(this)) || this.topNode;
233
- let cursor = new TreeCursor(scope);
234
- if (pos != null) {
235
- cursor.moveTo(pos, side);
236
- CachedNode.set(this, cursor._tree);
237
- }
238
- return cursor;
239
- }
240
- /// Get a [tree cursor](#tree.TreeCursor) that, unlike regular
241
- /// cursors, doesn't skip [anonymous](#tree.NodeType.isAnonymous)
242
- /// nodes.
243
- fullCursor() {
244
- return new TreeCursor(this.topNode, true);
245
- }
246
- /// Get a [syntax node](#tree.SyntaxNode) object for the top of the
247
- /// tree.
248
- get topNode() {
249
- return new TreeNode(this, 0, 0, null);
250
- }
251
- /// Get the [syntax node](#tree.SyntaxNode) at the given position.
252
- /// If `side` is -1, this will move into nodes that end at the
253
- /// position. If 1, it'll move into nodes that start at the
254
- /// position. With 0, it'll only enter nodes that cover the position
255
- /// from both sides.
256
- resolve(pos, side = 0) {
257
- return this.cursor(pos, side).node;
258
- }
259
- /// Iterate over the tree and its children, calling `enter` for any
260
- /// node that touches the `from`/`to` region (if given) before
261
- /// running over such a node's children, and `leave` (if given) when
262
- /// leaving the node. When `enter` returns `false`, the given node
263
- /// will not have its children iterated over (or `leave` called).
264
- iterate(spec) {
265
- let { enter, leave, from = 0, to = this.length } = spec;
266
- for (let c = this.cursor();;) {
267
- let mustLeave = false;
268
- if (c.from <= to && c.to >= from && (c.type.isAnonymous || enter(c.type, c.from, c.to) !== false)) {
269
- if (c.firstChild())
270
- continue;
271
- if (!c.type.isAnonymous)
272
- mustLeave = true;
273
- }
274
- for (;;) {
275
- if (mustLeave && leave)
276
- leave(c.type, c.from, c.to);
277
- mustLeave = c.type.isAnonymous;
278
- if (c.nextSibling())
279
- break;
280
- if (!c.parent())
281
- return;
282
- mustLeave = true;
283
- }
284
- }
285
- }
286
- /// Balance the direct children of this tree.
287
- balance(maxBufferLength = DefaultBufferLength) {
288
- return this.children.length <= BalanceBranchFactor ? this
289
- : balanceRange(this.type, NodeType.none, this.children, this.positions, 0, this.children.length, 0, maxBufferLength, this.length, 0);
290
- }
291
- /// Build a tree from a postfix-ordered buffer of node information,
292
- /// or a cursor over such a buffer.
293
- static build(data) { return buildTree(data); }
294
- }
295
- /// The empty tree
296
- Tree.empty = new Tree(NodeType.none, [], [], 0);
297
- // For trees that need a context hash attached, we're using this
298
- // kludge which assigns an extra property directly after
299
- // initialization (creating a single new object shape).
300
- function withHash(tree, hash) {
301
- if (hash)
302
- tree.contextHash = hash;
303
- return tree;
304
- }
305
- /// Tree buffers contain (type, start, end, endIndex) quads for each
306
- /// node. In such a buffer, nodes are stored in prefix order (parents
307
- /// before children, with the endIndex of the parent indicating which
308
- /// children belong to it)
309
- class TreeBuffer {
310
- /// Create a tree buffer @internal
311
- constructor(
312
- /// @internal
313
- buffer,
314
- // The total length of the group of nodes in the buffer.
315
- length,
316
- /// @internal
317
- set, type = NodeType.none) {
318
- this.buffer = buffer;
319
- this.length = length;
320
- this.set = set;
321
- this.type = type;
322
- }
323
- /// @internal
324
- toString() {
325
- let result = [];
326
- for (let index = 0; index < this.buffer.length;) {
327
- result.push(this.childString(index));
328
- index = this.buffer[index + 3];
329
- }
330
- return result.join(",");
331
- }
332
- /// @internal
333
- childString(index) {
334
- let id = this.buffer[index], endIndex = this.buffer[index + 3];
335
- let type = this.set.types[id], result = type.name;
336
- if (/\W/.test(result) && !type.isError)
337
- result = JSON.stringify(result);
338
- index += 4;
339
- if (endIndex == index)
340
- return result;
341
- let children = [];
342
- while (index < endIndex) {
343
- children.push(this.childString(index));
344
- index = this.buffer[index + 3];
345
- }
346
- return result + "(" + children.join(",") + ")";
347
- }
348
- /// @internal
349
- findChild(startIndex, endIndex, dir, after) {
350
- let { buffer } = this, pick = -1;
351
- for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
352
- if (after != -100000000 /* None */) {
353
- let start = buffer[i + 1], end = buffer[i + 2];
354
- if (dir > 0) {
355
- if (end > after)
356
- pick = i;
357
- if (end > after)
358
- break;
359
- }
360
- else {
361
- if (start < after)
362
- pick = i;
363
- if (end >= after)
364
- break;
365
- }
366
- }
367
- else {
368
- pick = i;
369
- if (dir > 0)
370
- break;
371
- }
372
- }
373
- return pick;
374
- }
375
- }
376
- class TreeNode {
377
- constructor(node, from, index, _parent) {
378
- this.node = node;
379
- this.from = from;
380
- this.index = index;
381
- this._parent = _parent;
382
- }
383
- get type() { return this.node.type; }
384
- get name() { return this.node.type.name; }
385
- get to() { return this.from + this.node.length; }
386
- nextChild(i, dir, after, full = false) {
387
- for (let parent = this;;) {
388
- for (let { children, positions } = parent.node, e = dir > 0 ? children.length : -1; i != e; i += dir) {
389
- let next = children[i], start = positions[i] + parent.from;
390
- if (after != -100000000 /* None */ && (dir < 0 ? start >= after : start + next.length <= after))
391
- continue;
392
- if (next instanceof TreeBuffer) {
393
- let index = next.findChild(0, next.buffer.length, dir, after == -100000000 /* None */ ? -100000000 /* None */ : after - start);
394
- if (index > -1)
395
- return new BufferNode(new BufferContext(parent, next, i, start), null, index);
396
- }
397
- else if (full || (!next.type.isAnonymous || hasChild(next))) {
398
- let inner = new TreeNode(next, start, i, parent);
399
- return full || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, after);
400
- }
401
- }
402
- if (full || !parent.type.isAnonymous)
403
- return null;
404
- i = parent.index + dir;
405
- parent = parent._parent;
406
- if (!parent)
407
- return null;
408
- }
409
- }
410
- get firstChild() { return this.nextChild(0, 1, -100000000 /* None */); }
411
- get lastChild() { return this.nextChild(this.node.children.length - 1, -1, -100000000 /* None */); }
412
- childAfter(pos) { return this.nextChild(0, 1, pos); }
413
- childBefore(pos) { return this.nextChild(this.node.children.length - 1, -1, pos); }
414
- nextSignificantParent() {
415
- let val = this;
416
- while (val.type.isAnonymous && val._parent)
417
- val = val._parent;
418
- return val;
419
- }
420
- get parent() {
421
- return this._parent ? this._parent.nextSignificantParent() : null;
422
- }
423
- get nextSibling() {
424
- return this._parent ? this._parent.nextChild(this.index + 1, 1, -1) : null;
425
- }
426
- get prevSibling() {
427
- return this._parent ? this._parent.nextChild(this.index - 1, -1, -1) : null;
428
- }
429
- get cursor() { return new TreeCursor(this); }
430
- resolve(pos, side = 0) {
431
- return this.cursor.moveTo(pos, side).node;
432
- }
433
- getChild(type, before = null, after = null) {
434
- let r = getChildren(this, type, before, after);
435
- return r.length ? r[0] : null;
436
- }
437
- getChildren(type, before = null, after = null) {
438
- return getChildren(this, type, before, after);
439
- }
440
- /// @internal
441
- toString() { return this.node.toString(); }
442
- }
443
- function getChildren(node, type, before, after) {
444
- let cur = node.cursor, result = [];
445
- if (!cur.firstChild())
446
- return result;
447
- if (before != null)
448
- while (!cur.type.is(before))
449
- if (!cur.nextSibling())
450
- return result;
451
- for (;;) {
452
- if (after != null && cur.type.is(after))
453
- return result;
454
- if (cur.type.is(type))
455
- result.push(cur.node);
456
- if (!cur.nextSibling())
457
- return after == null ? result : [];
458
- }
459
- }
460
- class BufferContext {
461
- constructor(parent, buffer, index, start) {
462
- this.parent = parent;
463
- this.buffer = buffer;
464
- this.index = index;
465
- this.start = start;
466
- }
467
- }
468
- class BufferNode {
469
- constructor(context, _parent, index) {
470
- this.context = context;
471
- this._parent = _parent;
472
- this.index = index;
473
- this.type = context.buffer.set.types[context.buffer.buffer[index]];
474
- }
475
- get name() { return this.type.name; }
476
- get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
477
- get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
478
- child(dir, after) {
479
- let { buffer } = this.context;
480
- let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, after == -100000000 /* None */ ? -100000000 /* None */ : after - this.context.start);
481
- return index < 0 ? null : new BufferNode(this.context, this, index);
482
- }
483
- get firstChild() { return this.child(1, -100000000 /* None */); }
484
- get lastChild() { return this.child(-1, -100000000 /* None */); }
485
- childAfter(pos) { return this.child(1, pos); }
486
- childBefore(pos) { return this.child(-1, pos); }
487
- get parent() {
488
- return this._parent || this.context.parent.nextSignificantParent();
489
- }
490
- externalSibling(dir) {
491
- return this._parent ? null : this.context.parent.nextChild(this.context.index + dir, dir, -1);
492
- }
493
- get nextSibling() {
494
- let { buffer } = this.context;
495
- let after = buffer.buffer[this.index + 3];
496
- if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
497
- return new BufferNode(this.context, this._parent, after);
498
- return this.externalSibling(1);
499
- }
500
- get prevSibling() {
501
- let { buffer } = this.context;
502
- let parentStart = this._parent ? this._parent.index + 4 : 0;
503
- if (this.index == parentStart)
504
- return this.externalSibling(-1);
505
- return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, -100000000 /* None */));
506
- }
507
- get cursor() { return new TreeCursor(this); }
508
- resolve(pos, side = 0) {
509
- return this.cursor.moveTo(pos, side).node;
510
- }
511
- /// @internal
512
- toString() { return this.context.buffer.childString(this.index); }
513
- getChild(type, before = null, after = null) {
514
- let r = getChildren(this, type, before, after);
515
- return r.length ? r[0] : null;
516
- }
517
- getChildren(type, before = null, after = null) {
518
- return getChildren(this, type, before, after);
519
- }
520
- }
521
- /// A tree cursor object focuses on a given node in a syntax tree, and
522
- /// allows you to move to adjacent nodes.
523
- class TreeCursor {
524
- /// @internal
525
- constructor(node, full = false) {
526
- this.full = full;
527
- this.buffer = null;
528
- this.stack = [];
529
- this.index = 0;
530
- this.bufferNode = null;
531
- if (node instanceof TreeNode) {
532
- this.yieldNode(node);
533
- }
534
- else {
535
- this._tree = node.context.parent;
536
- this.buffer = node.context;
537
- for (let n = node._parent; n; n = n._parent)
538
- this.stack.unshift(n.index);
539
- this.bufferNode = node;
540
- this.yieldBuf(node.index);
541
- }
542
- }
543
- /// Shorthand for `.type.name`.
544
- get name() { return this.type.name; }
545
- yieldNode(node) {
546
- if (!node)
547
- return false;
548
- this._tree = node;
549
- this.type = node.type;
550
- this.from = node.from;
551
- this.to = node.to;
552
- return true;
553
- }
554
- yieldBuf(index, type) {
555
- this.index = index;
556
- let { start, buffer } = this.buffer;
557
- this.type = type || buffer.set.types[buffer.buffer[index]];
558
- this.from = start + buffer.buffer[index + 1];
559
- this.to = start + buffer.buffer[index + 2];
560
- return true;
561
- }
562
- yield(node) {
563
- if (!node)
564
- return false;
565
- if (node instanceof TreeNode) {
566
- this.buffer = null;
567
- return this.yieldNode(node);
568
- }
569
- this.buffer = node.context;
570
- return this.yieldBuf(node.index, node.type);
571
- }
572
- /// @internal
573
- toString() {
574
- return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
575
- }
576
- /// @internal
577
- enter(dir, after) {
578
- if (!this.buffer)
579
- return this.yield(this._tree.nextChild(dir < 0 ? this._tree.node.children.length - 1 : 0, dir, after, this.full));
580
- let { buffer } = this.buffer;
581
- let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, after == -100000000 /* None */ ? -100000000 /* None */ : after - this.buffer.start);
582
- if (index < 0)
583
- return false;
584
- this.stack.push(this.index);
585
- return this.yieldBuf(index);
586
- }
587
- /// Move the cursor to this node's first child. When this returns
588
- /// false, the node has no child, and the cursor has not been moved.
589
- firstChild() { return this.enter(1, -100000000 /* None */); }
590
- /// Move the cursor to this node's last child.
591
- lastChild() { return this.enter(-1, -100000000 /* None */); }
592
- /// Move the cursor to the first child that starts at or after `pos`.
593
- childAfter(pos) { return this.enter(1, pos); }
594
- /// Move to the last child that ends at or before `pos`.
595
- childBefore(pos) { return this.enter(-1, pos); }
596
- /// Move the node's parent node, if this isn't the top node.
597
- parent() {
598
- if (!this.buffer)
599
- return this.yieldNode(this.full ? this._tree._parent : this._tree.parent);
600
- if (this.stack.length)
601
- return this.yieldBuf(this.stack.pop());
602
- let parent = this.full ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
603
- this.buffer = null;
604
- return this.yieldNode(parent);
605
- }
606
- /// @internal
607
- sibling(dir) {
608
- if (!this.buffer)
609
- return !this._tree._parent ? false
610
- : this.yield(this._tree._parent.nextChild(this._tree.index + dir, dir, -100000000 /* None */, this.full));
611
- let { buffer } = this.buffer, d = this.stack.length - 1;
612
- if (dir < 0) {
613
- let parentStart = d < 0 ? 0 : this.stack[d] + 4;
614
- if (this.index != parentStart)
615
- return this.yieldBuf(buffer.findChild(parentStart, this.index, -1, -100000000 /* None */));
616
- }
617
- else {
618
- let after = buffer.buffer[this.index + 3];
619
- if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
620
- return this.yieldBuf(after);
621
- }
622
- return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, -100000000 /* None */, this.full)) : false;
623
- }
624
- /// Move to this node's next sibling, if any.
625
- nextSibling() { return this.sibling(1); }
626
- /// Move to this node's previous sibling, if any.
627
- prevSibling() { return this.sibling(-1); }
628
- atLastNode(dir) {
629
- let index, parent, { buffer } = this;
630
- if (buffer) {
631
- if (dir > 0) {
632
- if (this.index < buffer.buffer.buffer.length)
633
- return false;
634
- }
635
- else {
636
- for (let i = 0; i < this.index; i++)
637
- if (buffer.buffer.buffer[i + 3] < this.index)
638
- return false;
639
- }
640
- ({ index, parent } = buffer);
641
- }
642
- else {
643
- ({ index, _parent: parent } = this._tree);
644
- }
645
- for (; parent; { index, _parent: parent } = parent) {
646
- for (let i = index + dir, e = dir < 0 ? -1 : parent.node.children.length; i != e; i += dir) {
647
- let child = parent.node.children[i];
648
- if (this.full || !child.type.isAnonymous || child instanceof TreeBuffer || hasChild(child))
649
- return false;
650
- }
651
- }
652
- return true;
653
- }
654
- move(dir) {
655
- if (this.enter(dir, -100000000 /* None */))
656
- return true;
657
- for (;;) {
658
- if (this.sibling(dir))
659
- return true;
660
- if (this.atLastNode(dir) || !this.parent())
661
- return false;
662
- }
663
- }
664
- /// Move to the next node in a
665
- /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR))
666
- /// traversal, going from a node to its first child or, if the
667
- /// current node is empty, its next sibling or the next sibling of
668
- /// the first parent node that has one.
669
- next() { return this.move(1); }
670
- /// Move to the next node in a last-to-first pre-order traveral. A
671
- /// node is followed by ist last child or, if it has none, its
672
- /// previous sibling or the previous sibling of the first parent
673
- /// node that has one.
674
- prev() { return this.move(-1); }
675
- /// Move the cursor to the innermost node that covers `pos`. If
676
- /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
677
- /// it will enter nodes that start at `pos`.
678
- moveTo(pos, side = 0) {
679
- // Move up to a node that actually holds the position, if possible
680
- while (this.from == this.to ||
681
- (side < 1 ? this.from >= pos : this.from > pos) ||
682
- (side > -1 ? this.to <= pos : this.to < pos))
683
- if (!this.parent())
684
- break;
685
- // Then scan down into child nodes as far as possible
686
- for (;;) {
687
- if (side < 0 ? !this.childBefore(pos) : !this.childAfter(pos))
688
- break;
689
- if (this.from == this.to ||
690
- (side < 1 ? this.from >= pos : this.from > pos) ||
691
- (side > -1 ? this.to <= pos : this.to < pos)) {
692
- this.parent();
693
- break;
694
- }
695
- }
696
- return this;
697
- }
698
- /// Get a [syntax node](#tree.SyntaxNode) at the cursor's current
699
- /// position.
700
- get node() {
701
- if (!this.buffer)
702
- return this._tree;
703
- let cache = this.bufferNode, result = null, depth = 0;
704
- if (cache && cache.context == this.buffer) {
705
- scan: for (let index = this.index, d = this.stack.length; d >= 0;) {
706
- for (let c = cache; c; c = c._parent)
707
- if (c.index == index) {
708
- if (index == this.index)
709
- return c;
710
- result = c;
711
- depth = d + 1;
712
- break scan;
713
- }
714
- index = this.stack[--d];
715
- }
716
- }
717
- for (let i = depth; i < this.stack.length; i++)
718
- result = new BufferNode(this.buffer, result, this.stack[i]);
719
- return this.bufferNode = new BufferNode(this.buffer, result, this.index);
720
- }
721
- /// Get the [tree](#tree.Tree) that represents the current node, if
722
- /// any. Will return null when the node is in a [tree
723
- /// buffer](#tree.TreeBuffer).
724
- get tree() {
725
- return this.buffer ? null : this._tree.node;
726
- }
727
- }
728
- function hasChild(tree) {
729
- return tree.children.some(ch => !ch.type.isAnonymous || ch instanceof TreeBuffer || hasChild(ch));
730
- }
731
- class FlatBufferCursor {
732
- constructor(buffer, index) {
733
- this.buffer = buffer;
734
- this.index = index;
735
- }
736
- get id() { return this.buffer[this.index - 4]; }
737
- get start() { return this.buffer[this.index - 3]; }
738
- get end() { return this.buffer[this.index - 2]; }
739
- get size() { return this.buffer[this.index - 1]; }
740
- get pos() { return this.index; }
741
- next() { this.index -= 4; }
742
- fork() { return new FlatBufferCursor(this.buffer, this.index); }
743
- }
744
- const BalanceBranchFactor = 8;
745
- function buildTree(data) {
746
- var _a;
747
- let { buffer, nodeSet, topID = 0, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
748
- let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
749
- let types = nodeSet.types;
750
- let contextHash = 0;
751
- function takeNode(parentStart, minPos, children, positions, inRepeat) {
752
- let { id, start, end, size } = cursor;
753
- let startPos = start - parentStart;
754
- if (size < 0) {
755
- if (size == -1) { // Reused node
756
- children.push(reused[id]);
757
- positions.push(startPos);
758
- }
759
- else { // Context change
760
- contextHash = id;
761
- }
762
- cursor.next();
763
- return;
764
- }
765
- let type = types[id], node, buffer;
766
- if (end - start <= maxBufferLength && (buffer = findBufferSize(cursor.pos - minPos, inRepeat))) {
767
- // Small enough for a buffer, and no reused nodes inside
768
- let data = new Uint16Array(buffer.size - buffer.skip);
769
- let endPos = cursor.pos - buffer.size, index = data.length;
770
- while (cursor.pos > endPos)
771
- index = copyToBuffer(buffer.start, data, index, inRepeat);
772
- node = new TreeBuffer(data, end - buffer.start, nodeSet, inRepeat < 0 ? NodeType.none : types[inRepeat]);
773
- startPos = buffer.start - parentStart;
774
- }
775
- else { // Make it a node
776
- let endPos = cursor.pos - size;
777
- cursor.next();
778
- let localChildren = [], localPositions = [];
779
- let localInRepeat = id >= minRepeatType ? id : -1;
780
- while (cursor.pos > endPos) {
781
- if (cursor.id == localInRepeat)
782
- cursor.next();
783
- else
784
- takeNode(start, endPos, localChildren, localPositions, localInRepeat);
785
- }
786
- localChildren.reverse();
787
- localPositions.reverse();
788
- if (localInRepeat > -1 && localChildren.length > BalanceBranchFactor)
789
- node = balanceRange(type, type, localChildren, localPositions, 0, localChildren.length, 0, maxBufferLength, end - start, contextHash);
790
- else
791
- node = withHash(new Tree(type, localChildren, localPositions, end - start), contextHash);
792
- }
793
- children.push(node);
794
- positions.push(startPos);
795
- }
796
- function findBufferSize(maxSize, inRepeat) {
797
- // Scan through the buffer to find previous siblings that fit
798
- // together in a TreeBuffer, and don't contain any reused nodes
799
- // (which can't be stored in a buffer).
800
- // If `inRepeat` is > -1, ignore node boundaries of that type for
801
- // nesting, but make sure the end falls either at the start
802
- // (`maxSize`) or before such a node.
803
- let fork = cursor.fork();
804
- let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
805
- let result = { size: 0, start: 0, skip: 0 };
806
- scan: for (let minPos = fork.pos - maxSize; fork.pos > minPos;) {
807
- // Pretend nested repeat nodes of the same type don't exist
808
- if (fork.id == inRepeat) {
809
- // Except that we store the current state as a valid return
810
- // value.
811
- result.size = size;
812
- result.start = start;
813
- result.skip = skip;
814
- skip += 4;
815
- size += 4;
816
- fork.next();
817
- continue;
818
- }
819
- let nodeSize = fork.size, startPos = fork.pos - nodeSize;
820
- if (nodeSize < 0 || startPos < minPos || fork.start < minStart)
821
- break;
822
- let localSkipped = fork.id >= minRepeatType ? 4 : 0;
823
- let nodeStart = fork.start;
824
- fork.next();
825
- while (fork.pos > startPos) {
826
- if (fork.size < 0)
827
- break scan;
828
- if (fork.id >= minRepeatType)
829
- localSkipped += 4;
830
- fork.next();
831
- }
832
- start = nodeStart;
833
- size += nodeSize;
834
- skip += localSkipped;
835
- }
836
- if (inRepeat < 0 || size == maxSize) {
837
- result.size = size;
838
- result.start = start;
839
- result.skip = skip;
840
- }
841
- return result.size > 4 ? result : undefined;
842
- }
843
- function copyToBuffer(bufferStart, buffer, index, inRepeat) {
844
- let { id, start, end, size } = cursor;
845
- cursor.next();
846
- if (id == inRepeat)
847
- return index;
848
- let startIndex = index;
849
- if (size > 4) {
850
- let endPos = cursor.pos - (size - 4);
851
- while (cursor.pos > endPos)
852
- index = copyToBuffer(bufferStart, buffer, index, inRepeat);
853
- }
854
- if (id < minRepeatType) { // Don't copy repeat nodes into buffers
855
- buffer[--index] = startIndex;
856
- buffer[--index] = end - bufferStart;
857
- buffer[--index] = start - bufferStart;
858
- buffer[--index] = id;
859
- }
860
- return index;
861
- }
862
- let children = [], positions = [];
863
- while (cursor.pos > 0)
864
- takeNode(data.start || 0, 0, children, positions, -1);
865
- let length = (_a = data.length) !== null && _a !== void 0 ? _a : (children.length ? positions[0] + children[0].length : 0);
866
- return new Tree(types[topID], children.reverse(), positions.reverse(), length);
867
- }
868
- function balanceRange(outerType, innerType, children, positions, from, to, start, maxBufferLength, length, contextHash) {
869
- let localChildren = [], localPositions = [];
870
- if (length <= maxBufferLength) {
871
- for (let i = from; i < to; i++) {
872
- localChildren.push(children[i]);
873
- localPositions.push(positions[i] - start);
874
- }
875
- }
876
- else {
877
- let maxChild = Math.max(maxBufferLength, Math.ceil(length * 1.5 / BalanceBranchFactor));
878
- for (let i = from; i < to;) {
879
- let groupFrom = i, groupStart = positions[i];
880
- i++;
881
- for (; i < to; i++) {
882
- let nextEnd = positions[i] + children[i].length;
883
- if (nextEnd - groupStart > maxChild)
884
- break;
885
- }
886
- if (i == groupFrom + 1) {
887
- let only = children[groupFrom];
888
- if (only instanceof Tree && only.type == innerType && only.length > maxChild << 1) { // Too big, collapse
889
- for (let j = 0; j < only.children.length; j++) {
890
- localChildren.push(only.children[j]);
891
- localPositions.push(only.positions[j] + groupStart - start);
892
- }
893
- continue;
894
- }
895
- localChildren.push(only);
896
- }
897
- else if (i == groupFrom + 1) {
898
- localChildren.push(children[groupFrom]);
899
- }
900
- else {
901
- let inner = balanceRange(innerType, innerType, children, positions, groupFrom, i, groupStart, maxBufferLength, positions[i - 1] + children[i - 1].length - groupStart, contextHash);
902
- if (innerType != NodeType.none && !containsType(inner.children, innerType))
903
- inner = withHash(new Tree(NodeType.none, inner.children, inner.positions, inner.length), contextHash);
904
- localChildren.push(inner);
905
- }
906
- localPositions.push(groupStart - start);
907
- }
908
- }
909
- return withHash(new Tree(outerType, localChildren, localPositions, length), contextHash);
910
- }
911
- function containsType(nodes, type) {
912
- for (let elt of nodes)
913
- if (elt.type == type)
914
- return true;
915
- return false;
916
- }
917
- // Creates an `Input` that is backed by a single, flat string.
918
- function stringInput(input) { return new StringInput(input); }
919
- class StringInput {
920
- constructor(string, length = string.length) {
921
- this.string = string;
922
- this.length = length;
923
- }
924
- get(pos) {
925
- return pos < 0 || pos >= this.length ? -1 : this.string.charCodeAt(pos);
926
- }
927
- lineAfter(pos) {
928
- if (pos < 0)
929
- return "";
930
- let end = this.string.indexOf("\n", pos);
931
- return this.string.slice(pos, end < 0 ? this.length : Math.min(end, this.length));
932
- }
933
- read(from, to) { return this.string.slice(from, Math.min(this.length, to)); }
934
- clip(at) { return new StringInput(this.string, at); }
935
- }
936
-
937
- /// A parse stack. These are used internally by the parser to track
938
- /// parsing progress. They also provide some properties and methods
939
- /// that external code such as a tokenizer can use to get information
940
- /// about the parse state.
941
- class Stack {
942
- /// @internal
943
- constructor(
944
- /// A the parse that this stack is part of @internal
945
- p,
946
- /// Holds state, pos, value stack pos (15 bits array index, 15 bits
947
- /// buffer index) triplets for all but the top state
948
- /// @internal
949
- stack,
950
- /// The current parse state @internal
951
- state,
952
- // The position at which the next reduce should take place. This
953
- // can be less than `this.pos` when skipped expressions have been
954
- // added to the stack (which should be moved outside of the next
955
- // reduction)
956
- /// @internal
957
- reducePos,
958
- /// The input position up to which this stack has parsed.
959
- pos,
960
- /// The dynamic score of the stack, including dynamic precedence
961
- /// and error-recovery penalties
962
- /// @internal
963
- score,
964
- // The output buffer. Holds (type, start, end, size) quads
965
- // representing nodes created by the parser, where `size` is
966
- // amount of buffer array entries covered by this node.
967
- /// @internal
968
- buffer,
969
- // The base offset of the buffer. When stacks are split, the split
970
- // instance shared the buffer history with its parent up to
971
- // `bufferBase`, which is the absolute offset (including the
972
- // offset of previous splits) into the buffer at which this stack
973
- // starts writing.
974
- /// @internal
975
- bufferBase,
976
- /// @internal
977
- curContext,
978
- // A parent stack from which this was split off, if any. This is
979
- // set up so that it always points to a stack that has some
980
- // additional buffer content, never to a stack with an equal
981
- // `bufferBase`.
982
- /// @internal
983
- parent) {
984
- this.p = p;
985
- this.stack = stack;
986
- this.state = state;
987
- this.reducePos = reducePos;
988
- this.pos = pos;
989
- this.score = score;
990
- this.buffer = buffer;
991
- this.bufferBase = bufferBase;
992
- this.curContext = curContext;
993
- this.parent = parent;
994
- }
995
- /// @internal
996
- toString() {
997
- return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
998
- }
999
- // Start an empty stack
1000
- /// @internal
1001
- static start(p, state, pos = 0) {
1002
- let cx = p.parser.context;
1003
- return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, null);
1004
- }
1005
- /// The stack's current [context](#lezer.ContextTracker) value, if
1006
- /// any. Its type will depend on the context tracker's type
1007
- /// parameter, or it will be `null` if there is no context
1008
- /// tracker.
1009
- get context() { return this.curContext ? this.curContext.context : null; }
1010
- // Push a state onto the stack, tracking its start position as well
1011
- // as the buffer base at that point.
1012
- /// @internal
1013
- pushState(state, start) {
1014
- this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
1015
- this.state = state;
1016
- }
1017
- // Apply a reduce action
1018
- /// @internal
1019
- reduce(action) {
1020
- let depth = action >> 19 /* ReduceDepthShift */, type = action & 65535 /* ValueMask */;
1021
- let { parser } = this.p;
1022
- let dPrec = parser.dynamicPrecedence(type);
1023
- if (dPrec)
1024
- this.score += dPrec;
1025
- if (depth == 0) {
1026
- // Zero-depth reductions are a special case—they add stuff to
1027
- // the stack without popping anything off.
1028
- if (type < parser.minRepeatTerm)
1029
- this.storeNode(type, this.reducePos, this.reducePos, 4, true);
1030
- this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
1031
- this.reduceContext(type);
1032
- return;
1033
- }
1034
- // Find the base index into `this.stack`, content after which will
1035
- // be dropped. Note that with `StayFlag` reductions we need to
1036
- // consume two extra frames (the dummy parent node for the skipped
1037
- // expression and the state that we'll be staying in, which should
1038
- // be moved to `this.state`).
1039
- let base = this.stack.length - ((depth - 1) * 3) - (action & 262144 /* StayFlag */ ? 6 : 0);
1040
- let start = this.stack[base - 2];
1041
- let bufferBase = this.stack[base - 1], count = this.bufferBase + this.buffer.length - bufferBase;
1042
- // Store normal terms or `R -> R R` repeat reductions
1043
- if (type < parser.minRepeatTerm || (action & 131072 /* RepeatFlag */)) {
1044
- let pos = parser.stateFlag(this.state, 1 /* Skipped */) ? this.pos : this.reducePos;
1045
- this.storeNode(type, start, pos, count + 4, true);
1046
- }
1047
- if (action & 262144 /* StayFlag */) {
1048
- this.state = this.stack[base];
1049
- }
1050
- else {
1051
- let baseStateID = this.stack[base - 3];
1052
- this.state = parser.getGoto(baseStateID, type, true);
1053
- }
1054
- while (this.stack.length > base)
1055
- this.stack.pop();
1056
- this.reduceContext(type);
1057
- }
1058
- // Shift a value into the buffer
1059
- /// @internal
1060
- storeNode(term, start, end, size = 4, isReduce = false) {
1061
- if (term == 0 /* Err */) { // Try to omit/merge adjacent error nodes
1062
- let cur = this, top = this.buffer.length;
1063
- if (top == 0 && cur.parent) {
1064
- top = cur.bufferBase - cur.parent.bufferBase;
1065
- cur = cur.parent;
1066
- }
1067
- if (top > 0 && cur.buffer[top - 4] == 0 /* Err */ && cur.buffer[top - 1] > -1) {
1068
- if (start == end)
1069
- return;
1070
- if (cur.buffer[top - 2] >= start) {
1071
- cur.buffer[top - 2] = end;
1072
- return;
1073
- }
1074
- }
1075
- }
1076
- if (!isReduce || this.pos == end) { // Simple case, just append
1077
- this.buffer.push(term, start, end, size);
1078
- }
1079
- else { // There may be skipped nodes that have to be moved forward
1080
- let index = this.buffer.length;
1081
- if (index > 0 && this.buffer[index - 4] != 0 /* Err */)
1082
- while (index > 0 && this.buffer[index - 2] > end) {
1083
- // Move this record forward
1084
- this.buffer[index] = this.buffer[index - 4];
1085
- this.buffer[index + 1] = this.buffer[index - 3];
1086
- this.buffer[index + 2] = this.buffer[index - 2];
1087
- this.buffer[index + 3] = this.buffer[index - 1];
1088
- index -= 4;
1089
- if (size > 4)
1090
- size -= 4;
1091
- }
1092
- this.buffer[index] = term;
1093
- this.buffer[index + 1] = start;
1094
- this.buffer[index + 2] = end;
1095
- this.buffer[index + 3] = size;
1096
- }
1097
- }
1098
- // Apply a shift action
1099
- /// @internal
1100
- shift(action, next, nextEnd) {
1101
- if (action & 131072 /* GotoFlag */) {
1102
- this.pushState(action & 65535 /* ValueMask */, this.pos);
1103
- }
1104
- else if ((action & 262144 /* StayFlag */) == 0) { // Regular shift
1105
- let start = this.pos, nextState = action, { parser } = this.p;
1106
- if (nextEnd > this.pos || next <= parser.maxNode) {
1107
- this.pos = nextEnd;
1108
- if (!parser.stateFlag(nextState, 1 /* Skipped */))
1109
- this.reducePos = nextEnd;
1110
- }
1111
- this.pushState(nextState, start);
1112
- if (next <= parser.maxNode)
1113
- this.buffer.push(next, start, nextEnd, 4);
1114
- this.shiftContext(next);
1115
- }
1116
- else { // Shift-and-stay, which means this is a skipped token
1117
- if (next <= this.p.parser.maxNode)
1118
- this.buffer.push(next, this.pos, nextEnd, 4);
1119
- this.pos = nextEnd;
1120
- }
1121
- }
1122
- // Apply an action
1123
- /// @internal
1124
- apply(action, next, nextEnd) {
1125
- if (action & 65536 /* ReduceFlag */)
1126
- this.reduce(action);
1127
- else
1128
- this.shift(action, next, nextEnd);
1129
- }
1130
- // Add a prebuilt node into the buffer. This may be a reused node or
1131
- // the result of running a nested parser.
1132
- /// @internal
1133
- useNode(value, next) {
1134
- let index = this.p.reused.length - 1;
1135
- if (index < 0 || this.p.reused[index] != value) {
1136
- this.p.reused.push(value);
1137
- index++;
1138
- }
1139
- let start = this.pos;
1140
- this.reducePos = this.pos = start + value.length;
1141
- this.pushState(next, start);
1142
- this.buffer.push(index, start, this.reducePos, -1 /* size < 0 means this is a reused value */);
1143
- if (this.curContext)
1144
- this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this.p.input, this));
1145
- }
1146
- // Split the stack. Due to the buffer sharing and the fact
1147
- // that `this.stack` tends to stay quite shallow, this isn't very
1148
- // expensive.
1149
- /// @internal
1150
- split() {
1151
- let parent = this;
1152
- let off = parent.buffer.length;
1153
- // Because the top of the buffer (after this.pos) may be mutated
1154
- // to reorder reductions and skipped tokens, and shared buffers
1155
- // should be immutable, this copies any outstanding skipped tokens
1156
- // to the new buffer, and puts the base pointer before them.
1157
- while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
1158
- off -= 4;
1159
- let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
1160
- // Make sure parent points to an actual parent with content, if there is such a parent.
1161
- while (parent && base == parent.bufferBase)
1162
- parent = parent.parent;
1163
- return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, parent);
1164
- }
1165
- // Try to recover from an error by 'deleting' (ignoring) one token.
1166
- /// @internal
1167
- recoverByDelete(next, nextEnd) {
1168
- let isNode = next <= this.p.parser.maxNode;
1169
- if (isNode)
1170
- this.storeNode(next, this.pos, nextEnd);
1171
- this.storeNode(0 /* Err */, this.pos, nextEnd, isNode ? 8 : 4);
1172
- this.pos = this.reducePos = nextEnd;
1173
- this.score -= 200 /* Token */;
1174
- }
1175
- /// Check if the given term would be able to be shifted (optionally
1176
- /// after some reductions) on this stack. This can be useful for
1177
- /// external tokenizers that want to make sure they only provide a
1178
- /// given token when it applies.
1179
- canShift(term) {
1180
- for (let sim = new SimulatedStack(this);;) {
1181
- let action = this.p.parser.stateSlot(sim.top, 4 /* DefaultReduce */) || this.p.parser.hasAction(sim.top, term);
1182
- if ((action & 65536 /* ReduceFlag */) == 0)
1183
- return true;
1184
- if (action == 0)
1185
- return false;
1186
- sim.reduce(action);
1187
- }
1188
- }
1189
- /// Find the start position of the rule that is currently being parsed.
1190
- get ruleStart() {
1191
- for (let state = this.state, base = this.stack.length;;) {
1192
- let force = this.p.parser.stateSlot(state, 5 /* ForcedReduce */);
1193
- if (!(force & 65536 /* ReduceFlag */))
1194
- return 0;
1195
- base -= 3 * (force >> 19 /* ReduceDepthShift */);
1196
- if ((force & 65535 /* ValueMask */) < this.p.parser.minRepeatTerm)
1197
- return this.stack[base + 1];
1198
- state = this.stack[base];
1199
- }
1200
- }
1201
- /// Find the start position of an instance of any of the given term
1202
- /// types, or return `null` when none of them are found.
1203
- ///
1204
- /// **Note:** this is only reliable when there is at least some
1205
- /// state that unambiguously matches the given rule on the stack.
1206
- /// I.e. if you have a grammar like this, where the difference
1207
- /// between `a` and `b` is only apparent at the third token:
1208
- ///
1209
- /// a { b | c }
1210
- /// b { "x" "y" "x" }
1211
- /// c { "x" "y" "z" }
1212
- ///
1213
- /// Then a parse state after `"x"` will not reliably tell you that
1214
- /// `b` is on the stack. You _can_ pass `[b, c]` to reliably check
1215
- /// for either of those two rules (assuming that `a` isn't part of
1216
- /// some rule that includes other things starting with `"x"`).
1217
- ///
1218
- /// When `before` is given, this keeps scanning up the stack until
1219
- /// it finds a match that starts before that position.
1220
- ///
1221
- /// Note that you have to be careful when using this in tokenizers,
1222
- /// since it's relatively easy to introduce data dependencies that
1223
- /// break incremental parsing by using this method.
1224
- startOf(types, before) {
1225
- let state = this.state, frame = this.stack.length, { parser } = this.p;
1226
- for (;;) {
1227
- let force = parser.stateSlot(state, 5 /* ForcedReduce */);
1228
- let depth = force >> 19 /* ReduceDepthShift */, term = force & 65535 /* ValueMask */;
1229
- if (types.indexOf(term) > -1) {
1230
- let base = frame - (3 * (force >> 19 /* ReduceDepthShift */)), pos = this.stack[base + 1];
1231
- if (before == null || before > pos)
1232
- return pos;
1233
- }
1234
- if (frame == 0)
1235
- return null;
1236
- if (depth == 0) {
1237
- frame -= 3;
1238
- state = this.stack[frame];
1239
- }
1240
- else {
1241
- frame -= 3 * (depth - 1);
1242
- state = parser.getGoto(this.stack[frame - 3], term, true);
1243
- }
1244
- }
1245
- }
1246
- // Apply up to Recover.MaxNext recovery actions that conceptually
1247
- // inserts some missing token or rule.
1248
- /// @internal
1249
- recoverByInsert(next) {
1250
- if (this.stack.length >= 300 /* MaxInsertStackDepth */)
1251
- return [];
1252
- let nextStates = this.p.parser.nextStates(this.state);
1253
- if (nextStates.length > 4 /* MaxNext */ << 1 || this.stack.length >= 120 /* DampenInsertStackDepth */) {
1254
- let best = [];
1255
- for (let i = 0, s; i < nextStates.length; i += 2) {
1256
- if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
1257
- best.push(nextStates[i], s);
1258
- }
1259
- if (this.stack.length < 120 /* DampenInsertStackDepth */)
1260
- for (let i = 0; best.length < 4 /* MaxNext */ << 1 && i < nextStates.length; i += 2) {
1261
- let s = nextStates[i + 1];
1262
- if (!best.some((v, i) => (i & 1) && v == s))
1263
- best.push(nextStates[i], s);
1264
- }
1265
- nextStates = best;
1266
- }
1267
- let result = [];
1268
- for (let i = 0; i < nextStates.length && result.length < 4 /* MaxNext */; i += 2) {
1269
- let s = nextStates[i + 1];
1270
- if (s == this.state)
1271
- continue;
1272
- let stack = this.split();
1273
- stack.storeNode(0 /* Err */, stack.pos, stack.pos, 4, true);
1274
- stack.pushState(s, this.pos);
1275
- stack.shiftContext(nextStates[i]);
1276
- stack.score -= 200 /* Token */;
1277
- result.push(stack);
1278
- }
1279
- return result;
1280
- }
1281
- // Force a reduce, if possible. Return false if that can't
1282
- // be done.
1283
- /// @internal
1284
- forceReduce() {
1285
- let reduce = this.p.parser.stateSlot(this.state, 5 /* ForcedReduce */);
1286
- if ((reduce & 65536 /* ReduceFlag */) == 0)
1287
- return false;
1288
- if (!this.p.parser.validAction(this.state, reduce)) {
1289
- this.storeNode(0 /* Err */, this.reducePos, this.reducePos, 4, true);
1290
- this.score -= 100 /* Reduce */;
1291
- }
1292
- this.reduce(reduce);
1293
- return true;
1294
- }
1295
- /// @internal
1296
- forceAll() {
1297
- while (!this.p.parser.stateFlag(this.state, 2 /* Accepting */) && this.forceReduce()) { }
1298
- return this;
1299
- }
1300
- /// Check whether this state has no further actions (assumed to be a direct descendant of the
1301
- /// top state, since any other states must be able to continue
1302
- /// somehow). @internal
1303
- get deadEnd() {
1304
- if (this.stack.length != 3)
1305
- return false;
1306
- let { parser } = this.p;
1307
- return parser.data[parser.stateSlot(this.state, 1 /* Actions */)] == 65535 /* End */ &&
1308
- !parser.stateSlot(this.state, 4 /* DefaultReduce */);
1309
- }
1310
- /// Restart the stack (put it back in its start state). Only safe
1311
- /// when this.stack.length == 3 (state is directly below the top
1312
- /// state). @internal
1313
- restart() {
1314
- this.state = this.stack[0];
1315
- this.stack.length = 0;
1316
- }
1317
- /// @internal
1318
- sameState(other) {
1319
- if (this.state != other.state || this.stack.length != other.stack.length)
1320
- return false;
1321
- for (let i = 0; i < this.stack.length; i += 3)
1322
- if (this.stack[i] != other.stack[i])
1323
- return false;
1324
- return true;
1325
- }
1326
- /// Get the parser used by this stack.
1327
- get parser() { return this.p.parser; }
1328
- /// Test whether a given dialect (by numeric ID, as exported from
1329
- /// the terms file) is enabled.
1330
- dialectEnabled(dialectID) { return this.p.parser.dialect.flags[dialectID]; }
1331
- shiftContext(term) {
1332
- if (this.curContext)
1333
- this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this.p.input, this));
1334
- }
1335
- reduceContext(term) {
1336
- if (this.curContext)
1337
- this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this.p.input, this));
1338
- }
1339
- /// @internal
1340
- emitContext() {
1341
- let cx = this.curContext;
1342
- if (!cx.tracker.strict)
1343
- return;
1344
- let last = this.buffer.length - 1;
1345
- if (last < 0 || this.buffer[last] != -2)
1346
- this.buffer.push(cx.hash, this.reducePos, this.reducePos, -2);
1347
- }
1348
- updateContext(context) {
1349
- if (context != this.curContext.context) {
1350
- let newCx = new StackContext(this.curContext.tracker, context);
1351
- if (newCx.hash != this.curContext.hash)
1352
- this.emitContext();
1353
- this.curContext = newCx;
1354
- }
1355
- }
1356
- }
1357
- class StackContext {
1358
- constructor(tracker, context) {
1359
- this.tracker = tracker;
1360
- this.context = context;
1361
- this.hash = tracker.hash(context);
1362
- }
1363
- }
1364
- var Recover;
1365
- (function (Recover) {
1366
- Recover[Recover["Token"] = 200] = "Token";
1367
- Recover[Recover["Reduce"] = 100] = "Reduce";
1368
- Recover[Recover["MaxNext"] = 4] = "MaxNext";
1369
- Recover[Recover["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
1370
- Recover[Recover["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
1371
- })(Recover || (Recover = {}));
1372
- // Used to cheaply run some reductions to scan ahead without mutating
1373
- // an entire stack
1374
- class SimulatedStack {
1375
- constructor(stack) {
1376
- this.stack = stack;
1377
- this.top = stack.state;
1378
- this.rest = stack.stack;
1379
- this.offset = this.rest.length;
1380
- }
1381
- reduce(action) {
1382
- let term = action & 65535 /* ValueMask */, depth = action >> 19 /* ReduceDepthShift */;
1383
- if (depth == 0) {
1384
- if (this.rest == this.stack.stack)
1385
- this.rest = this.rest.slice();
1386
- this.rest.push(this.top, 0, 0);
1387
- this.offset += 3;
1388
- }
1389
- else {
1390
- this.offset -= (depth - 1) * 3;
1391
- }
1392
- let goto = this.stack.p.parser.getGoto(this.rest[this.offset - 3], term, true);
1393
- this.top = goto;
1394
- }
1395
- }
1396
- // This is given to `Tree.build` to build a buffer, and encapsulates
1397
- // the parent-stack-walking necessary to read the nodes.
1398
- class StackBufferCursor {
1399
- constructor(stack, pos, index) {
1400
- this.stack = stack;
1401
- this.pos = pos;
1402
- this.index = index;
1403
- this.buffer = stack.buffer;
1404
- if (this.index == 0)
1405
- this.maybeNext();
1406
- }
1407
- static create(stack) {
1408
- return new StackBufferCursor(stack, stack.bufferBase + stack.buffer.length, stack.buffer.length);
1409
- }
1410
- maybeNext() {
1411
- let next = this.stack.parent;
1412
- if (next != null) {
1413
- this.index = this.stack.bufferBase - next.bufferBase;
1414
- this.stack = next;
1415
- this.buffer = next.buffer;
1416
- }
1417
- }
1418
- get id() { return this.buffer[this.index - 4]; }
1419
- get start() { return this.buffer[this.index - 3]; }
1420
- get end() { return this.buffer[this.index - 2]; }
1421
- get size() { return this.buffer[this.index - 1]; }
1422
- next() {
1423
- this.index -= 4;
1424
- this.pos -= 4;
1425
- if (this.index == 0)
1426
- this.maybeNext();
1427
- }
1428
- fork() {
1429
- return new StackBufferCursor(this.stack, this.pos, this.index);
1430
- }
1431
- }
1432
-
1433
- /// Tokenizers write the tokens they read into instances of this class.
1434
- class Token {
1435
- constructor() {
1436
- /// The start of the token. This is set by the parser, and should not
1437
- /// be mutated by the tokenizer.
1438
- this.start = -1;
1439
- /// This starts at -1, and should be updated to a term id when a
1440
- /// matching token is found.
1441
- this.value = -1;
1442
- /// When setting `.value`, you should also set `.end` to the end
1443
- /// position of the token. (You'll usually want to use the `accept`
1444
- /// method.)
1445
- this.end = -1;
1446
- }
1447
- /// Accept a token, setting `value` and `end` to the given values.
1448
- accept(value, end) {
1449
- this.value = value;
1450
- this.end = end;
1451
- }
1452
- }
1453
- /// @internal
1454
- class TokenGroup {
1455
- constructor(data, id) {
1456
- this.data = data;
1457
- this.id = id;
1458
- }
1459
- token(input, token, stack) { readToken(this.data, input, token, stack, this.id); }
1460
- }
1461
- TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
1462
- // Tokenizer data is stored a big uint16 array containing, for each
1463
- // state:
1464
- //
1465
- // - A group bitmask, indicating what token groups are reachable from
1466
- // this state, so that paths that can only lead to tokens not in
1467
- // any of the current groups can be cut off early.
1468
- //
1469
- // - The position of the end of the state's sequence of accepting
1470
- // tokens
1471
- //
1472
- // - The number of outgoing edges for the state
1473
- //
1474
- // - The accepting tokens, as (token id, group mask) pairs
1475
- //
1476
- // - The outgoing edges, as (start character, end character, state
1477
- // index) triples, with end character being exclusive
1478
- //
1479
- // This function interprets that data, running through a stream as
1480
- // long as new states with the a matching group mask can be reached,
1481
- // and updating `token` when it matches a token.
1482
- function readToken(data, input, token, stack, group) {
1483
- let state = 0, groupMask = 1 << group, dialect = stack.p.parser.dialect;
1484
- scan: for (let pos = token.start;;) {
1485
- if ((groupMask & data[state]) == 0)
1486
- break;
1487
- let accEnd = data[state + 1];
1488
- // Check whether this state can lead to a token in the current group
1489
- // Accept tokens in this state, possibly overwriting
1490
- // lower-precedence / shorter tokens
1491
- for (let i = state + 3; i < accEnd; i += 2)
1492
- if ((data[i + 1] & groupMask) > 0) {
1493
- let term = data[i];
1494
- if (dialect.allows(term) &&
1495
- (token.value == -1 || token.value == term || stack.p.parser.overrides(term, token.value))) {
1496
- token.accept(term, pos);
1497
- break;
1498
- }
1499
- }
1500
- let next = input.get(pos++);
1501
- // Do a binary search on the state's edges
1502
- for (let low = 0, high = data[state + 2]; low < high;) {
1503
- let mid = (low + high) >> 1;
1504
- let index = accEnd + mid + (mid << 1);
1505
- let from = data[index], to = data[index + 1];
1506
- if (next < from)
1507
- high = mid;
1508
- else if (next >= to)
1509
- low = mid + 1;
1510
- else {
1511
- state = data[index + 2];
1512
- continue scan;
1513
- }
1514
- }
1515
- break;
1516
- }
1517
- }
1518
-
1519
- // See lezer-generator/src/encode.ts for comments about the encoding
1520
- // used here
1521
- function decodeArray(input, Type = Uint16Array) {
1522
- if (typeof input != "string")
1523
- return input;
1524
- let array = null;
1525
- for (let pos = 0, out = 0; pos < input.length;) {
1526
- let value = 0;
1527
- for (;;) {
1528
- let next = input.charCodeAt(pos++), stop = false;
1529
- if (next == 126 /* BigValCode */) {
1530
- value = 65535 /* BigVal */;
1531
- break;
1532
- }
1533
- if (next >= 92 /* Gap2 */)
1534
- next--;
1535
- if (next >= 34 /* Gap1 */)
1536
- next--;
1537
- let digit = next - 32 /* Start */;
1538
- if (digit >= 46 /* Base */) {
1539
- digit -= 46 /* Base */;
1540
- stop = true;
1541
- }
1542
- value += digit;
1543
- if (stop)
1544
- break;
1545
- value *= 46 /* Base */;
1546
- }
1547
- if (array)
1548
- array[out++] = value;
1549
- else
1550
- array = new Type(value);
1551
- }
1552
- return array;
1553
- }
1554
-
1555
- // FIXME find some way to reduce recovery work done when the input
1556
- // doesn't match the grammar at all.
1557
- // Environment variable used to control console output
1558
- const verbose = typeof process != "undefined" && /\bparse\b/.test(process.env.LOG);
1559
- let stackIDs = null;
1560
- function cutAt(tree, pos, side) {
1561
- let cursor = tree.cursor(pos);
1562
- for (;;) {
1563
- if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
1564
- for (;;) {
1565
- if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
1566
- return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 5)) : Math.min(tree.length, Math.max(cursor.from + 1, pos + 5));
1567
- if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
1568
- break;
1569
- if (!cursor.parent())
1570
- return side < 0 ? 0 : tree.length;
1571
- }
1572
- }
1573
- }
1574
- class FragmentCursor {
1575
- constructor(fragments) {
1576
- this.fragments = fragments;
1577
- this.i = 0;
1578
- this.fragment = null;
1579
- this.safeFrom = -1;
1580
- this.safeTo = -1;
1581
- this.trees = [];
1582
- this.start = [];
1583
- this.index = [];
1584
- this.nextFragment();
1585
- }
1586
- nextFragment() {
1587
- let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
1588
- if (fr) {
1589
- this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
1590
- this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
1591
- while (this.trees.length) {
1592
- this.trees.pop();
1593
- this.start.pop();
1594
- this.index.pop();
1595
- }
1596
- this.trees.push(fr.tree);
1597
- this.start.push(-fr.offset);
1598
- this.index.push(0);
1599
- this.nextStart = this.safeFrom;
1600
- }
1601
- else {
1602
- this.nextStart = 1e9;
1603
- }
1604
- }
1605
- // `pos` must be >= any previously given `pos` for this cursor
1606
- nodeAt(pos) {
1607
- if (pos < this.nextStart)
1608
- return null;
1609
- while (this.fragment && this.safeTo <= pos)
1610
- this.nextFragment();
1611
- if (!this.fragment)
1612
- return null;
1613
- for (;;) {
1614
- let last = this.trees.length - 1;
1615
- if (last < 0) { // End of tree
1616
- this.nextFragment();
1617
- return null;
1618
- }
1619
- let top = this.trees[last], index = this.index[last];
1620
- if (index == top.children.length) {
1621
- this.trees.pop();
1622
- this.start.pop();
1623
- this.index.pop();
1624
- continue;
1625
- }
1626
- let next = top.children[index];
1627
- let start = this.start[last] + top.positions[index];
1628
- if (start > pos) {
1629
- this.nextStart = start;
1630
- return null;
1631
- }
1632
- else if (start == pos && start + next.length <= this.safeTo) {
1633
- return start == pos && start >= this.safeFrom ? next : null;
1634
- }
1635
- if (next instanceof TreeBuffer) {
1636
- this.index[last]++;
1637
- this.nextStart = start + next.length;
1638
- }
1639
- else {
1640
- this.index[last]++;
1641
- if (start + next.length >= pos) { // Enter this node
1642
- this.trees.push(next);
1643
- this.start.push(start);
1644
- this.index.push(0);
1645
- }
1646
- }
1647
- }
1648
- }
1649
- }
1650
- class CachedToken extends Token {
1651
- constructor() {
1652
- super(...arguments);
1653
- this.extended = -1;
1654
- this.mask = 0;
1655
- this.context = 0;
1656
- }
1657
- clear(start) {
1658
- this.start = start;
1659
- this.value = this.extended = -1;
1660
- }
1661
- }
1662
- const dummyToken = new Token;
1663
- class TokenCache {
1664
- constructor(parser) {
1665
- this.tokens = [];
1666
- this.mainToken = dummyToken;
1667
- this.actions = [];
1668
- this.tokens = parser.tokenizers.map(_ => new CachedToken);
1669
- }
1670
- getActions(stack, input) {
1671
- let actionIndex = 0;
1672
- let main = null;
1673
- let { parser } = stack.p, { tokenizers } = parser;
1674
- let mask = parser.stateSlot(stack.state, 3 /* TokenizerMask */);
1675
- let context = stack.curContext ? stack.curContext.hash : 0;
1676
- for (let i = 0; i < tokenizers.length; i++) {
1677
- if (((1 << i) & mask) == 0)
1678
- continue;
1679
- let tokenizer = tokenizers[i], token = this.tokens[i];
1680
- if (main && !tokenizer.fallback)
1681
- continue;
1682
- if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
1683
- this.updateCachedToken(token, tokenizer, stack, input);
1684
- token.mask = mask;
1685
- token.context = context;
1686
- }
1687
- if (token.value != 0 /* Err */) {
1688
- let startIndex = actionIndex;
1689
- if (token.extended > -1)
1690
- actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
1691
- actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
1692
- if (!tokenizer.extend) {
1693
- main = token;
1694
- if (actionIndex > startIndex)
1695
- break;
1696
- }
1697
- }
1698
- }
1699
- while (this.actions.length > actionIndex)
1700
- this.actions.pop();
1701
- if (!main) {
1702
- main = dummyToken;
1703
- main.start = stack.pos;
1704
- if (stack.pos == input.length)
1705
- main.accept(stack.p.parser.eofTerm, stack.pos);
1706
- else
1707
- main.accept(0 /* Err */, stack.pos + 1);
1708
- }
1709
- this.mainToken = main;
1710
- return this.actions;
1711
- }
1712
- updateCachedToken(token, tokenizer, stack, input) {
1713
- token.clear(stack.pos);
1714
- tokenizer.token(input, token, stack);
1715
- if (token.value > -1) {
1716
- let { parser } = stack.p;
1717
- for (let i = 0; i < parser.specialized.length; i++)
1718
- if (parser.specialized[i] == token.value) {
1719
- let result = parser.specializers[i](input.read(token.start, token.end), stack);
1720
- if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
1721
- if ((result & 1) == 0 /* Specialize */)
1722
- token.value = result >> 1;
1723
- else
1724
- token.extended = result >> 1;
1725
- break;
1726
- }
1727
- }
1728
- }
1729
- else if (stack.pos == input.length) {
1730
- token.accept(stack.p.parser.eofTerm, stack.pos);
1731
- }
1732
- else {
1733
- token.accept(0 /* Err */, stack.pos + 1);
1734
- }
1735
- }
1736
- putAction(action, token, end, index) {
1737
- // Don't add duplicate actions
1738
- for (let i = 0; i < index; i += 3)
1739
- if (this.actions[i] == action)
1740
- return index;
1741
- this.actions[index++] = action;
1742
- this.actions[index++] = token;
1743
- this.actions[index++] = end;
1744
- return index;
1745
- }
1746
- addActions(stack, token, end, index) {
1747
- let { state } = stack, { parser } = stack.p, { data } = parser;
1748
- for (let set = 0; set < 2; set++) {
1749
- for (let i = parser.stateSlot(state, set ? 2 /* Skip */ : 1 /* Actions */);; i += 3) {
1750
- if (data[i] == 65535 /* End */) {
1751
- if (data[i + 1] == 1 /* Next */) {
1752
- i = pair(data, i + 2);
1753
- }
1754
- else {
1755
- if (index == 0 && data[i + 1] == 2 /* Other */)
1756
- index = this.putAction(pair(data, i + 1), token, end, index);
1757
- break;
1758
- }
1759
- }
1760
- if (data[i] == token)
1761
- index = this.putAction(pair(data, i + 1), token, end, index);
1762
- }
1763
- }
1764
- return index;
1765
- }
1766
- }
1767
- var Rec;
1768
- (function (Rec) {
1769
- Rec[Rec["Distance"] = 5] = "Distance";
1770
- Rec[Rec["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
1771
- Rec[Rec["MinBufferLengthPrune"] = 200] = "MinBufferLengthPrune";
1772
- Rec[Rec["ForceReduceLimit"] = 10] = "ForceReduceLimit";
1773
- })(Rec || (Rec = {}));
1774
- /// A parse context can be used for step-by-step parsing. After
1775
- /// creating it, you repeatedly call `.advance()` until it returns a
1776
- /// tree to indicate it has reached the end of the parse.
1777
- class Parse {
1778
- constructor(parser, input, startPos, context) {
1779
- this.parser = parser;
1780
- this.input = input;
1781
- this.startPos = startPos;
1782
- this.context = context;
1783
- // The position to which the parse has advanced.
1784
- this.pos = 0;
1785
- this.recovering = 0;
1786
- this.nextStackID = 0x2654;
1787
- this.nested = null;
1788
- this.nestEnd = 0;
1789
- this.nestWrap = null;
1790
- this.reused = [];
1791
- this.tokens = new TokenCache(parser);
1792
- this.topTerm = parser.top[1];
1793
- this.stacks = [Stack.start(this, parser.top[0], this.startPos)];
1794
- let fragments = context === null || context === void 0 ? void 0 : context.fragments;
1795
- this.fragments = fragments && fragments.length ? new FragmentCursor(fragments) : null;
1796
- }
1797
- // Move the parser forward. This will process all parse stacks at
1798
- // `this.pos` and try to advance them to a further position. If no
1799
- // stack for such a position is found, it'll start error-recovery.
1800
- //
1801
- // When the parse is finished, this will return a syntax tree. When
1802
- // not, it returns `null`.
1803
- advance() {
1804
- if (this.nested) {
1805
- let result = this.nested.advance();
1806
- this.pos = this.nested.pos;
1807
- if (result) {
1808
- this.finishNested(this.stacks[0], result);
1809
- this.nested = null;
1810
- }
1811
- return null;
1812
- }
1813
- let stacks = this.stacks, pos = this.pos;
1814
- // This will hold stacks beyond `pos`.
1815
- let newStacks = this.stacks = [];
1816
- let stopped, stoppedTokens;
1817
- let maybeNest;
1818
- // Keep advancing any stacks at `pos` until they either move
1819
- // forward or can't be advanced. Gather stacks that can't be
1820
- // advanced further in `stopped`.
1821
- for (let i = 0; i < stacks.length; i++) {
1822
- let stack = stacks[i], nest;
1823
- for (;;) {
1824
- if (stack.pos > pos) {
1825
- newStacks.push(stack);
1826
- }
1827
- else if (nest = this.checkNest(stack)) {
1828
- if (!maybeNest || maybeNest.stack.score < stack.score)
1829
- maybeNest = nest;
1830
- }
1831
- else if (this.advanceStack(stack, newStacks, stacks)) {
1832
- continue;
1833
- }
1834
- else {
1835
- if (!stopped) {
1836
- stopped = [];
1837
- stoppedTokens = [];
1838
- }
1839
- stopped.push(stack);
1840
- let tok = this.tokens.mainToken;
1841
- stoppedTokens.push(tok.value, tok.end);
1842
- }
1843
- break;
1844
- }
1845
- }
1846
- if (maybeNest) {
1847
- this.startNested(maybeNest);
1848
- return null;
1849
- }
1850
- if (!newStacks.length) {
1851
- let finished = stopped && findFinished(stopped);
1852
- if (finished)
1853
- return this.stackToTree(finished);
1854
- if (this.parser.strict) {
1855
- if (verbose && stopped)
1856
- console.log("Stuck with token " + this.parser.getName(this.tokens.mainToken.value));
1857
- throw new SyntaxError("No parse at " + pos);
1858
- }
1859
- if (!this.recovering)
1860
- this.recovering = 5 /* Distance */;
1861
- }
1862
- if (this.recovering && stopped) {
1863
- let finished = this.runRecovery(stopped, stoppedTokens, newStacks);
1864
- if (finished)
1865
- return this.stackToTree(finished.forceAll());
1866
- }
1867
- if (this.recovering) {
1868
- let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3 /* MaxRemainingPerStep */;
1869
- if (newStacks.length > maxRemaining) {
1870
- newStacks.sort((a, b) => b.score - a.score);
1871
- while (newStacks.length > maxRemaining)
1872
- newStacks.pop();
1873
- }
1874
- if (newStacks.some(s => s.reducePos > pos))
1875
- this.recovering--;
1876
- }
1877
- else if (newStacks.length > 1) {
1878
- // Prune stacks that are in the same state, or that have been
1879
- // running without splitting for a while, to avoid getting stuck
1880
- // with multiple successful stacks running endlessly on.
1881
- outer: for (let i = 0; i < newStacks.length - 1; i++) {
1882
- let stack = newStacks[i];
1883
- for (let j = i + 1; j < newStacks.length; j++) {
1884
- let other = newStacks[j];
1885
- if (stack.sameState(other) ||
1886
- stack.buffer.length > 200 /* MinBufferLengthPrune */ && other.buffer.length > 200 /* MinBufferLengthPrune */) {
1887
- if (((stack.score - other.score) || (stack.buffer.length - other.buffer.length)) > 0) {
1888
- newStacks.splice(j--, 1);
1889
- }
1890
- else {
1891
- newStacks.splice(i--, 1);
1892
- continue outer;
1893
- }
1894
- }
1895
- }
1896
- }
1897
- }
1898
- this.pos = newStacks[0].pos;
1899
- for (let i = 1; i < newStacks.length; i++)
1900
- if (newStacks[i].pos < this.pos)
1901
- this.pos = newStacks[i].pos;
1902
- return null;
1903
- }
1904
- // Returns an updated version of the given stack, or null if the
1905
- // stack can't advance normally. When `split` and `stacks` are
1906
- // given, stacks split off by ambiguous operations will be pushed to
1907
- // `split`, or added to `stacks` if they move `pos` forward.
1908
- advanceStack(stack, stacks, split) {
1909
- let start = stack.pos, { input, parser } = this;
1910
- let base = verbose ? this.stackID(stack) + " -> " : "";
1911
- if (this.fragments) {
1912
- let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
1913
- for (let cached = this.fragments.nodeAt(start); cached;) {
1914
- let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
1915
- if (match > -1 && cached.length && (!strictCx || (cached.contextHash || 0) == cxHash)) {
1916
- stack.useNode(cached, match);
1917
- if (verbose)
1918
- console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
1919
- return true;
1920
- }
1921
- if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
1922
- break;
1923
- let inner = cached.children[0];
1924
- if (inner instanceof Tree)
1925
- cached = inner;
1926
- else
1927
- break;
1928
- }
1929
- }
1930
- let defaultReduce = parser.stateSlot(stack.state, 4 /* DefaultReduce */);
1931
- if (defaultReduce > 0) {
1932
- stack.reduce(defaultReduce);
1933
- if (verbose)
1934
- console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535 /* ValueMask */)})`);
1935
- return true;
1936
- }
1937
- let actions = this.tokens.getActions(stack, input);
1938
- for (let i = 0; i < actions.length;) {
1939
- let action = actions[i++], term = actions[i++], end = actions[i++];
1940
- let last = i == actions.length || !split;
1941
- let localStack = last ? stack : stack.split();
1942
- localStack.apply(action, term, end);
1943
- if (verbose)
1944
- console.log(base + this.stackID(localStack) + ` (via ${(action & 65536 /* ReduceFlag */) == 0 ? "shift"
1945
- : `reduce of ${parser.getName(action & 65535 /* ValueMask */)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
1946
- if (last)
1947
- return true;
1948
- else if (localStack.pos > start)
1949
- stacks.push(localStack);
1950
- else
1951
- split.push(localStack);
1952
- }
1953
- return false;
1954
- }
1955
- // Advance a given stack forward as far as it will go. Returns the
1956
- // (possibly updated) stack if it got stuck, or null if it moved
1957
- // forward and was given to `pushStackDedup`.
1958
- advanceFully(stack, newStacks) {
1959
- let pos = stack.pos;
1960
- for (;;) {
1961
- let nest = this.checkNest(stack);
1962
- if (nest)
1963
- return nest;
1964
- if (!this.advanceStack(stack, null, null))
1965
- return false;
1966
- if (stack.pos > pos) {
1967
- pushStackDedup(stack, newStacks);
1968
- return true;
1969
- }
1970
- }
1971
- }
1972
- runRecovery(stacks, tokens, newStacks) {
1973
- let finished = null, restarted = false;
1974
- let maybeNest;
1975
- for (let i = 0; i < stacks.length; i++) {
1976
- let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
1977
- let base = verbose ? this.stackID(stack) + " -> " : "";
1978
- if (stack.deadEnd) {
1979
- if (restarted)
1980
- continue;
1981
- restarted = true;
1982
- stack.restart();
1983
- if (verbose)
1984
- console.log(base + this.stackID(stack) + " (restarted)");
1985
- let done = this.advanceFully(stack, newStacks);
1986
- if (done) {
1987
- if (done !== true)
1988
- maybeNest = done;
1989
- continue;
1990
- }
1991
- }
1992
- let force = stack.split(), forceBase = base;
1993
- for (let j = 0; force.forceReduce() && j < 10 /* ForceReduceLimit */; j++) {
1994
- if (verbose)
1995
- console.log(forceBase + this.stackID(force) + " (via force-reduce)");
1996
- let done = this.advanceFully(force, newStacks);
1997
- if (done) {
1998
- if (done !== true)
1999
- maybeNest = done;
2000
- break;
2001
- }
2002
- if (verbose)
2003
- forceBase = this.stackID(force) + " -> ";
2004
- }
2005
- for (let insert of stack.recoverByInsert(token)) {
2006
- if (verbose)
2007
- console.log(base + this.stackID(insert) + " (via recover-insert)");
2008
- this.advanceFully(insert, newStacks);
2009
- }
2010
- if (this.input.length > stack.pos) {
2011
- if (tokenEnd == stack.pos) {
2012
- tokenEnd++;
2013
- token = 0 /* Err */;
2014
- }
2015
- stack.recoverByDelete(token, tokenEnd);
2016
- if (verbose)
2017
- console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
2018
- pushStackDedup(stack, newStacks);
2019
- }
2020
- else if (!finished || finished.score < stack.score) {
2021
- finished = stack;
2022
- }
2023
- }
2024
- if (finished)
2025
- return finished;
2026
- if (maybeNest)
2027
- for (let s of this.stacks)
2028
- if (s.score > maybeNest.stack.score) {
2029
- maybeNest = undefined;
2030
- break;
2031
- }
2032
- if (maybeNest)
2033
- this.startNested(maybeNest);
2034
- return null;
2035
- }
2036
- forceFinish() {
2037
- let stack = this.stacks[0].split();
2038
- if (this.nested)
2039
- this.finishNested(stack, this.nested.forceFinish());
2040
- return this.stackToTree(stack.forceAll());
2041
- }
2042
- // Convert the stack's buffer to a syntax tree.
2043
- stackToTree(stack, pos = stack.pos) {
2044
- if (this.parser.context)
2045
- stack.emitContext();
2046
- return Tree.build({ buffer: StackBufferCursor.create(stack),
2047
- nodeSet: this.parser.nodeSet,
2048
- topID: this.topTerm,
2049
- maxBufferLength: this.parser.bufferLength,
2050
- reused: this.reused,
2051
- start: this.startPos,
2052
- length: pos - this.startPos,
2053
- minRepeatType: this.parser.minRepeatTerm });
2054
- }
2055
- checkNest(stack) {
2056
- let info = this.parser.findNested(stack.state);
2057
- if (!info)
2058
- return null;
2059
- let spec = info.value;
2060
- if (typeof spec == "function")
2061
- spec = spec(this.input, stack);
2062
- return spec ? { stack, info, spec } : null;
2063
- }
2064
- startNested(nest) {
2065
- let { stack, info, spec } = nest;
2066
- this.stacks = [stack];
2067
- this.nestEnd = this.scanForNestEnd(stack, info.end, spec.filterEnd);
2068
- this.nestWrap = typeof spec.wrapType == "number" ? this.parser.nodeSet.types[spec.wrapType] : spec.wrapType || null;
2069
- if (spec.startParse) {
2070
- this.nested = spec.startParse(this.input.clip(this.nestEnd), stack.pos, this.context);
2071
- }
2072
- else {
2073
- this.finishNested(stack);
2074
- }
2075
- }
2076
- scanForNestEnd(stack, endToken, filter) {
2077
- for (let pos = stack.pos; pos < this.input.length; pos++) {
2078
- dummyToken.start = pos;
2079
- dummyToken.value = -1;
2080
- endToken.token(this.input, dummyToken, stack);
2081
- if (dummyToken.value > -1 && (!filter || filter(this.input.read(pos, dummyToken.end))))
2082
- return pos;
2083
- }
2084
- return this.input.length;
2085
- }
2086
- finishNested(stack, tree) {
2087
- if (this.nestWrap)
2088
- tree = new Tree(this.nestWrap, tree ? [tree] : [], tree ? [0] : [], this.nestEnd - stack.pos);
2089
- else if (!tree)
2090
- tree = new Tree(NodeType.none, [], [], this.nestEnd - stack.pos);
2091
- let info = this.parser.findNested(stack.state);
2092
- stack.useNode(tree, this.parser.getGoto(stack.state, info.placeholder, true));
2093
- if (verbose)
2094
- console.log(this.stackID(stack) + ` (via unnest)`);
2095
- }
2096
- stackID(stack) {
2097
- let id = (stackIDs || (stackIDs = new WeakMap)).get(stack);
2098
- if (!id)
2099
- stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
2100
- return id + stack;
2101
- }
2102
- }
2103
- function pushStackDedup(stack, newStacks) {
2104
- for (let i = 0; i < newStacks.length; i++) {
2105
- let other = newStacks[i];
2106
- if (other.pos == stack.pos && other.sameState(stack)) {
2107
- if (newStacks[i].score < stack.score)
2108
- newStacks[i] = stack;
2109
- return;
2110
- }
2111
- }
2112
- newStacks.push(stack);
2113
- }
2114
- class Dialect {
2115
- constructor(source, flags, disabled) {
2116
- this.source = source;
2117
- this.flags = flags;
2118
- this.disabled = disabled;
2119
- }
2120
- allows(term) { return !this.disabled || this.disabled[term] == 0; }
2121
- }
2122
- /// A parser holds the parse tables for a given grammar, as generated
2123
- /// by `lezer-generator`.
2124
- class Parser {
2125
- /// @internal
2126
- constructor(spec) {
2127
- /// @internal
2128
- this.bufferLength = DefaultBufferLength;
2129
- /// @internal
2130
- this.strict = false;
2131
- this.cachedDialect = null;
2132
- if (spec.version != 13 /* Version */)
2133
- throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${13 /* Version */})`);
2134
- let tokenArray = decodeArray(spec.tokenData);
2135
- let nodeNames = spec.nodeNames.split(" ");
2136
- this.minRepeatTerm = nodeNames.length;
2137
- this.context = spec.context;
2138
- for (let i = 0; i < spec.repeatNodeCount; i++)
2139
- nodeNames.push("");
2140
- let nodeProps = [];
2141
- for (let i = 0; i < nodeNames.length; i++)
2142
- nodeProps.push([]);
2143
- function setProp(nodeID, prop, value) {
2144
- nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
2145
- }
2146
- if (spec.nodeProps)
2147
- for (let propSpec of spec.nodeProps) {
2148
- let prop = propSpec[0];
2149
- for (let i = 1; i < propSpec.length;) {
2150
- let next = propSpec[i++];
2151
- if (next >= 0) {
2152
- setProp(next, prop, propSpec[i++]);
2153
- }
2154
- else {
2155
- let value = propSpec[i + -next];
2156
- for (let j = -next; j > 0; j--)
2157
- setProp(propSpec[i++], prop, value);
2158
- i++;
2159
- }
2160
- }
2161
- }
2162
- this.specialized = new Uint16Array(spec.specialized ? spec.specialized.length : 0);
2163
- this.specializers = [];
2164
- if (spec.specialized)
2165
- for (let i = 0; i < spec.specialized.length; i++) {
2166
- this.specialized[i] = spec.specialized[i].term;
2167
- this.specializers[i] = spec.specialized[i].get;
2168
- }
2169
- this.states = decodeArray(spec.states, Uint32Array);
2170
- this.data = decodeArray(spec.stateData);
2171
- this.goto = decodeArray(spec.goto);
2172
- let topTerms = Object.keys(spec.topRules).map(r => spec.topRules[r][1]);
2173
- this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
2174
- name: i >= this.minRepeatTerm ? undefined : name,
2175
- id: i,
2176
- props: nodeProps[i],
2177
- top: topTerms.indexOf(i) > -1,
2178
- error: i == 0,
2179
- skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
2180
- })));
2181
- this.maxTerm = spec.maxTerm;
2182
- this.tokenizers = spec.tokenizers.map(value => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
2183
- this.topRules = spec.topRules;
2184
- this.nested = (spec.nested || []).map(([name, value, endToken, placeholder]) => {
2185
- return { name, value, end: new TokenGroup(decodeArray(endToken), 0), placeholder };
2186
- });
2187
- this.dialects = spec.dialects || {};
2188
- this.dynamicPrecedences = spec.dynamicPrecedences || null;
2189
- this.tokenPrecTable = spec.tokenPrec;
2190
- this.termNames = spec.termNames || null;
2191
- this.maxNode = this.nodeSet.types.length - 1;
2192
- this.dialect = this.parseDialect();
2193
- this.top = this.topRules[Object.keys(this.topRules)[0]];
2194
- }
2195
- /// Parse a given string or stream.
2196
- parse(input, startPos = 0, context = {}) {
2197
- if (typeof input == "string")
2198
- input = stringInput(input);
2199
- let cx = new Parse(this, input, startPos, context);
2200
- for (;;) {
2201
- let done = cx.advance();
2202
- if (done)
2203
- return done;
2204
- }
2205
- }
2206
- /// Start an incremental parse.
2207
- startParse(input, startPos = 0, context = {}) {
2208
- if (typeof input == "string")
2209
- input = stringInput(input);
2210
- return new Parse(this, input, startPos, context);
2211
- }
2212
- /// Get a goto table entry @internal
2213
- getGoto(state, term, loose = false) {
2214
- let table = this.goto;
2215
- if (term >= table[0])
2216
- return -1;
2217
- for (let pos = table[term + 1];;) {
2218
- let groupTag = table[pos++], last = groupTag & 1;
2219
- let target = table[pos++];
2220
- if (last && loose)
2221
- return target;
2222
- for (let end = pos + (groupTag >> 1); pos < end; pos++)
2223
- if (table[pos] == state)
2224
- return target;
2225
- if (last)
2226
- return -1;
2227
- }
2228
- }
2229
- /// Check if this state has an action for a given terminal @internal
2230
- hasAction(state, terminal) {
2231
- let data = this.data;
2232
- for (let set = 0; set < 2; set++) {
2233
- for (let i = this.stateSlot(state, set ? 2 /* Skip */ : 1 /* Actions */), next;; i += 3) {
2234
- if ((next = data[i]) == 65535 /* End */) {
2235
- if (data[i + 1] == 1 /* Next */)
2236
- next = data[i = pair(data, i + 2)];
2237
- else if (data[i + 1] == 2 /* Other */)
2238
- return pair(data, i + 2);
2239
- else
2240
- break;
2241
- }
2242
- if (next == terminal || next == 0 /* Err */)
2243
- return pair(data, i + 1);
2244
- }
2245
- }
2246
- return 0;
2247
- }
2248
- /// @internal
2249
- stateSlot(state, slot) {
2250
- return this.states[(state * 6 /* Size */) + slot];
2251
- }
2252
- /// @internal
2253
- stateFlag(state, flag) {
2254
- return (this.stateSlot(state, 0 /* Flags */) & flag) > 0;
2255
- }
2256
- /// @internal
2257
- findNested(state) {
2258
- let flags = this.stateSlot(state, 0 /* Flags */);
2259
- return flags & 4 /* StartNest */ ? this.nested[flags >> 10 /* NestShift */] : null;
2260
- }
2261
- /// @internal
2262
- validAction(state, action) {
2263
- if (action == this.stateSlot(state, 4 /* DefaultReduce */))
2264
- return true;
2265
- for (let i = this.stateSlot(state, 1 /* Actions */);; i += 3) {
2266
- if (this.data[i] == 65535 /* End */) {
2267
- if (this.data[i + 1] == 1 /* Next */)
2268
- i = pair(this.data, i + 2);
2269
- else
2270
- return false;
2271
- }
2272
- if (action == pair(this.data, i + 1))
2273
- return true;
2274
- }
2275
- }
2276
- /// Get the states that can follow this one through shift actions or
2277
- /// goto jumps. @internal
2278
- nextStates(state) {
2279
- let result = [];
2280
- for (let i = this.stateSlot(state, 1 /* Actions */);; i += 3) {
2281
- if (this.data[i] == 65535 /* End */) {
2282
- if (this.data[i + 1] == 1 /* Next */)
2283
- i = pair(this.data, i + 2);
2284
- else
2285
- break;
2286
- }
2287
- if ((this.data[i + 2] & (65536 /* ReduceFlag */ >> 16)) == 0) {
2288
- let value = this.data[i + 1];
2289
- if (!result.some((v, i) => (i & 1) && v == value))
2290
- result.push(this.data[i], value);
2291
- }
2292
- }
2293
- return result;
2294
- }
2295
- /// @internal
2296
- overrides(token, prev) {
2297
- let iPrev = findOffset(this.data, this.tokenPrecTable, prev);
2298
- return iPrev < 0 || findOffset(this.data, this.tokenPrecTable, token) < iPrev;
2299
- }
2300
- /// Configure the parser. Returns a new parser instance that has the
2301
- /// given settings modified. Settings not provided in `config` are
2302
- /// kept from the original parser.
2303
- configure(config) {
2304
- // Hideous reflection-based kludge to make it easy to create a
2305
- // slightly modified copy of a parser.
2306
- let copy = Object.assign(Object.create(Parser.prototype), this);
2307
- if (config.props)
2308
- copy.nodeSet = this.nodeSet.extend(...config.props);
2309
- if (config.top) {
2310
- let info = this.topRules[config.top];
2311
- if (!info)
2312
- throw new RangeError(`Invalid top rule name ${config.top}`);
2313
- copy.top = info;
2314
- }
2315
- if (config.tokenizers)
2316
- copy.tokenizers = this.tokenizers.map(t => {
2317
- let found = config.tokenizers.find(r => r.from == t);
2318
- return found ? found.to : t;
2319
- });
2320
- if (config.dialect)
2321
- copy.dialect = this.parseDialect(config.dialect);
2322
- if (config.nested)
2323
- copy.nested = this.nested.map(obj => {
2324
- if (!Object.prototype.hasOwnProperty.call(config.nested, obj.name))
2325
- return obj;
2326
- return { name: obj.name, value: config.nested[obj.name], end: obj.end, placeholder: obj.placeholder };
2327
- });
2328
- if (config.strict != null)
2329
- copy.strict = config.strict;
2330
- if (config.bufferLength != null)
2331
- copy.bufferLength = config.bufferLength;
2332
- return copy;
2333
- }
2334
- /// Returns the name associated with a given term. This will only
2335
- /// work for all terms when the parser was generated with the
2336
- /// `--names` option. By default, only the names of tagged terms are
2337
- /// stored.
2338
- getName(term) {
2339
- return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
2340
- }
2341
- /// The eof term id is always allocated directly after the node
2342
- /// types. @internal
2343
- get eofTerm() { return this.maxNode + 1; }
2344
- /// Tells you whether this grammar has any nested grammars.
2345
- get hasNested() { return this.nested.length > 0; }
2346
- /// The type of top node produced by the parser.
2347
- get topNode() { return this.nodeSet.types[this.top[1]]; }
2348
- /// @internal
2349
- dynamicPrecedence(term) {
2350
- let prec = this.dynamicPrecedences;
2351
- return prec == null ? 0 : prec[term] || 0;
2352
- }
2353
- /// @internal
2354
- parseDialect(dialect) {
2355
- if (this.cachedDialect && this.cachedDialect.source == dialect)
2356
- return this.cachedDialect;
2357
- let values = Object.keys(this.dialects), flags = values.map(() => false);
2358
- if (dialect)
2359
- for (let part of dialect.split(" ")) {
2360
- let id = values.indexOf(part);
2361
- if (id >= 0)
2362
- flags[id] = true;
2363
- }
2364
- let disabled = null;
2365
- for (let i = 0; i < values.length; i++)
2366
- if (!flags[i]) {
2367
- for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535 /* End */;)
2368
- (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
2369
- }
2370
- return this.cachedDialect = new Dialect(dialect, flags, disabled);
2371
- }
2372
- /// (used by the output of the parser generator) @internal
2373
- static deserialize(spec) {
2374
- return new Parser(spec);
2375
- }
2376
- }
2377
- function pair(data, off) { return data[off] | (data[off + 1] << 16); }
2378
- function findOffset(data, start, term) {
2379
- for (let i = start, next; (next = data[i]) != 65535 /* End */; i++)
2380
- if (next == term)
2381
- return i - start;
2382
- return -1;
2383
- }
2384
- function findFinished(stacks) {
2385
- let best = null;
2386
- for (let stack of stacks) {
2387
- if (stack.pos == stack.p.input.length &&
2388
- stack.p.parser.stateFlag(stack.state, 2 /* Accepting */) &&
2389
- (!best || best.score < stack.score))
2390
- best = stack;
2391
- }
2392
- return best;
2393
- }
2394
-
2395
10
  // This file was generated by lezer-generator. You probably shouldn't edit it.
2396
- const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:132, as:139, in:144, while:148, if:152, else:154, return:158, break:162, continue:166, foreign:172, class:174, var:194};
11
+ const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:134, as:138, in:144, while:148, if:152, else:154, return:158, break:162, continue:166, foreign:172, class:174, var:194};
2397
12
  const spec_word = {__proto__:null,static:183, foreign:185, construct:187};
2398
- const parser = Parser.deserialize({
2399
- version: 13,
2400
- states: "@jO]QPOOOOQO'#Cm'#CmO#wQPO'#CtO$RQPO'#ESO!yQPO'#C{O!yQPO'#DQO%jQPO'#EtO(pQPO'#EuOOQO'#Eu'#EuOOQO'#Et'#EtO*lOQO'#CbO+VOSO'#CbOOQO'#FP'#FPOOQO'#Eb'#EbOOQO'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g$j$k$l$m$n$o$p$q$r$s$t$u$v$w$x%m&YR#a!WqXORT`qu!W!b!i!j!k#`#a$S$W$XQ$V#kR%c%PQ!pjS$U#k%PQ%b%OQ%f%UR%t%nR!ibh^OR`q!W!i!j!k#`#a$S$XQ%V$[S%h%W%ZS%q%i%jS%v%r%sR%x%wi[OR`q!W!i!j!k#`#a$S$XQ!mhQ#s!nQ$c#rR%_$eQ#q!mQ$d#sQ%^$cR%l%_T$]#p$^S$[#p$^U%Z$`$a$bS%j%[%]R%s%kQ%W$[Q%i%ZQ%r%jR%w%sQ`OQqRW!e`q#`$SQ#`!WR$S#aQ!_YR#g!_Q!dZR#j!dQlQS!rl!sR!smQ#w!vR$i#wQ#}#[R$y#}Q${$PR%a${Q!ZUR#d!ZQ%Q$VR%d%QQ$^#pR%X$^Q%o%fR%u%o`_OR`q!W#`#a$SQ#m!iQ#n!jQ#o!kR%S$Xh]OR`q!W!i!j!k#`#a$S$XQsTQ!|uQ#i!bR%R$WpUORT`qu!W!b!i!j!k#`#a$S$W$XQmQQrSQ!qkS!uo#vQ!}xQ#OyQ#PzQ#Q{Q#R|Q#S}Q#T!OQ#U!PQ#V!QQ#W!RQ#X!SQ#Y!UQ#[!VQ#c!YQ#e![Q#f!]Q#z%yQ$f#tQ$g#uQ$j%zQ$k%{Q$l%|Q$m%}Q$n&OQ$o&PQ$p&QQ$q&RQ$r&SQ$s&TQ$t&UQ$u#{Q$v&VQ$w&WQ$x#|Q%m&XR&Y&ZRnQR!woR#]!VR$Q#^R!gbR%g%U",
2403
- nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs SequenceExpression for ImportName VariableDefinition as ForStatement ForInSpec in WhileStatement while IfStatement if else ReturnStatement return BreakStatement break ContinueStatement continue Block ClassDeclaration foreign class ClassName ClassBody MethodDeclaration static foreign construct ClassMethodName ParamList VariableDeclaration var ExpressionStatement",
13
+ const parser = lr.LRParser.deserialize({
14
+ version: 14,
15
+ states: "AYO]QPOOOOQO'#Cm'#CmO#wQPO'#CtO$RQPO'#ESO!yQPO'#C{O!yQPO'#DQO%jQPO'#EtO(pQPO'#EuOOQO'#Eu'#EuOOQO'#Et'#EtO*lOQO'#CbO+VOSO'#CbOOQO'#FP'#FPOOQO'#Eb'#EbOOQO'#Eq'#EqOOQO'#Ec'#EcQ]QPOOO+^QPO'#C`O+fQPO'#DtO+kQPO'#DwO+kQPO'#DyO+pQPO'#D|OOQO'#EO'#EOOOQO'#EQ'#EQO,mQWO'#ETO,rQPO'#ETO,wQPO'#E`O,|QPO'#EfO-WQPO'#EvO-`QPO'#EvO-jQPO,59`O-oQPO'#CxOOQO,5:n,5:nO-vQPO,5:nO/_QPO,59gO1WQPO,59lO1]Q`O,59mO!yQPO,59mOOQO'#D['#D[OOQO'#D^'#D^O!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pO!yQPO,59pOOQO'#Dg'#DgO1bQPO,5:QO2`QPO'#DlO2gQPO'#DmOOQO,5:V,5:VO!yQPO'#EjO2qQPO,5:[O!yQPO,59pO!yQPO,5:TOOOO'#Ed'#EdO4qOQO,58|OOQO,58|,58|OOOO'#Ce'#CeO!yQPO'#CkOOOO'#Ee'#EeO4yOSO,58|OOQO-E8a-E8aO5QQPO,58zOOQO'#Du'#DuO,wQPO'#FOO]QPO,5:`O]QPO,5:cO]QPO,5:eOOQO,5:h,5:hOOQO'#EW'#EWO6wQPO,5:o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#]!VQ#d!YQ#f![Q#g!]Q#{&OQ$h#uQ$i#vQ$l&PQ$m&QQ$n&RQ$o&SQ$p&TQ$q&UQ$r&VQ$s&WQ$t&XQ$u&YQ$v&ZQ$w#|Q$x&[Q$y&]Q$z#}Q%s&^R&_&`RnQR!xoR#^!VQ$R#_R%m%YR!gbR%X$[",
18
+ nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs VariableDefinition SequenceExpression for ImportName as ForStatement ForInSpec in WhileStatement while IfStatement if else ReturnStatement return BreakStatement break ContinueStatement continue Block ClassDeclaration foreign class ClassName ClassBody MethodDeclaration static foreign construct ClassMethodName ParamList VariableDeclaration var ExpressionStatement",
2404
19
  maxTerm: 139,
2405
20
  nodeProps: [
2406
- [NodeProp.group, -11,4,70,73,75,78,80,82,84,85,96,98,"Statement",-17,6,16,17,18,19,20,21,24,28,31,36,37,40,56,59,61,65,"Expression",90,"ClassItem"],
2407
- [NodeProp.openedBy, 13,"%( (",22,"[",26,"{"],
2408
- [NodeProp.closedBy, -2,14,35,")",23,"]",27,"}"]
21
+ ["group", -11,4,70,73,75,78,80,82,84,85,96,98,"Statement",-17,6,16,17,18,19,20,21,24,28,31,36,37,40,56,59,61,66,"Expression",90,"ClassItem"],
22
+ ["openedBy", 13,"%( (",22,"[",26,"{"],
23
+ ["closedBy", -2,14,35,")",23,"]",27,"}"]
2409
24
  ],
2410
25
  skippedNodes: [0,1,2],
2411
26
  repeatNodeCount: 11,
2412
- tokenData: "?u~R!ZOX$tX^${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q#T#Z=qS=vOZSS=yR!Q![>S!c!i>S#T#Z>SS>VR!Q![>`!c!i>`#T#Z>`S>eOYSV>nOfP#gQ#qSw>wO!Pq#gQ#qSw?QOkq#gQ#qS!X?ZP!R!R#gQ#qS#p#q?^q?cO!Xqg?lOja#gQ#qSg?wO$P`qP#gQ#qS!a@Uh#gQ#qS#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!ZAyh#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!XCjP#gQ;=`<%l'nQCrO#gQ",
2413
28
  tokenizers: [0, 1, 2, 3, 4, 5],
2414
29
  topRules: {"Script":[0,3]},
2415
- specialized: [{term: 114, get: value => spec_identifier[value] || -1},{term: 120, get: value => spec_word[value] || -1}],
2416
- tokenPrec: 3631
30
+ specialized: [{term: 114, get: (value) => spec_identifier[value] || -1},{term: 120, get: (value) => spec_word[value] || -1}],
31
+ tokenPrec: 3694
2417
32
  });
2418
33
 
2419
34
  /// A collection of Wren-related snippets
@@ -2448,11 +63,265 @@ const snippets = [
2448
63
  detail: "as",
2449
64
  type: "keyword"
2450
65
  }),
66
+ autocomplete.snippetCompletion("if (${condition}) {\n\t${}\n}", {
67
+ label: "if",
68
+ detail: "block",
69
+ type: "keyword"
70
+ }),
71
+ autocomplete.snippetCompletion("if (${condition}) {\n\t${}\n} else {\n\t${}\n}", {
72
+ label: "if",
73
+ detail: "/ else block",
74
+ type: "keyword"
75
+ }),
76
+ autocomplete.snippetCompletion("while (${condition}) {\n\t${}\n}", {
77
+ label: "while",
78
+ detail: "loop",
79
+ type: "keyword"
80
+ }),
81
+ autocomplete.snippetCompletion("${name}(${params}) {\n\t${}\n}", {
82
+ label: "method",
83
+ detail: "definition",
84
+ type: "keyword"
85
+ }),
86
+ autocomplete.snippetCompletion("static ${name}(${params}) {\n\t${}\n}", {
87
+ label: "static",
88
+ detail: "method definition",
89
+ type: "keyword"
90
+ }),
91
+ autocomplete.snippetCompletion("construct new(${params}) {\n\t${}\n}", {
92
+ label: "construct",
93
+ detail: "constructor",
94
+ type: "keyword"
95
+ }),
2451
96
  ];
2452
97
 
98
+ // Wren's reserved words, and the classes and methods of its core library
99
+ // (https://wren.io/modules/core/) and the CLI's "random" module.
100
+
101
+ const keywords = ("as break class construct continue else false for foreign if " +
102
+ "import in is null return static super this true var while").split(" ");
103
+
104
+ const coreClasses = ("Bool Class Fiber Fn List Map Null Num Object Range " +
105
+ "Sequence String System").split(" ");
106
+
107
+ // Methods called on a class, as in `Num.fromString("1")`.
108
+ const staticMembers = {
109
+ Fiber: ["abort(message)", "current", "new(function)", "suspend()", "yield()", "yield(value)"],
110
+ Fn: ["new(function)"],
111
+ List: ["filled(size, element)", "new()"],
112
+ Map: ["new()"],
113
+ Num: ["fromString(value)", "infinity", "largest", "maxSafeInteger", "minSafeInteger",
114
+ "nan", "pi", "smallest", "tau"],
115
+ Object: ["same(obj1, obj2)"],
116
+ String: ["fromByte(byte)", "fromCodePoint(codePoint)"],
117
+ System: ["clock", "gc()", "print()", "print(object)", "printAll(sequence)",
118
+ "write(object)", "writeAll(sequence)"],
119
+ Random: ["new()", "new(seed)"],
120
+ };
121
+
122
+ // Methods called on a value, as in `list.count`.
123
+ const instanceMembers = {
124
+ Object: ["toString", "type"],
125
+ Class: ["name", "supertype"],
126
+ Fiber: ["call()", "call(value)", "error", "isDone", "transfer()", "transfer(value)",
127
+ "transferError(error)", "try()", "try(value)"],
128
+ Fn: ["arity", "call()"],
129
+ Sequence: ["all(predicate)", "any(predicate)", "contains(element)", "count",
130
+ "count(predicate)", "each(function)", "isEmpty", "join()", "join(separator)",
131
+ "map(transformation)", "reduce(function)", "reduce(seed, function)", "skip(count)",
132
+ "take(count)", "toList", "where(predicate)"],
133
+ List: ["add(item)", "addAll(other)", "clear()", "indexOf(value)", "insert(index, item)",
134
+ "remove(value)", "removeAt(index)", "sort()", "sort(comparer)", "swap(index0, index1)"],
135
+ Map: ["containsKey(key)", "keys", "remove(key)", "values"],
136
+ Num: ["abs", "acos", "asin", "atan", "atan(x)", "cbrt", "ceil", "clamp(min, max)", "cos",
137
+ "exp", "floor", "fraction", "isInfinity", "isInteger", "isNan", "log", "log2",
138
+ "max(other)", "min(other)", "pow(power)", "round", "sign", "sin", "sqrt", "tan",
139
+ "truncate"],
140
+ Range: ["from", "isInclusive", "max", "min", "to"],
141
+ String: ["bytes", "codePoints", "endsWith(suffix)", "indexOf(search)",
142
+ "indexOf(search, start)", "replace(old, swap)", "split(separator)",
143
+ "startsWith(prefix)", "trim()", "trim(chars)", "trimEnd()", "trimEnd(chars)",
144
+ "trimStart()", "trimStart(chars)"],
145
+ Random: ["float()", "float(end)", "float(start, end)", "int(end)", "int(start, end)",
146
+ "sample(list)", "sample(list, count)", "shuffle(list)"],
147
+ };
148
+
149
+ const ScopeNodes = new Set([
150
+ "Script", "Block", "BlockMaybeArgs", "MethodDeclaration", "ForStatement", "ClassBody"
151
+ ]);
152
+
153
+ const dontComplete = [
154
+ "String", "LineComment", "BlockComment", "VariableDefinition", "ClassMethodName"
155
+ ];
156
+
157
+ const Identifier = /^[\w$\xa1-￿]*$/;
158
+
159
+ // `foo.ba|` (the cursor is after a dot) is member completion's job.
160
+ function afterDot(context) {
161
+ return context.matchBefore(/\.\w*$/) != null
162
+ }
163
+
164
+ function text(state, node) {
165
+ return state.sliceDoc(node.from, node.to)
166
+ }
167
+
168
+ function children(node, name) {
169
+ let found = [];
170
+ for (let child = node.firstChild; child; child = child.nextSibling)
171
+ if (child.name == name) found.push(child);
172
+ return found
173
+ }
174
+
175
+ // Instance method names in a class are in scope inside its body, because
176
+ // `count` there means `this.count`.
177
+ function methodName(state, method) {
178
+ let name = children(method, "ClassMethodName")[0];
179
+ let match = name && /^[A-Za-z_]\w*/.exec(text(state, name));
180
+ return match ? match[0] : null
181
+ }
182
+
183
+ function classBodyNames(state, body, add) {
184
+ for (let method of children(body, "MethodDeclaration")) {
185
+ let name = methodName(state, method);
186
+ if (name) add(name, "method");
187
+ }
188
+ // Fields (`_name`) and static fields (`__name`) are created by assigning
189
+ // to them anywhere in the class.
190
+ body.cursor().iterate(node => {
191
+ if (node.name == "VariableName") {
192
+ let name = text(state, node);
193
+ if (name.startsWith("_")) add(name, "property");
194
+ }
195
+ });
196
+ }
197
+
198
+ function scopeNames(state, scope, add) {
199
+ if (scope.name == "ClassBody") return classBodyNames(state, scope, add)
200
+ let gather = node => {
201
+ for (let child = node.firstChild; child; child = child.nextSibling) {
202
+ if (child.name == "ImportName") {
203
+ // In `import "x" for A as B`, only `B` is in scope.
204
+ let defs = children(child, "VariableDefinition");
205
+ let name = text(state, defs[defs.length - 1]);
206
+ add(name, /^[A-Z]/.test(name) ? "class" : "variable");
207
+ } else if (child.name == "ClassDeclaration") {
208
+ let name = children(child, "ClassName")[0];
209
+ if (name) add(text(state, name), "class");
210
+ } else if (child.name == "VariableDefinition") {
211
+ add(text(state, child), "variable");
212
+ } else if (!ScopeNodes.has(child.name)) {
213
+ gather(child);
214
+ }
215
+ }
216
+ };
217
+ gather(scope);
218
+ }
219
+
220
+ /// Completes the names of variables, parameters, classes, methods and
221
+ /// fields that are in scope at the cursor.
222
+ function localCompletionSource(context) {
223
+ let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
224
+ if (dontComplete.includes(inner.name) || afterDot(context)) return null
225
+ let word = context.matchBefore(/[\w$\xa1-￿]+$/);
226
+ if (!word && !context.explicit) return null
227
+ let seen = new Set(), options = [];
228
+ let add = (label, type) => {
229
+ if (seen.has(label)) return
230
+ seen.add(label);
231
+ options.push({label, type});
232
+ };
233
+ for (let pos = inner; pos; pos = pos.parent)
234
+ if (ScopeNodes.has(pos.name)) scopeNames(context.state, pos, add);
235
+ return {options, from: word ? word.from : context.pos, validFor: Identifier}
236
+ }
237
+
238
+ function memberOptions(signatures) {
239
+ let byName = new Map();
240
+ for (let sig of signatures) {
241
+ let paren = sig.indexOf("(");
242
+ let name = paren < 0 ? sig : sig.slice(0, paren);
243
+ let args = paren < 0 ? "" : sig.slice(paren);
244
+ if (!byName.has(name)) byName.set(name, []);
245
+ if (args) byName.get(name).push(args);
246
+ }
247
+ return [...byName].map(([label, args]) => ({
248
+ label,
249
+ type: args.length ? "method" : "property",
250
+ detail: args.join(" ") || undefined
251
+ }))
252
+ }
253
+
254
+ const staticOptions = {};
255
+ for (let name in staticMembers) staticOptions[name] = memberOptions(staticMembers[name]);
256
+
257
+ const instanceOptions = memberOptions(Object.values(instanceMembers).flat());
258
+
259
+ function fileClasses(state) {
260
+ let classes = new Map();
261
+ language.syntaxTree(state).topNode.cursor().iterate(node => {
262
+ if (node.name != "ClassDeclaration") return
263
+ let decl = node.node;
264
+ let name = children(decl, "ClassName")[0];
265
+ let body = children(decl, "ClassBody")[0];
266
+ if (!name || !body) return false
267
+ let statics = [], instance = [];
268
+ for (let method of children(body, "MethodDeclaration")) {
269
+ let label = methodName(state, method);
270
+ if (!label) continue
271
+ let onClass = children(method, "static").length || children(method, "construct").length
272
+ ;(onClass ? statics : instance).push({label, type: "method"});
273
+ }
274
+ classes.set(text(state, name), {statics, instance});
275
+ return false
276
+ });
277
+ return classes
278
+ }
279
+
280
+ /// Completes method names after a dot. After a class name, it offers that
281
+ /// class's static methods and constructors. After anything else, it offers
282
+ /// the instance methods of the core classes and of classes in the file.
283
+ function memberCompletionSource(context) {
284
+ let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
285
+ if (dontComplete.includes(inner.name)) return null
286
+ let member = context.matchBefore(/\.\w*$/);
287
+ if (!member) return null
288
+ let line = context.state.doc.lineAt(member.from);
289
+ let before = context.state.sliceDoc(line.from, member.from);
290
+ // `0..1` is a range.
291
+ if (before.endsWith(".")) return null
292
+ let receiver = /([A-Za-z_]\w*)\s*$/.exec(before);
293
+ let name = receiver ? receiver[1] : null;
294
+ let classes = fileClasses(context.state);
295
+ let options;
296
+ if (name && classes.has(name)) options = classes.get(name).statics;
297
+ else if (name && staticOptions[name]) options = staticOptions[name];
298
+ else if (name && /^[A-Z]/.test(name)) options = [];
299
+ else {
300
+ options = [...instanceOptions];
301
+ for (let cls of classes.values()) options.push(...cls.instance);
302
+ }
303
+ let seen = new Set();
304
+ options = options.filter(o => !seen.has(o.label) && seen.add(o.label));
305
+ return {options, from: member.from + 1, validFor: Identifier}
306
+ }
307
+
308
+ const globals = snippets.concat(
309
+ keywords.map(label => ({label, type: "keyword"})),
310
+ coreClasses.map(label => ({label, type: "class"}))
311
+ );
312
+
313
+ const globalList = autocomplete.completeFromList(globals);
314
+
315
+ /// Completes snippets, keywords and the core classes.
316
+ function globalCompletionSource(context) {
317
+ let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
318
+ if (dontComplete.includes(inner.name) || afterDot(context)) return null
319
+ return globalList(context)
320
+ }
321
+
2453
322
  const lezerParser = parser;
2454
323
 
2455
- const wrenLanguage = language.LezerLanguage.define({
324
+ const wrenLanguage = language.LRLanguage.define({
2456
325
  parser: parser.configure({
2457
326
  props: [
2458
327
  language.indentNodeProp.add({
@@ -2519,15 +388,19 @@ const wrenLanguage = language.LezerLanguage.define({
2519
388
  });
2520
389
 
2521
390
 
2522
- /// Wren support. Includes snippets.
391
+ /// Wren support. Includes completion of snippets, keywords, core
392
+ /// classes, names in scope and methods after a dot.
2523
393
  function wren(config = {}) {
2524
394
  let lang = wrenLanguage;
2525
- return new language.LanguageSupport(lang, wrenLanguage.data.of({
2526
- autocomplete: autocomplete.ifNotIn(["LineComment", "BlockComment", "String"], autocomplete.completeFromList(snippets))
2527
- }))
395
+ return new language.LanguageSupport(lang, [
396
+ globalCompletionSource, localCompletionSource, memberCompletionSource
397
+ ].map(autocomplete => wrenLanguage.data.of({autocomplete})))
2528
398
  }
2529
399
 
400
+ exports.globalCompletionSource = globalCompletionSource;
2530
401
  exports.lezerParser = lezerParser;
402
+ exports.localCompletionSource = localCompletionSource;
403
+ exports.memberCompletionSource = memberCompletionSource;
2531
404
  exports.snippets = snippets;
2532
405
  exports.wren = wren;
2533
406
  exports.wrenLanguage = wrenLanguage;