@exercism/codemirror-lang-raku 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,3297 @@
1
+ 'use strict';
2
+
3
+ var lr = require('@lezer/lr');
4
+ var common = require('@lezer/common');
5
+ var language = require('@codemirror/language');
6
+ var highlight = require('@lezer/highlight');
7
+ var autocomplete = require('@codemirror/autocomplete');
8
+ var state = require('@codemirror/state');
9
+
10
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
11
+ const smiley = 205,
12
+ noSmiley = 206,
13
+ BlockComment = 1,
14
+ podStart = 2,
15
+ podEnd = 207,
16
+ podEndDirective = 3,
17
+ podText = 208,
18
+ PodDirective = 4,
19
+ PodHeading = 5,
20
+ PodStrong = 6,
21
+ PodEmphasis = 7,
22
+ PodCode = 8,
23
+ PodLink = 9,
24
+ PodFormat = 10,
25
+ rawHeredoc = 11,
26
+ interpolatingHeredoc = 12,
27
+ heredocElement = 13,
28
+ interpolatingHeredocElement = 14,
29
+ heredocStart = 209,
30
+ methodDot = 15,
31
+ MethodName = 16,
32
+ declaredName = 210,
33
+ declaredMethodName = 211,
34
+ declaredVariable = 212,
35
+ Version = 17,
36
+ regexStart = 213,
37
+ regexBodyEnd = 214,
38
+ regexLitOpen = 215,
39
+ regexLitClose = 216,
40
+ regexText = 217,
41
+ CharacterClass = 18,
42
+ Assertion = 19,
43
+ regexQuote = 20,
44
+ regexOperator = 21,
45
+ regexComment = 22,
46
+ regexBlockComment = 23,
47
+ regexCapture = 24,
48
+ quoteContent = 218,
49
+ quoteNestOpen = 219,
50
+ quoteNestClose = 220,
51
+ quoteEnd = 221,
52
+ rawString = 222,
53
+ quoteStart = 223,
54
+ interpolatingWordList = 25,
55
+ regexLiteral = 26,
56
+ transliteration = 27,
57
+ plainName = 224,
58
+ wordOperator = 28,
59
+ multiName = 225,
60
+ operatorVariable = 29,
61
+ namedCapture = 30,
62
+ LineComment = 31,
63
+ DocComment = 32,
64
+ Pod = 34,
65
+ radixNumber = 35,
66
+ PackageName = 48,
67
+ RoutineName = 55,
68
+ methodRoutineName = 58,
69
+ multiRoutineName = 59,
70
+ RegexName = 64,
71
+ regexBody = 66,
72
+ VariableName = 68,
73
+ AttributeName = 69,
74
+ SpecialVariable = 70,
75
+ EnumName = 74,
76
+ SubsetName = 77,
77
+ ConstantName = 80,
78
+ Identifier = 82,
79
+ TypeName = 83,
80
+ Number = 84,
81
+ quotedString = 85,
82
+ NestedDelimiters = 86,
83
+ Interpolation = 87,
84
+ PairKey = 88,
85
+ multi = 99,
86
+ proto = 100,
87
+ only = 101,
88
+ self = 168,
89
+ True = 169,
90
+ False = 170,
91
+ Nil = 171,
92
+ Operator = 190,
93
+ Regex = 195,
94
+ Heredoc = 196,
95
+ StringLiteral = 197;
96
+
97
+ // Opening bracket -> closing bracket, for the delimiters of quotes and
98
+ // embedded comments. Raku accepts any Unicode bracket pair; this lists
99
+ // the ones that are likely to be typed.
100
+ const brackets$1 = {};
101
+ for (let pair of ["()", "[]", "{}", "<>", "«»", "「」", "「」", "『』", "()", "[]", "{}", "【】", "〈〉", "《》", "〔〕"])
102
+ brackets$1[pair.charCodeAt(0)] = pair.charCodeAt(1);
103
+ function isAsciiLetter(ch) { return ch >= 97 /* Ch.a */ && ch <= 122 /* Ch.z */ || ch >= 65 /* Ch.A */ && ch <= 90 /* Ch.Z */; }
104
+ function isDigit(ch) { return ch >= 48 /* Ch._0 */ && ch <= 57 /* Ch._9 */; }
105
+ // The characters of the grammar's whitespace token, the byte order mark among them.
106
+ function isSpace(ch) {
107
+ return ch == 32 /* Ch.Space */ || ch >= 9 /* Ch.Tab */ && ch <= 13 /* Ch.Return */ || ch == 0x85 || ch == 0xa0 || ch == 0x1680 ||
108
+ ch >= 0x2000 && ch <= 0x200a || ch == 0x2028 || ch == 0x2029 || ch == 0x202f || ch == 0x205f || ch == 0x3000 ||
109
+ ch == 0xfeff;
110
+ }
111
+ // Keep these ranges in sync with identifierStart in syntax.grammar. The
112
+ // input is read in UTF-16 code units, so the astral planes show up here
113
+ // as the surrogate range.
114
+ function isIdentifierStart(ch) {
115
+ return isAsciiLetter(ch) || ch == 95 /* Ch.Underscore */ ||
116
+ ch == 0xaa || ch == 0xb5 || ch == 0xba ||
117
+ ch >= 0xc0 && ch <= 0x1fff && ch != 0xd7 && ch != 0xf7 && ch != 0x1680 ||
118
+ ch >= 0x2071 && ch <= 0x2184 && isLetterAmongSymbols(ch) ||
119
+ ch >= 0x2c00 && ch <= 0x2fef ||
120
+ ch >= 0x3005 && ch <= 0x303c && (ch <= 0x3006 || ch >= 0x302a && ch <= 0x3035 && ch != 0x3030 || ch >= 0x303b) ||
121
+ ch >= 0x3040 && ch <= 0xdfff && !isEnclosedCjkNumber(ch) ||
122
+ ch >= 0xf900 && ch <= 0xfdff ||
123
+ ch >= 0xfe70 && ch <= 0xfefc ||
124
+ ch >= 0xff21 && ch <= 0xff3a || ch >= 0xff41 && ch <= 0xff5a || ch >= 0xff66 && ch <= 0xffdc;
125
+ }
126
+ // The letters among the superscripts, subscripts, letterlike symbols
127
+ // and number forms: ⁿ ₐ ℂ ℝ ℵ ⅅ Ↄ.
128
+ function isLetterAmongSymbols(ch) {
129
+ return ch == 0x2071 || ch == 0x207f || ch >= 0x2090 && ch <= 0x209c ||
130
+ ch == 0x2102 || ch == 0x2107 || ch >= 0x210a && ch <= 0x2113 || ch == 0x2115 ||
131
+ ch >= 0x2119 && ch <= 0x211d || ch == 0x2124 || ch == 0x2126 || ch == 0x2128 ||
132
+ ch >= 0x212a && ch <= 0x212d || ch >= 0x212f && ch <= 0x2139 || ch >= 0x213c && ch <= 0x213f ||
133
+ ch >= 0x2145 && ch <= 0x2149 || ch == 0x214e || ch == 0x2183 || ch == 0x2184;
134
+ }
135
+ // The numbers in the CJK blocks, which the grammar's Number takes: ㆒ ㈠ ㉑ ㊀ ㊱
136
+ function isEnclosedCjkNumber(ch) {
137
+ return ch >= 0x3192 && ch <= 0x3195 || ch >= 0x3220 && ch <= 0x3229 || ch >= 0x3248 && ch <= 0x324f ||
138
+ ch >= 0x3251 && ch <= 0x325f || ch >= 0x3280 && ch <= 0x3289 || ch >= 0x32b1 && ch <= 0x32bf;
139
+ }
140
+ // The characters that Operator runs are made of in syntax.grammar,
141
+ // leaving out the non-ASCII ones.
142
+ function isOperatorChar(ch) {
143
+ return ch == 43 /* Ch.Plus */ || ch == 45 /* Ch.Hyphen */ || ch == 42 /* Ch.Star */ || ch == 47 /* Ch.Slash */ || ch == 126 /* Ch.Tilde */ ||
144
+ ch == 94 /* Ch.Caret */ || ch == 124 /* Ch.Pipe */ || ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */ || ch == 61 /* Ch.Equals */ ||
145
+ ch == 33 /* Ch.Bang */ || ch == 63 /* Ch.Question */ || ch == 37 /* Ch.Percent */ || ch == 38 /* Ch.Amp */;
146
+ }
147
+ // Keep these in sync with operatorChar in syntax.grammar: the characters
148
+ // that a run of them makes one Operator token of.
149
+ function isOperatorRunChar(ch) {
150
+ if (ch < 0x80)
151
+ return ch == 43 /* Ch.Plus */ || ch == 45 /* Ch.Hyphen */ || ch == 42 /* Ch.Star */ || ch == 47 /* Ch.Slash */ || ch == 126 /* Ch.Tilde */ || ch == 94 /* Ch.Caret */ ||
152
+ ch == 124 /* Ch.Pipe */ || ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */ || ch == 61 /* Ch.Equals */ || ch == 33 /* Ch.Bang */ || ch == 63 /* Ch.Question */ ||
153
+ ch == 92 /* Ch.Backslash */;
154
+ return ch >= 0xa1 && ch <= 0xa9 || ch == 0xab || ch == 0xac || ch >= 0xae && ch <= 0xb1 || ch == 0xb4 ||
155
+ ch >= 0xb6 && ch <= 0xb8 || ch == 0xbb || ch == 0xbf || ch == 0xd7 || ch == 0xf7 ||
156
+ ch >= 0x2010 && ch <= 0x2017 || ch >= 0x2020 && ch <= 0x2027 || ch >= 0x2030 && ch <= 0x205e ||
157
+ ch >= 0x2190 && ch <= 0x2bff && ch != 0x2205 /* ∅ */ && ch != 0x221e /* ∞ */ &&
158
+ // The circled numbers: ① ⑴ ⒈ ⓪ ❶
159
+ !(ch >= 0x2460 && ch <= 0x249b || ch >= 0x24ea && ch <= 0x24ff || ch >= 0x2776 && ch <= 0x2793);
160
+ }
161
+ // Whether the character at offset `pos` would continue a name that ends
162
+ // right before it.
163
+ function continuesName(input, pos) {
164
+ let ch = input.peek(pos);
165
+ return isIdentifierStart(ch) || isDigit(ch) ||
166
+ (ch == 45 /* Ch.Hyphen */ || ch == 39 /* Ch.Apostrophe */) && isIdentifierStart(input.peek(pos + 1));
167
+ }
168
+ // The offset after the (possibly `::`-qualified) name that starts at
169
+ // offset `pos`, or -1 when there is no name there.
170
+ function nameEnd(input, pos) {
171
+ if (!isIdentifierStart(input.peek(pos)))
172
+ return -1;
173
+ for (pos++;;) {
174
+ let ch = input.peek(pos);
175
+ if (continuesName(input, pos))
176
+ pos++;
177
+ else if (ch == 58 /* Ch.Colon */ && input.peek(pos + 1) == 58 /* Ch.Colon */ && isIdentifierStart(input.peek(pos + 2)))
178
+ pos += 3;
179
+ else
180
+ return pos;
181
+ }
182
+ }
183
+ function repeats(input, pos, ch, count) {
184
+ for (let i = 0; i < count; i++)
185
+ if (input.peek(pos + i) != ch)
186
+ return false;
187
+ return true;
188
+ }
189
+ function word(input, from, to) {
190
+ let result = "";
191
+ for (let i = from; i < to; i++)
192
+ result += String.fromCharCode(input.peek(i));
193
+ return result;
194
+ }
195
+ // A quote that is being read piece by piece because it interpolates.
196
+ class Quote {
197
+ constructor(parent, open, close, count, interpolates,
198
+ // Whether a backslash that does not start an escape still
199
+ // takes the delimiter after it out of play: q:c[a \] b]
200
+ escapes) {
201
+ this.parent = parent;
202
+ this.open = open;
203
+ this.close = close;
204
+ this.count = count;
205
+ this.interpolates = interpolates;
206
+ this.escapes = escapes;
207
+ let hash = parent ? parent.hash : 7;
208
+ for (let part of [open, count, interpolates, escapes ? 1 : 0])
209
+ hash = (hash * 31 + part) | 0;
210
+ this.hash = hash;
211
+ }
212
+ }
213
+ const noHeredocs = [];
214
+ // The quote that the text of a heredoc is read as. It has no
215
+ // delimiters, and ends where the text does.
216
+ const heredocQuote = new Quote(null, -1, -1, 1, 63 /* Interpolate.All */, true);
217
+ // The body of a regex declaration, or the inside of a regex literal,
218
+ // that is being read piece by piece.
219
+ class RegexBody {
220
+ constructor(// The body around the block of code that this one is in.
221
+ parent,
222
+ // How many braces are open in a block of code in the
223
+ // regex. Zero in the regex itself.
224
+ braces,
225
+ // For a regex literal, the position in the document of
226
+ // the delimiter that closes it. It is not part of the
227
+ // hash, which is to be the same before and after an edit
228
+ // that moves the literal.
229
+ literalEnd = -1) {
230
+ this.parent = parent;
231
+ this.braces = braces;
232
+ this.literalEnd = literalEnd;
233
+ this.hash = ((parent ? parent.hash * 31 : 0) + 7919 * (braces + 1) + (literalEnd < 0 ? 0 : 104729)) | 0;
234
+ }
235
+ withBraces(braces) { return new RegexBody(this.parent, braces, this.literalEnd); }
236
+ }
237
+ // A Pod block that is being read piece by piece.
238
+ class PodBlock {
239
+ constructor(kind,
240
+ // What follows `=begin`, which `=end` has to repeat.
241
+ name,
242
+ // Whether it holds code, in which formatting codes are not read.
243
+ code) {
244
+ this.kind = kind;
245
+ this.name = name;
246
+ this.code = code;
247
+ let hash = 101 + kind * 7 + (code ? 3 : 0);
248
+ for (let i = 0; i < name.length; i++)
249
+ hash = (hash * 31 + name.charCodeAt(i)) | 0;
250
+ this.hash = hash;
251
+ }
252
+ }
253
+ class Context {
254
+ constructor(mode, quote,
255
+ // The heredocs that were opened on the current line, whose
256
+ // text starts on the next one.
257
+ heredocs, pod,
258
+ // The body of a regex declaration that this is in.
259
+ regex, hash = -1) {
260
+ this.mode = mode;
261
+ this.quote = quote;
262
+ this.heredocs = heredocs;
263
+ this.pod = pod;
264
+ this.regex = regex;
265
+ if (hash < 0) {
266
+ hash = (quote ? quote.hash : 0) ^ (pod ? pod.hash : 0) ^ (regex ? regex.hash : 0);
267
+ for (let { terminator, interpolates } of heredocs) {
268
+ hash = (hash * 31 + (interpolates ? 19 : 17)) | 0;
269
+ for (let i = 0; i < terminator.length; i++)
270
+ hash = (hash * 31 + terminator.charCodeAt(i)) | 0;
271
+ }
272
+ // Negative values stand for "not worked out yet".
273
+ hash &= 0x7fffffff;
274
+ }
275
+ this.hash = hash;
276
+ }
277
+ withMode(mode) {
278
+ return mode == this.mode ? this : new Context(mode, this.quote, this.heredocs, this.pod, this.regex, this.hash);
279
+ }
280
+ withHeredocs(heredocs) {
281
+ return heredocs == this.heredocs ? this : new Context(this.mode, this.quote, heredocs, this.pod, this.regex);
282
+ }
283
+ withQuote(mode, quote, heredocs = this.heredocs) {
284
+ return new Context(mode, quote, heredocs, this.pod, this.regex);
285
+ }
286
+ withPod(pod) { return new Context(this.mode, this.quote, this.heredocs, pod, this.regex); }
287
+ withRegex(regex) {
288
+ return new Context(this.mode, this.quote, this.heredocs, this.pod, regex);
289
+ }
290
+ }
291
+ // The nodes of a string: a quote, the token of a word list that
292
+ // interpolates, and the tree of its inside, which takes the place of
293
+ // that token.
294
+ const stringTerms = new Set([quotedString, interpolatingWordList, StringLiteral]);
295
+ // The mode after a token or a node, for those where the term settles
296
+ // it. Shifting a token and reusing a node both look here, so that they
297
+ // agree.
298
+ const termModes = new Map();
299
+ for (let term of [VariableName, AttributeName, SpecialVariable, operatorVariable, namedCapture, Number, radixNumber, Version, MethodName,
300
+ PairKey, rawString, quoteEnd, ...stringTerms, regexLiteral, transliteration, regexBody,
301
+ // The tree of the inside of a regex literal, which takes the
302
+ // place of the literal's token in a node that is reused.
303
+ Regex, self, True, False, Nil,
304
+ // The pieces of a regex. What follows them is more of
305
+ // the regex, or the brace that closes it.
306
+ regexText, CharacterClass, Assertion, regexQuote, regexOperator, regexComment,
307
+ regexBlockComment, regexCapture])
308
+ termModes.set(term, 1 /* Mode.AfterTerm */);
309
+ for (let term of [Identifier, TypeName, smiley, noSmiley, declaredName, declaredMethodName, declaredVariable, PackageName, RoutineName,
310
+ methodRoutineName, multiName, multiRoutineName, RegexName, EnumName, SubsetName, ConstantName])
311
+ termModes.set(term, 2 /* Mode.AfterName */);
312
+ // The `}` of "{...}" in a string does not take a subscript.
313
+ for (let term of [quoteContent, quoteNestOpen, quoteNestClose, NestedDelimiters, Interpolation])
314
+ termModes.set(term, 0 /* Mode.Term */);
315
+ for (let term of [multi, proto, only])
316
+ termModes.set(term, 4 /* Mode.AfterMulti */);
317
+ // The mode after the operator at offset `offset`, from its first three
318
+ // characters. `after` is the mode before it.
319
+ function modeAfterOperator(input, offset, first, second, third, after) {
320
+ // A lone `*` is as often the whatever star as a multiplication. After
321
+ // a term, it is the multiplication: in `$x * «-1 2»`, a word list follows.
322
+ if (first == 42 /* Ch.Star */ && !isOperatorChar(second))
323
+ return after == 1 /* Mode.AfterTerm */ || after == 3 /* Mode.AfterBlock */ && !atLineStart(input, offset) ? 2 /* Mode.AfterName */ : 5 /* Mode.AfterStar */;
324
+ // A power in superscript, $x², leaves the term complete. These are
325
+ // the characters that the grammar's Operator token takes for one.
326
+ // So does the empty set, ∅, which is a term.
327
+ if (first == 0xb2 || first == 0xb3 || first == 0xb9 || first == 0x2070 || first >= 0x2074 && first <= 0x207b ||
328
+ first == 0x2205 && second < 0)
329
+ return 1 /* Mode.AfterTerm */;
330
+ // Postfix increment and decrement leave the term complete. After a
331
+ // block, only on its line: the statement ends at the line break.
332
+ if ((first == 43 /* Ch.Plus */ || first == 45 /* Ch.Hyphen */) && second == first && !isOperatorChar(third) &&
333
+ (after == 1 /* Mode.AfterTerm */ || after == 3 /* Mode.AfterBlock */ && !atLineStart(input, offset)))
334
+ return 1 /* Mode.AfterTerm */;
335
+ return 0 /* Mode.Term */;
336
+ }
337
+ // The mode after a token that the terms file has no name for, from its
338
+ // first character. Keywords and identifiers come through here alike;
339
+ // an identifier gets its mode when the Identifier node is reduced,
340
+ // from modeAfter, which also looks at how it is spelled.
341
+ function modeAfterChar(first) {
342
+ if (first == 41 /* Ch.ParenClose */ || first == 93 /* Ch.BracketClose */ || first == 36 /* Ch.Dollar */ || first == 64 /* Ch.At */)
343
+ return 1 /* Mode.AfterTerm */;
344
+ // A capitalized name, taken to be a type.
345
+ if (first >= 65 /* Ch.A */ && first <= 90 /* Ch.Z */)
346
+ return 2 /* Mode.AfterName */;
347
+ return first == 125 /* Ch.BraceClose */ ? 3 /* Mode.AfterBlock */ : 0 /* Mode.Term */;
348
+ }
349
+ // The built-in names that stand for a value and take no arguments. The
350
+ // constant `e` is left out: a routine or a variable of one's own is too
351
+ // often named that.
352
+ const termWords = /^(pi|π|tau|τ|now|time|rand)$/;
353
+ // Whether the `<` at offset `at` follows the key of a pair, as in
354
+ // :ver<1> and :auth<zef:me>, and not a qualified name: Foo::Bar<x>
355
+ function isPairValue(input, at) {
356
+ let pos = at - 1;
357
+ while (pos > at - maxGap && continuesName(input, pos))
358
+ pos--;
359
+ return pos < at - 1 && input.peek(pos) == 58 /* Ch.Colon */ && input.peek(pos - 1) != 58 /* Ch.Colon */ &&
360
+ isIdentifierStart(input.peek(pos + 1));
361
+ }
362
+ // The mode after the token of the given term at the input's position.
363
+ // `before` is the mode before it, and `size` the token's length, which
364
+ // only an operator needs: one can be cut short of the operator
365
+ // characters after it, as the `*` of `*/2` and the `++` of `$i++/2`.
366
+ function modeAfter(term, input, offset, before, size = 0) {
367
+ // A term that takes no arguments is followed by an operator: pi /2
368
+ if (term == Identifier) {
369
+ let end = nameEnd(input, offset);
370
+ // Most names are longer than these, and are not looked at further.
371
+ if (end - offset <= 4 && termWords.test(word(input, offset, end)))
372
+ return 1 /* Mode.AfterTerm */;
373
+ }
374
+ // The value of a pair, as in :ver<1>, can be followed by a term: the
375
+ // import list of `use Foo:ver<1> <a b>`. Spacing decides, as after a name.
376
+ if ((term == rawString || term == quotedString) && input.peek(offset) == 60 /* Ch.Less */ && isPairValue(input, offset))
377
+ return 2 /* Mode.AfterName */;
378
+ let mode = termModes.get(term);
379
+ if (mode != null)
380
+ return mode;
381
+ let first = input.peek(offset);
382
+ if (term == Operator || term == wordOperator)
383
+ return modeAfterOperator(input, offset, first, size > 1 ? input.peek(offset + 1) : -1, size > 2 ? input.peek(offset + 2) : -1, before);
384
+ return modeAfterChar(first);
385
+ }
386
+ // The context at the start of a parse. The tokens that start the parse
387
+ // of the inside of another token are only looked for while the context
388
+ // is still this one, which spares asking the parser whether they can
389
+ // be shifted at every other token.
390
+ const startContext = new Context(0 /* Mode.Term */, null, noHeredocs, null, null);
391
+ // The tokens of the text of a heredoc, and the tree of its inside,
392
+ // which takes the place of the token of one that interpolates.
393
+ const heredocTerms = new Set([rawHeredoc, interpolatingHeredoc, heredocElement, interpolatingHeredocElement, Heredoc]);
394
+ const skippedTerms = new Set([LineComment, DocComment, BlockComment, ...heredocTerms, Pod, podStart, podEnd, podEndDirective,
395
+ podText, PodDirective, PodHeading, PodStrong, PodEmphasis, PodCode, PodLink, PodFormat]);
396
+ // The heredoc that the quote at offset `at` opens, when it opens one.
397
+ // Its terminator is what the quote holds: END for q:to/END/
398
+ function heredocAt(input, at) {
399
+ let first = input.peek(at);
400
+ if (first != 113 /* Ch.q */ && first != 81 /* Ch.Q */)
401
+ return null;
402
+ let opening = readOpening(input, at);
403
+ if (!opening || !opening.heredoc)
404
+ return null;
405
+ let end = opening.start;
406
+ while (input.peek(end) != opening.close && input.peek(end) != 10 /* Ch.Newline */ && input.peek(end) >= 0)
407
+ end++;
408
+ // An empty one, as in the `q:to//` of a quote that is being typed,
409
+ // would end the heredoc at the next blank line.
410
+ let terminator = word(input, opening.start, end).trim();
411
+ return terminator ? { terminator, interpolates: opening.interpolates == 63 /* Interpolate.All */ } : null;
412
+ }
413
+ // `heredocs`, with the heredoc that the quote at offset `at` opens, if
414
+ // it opens one.
415
+ function withHeredocAt(heredocs, input, at) {
416
+ let heredoc = heredocAt(input, at);
417
+ return heredoc ? heredocs.concat(heredoc) : heredocs;
418
+ }
419
+ function hasNewline(input, from, to) {
420
+ for (let i = from; i < to; i++)
421
+ if (input.peek(i) == 10 /* Ch.Newline */)
422
+ return true;
423
+ return false;
424
+ }
425
+ // The heredocs that are open after a reused node, of which the input is
426
+ // at the start. As when tokens are shifted, a line break between tokens
427
+ // and the text of a heredoc close the ones before them. `inQuote` tells
428
+ // that the node is a run of pieces of a quote.
429
+ function heredocsAfter(node, input, before, inQuote) {
430
+ // Most reused nodes are single tokens.
431
+ if (!node.children.length && !stringTerms.has(node.type.id) && !heredocTerms.has(node.type.id))
432
+ return before;
433
+ let cursor = node.cursor(), found = [], closedAt = -1;
434
+ // Goes over the node at the cursor, and tells whether the heredocs
435
+ // before some point in it are closed. It sets `closedAt` to the last
436
+ // such point in the node, or to -1.
437
+ function scan(text = false) {
438
+ closedAt = -1;
439
+ let type = cursor.type.id, { from, to } = cursor;
440
+ if (heredocTerms.has(type)) {
441
+ closedAt = to;
442
+ return true;
443
+ }
444
+ let isString = stringTerms.has(type);
445
+ if (isString) {
446
+ let heredoc = heredocAt(input, from);
447
+ if (heredoc)
448
+ found.push({ pos: from, heredoc });
449
+ }
450
+ // The tree of the inside of a regex literal or of a word list. It
451
+ // was one token when it was shifted, which opens no heredoc.
452
+ if (type == Regex || type == StringLiteral)
453
+ return false;
454
+ // Between the pieces of a string lies its text, not whitespace.
455
+ if (isString || text || type == NestedDelimiters) {
456
+ // Nothing between the pieces closes the heredocs, so there is no
457
+ // point at which a walk from the end could stop. The children are
458
+ // gone over from the start instead, as going back to the previous
459
+ // one in a buffer is a search from its start. The last child that
460
+ // closes the heredocs sets the point.
461
+ if (!cursor.firstChild())
462
+ return false;
463
+ let last = -1;
464
+ do {
465
+ if (scan())
466
+ last = closedAt;
467
+ } while (cursor.nextSibling());
468
+ closedAt = last;
469
+ cursor.parent();
470
+ return closedAt >= 0;
471
+ }
472
+ // Between the children of anything else lie tokens, and a line
473
+ // break there closes the heredocs, so the walk goes from the end and
474
+ // stops at the last one.
475
+ if (!cursor.lastChild())
476
+ return false;
477
+ for (let gapEnd = to;;) {
478
+ if (hasNewline(input, cursor.to, gapEnd)) {
479
+ closedAt = gapEnd;
480
+ break;
481
+ }
482
+ if (scan())
483
+ break;
484
+ gapEnd = cursor.from;
485
+ if (!cursor.prevSibling()) {
486
+ if (hasNewline(input, from, gapEnd))
487
+ closedAt = gapEnd;
488
+ break;
489
+ }
490
+ }
491
+ cursor.parent();
492
+ return closedAt >= 0;
493
+ }
494
+ // A piece on its own, such as an Interpolation, is a named node.
495
+ scan(inQuote && node.type.isAnonymous);
496
+ if (!found.length && closedAt < 0)
497
+ return before;
498
+ let after = found.filter(opener => opener.pos >= closedAt).sort((a, b) => a.pos - b.pos).map(opener => opener.heredoc);
499
+ return closedAt < 0 ? before.concat(after) : after.length ? after : noHeredocs;
500
+ }
501
+ // The last token in `node` that says what the mode after it is: one
502
+ // that is not a comment or Pod, which leave the mode as it was. A node
503
+ // that settles the mode by itself counts as a token. Null when the
504
+ // node holds nothing but comments.
505
+ function lastToken$1(node) {
506
+ if (termModes.has(node.type.id) || !node.lastChild)
507
+ return skippedTerms.has(node.type.id) ? null : node;
508
+ for (let child = node.lastChild; child; child = child.prevSibling) {
509
+ let found = skippedTerms.has(child.type.id) ? null : lastToken$1(child);
510
+ if (found)
511
+ return found;
512
+ }
513
+ return null;
514
+ }
515
+ // The token before `token` in `top`, by the same rule as lastToken.
516
+ // Null when there is none in it.
517
+ function tokenBefore$1(token, top) {
518
+ for (let node = token; node != top && node.parent; node = node.parent)
519
+ for (let sibling = node.prevSibling; sibling; sibling = sibling.prevSibling) {
520
+ let found = skippedTerms.has(sibling.type.id) ? null : lastToken$1(sibling);
521
+ if (found)
522
+ return found;
523
+ }
524
+ return null;
525
+ }
526
+ // The mode after a reused node, which `before` is the mode before. Only
527
+ // an operator's mode depends on the mode before it (a `++` is postfix
528
+ // after a term), so the operators at the end of the node are gone back
529
+ // over to the token before them, and their modes are worked out from
530
+ // there, as shifting them did. Null when the node holds no token.
531
+ function modeAfterNode(top, input, before) {
532
+ let last = lastToken$1(top);
533
+ if (!last)
534
+ return null;
535
+ let operators = [], token = last;
536
+ while (token && (token.type.id == Operator || token.type.id == wordOperator)) {
537
+ operators.push(token);
538
+ token = tokenBefore$1(token, top);
539
+ }
540
+ // The node's positions count from its start, where the input is.
541
+ let mode = token ? modeAfter(token.type.id, input, token.from, before, token.to - token.from) : before;
542
+ for (let i = operators.length - 1; i >= 0; i--)
543
+ mode = modeAfter(operators[i].type.id, input, operators[i].from, mode, operators[i].to - operators[i].from);
544
+ return mode;
545
+ }
546
+ const trackContext = new lr.ContextTracker({
547
+ start: startContext,
548
+ shift(context, term, stack, input) {
549
+ if (heredocTerms.has(term))
550
+ return context.withHeredocs(noHeredocs);
551
+ // The text of a heredoc that interpolates is read by a parser of
552
+ // its own, as a quote without delimiters.
553
+ if (term == heredocStart)
554
+ return context.withQuote(0 /* Mode.Term */, heredocQuote);
555
+ // Error recovery can insert a podStart of no length where there is
556
+ // no directive. That starts no block, or the text up to the next
557
+ // blank line would become Pod.
558
+ if (term == podStart) {
559
+ let end = podDirectiveEnd(input);
560
+ return end > 0 ? context.withPod(readPodStart(input, end)) : context;
561
+ }
562
+ if (term == podEnd || term == podEndDirective)
563
+ return context.withPod(null);
564
+ if (skippedTerms.has(term))
565
+ return context;
566
+ let { regex } = context;
567
+ if (term == regexStart)
568
+ return context.withRegex(new RegexBody(regex, 0));
569
+ if (term == regexBodyEnd)
570
+ return context.withRegex(regex && regex.parent).withMode(termModes.get(regexBody));
571
+ // The inside of a regex literal is read by a parser of its own, of
572
+ // which these are the first and the last token. The closing
573
+ // delimiter is found the way termToken found it when it made the
574
+ // literal one token, so that the two agree on where the regex ends.
575
+ if (term == regexLitOpen) {
576
+ let opening = regexOpening(input), end = opening ? regexEnd(input, opening) : -1;
577
+ // Without one, which takes a parse that does not start from a
578
+ // literal, the regex runs to the end of what is parsed.
579
+ return context.withRegex(new RegexBody(null, 0, end < 0 ? Infinity : input.pos + end));
580
+ }
581
+ if (term == regexLitClose)
582
+ return context.withRegex(null);
583
+ // The braces of a block of code in a regex, and of the blocks in it.
584
+ // The tokens `{` and `}` have no term to go by.
585
+ if (regex && !termModes.has(term)) {
586
+ if (input.next == 123 /* Ch.BraceOpen */)
587
+ context = context.withRegex(regex.withBraces(regex.braces + 1));
588
+ else if (input.next == 125 /* Ch.BraceClose */ && regex.braces > 0)
589
+ context = context.withRegex(regex.withBraces(regex.braces - 1));
590
+ }
591
+ switch (term) {
592
+ case quoteStart: {
593
+ let opening = wordListOpening(input, 0) || readOpening(input);
594
+ if (!opening)
595
+ return context;
596
+ let quote = new Quote(context.quote, opening.open, opening.close, opening.count, opening.interpolates, opening.escapes);
597
+ return context.withQuote(0 /* Mode.Term */, quote, withHeredocAt(context.heredocs, input, 0));
598
+ }
599
+ case quoteEnd:
600
+ return context.withQuote(1 /* Mode.AfterTerm */, context.quote && context.quote.parent);
601
+ }
602
+ // The whitespace token has no term to go by. It is the only token
603
+ // that starts with a space. A line break in it leaves the heredocs
604
+ // that found no terminator behind.
605
+ if (!termModes.has(term) && isSpace(input.next)) {
606
+ if (!context.heredocs.length)
607
+ return context;
608
+ for (let pos = 0; isSpace(input.peek(pos)); pos++)
609
+ if (input.peek(pos) == 10 /* Ch.Newline */)
610
+ return context.withHeredocs(noHeredocs);
611
+ return context;
612
+ }
613
+ if (term == rawString)
614
+ context = context.withHeredocs(withHeredocAt(context.heredocs, input, 0));
615
+ // In the body of a regex, a line break is in the text of the regex,
616
+ // which is no node. Like a line break between tokens, it leaves the
617
+ // heredocs that found no terminator behind, as heredocsAfter takes
618
+ // a line break between nodes to do.
619
+ if (term == regexText && context.heredocs.length && hasNewline(input, 0, stack.pos - input.pos))
620
+ context = context.withHeredocs(noHeredocs);
621
+ // The input is at the start of the token, and the stack at its end.
622
+ return context.withMode(modeAfter(term, input, 0, context.mode, stack.pos - input.pos));
623
+ },
624
+ reduce(context, term, _stack, input) {
625
+ // The input is at the start of the node that is reduced.
626
+ return term == Identifier || term == Interpolation ? context.withMode(modeAfter(term, input, 0, context.mode))
627
+ : context;
628
+ },
629
+ // A node that is reused leaves the quote and the regex of the context
630
+ // as they are: the grammar pairs the delimiters that nest in a quote
631
+ // (NestedDelimiters) and the braces of a block, so a node closes what
632
+ // it opens.
633
+ reuse(context, node, stack, input) {
634
+ let inQuote = context.quote != null && inQuoteText(stack);
635
+ context = context.withHeredocs(heredocsAfter(node, input, context.heredocs, inQuote));
636
+ let mode = modeAfterNode(node.topNode, input, context.mode);
637
+ return mode == null ? context : context.withMode(mode);
638
+ },
639
+ hash: context => context.hash
640
+ });
641
+ function context(stack) { return stack.context; }
642
+ // Whether a token of `size` characters at the current position is where
643
+ // a term starts, as opposed to an infix operator.
644
+ function inTermPosition(input, mode, size) {
645
+ if (mode == 0 /* Mode.Term */ || mode == 4 /* Mode.AfterMulti */)
646
+ return true;
647
+ if (mode == 1 /* Mode.AfterTerm */)
648
+ return false;
649
+ if (mode == 2 /* Mode.AfterName */ || mode == 5 /* Mode.AfterStar */)
650
+ return isSpace(input.peek(-1)) && !isSpace(input.peek(size));
651
+ return atLineStart(input);
652
+ }
653
+ // ---- Comments and Pod ----
654
+ // #`( ... ), with any bracket pair. A repeated opening bracket, as in
655
+ // #`(( ... )), needs the same number of closing ones. Brackets of the
656
+ // same kind nest. An unclosed comment runs to the end of the input.
657
+ const blockComment = new lr.ExternalTokenizer(input => {
658
+ let end = embeddedCommentEnd(input, 0);
659
+ if (!end)
660
+ return;
661
+ // A declarator comment with brackets, #|( ... ) and #=( ... ), is
662
+ // still a declarator comment.
663
+ let term = input.peek(1) == 96 /* Ch.Backtick */ ? BlockComment : DocComment;
664
+ if (end < 0)
665
+ skipToEnd(input);
666
+ else
667
+ input.advance(end);
668
+ input.acceptToken(term);
669
+ });
670
+ // The offset after the embedded comment that starts at offset `at`.
671
+ // Zero when none starts there, and -1 when it is not closed.
672
+ //
673
+ // A declarator comment with brackets that is not closed is none: it is
674
+ // left to be a comment of one line, so that one that is being typed
675
+ // does not take the declarations after it.
676
+ function embeddedCommentEnd(input, at) {
677
+ let mark = input.peek(at + 1);
678
+ if (input.peek(at) != 35 /* Ch.Hash */ || mark != 96 /* Ch.Backtick */ && mark != 124 /* Ch.Pipe */ && mark != 61 /* Ch.Equals */)
679
+ return 0;
680
+ let open = input.peek(at + 2), close = brackets$1[open];
681
+ if (close == null)
682
+ return 0;
683
+ let count = 1;
684
+ while (input.peek(at + 2 + count) == open)
685
+ count++;
686
+ let end = rawEnd(input, at + 2 + count, { open, close, count, escapes: false });
687
+ return end < 0 && mark != 96 /* Ch.Backtick */ ? 0 : end;
688
+ }
689
+ // The byte order mark counts, so that a directive after it, at the start
690
+ // of a file, is at the start of a line.
691
+ function isBlank(ch) { return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 13 /* Ch.Return */ || ch == 0xfeff; }
692
+ // The offset of the first character at or after `pos` that is not a blank.
693
+ function blanksEnd(input, pos) {
694
+ while (isBlank(input.peek(pos)))
695
+ pos++;
696
+ return pos;
697
+ }
698
+ // How far a token looks over the whitespace after it, to see what
699
+ // follows. A token must not look far past its end: see the note on
700
+ // lookahead in AGENTS.md.
701
+ const maxGap = 20;
702
+ // The offset of the first character at or after `pos` that is not a
703
+ // blank, or not whitespace when `lines` is set, going over at most
704
+ // maxGap characters.
705
+ function gapEnd(input, pos, lines = false) {
706
+ for (let end = pos + maxGap; pos < end && (lines ? isSpace : isBlank)(input.peek(pos));)
707
+ pos++;
708
+ return pos;
709
+ }
710
+ // Whether only blanks separate offset `pos` from the start of its line.
711
+ function atLineStart(input, pos = 0) {
712
+ for (let i = pos - 1;; i--) {
713
+ let ch = input.peek(i);
714
+ if (ch == 10 /* Ch.Newline */ || ch < 0)
715
+ return true;
716
+ if (!isBlank(ch))
717
+ return false;
718
+ }
719
+ }
720
+ // Whether only blanks separate offset `pos` from the end of its line.
721
+ function isLineEnd(input, pos) {
722
+ let ch = input.peek(blanksEnd(input, pos));
723
+ return ch == 10 /* Ch.Newline */ || ch < 0;
724
+ }
725
+ function skipLine(input) {
726
+ while (input.next >= 0 && input.next != 10 /* Ch.Newline */)
727
+ input.advance();
728
+ }
729
+ function skipToEnd(input) {
730
+ while (input.next >= 0)
731
+ input.advance();
732
+ }
733
+ function skipBlanks(input) {
734
+ input.advance(blanksEnd(input, 0));
735
+ }
736
+ // Skips blanks, and tells whether the rest of the line starts with `text`.
737
+ function lineStartsWith(input, text) {
738
+ skipBlanks(input);
739
+ return startsWith(input, 0, text);
740
+ }
741
+ // Whether the text from offset `pos` starts with `text`, as a whole name.
742
+ function startsWith(input, pos, text) {
743
+ for (let i = 0; i < text.length; i++)
744
+ if (input.peek(pos + i) != text.charCodeAt(i))
745
+ return false;
746
+ return !continuesName(input, pos + text.length);
747
+ }
748
+ const podDirective = /^(begin|for|end|finish|head\d*|item\d*|para|code|input|output|defn|comment|table|pod|rakudoc|config|alias|nested|data|[A-Z]{2,})$/;
749
+ const podCodeBlock = /^(code|input|output)$/;
750
+ // The offset after the directive that starts at the current position,
751
+ // as in `=begin` or `=head1`, or -1 when there is none.
752
+ function podDirectiveEnd(input) {
753
+ if (input.next != 61 /* Ch.Equals */ || !isAsciiLetter(input.peek(1)) || !atLineStart(input))
754
+ return -1;
755
+ let end = 1;
756
+ while (isAsciiLetter(input.peek(end)) || isDigit(input.peek(end)))
757
+ end++;
758
+ let directive = word(input, 1, end);
759
+ if (!podDirective.test(directive) || continuesName(input, end))
760
+ return -1;
761
+ // A semantic block such as =TITLE has to start in the first column.
762
+ // An indented `=FOO + 1` continues an assignment.
763
+ if (directive.charCodeAt(0) <= 90 /* Ch.Z */ && input.peek(-1) >= 0 && input.peek(-1) != 10 /* Ch.Newline */)
764
+ return -1;
765
+ return end;
766
+ }
767
+ // The offset after the name that goes with a directive which ends at
768
+ // offset `end`: `=begin pod`, `=for comment`, `=end code`. The other
769
+ // directives have none.
770
+ function podNameEnd(input, end) {
771
+ if (!/^(begin|for|end)$/.test(word(input, 1, end)))
772
+ return end;
773
+ let name = nameEnd(input, blanksEnd(input, end));
774
+ return name < 0 ? end : name;
775
+ }
776
+ // The block that the directive at the current position, which ends at
777
+ // offset `end`, starts.
778
+ // =begin name ... =end name delimited, can hold blocks of other names
779
+ // =finish the rest of the file
780
+ // =for name, =head1, ... up to the next blank line
781
+ function readPodStart(input, end) {
782
+ let directive = word(input, 1, end);
783
+ if (directive == "finish")
784
+ return new PodBlock(2 /* PodKind.Finish */, "", false);
785
+ let nameStart = blanksEnd(input, end), name = word(input, nameStart, Math.max(nameStart, nameEnd(input, nameStart)));
786
+ if (directive == "begin")
787
+ return new PodBlock(0 /* PodKind.Delimited */, name, podCodeBlock.test(name));
788
+ return new PodBlock(1 /* PodKind.Paragraph */, "", podCodeBlock.test(directive == "for" ? name : directive));
789
+ }
790
+ // Whether the current position is right after a `=head` directive,
791
+ // where the text of the heading starts.
792
+ function atHeadingText(input) {
793
+ let pos = -1;
794
+ while (isDigit(input.peek(pos)))
795
+ pos--;
796
+ for (let i = 0; i < 5; i++)
797
+ if (input.peek(pos - i) != "=head".charCodeAt(4 - i))
798
+ return false;
799
+ for (pos -= 5; isBlank(input.peek(pos)); pos--) { }
800
+ return input.peek(pos) < 0 || input.peek(pos) == 10 /* Ch.Newline */;
801
+ }
802
+ // Whether a formatting code starts at offset `pos`: B<, C<<, L«
803
+ function isFormattingCode(input, pos) {
804
+ let ch = input.peek(pos), after = input.peek(pos + 1), before = input.peek(pos - 1);
805
+ return ch >= 65 /* Ch.A */ && ch <= 90 /* Ch.Z */ && (after == 60 /* Ch.Less */ || after == 171 /* Ch.GuillemetOpen */) &&
806
+ !isAsciiLetter(before) && !isDigit(before);
807
+ }
808
+ // The offset after the formatting code at the current position. When
809
+ // the code is not closed in its paragraph, this is the negated offset
810
+ // of the end of the text that was gone over to find that out.
811
+ function formattingCodeEnd(input) {
812
+ let open = input.peek(1), close = brackets$1[open], count = 1;
813
+ while (open == 60 /* Ch.Less */ && input.peek(1 + count) == open)
814
+ count++;
815
+ for (let pos = 1 + count, depth = 1;; pos++) {
816
+ let ch = input.peek(pos);
817
+ if (ch < 0)
818
+ return -pos;
819
+ if (ch == 10 /* Ch.Newline */) {
820
+ // A blank line or a directive ends the paragraph.
821
+ let next = blanksEnd(input, pos + 1), after = input.peek(next);
822
+ if (after < 0 || after == 10 /* Ch.Newline */ || after == 61 /* Ch.Equals */ && isAsciiLetter(input.peek(next + 1)))
823
+ return -pos;
824
+ }
825
+ else if (ch == close && repeats(input, pos, close, count)) {
826
+ pos += count - 1;
827
+ if (--depth == 0)
828
+ return pos + 1;
829
+ }
830
+ else if (ch == open && count == 1) {
831
+ // C<a < b> is not closed by the first `>` when another `<` came before it.
832
+ depth++;
833
+ }
834
+ }
835
+ }
836
+ const formattingTerms = { 66: PodStrong, 73: PodEmphasis, 67: PodCode, 76: PodLink };
837
+ // The pieces of a Pod block, which starts with a `=directive` at the
838
+ // start of a line. What it is, and with that where it ends, is kept in
839
+ // the context.
840
+ const podToken = new lr.ExternalTokenizer((input, stack) => {
841
+ let { pod } = context(stack);
842
+ if (!pod) {
843
+ let end = podDirectiveEnd(input);
844
+ if (end > 0)
845
+ input.acceptToken(podStart, podNameEnd(input, end));
846
+ return;
847
+ }
848
+ let next = input.next;
849
+ if (next < 0)
850
+ return input.acceptToken(podEnd);
851
+ if (next == 10 /* Ch.Newline */ && pod.kind == 1 /* PodKind.Paragraph */) {
852
+ // Ends before a blank line or another directive.
853
+ let pos = blanksEnd(input, 1), ch = input.peek(pos);
854
+ if (ch == 10 /* Ch.Newline */ || ch < 0 || ch == 61 /* Ch.Equals */ && isAsciiLetter(input.peek(pos + 1)))
855
+ return input.acceptToken(podEnd);
856
+ }
857
+ let directive = pod.kind == 0 /* PodKind.Delimited */ ? podDirectiveEnd(input) : -1;
858
+ if (directive > 0) {
859
+ if (directive == 4 && startsWith(input, 1, "end") && startsWith(input, blanksEnd(input, 4), pod.name)) {
860
+ skipLine(input);
861
+ return input.acceptToken(podEndDirective);
862
+ }
863
+ return input.acceptToken(PodDirective, podNameEnd(input, directive));
864
+ }
865
+ if (atHeadingText(input) && !isLineEnd(input, 0)) {
866
+ skipLine(input);
867
+ return input.acceptToken(PodHeading);
868
+ }
869
+ if (!pod.code && isFormattingCode(input, 0)) {
870
+ let end = formattingCodeEnd(input);
871
+ if (end > 0)
872
+ return input.acceptToken(formattingTerms[next] || PodFormat, end);
873
+ // What looked like a code is text. The text that was gone over is
874
+ // made one token, so that no token has looked beyond its own end.
875
+ // A token that does keeps the tokens before it from being reused.
876
+ return input.acceptToken(podText, -end);
877
+ }
878
+ // Text, up to where one of the above may apply.
879
+ for (;;) {
880
+ input.advance();
881
+ let ch = input.next;
882
+ if (ch < 0 || ch == 10 /* Ch.Newline */ || !pod.code && isFormattingCode(input, 0))
883
+ break;
884
+ // A directive can only follow the blanks at the start of a line.
885
+ if (ch == 61 /* Ch.Equals */ && atLineStart(input))
886
+ break;
887
+ }
888
+ input.acceptToken(podText);
889
+ });
890
+ const quoteWords = {
891
+ q: "raw", Q: "raw", qw: "raw", qww: "raw", qx: "raw", Qw: "raw", Qww: "raw", Qx: "raw",
892
+ qq: "interpolating", qqw: "interpolating", qqww: "interpolating", qqx: "interpolating",
893
+ rx: "regex", m: "regex", ms: "regex",
894
+ s: "substitution", ss: "substitution", S: "substitution",
895
+ // Like a substitution, but its first part is not a regex.
896
+ tr: "transliteration", TR: "transliteration"
897
+ };
898
+ // The kinds of interpolation that the adverbs of a quote switch.
899
+ const interpolationAdverbs = new Map([
900
+ ["c", 1 /* Interpolate.Closure */], ["closure", 1 /* Interpolate.Closure */],
901
+ ["s", 2 /* Interpolate.Scalar */], ["scalar", 2 /* Interpolate.Scalar */],
902
+ ["a", 4 /* Interpolate.Array */], ["array", 4 /* Interpolate.Array */],
903
+ ["h", 8 /* Interpolate.Hash */], ["hash", 8 /* Interpolate.Hash */],
904
+ ["f", 16 /* Interpolate.Function */], ["function", 16 /* Interpolate.Function */],
905
+ ["b", 32 /* Interpolate.Backslash */], ["backslash", 32 /* Interpolate.Backslash */],
906
+ ["qq", 63 /* Interpolate.All */], ["double", 63 /* Interpolate.All */]
907
+ ]);
908
+ // The opening of a word list that interpolates, at offset `at`: << or «
909
+ function wordListOpening(input, at) {
910
+ let open = input.peek(at), count = open == 60 /* Ch.Less */ ? 2 : 1;
911
+ if (open != 171 /* Ch.GuillemetOpen */ && !(open == 60 /* Ch.Less */ && input.peek(at + 1) == 60 /* Ch.Less */))
912
+ return null;
913
+ return { open, close: brackets$1[open], count, start: at + count, kind: "interpolating",
914
+ interpolates: 63 /* Interpolate.All */, escapes: true };
915
+ }
916
+ // The opening of a quote that starts with a quote character at offset `at`.
917
+ function quoteCharOpening(open, close, at, interpolates, escapes = true) {
918
+ return { open, close, count: 1, start: at + 1, kind: interpolates ? "interpolating" : "raw", interpolates, escapes };
919
+ }
920
+ // The delimiters, other than brackets, that are accepted after a quote word.
921
+ function isQuoteDelimiter(ch) {
922
+ return ch == 47 /* Ch.Slash */ || ch == 33 /* Ch.Bang */ || ch == 124 /* Ch.Pipe */ || ch == 126 /* Ch.Tilde */ || ch == 94 /* Ch.Caret */ ||
923
+ ch == 37 /* Ch.Percent */ || ch == 64 /* Ch.At */ || ch == 34 /* Ch.DoubleQuote */ || ch == 39 /* Ch.Apostrophe */ || ch == 96 /* Ch.Backtick */ ||
924
+ // A symbol outside of ASCII: Q♥a♥
925
+ ch > 0xa0 && ch != 0xd7 && ch != 0xf7 && !isIdentifierStart(ch) && !isSpace(ch) && ch < 0xd800;
926
+ }
927
+ // Reads the start of a quote at offset `at`: a quote character, or a
928
+ // quote word (q, qq, m, s, ...) with its adverbs and its delimiter.
929
+ // The offsets in the result count from the current position.
930
+ function readOpening(input, at = 0) {
931
+ let next = input.peek(at);
932
+ if (next == 34 /* Ch.DoubleQuote */)
933
+ return quoteCharOpening(next, next, at, 63 /* Interpolate.All */);
934
+ if (next == 39 /* Ch.Apostrophe */)
935
+ return quoteCharOpening(next, next, at, 0);
936
+ if (next == 0x201c /* “ */)
937
+ return quoteCharOpening(next, 0x201d, at, 63 /* Interpolate.All */);
938
+ if (next == 0x2018 /* ‘ */)
939
+ return quoteCharOpening(next, 0x2019, at, 0);
940
+ if (next == 0x201e /* „ */)
941
+ return quoteCharOpening(next, 0x201d, at, 63 /* Interpolate.All */);
942
+ if (next == 0x201d /* ” */)
943
+ return quoteCharOpening(next, next, at, 63 /* Interpolate.All */);
944
+ if (next == 0x201a /* ‚ */)
945
+ return quoteCharOpening(next, 0x2019, at, 0);
946
+ if (next == 0x300c /* 「 */)
947
+ return quoteCharOpening(next, 0x300d, at, 0, false);
948
+ if (next == 0xff62 /* 「 */)
949
+ return quoteCharOpening(next, 0xff63, at, 0, false);
950
+ if (!isAsciiLetter(next))
951
+ return null;
952
+ let pos = at + 1;
953
+ while (isAsciiLetter(input.peek(pos)))
954
+ pos++;
955
+ if (pos - at > 4)
956
+ return null;
957
+ let name = word(input, at, pos), kind = quoteWords[name];
958
+ if (!kind)
959
+ return null;
960
+ // Adverbs: :w, :to, :g, :x(2). Those of a regex mean other things
961
+ // than those of a quote: m:s/a b/
962
+ let adverbs = false, heredoc = false, isQuote = kind == "raw" || kind == "interpolating";
963
+ let interpolates = kind == "interpolating" ? 63 /* Interpolate.All */ : 0;
964
+ // Whether a backslash escapes the delimiter, apart from the escapes
965
+ // of :b. That comes with q and its :q adverb: Q and qq:!b have none.
966
+ let escapes = isQuote ? kind == "raw" && next == 113 /* Ch.q */ : true;
967
+ // The adverbs of a quote can follow blanks on the same line: Q :q [a]
968
+ if (isQuote && isBlank(input.peek(pos))) {
969
+ let adverb = gapEnd(input, pos);
970
+ if (input.peek(adverb) == 58 /* Ch.Colon */)
971
+ pos = adverb;
972
+ }
973
+ for (;;) {
974
+ if (input.peek(pos) != 58 /* Ch.Colon */)
975
+ break;
976
+ // An adverb can start with its count: m:2nd/a/, s:3x/a/b/
977
+ let letter = pos + 1;
978
+ while (isDigit(input.peek(letter)))
979
+ letter++;
980
+ if (!isAsciiLetter(input.peek(letter)) && !(letter == pos + 1 && input.peek(letter) == 33 /* Ch.Bang */))
981
+ break;
982
+ adverbs = true;
983
+ let negated = input.peek(pos + 1) == 33 /* Ch.Bang */, adverbStart = pos + (negated ? 2 : 1);
984
+ pos = letter + 1;
985
+ while (isAsciiLetter(input.peek(pos)) || isDigit(input.peek(pos)))
986
+ pos++;
987
+ let adverb = word(input, adverbStart, pos);
988
+ // An argument that is False or 0 switches the adverb off: q:c(False)
989
+ if (input.peek(pos) == 40 /* Ch.ParenOpen */) {
990
+ let argStart = pos + 1;
991
+ while (input.peek(pos) != 41 /* Ch.ParenClose */) {
992
+ if (input.peek(pos) < 0 || input.peek(pos) == 10 /* Ch.Newline */)
993
+ return null;
994
+ pos++;
995
+ }
996
+ if (/^\s*(False|0)\s*$/.test(word(input, argStart, pos)))
997
+ negated = true;
998
+ pos++;
999
+ }
1000
+ if (isQuote) {
1001
+ let bits = interpolationAdverbs.get(adverb);
1002
+ if (bits != null)
1003
+ interpolates = negated ? interpolates & ~bits : interpolates | bits;
1004
+ else if (!negated && (adverb == "q" || adverb == "single"))
1005
+ escapes = true;
1006
+ else if (!negated && (adverb == "to" || adverb == "heredoc"))
1007
+ heredoc = true;
1008
+ }
1009
+ }
1010
+ if (!adverbs && continuesName(input, pos))
1011
+ return null;
1012
+ // The delimiter follows directly, or, for q, qq and Q, after blanks
1013
+ // on the same line: q {...}. Not for m, s and the others: `s { ... }`
1014
+ // and `m ($x)` are more often calls of a routine of one's own.
1015
+ if (isQuote && isBlank(input.peek(pos))) {
1016
+ let bracket = gapEnd(input, pos);
1017
+ if (brackets$1[input.peek(bracket)] != null && input.peek(bracket) != 40 /* Ch.ParenOpen */)
1018
+ pos = bracket;
1019
+ }
1020
+ let open = input.peek(pos), close = brackets$1[open];
1021
+ if (close == null) {
1022
+ if (!isQuoteDelimiter(open))
1023
+ return null;
1024
+ close = open;
1025
+ }
1026
+ // q(...) is a call.
1027
+ if (open == 40 /* Ch.ParenOpen */ && !adverbs)
1028
+ return null;
1029
+ let count = 1;
1030
+ if (close != open)
1031
+ while (input.peek(pos + count) == open)
1032
+ count++;
1033
+ if (isQuote)
1034
+ kind = interpolates ? "interpolating" : "raw";
1035
+ if (interpolates & 32 /* Interpolate.Backslash */)
1036
+ escapes = true;
1037
+ return { open, close, count, start: pos + count, kind, interpolates, escapes, heredoc };
1038
+ }
1039
+ // The offset after the delimiter that closes a quote whose content
1040
+ // starts at `pos`, or -1 when it is not closed.
1041
+ function rawEnd(input, pos, opening) {
1042
+ let { open, close, count } = opening, other = otherClose(open);
1043
+ for (let depth = 1;;) {
1044
+ let ch = input.peek(pos);
1045
+ if (ch < 0)
1046
+ return -1;
1047
+ if (ch == 92 /* Ch.Backslash */ && opening.escapes)
1048
+ pos += 2;
1049
+ else if (ch == close && repeats(input, pos, close, count) || ch == other) {
1050
+ pos += count;
1051
+ if (--depth == 0)
1052
+ return pos;
1053
+ }
1054
+ else if (ch == open && repeats(input, pos, open, count)) {
1055
+ pos += count;
1056
+ depth++;
1057
+ }
1058
+ else
1059
+ pos++;
1060
+ }
1061
+ }
1062
+ // The character that closes a quote in a regex that opens with `ch`,
1063
+ // or 0 when `ch` opens none: 'a', "a", ‘a’, ‚a’, “a”, „a”, 「a」
1064
+ function quoteClose(ch) {
1065
+ return ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */ ? ch : ch == 0x2018 || ch == 0x201a ? 0x2019 :
1066
+ ch == 0x201c || ch == 0x201e ? 0x201d : ch == 0xff62 ? 0xff63 : 0;
1067
+ }
1068
+ // A low quote is also closed by the quote that points the other way:
1069
+ // ‚a‘, „a“. This is that quote for the given opening one, or -1.
1070
+ function otherClose(open) { return open == 0x201a ? 0x2018 : open == 0x201e ? 0x201c : -1; }
1071
+ // The offset after a quoted string that starts at `pos`, or -1.
1072
+ function quotedEnd(input, pos) {
1073
+ let open = input.peek(pos), close = quoteClose(open), other = otherClose(open);
1074
+ for (pos++;;) {
1075
+ let ch = input.peek(pos);
1076
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1077
+ return -1;
1078
+ // Nothing is escaped in 「...」.
1079
+ if (ch == 92 /* Ch.Backslash */ && open != 0xff62)
1080
+ pos += 2;
1081
+ else if (ch == close || ch == other)
1082
+ return pos + 1;
1083
+ else
1084
+ pos++;
1085
+ }
1086
+ }
1087
+ // The offset after the names and the arguments of the assertion that
1088
+ // starts with the `<` at `pos`, or 0 when no name starts it. The
1089
+ // arguments are code, in which the delimiter of the regex does not end
1090
+ // it: <name(1/2)>, <:name(/x/)>, <name: /a<b>+/ >. A name takes in an
1091
+ // apostrophe before a letter, which starts no quote: <it's>
1092
+ function assertionArgumentsEnd(input, pos) {
1093
+ // An assertion can add up several names: <+:Lu +:name(/SMALL/)>
1094
+ for (let at = pos + 1, names = 0;;) {
1095
+ while (isAssertionMark(input.peek(at)) || isBlank(input.peek(at)))
1096
+ at++;
1097
+ let end = nameEnd(input, at);
1098
+ if (end < 0)
1099
+ return names;
1100
+ // With parentheses, up to the one that closes them. After a colon
1101
+ // and a space, up to the `>` that closes the assertion.
1102
+ let open = input.peek(end);
1103
+ if (open == 40 /* Ch.ParenOpen */)
1104
+ return balancedEnd(input, end + 1, 40 /* Ch.ParenOpen */, 41 /* Ch.ParenClose */);
1105
+ if (open == 58 /* Ch.Colon */ && isBlank(input.peek(end + 1)))
1106
+ return balancedEnd(input, end + 1, 60 /* Ch.Less */, 62 /* Ch.Greater */);
1107
+ at = names = end;
1108
+ // The name of an alias is followed by the assertion it names: <foo=it's>
1109
+ if (input.peek(at) == 61 /* Ch.Equals */)
1110
+ at++;
1111
+ else if (!isAssertionMark(input.peek(at)) && !isBlank(input.peek(at)))
1112
+ return names;
1113
+ }
1114
+ }
1115
+ // The characters that come before the name in an assertion: <.ws>, <?before>, <+alpha>
1116
+ function isAssertionMark(ch) {
1117
+ return ch == 46 /* Ch.Dot */ || ch == 63 /* Ch.Question */ || ch == 33 /* Ch.Bang */ || ch == 58 /* Ch.Colon */ || ch == 38 /* Ch.Amp */ || ch == 43 /* Ch.Plus */ ||
1118
+ ch == 45 /* Ch.Hyphen */;
1119
+ }
1120
+ // The offset after the names and the code that the `<` or `:` at `pos`
1121
+ // in a regex starts, or 0 when it starts neither.
1122
+ function regexCodeEnd(input, pos) {
1123
+ return input.peek(pos) == 60 /* Ch.Less */ ? assertionArgumentsEnd(input, pos) : regexDeclarationEnd(input, pos);
1124
+ }
1125
+ // The offset after the declaration that starts with the `:` at `pos`
1126
+ // in a regex, or 0 when none does: `:my $c = $/;`. It is code up to
1127
+ // its `;`, in which the delimiter of the regex does not end it.
1128
+ function regexDeclarationEnd(input, pos) {
1129
+ let end = nameEnd(input, pos + 1);
1130
+ if (end < 0 || end - pos > 9 || !isBlank(input.peek(end)) ||
1131
+ !/^(my|our|state|constant|temp|let)$/.test(word(input, pos + 1, end)))
1132
+ return 0;
1133
+ for (;;) {
1134
+ let ch = input.peek(end);
1135
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1136
+ return 0;
1137
+ if (ch == 59 /* Ch.Semicolon */)
1138
+ return end + 1;
1139
+ let quoted = quoteClose(ch) ? quotedEnd(input, end) : isIdentifierStart(ch) ? nameEnd(input, end) : -1;
1140
+ end = quoted > 0 ? quoted : end + 1;
1141
+ }
1142
+ }
1143
+ // The offset after the `close` that matches an `open` before `pos`, or
1144
+ // 0 when there is none on the line. Quotes are gone over, and so are
1145
+ // names, which take in an apostrophe before a letter: don't
1146
+ function balancedEnd(input, pos, open, close) {
1147
+ for (let depth = 1;;) {
1148
+ let ch = input.peek(pos);
1149
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1150
+ return 0;
1151
+ if (ch == 92 /* Ch.Backslash */)
1152
+ pos += 2;
1153
+ else if (isIdentifierStart(ch))
1154
+ pos = nameEnd(input, pos);
1155
+ else if (quoteClose(ch)) {
1156
+ let quoted = quotedEnd(input, pos);
1157
+ pos = quoted < 0 ? pos + 1 : quoted;
1158
+ }
1159
+ else {
1160
+ pos++;
1161
+ if (ch == open)
1162
+ depth++;
1163
+ else if (ch == close && --depth == 0)
1164
+ return pos;
1165
+ }
1166
+ }
1167
+ }
1168
+ // The offset of the delimiter that closes a regex whose content starts
1169
+ // at `pos`, or -1. Delimiters do not count inside quotes, character
1170
+ // classes, comments and code blocks. `code` is set for the inside of a
1171
+ // code block, where a `<` is an operator, and a name takes in an
1172
+ // apostrophe before a letter, which starts no quote there: don't()
1173
+ function regexEnd(input, { start: pos, open, close, count }, code = false) {
1174
+ for (let depth = 1, codeEnd;;) {
1175
+ let ch = input.peek(pos);
1176
+ if (ch < 0)
1177
+ return -1;
1178
+ if (ch == 92 /* Ch.Backslash */) {
1179
+ pos += 2;
1180
+ }
1181
+ else if (ch == close && repeats(input, pos, close, count)) {
1182
+ if (--depth == 0)
1183
+ return pos;
1184
+ pos += count;
1185
+ }
1186
+ else if (ch == open && repeats(input, pos, open, count)) {
1187
+ // In a regex in braces, a brace opens a block of code, as it
1188
+ // does in other regexes (below): m{ a { don't() } }. When the
1189
+ // block is not closed, neither is the regex.
1190
+ if (!code && open == 123 /* Ch.BraceOpen */ && count == 1) {
1191
+ let end = regexEnd(input, { start: pos + 1, open, close, count }, true);
1192
+ if (end < 0)
1193
+ return -1;
1194
+ pos = end + 1;
1195
+ }
1196
+ else {
1197
+ pos += count;
1198
+ depth++;
1199
+ }
1200
+ }
1201
+ else if (code && isIdentifierStart(ch)) {
1202
+ pos = nameEnd(input, pos);
1203
+ }
1204
+ else if (quoteClose(ch)) {
1205
+ let end = quotedEnd(input, pos);
1206
+ pos = end < 0 ? pos + 1 : end;
1207
+ }
1208
+ else if (!code && ch == 60 /* Ch.Less */ && isBlank(input.peek(pos + 1))) {
1209
+ // A list of words, in which quotes are text: < a ' b >
1210
+ let end = pos + 2;
1211
+ while (input.peek(end) != 62 /* Ch.Greater */ && input.peek(end) != 10 /* Ch.Newline */ && input.peek(end) >= 0)
1212
+ end++;
1213
+ pos = input.peek(end) == 62 /* Ch.Greater */ ? end + 1 : pos + 1;
1214
+ }
1215
+ else if (!code && (ch == 60 /* Ch.Less */ || ch == 58 /* Ch.Colon */) && (codeEnd = regexCodeEnd(input, pos)) > 0) {
1216
+ pos = codeEnd;
1217
+ }
1218
+ else if (!code && (ch == 36 /* Ch.Dollar */ || ch == 64 /* Ch.At */) && input.peek(pos + 1) == 40 /* Ch.ParenOpen */) {
1219
+ // Code that is interpolated: $( rx/ a / )
1220
+ let end = balancedEnd(input, pos + 2, 40 /* Ch.ParenOpen */, 41 /* Ch.ParenClose */);
1221
+ pos = end > 0 ? end : pos + 1;
1222
+ }
1223
+ else if (ch == 60 /* Ch.Less */ && (input.peek(pos + 1) == 91 /* Ch.BracketOpen */ ||
1224
+ (input.peek(pos + 1) == 45 /* Ch.Hyphen */ || input.peek(pos + 1) == 43 /* Ch.Plus */) && input.peek(pos + 2) == 91 /* Ch.BracketOpen */)) {
1225
+ // <[...]>, <-[...]>, and combinations: <+[a..z]-[aeiou]>
1226
+ for (pos++;;) {
1227
+ while (input.peek(pos) != 91 /* Ch.BracketOpen */) {
1228
+ if (input.peek(pos) < 0)
1229
+ return -1;
1230
+ pos++;
1231
+ }
1232
+ for (pos++; input.peek(pos) != 93 /* Ch.BracketClose */; pos++) {
1233
+ if (input.peek(pos) < 0)
1234
+ return -1;
1235
+ if (input.peek(pos) == 92 /* Ch.Backslash */)
1236
+ pos++;
1237
+ }
1238
+ let more = pos + 1;
1239
+ while (input.peek(more) == 32 /* Ch.Space */)
1240
+ more++;
1241
+ if (input.peek(more) != 43 /* Ch.Plus */ && input.peek(more) != 45 /* Ch.Hyphen */)
1242
+ break;
1243
+ do
1244
+ more++;
1245
+ while (input.peek(more) == 32 /* Ch.Space */);
1246
+ if (input.peek(more) != 91 /* Ch.BracketOpen */)
1247
+ break;
1248
+ pos = more;
1249
+ }
1250
+ // The bracket that closes the class is not one of the regex: rx[ <[a]> ]
1251
+ pos++;
1252
+ // A name that is added to the class, as in <[a]+it's>, takes in an
1253
+ // apostrophe before a letter, as assertionEnd reads it.
1254
+ let name = pos;
1255
+ while (input.peek(name) == 32 /* Ch.Space */)
1256
+ name++;
1257
+ if (input.peek(name) == 43 /* Ch.Plus */ || input.peek(name) == 45 /* Ch.Hyphen */) {
1258
+ do
1259
+ name++;
1260
+ while (input.peek(name) == 32 /* Ch.Space */);
1261
+ let end = nameEnd(input, name);
1262
+ if (end > 0)
1263
+ pos = end;
1264
+ }
1265
+ }
1266
+ else if (ch == 35 /* Ch.Hash */) {
1267
+ // An embedded comment, or one that runs to the end of the line.
1268
+ let end = embeddedCommentEnd(input, pos);
1269
+ if (end > 0)
1270
+ pos = end;
1271
+ else
1272
+ while (input.peek(pos) >= 0 && input.peek(pos) != 10 /* Ch.Newline */)
1273
+ pos++;
1274
+ }
1275
+ else if (ch == 123 /* Ch.BraceOpen */ && close != 125 /* Ch.BraceClose */) {
1276
+ let end = regexEnd(input, { start: pos + 1, open: 123 /* Ch.BraceOpen */, close: 125 /* Ch.BraceClose */, count: 1 }, true);
1277
+ pos = end < 0 ? pos + 1 : end + 1;
1278
+ }
1279
+ else {
1280
+ pos++;
1281
+ }
1282
+ }
1283
+ }
1284
+ // The offset after the `/` that closes the replacement of s/a/b/, which
1285
+ // starts at `pos`, or -1. A `$/` in it does not close it, when a `/`
1286
+ // follows on the same line: in s/a/$/, the `$` is text.
1287
+ function replacementEnd(input, pos) {
1288
+ for (let match = false;;) {
1289
+ let ch = input.peek(pos);
1290
+ if (ch < 0 || match && ch == 10 /* Ch.Newline */)
1291
+ return -1;
1292
+ if (ch == 47 /* Ch.Slash */)
1293
+ return pos + 1;
1294
+ if (ch == 36 /* Ch.Dollar */ && input.peek(pos + 1) == 47 /* Ch.Slash */)
1295
+ match = true;
1296
+ pos += match && ch == 36 /* Ch.Dollar */ || ch == 92 /* Ch.Backslash */ ? 2 : 1;
1297
+ }
1298
+ }
1299
+ // The offset after a regex or substitution, given its opening, or -1.
1300
+ function regexTokenEnd(input, opening) {
1301
+ let end = regexEnd(input, opening);
1302
+ if (end < 0)
1303
+ return -1;
1304
+ end += opening.count;
1305
+ // s/a/b/ has a second part. s{a} = 'b' does not.
1306
+ if (opening.kind != "regex" && opening.open == opening.close) {
1307
+ // A `$/` in the replacement is the match variable, not a `$` before
1308
+ // the closing delimiter: s/(a)/[$/]/. Unless nothing closes it then.
1309
+ let withMatch = opening.close == 47 /* Ch.Slash */ ? replacementEnd(input, end) : -1;
1310
+ end = withMatch < 0 ? rawEnd(input, end, opening) : withMatch;
1311
+ }
1312
+ return end;
1313
+ }
1314
+ // The opening of a bare regex: /a/
1315
+ const slashOpening = { open: 47 /* Ch.Slash */, close: 47 /* Ch.Slash */, count: 1, start: 1, kind: "regex",
1316
+ interpolates: 0, escapes: true };
1317
+ // The opening of the regex literal at the current position. The token
1318
+ // that makes a literal one token, and the parse of its inside, both
1319
+ // find its closing delimiter from this, so that they agree.
1320
+ function regexOpening(input) {
1321
+ if (input.next == 47 /* Ch.Slash */)
1322
+ return slashOpening;
1323
+ let opening = readOpening(input);
1324
+ return opening && (opening.kind == "regex" || opening.kind == "substitution") ? opening : null;
1325
+ }
1326
+ // The offset after a word list that opens at the current position, or
1327
+ // -1. A list that spans lines has to hold plain words, so that a stray
1328
+ // `<` does not swallow the code up to some later `>`. `strict` is for
1329
+ // a subscript, which has to be on one line, and cannot hold what
1330
+ // would make it a comparison: `$a<5 && $b>3`.
1331
+ //
1332
+ // A list with double angles is rarely a stray operator, and may hold
1333
+ // code over a few lines. Not over more: one that is being typed would
1334
+ // swallow the code up to some later `>>`.
1335
+ function wordListEnd(input, strict) {
1336
+ let open = input.next, close = open == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : 62 /* Ch.Greater */;
1337
+ let count = open == 60 /* Ch.Less */ && input.peek(1) == 60 /* Ch.Less */ ? 2 : 1;
1338
+ let codeLines = open == 171 /* Ch.GuillemetOpen */ || count == 2 ? maxCodeWordListLines : 1;
1339
+ for (let pos = count, lines = 1, code = false;; pos++) {
1340
+ let ch = input.peek(pos);
1341
+ if (ch == close && repeats(input, pos, close, count))
1342
+ return pos + count;
1343
+ if (ch < 0)
1344
+ return -1;
1345
+ // A backslash keeps the delimiter after it from closing the list: <a \> b>
1346
+ // Not in a subscript, which cannot hold what follows it: $a<\$b>
1347
+ if (ch == 92 /* Ch.Backslash */ && !strict && input.peek(pos + 1) >= 0 && input.peek(pos + 1) != 10 /* Ch.Newline */)
1348
+ pos++;
1349
+ else if (ch == 10 /* Ch.Newline */)
1350
+ lines++;
1351
+ else if (ch == 59 /* Ch.Semicolon */ || ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ ||
1352
+ ch == 40 /* Ch.ParenOpen */ || ch == 41 /* Ch.ParenClose */)
1353
+ code = true;
1354
+ if (lines > 1 && (code && lines > codeLines || strict))
1355
+ return -1;
1356
+ if (strict && (code || ch == 36 /* Ch.Dollar */ || ch == 64 /* Ch.At */ || ch == 37 /* Ch.Percent */ || ch == 38 /* Ch.Amp */ ||
1357
+ ch == 124 /* Ch.Pipe */ || ch == 61 /* Ch.Equals */ || ch == 44 /* Ch.Comma */ || ch == 63 /* Ch.Question */ ||
1358
+ ch == 33 /* Ch.Bang */ || ch == 34 /* Ch.DoubleQuote */ || ch == 60 /* Ch.Less */))
1359
+ return -1;
1360
+ }
1361
+ }
1362
+ // How many lines a <<...>> list that holds code may span.
1363
+ const maxCodeWordListLines = 10;
1364
+ // How long a <<...>> subscript can be. Whether it is closed is found
1365
+ // out from its start, and a token must not look far past its end.
1366
+ const maxDoubleSubscript = 24;
1367
+ // Whether a character can start or end the content of a <<...>>
1368
+ // subscript: part of a word, a variable or a quote. An operator
1369
+ // character cannot, which tells the hyper operators apart: @a<<+>>@b,
1370
+ // @a«R-»@b
1371
+ function isSubscriptEdge(ch) {
1372
+ return isIdentifierStart(ch) || isDigit(ch) || ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */;
1373
+ }
1374
+ // The offset after the <<...>> subscript at the current position, with
1375
+ // the given opening, or -1. It is short, on one line, and holds no
1376
+ // punctuation of statements.
1377
+ function doubleSubscriptEnd(input, { start, close, count }) {
1378
+ let first = input.peek(start);
1379
+ if (!isSubscriptEdge(first) && first != 36 /* Ch.Dollar */ && first != 64 /* Ch.At */ && first != 37 /* Ch.Percent */ && first != 38 /* Ch.Amp */)
1380
+ return -1;
1381
+ for (let pos = start; pos < maxDoubleSubscript; pos++) {
1382
+ let ch = input.peek(pos);
1383
+ if (ch == close && repeats(input, pos, close, count))
1384
+ return isSubscriptEdge(input.peek(pos - 1)) ? pos + count : -1;
1385
+ if (ch < 0 || ch == 10 /* Ch.Newline */ || ch == 59 /* Ch.Semicolon */ || ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ ||
1386
+ ch == 40 /* Ch.ParenOpen */ || ch == 41 /* Ch.ParenClose */)
1387
+ return -1;
1388
+ }
1389
+ return -1;
1390
+ }
1391
+ // Whether every `{` between two offsets has its `}` there, and the
1392
+ // other way around.
1393
+ function hasBalancedBraces(input, from, to) {
1394
+ let depth = 0;
1395
+ for (let pos = from; pos < to; pos++) {
1396
+ let ch = input.peek(pos);
1397
+ if (ch == 123 /* Ch.BraceOpen */)
1398
+ depth++;
1399
+ else if (ch == 125 /* Ch.BraceClose */ && --depth < 0)
1400
+ return false;
1401
+ }
1402
+ return depth == 0;
1403
+ }
1404
+ // A `<` subscript right after a term: %h<key>
1405
+ function subscriptEnd(input) {
1406
+ if (input.next != 60 /* Ch.Less */ || isSpace(input.peek(-1)) || input.peek(1) == 60 /* Ch.Less */)
1407
+ return -1;
1408
+ return wordListEnd(input, true);
1409
+ }
1410
+ // The keywords that are routines or prefix operators, and can be called
1411
+ // with parentheses. `if(1)` and `my($x)` are not calls of this kind.
1412
+ const callableKeywords = /^(take|return|emit|next|last|redo|proceed|succeed|so|not)$/;
1413
+ // The words that declare what follows `multi`, `proto` or `only`.
1414
+ const declarators$1 = /^(sub|method|submethod|token|rule|regex)$/;
1415
+ // The words that start a declaration node of the grammar.
1416
+ const allDeclarators = /^(class|role|grammar|module|package|sub|method|submethod|token|rule|regex|enum|subset|constant)$/;
1417
+ // Whether a declarator starts with the given word, as `su` starts `sub`.
1418
+ function startsDeclarator(name) {
1419
+ return ["sub", "method", "submethod", "token", "rule", "regex"].some(declarator => declarator.startsWith(name));
1420
+ }
1421
+ // What stands between the parentheses of a set operator.
1422
+ const setOperators = /^(<=?|>=?|<\+|>\+|==|[|&\-^+.]|elem|cont)$/;
1423
+ const operatorCategory = /^(infix|prefix|postfix|circumfix|postcircumfix|term)$/;
1424
+ // The infixes that are words and are not keywords of the grammar. They
1425
+ // are operators only where one is expected.
1426
+ const wordOperators$1 = /^(x|xx|min|max|minmax|ff|fff|before|after|unicmp|coll|Z|X)$/;
1427
+ // The infixes that are words, which the Z, X and R meta operators can
1428
+ // take: Zmin, Xeq, Rcmp
1429
+ const metaWordOperators = /^(x|xx|min|max|minmax|eq|ne|lt|gt|le|ge|eqv|cmp|leg|unicmp|coll|before|after|div|mod|gcd|lcm|ff|fff)$/;
1430
+ // Whether the word from 0 to `end` is an infix: x, before, Zmin, Rcmp
1431
+ function isWordOperator(input, end) {
1432
+ if (end > 7)
1433
+ return false;
1434
+ let name = word(input, 0, end), first = name.charCodeAt(0);
1435
+ return wordOperators$1.test(name) ||
1436
+ (first == 90 /* Ch.Z */ || first == 88 /* Ch.X */ || first == 82 /* Ch.R */) && metaWordOperators.test(name.slice(1));
1437
+ }
1438
+ // Whether an infix is expected: after a term, or after a block on the
1439
+ // same line, which is a subscript or a term itself: %h{$k} x 3,
1440
+ // { rand } xx 3. A line break after a block ends the statement.
1441
+ function infixExpected(input, mode) {
1442
+ return mode == 1 /* Mode.AfterTerm */ || mode == 3 /* Mode.AfterBlock */ && !atLineStart(input);
1443
+ }
1444
+ // The length of the operator at the start of a run of operator
1445
+ // characters that a term follows in the same run: the `=` of
1446
+ // `@a=<a b>`, the `!` of `!/x/`, the `~~` of `$s ~~/x/`. Zero when the
1447
+ // run is one operator, which the grammar's Operator token reads. What
1448
+ // follows is not looked at: whether it is a term is for the tokenizers
1449
+ // to find out from where it starts, as they do after a space.
1450
+ //
1451
+ // After a term, the run starts with an infix, and a term follows it.
1452
+ // In term position, it starts with prefixes, and a term follows them.
1453
+ // Not split are:
1454
+ // - the hyper operators: >>+<<, »+«, <<+>>, «+», >>/<<
1455
+ // - a run that starts with `<`, which no term follows: <=, <==, </
1456
+ // - `//` and `//=`
1457
+ // - the infixes +<, ~< and !< (left shifts and not-less-than), and the
1458
+ // assignments made of them, after a term: in `$a +<b>`, Raku reads
1459
+ // the infix too. In term position, a space or `=` after them tells
1460
+ // that a sigilless name was a term: `first +< 64`
1461
+ // - a prefix with double angles, which make it a hyper: -<<@a, -«@a,
1462
+ // also after an infix: $a=-<<@b. After a term, double angles are a
1463
+ // word list only right after an infix of one character or one that
1464
+ // ends in `=`: @a=«a b», $a==<<a b>>
1465
+ // - a `<` that no word follows, after a whatever star or a postfix
1466
+ // `++` or `--`: in `*<5 and $x > 1`, the `<` compares. One that a
1467
+ // word follows starts a subscript: *<key>
1468
+ // - a run that starts with `\`, as in the triangular reductions [\<]
1469
+ // and [\/]
1470
+ // - an `=` and double angles that close a hyper operator in brackets:
1471
+ // @a >>[&f]=<< @b, @a »[+]=« @b (see closesHyperInfix)
1472
+ function operatorHeadEnd(input, termPosition) {
1473
+ let first = input.next;
1474
+ if (first == 61 /* Ch.Equals */ && !termPosition) {
1475
+ let hyper = closesHyperInfix(input);
1476
+ if (hyper > 0)
1477
+ return hyper;
1478
+ }
1479
+ if (first == 60 /* Ch.Less */ || first == 171 /* Ch.GuillemetOpen */ || first == 187 /* Ch.GuillemetClose */ || first == 92 /* Ch.Backslash */ ||
1480
+ first == 62 /* Ch.Greater */ && input.peek(1) == first)
1481
+ return 0;
1482
+ for (let pos = 1;; pos++) {
1483
+ let ch = input.peek(pos), before = input.peek(pos - 1);
1484
+ if (!isOperatorRunChar(ch))
1485
+ return 0;
1486
+ // Double angles, which are a word list right after an infix, and
1487
+ // otherwise a hyper prefix.
1488
+ let double = ch == 171 /* Ch.GuillemetOpen */ || ch == 60 /* Ch.Less */ && input.peek(pos + 1) == 60 /* Ch.Less */;
1489
+ if (double) {
1490
+ if (!termPosition && (pos == 1 || before == 61 /* Ch.Equals */))
1491
+ return pos;
1492
+ if (ch == 60 /* Ch.Less */)
1493
+ pos++;
1494
+ }
1495
+ else if (ch == 47 /* Ch.Slash */) {
1496
+ if (before != 47 /* Ch.Slash */)
1497
+ return pos;
1498
+ }
1499
+ else if (ch == 60 /* Ch.Less */) {
1500
+ let after = input.peek(pos + 1);
1501
+ let infix = pos == 1 && (first == 43 /* Ch.Plus */ || first == 126 /* Ch.Tilde */ || first == 33 /* Ch.Bang */) &&
1502
+ (!termPosition || after == 61 /* Ch.Equals */ || isSpace(after));
1503
+ let afterTerm = (pos == 1 && first == 42 /* Ch.Star */ || pos == 2 && (first == 43 /* Ch.Plus */ || first == 45 /* Ch.Hyphen */) && before == first) &&
1504
+ !isIdentifierStart(after);
1505
+ if (!infix && !afterTerm)
1506
+ return pos;
1507
+ }
1508
+ }
1509
+ }
1510
+ // Whether the run of `=` and double angles at the current position
1511
+ // closes a hyper operator that holds an infix in brackets or
1512
+ // parentheses, as in @a >>[&f]=<< @b and @a »(|)=« @b. The `=` makes
1513
+ // the infix an assignment, and the angles close the hyper. Right after
1514
+ // a subscript, the same characters are an assignment of a word list:
1515
+ // @a[1]=<<a b>>. What tells them apart is the `>>` or `»` before the
1516
+ // opening bracket, that the bracket does not start with a digit or a
1517
+ // `$` or `@` sigil, which start an index, and that no word follows the
1518
+ // angles: in @a>>[0]=<< a b >> and @a>>[$i]=<<a b>>, a hyper subscript
1519
+ // is assigned a word list. Returns the length of the `=` and the angles,
1520
+ // or 0, so that a prefix right after them is a token of its own:
1521
+ // @a >>[+]=<<-@b
1522
+ function closesHyperInfix(input) {
1523
+ let angles = input.peek(1) == 171 /* Ch.GuillemetOpen */ ? 1 : input.peek(1) == 60 /* Ch.Less */ && input.peek(2) == 60 /* Ch.Less */ ? 2 : 0;
1524
+ let after = input.peek(1 + angles);
1525
+ if (!angles || isIdentifierStart(after) || isDigit(after))
1526
+ return 0;
1527
+ let close = input.peek(-1);
1528
+ if (close != 93 /* Ch.BracketClose */ && close != 41 /* Ch.ParenClose */)
1529
+ return 0;
1530
+ let open = close == 93 /* Ch.BracketClose */ ? 91 /* Ch.BracketOpen */ : 40 /* Ch.ParenOpen */;
1531
+ for (let pos = -2, depth = 0; pos > -22; pos--) {
1532
+ let ch = input.peek(pos);
1533
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1534
+ return 0;
1535
+ if (ch == close)
1536
+ depth++;
1537
+ else if (ch == open && depth-- == 0) {
1538
+ let inside = input.peek(pos + 1);
1539
+ if (isDigit(inside) || inside == 36 /* Ch.Dollar */ || inside == 64 /* Ch.At */)
1540
+ return 0;
1541
+ let hyper = input.peek(pos - 1) == 187 /* Ch.GuillemetClose */ ||
1542
+ input.peek(pos - 1) == 62 /* Ch.Greater */ && input.peek(pos - 2) == 62 /* Ch.Greater */;
1543
+ return hyper ? 1 + angles : 0;
1544
+ }
1545
+ }
1546
+ return 0;
1547
+ }
1548
+ // The number of angles of a hyper operator at offset `pos`: 1 for « and
1549
+ // », 2 for << and >>, 0 for none.
1550
+ function hyperAngles(input, pos) {
1551
+ let ch = input.peek(pos);
1552
+ if (ch == 171 /* Ch.GuillemetOpen */ || ch == 187 /* Ch.GuillemetClose */)
1553
+ return 1;
1554
+ return (ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */) && input.peek(pos + 1) == ch ? 2 : 0;
1555
+ }
1556
+ // The offset after the hyper comma at offset `at`, as in @a »,« @b,
1557
+ // @a <<,>> @b and @a Z»,« @b, or 0. The comma is not an operator
1558
+ // character, so the grammar's Operator token would end before it, and
1559
+ // the angles after it would open a word list in term position. One that
1560
+ // starts with `«` or `<<` is only looked for after a term: `«a b»,«c d»`
1561
+ // are two word lists, whose `»` is part of a token of its own.
1562
+ function hyperCommaEnd(input, at = 0) {
1563
+ let open = hyperAngles(input, at);
1564
+ if (!open || input.peek(at + open) != 44 /* Ch.Comma */)
1565
+ return 0;
1566
+ let close = hyperAngles(input, at + open + 1);
1567
+ return close ? at + open + 1 + close : 0;
1568
+ }
1569
+ function operatorHead(input, mode) {
1570
+ // A run that starts with » or >> starts no term.
1571
+ let comma = hyperCommaEnd(input);
1572
+ if (comma > 0)
1573
+ return input.acceptToken(wordOperator, comma);
1574
+ let end = operatorHeadEnd(input, inTermPosition(input, mode, 1));
1575
+ if (end > 0)
1576
+ input.acceptToken(wordOperator, end);
1577
+ }
1578
+ // The offset after the named capture at the current position, as in
1579
+ // $<name> and @<name>, or -1. Only a short name is looked for, so that
1580
+ // a `$<` that is not closed does not look far: one of more than 20
1581
+ // characters is a sigil and a subscript.
1582
+ function namedCaptureEnd(input) {
1583
+ let next = input.next;
1584
+ if (next != 36 /* Ch.Dollar */ && next != 64 /* Ch.At */ || input.peek(1) != 60 /* Ch.Less */ || !isIdentifierStart(input.peek(2)))
1585
+ return -1;
1586
+ for (let pos = 3; pos <= 22; pos++)
1587
+ if (!continuesName(input, pos))
1588
+ return input.peek(pos) == 62 /* Ch.Greater */ ? pos + 1 : -1;
1589
+ return -1;
1590
+ }
1591
+ // The tokens that depend on whether a term or an operator is expected.
1592
+ const termToken = new lr.ExternalTokenizer((input, stack) => {
1593
+ // Also in a string, where it is interpolated.
1594
+ let capture = namedCaptureEnd(input);
1595
+ if (capture > 0 && stack.canShift(namedCapture))
1596
+ return input.acceptToken(namedCapture, capture);
1597
+ if (!stack.canShift(regexLiteral)) {
1598
+ // At the start of the parse of the inside of a word list that
1599
+ // interpolates, its opening delimiter.
1600
+ let opening = context(stack) == startContext && stack.canShift(quoteStart) ? wordListOpening(input, 0) : null;
1601
+ if (opening)
1602
+ input.acceptToken(quoteStart, opening.start);
1603
+ return;
1604
+ }
1605
+ let next = input.next, { mode } = context(stack);
1606
+ // The set operators that are written in parentheses: $a (<=) $b, $x (elem) $s
1607
+ // Not right after the term, where the parentheses hold arguments: $f(elem)
1608
+ if (next == 40 /* Ch.ParenOpen */ && isSpace(input.peek(-1)) && infixExpected(input, mode)) {
1609
+ let end = 1;
1610
+ while (end < 6 && input.peek(end) != 41 /* Ch.ParenClose */ && input.peek(end) >= 0)
1611
+ end++;
1612
+ if (input.peek(end) == 41 /* Ch.ParenClose */ && setOperators.test(word(input, 1, end)))
1613
+ input.acceptToken(wordOperator, end + 1);
1614
+ return;
1615
+ }
1616
+ if (isIdentifierStart(next)) {
1617
+ // The Z, X and R meta operators: Z+, X~, R-, Z=>, Z»,«
1618
+ let meta = (next == 90 /* Ch.Z */ || next == 88 /* Ch.X */ || next == 82 /* Ch.R */) && infixExpected(input, mode);
1619
+ let metaComma = meta ? hyperCommaEnd(input, 1) : 0;
1620
+ if (metaComma > 0)
1621
+ return input.acceptToken(wordOperator, metaComma);
1622
+ if (meta && isOperatorChar(input.peek(1)) && !continuesName(input, 1)) {
1623
+ let pos = 2;
1624
+ while (isOperatorChar(input.peek(pos)))
1625
+ pos++;
1626
+ return input.acceptToken(wordOperator, pos);
1627
+ }
1628
+ // A word before `=>` is a key, whatever it spells. A word after a
1629
+ // backslash is a sigilless name, and so is a declarator that a
1630
+ // method is called on: sub f(\class) { class.say }
1631
+ // A capitalized one is left to be a TypeName, as it is where it is used.
1632
+ let end = nameEnd(input, 0), after = gapEnd(input, end), lower = next < 65 /* Ch.A */ || next > 90 /* Ch.Z */;
1633
+ if (input.peek(after) == 61 /* Ch.Equals */ && input.peek(after + 1) == 62 /* Ch.Greater */ || lower && input.peek(-1) == 92 /* Ch.Backslash */ ||
1634
+ input.peek(end) == 46 /* Ch.Dot */ && end <= 9 && methodDotSize(input, end) > 0 && allDeclarators.test(word(input, 0, end)))
1635
+ return input.acceptToken(plainName, end);
1636
+ // After `multi`, `proto` or `only`, a name that is not a declarator
1637
+ // is that of a sub: multi foo($x) { }
1638
+ // Only with a signature or a body right after it. A name alone may
1639
+ // be a declarator that is still being typed (`multi su`), and
1640
+ // `only` and `proto` can be routines of one's own (`only foo, 1`).
1641
+ // The signature may start on the next line, unless the name can
1642
+ // still become a declarator: `multi su` above a line with a `(`.
1643
+ if (mode == 4 /* Mode.AfterMulti */ && !(end <= 9 && declarators$1.test(word(input, 0, end)))) {
1644
+ let nameTo = categoryEnd(input, 0, end), opens = (ch) => ch == 40 /* Ch.ParenOpen */ || ch == 123 /* Ch.BraceOpen */;
1645
+ if (opens(input.peek(gapEnd(input, nameTo))) ||
1646
+ opens(input.peek(gapEnd(input, nameTo, true))) && !startsDeclarator(word(input, 0, end)))
1647
+ return input.acceptToken(multiName, nameTo);
1648
+ }
1649
+ // So is one of the keywords that are routines, when it is called
1650
+ // with parentheses: take(1). They are 2 to 7 characters long.
1651
+ if (input.peek(end) == 40 /* Ch.ParenOpen */ && end <= 7 && callableKeywords.test(word(input, 0, end)))
1652
+ return input.acceptToken(plainName, end);
1653
+ if (infixExpected(input, mode) && isWordOperator(input, end))
1654
+ return input.acceptToken(wordOperator, end);
1655
+ if (mode == 1 /* Mode.AfterTerm */)
1656
+ return;
1657
+ }
1658
+ else if (next == 37 /* Ch.Percent */ || next == 38 /* Ch.Amp */) {
1659
+ // Squeezed between two terms, a sigil is the operator: $a%b. With a
1660
+ // space before it, it is a variable: `my Array[Int] %h`. So it is
1661
+ // after a lone sigil, which makes a container of it: $%h, @%h
1662
+ let before = input.peek(-1);
1663
+ if (mode == 1 /* Mode.AfterTerm */ && isIdentifierStart(input.peek(1)) && !isSpace(before) &&
1664
+ before != 36 /* Ch.Dollar */ && before != 64 /* Ch.At */)
1665
+ return input.acceptToken(wordOperator, 1);
1666
+ // An operator as a routine: &[+], &[»+»], &[max]
1667
+ // After a term, the `&` is an operator: $a &[1, 2]
1668
+ if (next == 38 /* Ch.Amp */ && input.peek(1) == 91 /* Ch.BracketOpen */ && mode != 1 /* Mode.AfterTerm */) {
1669
+ // A meta operator brings brackets of its own: &[R[~~]]
1670
+ for (let end = 2, depth = 1; end < 14; end++) {
1671
+ let ch = input.peek(end);
1672
+ if (ch < 0 || isSpace(ch))
1673
+ break;
1674
+ if (ch == 91 /* Ch.BracketOpen */)
1675
+ depth++;
1676
+ else if (ch == 93 /* Ch.BracketClose */ && --depth == 0) {
1677
+ if (end > 2)
1678
+ input.acceptToken(operatorVariable, end + 1);
1679
+ break;
1680
+ }
1681
+ }
1682
+ return;
1683
+ }
1684
+ // The same by its full name: &infix:<+>
1685
+ if (next == 38 /* Ch.Amp */) {
1686
+ let end = nameEnd(input, 1);
1687
+ if (end > 0 && operatorCategory.test(word(input, 1, end))) {
1688
+ let categoryTo = categoryEnd(input, 1, end);
1689
+ if (categoryTo > end)
1690
+ input.acceptToken(operatorVariable, categoryTo);
1691
+ }
1692
+ }
1693
+ return;
1694
+ }
1695
+ else if (next == 60 /* Ch.Less */ || next == 171 /* Ch.GuillemetOpen */) {
1696
+ let end, opening = wordListOpening(input, 0);
1697
+ // After a term or a whatever star, double angles that an operator
1698
+ // character follows start a hyper infix: @a «,« @b, * «+« 1
1699
+ let afterStar = mode == 5 /* Mode.AfterStar */;
1700
+ if (opening && (afterStar || infixExpected(input, mode))) {
1701
+ let comma = hyperCommaEnd(input);
1702
+ if (comma > 0)
1703
+ return input.acceptToken(wordOperator, comma);
1704
+ if (afterStar && isOperatorRunChar(input.peek(opening.start)))
1705
+ return;
1706
+ }
1707
+ if (inTermPosition(input, mode, 1)) {
1708
+ // [<] and [<=] are reductions, <-> starts a pointy block.
1709
+ let after = input.peek(1);
1710
+ if (after == 61 /* Ch.Equals */ || after == 93 /* Ch.BracketClose */ || after == 45 /* Ch.Hyphen */ && input.peek(2) == 62 /* Ch.Greater */)
1711
+ return;
1712
+ end = wordListEnd(input, false);
1713
+ }
1714
+ else if (opening && !isSpace(input.peek(-1))) {
1715
+ // A subscript with double angles, which touches its term:
1716
+ // %h«$key», :a<<b $c>>
1717
+ end = doubleSubscriptEnd(input, opening);
1718
+ }
1719
+ else {
1720
+ end = subscriptEnd(input);
1721
+ }
1722
+ if (end <= 0)
1723
+ return;
1724
+ // <<a $b>> and «a $b» interpolate. The list is one token here:
1725
+ // that it is closed has to be known where it starts. Its inside
1726
+ // is parsed again, piece by piece (see index.ts), by rules that
1727
+ // count nested delimiters, escapes and the braces of blocks. A
1728
+ // list that those rules would end elsewhere is not read inside.
1729
+ let interpolates = opening && rawEnd(input, opening.start, opening) == end &&
1730
+ hasBalancedBraces(input, opening.start, end);
1731
+ return input.acceptToken(interpolates ? interpolatingWordList : rawString, end);
1732
+ }
1733
+ else if (next == 47 /* Ch.Slash */) {
1734
+ // [/] is a reduction, as [<] is. [/]/] holds the regex /]/.
1735
+ let reduction = input.peek(-1) == 91 /* Ch.BracketOpen */ && input.peek(1) == 93 /* Ch.BracketClose */ && input.peek(2) != 47 /* Ch.Slash */;
1736
+ let end = input.peek(1) != 47 /* Ch.Slash */ && !reduction && inTermPosition(input, mode, 1) ?
1737
+ regexTokenEnd(input, slashOpening) : -1;
1738
+ return end > 0 ? input.acceptToken(regexLiteral, end) : operatorHead(input, mode);
1739
+ }
1740
+ else if (isOperatorRunChar(next)) {
1741
+ return operatorHead(input, mode);
1742
+ }
1743
+ else if (next == 0x2205 /* ∅ */) {
1744
+ // The empty set is a term, which operator runs leave out: -∅
1745
+ return input.acceptToken(wordOperator, 1);
1746
+ }
1747
+ let opening = readOpening(input);
1748
+ if (!opening)
1749
+ return;
1750
+ if (opening.kind == "interpolating")
1751
+ return input.acceptToken(quoteStart, opening.start);
1752
+ if (opening.kind != "raw") {
1753
+ let end = regexTokenEnd(input, opening);
1754
+ if (end > 0)
1755
+ input.acceptToken(opening.kind == "transliteration" ? transliteration : regexLiteral, end);
1756
+ return;
1757
+ }
1758
+ let end = rawEnd(input, opening.start, opening);
1759
+ if (end > 0)
1760
+ input.acceptToken(rawString, end);
1761
+ });
1762
+ // The twigils that the grammar's variable tokens take: $!x, $.x, $*x,
1763
+ // $?x, $=x, $~x, $^x, $:x
1764
+ function isTwigil(ch) {
1765
+ return ch == 33 /* Ch.Bang */ || ch == 46 /* Ch.Dot */ || ch == 42 /* Ch.Star */ || ch == 63 /* Ch.Question */ || ch == 61 /* Ch.Equals */ || ch == 126 /* Ch.Tilde */ ||
1766
+ ch == 94 /* Ch.Caret */ || ch == 58 /* Ch.Colon */;
1767
+ }
1768
+ // Whether a sigil other than `$` interpolates: only when a subscript or
1769
+ // a call follows its name. `end` is the offset after the name.
1770
+ function hasPostfix(input, end) {
1771
+ let ch = input.peek(end);
1772
+ if (ch == 91 /* Ch.BracketOpen */ || ch == 40 /* Ch.ParenOpen */ || ch == 123 /* Ch.BraceOpen */ || ch == 60 /* Ch.Less */)
1773
+ return true;
1774
+ return interpolatesCall(input, end);
1775
+ }
1776
+ // How far interpolatesCall looks for the argument list of a chain of
1777
+ // calls. A token must not look far past its end.
1778
+ const maxCallChain = 24;
1779
+ // Whether the method call that starts with the dot at offset `start` in
1780
+ // a string is interpolated: when it has an argument list, or when the
1781
+ // calls chained to it, up to one that has one, are short: "$x.a()",
1782
+ // "$x.a.b()". A chain that ends in no argument list is text: "$x.a.b"
1783
+ function interpolatesCall(input, start) {
1784
+ let size = methodDotSize(input, start);
1785
+ if (!size)
1786
+ return false;
1787
+ // The limit counts from the current position, where the token that
1788
+ // looks starts: the dot, or the sigil of "@a.sort.join()".
1789
+ let pos = nameEnd(input, start + size), limit = maxCallChain;
1790
+ if (input.peek(pos) == 40 /* Ch.ParenOpen */)
1791
+ return true;
1792
+ while (pos <= limit) {
1793
+ size = methodDotSize(input, pos);
1794
+ if (!size)
1795
+ return false;
1796
+ // A name, which can be qualified: .Foo::bar
1797
+ for (pos += size + 1; pos <= limit;) {
1798
+ if (continuesName(input, pos))
1799
+ pos++;
1800
+ else if (input.peek(pos) == 58 /* Ch.Colon */ && input.peek(pos + 1) == 58 /* Ch.Colon */ && isIdentifierStart(input.peek(pos + 2)))
1801
+ pos += 3;
1802
+ else
1803
+ break;
1804
+ }
1805
+ if (input.peek(pos) == 40 /* Ch.ParenOpen */)
1806
+ return pos <= limit;
1807
+ }
1808
+ return false;
1809
+ }
1810
+ // Whether the parser is between the pieces of a quote, as opposed to
1811
+ // in the code of a block in it.
1812
+ function inQuoteText(stack) { return stack.canShift(quoteContent); }
1813
+ // Whether the parser is, in a quote, right after a variable or after a
1814
+ // subscript or a call on one: where the grammar takes a quotePostfix.
1815
+ // This is asked of the parser and not of the mode, which is not known
1816
+ // to this precision after a reused node that ends in text of the quote.
1817
+ function afterQuotedVariable(stack) { return stack.canShift(rawString); }
1818
+ // The pieces of a quote that interpolates.
1819
+ const quoteToken = new lr.ExternalTokenizer((input, stack) => {
1820
+ if (!inQuoteText(stack))
1821
+ return;
1822
+ let { quote } = context(stack);
1823
+ if (!quote)
1824
+ return;
1825
+ let { open, close, count, interpolates } = quote, nests = open != close, other = otherClose(open);
1826
+ // After a variable, a subscript or a call continues the interpolation.
1827
+ // `[` and `(` are left to the grammar's own tokens.
1828
+ if (afterQuotedVariable(stack)) {
1829
+ if (input.next == 91 /* Ch.BracketOpen */ || input.next == 40 /* Ch.ParenOpen */)
1830
+ return;
1831
+ let end = subscriptEnd(input);
1832
+ if (end > 0)
1833
+ return input.acceptToken(rawString, end);
1834
+ }
1835
+ let start = input.pos;
1836
+ // The text of a heredoc ends where the input does, and so does a
1837
+ // quote that is not closed, with its nested pairs. Closing them here
1838
+ // leaves the context outside the quote at the end of the document,
1839
+ // where the parser records it for every repetition of the elements
1840
+ // (see AGENTS.md). With the quote still open there, an edit before
1841
+ // the quote reused nothing until the quote was closed.
1842
+ if (input.next < 0)
1843
+ return input.acceptToken(quoteEnd);
1844
+ for (;;) {
1845
+ let next = input.next;
1846
+ if (next < 0)
1847
+ break;
1848
+ let atClose = next == close && repeats(input, 0, close, count) || next == other;
1849
+ if (atClose || nests && next == open && repeats(input, 0, open, count)) {
1850
+ if (input.pos > start)
1851
+ break;
1852
+ input.advance(count);
1853
+ // Inside a nested pair, a closing delimiter closes that pair.
1854
+ return input.acceptToken(!atClose ? quoteNestOpen : stack.canShift(quoteNestClose) ? quoteNestClose : quoteEnd);
1855
+ }
1856
+ if (next == 92 /* Ch.Backslash */) {
1857
+ // A backslash at the end of the input escapes nothing. It is text,
1858
+ // so that the quote is closed after it.
1859
+ if (interpolates & 32 /* Interpolate.Backslash */ && input.peek(1) >= 0)
1860
+ break;
1861
+ // Still keeps a delimiter after it from closing the quote.
1862
+ if (quote.escapes && input.peek(1) >= 0)
1863
+ input.advance();
1864
+ }
1865
+ else if (next == 36 /* Ch.Dollar */) {
1866
+ if (interpolates & 2 /* Interpolate.Scalar */)
1867
+ break;
1868
+ }
1869
+ else if (next == 123 /* Ch.BraceOpen */) {
1870
+ if (interpolates & 1 /* Interpolate.Closure */)
1871
+ break;
1872
+ }
1873
+ else if (next == 64 /* Ch.At */ && interpolates & 4 /* Interpolate.Array */ ||
1874
+ next == 37 /* Ch.Percent */ && interpolates & 8 /* Interpolate.Hash */ ||
1875
+ next == 38 /* Ch.Amp */ && interpolates & 16 /* Interpolate.Function */) {
1876
+ // A name can have a twigil: "@*ARGS[0]", "%.h<k>", "&?ROUTINE.name()"
1877
+ let end = nameEnd(input, isTwigil(input.peek(1)) ? 2 : 1);
1878
+ if (end > 0 && hasPostfix(input, end))
1879
+ break;
1880
+ }
1881
+ input.advance();
1882
+ }
1883
+ if (input.pos > start)
1884
+ input.acceptToken(quoteContent);
1885
+ });
1886
+ // The text of a heredoc: the lines after the one that holds its opener,
1887
+ // up to the line that holds only its terminator. As a skipped token, it
1888
+ // leaves the rest of the opener's line to be parsed as usual. The
1889
+ // context holds the terminators of the heredocs that the line opened.
1890
+ //
1891
+ // The text is one token, also when it interpolates: that it has a
1892
+ // terminator has to be known where it starts. A text in which
1893
+ // everything interpolates is a token of its own kind, the inside of
1894
+ // which is parsed again (see index.ts), from an empty token that puts
1895
+ // the quote in the context. When a line opens several heredocs, their
1896
+ // texts are one token, which interpolates if all of them do.
1897
+ //
1898
+ // Where an element can stand, the text is an element, and is skipped
1899
+ // elsewhere, as between a signature and its body. @lezer/common gives
1900
+ // every run of elements in a repeat the context hash at the end of the
1901
+ // last element of the repeat, and reuses a run only where the hash is
1902
+ // the same. A skipped text is no element, so a repeat whose last line
1903
+ // opened a heredoc used to end with the heredoc still open, and none of
1904
+ // its runs were reused (issue 33).
1905
+ const heredocToken = new lr.ExternalTokenizer((input, stack) => {
1906
+ if (context(stack) == startContext && stack.canShift(heredocStart))
1907
+ return input.acceptToken(heredocStart);
1908
+ let { heredocs } = context(stack);
1909
+ if (!heredocs.length)
1910
+ return;
1911
+ let pos = blanksEnd(input, 0);
1912
+ if (input.peek(pos) != 10 /* Ch.Newline */)
1913
+ return;
1914
+ input.advance(pos);
1915
+ for (let { terminator } of heredocs) {
1916
+ for (;;) {
1917
+ // Without its terminator, this is not taken to be a heredoc.
1918
+ if (input.next < 0)
1919
+ return;
1920
+ input.advance();
1921
+ if (lineStartsWith(input, terminator) && isLineEnd(input, terminator.length)) {
1922
+ input.advance(terminator.length);
1923
+ break;
1924
+ }
1925
+ skipLine(input);
1926
+ }
1927
+ }
1928
+ let interpolates = heredocs.every(heredoc => heredoc.interpolates);
1929
+ let element = interpolates ? interpolatingHeredocElement : heredocElement;
1930
+ input.acceptToken(stack.canShift(element) ? element : interpolates ? interpolatingHeredoc : rawHeredoc);
1931
+ // Contextual: which of the terms it is depends on the stack, and two
1932
+ // stacks with the same context can be at the same text.
1933
+ }, { contextual: true });
1934
+ const regexDeclarator = /^(token|rule|regex)$/;
1935
+ const regexDeclaratorPrefix = /^(proto|multi|my|our)$/;
1936
+ // Whether the line that starts at offset `pos` starts a regex
1937
+ // declaration: a declarator, a name, and further on a brace, as in
1938
+ // `token name {`. In a regex, the words alone can be literals:
1939
+ // `token | rule`
1940
+ function startsRegexDeclaration(input, pos) {
1941
+ let start = blanksEnd(input, pos), end = nameEnd(input, start);
1942
+ // proto token, my regex
1943
+ if (end > 0 && isBlank(input.peek(end)) && regexDeclaratorPrefix.test(word(input, start, end))) {
1944
+ start = blanksEnd(input, end);
1945
+ end = nameEnd(input, start);
1946
+ }
1947
+ if (end < 0 || end - start > 5 || !isBlank(input.peek(end)) || !regexDeclarator.test(word(input, start, end)))
1948
+ return false;
1949
+ let name = blanksEnd(input, end), after = nameEnd(input, name);
1950
+ if (after < 0)
1951
+ return false;
1952
+ for (after = categoryEnd(input, name, after);; after++) {
1953
+ let next = input.peek(after);
1954
+ if (next == 123 /* Ch.BraceOpen */)
1955
+ return true;
1956
+ if (next < 0 || next == 10 /* Ch.Newline */)
1957
+ return false;
1958
+ }
1959
+ }
1960
+ // The characters that quantify, combine and anchor in a regex.
1961
+ function isRegexOperator(ch) {
1962
+ return ch == 43 /* Ch.Plus */ || ch == 42 /* Ch.Star */ || ch == 63 /* Ch.Question */ || ch == 124 /* Ch.Pipe */ || ch == 38 /* Ch.Amp */ || ch == 94 /* Ch.Caret */ ||
1963
+ ch == 126 /* Ch.Tilde */ || ch == 37 /* Ch.Percent */;
1964
+ }
1965
+ // The offset after the `<...>` at the current position in a regex.
1966
+ // When it is not closed on its line, this is the negated offset of the
1967
+ // end of the text that was gone over to find that out.
1968
+ function assertionEnd(input) {
1969
+ // A list of words, in which quotes and brackets are text: < a ' b >
1970
+ let words = isBlank(input.peek(1));
1971
+ for (let pos = 1, depth = 1;;) {
1972
+ let ch = input.peek(pos);
1973
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1974
+ return -pos;
1975
+ if (words) {
1976
+ pos++;
1977
+ if (ch == 62 /* Ch.Greater */)
1978
+ return pos;
1979
+ }
1980
+ else if (ch == 92 /* Ch.Backslash */) {
1981
+ pos += input.peek(pos + 1) == 10 /* Ch.Newline */ || input.peek(pos + 1) < 0 ? 1 : 2;
1982
+ }
1983
+ else if (isIdentifierStart(ch)) {
1984
+ // A name takes in an apostrophe before a letter, as regexEnd
1985
+ // reads it: <it's>
1986
+ pos = nameEnd(input, pos);
1987
+ }
1988
+ else if (quoteClose(ch)) {
1989
+ let end = quotedEnd(input, pos);
1990
+ pos = end < 0 ? pos + 1 : end;
1991
+ }
1992
+ else if (ch == 91 /* Ch.BracketOpen */) {
1993
+ // The brackets of a character class can hold a `>` and a `}`,
1994
+ // and can span lines.
1995
+ let end = pos + 1;
1996
+ while (input.peek(end) != 93 /* Ch.BracketClose */ && input.peek(end) >= 0)
1997
+ end += input.peek(end) == 92 /* Ch.Backslash */ ? 2 : 1;
1998
+ pos = input.peek(end) == 93 /* Ch.BracketClose */ ? end + 1 : pos + 1;
1999
+ }
2000
+ else if (ch == 123 /* Ch.BraceOpen */) {
2001
+ // So can a block of code: <?{ $x > 1 }>
2002
+ let end = pos + 1;
2003
+ for (let braces = 1; braces > 0; end++) {
2004
+ let inner = input.peek(end);
2005
+ if (inner < 0 || inner == 10 /* Ch.Newline */)
2006
+ return -pos;
2007
+ if (inner == 123 /* Ch.BraceOpen */)
2008
+ braces++;
2009
+ else if (inner == 125 /* Ch.BraceClose */)
2010
+ braces--;
2011
+ }
2012
+ pos = end;
2013
+ }
2014
+ else if (ch == 60 /* Ch.Less */) {
2015
+ depth++;
2016
+ pos++;
2017
+ }
2018
+ else if (ch == 62 /* Ch.Greater */) {
2019
+ pos++;
2020
+ if (--depth == 0)
2021
+ return pos;
2022
+ }
2023
+ else {
2024
+ pos++;
2025
+ }
2026
+ }
2027
+ }
2028
+ // The pieces of the body of a token, rule or regex declaration. The
2029
+ // context tells whether the position is in such a body, and whether it
2030
+ // is in a block of code there, which is left to the other tokenizers.
2031
+ const regexToken = new lr.ExternalTokenizer((input, stack) => {
2032
+ let current = context(stack), { regex } = current, next = input.next;
2033
+ if (!regex || regex.braces > 0) {
2034
+ // At the start of the parse of the inside of a regex literal, the
2035
+ // opening delimiter: `/`, or a quote word with its adverbs: rx:i/
2036
+ if (current == startContext && stack.canShift(regexLitOpen)) {
2037
+ let opening = regexOpening(input);
2038
+ if (opening)
2039
+ input.acceptToken(regexLitOpen, opening.start);
2040
+ return;
2041
+ }
2042
+ // Outside of a regex, or in a block of code in one, where another
2043
+ // regex can be declared. An empty body, `{}`, has no regex.
2044
+ if (next >= 0 && next != 125 /* Ch.BraceClose */ && stack.canShift(regexStart))
2045
+ input.acceptToken(regexStart);
2046
+ return;
2047
+ }
2048
+ let { literalEnd } = regex;
2049
+ if (literalEnd >= 0) {
2050
+ // A literal ends at its closing delimiter. The rest of what is
2051
+ // parsed, which for s/a/b/ includes the replacement, is one token.
2052
+ if (next < 0 || input.pos >= literalEnd) {
2053
+ skipToEnd(input);
2054
+ return input.acceptToken(regexLitClose);
2055
+ }
2056
+ }
2057
+ else if (next < 0 || next == 125 /* Ch.BraceClose */ || next == 10 /* Ch.Newline */ && startsRegexDeclaration(input, 1)) {
2058
+ // The body ends at its closing brace. One that is not closed ends
2059
+ // before the next regex declaration, which a body does not hold, so
2060
+ // that the declarations after it are still found.
2061
+ return input.acceptToken(regexBodyEnd);
2062
+ }
2063
+ // A block of code, and an escape, are tokens of the grammar. An
2064
+ // escape does not take a line break, where the check above is made.
2065
+ if (next == 123 /* Ch.BraceOpen */)
2066
+ return;
2067
+ if (next == 92 /* Ch.Backslash */ && input.peek(1) >= 0 && input.peek(1) != 10 /* Ch.Newline */)
2068
+ return;
2069
+ // How far a piece of a literal can go: up to its closing delimiter.
2070
+ // The pieces are read by other rules than the ones that found that
2071
+ // delimiter, and where the two disagree, the delimiter wins. A piece
2072
+ // that would go over it is text.
2073
+ let limit = literalEnd < 0 ? Infinity : literalEnd - input.pos;
2074
+ if (next == 35 /* Ch.Hash */) {
2075
+ // An embedded comment, #`( ... ), or one that runs to the end of the line.
2076
+ let end = embeddedCommentEnd(input, 0);
2077
+ if (end > 0)
2078
+ return input.acceptToken(regexBlockComment, end);
2079
+ skipLine(input);
2080
+ return input.acceptToken(regexComment);
2081
+ }
2082
+ if (quoteClose(next)) {
2083
+ let end = quotedEnd(input, 0);
2084
+ if (end > 0 && end <= limit)
2085
+ return input.acceptToken(regexQuote, end);
2086
+ }
2087
+ else if (next == 60 /* Ch.Less */ || next == 62 /* Ch.Greater */ || next == 171 /* Ch.GuillemetOpen */ || next == 187 /* Ch.GuillemetClose */ ||
2088
+ next == 41 /* Ch.ParenClose */ && input.peek(1) == 62 /* Ch.Greater */) {
2089
+ // Word boundaries and capture markers stand alone: << >> « » <( )>
2090
+ let after = input.peek(1);
2091
+ if (next != 60 /* Ch.Less */ || after == 60 /* Ch.Less */ || after == 40 /* Ch.ParenOpen */) {
2092
+ let size = next == 171 /* Ch.GuillemetOpen */ || next == 187 /* Ch.GuillemetClose */ ? 1 : 2;
2093
+ if (next != 62 /* Ch.Greater */ || after == 62 /* Ch.Greater */)
2094
+ return input.acceptToken(regexOperator, size);
2095
+ }
2096
+ else {
2097
+ let end = assertionEnd(input);
2098
+ if (end > limit)
2099
+ return input.acceptToken(regexText, 1);
2100
+ if (end > 0) {
2101
+ // <[a..z]>, <-[a]>, <+alpha-[b]>, <?[c]>
2102
+ let kind = after == 63 /* Ch.Question */ || after == 33 /* Ch.Bang */ ? input.peek(2) : after;
2103
+ let isClass = kind == 91 /* Ch.BracketOpen */ || kind == 45 /* Ch.Hyphen */ || kind == 43 /* Ch.Plus */;
2104
+ return input.acceptToken(isClass ? CharacterClass : Assertion, end);
2105
+ }
2106
+ // What is not closed is text, up to the brace that closes the
2107
+ // body if there is one on the line.
2108
+ let stop = 1;
2109
+ while (stop < -end && input.peek(stop) != 125 /* Ch.BraceClose */)
2110
+ stop++;
2111
+ return input.acceptToken(regexText, stop);
2112
+ }
2113
+ }
2114
+ else if (next == 36 /* Ch.Dollar */ || next == 64 /* Ch.At */) {
2115
+ let after = input.peek(1);
2116
+ // A named capture: $<name>
2117
+ if (next == 36 /* Ch.Dollar */ && after == 60 /* Ch.Less */) {
2118
+ let end = nameEnd(input, 2);
2119
+ if (end > 0 && input.peek(end) == 62 /* Ch.Greater */)
2120
+ return input.acceptToken(regexCapture, end + 1);
2121
+ }
2122
+ // A variable is a token of the grammar: $x, $0, $/, @list, $!attr, $*dynamic
2123
+ // Not the `$` before the delimiter that closes a literal: /a$/
2124
+ if (limit != 1) {
2125
+ if (isIdentifierStart(after) || next == 36 /* Ch.Dollar */ && (isDigit(after) || after == 47 /* Ch.Slash */))
2126
+ return;
2127
+ if ((after == 33 /* Ch.Bang */ || after == 46 /* Ch.Dot */ || after == 42 /* Ch.Star */ || after == 63 /* Ch.Question */) &&
2128
+ isIdentifierStart(input.peek(2)))
2129
+ return;
2130
+ }
2131
+ // Otherwise `$` and `$$` anchor.
2132
+ if (next == 36 /* Ch.Dollar */) {
2133
+ while (input.next == 36 /* Ch.Dollar */ && input.pos != literalEnd)
2134
+ input.advance();
2135
+ return input.acceptToken(regexOperator);
2136
+ }
2137
+ }
2138
+ else if (isRegexOperator(next)) {
2139
+ while (isRegexOperator(input.next) && input.pos != literalEnd)
2140
+ input.advance();
2141
+ return input.acceptToken(regexOperator);
2142
+ }
2143
+ // Text, up to where one of the above may apply.
2144
+ for (;;) {
2145
+ input.advance();
2146
+ let ch = input.next;
2147
+ if (ch < 0 || input.pos == literalEnd ||
2148
+ ch == 10 /* Ch.Newline */ || ch == 92 /* Ch.Backslash */ || quoteClose(ch) ||
2149
+ ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */ || ch == 171 /* Ch.GuillemetOpen */ || ch == 187 /* Ch.GuillemetClose */ ||
2150
+ ch == 41 /* Ch.ParenClose */ && input.peek(1) == 62 /* Ch.Greater */ ||
2151
+ ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ || ch == 35 /* Ch.Hash */ || ch == 36 /* Ch.Dollar */ ||
2152
+ ch == 64 /* Ch.At */ || isRegexOperator(ch))
2153
+ break;
2154
+ }
2155
+ input.acceptToken(regexText);
2156
+ });
2157
+ // ---- Names ----
2158
+ // The length of the method dot at offset `pos`, with its modifier, or
2159
+ // zero when no name follows it there.
2160
+ function methodDotSize(input, pos) {
2161
+ if (input.peek(pos) != 46 /* Ch.Dot */)
2162
+ return 0;
2163
+ let size = 1, next = input.peek(pos + 1);
2164
+ if (next == 63 /* Ch.Question */ || next == 43 /* Ch.Plus */ || next == 42 /* Ch.Star */ || next == 94 /* Ch.Caret */ || next == 38 /* Ch.Amp */)
2165
+ next = input.peek(pos + ++size);
2166
+ return isIdentifierStart(next) ? size : 0;
2167
+ }
2168
+ // The dot of a method call, with its optional `?`, `+`, `*`, `^` or `&`
2169
+ // modifier. It is only produced when a name follows. In a string, a
2170
+ // method call is only interpolated after a variable, and when it or the
2171
+ // calls chained to it end in an argument list: "$x.foo()", "$x.a.b()"
2172
+ const methodDotToken = new lr.ExternalTokenizer((input, stack) => {
2173
+ let size = methodDotSize(input, 0);
2174
+ if (!size)
2175
+ return;
2176
+ if (context(stack).quote && inQuoteText(stack) && (!afterQuotedVariable(stack) || !interpolatesCall(input, 0)))
2177
+ return;
2178
+ input.acceptToken(methodDot, size);
2179
+ });
2180
+ // The offset after an operator name's `:<...>` part, as in infix:<+>,
2181
+ // circumfix:<[ ]>, infix:['+'] and term:sym<x>, or `pos` when there is
2182
+ // none there. The name before it runs from `nameStart` to `pos`.
2183
+ function categoryEnd(input, nameStart, pos) {
2184
+ if (input.peek(pos) != 58 /* Ch.Colon */)
2185
+ return pos;
2186
+ let open = pos + 1, sym = word(input, open, open + 3) == "sym";
2187
+ if (sym)
2188
+ open += 3;
2189
+ let first = input.peek(open);
2190
+ if (first == 91 /* Ch.BracketOpen */) {
2191
+ // Only a quoted operator: ['+']
2192
+ let quote = input.peek(open + 1);
2193
+ if (quote != 39 /* Ch.Apostrophe */ && quote != 34 /* Ch.DoubleQuote */)
2194
+ return pos;
2195
+ let end = quotedEnd(input, open + 1);
2196
+ return end > 0 && input.peek(end) == 93 /* Ch.BracketClose */ ? end + 1 : pos;
2197
+ }
2198
+ let close = first == 60 /* Ch.Less */ ? 62 /* Ch.Greater */ : first == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : -1;
2199
+ if (close < 0)
2200
+ return pos;
2201
+ // With double angles, blanks can surround the operator, which can
2202
+ // hold a `>` itself: infix:<< stash-eq >>, infix:<<(>=)>>
2203
+ // When this is not that form, the operator starts with `<`: infix:<<=>
2204
+ if (first == 60 /* Ch.Less */ && input.peek(open + 1) == 60 /* Ch.Less */) {
2205
+ let start = blanksEnd(input, open + 2);
2206
+ let closes = (at) => input.peek(at) == close && input.peek(at + 1) == close && input.peek(at + 2) != close;
2207
+ // An operator is short, and a token must not look far past its end.
2208
+ for (let end = start; end < start + maxGap; end++) {
2209
+ let ch = input.peek(end);
2210
+ // Not a shift in code without spaces: infix:<<=>($a){$a>>1}
2211
+ if (end > start && closes(end) && !continuesName(input, end + 2) && input.peek(end + 2) != 36 /* Ch.Dollar */)
2212
+ return end + 2;
2213
+ if (ch < 0 || isSpace(ch)) {
2214
+ let after = blanksEnd(input, end);
2215
+ if (end > start && closes(after))
2216
+ return after + 2;
2217
+ break;
2218
+ }
2219
+ }
2220
+ }
2221
+ // A `:sym<…>` that holds a pair of brackets with a space between them,
2222
+ // as the sym of a circumfix does: token b:sym<{ }>
2223
+ let inner = brackets$1[input.peek(open + 1)];
2224
+ if (sym && inner != null && input.peek(open + 2) == 32 /* Ch.Space */ && input.peek(open + 3) == inner &&
2225
+ input.peek(open + 4) == close)
2226
+ return open + 5;
2227
+ // The two halves of a circumfix are separated by one space.
2228
+ let spaces = /circumfix$/.test(word(input, nameStart, pos)) ? 1 : 0;
2229
+ for (let i = open + 1;; i++) {
2230
+ let ch = input.peek(i);
2231
+ if (ch < 0 || isSpace(ch) && (ch != 32 /* Ch.Space */ || i == open + 1 || --spaces < 0))
2232
+ return pos;
2233
+ // The operator itself can be `>`, so the last closer before a break counts.
2234
+ if (ch == close && !(input.peek(i + 1) == close))
2235
+ return i + 1;
2236
+ }
2237
+ }
2238
+ // A name after a method dot or a declarator. The grammar's keywords are
2239
+ // specialized identifiers, and specialization does not look at the
2240
+ // parse state, so these positions get tokens of their own.
2241
+ const nameToken = new lr.ExternalTokenizer((input, stack) => {
2242
+ let next = input.next;
2243
+ // The name of a constant can have a sigil: constant $LIMIT = 3
2244
+ if ((next == 36 /* Ch.Dollar */ || next == 64 /* Ch.At */ || next == 37 /* Ch.Percent */ || next == 38 /* Ch.Amp */) && stack.canShift(declaredVariable)) {
2245
+ let end = nameEnd(input, 1);
2246
+ // constant &infix:<plus> = &infix:<+>
2247
+ if (end > 0)
2248
+ input.acceptToken(declaredVariable, next == 38 /* Ch.Amp */ ? categoryEnd(input, 1, end) : end);
2249
+ return;
2250
+ }
2251
+ // Only a method declaration takes a mark: `method !private`, `method ^meta`.
2252
+ let mark = next == 33 /* Ch.Bang */ || next == 94 /* Ch.Caret */ ? 1 : 0;
2253
+ let end = nameEnd(input, mark);
2254
+ if (end < 0)
2255
+ return;
2256
+ if (stack.canShift(MethodName)) {
2257
+ if (!mark)
2258
+ input.acceptToken(MethodName, end);
2259
+ return;
2260
+ }
2261
+ let named = end;
2262
+ end = categoryEnd(input, mark, end);
2263
+ // Blanks can come before the `:sym<...>` of a declaration: token c :sym<a> { a }
2264
+ if (end == named) {
2265
+ let sym = gapEnd(input, end);
2266
+ if (sym > end && word(input, sym, sym + 4) == ":sym") {
2267
+ let symEnd = categoryEnd(input, mark, sym);
2268
+ if (symEnd > sym)
2269
+ end = symEnd;
2270
+ }
2271
+ }
2272
+ // The name follows the declarator. After a character that is no
2273
+ // token, error recovery would take the next word for it: the `is` of
2274
+ // `class 42 is Foo`.
2275
+ if (!afterWord(input))
2276
+ return;
2277
+ if (!mark && stack.canShift(declaredName))
2278
+ input.acceptToken(declaredName, end);
2279
+ else if (stack.canShift(declaredMethodName))
2280
+ input.acceptToken(declaredMethodName, end);
2281
+ });
2282
+ // Whether the last character before the current position, leaving out
2283
+ // whitespace, ends a word, or may end a comment: a `#` comes before it
2284
+ // on its line, as in `class #`(c) Foo`.
2285
+ function afterWord(input) {
2286
+ let pos = -1;
2287
+ while (isSpace(input.peek(pos)))
2288
+ pos--;
2289
+ let ch = input.peek(pos);
2290
+ if (isIdentifierStart(ch) || isDigit(ch))
2291
+ return true;
2292
+ for (; ch >= 0 && ch != 10 /* Ch.Newline */; ch = input.peek(--pos))
2293
+ if (ch == 35 /* Ch.Hash */)
2294
+ return true;
2295
+ return false;
2296
+ }
2297
+ // The type smiley in Int:D, Str:U and Any:_. It has to touch the type
2298
+ // name, and must not be the start of a longer pair such as :Default.
2299
+ //
2300
+ // A type name without a smiley ends in an empty token. Without it, the
2301
+ // parser has to read the token after the name to know that the name is
2302
+ // complete, and when a long comment is in between, it records that as
2303
+ // a lookahead, which keeps the tokens before it from being reused.
2304
+ const smileyToken = new lr.ExternalTokenizer((input, stack) => {
2305
+ if (!stack.canShift(noSmiley))
2306
+ return;
2307
+ if (input.next == 58 /* Ch.Colon */) {
2308
+ let kind = input.peek(1);
2309
+ if ((kind == 68 /* Ch.D */ || kind == 85 /* Ch.U */ || kind == 95 /* Ch.Underscore */) && !continuesName(input, 2))
2310
+ return input.acceptToken(smiley, 2);
2311
+ }
2312
+ input.acceptToken(noSmiley, 0);
2313
+ });
2314
+ // v6, v6.d, v1.2.3, v1.2+, v1.*. A name such as v8-engine is not a version.
2315
+ const versionToken = new lr.ExternalTokenizer((input, stack) => {
2316
+ if (input.next != 118 /* Ch.v */ || !isDigit(input.peek(1)) || !stack.canShift(Version))
2317
+ return;
2318
+ let pos = 2;
2319
+ for (;;) {
2320
+ while (isDigit(input.peek(pos)))
2321
+ pos++;
2322
+ if (input.peek(pos) != 46 /* Ch.Dot */)
2323
+ break;
2324
+ let part = input.peek(pos + 1);
2325
+ if (part == 42 /* Ch.Star */) {
2326
+ pos += 2;
2327
+ break;
2328
+ }
2329
+ if (isDigit(part))
2330
+ pos++;
2331
+ else if (isAsciiLetter(part)) {
2332
+ pos += 2;
2333
+ while (isAsciiLetter(input.peek(pos)))
2334
+ pos++;
2335
+ }
2336
+ else
2337
+ break;
2338
+ }
2339
+ if (input.peek(pos) == 43 /* Ch.Plus */)
2340
+ pos++;
2341
+ else if (continuesName(input, pos))
2342
+ return;
2343
+ input.acceptToken(Version, pos);
2344
+ });
2345
+
2346
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2347
+ const spec_identifier = {__proto__:null,class:86, role:88, grammar:90, module:92, package:94, sub:108, method:112, submethod:114, token:122, rule:124, regex:126, enum:146, subset:152, constant:158, my:178, our:180, has:182, state:184, temp:186, let:188, anon:190, augment:192, supersede:194, unit:196, multi:198, proto:200, only:202, if:204, elsif:206, else:208, unless:210, with:212, orwith:214, without:216, for:218, while:220, until:222, loop:224, repeat:226, given:228, when:230, default:232, do:234, gather:236, take:238, try:240, return:242, next:244, last:246, redo:248, proceed:250, succeed:252, react:254, whenever:256, supply:258, emit:260, start:262, use:264, need:266, import:268, require:270, no:272, is:274, does:276, of:278, returns:280, handles:282, where:284, will:286, trusts:288, hides:290, and:292, or:294, not:296, xor:298, so:300, andthen:302, orelse:304, notandthen:306, div:308, mod:310, gcd:312, lcm:314, eq:316, ne:318, lt:320, gt:322, le:324, ge:326, cmp:328, leg:330, eqv:332, but:334, self:336};
2348
+ const spec_capIdentifier = {__proto__:null,True:338, False:340, Nil:342, BEGIN:344, CHECK:346, INIT:348, END:350, ENTER:352, LEAVE:354, KEEP:356, UNDO:358, FIRST:360, NEXT:362, LAST:364, PRE:366, POST:368, CATCH:370, CONTROL:372, QUIT:374, CLOSE:376, DOC:378};
2349
+ const parser$1 = lr.LRParser.deserialize({
2350
+ version: 14,
2351
+ states: "/`QfQDdOOO+WO#tOOO+]OWOOO+bO,UOOO,ROSO'#DOO,]QDdO'#DSO,dQDdO'#DVO,kQDdO'#DaOOQ.W'#Di'#DiO,rQDdO'#DcO6^Q8WO'#EPOOQ.W'#EQ'#EQO6cQ7gO'#EROOQ.W'#ET'#ETO7YO!0YO'#ETOOQ.W'#HZ'#HZOOQ.W'#HY'#HYOOQ.W'#Gj'#GjQfQDdOOO7aQEUO'#DWO7hQEUO'#DcO7oQEUO'#DcOA_QEUO'#DjOAiQEUO'#DvOKjQEUO'#DyO!'kQEUO'#D|OOQ.W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Link PodFormat Heredoc Heredoc Heredoc Heredoc . MethodName Version CharacterClass Assertion StringLiteral Operator LineComment BlockComment VariableName StringLiteral Regex Regex Operator VariableName VariableName LineComment DocComment Program Pod Number ) ( Parens ] [ Brackets PackageDeclaration class role grammar module package PackageName } { Block ; RoutineDeclaration sub RoutineName method submethod RoutineName RoutineName RegexDeclaration token rule regex RegexName Block Regex Escape VariableName AttributeName SpecialVariable Block EnumDeclaration enum EnumName SubsetDeclaration subset SubsetName ConstantDeclaration constant ConstantName MethodCall Identifier TypeName Number StringLiteral NestedDelimiters Interpolation PairKey my our has state temp let anon augment supersede unit multi proto only if elsif else unless with orwith without for while until loop repeat given when default do gather take try return next last redo proceed succeed react whenever supply emit start use need import require no is does of returns handles where will trusts hides and or not xor so andthen orelse notandthen div mod gcd lcm eq ne lt gt le ge cmp leg eqv but self True False Nil BEGIN CHECK INIT END ENTER LEAVE KEEP UNDO FIRST NEXT LAST PRE POST CATCH CONTROL QUIT CLOSE DOC Operator , : :: . Regex Heredoc StringLiteral",
2355
+ maxTerm: 237,
2356
+ context: trackContext,
2357
+ nodeProps: [
2358
+ ["openedBy", 36,"(",39,"[",49,"{"],
2359
+ ["closedBy", 37,")",40,"]",50,"}"]
2360
+ ],
2361
+ skippedNodes: [0,1,31,32],
2362
+ repeatNodeCount: 6,
2363
+ tokenData: "#*w~R#vX^)ipq)iqr*ast,jtu.ZuvMwvw!'Xxy!+Pyz!+Uz{*a{|*a|}!+Z}!O*a!O!P!+`!P!Q*a!Q!R!,O!R![!._![!]!1S!]!^!DS!^!_*a!_!`!DX!`!a*a!a!b*a!b!c!Fk!c!}!=U!}#O!J`#O#P!Je#P#Q##U#Q#R*a#R#S##Z#T#o##Z#o#p#*X#p#q*a#q#r#*^#r#s*a#y#z)i$f$g)i$g$p*a$p$q##Z$q$r*a$r$s*a$t$x*a$x$y#*c$y$z#*c$z${*a${$|##Z$|%P*a%P%Q#*c%Q%R##Z%R%S*a%S%V!.Y%V%W*a%W%o##Z%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&[''T##Z''d;'S##Z;'S;=`#){?&r?Bj##Z?EO?HR##Z?Hw?Ic##Z?Ii?JT##Z?J`?L{##Z~#*OP;=`<%l##Z~#*UP![!]#&r~#*^O!S~~#*cO!R~P#*hT%UP$x$y#*c$y$z#*c%P%Q#*c$Kh$Ki#*c$Kl$Kt#*c",
2364
+ tokenizers: [smileyToken, blockComment, podToken, heredocToken, methodDotToken, nameToken, versionToken, regexToken, quoteToken, termToken, 0, 1],
2365
+ topRules: {"Program":[0,33],"Regex":[1,195],"Heredoc":[2,196],"StringLiteral":[3,197]},
2366
+ specialized: [{term: 230, get: (value) => spec_identifier[value] || -1},{term: 233, get: (value) => spec_capIdentifier[value] || -1}],
2367
+ tokenPrec: 3646
2368
+ });
2369
+
2370
+ // The keywords of the grammar, with the tag each is highlighted with.
2371
+ // Highlighting and completion both read this table. `True`, `False` and
2372
+ // `Nil` are values, and are not in it.
2373
+ const keywordTags = {
2374
+ "my our has state temp let constant anon augment supersede unit multi proto only": highlight.tags.definitionKeyword,
2375
+ "class role grammar module package sub method submethod token rule regex enum subset": highlight.tags.definitionKeyword,
2376
+ "if elsif else unless with orwith without for while until loop repeat given when default": highlight.tags.controlKeyword,
2377
+ "do gather take try return next last redo proceed succeed react whenever supply emit start": highlight.tags.controlKeyword,
2378
+ "BEGIN CHECK INIT END ENTER LEAVE KEEP UNDO FIRST NEXT LAST PRE POST CATCH CONTROL QUIT CLOSE DOC": highlight.tags.controlKeyword,
2379
+ "use need import require no": highlight.tags.moduleKeyword,
2380
+ "is does of returns handles where will trusts hides": highlight.tags.modifier,
2381
+ "and or not xor so andthen orelse notandthen div mod gcd lcm": highlight.tags.operatorKeyword,
2382
+ "eq ne lt gt le ge cmp leg eqv but": highlight.tags.operatorKeyword,
2383
+ self: highlight.tags.self
2384
+ };
2385
+
2386
+ const scopes = new common.NodeWeakMap();
2387
+ const scopeNodes = new Set(["Block", "Interpolation", "Program"]);
2388
+ const variableNodes = new Set(["VariableName", "AttributeName"]);
2389
+ const declarators = new Set(["my", "our", "has", "state"]);
2390
+ function isDeclaration(name) { return name.endsWith("Declaration"); }
2391
+ /// Whether a variable is a placeholder, which is declared by being
2392
+ /// used: $^a, and the named $:a
2393
+ function isPlaceholder(name) { return /^[$@%&][\^:]/.test(name); }
2394
+ // Whether the node `name` is a term that a block can be the subscript
2395
+ // of, when it touches the block: %h{$key}
2396
+ function isSubscripted(name) { return /^[A-Z]/.test(name) && name != "Operator"; }
2397
+ // The name of the variable without a sigil that the backslash `node`
2398
+ // comes right before, as in `\x`. A capitalized one reads as a type.
2399
+ function sigillessName(state, node) {
2400
+ let next = node.nextSibling;
2401
+ return node.name == "Operator" && next && (next.name == "Identifier" || next.name == "TypeName") &&
2402
+ next.from == node.to && state.sliceDoc(node.from, node.to) == "\\" ? next : null;
2403
+ }
2404
+ // Whether a block is a subscript, as in %h{$key}: it touches the term
2405
+ // before it. It is not a scope for placeholder variables.
2406
+ function isSubscript(block) {
2407
+ let prev = block.prevSibling;
2408
+ return block.name == "Block" && prev != null && prev.to == block.from && isSubscripted(prev.name);
2409
+ }
2410
+ // The native types, whose names are not capitalized. Another word after
2411
+ // a declarator is more likely a call that follows an unfinished `my`.
2412
+ const nativeTypes = /^(u?int(8|16|32|64)?|num(32|64)?|str|atomicint|byte|bool|u?long(long)?|s?size_t)$/;
2413
+ // Whether `node`, which comes after a declarator, is (part of) the type
2414
+ // of what is declared: my Int $x, my int $x, my Array[Int] @y, and the
2415
+ // coercion type my Foo(Str) $x, whose parentheses touch the type name
2416
+ // `prev`. `types` holds the names of the types that the document
2417
+ // declares, which need not be capitalized.
2418
+ function isType(state, node, prev, types) {
2419
+ let { name } = node, text = state.sliceDoc(node.from, node.to);
2420
+ if (name == "Identifier")
2421
+ return nativeTypes.test(text) || types != null && types.has(text);
2422
+ return name == "TypeName" || name == "Brackets" ||
2423
+ (name == "Parens" || isSmiley(text, name)) && prev == "TypeName";
2424
+ }
2425
+ // Whether a node is the smiley of a type whose name is not capitalized,
2426
+ // which is a pair key: the `:D` of `my foo:D $x`
2427
+ function isSmiley(text, name) { return name == "PairKey" && /^:[DU_]$/.test(text); }
2428
+ function hasSigil(completion) { return /^[$@%&]/.test(completion.label); }
2429
+ function variable(label) {
2430
+ return { label, type: label[0] == "&" ? "function" : /^.[!.]/.test(label) ? "property" : "variable", boost: 1 };
2431
+ }
2432
+ function isArrow(text) { return text == "->" || text == "<->"; }
2433
+ // The part of the flow that the first child of a part of a node, which
2434
+ // starts at `from`, depends on.
2435
+ function flowKey(flow, from) {
2436
+ let touching = flow.prevTo == from;
2437
+ let prev = !touching ? 0 : flow.prev == "TypeName" ? 1 : isSubscripted(flow.prev) ? 2 : 0;
2438
+ let key = (flow.declaring ? 1 : 0) | (touching && flow.sigilless ? 2 : 0) | prev << 2;
2439
+ return flow.maybeType ? key + " " + flow.maybeType : key;
2440
+ }
2441
+ // What the anonymous nodes that group the children of a long node
2442
+ // declare. The tree after an edit reuses those that the edit leaves
2443
+ // alone, with the same text in them. Only their position can differ,
2444
+ // and what is kept does not depend on it.
2445
+ const chunks = new WeakMap();
2446
+ function append(to, from) {
2447
+ for (let item of from)
2448
+ to.push(item);
2449
+ }
2450
+ class Gatherer {
2451
+ constructor(state) {
2452
+ this.state = state;
2453
+ this.variables = [];
2454
+ this.names = [];
2455
+ this.methods = [];
2456
+ this.typed = [];
2457
+ // The number of children gone over by `child`.
2458
+ this.children = 0;
2459
+ }
2460
+ text(node) { return this.state.sliceDoc(node.from, node.to); }
2461
+ add(completion) {
2462
+ (hasSigil(completion) ? this.variables : this.names).push(completion);
2463
+ }
2464
+ declare(node) {
2465
+ let label = this.text(node);
2466
+ // A name without a sigil: my \x
2467
+ if (!variableNodes.has(node.name))
2468
+ return this.names.push({ label, type: "variable", boost: 1 });
2469
+ this.variables.push(variable(label));
2470
+ // `has $.x` also makes the private `$!x`, and `$^a` can be written `$a`.
2471
+ if (label[1] == ".")
2472
+ this.variables.push(variable(label[0] + "!" + label.slice(2)));
2473
+ else if (isPlaceholder(label))
2474
+ this.variables.push(variable(label[0] + label.slice(2)));
2475
+ }
2476
+ // Declares the variable `node` if `type` turns out to be a type.
2477
+ declareTyped(node, type) {
2478
+ let start = this.variables.length;
2479
+ this.declare(node);
2480
+ for (let completion of this.variables.splice(start))
2481
+ this.typed.push({ type, completion });
2482
+ }
2483
+ // Whether the variable `node` is a placeholder. Its first character is a sigil.
2484
+ isPlaceholderNode(node) {
2485
+ let second = this.state.sliceDoc(node.from + 1, node.from + 2);
2486
+ return second == "^" || second == ":";
2487
+ }
2488
+ // Declares the name after `node`, when `node` is the backslash of a
2489
+ // variable without a sigil: my \x = 1, sub f(\x) { }
2490
+ declareSigilless(node) {
2491
+ let name = sigillessName(this.state, node);
2492
+ if (name)
2493
+ this.declare(name);
2494
+ return name != null;
2495
+ }
2496
+ // The variables of a signature, or of the parentheses of `my (...)`.
2497
+ // What follows a `=` or a `where`, up to the next comma, is a default
2498
+ // value or a constraint, and uses variables rather than declaring them.
2499
+ declareAll(node) {
2500
+ let uses = false;
2501
+ for (let child = node.firstChild; child; child = child.nextSibling) {
2502
+ let { name } = child;
2503
+ if (name == ",")
2504
+ uses = false;
2505
+ else if (name == "where" || name == "Operator" && this.text(child) == "=")
2506
+ uses = true;
2507
+ else if (uses)
2508
+ continue;
2509
+ else if (this.declareSigilless(child))
2510
+ continue;
2511
+ else if (variableNodes.has(name))
2512
+ this.declare(child);
2513
+ else if (name == "Parens" || name == "Brackets")
2514
+ this.declareAll(child);
2515
+ }
2516
+ }
2517
+ addMethods(scope) {
2518
+ append(this.methods, scopeOf(scope, this.state).methods);
2519
+ }
2520
+ // Goes over the content of a node that is not a scope of its own.
2521
+ content(node) {
2522
+ let cursor = node.cursor(common.IterMode.IncludeAnonymous);
2523
+ if (cursor.firstChild())
2524
+ this.sequence(cursor, { declaring: false, sigilless: false, prev: "", prevTo: -1, maybeType: "" });
2525
+ }
2526
+ // Goes over the node at `cursor` and the siblings after it. They are
2527
+ // the children of a node, or the anonymous nodes that group them.
2528
+ sequence(cursor, flow) {
2529
+ do {
2530
+ if (!cursor.type.isAnonymous) {
2531
+ this.child(cursor.node, flow);
2532
+ }
2533
+ else if (cursor.tree) {
2534
+ this.chunk(cursor, cursor.tree, flow);
2535
+ }
2536
+ else if (cursor.firstChild()) {
2537
+ this.sequence(cursor, flow);
2538
+ cursor.parent();
2539
+ }
2540
+ } while (cursor.nextSibling());
2541
+ }
2542
+ // Goes over the anonymous node `tree` at `cursor`, or takes what was
2543
+ // gathered from it before, with the same flow.
2544
+ chunk(cursor, tree, flow) {
2545
+ let { from, to } = cursor, chunk = chunks.get(tree);
2546
+ let found = chunk && chunk.gathered.get(flowKey(flow, from + chunk.startGap));
2547
+ if (!found) {
2548
+ if (!cursor.firstChild())
2549
+ return;
2550
+ let start = cursor.from, key = flowKey(flow, start);
2551
+ let inner = new Gatherer(this.state), after = Object.assign({}, flow);
2552
+ inner.sequence(cursor, after);
2553
+ cursor.parent();
2554
+ // Without a child, the flow after the part is the one before it.
2555
+ if (!inner.children)
2556
+ return;
2557
+ if (!chunk)
2558
+ chunks.set(tree, chunk = { startGap: start - from, gathered: new Map });
2559
+ found = { variables: inner.variables, names: inner.names, methods: inner.methods, typed: inner.typed,
2560
+ declaring: after.declaring, sigilless: after.sigilless, maybeType: after.maybeType, prev: after.prev,
2561
+ endGap: to - after.prevTo };
2562
+ chunk.gathered.set(key, found);
2563
+ }
2564
+ // Only a part with children is kept.
2565
+ this.children++;
2566
+ append(this.variables, found.variables);
2567
+ append(this.names, found.names);
2568
+ append(this.methods, found.methods);
2569
+ append(this.typed, found.typed);
2570
+ flow.declaring = found.declaring;
2571
+ flow.sigilless = found.sigilless;
2572
+ flow.maybeType = found.maybeType;
2573
+ flow.prev = found.prev;
2574
+ flow.prevTo = to - found.endGap;
2575
+ }
2576
+ // Goes over a child of a node that is not a scope of its own. What it
2577
+ // declares depends on the children before it only through `flow`.
2578
+ child(child, flow) {
2579
+ let { name } = child, touching = flow.prevTo == child.from;
2580
+ let { declaring } = flow, prev = touching ? flow.prev : "";
2581
+ let sigilless = flow.sigilless && touching, { maybeType } = flow;
2582
+ this.children++;
2583
+ flow.prev = name;
2584
+ flow.prevTo = child.to;
2585
+ flow.sigilless = false;
2586
+ flow.maybeType = "";
2587
+ if (sigilless && (name == "Identifier" || name == "TypeName")) {
2588
+ this.declare(child);
2589
+ flow.declaring = false;
2590
+ return;
2591
+ }
2592
+ if (declarators.has(name)) {
2593
+ flow.declaring = true;
2594
+ return;
2595
+ }
2596
+ if (declaring && isType(this.state, child, prev))
2597
+ return;
2598
+ flow.declaring = false;
2599
+ if (declaring && name == "Identifier") {
2600
+ flow.maybeType = this.text(child);
2601
+ return;
2602
+ }
2603
+ // What can follow a type: my foo:D $x, my foo(Str) $x, my foo[Int] @a
2604
+ if (maybeType && touching && (name == "Parens" || name == "Brackets" || isSmiley(this.text(child), name))) {
2605
+ flow.maybeType = maybeType;
2606
+ return;
2607
+ }
2608
+ // A placeholder variable declares itself where it is used: { $^a + $^b }
2609
+ if (name == "VariableName" && this.isPlaceholderNode(child))
2610
+ this.declare(child);
2611
+ else if (maybeType && variableNodes.has(name))
2612
+ this.declareTyped(child, maybeType);
2613
+ else if (declaring && name == "Operator" && this.text(child) == "\\")
2614
+ flow.sigilless = true;
2615
+ else if (declaring && variableNodes.has(name))
2616
+ this.declare(child);
2617
+ else if (declaring && name == "Parens")
2618
+ this.declareAll(child);
2619
+ else if (scopeNodes.has(name)) {
2620
+ // The placeholders in a subscript are those of the block around it.
2621
+ if (name == "Block" && isSubscripted(prev))
2622
+ this.placeholders(child);
2623
+ this.addMethods(child);
2624
+ }
2625
+ else if (isDeclaration(name)) {
2626
+ this.declaration(child);
2627
+ // A constant that is declared with a backslash has its name after
2628
+ // the declaration node: constant \limit = 3
2629
+ if (name == "ConstantDeclaration" && child.lastChild.name == "constant")
2630
+ flow.declaring = true;
2631
+ }
2632
+ else if (child.firstChild)
2633
+ this.content(child);
2634
+ }
2635
+ // The placeholder variables in a node, and in the subscripts in it.
2636
+ placeholders(node) {
2637
+ for (let child = node.firstChild; child; child = child.nextSibling) {
2638
+ if (child.name == "VariableName") {
2639
+ if (this.isPlaceholderNode(child))
2640
+ this.declare(child);
2641
+ }
2642
+ else if (child.firstChild && (!scopeNodes.has(child.name) || isSubscript(child)))
2643
+ this.placeholders(child);
2644
+ }
2645
+ }
2646
+ declaration(node) {
2647
+ let kind = node.firstChild.name;
2648
+ for (let child = node.firstChild; child; child = child.nextSibling) {
2649
+ let { name } = child;
2650
+ if (name == "RoutineName") {
2651
+ let label = this.text(child);
2652
+ // An operator is not called by its name: infix:<+>
2653
+ if (/:[<«\[]/.test(label))
2654
+ continue;
2655
+ // `multi foo` has no declarator, and declares a sub.
2656
+ if (kind == "sub" || kind == "RoutineName") {
2657
+ this.names.push({ label, type: "function", boost: 1 });
2658
+ this.variables.push(variable("&" + label));
2659
+ }
2660
+ // A private method is called as self!name, where nothing is completed.
2661
+ else if (/^[^!^]/.test(label))
2662
+ this.methods.push({ label, type: "method", boost: 1 });
2663
+ }
2664
+ else if (name == "PackageName") {
2665
+ this.names.push({ label: this.text(child), type: "class", boost: 1 });
2666
+ }
2667
+ else if (name == "EnumName" || name == "SubsetName") {
2668
+ this.names.push({ label: this.text(child), type: "type", boost: 1 });
2669
+ }
2670
+ else if (name == "ConstantName") {
2671
+ let label = this.text(child);
2672
+ this.add(/^[$@%&]/.test(label) ? variable(label) : { label, type: "constant", boost: 1 });
2673
+ }
2674
+ else if (scopeNodes.has(name)) {
2675
+ this.addMethods(child);
2676
+ }
2677
+ else if (name != "Parens" && child.firstChild) {
2678
+ // The signature belongs to the scope of the body.
2679
+ this.content(child);
2680
+ }
2681
+ }
2682
+ }
2683
+ // The parameters of a block: those of the routine that it is the body
2684
+ // of, or the ones after the arrow of a pointy block.
2685
+ parameters(block) {
2686
+ let parent = block.parent;
2687
+ if (parent && parent.name == "RoutineDeclaration") {
2688
+ for (let child = parent.firstChild; child; child = child.nextSibling)
2689
+ if (child.name == "Parens")
2690
+ this.declareAll(child);
2691
+ return;
2692
+ }
2693
+ // Going backwards, the variables of a parameter come before the
2694
+ // `=` of its default value.
2695
+ let found = [], parameter = [];
2696
+ for (let prev = block.prevSibling; prev; prev = prev.prevSibling) {
2697
+ let { name } = prev;
2698
+ if (name == ";" || name == "Block" || isDeclaration(name))
2699
+ return;
2700
+ if (name == "VariableName") {
2701
+ parameter.push(prev);
2702
+ }
2703
+ else if (prev.prevSibling && sigillessName(this.state, prev.prevSibling)) {
2704
+ // -> \item { }
2705
+ parameter.push(prev);
2706
+ }
2707
+ else if (name == ",") {
2708
+ found = found.concat(parameter);
2709
+ parameter = [];
2710
+ }
2711
+ else if (name == "Operator") {
2712
+ let text = this.text(prev);
2713
+ if (text == "=")
2714
+ parameter = [];
2715
+ else if (isArrow(text)) {
2716
+ for (let node of found.concat(parameter))
2717
+ this.declare(node);
2718
+ return;
2719
+ }
2720
+ }
2721
+ }
2722
+ }
2723
+ }
2724
+ // The names that the scope node `node` declares in its content. The
2725
+ // parameters of a block are not part of its node, and are left out.
2726
+ function scopeOf(node, state) {
2727
+ let scope = scopes.get(node);
2728
+ if (scope)
2729
+ return scope;
2730
+ let gatherer = new Gatherer(state);
2731
+ gatherer.content(node);
2732
+ scope = { variables: gatherer.variables, names: gatherer.names, methods: gatherer.methods, typed: gatherer.typed };
2733
+ scopes.set(node, scope);
2734
+ return scope;
2735
+ }
2736
+ /// The names that are in scope at `node`, innermost scope first, and
2737
+ /// the methods of the whole document.
2738
+ function localNames(node, state) {
2739
+ let variables = [], names = [], methods = [];
2740
+ // A variable that is declared with a type of the document's own goes
2741
+ // with the other variables of its scope, once all the types are known.
2742
+ // A type that a scope declares is known in it and in the scopes in it.
2743
+ let levels = [];
2744
+ for (let cur = node; cur; cur = cur.parent) {
2745
+ if (!scopeNodes.has(cur.name))
2746
+ continue;
2747
+ let scope = scopeOf(cur, state);
2748
+ // An edit to the parameters does not replace the block's node, so
2749
+ // these are read every time.
2750
+ let parameters = new Gatherer(state);
2751
+ parameters.parameters(cur);
2752
+ append(variables, parameters.variables);
2753
+ append(names, parameters.names);
2754
+ append(variables, scope.variables);
2755
+ levels.push({ at: variables.length, typed: scope.typed, names: scope.names });
2756
+ append(names, scope.names);
2757
+ methods = scope.methods;
2758
+ }
2759
+ let types = new Set();
2760
+ // From the outermost scope in. The variables of an outer scope come
2761
+ // later in the list, so inserting them first keeps the positions of
2762
+ // those of the inner scopes.
2763
+ for (let i = levels.length - 1; i >= 0; i--) {
2764
+ for (let { label, type } of levels[i].names)
2765
+ if (type == "class" || type == "type")
2766
+ types.add(label);
2767
+ let found = levels[i].typed.filter(({ type }) => types.has(type)).map(({ completion }) => completion);
2768
+ if (found.length)
2769
+ variables.splice(levels[i].at, 0, ...found);
2770
+ }
2771
+ return { variables, names, methods, types };
2772
+ }
2773
+ /// Whether a variable is in a place where variables are declared, so
2774
+ /// that its name is a new one. The variable is a child of `parent`, and
2775
+ /// comes after the sibling `prev`. `types` holds the names of the types
2776
+ /// in scope.
2777
+ function declaresVariable(state, parent, prev, types) {
2778
+ let text = (node) => state.sliceDoc(node.from, node.to);
2779
+ // A signature, or the list of `my ($a, $b)`, unless the variable is
2780
+ // in a default value or in a constraint.
2781
+ if (parent.name == "Parens") {
2782
+ let before = parent.prevSibling;
2783
+ if (parent.parent && parent.parent.name == "RoutineDeclaration" || before && declarators.has(before.name)) {
2784
+ for (let node = prev; node && node.name != ","; node = node.prevSibling)
2785
+ if (node.name == "where" || node.name == "Operator" && text(node) == "=")
2786
+ return false;
2787
+ return true;
2788
+ }
2789
+ }
2790
+ // After a declarator, or after the arrow of a pointy block.
2791
+ let first = true;
2792
+ for (let node = prev; node; node = node.prevSibling) {
2793
+ let { name } = node;
2794
+ // `my $a, $b` declares the first one only.
2795
+ if (declarators.has(name))
2796
+ return first;
2797
+ if (name == ";" || name == "Block" || name == "{" || isDeclaration(name))
2798
+ return false;
2799
+ if (name == "Operator") {
2800
+ let operator = text(node);
2801
+ if (isArrow(operator))
2802
+ return true;
2803
+ if (operator == "=")
2804
+ return false;
2805
+ }
2806
+ // Only a type can stand between a declarator and its variable. A
2807
+ // type of the document's own, `foo`, can take a smiley as TypeName does.
2808
+ let before = node.prevSibling, touching = before != null && before.to == node.from;
2809
+ let prevName = !touching ? "" : before.name == "Identifier" && isType(state, before, "", types) ? "TypeName" : before.name;
2810
+ if (!isType(state, node, prevName, types))
2811
+ first = false;
2812
+ }
2813
+ return false;
2814
+ }
2815
+
2816
+ /// Snippets for the common constructs of Raku. Each one is offered
2817
+ /// where a keyword can be typed, next to the keyword it starts with.
2818
+ const snippets = [
2819
+ autocomplete.snippetCompletion("sub ${name}(${params}) {\n\t${}\n}", { label: "sub", detail: "definition", type: "keyword" }),
2820
+ autocomplete.snippetCompletion("multi sub ${name}(${params}) {\n\t${}\n}", { label: "multi", detail: "multi sub", type: "keyword" }),
2821
+ autocomplete.snippetCompletion("method ${name}(${params}) {\n\t${}\n}", { label: "method", detail: "definition", type: "keyword" }),
2822
+ autocomplete.snippetCompletion("class ${Name} {\n\t${}\n}", { label: "class", detail: "definition", type: "keyword" }),
2823
+ autocomplete.snippetCompletion("role ${Name} {\n\t${}\n}", { label: "role", detail: "definition", type: "keyword" }),
2824
+ autocomplete.snippetCompletion("grammar ${Name} {\n\ttoken TOP { ${} }\n}", { label: "grammar", detail: "definition", type: "keyword" }),
2825
+ autocomplete.snippetCompletion("token ${name} { ${} }", { label: "token", detail: "definition", type: "keyword" }),
2826
+ autocomplete.snippetCompletion("enum ${Name} <${a b c}>;", { label: "enum", detail: "definition", type: "keyword" }),
2827
+ autocomplete.snippetCompletion("subset ${Name} of ${Int} where ${* > 0};", { label: "subset", detail: "definition", type: "keyword" }),
2828
+ autocomplete.snippetCompletion("unit module ${Name};", { label: "unit", detail: "module", type: "keyword" }),
2829
+ autocomplete.snippetCompletion("has ${$.name};", { label: "has", detail: "attribute", type: "keyword" }),
2830
+ autocomplete.snippetCompletion("if ${condition} {\n\t${}\n}", { label: "if", detail: "block", type: "keyword" }),
2831
+ autocomplete.snippetCompletion("if ${condition} {\n\t${}\n} else {\n\t\n}", { label: "if", detail: "/ else block", type: "keyword" }),
2832
+ autocomplete.snippetCompletion("unless ${condition} {\n\t${}\n}", { label: "unless", detail: "block", type: "keyword" }),
2833
+ autocomplete.snippetCompletion("with ${value} -> ${$x} {\n\t${}\n}", { label: "with", detail: "block", type: "keyword" }),
2834
+ autocomplete.snippetCompletion("for ${@list} -> ${$x} {\n\t${}\n}", { label: "for", detail: "loop", type: "keyword" }),
2835
+ autocomplete.snippetCompletion("while ${condition} {\n\t${}\n}", { label: "while", detail: "loop", type: "keyword" }),
2836
+ autocomplete.snippetCompletion("loop (my ${$i} = 0; ${$i} < ${n}; ${$i}++) {\n\t${}\n}", { label: "loop", detail: "C-style loop", type: "keyword" }),
2837
+ autocomplete.snippetCompletion("given ${value} {\n\twhen ${match} { ${} }\n\tdefault { }\n}", { label: "given", detail: "/ when block", type: "keyword" }),
2838
+ autocomplete.snippetCompletion("when ${match} { ${} }", { label: "when", detail: "block", type: "keyword" }),
2839
+ autocomplete.snippetCompletion("try {\n\t${}\n\tCATCH {\n\t\tdefault { }\n\t}\n}", { label: "try", detail: "/ CATCH block", type: "keyword" })
2840
+ ];
2841
+
2842
+ function completions(type, ...labels) {
2843
+ return labels.join(" ").split(" ").map(label => ({ label, type }));
2844
+ }
2845
+ const keywords = completions("keyword", ...Object.keys(keywordTags));
2846
+ const constants = completions("constant", "True False Nil Inf NaN Empty pi tau");
2847
+ const types = completions("type", "Mu Any Cool Bool Int UInt Num Rat FatRat Complex Str Numeric Real Rational Stringy", "int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 num num32 num64 str", "Array List Seq Slip Range Hash Map Pair Set SetHash Bag BagHash Mix MixHash", "Positional Associative Iterable Iterator Callable Code Block Routine Sub Method Signature Parameter Capture", "Regex Match Grammar Junction Whatever Order Version", "IO IO::Path IO::Handle Proc Proc::Async Buf Blob", "Promise Supply Supplier Channel Lock Thread", "Date DateTime Duration Instant", "Exception Failure X::AdHoc");
2848
+ const routines = completions("function", "say put print note printf sprintf prompt get lines words slurp spurt open close", "dir mkdir rmdir unlink chdir shell run exit die warn fail sleep await now time rand srand", "elems end keys values kv pairs antipairs map grep first sort reverse join split comb", "push pop shift unshift append prepend splice flat unique squish classify categorize", "min max minmax sum pick roll zip cross reduce produce", "abs sqrt floor ceiling round truncate exp log sin cos", "chars chr ord uc lc tc flip trim chomp chop index rindex substr", "defined EVAL");
2849
+ const methods = completions("method", "new clone defined WHAT gist raku Str Int Num Rat Bool Numeric Array List Hash Set Bag Seq", "say put print note lines words slurp spurt open close", "elems end keys values kv pairs antipairs map grep first sort reverse join split comb", "push pop shift unshift append prepend splice flat unique squish classify categorize", "min max minmax sum pick roll reduce produce head tail skip rotor batch", "abs sqrt floor ceiling round truncate", "chars ord uc lc tc flip trim chomp chop index rindex substr subst match contains", "starts-with ends-with fmt succ pred exists then tap");
2850
+ const specialVariables = completions("variable", "$*IN $*OUT $*ERR $*ARGFILES @*ARGS %*ENV $*CWD $*HOME $*TMPDIR $*PROGRAM $*PROGRAM-NAME", "$*EXECUTABLE $*PID $*USER $*KERNEL $*DISTRO $*VM $*RAKU $*REPO $*SPEC $*TZ", "$*THREAD $*SCHEDULER $*INIT-INSTANT", "$?FILE $?LINE $?PACKAGE $?MODULE $?CLASS $?ROLE $?DISTRIBUTION %?RESOURCES &?ROUTINE &?BLOCK");
2851
+ const globals = [...keywords, ...constants, ...types, ...routines];
2852
+ // The offered names are all ASCII, so there is no need to follow the
2853
+ // grammar's notion of an identifier here.
2854
+ // A name cannot start with a colon: after a request at `f(|`, typing
2855
+ // `:key` is not a name from the list.
2856
+ const nameTail = /^(\w[\w:'\-]*)?$/;
2857
+ const specialVariableTail = /^[$@%&][*?][\w\-]*$/;
2858
+ const variableTail = /^[$@%&][!.^:]?[\w'\-]*$/;
2859
+ // Whether the position of `node` holds code, as opposed to the text of
2860
+ // a string, a regex, a comment or Pod. An interpolation is code again.
2861
+ function inCode(node) {
2862
+ var _a;
2863
+ for (; node; node = node.parent) {
2864
+ // The body of a regex declaration, which has no Regex node when it is empty.
2865
+ if (node.name == "Block" && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.name) == "RegexDeclaration")
2866
+ return false;
2867
+ if (/^(Interpolation|Block|Parens|Brackets)$/.test(node.name))
2868
+ return true;
2869
+ if (/^(StringLiteral|Heredoc|Regex|Pod|LineComment|DocComment|BlockComment)$/.test(node.name))
2870
+ return false;
2871
+ }
2872
+ return true;
2873
+ }
2874
+ // Whether the word at `node` is the name of a private method, as in
2875
+ // `self!name`: it follows a `!` that is attached to a term. A `!` after
2876
+ // anything else negates, as in `f(!defined $x)`.
2877
+ function isPrivateMethodName(tree, state, node) {
2878
+ let mark = tree.resolveInner(node.from, -1);
2879
+ if (mark.name != "Operator" || mark.to != node.from || state.sliceDoc(mark.from, mark.to) != "!")
2880
+ return false;
2881
+ let invocant = tree.resolveInner(mark.from, -1);
2882
+ return invocant.to == mark.from &&
2883
+ /^(self|VariableName|AttributeName|SpecialVariable|Identifier|TypeName|Parens|Brackets|[)\]])$/.test(invocant.name);
2884
+ }
2885
+ // The names declared in the document, followed by the built-in ones
2886
+ // that they do not hide.
2887
+ function withLocal(local, builtin) {
2888
+ if (!local.length)
2889
+ return builtin;
2890
+ let labels = new Set(), result = [];
2891
+ for (let completion of local) {
2892
+ if (labels.has(completion.label))
2893
+ continue;
2894
+ labels.add(completion.label);
2895
+ result.push(completion);
2896
+ }
2897
+ for (let completion of builtin)
2898
+ if (!labels.has(completion.label))
2899
+ result.push(completion);
2900
+ return result;
2901
+ }
2902
+ /// A completion source for Raku keywords, for the commonly used
2903
+ /// built-in types, routines, methods and special variables, and for the
2904
+ /// names that the document declares.
2905
+ const rakuCompletionSource = context => {
2906
+ let { state, pos } = context, tree = language.syntaxTree(state), node = tree.resolveInner(pos, -1);
2907
+ if (!inCode(node))
2908
+ return null;
2909
+ // `$*` alone is not a variable token yet.
2910
+ let special = node.name == "SpecialVariable" ? node : context.matchBefore(/[$@%&][*?]$/);
2911
+ if (special)
2912
+ return { from: special.from, options: specialVariables, validFor: specialVariableTail };
2913
+ // A variable, or a sigil that is about to be one. A lone `%` or `&`
2914
+ // is as often an operator, and has to be followed by a name first.
2915
+ let isVariableNode = node.name == "VariableName" || node.name == "AttributeName";
2916
+ let sigil = isVariableNode ? null : context.matchBefore(/[$@]$|[$@%&][!.^:]$/);
2917
+ if (isVariableNode || sigil) {
2918
+ let from = isVariableNode ? node.from : sigil.from;
2919
+ // A lone sigil is not a node. It lies in the node around it.
2920
+ let parent = isVariableNode ? node.parent : tree.resolveInner(from, 0);
2921
+ let prev = isVariableNode ? node.prevSibling : parent.childBefore(from);
2922
+ let local = localNames(parent, state);
2923
+ if (declaresVariable(state, parent, prev, local.types))
2924
+ return null;
2925
+ // A placeholder variable is declared by being used, also by the
2926
+ // one that is being typed, which is not offered for itself.
2927
+ let typed = isVariableNode ? state.sliceDoc(from, node.to) : "";
2928
+ let options = withLocal(local.variables, []);
2929
+ if (isPlaceholder(typed))
2930
+ options = options.filter(completion => completion.label != typed);
2931
+ return options.length ? { from, options, validFor: variableTail } : null;
2932
+ }
2933
+ let local = localNames(node, state), localMethods = () => withLocal(local.methods, methods);
2934
+ if (node.name == "MethodName")
2935
+ return { from: node.from, options: localMethods(), validFor: nameTail };
2936
+ // A dot or `.=` with no name after it yet. Two dots are a range operator.
2937
+ let before = state.sliceDoc(Math.max(0, pos - 2), pos);
2938
+ if (before == ".=")
2939
+ return { from: pos, options: localMethods(), validFor: nameTail };
2940
+ if (/(^|[^.])\.$/.test(before)) {
2941
+ // The dot of `1.5` and of `v6.d` is far more often typed than a
2942
+ // method call on a number.
2943
+ let numeric = /^(Number|Version)$/.test(tree.resolveInner(pos - 1, -1).name);
2944
+ return numeric && !context.explicit ? null : { from: pos, options: localMethods(), validFor: nameTail };
2945
+ }
2946
+ // A snippet shares its label with its keyword, so it is added after
2947
+ // the list has lost its repeated labels.
2948
+ let localGlobals = () => withLocal(local.names, globals).concat(snippets);
2949
+ // A keyword's node is named after the keyword, as are those of `,` and `;`.
2950
+ let isKeyword = /^\w/.test(node.name) && node.name == state.sliceDoc(node.from, node.to);
2951
+ if (isKeyword || node.name == "Identifier" || node.name == "TypeName") {
2952
+ if (isPrivateMethodName(tree, state, node))
2953
+ return null;
2954
+ let prev = node.prevSibling;
2955
+ // The name of a variable without a sigil, where it is declared: my \x
2956
+ if (prev && prev.to == node.from && state.sliceDoc(prev.from, prev.to) == "\\" &&
2957
+ declaresVariable(state, node.parent, prev.prevSibling, local.types))
2958
+ return null;
2959
+ // `$x .= trim` calls a method.
2960
+ let afterDotAssign = prev != null && prev.name == "Operator" && state.sliceDoc(prev.from, prev.to) == ".=";
2961
+ // The colons of a type capture, ::T, and of ::?CLASS are not part of the name.
2962
+ let colons = /^::\??/.exec(state.sliceDoc(node.from, node.from + 3));
2963
+ return { from: node.from + (colons ? colons[0].length : 0), options: afterDotAssign ? localMethods() : localGlobals(),
2964
+ validFor: nameTail };
2965
+ }
2966
+ // Other names (pair keys, names being declared) are made up by the
2967
+ // user, so only a position where no token has been started gets the
2968
+ // whole list, and only on request.
2969
+ if (context.explicit && /^[\s(\[{,;=]?$/.test(state.sliceDoc(Math.max(0, pos - 1), pos)))
2970
+ return { from: pos, options: localGlobals(), validFor: nameTail };
2971
+ return null;
2972
+ };
2973
+
2974
+ // The grammar has no statement nodes, so whether a line continues the
2975
+ // statement before it is worked out here, from the token that precedes
2976
+ // the line and from what the line starts with.
2977
+ const skipped = /^(LineComment|DocComment|BlockComment|Pod|Heredoc)$/;
2978
+ const brackets = /^(Block|Parens|Brackets|Interpolation|Program)$/;
2979
+ const wordOperators = /^(and|or|xor|andthen|orelse|notandthen|div|mod|gcd|lcm|eq|ne|lt|gt|le|ge|cmp|leg|eqv|but)$/;
2980
+ // Operators that end a term or stand for a whole statement.
2981
+ const closingOperators = /^(\+\+|--|\.\.\.|!!!|\?\?\?)$/;
2982
+ // The words that start a trait. `of` is left out: it is as often a
2983
+ // name of one's own.
2984
+ const traits = "is|does|returns|handles|where|will";
2985
+ /// The lines that are indented again when they are typed: one that
2986
+ /// closes a bracket, and one that starts with a trait, which is only
2987
+ /// known to continue a statement once the trait's word is there.
2988
+ const indentOnInput = new RegExp("^\\s*(?:[\\}\\]\\)]|(?:" + traits + ")\\s)$");
2989
+ // A line that starts with an infix: an operator that has a space after
2990
+ // it and more on the line, an operator that is a word, a statement
2991
+ // modifier, or a trait (`is export`). A prefix operator touches its
2992
+ // operand, and `...` stands alone.
2993
+ const startsWithInfix = new RegExp("^\\s*(?:[~+\\-*/%<>=|&^?!]+[ \\t]+\\S|(?:" + wordOperators.source.slice(2, -2) +
2994
+ "|if|unless|for|while|until|given|when|with|without" +
2995
+ "|" + traits + ")(?![\\w'-]))");
2996
+ const startsWithMethod = /^\s*\.[^\s\d.]/;
2997
+ // The last token of `node`. A string, a regex, a heredoc and a Pod
2998
+ // block count as one token: what they end in is not code.
2999
+ const wholeTokens = /^(StringLiteral|Regex|Heredoc|Pod)$/;
3000
+ function lastToken(node) {
3001
+ while (node.lastChild && !wholeTokens.test(node.name))
3002
+ node = node.lastChild;
3003
+ return node;
3004
+ }
3005
+ // The last token that ends at or before `pos` in `bracket`, not
3006
+ // counting comments.
3007
+ function tokenBefore(bracket, pos) {
3008
+ let node = bracket.resolveInner(pos, -1);
3009
+ // Either the node that ends there, or the one around the position.
3010
+ if (node.to > pos)
3011
+ node = node.childBefore(pos);
3012
+ while (node) {
3013
+ let token = lastToken(node);
3014
+ if (!skipped.test(token.name))
3015
+ return token;
3016
+ // Go to what comes before the comment, in this node or around it.
3017
+ while (node && !node.prevSibling)
3018
+ node = node.parent;
3019
+ node = node && node.prevSibling;
3020
+ }
3021
+ return null;
3022
+ }
3023
+ function bracketAround(node) {
3024
+ for (let parent = node.parent; parent; parent = parent.parent)
3025
+ if (brackets.test(parent.name))
3026
+ return parent;
3027
+ return null;
3028
+ }
3029
+ // The bracket node whose content a token is part of. The brackets of a
3030
+ // node are part of the content around that node.
3031
+ function bracketOf(token) {
3032
+ let around = bracketAround(token);
3033
+ return around && around == token.parent && /^[()\[\]{}]$/.test(token.name) ? bracketAround(around) : around;
3034
+ }
3035
+ // The first node after `node` that is not a comment.
3036
+ function nextCode(node) {
3037
+ do
3038
+ node = node && node.nextSibling;
3039
+ while (node && skipped.test(node.name));
3040
+ return node;
3041
+ }
3042
+ // Whether a block in braces holds the pairs of a hash, in which a comma
3043
+ // separates items that line up.
3044
+ function holdsPairs(block, state) {
3045
+ let first = block.name == "Block" ? nextCode(block.firstChild) : null;
3046
+ if (!first)
3047
+ return false;
3048
+ if (first.name == "PairKey")
3049
+ return true;
3050
+ let second = nextCode(first);
3051
+ return second != null && second.name == "Operator" && state.sliceDoc(second.from, second.to) == "=>";
3052
+ }
3053
+ // Whether a line continues a statement of `bracket`. The line starts at
3054
+ // `pos` with the text `after`.
3055
+ function continuesStatement(state, bracket, pos, after) {
3056
+ // The lines of a regex are not statements: its `+` and `|` are not
3057
+ // the operators of an expression.
3058
+ for (let node = bracket.resolveInner(pos, -1); node && node.from >= bracket.from; node = node.parent) {
3059
+ if (node.name == "Regex")
3060
+ return false;
3061
+ if (brackets.test(node.name))
3062
+ break;
3063
+ }
3064
+ let before = tokenBefore(bracket, pos);
3065
+ if (!before || bracketOf(before) != bracket)
3066
+ return false;
3067
+ let name = before.name, text = state.sliceDoc(before.from, before.to);
3068
+ if (name == "Operator")
3069
+ return !closingOperators.test(text);
3070
+ if (wordOperators.test(name) && name == text)
3071
+ return true;
3072
+ if (name == ",")
3073
+ return !holdsPairs(bracket, state);
3074
+ if (name == ";" || name == "{")
3075
+ return false;
3076
+ if (name == "}") {
3077
+ // A block ends its statement. A subscript, which touches the term
3078
+ // that it follows, does not: %h{$key}
3079
+ let block = before.parent;
3080
+ return block.from > 0 && !/\s/.test(state.sliceDoc(block.from - 1, block.from)) && startsWithInfix.test(after);
3081
+ }
3082
+ // After the end of a statement, a `.` calls a method on the topic.
3083
+ return startsWithInfix.test(after) || startsWithMethod.test(after);
3084
+ }
3085
+ // Whether the content of a bracket node starts on the line of its
3086
+ // opening bracket, which `delimitedIndent` then aligns the rest with.
3087
+ function isAligned(node, state) {
3088
+ let open = node.firstChild, next = nextCode(open);
3089
+ return open != null && next != null && next != node.lastChild && next.from < state.doc.lineAt(open.from).to;
3090
+ }
3091
+ const bodyKeywords = /^(if|elsif|else|unless|with|orwith|without|for|while|until|loop|repeat|given|when|default|whenever|react|supply|gather|do|try|start)$/;
3092
+ const declarationPrefixes = /^(my|our|has|state|anon|augment|supersede|unit|multi|proto|only)$/;
3093
+ // The first node of the statement that a block is the body of, when it
3094
+ // is the body of a control statement or of a declaration. A block that
3095
+ // is a term in an expression has none: `my $f = sub { ... }`
3096
+ function statementOfBody(block, state) {
3097
+ let declaration = block.parent && /Declaration$/.test(block.parent.name) ? block.parent : null;
3098
+ let first = declaration || block;
3099
+ for (let prev = first.prevSibling; prev; prev = prev.prevSibling) {
3100
+ if (skipped.test(prev.name))
3101
+ continue;
3102
+ if (prev.name == ";" || prev.name == "{")
3103
+ break;
3104
+ // A closing brace that is followed by a line break ends a statement.
3105
+ if (lastToken(prev).name == "}" && /\n/.test(state.sliceDoc(prev.to, first.from)))
3106
+ break;
3107
+ if (declaration && !declarationPrefixes.test(prev.name))
3108
+ return null;
3109
+ first = prev;
3110
+ }
3111
+ return declaration || bodyKeywords.test(first.name) ? first : null;
3112
+ }
3113
+ /// The indentation of the lines in a node that holds statements between
3114
+ /// braces: that of `delimitedIndent`, and one unit more for a line that
3115
+ /// continues a statement.
3116
+ function statementIndent(closing) {
3117
+ let delimited = language.delimitedIndent({ closing });
3118
+ return (context) => {
3119
+ let { node, state, unit } = context, after = context.textAfter;
3120
+ let closed = after.slice(/^\s*/.exec(after)[0].length).startsWith(closing);
3121
+ // The body of a statement is indented from the line where the
3122
+ // statement starts, which need not be the line of its brace.
3123
+ // if $a
3124
+ // && $b {
3125
+ // say 1;
3126
+ // }
3127
+ let statement = isAligned(node, state) ? null : statementOfBody(node, state);
3128
+ let indent = statement ? context.lineIndent(statement.from) + (closed ? 0 : unit) : delimited(context);
3129
+ return !closed && continuesStatement(state, node, context.pos, after) ? indent + unit : indent;
3130
+ };
3131
+ }
3132
+ /// The indentation of the lines at the top level.
3133
+ function topIndent(context) {
3134
+ return continuesStatement(context.state, context.node, context.pos, context.textAfter) ? context.unit : 0;
3135
+ }
3136
+
3137
+ function closing(open) { return String.fromCharCode(brackets$1[open.charCodeAt(0)]); }
3138
+ // The brackets to try, in this order. A bracket that is repeated has
3139
+ // to be closed as many times.
3140
+ const pairs = ["(", "[", "{", "<", "«", "「", "((", "[[", "{{", "(((", "[[[", "{{{"].map(open => {
3141
+ return { open, close: closing(open).repeat(open.length) };
3142
+ });
3143
+ // Whether `text` can stand between the delimiters: none of them is
3144
+ // left open in it, and none closes more than were opened.
3145
+ function fits(text, { open, close }) {
3146
+ let depth = 0;
3147
+ for (let pos = 0; pos < text.length;) {
3148
+ if (text.startsWith(close, pos)) {
3149
+ if (--depth < 0)
3150
+ return false;
3151
+ pos += close.length;
3152
+ }
3153
+ else if (text.startsWith(open, pos)) {
3154
+ depth++;
3155
+ pos += open.length;
3156
+ }
3157
+ else {
3158
+ pos++;
3159
+ }
3160
+ }
3161
+ return depth == 0;
3162
+ }
3163
+ // The delimiters of the comment that a block comment command would
3164
+ // remove for the range, if there is one: the range is that comment, or
3165
+ // all of its text, give or take whitespace.
3166
+ function commentAt(state, from, to) {
3167
+ let start = from + /^\s*/.exec(state.sliceDoc(from, to))[0].length;
3168
+ let node = language.syntaxTree(state).resolveInner(start, 1);
3169
+ if (node.name != "BlockComment")
3170
+ return null;
3171
+ let text = state.sliceDoc(node.from, node.to), open = /^#`(.)\1*/.exec(text);
3172
+ if (!open || brackets$1[open[1].charCodeAt(0)] == null)
3173
+ return null;
3174
+ let close = closing(open[1]).repeat(open[0].length - 2);
3175
+ if (!text.endsWith(close))
3176
+ return null;
3177
+ let blank = (a, b) => a >= b || !/\S/.test(state.sliceDoc(a, b));
3178
+ let isComment = start == node.from && blank(node.to, to);
3179
+ let isContent = blank(node.from + open[0].length, from) && blank(to, node.to - close.length) && to <= node.to;
3180
+ return isComment || isContent ? { open: open[0], close } : null;
3181
+ }
3182
+ function blockTokens(state, pos) {
3183
+ // The command asks at the start of what it works on, which is a
3184
+ // selection range, or the first text of a selected line.
3185
+ let range = state.selection.ranges.find(range => range.from == pos);
3186
+ let existing = range && commentAt(state, range.from, range.to);
3187
+ if (existing)
3188
+ return existing;
3189
+ // The command that goes by lines wraps up to the end of the line, so
3190
+ // the brackets have to fit that text as well.
3191
+ let texts = [], line = state.doc.lineAt(pos);
3192
+ if (range) {
3193
+ texts.push(state.sliceDoc(range.from, range.to));
3194
+ line = state.doc.lineAt(range.to);
3195
+ }
3196
+ else {
3197
+ let onLine = state.selection.ranges.find(range => range.from <= pos && range.from >= line.from);
3198
+ if (onLine)
3199
+ line = state.doc.lineAt(onLine.to);
3200
+ }
3201
+ if (!range || range.to < line.to)
3202
+ texts.push(state.sliceDoc(pos, line.to));
3203
+ // The spaces keep a bracket at the edge of the text from joining the delimiters.
3204
+ let pair = pairs.find(pair => texts.every(text => fits(" " + text + " ", pair))) || pairs[0];
3205
+ return { open: "#`" + pair.open, close: pair.close };
3206
+ }
3207
+ /// Language data that gives `language` block comment tokens which fit
3208
+ /// the selection. It takes precedence over the fixed tokens in the
3209
+ /// language's own data.
3210
+ function embeddedCommentTokens(language) {
3211
+ return state.Prec.high(state.EditorState.languageData.of((state, pos, side) => {
3212
+ if (!language.isActiveAt(state, pos, side))
3213
+ return [];
3214
+ // Only worked out when asked for: this is called for every kind of
3215
+ // language data, and the line comment commands do not read `block`.
3216
+ return [{ get commentTokens() {
3217
+ return { line: "#", get block() { return blockTokens(state, pos); } };
3218
+ } }];
3219
+ }));
3220
+ }
3221
+
3222
+ // A regex literal is one token to the parser of a program: whether it
3223
+ // is closed has to be known where it starts, and a token that is read
3224
+ // piece by piece cannot look that far ahead (see AGENTS.md). Its inside
3225
+ // is parsed by the same grammar, from the top rule for a regex literal,
3226
+ // and that tree takes the place of the token's node. The inner parser
3227
+ // is made from `base` so that it has the same props, among them the
3228
+ // language data that LRLanguage.define puts on top nodes.
3229
+ function nestedParsers(base) {
3230
+ // From the term of a token to the parser of its inside. The
3231
+ // generator registers a top rule under its node name.
3232
+ let parsers = new Map();
3233
+ let wrap = common.parseMixed(node => parsers.get(node.type.id) || null);
3234
+ // The inner parsers are wrapped as well: a regex can hold a block of
3235
+ // code, and that can hold a regex.
3236
+ parsers.set(regexLiteral, { parser: base.configure({ top: "Regex", wrap }) });
3237
+ let heredoc = { parser: base.configure({ top: "Heredoc", wrap }) };
3238
+ parsers.set(interpolatingHeredoc, heredoc);
3239
+ parsers.set(interpolatingHeredocElement, heredoc);
3240
+ parsers.set(interpolatingWordList, { parser: base.configure({ top: "StringLiteral", wrap }) });
3241
+ return wrap;
3242
+ }
3243
+ /// The Lezer parser for Raku, without the editor-specific node props.
3244
+ const parser = parser$1.configure({ wrap: nestedParsers(parser$1) });
3245
+ const baseLanguage = language.LRLanguage.define({
3246
+ name: "raku",
3247
+ parser: parser$1.configure({
3248
+ props: [
3249
+ language.indentNodeProp.add({
3250
+ Program: topIndent,
3251
+ "Block Interpolation": statementIndent("}"),
3252
+ Parens: language.delimitedIndent({ closing: ")" }),
3253
+ Brackets: language.delimitedIndent({ closing: "]" }),
3254
+ // The lines of these are text, which keeps its indentation.
3255
+ "StringLiteral Heredoc Pod BlockComment DocComment": () => null
3256
+ }),
3257
+ language.foldNodeProp.add({
3258
+ "Block Parens Brackets": language.foldInside,
3259
+ BlockComment(tree) { return { from: tree.from + 2, to: tree.to }; },
3260
+ // Keep the first line, which holds the directive, visible.
3261
+ Pod(tree, state) { return { from: state.doc.lineAt(tree.from).to, to: tree.to }; },
3262
+ // A heredoc starts with the line break before its first line.
3263
+ Heredoc(tree) { return { from: tree.from, to: tree.to }; }
3264
+ }),
3265
+ highlight.styleTags(Object.assign(Object.assign({}, keywordTags), { "True False": highlight.tags.bool, Nil: highlight.tags.null, Identifier: highlight.tags.function(highlight.tags.variableName), TypeName: highlight.tags.typeName, PackageName: highlight.tags.definition(highlight.tags.className), "EnumName SubsetName": highlight.tags.definition(highlight.tags.typeName), ConstantName: highlight.tags.definition(highlight.tags.constant(highlight.tags.variableName)), "RoutineName RegexName": highlight.tags.function(highlight.tags.definition(highlight.tags.variableName)), MethodName: highlight.tags.function(highlight.tags.propertyName), VariableName: highlight.tags.variableName, AttributeName: highlight.tags.propertyName, SpecialVariable: highlight.tags.special(highlight.tags.variableName), PairKey: highlight.tags.attributeName, Number: highlight.tags.number, Version: highlight.tags.literal,
3266
+ // A pair of delimiters in a quote is text of it, and a tag
3267
+ // does not reach the text in a child node.
3268
+ "StringLiteral Heredoc NestedDelimiters": highlight.tags.string, Regex: highlight.tags.regexp, CharacterClass: highlight.tags.character, Assertion: highlight.tags.function(highlight.tags.variableName), "Pod PodFormat": highlight.tags.docComment, PodDirective: highlight.tags.meta,
3269
+ // These are still part of a comment, and are styled as one where
3270
+ // a theme has no style for the second tag.
3271
+ PodHeading: [highlight.tags.docComment, highlight.tags.heading], PodStrong: [highlight.tags.docComment, highlight.tags.strong], PodEmphasis: [highlight.tags.docComment, highlight.tags.emphasis], PodCode: [highlight.tags.docComment, highlight.tags.monospace], PodLink: [highlight.tags.docComment, highlight.tags.link], Escape: highlight.tags.escape, "Interpolation/{ Interpolation/}": highlight.tags.special(highlight.tags.brace), LineComment: highlight.tags.lineComment, BlockComment: highlight.tags.blockComment, DocComment: highlight.tags.docComment, Operator: highlight.tags.operator, ".": highlight.tags.derefOperator, ", ;": highlight.tags.separator, ": ::": highlight.tags.punctuation, "( )": highlight.tags.paren, "[ ]": highlight.tags.squareBracket, "{ }": highlight.tags.brace }))
3272
+ ]
3273
+ }),
3274
+ languageData: {
3275
+ // An embedded comment can use any bracket. Parentheses are the usual choice.
3276
+ commentTokens: { line: "#", block: { open: "#`(", close: ")" } },
3277
+ closeBrackets: { brackets: ["(", "[", "{", "'", '"', "「"] },
3278
+ indentOnInput
3279
+ }
3280
+ });
3281
+ /// A language provider based on the Lezer Raku parser, extended with
3282
+ /// highlighting and indentation information.
3283
+ const rakuLanguage = baseLanguage.configure({ wrap: nestedParsers(baseLanguage.parser) });
3284
+ /// Completion of Raku keywords, of the commonly used built-in types,
3285
+ /// routines, methods and special variables, and of the names that the
3286
+ /// document declares.
3287
+ const rakuCompletion = rakuLanguage.data.of({ autocomplete: rakuCompletionSource });
3288
+ /// Raku language support, with completion, and with block comment
3289
+ /// tokens that fit the selection.
3290
+ function raku() {
3291
+ return new language.LanguageSupport(rakuLanguage, [rakuCompletion, embeddedCommentTokens(rakuLanguage)]);
3292
+ }
3293
+
3294
+ exports.parser = parser;
3295
+ exports.raku = raku;
3296
+ exports.rakuCompletion = rakuCompletion;
3297
+ exports.rakuLanguage = rakuLanguage;