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