codemirror-lang-raku 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4,58 +4,96 @@ var lr = require('@lezer/lr');
4
4
  var common = require('@lezer/common');
5
5
  var language = require('@codemirror/language');
6
6
  var highlight = require('@lezer/highlight');
7
+ var state = require('@codemirror/state');
7
8
 
8
9
  // This file was generated by lezer-generator. You probably shouldn't edit it.
9
- const BlockComment = 1,
10
- Pod = 2,
11
- Heredoc = 3,
12
- methodDot = 4,
13
- MethodName = 5,
14
- declaredName = 172,
15
- declaredMethodName = 173,
16
- smiley = 174,
17
- Version = 6,
18
- regexBody = 7,
19
- quoteContent = 175,
20
- quoteNestOpen = 176,
21
- quoteNestClose = 177,
22
- quoteEnd = 178,
23
- rawString = 179,
24
- quoteStart = 180,
25
- Regex = 8,
26
- fatArrowKey = 181,
27
- wordOperator = 9,
28
- LineComment = 10,
29
- DocComment = 11,
30
- radixNumber = 13,
31
- PackageName = 26,
32
- RoutineName = 33,
33
- methodRoutineName = 36,
34
- RegexName = 41,
35
- EnumName = 45,
36
- SubsetName = 48,
37
- ConstantName = 51,
38
- VariableName = 53,
39
- AttributeName = 54,
40
- SpecialVariable = 55,
41
- Identifier = 56,
42
- TypeName = 57,
43
- Number = 58,
44
- StringLiteral = 59,
45
- Interpolation = 61,
46
- PairKey = 62,
47
- self = 142,
48
- True = 143,
49
- False = 144,
50
- Nil = 145,
51
- Operator = 164;
10
+ const smiley = 199,
11
+ noSmiley = 200,
12
+ BlockComment = 1,
13
+ podStart = 2,
14
+ podEnd = 201,
15
+ podEndDirective = 3,
16
+ podText = 202,
17
+ PodDirective = 4,
18
+ PodHeading = 5,
19
+ PodStrong = 6,
20
+ PodEmphasis = 7,
21
+ PodCode = 8,
22
+ PodLink = 9,
23
+ PodFormat = 10,
24
+ rawHeredoc = 11,
25
+ interpolatingHeredoc = 12,
26
+ heredocStart = 203,
27
+ methodDot = 13,
28
+ MethodName = 14,
29
+ declaredName = 204,
30
+ declaredMethodName = 205,
31
+ Version = 15,
32
+ regexStart = 206,
33
+ regexBodyEnd = 207,
34
+ regexLitOpen = 208,
35
+ regexLitClose = 209,
36
+ regexText = 210,
37
+ CharacterClass = 16,
38
+ Assertion = 17,
39
+ regexQuote = 18,
40
+ regexOperator = 19,
41
+ regexComment = 20,
42
+ regexBlockComment = 21,
43
+ regexCapture = 22,
44
+ quoteContent = 211,
45
+ quoteNestOpen = 212,
46
+ quoteNestClose = 213,
47
+ quoteEnd = 214,
48
+ rawString = 215,
49
+ quoteStart = 216,
50
+ interpolatingWordList = 23,
51
+ regexLiteral = 24,
52
+ transliteration = 25,
53
+ plainName = 217,
54
+ wordOperator = 26,
55
+ multiName = 218,
56
+ operatorVariable = 27,
57
+ LineComment = 28,
58
+ DocComment = 29,
59
+ Pod = 31,
60
+ radixNumber = 32,
61
+ PackageName = 45,
62
+ RoutineName = 52,
63
+ methodRoutineName = 55,
64
+ multiRoutineName = 56,
65
+ RegexName = 61,
66
+ regexBody = 63,
67
+ VariableName = 65,
68
+ AttributeName = 66,
69
+ SpecialVariable = 67,
70
+ EnumName = 71,
71
+ SubsetName = 74,
72
+ ConstantName = 77,
73
+ Identifier = 79,
74
+ TypeName = 80,
75
+ Number = 81,
76
+ quotedString = 82,
77
+ Interpolation = 83,
78
+ PairKey = 84,
79
+ multi = 95,
80
+ proto = 96,
81
+ only = 97,
82
+ self = 164,
83
+ True = 165,
84
+ False = 166,
85
+ Nil = 167,
86
+ Operator = 186,
87
+ Regex = 190,
88
+ Heredoc = 191,
89
+ StringLiteral = 192;
52
90
 
53
91
  // Opening bracket -> closing bracket, for the delimiters of quotes and
54
92
  // embedded comments. Raku accepts any Unicode bracket pair; this lists
55
93
  // the ones that are likely to be typed.
56
- const brackets = {};
94
+ const brackets$1 = {};
57
95
  for (let pair of ["()", "[]", "{}", "<>", "«»", "「」", "『』", "()", "[]", "{}", "【】", "〈〉", "《》", "〔〕"])
58
- brackets[pair.charCodeAt(0)] = pair.charCodeAt(1);
96
+ brackets$1[pair.charCodeAt(0)] = pair.charCodeAt(1);
59
97
  function isAsciiLetter(ch) { return ch >= 97 /* Ch.a */ && ch <= 122 /* Ch.z */ || ch >= 65 /* Ch.A */ && ch <= 90 /* Ch.Z */; }
60
98
  function isDigit(ch) { return ch >= 48 /* Ch._0 */ && ch <= 57 /* Ch._9 */; }
61
99
  // The characters of the grammar's whitespace token.
@@ -120,39 +158,130 @@ function word(input, from, to) {
120
158
  class Quote {
121
159
  constructor(parent, open, close, count,
122
160
  // How many nested opening delimiters are unclosed.
123
- depth) {
161
+ depth, interpolates,
162
+ // Whether a backslash that does not start an escape still
163
+ // takes the delimiter after it out of play: q:c[a \] b]
164
+ escapes) {
124
165
  this.parent = parent;
125
166
  this.open = open;
126
167
  this.close = close;
127
168
  this.count = count;
128
169
  this.depth = depth;
129
- this.hash = ((parent ? parent.hash * 31 : 7) + open * 5 + count * 3 + depth) | 0;
170
+ this.interpolates = interpolates;
171
+ this.escapes = escapes;
172
+ let hash = parent ? parent.hash : 7;
173
+ for (let part of [open, count, depth, interpolates, escapes ? 1 : 0])
174
+ hash = (hash * 31 + part) | 0;
175
+ this.hash = hash;
176
+ }
177
+ withDepth(depth) {
178
+ return new Quote(this.parent, this.open, this.close, this.count, depth, this.interpolates, this.escapes);
179
+ }
180
+ }
181
+ const noHeredocs = [];
182
+ // The quote that the text of a heredoc is read as. It has no
183
+ // delimiters, and ends where the text does.
184
+ const heredocQuote = new Quote(null, -1, -1, 1, 0, 63 /* Interpolate.All */, true);
185
+ // The body of a regex declaration, or the inside of a regex literal,
186
+ // that is being read piece by piece.
187
+ class RegexBody {
188
+ constructor(// The body around the block of code that this one is in.
189
+ parent,
190
+ // How many braces are open in a block of code in the
191
+ // regex. Zero in the regex itself.
192
+ braces,
193
+ // For a regex literal, the position in the document of
194
+ // the delimiter that closes it. It is not part of the
195
+ // hash, which is to be the same before and after an edit
196
+ // that moves the literal.
197
+ literalEnd = -1) {
198
+ this.parent = parent;
199
+ this.braces = braces;
200
+ this.literalEnd = literalEnd;
201
+ this.hash = ((parent ? parent.hash * 31 : 0) + 7919 * (braces + 1) + (literalEnd < 0 ? 0 : 104729)) | 0;
202
+ }
203
+ withBraces(braces) { return new RegexBody(this.parent, braces, this.literalEnd); }
204
+ }
205
+ // A Pod block that is being read piece by piece.
206
+ class PodBlock {
207
+ constructor(kind,
208
+ // What follows `=begin`, which `=end` has to repeat.
209
+ name,
210
+ // Whether it holds code, in which formatting codes are not read.
211
+ code) {
212
+ this.kind = kind;
213
+ this.name = name;
214
+ this.code = code;
215
+ let hash = 101 + kind * 7 + (code ? 3 : 0);
216
+ for (let i = 0; i < name.length; i++)
217
+ hash = (hash * 31 + name.charCodeAt(i)) | 0;
218
+ this.hash = hash;
130
219
  }
131
220
  }
132
221
  class Context {
133
- constructor(mode, quote) {
222
+ constructor(mode, quote,
223
+ // The heredocs that were opened on the current line, whose
224
+ // text starts on the next one.
225
+ heredocs, pod,
226
+ // The body of a regex declaration that this is in.
227
+ regex, hash = -1) {
134
228
  this.mode = mode;
135
229
  this.quote = quote;
230
+ this.heredocs = heredocs;
231
+ this.pod = pod;
232
+ this.regex = regex;
233
+ if (hash < 0) {
234
+ hash = (quote ? quote.hash : 0) ^ (pod ? pod.hash : 0) ^ (regex ? regex.hash : 0);
235
+ for (let { terminator, interpolates } of heredocs) {
236
+ hash = (hash * 31 + (interpolates ? 19 : 17)) | 0;
237
+ for (let i = 0; i < terminator.length; i++)
238
+ hash = (hash * 31 + terminator.charCodeAt(i)) | 0;
239
+ }
240
+ // Negative values stand for "not worked out yet".
241
+ hash &= 0x7fffffff;
242
+ }
243
+ this.hash = hash;
244
+ }
245
+ withMode(mode) {
246
+ return mode == this.mode ? this : new Context(mode, this.quote, this.heredocs, this.pod, this.regex, this.hash);
247
+ }
248
+ withHeredocs(heredocs) {
249
+ return heredocs == this.heredocs ? this : new Context(this.mode, this.quote, heredocs, this.pod, this.regex);
250
+ }
251
+ withQuote(mode, quote, heredocs = this.heredocs) {
252
+ return new Context(mode, quote, heredocs, this.pod, this.regex);
253
+ }
254
+ withPod(pod) { return new Context(this.mode, this.quote, this.heredocs, pod, this.regex); }
255
+ withRegex(regex) {
256
+ return new Context(this.mode, this.quote, this.heredocs, this.pod, regex);
136
257
  }
137
- // An old node is only reused where this is the same as where it was
138
- // made. The mode is left out: it changes with every token, which
139
- // would rule out nearly all reuse, and `reuse` works it out again.
140
- get hash() { return this.quote ? this.quote.hash : 0; }
141
- withMode(mode) { return mode == this.mode ? this : new Context(mode, this.quote); }
142
258
  }
259
+ // The nodes of a string: a quote, the token of a word list that
260
+ // interpolates, and the tree of its inside, which takes the place of
261
+ // that token.
262
+ const stringTerms = new Set([quotedString, interpolatingWordList, StringLiteral]);
143
263
  // The mode after a token or a node, for those where the term settles
144
264
  // it. Shifting a token and reusing a node both look here, so that they
145
265
  // agree.
146
266
  const termModes = new Map();
147
- for (let term of [VariableName, AttributeName, SpecialVariable, Number, radixNumber, Version, MethodName,
148
- PairKey, rawString, quoteEnd, StringLiteral, Regex, regexBody, self, True, False, Nil])
267
+ for (let term of [VariableName, AttributeName, SpecialVariable, operatorVariable, Number, radixNumber, Version, MethodName,
268
+ PairKey, rawString, quoteEnd, ...stringTerms, regexLiteral, transliteration, regexBody,
269
+ // The tree of the inside of a regex literal, which takes the
270
+ // place of the literal's token in a node that is reused.
271
+ Regex, self, True, False, Nil,
272
+ // The pieces of a regex. What follows them is more of
273
+ // the regex, or the brace that closes it.
274
+ regexText, CharacterClass, Assertion, regexQuote, regexOperator, regexComment,
275
+ regexBlockComment, regexCapture])
149
276
  termModes.set(term, 1 /* Mode.AfterTerm */);
150
- for (let term of [Identifier, TypeName, smiley, declaredName, declaredMethodName, PackageName, RoutineName,
151
- methodRoutineName, RegexName, EnumName, SubsetName, ConstantName])
277
+ for (let term of [Identifier, TypeName, smiley, noSmiley, declaredName, declaredMethodName, PackageName, RoutineName,
278
+ methodRoutineName, multiName, multiRoutineName, RegexName, EnumName, SubsetName, ConstantName])
152
279
  termModes.set(term, 2 /* Mode.AfterName */);
153
280
  // The `}` of "{...}" in a string does not take a subscript.
154
281
  for (let term of [quoteContent, Interpolation])
155
282
  termModes.set(term, 0 /* Mode.Term */);
283
+ for (let term of [multi, proto, only])
284
+ termModes.set(term, 4 /* Mode.AfterMulti */);
156
285
  // The mode after an operator, from its first three characters. `after`
157
286
  // is the mode before it.
158
287
  function modeAfterOperator(first, second, third, after) {
@@ -167,7 +296,8 @@ function modeAfterOperator(first, second, third, after) {
167
296
  }
168
297
  // The mode after a token that the terms file has no name for, from its
169
298
  // first character. Keywords and identifiers come through here alike;
170
- // an identifier gets its mode when the Identifier node is reduced.
299
+ // an identifier gets its mode when the Identifier node is reduced,
300
+ // from modeAfter, which also looks at how it is spelled.
171
301
  function modeAfterChar(first) {
172
302
  if (first == 41 /* Ch.ParenClose */ || first == 93 /* Ch.BracketClose */ || first == 36 /* Ch.Dollar */ || first == 64 /* Ch.At */)
173
303
  return 1 /* Mode.AfterTerm */;
@@ -176,9 +306,20 @@ function modeAfterChar(first) {
176
306
  return 2 /* Mode.AfterName */;
177
307
  return first == 125 /* Ch.BraceClose */ ? 3 /* Mode.AfterBlock */ : 0 /* Mode.Term */;
178
308
  }
309
+ // The built-in names that stand for a value and take no arguments. The
310
+ // constant `e` is left out: a routine or a variable of one's own is too
311
+ // often named that.
312
+ const termWords = /^(pi|π|tau|τ|now|time|rand)$/;
179
313
  // The mode after the token of the given term at the input's position.
180
314
  // `before` is the mode before it.
181
315
  function modeAfter(term, input, offset, before) {
316
+ // A term that takes no arguments is followed by an operator: pi /2
317
+ if (term == Identifier) {
318
+ let end = nameEnd(input, offset);
319
+ // Most names are longer than these, and are not looked at further.
320
+ if (end - offset <= 4 && termWords.test(word(input, offset, end)))
321
+ return 1 /* Mode.AfterTerm */;
322
+ }
182
323
  let mode = termModes.get(term);
183
324
  if (mode != null)
184
325
  return mode;
@@ -187,17 +328,159 @@ function modeAfter(term, input, offset, before) {
187
328
  return modeAfterOperator(first, input.peek(offset + 1), input.peek(offset + 2), before);
188
329
  return modeAfterChar(first);
189
330
  }
190
- const skippedTerms = new Set([LineComment, DocComment, BlockComment, Pod, Heredoc]);
331
+ // The context at the start of a parse. The tokens that start the parse
332
+ // of the inside of another token are only looked for while the context
333
+ // is still this one, which spares asking the parser whether they can
334
+ // be shifted at every other token.
335
+ const startContext = new Context(0 /* Mode.Term */, null, noHeredocs, null, null);
336
+ // The tokens of the text of a heredoc, and the tree of its inside,
337
+ // which takes the place of the token of one that interpolates.
338
+ const heredocTerms = new Set([rawHeredoc, interpolatingHeredoc, Heredoc]);
339
+ const skippedTerms = new Set([LineComment, DocComment, BlockComment, ...heredocTerms, Pod, podStart, podEnd, podEndDirective,
340
+ podText, PodDirective, PodHeading, PodStrong, PodEmphasis, PodCode, PodLink, PodFormat]);
341
+ // The heredoc that the quote at offset `at` opens, when it opens one.
342
+ // Its terminator is what the quote holds: END for q:to/END/
343
+ function heredocAt(input, at) {
344
+ let first = input.peek(at);
345
+ if (first != 113 /* Ch.q */ && first != 81 /* Ch.Q */)
346
+ return null;
347
+ let opening = readOpening(input, at);
348
+ if (!opening || !opening.heredoc)
349
+ return null;
350
+ let end = opening.start;
351
+ while (input.peek(end) != opening.close && input.peek(end) != 10 /* Ch.Newline */ && input.peek(end) >= 0)
352
+ end++;
353
+ // An empty one, as in the `q:to//` of a quote that is being typed,
354
+ // would end the heredoc at the next blank line.
355
+ let terminator = word(input, opening.start, end).trim();
356
+ return terminator ? { terminator, interpolates: opening.interpolates == 63 /* Interpolate.All */ } : null;
357
+ }
358
+ // `heredocs`, with the heredoc that the quote at offset `at` opens, if
359
+ // it opens one.
360
+ function withHeredocAt(heredocs, input, at) {
361
+ let heredoc = heredocAt(input, at);
362
+ return heredoc ? heredocs.concat(heredoc) : heredocs;
363
+ }
364
+ function hasNewline(input, from, to) {
365
+ for (let i = from; i < to; i++)
366
+ if (input.peek(i) == 10 /* Ch.Newline */)
367
+ return true;
368
+ return false;
369
+ }
370
+ // The heredocs that are open after a reused node, of which the input is
371
+ // at the start. As when tokens are shifted, a line break between tokens
372
+ // and the text of a heredoc close the ones before them.
373
+ function heredocsAfter(node, input, before) {
374
+ // Most reused nodes are single tokens.
375
+ if (!node.children.length && !stringTerms.has(node.type.id) && !heredocTerms.has(node.type.id))
376
+ return before;
377
+ let cursor = node.cursor(), found = [], closedAt = -1;
378
+ // Goes over the node at the cursor from its end, and tells whether
379
+ // the heredocs before some point in it are closed.
380
+ function scan() {
381
+ let type = cursor.type.id, { from, to } = cursor;
382
+ if (heredocTerms.has(type)) {
383
+ closedAt = to;
384
+ return true;
385
+ }
386
+ let isString = stringTerms.has(type);
387
+ if (isString) {
388
+ let heredoc = heredocAt(input, from);
389
+ if (heredoc)
390
+ found.push({ pos: from, heredoc });
391
+ }
392
+ // The tree of the inside of a regex literal or of a word list. It
393
+ // was one token when it was shifted, which opens no heredoc.
394
+ if (type == Regex || type == StringLiteral)
395
+ return false;
396
+ if (!cursor.lastChild())
397
+ return false;
398
+ // Between the pieces of a string lies its text, not whitespace.
399
+ let gaps = !isString;
400
+ for (let gapEnd = to;;) {
401
+ if (gaps && hasNewline(input, cursor.to, gapEnd)) {
402
+ closedAt = gapEnd;
403
+ break;
404
+ }
405
+ if (scan())
406
+ break;
407
+ gapEnd = cursor.from;
408
+ if (!cursor.prevSibling()) {
409
+ if (gaps && hasNewline(input, from, gapEnd))
410
+ closedAt = gapEnd;
411
+ break;
412
+ }
413
+ }
414
+ cursor.parent();
415
+ return closedAt >= 0;
416
+ }
417
+ scan();
418
+ if (!found.length && closedAt < 0)
419
+ return before;
420
+ let after = found.filter(opener => opener.pos >= closedAt).sort((a, b) => a.pos - b.pos).map(opener => opener.heredoc);
421
+ return closedAt < 0 ? before.concat(after) : after.length ? after : noHeredocs;
422
+ }
423
+ // The last token in `node` that says what the mode after it is: one
424
+ // that is not a comment or Pod, which leave the mode as it was. A node
425
+ // that settles the mode by itself counts as a token. Null when the
426
+ // node holds nothing but comments.
427
+ function lastToken$1(node) {
428
+ if (termModes.has(node.type.id) || !node.lastChild)
429
+ return skippedTerms.has(node.type.id) ? null : node;
430
+ for (let child = node.lastChild; child; child = child.prevSibling) {
431
+ let found = skippedTerms.has(child.type.id) ? null : lastToken$1(child);
432
+ if (found)
433
+ return found;
434
+ }
435
+ return null;
436
+ }
191
437
  const trackContext = new lr.ContextTracker({
192
- start: new Context(0 /* Mode.Term */, null),
438
+ start: startContext,
193
439
  shift(context, term, _stack, input) {
440
+ if (term == rawHeredoc || term == interpolatingHeredoc)
441
+ return context.withHeredocs(noHeredocs);
442
+ // The text of a heredoc that interpolates is read by a parser of
443
+ // its own, as a quote without delimiters.
444
+ if (term == heredocStart)
445
+ return context.withQuote(0 /* Mode.Term */, heredocQuote);
446
+ if (term == podStart)
447
+ return context.withPod(readPodStart(input));
448
+ if (term == podEnd || term == podEndDirective)
449
+ return context.withPod(null);
194
450
  if (skippedTerms.has(term))
195
451
  return context;
452
+ let { regex } = context;
453
+ if (term == regexStart)
454
+ return context.withRegex(new RegexBody(regex, 0));
455
+ if (term == regexBodyEnd)
456
+ return context.withRegex(regex && regex.parent).withMode(termModes.get(regexBody));
457
+ // The inside of a regex literal is read by a parser of its own, of
458
+ // which these are the first and the last token. The closing
459
+ // delimiter is found the way termToken found it when it made the
460
+ // literal one token, so that the two agree on where the regex ends.
461
+ if (term == regexLitOpen) {
462
+ let opening = regexOpening(input), end = opening ? regexEnd(input, opening) : -1;
463
+ // Without one, which takes a parse that does not start from a
464
+ // literal, the regex runs to the end of what is parsed.
465
+ return context.withRegex(new RegexBody(null, 0, end < 0 ? Infinity : input.pos + end));
466
+ }
467
+ if (term == regexLitClose)
468
+ return context.withRegex(null);
469
+ // The braces of a block of code in a regex, and of the blocks in it.
470
+ // The tokens `{` and `}` have no term to go by.
471
+ if (regex && !termModes.has(term)) {
472
+ if (input.next == 123 /* Ch.BraceOpen */)
473
+ context = context.withRegex(regex.withBraces(regex.braces + 1));
474
+ else if (input.next == 125 /* Ch.BraceClose */ && regex.braces > 0)
475
+ context = context.withRegex(regex.withBraces(regex.braces - 1));
476
+ }
196
477
  switch (term) {
197
478
  case quoteStart: {
198
- let opening = readOpening(input);
199
- return opening ? new Context(0 /* Mode.Term */, new Quote(context.quote, opening.open, opening.close, opening.count, 0))
200
- : context;
479
+ let opening = wordListOpening(input, 0) || readOpening(input);
480
+ if (!opening)
481
+ return context;
482
+ let quote = new Quote(context.quote, opening.open, opening.close, opening.count, 0, opening.interpolates, opening.escapes);
483
+ return context.withQuote(0 /* Mode.Term */, quote, withHeredocAt(context.heredocs, input, 0));
201
484
  }
202
485
  case quoteNestOpen:
203
486
  case quoteNestClose: {
@@ -205,53 +488,37 @@ const trackContext = new lr.ContextTracker({
205
488
  if (!quote)
206
489
  return context;
207
490
  let depth = quote.depth + (term == quoteNestOpen ? 1 : -1);
208
- return new Context(0 /* Mode.Term */, new Quote(quote.parent, quote.open, quote.close, quote.count, depth));
491
+ return context.withQuote(0 /* Mode.Term */, quote.withDepth(depth));
209
492
  }
210
493
  case quoteEnd:
211
- return new Context(1 /* Mode.AfterTerm */, context.quote && context.quote.parent);
494
+ return context.withQuote(1 /* Mode.AfterTerm */, context.quote && context.quote.parent);
212
495
  }
213
496
  // The whitespace token has no term to go by. It is the only token
214
- // that starts with a space.
215
- if (!termModes.has(term) && isSpace(input.next))
497
+ // that starts with a space. A line break in it leaves the heredocs
498
+ // that found no terminator behind.
499
+ if (!termModes.has(term) && isSpace(input.next)) {
500
+ if (!context.heredocs.length)
501
+ return context;
502
+ for (let pos = 0; isSpace(input.peek(pos)); pos++)
503
+ if (input.peek(pos) == 10 /* Ch.Newline */)
504
+ return context.withHeredocs(noHeredocs);
216
505
  return context;
506
+ }
507
+ if (term == rawString)
508
+ context = context.withHeredocs(withHeredocAt(context.heredocs, input, 0));
217
509
  return context.withMode(modeAfter(term, input, 0, context.mode));
218
510
  },
219
- reduce(context, term) {
220
- return term == Identifier || term == Interpolation ? context.withMode(termModes.get(term)) : context;
511
+ reduce(context, term, _stack, input) {
512
+ // The input is at the start of the node that is reduced.
513
+ return term == Identifier || term == Interpolation ? context.withMode(modeAfter(term, input, 0, context.mode))
514
+ : context;
221
515
  },
222
516
  reuse(context, node, _stack, input) {
223
- // Walk down to the last token, keeping its offset from the node's
224
- // start, where the input is positioned. Stop at a node that settles
225
- // the mode by itself.
226
- let last = node, offset = 0;
227
- while (last instanceof common.Tree && last.children.length && !termModes.has(last.type.id)) {
228
- offset += last.positions[last.children.length - 1];
229
- last = last.children[last.children.length - 1];
230
- }
231
- let term;
232
- if (last instanceof common.Tree) {
233
- term = last.type.id;
234
- }
235
- else {
236
- // A buffer holds its nodes in pre-order, as type, start, end and
237
- // the index after the node's last descendant.
238
- let { buffer } = last, index = 0;
239
- for (let from = 0, to = buffer.length;;) {
240
- index = from;
241
- while (buffer[index + 3] < to)
242
- index = buffer[index + 3];
243
- from = index + 4;
244
- to = buffer[index + 3];
245
- if (from == to || termModes.has(buffer[index]))
246
- break;
247
- }
248
- term = buffer[index];
249
- offset += buffer[index + 1];
250
- }
251
- if (skippedTerms.has(term))
252
- return context;
517
+ context = context.withHeredocs(heredocsAfter(node, input, context.heredocs));
518
+ // The node's positions count from its start, where the input is.
519
+ let last = lastToken$1(node.topNode);
253
520
  // What comes before a trailing `++` in a reused node is a term.
254
- return context.withMode(modeAfter(term, input, offset, 1 /* Mode.AfterTerm */));
521
+ return last ? context.withMode(modeAfter(last.type.id, input, last.from, 1 /* Mode.AfterTerm */)) : context;
255
522
  },
256
523
  hash: context => context.hash
257
524
  });
@@ -259,7 +526,7 @@ function context(stack) { return stack.context; }
259
526
  // Whether a token of `size` characters at the current position is where
260
527
  // a term starts, as opposed to an infix operator.
261
528
  function inTermPosition(input, mode, size) {
262
- if (mode == 0 /* Mode.Term */)
529
+ if (mode == 0 /* Mode.Term */ || mode == 4 /* Mode.AfterMulti */)
263
530
  return true;
264
531
  if (mode == 1 /* Mode.AfterTerm */)
265
532
  return false;
@@ -272,21 +539,28 @@ function inTermPosition(input, mode, size) {
272
539
  // #`(( ... )), needs the same number of closing ones. Brackets of the
273
540
  // same kind nest. An unclosed comment runs to the end of the input.
274
541
  const blockComment = new lr.ExternalTokenizer(input => {
275
- if (input.next != 35 /* Ch.Hash */ || input.peek(1) != 96 /* Ch.Backtick */)
542
+ let end = embeddedCommentEnd(input, 0);
543
+ if (!end)
276
544
  return;
277
- let open = input.peek(2), close = brackets[open];
278
- if (close == null)
279
- return;
280
- let count = 1;
281
- while (input.peek(2 + count) == open)
282
- count++;
283
- let end = rawEnd(input, 2 + count, { open, close, count, escapes: false });
284
545
  if (end < 0)
285
546
  skipToEnd(input);
286
547
  else
287
548
  input.advance(end);
288
549
  input.acceptToken(BlockComment);
289
550
  });
551
+ // The offset after the embedded comment that starts at offset `at`.
552
+ // Zero when none starts there, and -1 when it is not closed.
553
+ function embeddedCommentEnd(input, at) {
554
+ if (input.peek(at) != 35 /* Ch.Hash */ || input.peek(at + 1) != 96 /* Ch.Backtick */)
555
+ return 0;
556
+ let open = input.peek(at + 2), close = brackets$1[open];
557
+ if (close == null)
558
+ return 0;
559
+ let count = 1;
560
+ while (input.peek(at + 2 + count) == open)
561
+ count++;
562
+ return rawEnd(input, at + 2 + count, { open, close, count, escapes: false });
563
+ }
290
564
  function isBlank(ch) { return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 13 /* Ch.Return */; }
291
565
  // The offset of the first character at or after `pos` that is not a blank.
292
566
  function blanksEnd(input, pos) {
@@ -294,6 +568,18 @@ function blanksEnd(input, pos) {
294
568
  pos++;
295
569
  return pos;
296
570
  }
571
+ // How far a token looks over the whitespace after it, to see what
572
+ // follows. A token must not look far past its end: see the note on
573
+ // lookahead in AGENTS.md.
574
+ const maxGap = 20;
575
+ // The offset of the first character at or after `pos` that is not a
576
+ // blank, or not whitespace when `lines` is set, going over at most
577
+ // maxGap characters.
578
+ function gapEnd(input, pos, lines = false) {
579
+ for (let end = pos + maxGap; pos < end && (lines ? isSpace : isBlank)(input.peek(pos));)
580
+ pos++;
581
+ return pos;
582
+ }
297
583
  // Whether only blanks separate the current position from the start of its line.
298
584
  function atLineStart(input) {
299
585
  for (let i = -1;; i--) {
@@ -323,121 +609,263 @@ function skipBlanks(input) {
323
609
  // Skips blanks, and tells whether the rest of the line starts with `text`.
324
610
  function lineStartsWith(input, text) {
325
611
  skipBlanks(input);
612
+ return startsWith(input, 0, text);
613
+ }
614
+ // Whether the text from offset `pos` starts with `text`, as a whole name.
615
+ function startsWith(input, pos, text) {
326
616
  for (let i = 0; i < text.length; i++)
327
- if (input.peek(i) != text.charCodeAt(i))
617
+ if (input.peek(pos + i) != text.charCodeAt(i))
328
618
  return false;
329
- return !continuesName(input, text.length);
619
+ return !continuesName(input, pos + text.length);
330
620
  }
331
621
  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,})$/;
332
- // A Pod block, from its `=directive` at the start of a line.
333
- // =begin name ... =end name delimited, can hold blocks of other names
334
- // =finish the rest of the file
335
- // =for name, =head1, ... up to the next blank line
336
- const podToken = new lr.ExternalTokenizer(input => {
622
+ const podCodeBlock = /^(code|input|output)$/;
623
+ // The offset after the directive that starts at the current position,
624
+ // as in `=begin` or `=head1`, or -1 when there is none.
625
+ function podDirectiveEnd(input) {
337
626
  if (input.next != 61 /* Ch.Equals */ || !isAsciiLetter(input.peek(1)) || !atLineStart(input))
338
- return;
627
+ return -1;
339
628
  let end = 1;
340
629
  while (isAsciiLetter(input.peek(end)) || isDigit(input.peek(end)))
341
630
  end++;
342
631
  let directive = word(input, 1, end);
343
632
  if (!podDirective.test(directive) || continuesName(input, end))
344
- return;
633
+ return -1;
345
634
  // A semantic block such as =TITLE has to start in the first column.
346
635
  // An indented `=FOO + 1` continues an assignment.
347
636
  if (directive.charCodeAt(0) <= 90 /* Ch.Z */ && input.peek(-1) >= 0 && input.peek(-1) != 10 /* Ch.Newline */)
637
+ return -1;
638
+ return end;
639
+ }
640
+ // The offset after the name that goes with a directive which ends at
641
+ // offset `end`: `=begin pod`, `=for comment`, `=end code`. The other
642
+ // directives have none.
643
+ function podNameEnd(input, end) {
644
+ if (!/^(begin|for|end)$/.test(word(input, 1, end)))
645
+ return end;
646
+ let name = nameEnd(input, blanksEnd(input, end));
647
+ return name < 0 ? end : name;
648
+ }
649
+ // The block that the directive at the current position starts.
650
+ // =begin name ... =end name delimited, can hold blocks of other names
651
+ // =finish the rest of the file
652
+ // =for name, =head1, ... up to the next blank line
653
+ function readPodStart(input) {
654
+ let end = podDirectiveEnd(input), directive = word(input, 1, end);
655
+ if (directive == "finish")
656
+ return new PodBlock(2 /* PodKind.Finish */, "", false);
657
+ let nameStart = blanksEnd(input, end), name = word(input, nameStart, Math.max(nameStart, nameEnd(input, nameStart)));
658
+ if (directive == "begin")
659
+ return new PodBlock(0 /* PodKind.Delimited */, name, podCodeBlock.test(name));
660
+ return new PodBlock(1 /* PodKind.Paragraph */, "", podCodeBlock.test(directive == "for" ? name : directive));
661
+ }
662
+ // Whether the current position is right after a `=head` directive,
663
+ // where the text of the heading starts.
664
+ function atHeadingText(input) {
665
+ let pos = -1;
666
+ while (isDigit(input.peek(pos)))
667
+ pos--;
668
+ for (let i = 0; i < 5; i++)
669
+ if (input.peek(pos - i) != "=head".charCodeAt(4 - i))
670
+ return false;
671
+ for (pos -= 5; isBlank(input.peek(pos)); pos--) { }
672
+ return input.peek(pos) < 0 || input.peek(pos) == 10 /* Ch.Newline */;
673
+ }
674
+ // Whether a formatting code starts at offset `pos`: B<, C<<, L«
675
+ function isFormattingCode(input, pos) {
676
+ let ch = input.peek(pos), after = input.peek(pos + 1), before = input.peek(pos - 1);
677
+ return ch >= 65 /* Ch.A */ && ch <= 90 /* Ch.Z */ && (after == 60 /* Ch.Less */ || after == 171 /* Ch.GuillemetOpen */) &&
678
+ !isAsciiLetter(before) && !isDigit(before);
679
+ }
680
+ // The offset after the formatting code at the current position. When
681
+ // the code is not closed in its paragraph, this is the negated offset
682
+ // of the end of the text that was gone over to find that out.
683
+ function formattingCodeEnd(input) {
684
+ let open = input.peek(1), close = brackets$1[open], count = 1;
685
+ while (open == 60 /* Ch.Less */ && input.peek(1 + count) == open)
686
+ count++;
687
+ for (let pos = 1 + count, depth = 1;; pos++) {
688
+ let ch = input.peek(pos);
689
+ if (ch < 0)
690
+ return -pos;
691
+ if (ch == 10 /* Ch.Newline */) {
692
+ // A blank line or a directive ends the paragraph.
693
+ let next = blanksEnd(input, pos + 1), after = input.peek(next);
694
+ if (after < 0 || after == 10 /* Ch.Newline */ || after == 61 /* Ch.Equals */ && isAsciiLetter(input.peek(next + 1)))
695
+ return -pos;
696
+ }
697
+ else if (ch == close && repeats(input, pos, close, count)) {
698
+ pos += count - 1;
699
+ if (--depth == 0)
700
+ return pos + 1;
701
+ }
702
+ else if (ch == open && count == 1) {
703
+ // C<a < b> is not closed by the first `>` when another `<` came before it.
704
+ depth++;
705
+ }
706
+ }
707
+ }
708
+ const formattingTerms = { 66: PodStrong, 73: PodEmphasis, 67: PodCode, 76: PodLink };
709
+ // The pieces of a Pod block, which starts with a `=directive` at the
710
+ // start of a line. What it is, and with that where it ends, is kept in
711
+ // the context.
712
+ const podToken = new lr.ExternalTokenizer((input, stack) => {
713
+ let { pod } = context(stack);
714
+ if (!pod) {
715
+ let end = podDirectiveEnd(input);
716
+ if (end > 0)
717
+ input.acceptToken(podStart, podNameEnd(input, end));
348
718
  return;
349
- input.advance(end);
350
- if (directive == "finish") {
351
- skipToEnd(input);
352
719
  }
353
- else if (directive == "begin") {
354
- skipBlanks(input);
355
- let name = word(input, 0, Math.max(0, nameEnd(input, 0)));
356
- for (;;) {
357
- skipLine(input);
358
- if (input.next < 0)
359
- break;
360
- input.advance();
361
- if (!lineStartsWith(input, "=end"))
362
- continue;
363
- input.advance(4);
364
- if (lineStartsWith(input, name)) {
365
- skipLine(input);
366
- break;
367
- }
368
- }
720
+ let next = input.next;
721
+ if (next < 0)
722
+ return input.acceptToken(podEnd);
723
+ if (next == 10 /* Ch.Newline */ && pod.kind == 1 /* PodKind.Paragraph */) {
724
+ // Ends before a blank line or another directive.
725
+ let pos = blanksEnd(input, 1), ch = input.peek(pos);
726
+ if (ch == 10 /* Ch.Newline */ || ch < 0 || ch == 61 /* Ch.Equals */ && isAsciiLetter(input.peek(pos + 1)))
727
+ return input.acceptToken(podEnd);
369
728
  }
370
- else {
371
- for (;;) {
729
+ let directive = pod.kind == 0 /* PodKind.Delimited */ ? podDirectiveEnd(input) : -1;
730
+ if (directive > 0) {
731
+ if (directive == 4 && startsWith(input, 1, "end") && startsWith(input, blanksEnd(input, 4), pod.name)) {
372
732
  skipLine(input);
373
- if (input.next < 0)
374
- break;
375
- // Stop before a blank line or another directive.
376
- let i = blanksEnd(input, 1), ch = input.peek(i);
377
- if (ch == 10 /* Ch.Newline */ || ch < 0 || ch == 61 /* Ch.Equals */ && isAsciiLetter(input.peek(i + 1)))
378
- break;
379
- input.advance();
733
+ return input.acceptToken(podEndDirective);
380
734
  }
735
+ return input.acceptToken(PodDirective, podNameEnd(input, directive));
381
736
  }
382
- input.acceptToken(Pod);
737
+ if (atHeadingText(input) && !isLineEnd(input, 0)) {
738
+ skipLine(input);
739
+ return input.acceptToken(PodHeading);
740
+ }
741
+ if (!pod.code && isFormattingCode(input, 0)) {
742
+ let end = formattingCodeEnd(input);
743
+ if (end > 0)
744
+ return input.acceptToken(formattingTerms[next] || PodFormat, end);
745
+ // What looked like a code is text. The text that was gone over is
746
+ // made one token, so that no token has looked beyond its own end.
747
+ // A token that does keeps the tokens before it from being reused.
748
+ return input.acceptToken(podText, -end);
749
+ }
750
+ // Text, up to where one of the above may apply.
751
+ for (;;) {
752
+ input.advance();
753
+ let ch = input.next;
754
+ if (ch < 0 || ch == 10 /* Ch.Newline */ || !pod.code && isFormattingCode(input, 0))
755
+ break;
756
+ // A directive can only follow the blanks at the start of a line.
757
+ if (ch == 61 /* Ch.Equals */ && atLineStart(input))
758
+ break;
759
+ }
760
+ input.acceptToken(podText);
383
761
  });
384
762
  const quoteWords = {
385
763
  q: "raw", Q: "raw", qw: "raw", qww: "raw", qx: "raw", Qw: "raw", Qww: "raw", Qx: "raw",
386
764
  qq: "interpolating", qqw: "interpolating", qqww: "interpolating", qqx: "interpolating",
387
765
  rx: "regex", m: "regex", ms: "regex",
388
- s: "substitution", ss: "substitution", S: "substitution", tr: "substitution", TR: "substitution"
766
+ s: "substitution", ss: "substitution", S: "substitution",
767
+ // Like a substitution, but its first part is not a regex.
768
+ tr: "transliteration", TR: "transliteration"
389
769
  };
770
+ // The kinds of interpolation that the adverbs of a quote switch.
771
+ const interpolationAdverbs = new Map([
772
+ ["c", 1 /* Interpolate.Closure */], ["closure", 1 /* Interpolate.Closure */],
773
+ ["s", 2 /* Interpolate.Scalar */], ["scalar", 2 /* Interpolate.Scalar */],
774
+ ["a", 4 /* Interpolate.Array */], ["array", 4 /* Interpolate.Array */],
775
+ ["h", 8 /* Interpolate.Hash */], ["hash", 8 /* Interpolate.Hash */],
776
+ ["f", 16 /* Interpolate.Function */], ["function", 16 /* Interpolate.Function */],
777
+ ["b", 32 /* Interpolate.Backslash */], ["backslash", 32 /* Interpolate.Backslash */],
778
+ ["qq", 63 /* Interpolate.All */], ["double", 63 /* Interpolate.All */]
779
+ ]);
780
+ // The opening of a word list that interpolates, at offset `at`: << or «
781
+ function wordListOpening(input, at) {
782
+ let open = input.peek(at), count = open == 60 /* Ch.Less */ ? 2 : 1;
783
+ if (open != 171 /* Ch.GuillemetOpen */ && !(open == 60 /* Ch.Less */ && input.peek(at + 1) == 60 /* Ch.Less */))
784
+ return null;
785
+ return { open, close: brackets$1[open], count, start: at + count, kind: "interpolating",
786
+ interpolates: 63 /* Interpolate.All */, escapes: true };
787
+ }
788
+ // The opening of a quote that starts with a quote character at offset `at`.
789
+ function quoteCharOpening(open, close, at, interpolates, escapes = true) {
790
+ return { open, close, count: 1, start: at + 1, kind: interpolates ? "interpolating" : "raw", interpolates, escapes };
791
+ }
390
792
  // The delimiters, other than brackets, that are accepted after a quote word.
391
793
  function isQuoteDelimiter(ch) {
392
794
  return ch == 47 /* Ch.Slash */ || ch == 33 /* Ch.Bang */ || ch == 124 /* Ch.Pipe */ || ch == 126 /* Ch.Tilde */ || ch == 94 /* Ch.Caret */ ||
393
795
  ch == 37 /* Ch.Percent */ || ch == 64 /* Ch.At */ || ch == 34 /* Ch.DoubleQuote */ || ch == 39 /* Ch.Apostrophe */;
394
796
  }
395
- // Reads the start of a quote at the current position: a quote character,
396
- // or a quote word (q, qq, m, s, ...) with its adverbs and its delimiter.
397
- function readOpening(input) {
398
- let next = input.next;
797
+ // Reads the start of a quote at offset `at`: a quote character, or a
798
+ // quote word (q, qq, m, s, ...) with its adverbs and its delimiter.
799
+ // The offsets in the result count from the current position.
800
+ function readOpening(input, at = 0) {
801
+ let next = input.peek(at);
399
802
  if (next == 34 /* Ch.DoubleQuote */)
400
- return { open: next, close: next, count: 1, start: 1, kind: "interpolating", escapes: true };
803
+ return quoteCharOpening(next, next, at, 63 /* Interpolate.All */);
401
804
  if (next == 39 /* Ch.Apostrophe */)
402
- return { open: next, close: next, count: 1, start: 1, kind: "raw", escapes: true };
805
+ return quoteCharOpening(next, next, at, 0);
403
806
  if (next == 0x201c /* “ */)
404
- return { open: next, close: 0x201d, count: 1, start: 1, kind: "interpolating", escapes: true };
807
+ return quoteCharOpening(next, 0x201d, at, 63 /* Interpolate.All */);
405
808
  if (next == 0x2018 /* ‘ */)
406
- return { open: next, close: 0x2019, count: 1, start: 1, kind: "raw", escapes: true };
809
+ return quoteCharOpening(next, 0x2019, at, 0);
407
810
  if (next == 0x300c /* 「 */)
408
- return { open: next, close: 0x300d, count: 1, start: 1, kind: "raw", escapes: false };
811
+ return quoteCharOpening(next, 0x300d, at, 0, false);
409
812
  if (!isAsciiLetter(next))
410
813
  return null;
411
- let pos = 1;
814
+ let pos = at + 1;
412
815
  while (isAsciiLetter(input.peek(pos)))
413
816
  pos++;
414
- if (pos > 4)
817
+ if (pos - at > 4)
415
818
  return null;
416
- let name = word(input, 0, pos), kind = quoteWords[name];
819
+ let name = word(input, at, pos), kind = quoteWords[name];
417
820
  if (!kind)
418
821
  return null;
419
- // Adverbs: :w, :to, :g, :x(2)
420
- let adverbs = false;
822
+ // Adverbs: :w, :to, :g, :x(2). Those of a regex mean other things
823
+ // than those of a quote: m:s/a b/
824
+ let adverbs = false, heredoc = false, isQuote = kind == "raw" || kind == "interpolating";
825
+ let interpolates = kind == "interpolating" ? 63 /* Interpolate.All */ : 0;
826
+ // Whether a backslash escapes the delimiter, apart from the escapes
827
+ // of :b. That comes with q and its :q adverb: Q and qq:!b have none.
828
+ let escapes = isQuote ? kind == "raw" && next == 113 /* Ch.q */ : true;
421
829
  while (input.peek(pos) == 58 /* Ch.Colon */ && (isAsciiLetter(input.peek(pos + 1)) || input.peek(pos + 1) == 33 /* Ch.Bang */)) {
422
830
  adverbs = true;
831
+ let negated = input.peek(pos + 1) == 33 /* Ch.Bang */, adverbStart = pos + (negated ? 2 : 1);
423
832
  pos += 2;
424
833
  while (isAsciiLetter(input.peek(pos)) || isDigit(input.peek(pos)))
425
834
  pos++;
835
+ let adverb = word(input, adverbStart, pos);
836
+ // An argument that is False or 0 switches the adverb off: q:c(False)
426
837
  if (input.peek(pos) == 40 /* Ch.ParenOpen */) {
838
+ let argStart = pos + 1;
427
839
  while (input.peek(pos) != 41 /* Ch.ParenClose */) {
428
840
  if (input.peek(pos) < 0 || input.peek(pos) == 10 /* Ch.Newline */)
429
841
  return null;
430
842
  pos++;
431
843
  }
844
+ if (/^\s*(False|0)\s*$/.test(word(input, argStart, pos)))
845
+ negated = true;
432
846
  pos++;
433
847
  }
848
+ if (isQuote) {
849
+ let bits = interpolationAdverbs.get(adverb);
850
+ if (bits != null)
851
+ interpolates = negated ? interpolates & ~bits : interpolates | bits;
852
+ else if (!negated && (adverb == "q" || adverb == "single"))
853
+ escapes = true;
854
+ else if (!negated && (adverb == "to" || adverb == "heredoc"))
855
+ heredoc = true;
856
+ }
434
857
  }
435
858
  if (!adverbs && continuesName(input, pos))
436
859
  return null;
437
- // The delimiter has to follow directly. Raku also takes `q {...}`, but
438
- // then `S { ... }` and `m ($x)` on a name that is not a quote word
439
- // would turn into quotes.
440
- let open = input.peek(pos), close = brackets[open];
860
+ // The delimiter follows directly, or, for q, qq and Q, after blanks
861
+ // on the same line: q {...}. Not for m, s and the others: `s { ... }`
862
+ // and `m ($x)` are more often calls of a routine of one's own.
863
+ if (isQuote && isBlank(input.peek(pos))) {
864
+ let bracket = gapEnd(input, pos);
865
+ if (brackets$1[input.peek(bracket)] != null && input.peek(bracket) != 40 /* Ch.ParenOpen */)
866
+ pos = bracket;
867
+ }
868
+ let open = input.peek(pos), close = brackets$1[open];
441
869
  if (close == null) {
442
870
  if (!isQuoteDelimiter(open))
443
871
  return null;
@@ -450,7 +878,11 @@ function readOpening(input) {
450
878
  if (close != open)
451
879
  while (input.peek(pos + count) == open)
452
880
  count++;
453
- return { open, close, count, start: pos + count, kind, escapes: name.charCodeAt(0) != 81 /* Ch.Q */ };
881
+ if (isQuote)
882
+ kind = interpolates ? "interpolating" : "raw";
883
+ if (interpolates & 32 /* Interpolate.Backslash */)
884
+ escapes = true;
885
+ return { open, close, count, start: pos + count, kind, interpolates, escapes, heredoc };
454
886
  }
455
887
  // The offset after the delimiter that closes a quote whose content
456
888
  // starts at `pos`, or -1 when it is not closed.
@@ -493,7 +925,7 @@ function quotedEnd(input, pos) {
493
925
  // The offset of the delimiter that closes a regex whose content starts
494
926
  // at `pos`, or -1. Delimiters do not count inside quotes, character
495
927
  // classes, comments and code blocks.
496
- function regexEnd(input, pos, open, close, count) {
928
+ function regexEnd(input, { start: pos, open, close, count }) {
497
929
  for (let depth = 1;;) {
498
930
  let ch = input.peek(pos);
499
931
  if (ch < 0)
@@ -541,13 +973,20 @@ function regexEnd(input, pos, open, close, count) {
541
973
  break;
542
974
  pos = more;
543
975
  }
976
+ // The bracket that closes the class is not one of the regex: rx[ <[a]> ]
977
+ pos++;
544
978
  }
545
979
  else if (ch == 35 /* Ch.Hash */) {
546
- while (input.peek(pos) >= 0 && input.peek(pos) != 10 /* Ch.Newline */)
547
- pos++;
980
+ // An embedded comment, or one that runs to the end of the line.
981
+ let end = embeddedCommentEnd(input, pos);
982
+ if (end > 0)
983
+ pos = end;
984
+ else
985
+ while (input.peek(pos) >= 0 && input.peek(pos) != 10 /* Ch.Newline */)
986
+ pos++;
548
987
  }
549
988
  else if (ch == 123 /* Ch.BraceOpen */ && close != 125 /* Ch.BraceClose */) {
550
- let end = regexEnd(input, pos + 1, 123 /* Ch.BraceOpen */, 125 /* Ch.BraceClose */, 1);
989
+ let end = regexEnd(input, { start: pos + 1, open: 123 /* Ch.BraceOpen */, close: 125 /* Ch.BraceClose */, count: 1 });
551
990
  pos = end < 0 ? pos + 1 : end + 1;
552
991
  }
553
992
  else {
@@ -557,25 +996,41 @@ function regexEnd(input, pos, open, close, count) {
557
996
  }
558
997
  // The offset after a regex or substitution, given its opening, or -1.
559
998
  function regexTokenEnd(input, opening) {
560
- let { open, close, count } = opening;
561
- let end = regexEnd(input, opening.start, open, close, count);
999
+ let end = regexEnd(input, opening);
562
1000
  if (end < 0)
563
1001
  return -1;
564
- end += count;
1002
+ end += opening.count;
565
1003
  // s/a/b/ has a second part. s{a} = 'b' does not.
566
- if (opening.kind == "substitution" && open == close)
1004
+ if (opening.kind != "regex" && opening.open == opening.close)
567
1005
  end = rawEnd(input, end, opening);
568
1006
  return end;
569
1007
  }
1008
+ // The opening of a bare regex: /a/
1009
+ const slashOpening = { open: 47 /* Ch.Slash */, close: 47 /* Ch.Slash */, count: 1, start: 1, kind: "regex",
1010
+ interpolates: 0, escapes: true };
1011
+ // The opening of the regex literal at the current position. The token
1012
+ // that makes a literal one token, and the parse of its inside, both
1013
+ // find its closing delimiter from this, so that they agree.
1014
+ function regexOpening(input) {
1015
+ if (input.next == 47 /* Ch.Slash */)
1016
+ return slashOpening;
1017
+ let opening = readOpening(input);
1018
+ return opening && (opening.kind == "regex" || opening.kind == "substitution") ? opening : null;
1019
+ }
570
1020
  // The offset after a word list that opens at the current position, or
571
1021
  // -1. A list that spans lines has to hold plain words, so that a stray
572
1022
  // `<` does not swallow the code up to some later `>`. `strict` is for
573
1023
  // a subscript, which has to be on one line, and cannot hold what
574
1024
  // would make it a comparison: `$a<5 && $b>3`.
1025
+ //
1026
+ // A list with double angles is rarely a stray operator, and may hold
1027
+ // code over a few lines. Not over more: one that is being typed would
1028
+ // swallow the code up to some later `>>`.
575
1029
  function wordListEnd(input, strict) {
576
1030
  let open = input.next, close = open == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : 62 /* Ch.Greater */;
577
1031
  let count = open == 60 /* Ch.Less */ && input.peek(1) == 60 /* Ch.Less */ ? 2 : 1;
578
- for (let pos = count, lines = 0, code = false;; pos++) {
1032
+ let codeLines = open == 171 /* Ch.GuillemetOpen */ || count == 2 ? maxCodeWordListLines : 1;
1033
+ for (let pos = count, lines = 1, code = false;; pos++) {
579
1034
  let ch = input.peek(pos);
580
1035
  if (ch == close && repeats(input, pos, close, count))
581
1036
  return pos + count;
@@ -586,7 +1041,7 @@ function wordListEnd(input, strict) {
586
1041
  else if (ch == 59 /* Ch.Semicolon */ || ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ ||
587
1042
  ch == 40 /* Ch.ParenOpen */ || ch == 41 /* Ch.ParenClose */)
588
1043
  code = true;
589
- if (lines && (code || strict))
1044
+ if (lines > 1 && (code && lines > codeLines || strict))
590
1045
  return -1;
591
1046
  if (strict && (code || ch == 36 /* Ch.Dollar */ || ch == 64 /* Ch.At */ || ch == 37 /* Ch.Percent */ || ch == 38 /* Ch.Amp */ ||
592
1047
  ch == 124 /* Ch.Pipe */ || ch == 61 /* Ch.Equals */ || ch == 44 /* Ch.Comma */ || ch == 63 /* Ch.Question */ ||
@@ -594,19 +1049,77 @@ function wordListEnd(input, strict) {
594
1049
  return -1;
595
1050
  }
596
1051
  }
1052
+ // How many lines a <<...>> list that holds code may span.
1053
+ const maxCodeWordListLines = 10;
1054
+ // How long a <<...>> subscript can be. Whether it is closed is found
1055
+ // out from its start, and a token must not look far past its end.
1056
+ const maxDoubleSubscript = 24;
1057
+ // Whether a character can start or end the content of a <<...>>
1058
+ // subscript: part of a word, a variable or a quote. An operator
1059
+ // character cannot, which tells the hyper operators apart: @a<<+>>@b,
1060
+ // @a«R-»@b
1061
+ function isSubscriptEdge(ch) {
1062
+ return isIdentifierStart(ch) || isDigit(ch) || ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */;
1063
+ }
1064
+ // The offset after the <<...>> subscript at the current position, with
1065
+ // the given opening, or -1. It is short, on one line, and holds no
1066
+ // punctuation of statements.
1067
+ function doubleSubscriptEnd(input, { start, close, count }) {
1068
+ let first = input.peek(start);
1069
+ if (!isSubscriptEdge(first) && first != 36 /* Ch.Dollar */ && first != 64 /* Ch.At */ && first != 37 /* Ch.Percent */ && first != 38 /* Ch.Amp */)
1070
+ return -1;
1071
+ for (let pos = start; pos < maxDoubleSubscript; pos++) {
1072
+ let ch = input.peek(pos);
1073
+ if (ch == close && repeats(input, pos, close, count))
1074
+ return isSubscriptEdge(input.peek(pos - 1)) ? pos + count : -1;
1075
+ if (ch < 0 || ch == 10 /* Ch.Newline */ || ch == 59 /* Ch.Semicolon */ || ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ ||
1076
+ ch == 40 /* Ch.ParenOpen */ || ch == 41 /* Ch.ParenClose */)
1077
+ return -1;
1078
+ }
1079
+ return -1;
1080
+ }
1081
+ // Whether every `{` between two offsets has its `}` there, and the
1082
+ // other way around.
1083
+ function hasBalancedBraces(input, from, to) {
1084
+ let depth = 0;
1085
+ for (let pos = from; pos < to; pos++) {
1086
+ let ch = input.peek(pos);
1087
+ if (ch == 123 /* Ch.BraceOpen */)
1088
+ depth++;
1089
+ else if (ch == 125 /* Ch.BraceClose */ && --depth < 0)
1090
+ return false;
1091
+ }
1092
+ return depth == 0;
1093
+ }
597
1094
  // A `<` subscript right after a term: %h<key>
598
1095
  function subscriptEnd(input) {
599
1096
  if (input.next != 60 /* Ch.Less */ || isSpace(input.peek(-1)) || input.peek(1) == 60 /* Ch.Less */)
600
1097
  return -1;
601
1098
  return wordListEnd(input, true);
602
1099
  }
1100
+ // The keywords that are routines or prefix operators, and can be called
1101
+ // with parentheses. `if(1)` and `my($x)` are not calls of this kind.
1102
+ const callableKeywords = /^(take|return|emit|next|last|redo|proceed|succeed|so|not)$/;
1103
+ // The words that declare what follows `multi`, `proto` or `only`.
1104
+ const declarators$1 = /^(sub|method|submethod|token|rule|regex)$/;
1105
+ // Whether a declarator starts with the given word, as `su` starts `sub`.
1106
+ function startsDeclarator(name) {
1107
+ return ["sub", "method", "submethod", "token", "rule", "regex"].some(declarator => declarator.startsWith(name));
1108
+ }
1109
+ const operatorCategory = /^(infix|prefix|postfix|circumfix|postcircumfix|term)$/;
603
1110
  function isWordOperator(name) {
604
1111
  return name == "x" || name == "xx" || name == "min" || name == "max" || name == "Z" || name == "X";
605
1112
  }
606
1113
  // The tokens that depend on whether a term or an operator is expected.
607
1114
  const termToken = new lr.ExternalTokenizer((input, stack) => {
608
- if (!stack.canShift(Regex))
1115
+ if (!stack.canShift(regexLiteral)) {
1116
+ // At the start of the parse of the inside of a word list that
1117
+ // interpolates, its opening delimiter.
1118
+ let opening = context(stack) == startContext && stack.canShift(quoteStart) ? wordListOpening(input, 0) : null;
1119
+ if (opening)
1120
+ input.acceptToken(quoteStart, opening.start);
609
1121
  return;
1122
+ }
610
1123
  let next = input.next, { mode } = context(stack);
611
1124
  if (isIdentifierStart(next)) {
612
1125
  // The Z, X and R meta operators: Z+, X~, R-, Z=>
@@ -618,14 +1131,29 @@ const termToken = new lr.ExternalTokenizer((input, stack) => {
618
1131
  return input.acceptToken(wordOperator, pos);
619
1132
  }
620
1133
  // A word before `=>` is a key, whatever it spells.
621
- let end = nameEnd(input, 0), after = end;
622
- while (input.peek(after) == 32 /* Ch.Space */ || input.peek(after) == 9 /* Ch.Tab */)
623
- after++;
1134
+ let end = nameEnd(input, 0), after = gapEnd(input, end);
624
1135
  if (input.peek(after) == 61 /* Ch.Equals */ && input.peek(after + 1) == 62 /* Ch.Greater */)
625
- return input.acceptToken(fatArrowKey, end);
1136
+ return input.acceptToken(plainName, end);
1137
+ // After `multi`, `proto` or `only`, a name that is not a declarator
1138
+ // is that of a sub: multi foo($x) { }
1139
+ // Only with a signature or a body right after it. A name alone may
1140
+ // be a declarator that is still being typed (`multi su`), and
1141
+ // `only` and `proto` can be routines of one's own (`only foo, 1`).
1142
+ // The signature may start on the next line, unless the name can
1143
+ // still become a declarator: `multi su` above a line with a `(`.
1144
+ if (mode == 4 /* Mode.AfterMulti */ && !(end <= 9 && declarators$1.test(word(input, 0, end)))) {
1145
+ let nameTo = categoryEnd(input, 0, end), opens = (ch) => ch == 40 /* Ch.ParenOpen */ || ch == 123 /* Ch.BraceOpen */;
1146
+ if (opens(input.peek(gapEnd(input, nameTo))) ||
1147
+ opens(input.peek(gapEnd(input, nameTo, true))) && !startsDeclarator(word(input, 0, end)))
1148
+ return input.acceptToken(multiName, nameTo);
1149
+ }
1150
+ // So is one of the keywords that are routines, when it is called
1151
+ // with parentheses: take(1). They are 2 to 7 characters long.
1152
+ if (input.peek(end) == 40 /* Ch.ParenOpen */ && end <= 7 && callableKeywords.test(word(input, 0, end)))
1153
+ return input.acceptToken(plainName, end);
626
1154
  if (mode == 1 /* Mode.AfterTerm */) {
627
1155
  // x, xx, min, max, Z and X are operators where one is expected.
628
- if (isWordOperator(word(input, 0, end)))
1156
+ if (end <= 3 && isWordOperator(word(input, 0, end)))
629
1157
  input.acceptToken(wordOperator, end);
630
1158
  return;
631
1159
  }
@@ -634,11 +1162,20 @@ const termToken = new lr.ExternalTokenizer((input, stack) => {
634
1162
  // Squeezed between two terms, a sigil is the operator: $a%b. With a
635
1163
  // space before it, it is a variable: `my Array[Int] %h`.
636
1164
  if (mode == 1 /* Mode.AfterTerm */ && isIdentifierStart(input.peek(1)) && !isSpace(input.peek(-1)))
637
- input.acceptToken(wordOperator, 1);
1165
+ return input.acceptToken(wordOperator, 1);
1166
+ // An operator as a routine: &infix:<+>
1167
+ if (next == 38 /* Ch.Amp */) {
1168
+ let end = nameEnd(input, 1);
1169
+ if (end > 0 && operatorCategory.test(word(input, 1, end))) {
1170
+ let categoryTo = categoryEnd(input, 1, end);
1171
+ if (categoryTo > end)
1172
+ input.acceptToken(operatorVariable, categoryTo);
1173
+ }
1174
+ }
638
1175
  return;
639
1176
  }
640
1177
  else if (next == 60 /* Ch.Less */ || next == 171 /* Ch.GuillemetOpen */) {
641
- let end;
1178
+ let end, opening = wordListOpening(input, 0);
642
1179
  if (inTermPosition(input, mode, 1)) {
643
1180
  // [<] and [<=] are reductions, <-> starts a pointy block.
644
1181
  let after = input.peek(1);
@@ -646,19 +1183,31 @@ const termToken = new lr.ExternalTokenizer((input, stack) => {
646
1183
  return;
647
1184
  end = wordListEnd(input, false);
648
1185
  }
1186
+ else if (opening && !isSpace(input.peek(-1))) {
1187
+ // A subscript with double angles, which touches its term:
1188
+ // %h«$key», :a<<b $c>>
1189
+ end = doubleSubscriptEnd(input, opening);
1190
+ }
649
1191
  else {
650
1192
  end = subscriptEnd(input);
651
1193
  }
652
- if (end > 0)
653
- input.acceptToken(rawString, end);
654
- return;
1194
+ if (end <= 0)
1195
+ return;
1196
+ // <<a $b>> and «a $b» interpolate. The list is one token here:
1197
+ // that it is closed has to be known where it starts. Its inside
1198
+ // is parsed again, piece by piece (see index.ts), by rules that
1199
+ // count nested delimiters, escapes and the braces of blocks. A
1200
+ // list that those rules would end elsewhere is not read inside.
1201
+ let interpolates = opening && rawEnd(input, opening.start, opening) == end &&
1202
+ hasBalancedBraces(input, opening.start, end);
1203
+ return input.acceptToken(interpolates ? interpolatingWordList : rawString, end);
655
1204
  }
656
1205
  else if (next == 47 /* Ch.Slash */) {
657
1206
  if (input.peek(1) == 47 /* Ch.Slash */ || !inTermPosition(input, mode, 1))
658
1207
  return;
659
- let end = regexEnd(input, 1, 47 /* Ch.Slash */, 47 /* Ch.Slash */, 1);
1208
+ let end = regexTokenEnd(input, slashOpening);
660
1209
  if (end > 0)
661
- input.acceptToken(Regex, end + 1);
1210
+ input.acceptToken(regexLiteral, end);
662
1211
  return;
663
1212
  }
664
1213
  let opening = readOpening(input);
@@ -666,9 +1215,15 @@ const termToken = new lr.ExternalTokenizer((input, stack) => {
666
1215
  return;
667
1216
  if (opening.kind == "interpolating")
668
1217
  return input.acceptToken(quoteStart, opening.start);
669
- let end = opening.kind == "raw" ? rawEnd(input, opening.start, opening) : regexTokenEnd(input, opening);
1218
+ if (opening.kind != "raw") {
1219
+ let end = regexTokenEnd(input, opening);
1220
+ if (end > 0)
1221
+ input.acceptToken(opening.kind == "transliteration" ? transliteration : regexLiteral, end);
1222
+ return;
1223
+ }
1224
+ let end = rawEnd(input, opening.start, opening);
670
1225
  if (end > 0)
671
- input.acceptToken(opening.kind == "raw" ? rawString : Regex, end);
1226
+ input.acceptToken(rawString, end);
672
1227
  });
673
1228
  // Whether a sigil other than `$` interpolates: only when a subscript or
674
1229
  // a call follows its name. `end` is the offset after the name.
@@ -688,7 +1243,7 @@ const quoteToken = new lr.ExternalTokenizer((input, stack) => {
688
1243
  let { quote, mode } = context(stack);
689
1244
  if (!quote)
690
1245
  return;
691
- let { open, close, count } = quote, nests = open != close;
1246
+ let { open, close, count, interpolates } = quote, nests = open != close;
692
1247
  // After a variable, a subscript or a call continues the interpolation.
693
1248
  // `[` and `(` are left to the grammar's own tokens.
694
1249
  if (mode == 1 /* Mode.AfterTerm */) {
@@ -699,6 +1254,9 @@ const quoteToken = new lr.ExternalTokenizer((input, stack) => {
699
1254
  return input.acceptToken(rawString, end);
700
1255
  }
701
1256
  let start = input.pos;
1257
+ // The text of a heredoc ends where the input does.
1258
+ if (input.next < 0 && quote == heredocQuote)
1259
+ return input.acceptToken(quoteEnd);
702
1260
  for (;;) {
703
1261
  let next = input.next;
704
1262
  if (next < 0)
@@ -710,9 +1268,24 @@ const quoteToken = new lr.ExternalTokenizer((input, stack) => {
710
1268
  input.advance(count);
711
1269
  return input.acceptToken(!atClose ? quoteNestOpen : quote.depth ? quoteNestClose : quoteEnd);
712
1270
  }
713
- if (next == 92 /* Ch.Backslash */ || next == 36 /* Ch.Dollar */ || next == 123 /* Ch.BraceOpen */)
714
- break;
715
- if (next == 64 /* Ch.At */ || next == 37 /* Ch.Percent */ || next == 38 /* Ch.Amp */) {
1271
+ if (next == 92 /* Ch.Backslash */) {
1272
+ if (interpolates & 32 /* Interpolate.Backslash */)
1273
+ break;
1274
+ // Still keeps a delimiter after it from closing the quote.
1275
+ if (quote.escapes && input.peek(1) >= 0)
1276
+ input.advance();
1277
+ }
1278
+ else if (next == 36 /* Ch.Dollar */) {
1279
+ if (interpolates & 2 /* Interpolate.Scalar */)
1280
+ break;
1281
+ }
1282
+ else if (next == 123 /* Ch.BraceOpen */) {
1283
+ if (interpolates & 1 /* Interpolate.Closure */)
1284
+ break;
1285
+ }
1286
+ else if (next == 64 /* Ch.At */ && interpolates & 4 /* Interpolate.Array */ ||
1287
+ next == 37 /* Ch.Percent */ && interpolates & 8 /* Interpolate.Hash */ ||
1288
+ next == 38 /* Ch.Amp */ && interpolates & 16 /* Interpolate.Function */) {
716
1289
  let end = nameEnd(input, 1);
717
1290
  if (end > 0 && hasPostfix(input, end))
718
1291
  break;
@@ -725,37 +1298,27 @@ const quoteToken = new lr.ExternalTokenizer((input, stack) => {
725
1298
  // The text of a heredoc: the lines after the one that holds its opener,
726
1299
  // up to the line that holds only its terminator. As a skipped token, it
727
1300
  // leaves the rest of the opener's line to be parsed as usual. The
728
- // opener is looked up in the text of that line rather than kept in the
729
- // context, so that it is also found when the line's nodes were reused
730
- // from an earlier parse.
731
- const heredocToken = new lr.ExternalTokenizer(input => {
1301
+ // context holds the terminators of the heredocs that the line opened.
1302
+ //
1303
+ // The text is one token, also when it interpolates: that it has a
1304
+ // terminator has to be known where it starts. A text in which
1305
+ // everything interpolates is a token of its own kind, the inside of
1306
+ // which is parsed again (see index.ts), from an empty token that puts
1307
+ // the quote in the context. When a line opens several heredocs, their
1308
+ // texts are one token, which interpolates if all of them do.
1309
+ const heredocToken = new lr.ExternalTokenizer((input, stack) => {
1310
+ if (context(stack) == startContext && stack.canShift(heredocStart))
1311
+ return input.acceptToken(heredocStart);
1312
+ let { heredocs } = context(stack);
1313
+ if (!heredocs.length)
1314
+ return;
732
1315
  let pos = blanksEnd(input, 0);
733
1316
  if (input.peek(pos) != 10 /* Ch.Newline */)
734
1317
  return;
735
- // Read the line that just ended, and look for heredoc openers in it.
736
- let lineStart = 0;
737
- while (lineStart > -500 && input.peek(lineStart - 1) >= 0 && input.peek(lineStart - 1) != 10 /* Ch.Newline */)
738
- lineStart--;
739
- let line = word(input, lineStart, 0);
740
- if (line.indexOf(":to") < 0 && line.indexOf(":heredoc") < 0 || /^\s*#/.test(line))
741
- return;
742
- let opener = /(?:^|[^\w$@%&.'-])[qQ]\w*(?::\w+)*:(?:to|heredoc)(?::\w+)*\s*(\S)/g, found;
743
- let terminators = [];
744
- while (found = opener.exec(line)) {
745
- let open = found[1], close = String.fromCharCode(brackets[open.charCodeAt(0)] || open.charCodeAt(0));
746
- let end = line.indexOf(close, opener.lastIndex);
747
- if (end < 0)
748
- continue;
749
- terminators.push(line.slice(opener.lastIndex, end).trim());
750
- opener.lastIndex = end + 1;
751
- }
752
- if (!terminators.length)
753
- return;
754
1318
  input.advance(pos);
755
- for (let terminator of terminators) {
1319
+ for (let { terminator } of heredocs) {
756
1320
  for (;;) {
757
- // Without its terminator, this is not taken to be a heredoc. The
758
- // opener is found by its text, and may be in a comment or a string.
1321
+ // Without its terminator, this is not taken to be a heredoc.
759
1322
  if (input.next < 0)
760
1323
  return;
761
1324
  input.advance();
@@ -766,22 +1329,218 @@ const heredocToken = new lr.ExternalTokenizer(input => {
766
1329
  skipLine(input);
767
1330
  }
768
1331
  }
769
- input.acceptToken(Heredoc);
1332
+ input.acceptToken(heredocs.every(heredoc => heredoc.interpolates) ? interpolatingHeredoc : rawHeredoc);
770
1333
  });
771
- // The body of a token, rule or regex declaration, up to its closing brace.
772
- const regexBodyToken = new lr.ExternalTokenizer((input, stack) => {
773
- if (!stack.canShift(regexBody))
1334
+ const regexDeclarator = /^(token|rule|regex)$/;
1335
+ const regexDeclaratorPrefix = /^(proto|multi|my|our)$/;
1336
+ // Whether the line that starts at offset `pos` starts a regex
1337
+ // declaration: a declarator, a name, and further on a brace, as in
1338
+ // `token name {`. In a regex, the words alone can be literals:
1339
+ // `token | rule`
1340
+ function startsRegexDeclaration(input, pos) {
1341
+ let start = blanksEnd(input, pos), end = nameEnd(input, start);
1342
+ // proto token, my regex
1343
+ if (end > 0 && isBlank(input.peek(end)) && regexDeclaratorPrefix.test(word(input, start, end))) {
1344
+ start = blanksEnd(input, end);
1345
+ end = nameEnd(input, start);
1346
+ }
1347
+ if (end < 0 || end - start > 5 || !isBlank(input.peek(end)) || !regexDeclarator.test(word(input, start, end)))
1348
+ return false;
1349
+ let name = blanksEnd(input, end), after = nameEnd(input, name);
1350
+ if (after < 0)
1351
+ return false;
1352
+ for (after = categoryEnd(input, name, after);; after++) {
1353
+ let next = input.peek(after);
1354
+ if (next == 123 /* Ch.BraceOpen */)
1355
+ return true;
1356
+ if (next < 0 || next == 10 /* Ch.Newline */)
1357
+ return false;
1358
+ }
1359
+ }
1360
+ // The characters that quantify, combine and anchor in a regex.
1361
+ function isRegexOperator(ch) {
1362
+ 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 */ ||
1363
+ ch == 126 /* Ch.Tilde */ || ch == 37 /* Ch.Percent */;
1364
+ }
1365
+ // The offset after the `<...>` at the current position in a regex.
1366
+ // When it is not closed on its line, this is the negated offset of the
1367
+ // end of the text that was gone over to find that out.
1368
+ function assertionEnd(input) {
1369
+ for (let pos = 1, depth = 1;;) {
1370
+ let ch = input.peek(pos);
1371
+ if (ch < 0 || ch == 10 /* Ch.Newline */)
1372
+ return -pos;
1373
+ if (ch == 92 /* Ch.Backslash */) {
1374
+ pos += input.peek(pos + 1) == 10 /* Ch.Newline */ || input.peek(pos + 1) < 0 ? 1 : 2;
1375
+ }
1376
+ else if (ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */) {
1377
+ let end = quotedEnd(input, pos);
1378
+ pos = end < 0 ? pos + 1 : end;
1379
+ }
1380
+ else if (ch == 91 /* Ch.BracketOpen */) {
1381
+ // The brackets of a character class can hold a `>` and a `}`,
1382
+ // and can span lines.
1383
+ let end = pos + 1;
1384
+ while (input.peek(end) != 93 /* Ch.BracketClose */ && input.peek(end) >= 0)
1385
+ end += input.peek(end) == 92 /* Ch.Backslash */ ? 2 : 1;
1386
+ pos = input.peek(end) == 93 /* Ch.BracketClose */ ? end + 1 : pos + 1;
1387
+ }
1388
+ else if (ch == 123 /* Ch.BraceOpen */) {
1389
+ // So can a block of code: <?{ $x > 1 }>
1390
+ let end = pos + 1;
1391
+ for (let braces = 1; braces > 0; end++) {
1392
+ let inner = input.peek(end);
1393
+ if (inner < 0 || inner == 10 /* Ch.Newline */)
1394
+ return -pos;
1395
+ if (inner == 123 /* Ch.BraceOpen */)
1396
+ braces++;
1397
+ else if (inner == 125 /* Ch.BraceClose */)
1398
+ braces--;
1399
+ }
1400
+ pos = end;
1401
+ }
1402
+ else if (ch == 60 /* Ch.Less */) {
1403
+ depth++;
1404
+ pos++;
1405
+ }
1406
+ else if (ch == 62 /* Ch.Greater */) {
1407
+ pos++;
1408
+ if (--depth == 0)
1409
+ return pos;
1410
+ }
1411
+ else {
1412
+ pos++;
1413
+ }
1414
+ }
1415
+ }
1416
+ // The pieces of the body of a token, rule or regex declaration. The
1417
+ // context tells whether the position is in such a body, and whether it
1418
+ // is in a block of code there, which is left to the other tokenizers.
1419
+ const regexToken = new lr.ExternalTokenizer((input, stack) => {
1420
+ let current = context(stack), { regex } = current, next = input.next;
1421
+ if (!regex || regex.braces > 0) {
1422
+ // At the start of the parse of the inside of a regex literal, the
1423
+ // opening delimiter: `/`, or a quote word with its adverbs: rx:i/
1424
+ if (current == startContext && stack.canShift(regexLitOpen)) {
1425
+ let opening = regexOpening(input);
1426
+ if (opening)
1427
+ input.acceptToken(regexLitOpen, opening.start);
1428
+ return;
1429
+ }
1430
+ // Outside of a regex, or in a block of code in one, where another
1431
+ // regex can be declared. An empty body, `{}`, has no regex.
1432
+ if (next >= 0 && next != 125 /* Ch.BraceClose */ && stack.canShift(regexStart))
1433
+ input.acceptToken(regexStart);
774
1434
  return;
775
- let end = regexEnd(input, 0, 123 /* Ch.BraceOpen */, 125 /* Ch.BraceClose */, 1);
776
- if (end < 0) {
777
- // Not closed: the rest of the input.
778
- skipToEnd(input);
779
- if (input.pos > stack.pos)
780
- input.acceptToken(regexBody);
781
1435
  }
782
- else if (end > 0) {
783
- input.acceptToken(regexBody, end);
1436
+ let { literalEnd } = regex;
1437
+ if (literalEnd >= 0) {
1438
+ // A literal ends at its closing delimiter. The rest of what is
1439
+ // parsed, which for s/a/b/ includes the replacement, is one token.
1440
+ if (next < 0 || input.pos >= literalEnd) {
1441
+ skipToEnd(input);
1442
+ return input.acceptToken(regexLitClose);
1443
+ }
1444
+ }
1445
+ else if (next < 0 || next == 125 /* Ch.BraceClose */ || next == 10 /* Ch.Newline */ && startsRegexDeclaration(input, 1)) {
1446
+ // The body ends at its closing brace. One that is not closed ends
1447
+ // before the next regex declaration, which a body does not hold, so
1448
+ // that the declarations after it are still found.
1449
+ return input.acceptToken(regexBodyEnd);
784
1450
  }
1451
+ // A block of code, and an escape, are tokens of the grammar. An
1452
+ // escape does not take a line break, where the check above is made.
1453
+ if (next == 123 /* Ch.BraceOpen */)
1454
+ return;
1455
+ if (next == 92 /* Ch.Backslash */ && input.peek(1) >= 0 && input.peek(1) != 10 /* Ch.Newline */)
1456
+ return;
1457
+ // How far a piece of a literal can go: up to its closing delimiter.
1458
+ // The pieces are read by other rules than the ones that found that
1459
+ // delimiter, and where the two disagree, the delimiter wins. A piece
1460
+ // that would go over it is text.
1461
+ let limit = literalEnd < 0 ? Infinity : literalEnd - input.pos;
1462
+ if (next == 35 /* Ch.Hash */) {
1463
+ // An embedded comment, #`( ... ), or one that runs to the end of the line.
1464
+ let end = embeddedCommentEnd(input, 0);
1465
+ if (end > 0)
1466
+ return input.acceptToken(regexBlockComment, end);
1467
+ skipLine(input);
1468
+ return input.acceptToken(regexComment);
1469
+ }
1470
+ if (next == 39 /* Ch.Apostrophe */ || next == 34 /* Ch.DoubleQuote */) {
1471
+ let end = quotedEnd(input, 0);
1472
+ if (end > 0 && end <= limit)
1473
+ return input.acceptToken(regexQuote, end);
1474
+ }
1475
+ else if (next == 60 /* Ch.Less */ || next == 62 /* Ch.Greater */ || next == 171 /* Ch.GuillemetOpen */ || next == 187 /* Ch.GuillemetClose */ ||
1476
+ next == 41 /* Ch.ParenClose */ && input.peek(1) == 62 /* Ch.Greater */) {
1477
+ // Word boundaries and capture markers stand alone: << >> « » <( )>
1478
+ let after = input.peek(1);
1479
+ if (next != 60 /* Ch.Less */ || after == 60 /* Ch.Less */ || after == 40 /* Ch.ParenOpen */) {
1480
+ let size = next == 171 /* Ch.GuillemetOpen */ || next == 187 /* Ch.GuillemetClose */ ? 1 : 2;
1481
+ if (next != 62 /* Ch.Greater */ || after == 62 /* Ch.Greater */)
1482
+ return input.acceptToken(regexOperator, size);
1483
+ }
1484
+ else {
1485
+ let end = assertionEnd(input);
1486
+ if (end > limit)
1487
+ return input.acceptToken(regexText, 1);
1488
+ if (end > 0) {
1489
+ // <[a..z]>, <-[a]>, <+alpha-[b]>, <?[c]>
1490
+ let kind = after == 63 /* Ch.Question */ || after == 33 /* Ch.Bang */ ? input.peek(2) : after;
1491
+ let isClass = kind == 91 /* Ch.BracketOpen */ || kind == 45 /* Ch.Hyphen */ || kind == 43 /* Ch.Plus */;
1492
+ return input.acceptToken(isClass ? CharacterClass : Assertion, end);
1493
+ }
1494
+ // What is not closed is text, up to the brace that closes the
1495
+ // body if there is one on the line.
1496
+ let stop = 1;
1497
+ while (stop < -end && input.peek(stop) != 125 /* Ch.BraceClose */)
1498
+ stop++;
1499
+ return input.acceptToken(regexText, stop);
1500
+ }
1501
+ }
1502
+ else if (next == 36 /* Ch.Dollar */ || next == 64 /* Ch.At */) {
1503
+ let after = input.peek(1);
1504
+ // A named capture: $<name>
1505
+ if (next == 36 /* Ch.Dollar */ && after == 60 /* Ch.Less */) {
1506
+ let end = nameEnd(input, 2);
1507
+ if (end > 0 && input.peek(end) == 62 /* Ch.Greater */)
1508
+ return input.acceptToken(regexCapture, end + 1);
1509
+ }
1510
+ // A variable is a token of the grammar: $x, $0, $/, @list, $!attr, $*dynamic
1511
+ // Not the `$` before the delimiter that closes a literal: /a$/
1512
+ if (limit != 1) {
1513
+ if (isIdentifierStart(after) || next == 36 /* Ch.Dollar */ && (isDigit(after) || after == 47 /* Ch.Slash */))
1514
+ return;
1515
+ if ((after == 33 /* Ch.Bang */ || after == 46 /* Ch.Dot */ || after == 42 /* Ch.Star */ || after == 63 /* Ch.Question */) &&
1516
+ isIdentifierStart(input.peek(2)))
1517
+ return;
1518
+ }
1519
+ // Otherwise `$` and `$$` anchor.
1520
+ if (next == 36 /* Ch.Dollar */) {
1521
+ while (input.next == 36 /* Ch.Dollar */ && input.pos != literalEnd)
1522
+ input.advance();
1523
+ return input.acceptToken(regexOperator);
1524
+ }
1525
+ }
1526
+ else if (isRegexOperator(next)) {
1527
+ while (isRegexOperator(input.next) && input.pos != literalEnd)
1528
+ input.advance();
1529
+ return input.acceptToken(regexOperator);
1530
+ }
1531
+ // Text, up to where one of the above may apply.
1532
+ for (;;) {
1533
+ input.advance();
1534
+ let ch = input.next;
1535
+ if (ch < 0 || input.pos == literalEnd ||
1536
+ ch == 10 /* Ch.Newline */ || ch == 92 /* Ch.Backslash */ || ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */ ||
1537
+ ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */ || ch == 171 /* Ch.GuillemetOpen */ || ch == 187 /* Ch.GuillemetClose */ ||
1538
+ ch == 41 /* Ch.ParenClose */ && input.peek(1) == 62 /* Ch.Greater */ ||
1539
+ ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ || ch == 35 /* Ch.Hash */ || ch == 36 /* Ch.Dollar */ ||
1540
+ ch == 64 /* Ch.At */ || isRegexOperator(ch))
1541
+ break;
1542
+ }
1543
+ input.acceptToken(regexText);
785
1544
  });
786
1545
  // ---- Names ----
787
1546
  // The dot of a method call, with its optional `?`, `+`, `*`, `^` or `&`
@@ -802,20 +1561,32 @@ const methodDotToken = new lr.ExternalTokenizer((input, stack) => {
802
1561
  return;
803
1562
  input.acceptToken(methodDot, size);
804
1563
  });
805
- // The offset after an operator name's `:<...>` part, as in infix:<+>
806
- // and term:sym<x>, or `pos` when there is none there.
807
- function categoryEnd(input, pos) {
1564
+ // The offset after an operator name's `:<...>` part, as in infix:<+>,
1565
+ // circumfix:<[ ]>, infix:['+'] and term:sym<x>, or `pos` when there is
1566
+ // none there. The name before it runs from `nameStart` to `pos`.
1567
+ function categoryEnd(input, nameStart, pos) {
808
1568
  if (input.peek(pos) != 58 /* Ch.Colon */)
809
1569
  return pos;
810
1570
  let open = pos + 1;
811
1571
  if (word(input, open, open + 3) == "sym")
812
1572
  open += 3;
813
- let close = input.peek(open) == 60 /* Ch.Less */ ? 62 /* Ch.Greater */ : input.peek(open) == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : -1;
1573
+ let first = input.peek(open);
1574
+ if (first == 91 /* Ch.BracketOpen */) {
1575
+ // Only a quoted operator: ['+']
1576
+ let quote = input.peek(open + 1);
1577
+ if (quote != 39 /* Ch.Apostrophe */ && quote != 34 /* Ch.DoubleQuote */)
1578
+ return pos;
1579
+ let end = quotedEnd(input, open + 1);
1580
+ return end > 0 && input.peek(end) == 93 /* Ch.BracketClose */ ? end + 1 : pos;
1581
+ }
1582
+ let close = first == 60 /* Ch.Less */ ? 62 /* Ch.Greater */ : first == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : -1;
814
1583
  if (close < 0)
815
1584
  return pos;
1585
+ // The two halves of a circumfix are separated by one space.
1586
+ let spaces = /circumfix$/.test(word(input, nameStart, pos)) ? 1 : 0;
816
1587
  for (let i = open + 1;; i++) {
817
1588
  let ch = input.peek(i);
818
- if (ch < 0 || isSpace(ch))
1589
+ if (ch < 0 || isSpace(ch) && (ch != 32 /* Ch.Space */ || i == open + 1 || --spaces < 0))
819
1590
  return pos;
820
1591
  // The operator itself can be `>`, so the last closer before a break counts.
821
1592
  if (ch == close && !(input.peek(i + 1) == close))
@@ -836,7 +1607,7 @@ const nameToken = new lr.ExternalTokenizer((input, stack) => {
836
1607
  input.acceptToken(MethodName, end);
837
1608
  return;
838
1609
  }
839
- end = categoryEnd(input, end);
1610
+ end = categoryEnd(input, mark, end);
840
1611
  if (!mark && stack.canShift(declaredName))
841
1612
  input.acceptToken(declaredName, end);
842
1613
  else if (stack.canShift(declaredMethodName))
@@ -844,12 +1615,20 @@ const nameToken = new lr.ExternalTokenizer((input, stack) => {
844
1615
  });
845
1616
  // The type smiley in Int:D, Str:U and Any:_. It has to touch the type
846
1617
  // name, and must not be the start of a longer pair such as :Default.
1618
+ //
1619
+ // A type name without a smiley ends in an empty token. Without it, the
1620
+ // parser has to read the token after the name to know that the name is
1621
+ // complete, and when a long comment is in between, it records that as
1622
+ // a lookahead, which keeps the tokens before it from being reused.
847
1623
  const smileyToken = new lr.ExternalTokenizer((input, stack) => {
848
- if (input.next != 58 /* Ch.Colon */ || !stack.canShift(smiley) || !continuesName(input, -1))
1624
+ if (!stack.canShift(noSmiley))
849
1625
  return;
850
- let kind = input.peek(1);
851
- if ((kind == 68 /* Ch.D */ || kind == 85 /* Ch.U */ || kind == 95 /* Ch.Underscore */) && !continuesName(input, 2))
852
- input.acceptToken(smiley, 2);
1626
+ if (input.next == 58 /* Ch.Colon */) {
1627
+ let kind = input.peek(1);
1628
+ if ((kind == 68 /* Ch.D */ || kind == 85 /* Ch.U */ || kind == 95 /* Ch.Underscore */) && !continuesName(input, 2))
1629
+ return input.acceptToken(smiley, 2);
1630
+ }
1631
+ input.acceptToken(noSmiley, 0);
853
1632
  });
854
1633
  // v6, v6.d, v1.2.3, v1.2+, v1.*. A name such as v8-engine is not a version.
855
1634
  const versionToken = new lr.ExternalTokenizer((input, stack) => {
@@ -884,27 +1663,27 @@ const versionToken = new lr.ExternalTokenizer((input, stack) => {
884
1663
  });
885
1664
 
886
1665
  // This file was generated by lezer-generator. You probably shouldn't edit it.
887
- const spec_identifier = {__proto__:null,class:42, role:44, grammar:46, module:48, package:50, sub:64, method:68, submethod:70, token:76, rule:78, regex:80, enum:88, subset:94, constant:100, my:126, our:128, has:130, state:132, temp:134, let:136, anon:138, augment:140, supersede:142, unit:144, multi:146, proto:148, only:150, if:152, elsif:154, else:156, unless:158, with:160, orwith:162, without:164, for:166, while:168, until:170, loop:172, repeat:174, given:176, when:178, default:180, do:182, gather:184, take:186, try:188, return:190, next:192, last:194, redo:196, proceed:198, succeed:200, react:202, whenever:204, supply:206, emit:208, start:210, use:212, need:214, import:216, require:218, no:220, is:222, does:224, of:226, returns:228, handles:230, where:232, will:234, trusts:236, hides:238, and:240, or:242, not:244, xor:246, so:248, andthen:250, orelse:252, notandthen:254, div:256, mod:258, gcd:260, lcm:262, eq:264, ne:266, lt:268, gt:270, le:272, ge:274, cmp:276, leg:278, eqv:280, but:282, self:284};
888
- const spec_capIdentifier = {__proto__:null,True:286, False:288, Nil:290, BEGIN:292, CHECK:294, INIT:296, END:298, ENTER:300, LEAVE:302, KEEP:304, UNDO:306, FIRST:308, NEXT:310, LAST:312, PRE:314, POST:316, CATCH:318, CONTROL:320, QUIT:322, CLOSE:324, DOC:326};
1666
+ const spec_identifier = {__proto__:null,class:80, role:82, grammar:84, module:86, package:88, sub:102, method:106, submethod:108, token:116, rule:118, regex:120, enum:140, subset:146, constant:152, my:170, our:172, has:174, state:176, temp:178, let:180, anon:182, augment:184, supersede:186, unit:188, multi:190, proto:192, only:194, if:196, elsif:198, else:200, unless:202, with:204, orwith:206, without:208, for:210, while:212, until:214, loop:216, repeat:218, given:220, when:222, default:224, do:226, gather:228, take:230, try:232, return:234, next:236, last:238, redo:240, proceed:242, succeed:244, react:246, whenever:248, supply:250, emit:252, start:254, use:256, need:258, import:260, require:262, no:264, is:266, does:268, of:270, returns:272, handles:274, where:276, will:278, trusts:280, hides:282, and:284, or:286, not:288, xor:290, so:292, andthen:294, orelse:296, notandthen:298, div:300, mod:302, gcd:304, lcm:306, eq:308, ne:310, lt:312, gt:314, le:316, ge:318, cmp:320, leg:322, eqv:324, but:326, self:328};
1667
+ const spec_capIdentifier = {__proto__:null,True:330, False:332, Nil:334, BEGIN:336, CHECK:338, INIT:340, END:342, ENTER:344, LEAVE:346, KEEP:348, UNDO:350, FIRST:352, NEXT:354, LAST:356, PRE:358, POST:360, CATCH:362, CONTROL:364, QUIT:366, CLOSE:368, DOC:370};
889
1668
  const parser$1 = lr.LRParser.deserialize({
890
1669
  version: 14,
891
- states: "*hQfQDTOOO*kQDTO'#ClO*rQDTO'#CoO*yQDTO'#CyO+QQ7sO'#DbOOQ-w'#Df'#DfO+VQDuO'#DgOOQ-w'#Di'#DiO5fO!0bO'#DiOOQ-w'#G]'#G]OOQ-w'#G['#G[OOQ-w'#Fz'#FzQfQDTOOO>rQDeO'#CpO>yQDeO'#C{O?QQDeO'#C{OHZQDeO'#DROHeQDeO'#DXO!#yQDeO'#D[O!-_QDeO'#D_OOQ-w'#Gb'#GbOOQ-w,59W,59WO!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!Q!]!gRw]dYOPQR[fhjm!]Yu]^_wzR!atRz^Rz_R!Q`Q!P`S!d|!QR!j!gR!SaR!UbR!WcQ[OQfPQhQQjRYq[fhj!]R!]mYt]^_wzQ|`U!`t|!gR!g!QQoWR!^oeZOPQR[fhjm!]dYOPQR[fhjm!]es]^_`twz|!Q!gQv]Sy^_Q!bwR!cz",
894
- nodeNames: "⚠ BlockComment Pod Heredoc . MethodName Version Regex Regex Operator LineComment DocComment Program Number ) ( Parens ] [ Brackets PackageDeclaration class role grammar module package PackageName } { Block ; RoutineDeclaration sub RoutineName method submethod RoutineName RegexDeclaration token rule regex RegexName Block EnumDeclaration enum EnumName SubsetDeclaration subset SubsetName ConstantDeclaration constant ConstantName MethodCall VariableName AttributeName SpecialVariable Identifier TypeName Number StringLiteral Escape 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 , : .",
895
- maxTerm: 190,
1670
+ states: ".WQfQDdOOO*zO#tOOO+POWOOO+UO,UOOO+uOSO'#C{O,PQDdO'#DPO,WQDdO'#DSO,_QDdO'#D^OOQ.W'#Df'#DfO,fQDdO'#D`O5zQ8WO'#D|OOQ.W'#D}'#D}O6PQ7gO'#EOOOQ.W'#EQ'#EQO7SO!0jO'#EQOOQ.W'#HS'#HSOOQ.W'#HR'#HROOQ.W'#Ge'#GeQfQDdOOO7ZQEUO'#DTO7bQEUO'#D`O7iQEUO'#D`OARQEUO'#DgOA]QEUO'#DsOKQQEUO'#DvO!&uQEUO'#DyOOQ.W'#HZ'#HZO!0jO!!^OOO!1hO!0jOOOOOS'#Gf'#GfO!1oOSO,59gOOQ.W,59g,59gOOQ.W,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r+QP+m+{P,RP&P!P_OTUVXbcdefqsuw|!U!W!Y!^!e!s!|#O!O_OTUVXbcdefqsuw|!U!W!Y!^!e!s!|#OX}^l!P!jR!Uch`OTUVbqsu|!e!s#O[xXcde!U!WR!qwR!WdR!We!PXOTUVXbcdefqsuw|!U!W!Y!^!e!s!|#OR!^fQ!]fS!x!Y!^R#U!|R!{![X!fk!h!y#RR!`gR!bhR!diQbOQqTQsUQuV[!Rbqsu!s#OQ!s|R#O!eQnSR!kn[wXcde!U!WQ!YfU!pw!Y!|R!|!^Q!hkS#P!h#RR#R!yQ!P^Q!jlT!t!P!jiaOTUVbqsu|!e!s#Oh`OTUVbqsu|!e!s#OgvXcdefw!U!W!Y!^!|UyXdeQ!TcQ!v!UR!w!WX!gk!h!y#RX!O^l!P!j",
1673
+ nodeNames: "⚠ BlockComment PodDirective PodDirective PodDirective PodHeading PodStrong PodEmphasis PodCode PodLink PodFormat Heredoc Heredoc . MethodName Version CharacterClass Assertion StringLiteral Operator LineComment BlockComment VariableName StringLiteral Regex Regex Operator 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 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",
1674
+ maxTerm: 229,
896
1675
  context: trackContext,
897
1676
  nodeProps: [
898
- ["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odyToken, quoteToken, termToken, 0, 1],
905
- topRules: {"Program":[0,12]},
906
- specialized: [{term: 186, get: (value) => spec_identifier[value] || -1},{term: 188, get: (value) => spec_capIdentifier[value] || -1}],
907
- tokenPrec: 3609
1680
+ skippedNodes: [0,1,11,12,28,29],
1681
+ repeatNodeCount: 5,
1682
+ tokenData: "!$`~R!aX^%Wpq%Wqr%{st']tu(|uv5Rvw8axy:Wyz:]z{%{{|%{|}:b}!O%{!O!P:g!P!Q%{!Q!R;V!R![=f![!]@Z!]!^FQ!^!_%{!_!`%{!`!a%{!a!b%{!b!cFV!c!}Gy!}#OJu#O#PJz#P#Q! T#Q#R%{#R#S! Y#T#o! Y#o#p!$U#p#q%{#q#r!$Z#r#s%{#y#z%W$f$g%W$p$q! Y$q$r%{${$|! Y%Q%R! Y%R%S%{%W%o! Y%o%p%{%p&a! Y&a&b%{&b#BY! Y#BY#BZ%W#BZ$IS! Y$IS$I_%W$Iz$I{%{$I|$JO%W$JT$JU%W$KV$KW%W%&Y%+t%{&/x&Et! Y&FU&FV%W&Gh;'S! Y;'S;=`!#x?&r?Bj! Y?Hw?Ic! Y?Ii?JT! Y?J`?L{! Y~%]Y%t~X^%Wpq%W#y#z%W$f$g%W#BY#BZ%W$IS$I_%W$I|$JO%W$JT$JU%W$KV$KW%W&FU&FV%WP&Qc%QPqr%{z{%{{|%{}!O%{!P!Q%{!^!_%{!_!`%{!`!a%{!a!b%{#O#P%{#Q#R%{#p#q%{#r#s%{$q$r%{%R%S%{%o%p%{&a&b%{$Iz$I{%{%&Y%+t%{~'bWl~OY'zZ!_'z!_!`(c!`#p'z#p#q(c#q;'S'z;'S;=`(]<%lO'z~(PSl~OY'zZ;'S'z;'S;=`(]<%lO'z~(`P;=`<%l'z~(jSm~l~OY(cZ;'S(c;'S;=`(v<%lO(c~(yP;=`<%l(c~)Rk%|~qr*vz{.|!O!P-h!P!Q1x!Q![1}![!]2V!_!`.|!a!b.|!c!}3_#Q#R2V#R#S3_#T#o3_#r#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Token, nameToken, versionToken, regexToken, quoteToken, termToken, 0, 1],
1684
+ topRules: {"Program":[0,30],"Regex":[1,190],"Heredoc":[2,191],"StringLiteral":[3,192]},
1685
+ specialized: [{term: 223, get: (value) => spec_identifier[value] || -1},{term: 226, get: (value) => spec_capIdentifier[value] || -1}],
1686
+ tokenPrec: 3469
908
1687
  });
909
1688
 
910
1689
  // The keywords of the grammar, with the tag each is highlighted with.
@@ -923,6 +1702,279 @@ const keywordTags = {
923
1702
  self: highlight.tags.self
924
1703
  };
925
1704
 
1705
+ const scopes = new common.NodeWeakMap();
1706
+ const scopeNodes = /^(Block|Interpolation|Program)$/;
1707
+ const variableNodes = /^(VariableName|AttributeName)$/;
1708
+ const declarators = /^(my|our|has|state)$/;
1709
+ /// Whether a variable is a placeholder, which is declared by being
1710
+ /// used: $^a, and the named $:a
1711
+ function isPlaceholder(name) { return /^[$@%&][\^:]/.test(name); }
1712
+ // The name of the variable without a sigil that the backslash `node`
1713
+ // comes right before, as in `\x`. A capitalized one reads as a type.
1714
+ function sigillessName(state, node) {
1715
+ let next = node.nextSibling;
1716
+ return node.name == "Operator" && next && (next.name == "Identifier" || next.name == "TypeName") &&
1717
+ next.from == node.to && state.sliceDoc(node.from, node.to) == "\\" ? next : null;
1718
+ }
1719
+ // Whether a block is a subscript, as in %h{$key}: it touches the term
1720
+ // before it. It is not a scope for placeholder variables.
1721
+ function isSubscript(block) {
1722
+ let prev = block.prevSibling;
1723
+ return block.name == "Block" && prev != null && prev.to == block.from && /^[A-Z]/.test(prev.name) && prev.name != "Operator";
1724
+ }
1725
+ /// Whether a completion is for a name with a sigil.
1726
+ function hasSigil(completion) { return /^[$@%&]/.test(completion.label); }
1727
+ function variable(label) {
1728
+ return { label, type: label[0] == "&" ? "function" : /^.[!.]/.test(label) ? "property" : "variable", boost: 1 };
1729
+ }
1730
+ function isArrow(text) { return text == "->" || text == "<->"; }
1731
+ class Gatherer {
1732
+ constructor(state) {
1733
+ this.state = state;
1734
+ this.names = [];
1735
+ this.methods = [];
1736
+ }
1737
+ text(node) { return this.state.sliceDoc(node.from, node.to); }
1738
+ declare(node) {
1739
+ let label = this.text(node);
1740
+ // A name without a sigil: my \x
1741
+ if (!variableNodes.test(node.name))
1742
+ return this.names.push({ label, type: "variable", boost: 1 });
1743
+ this.names.push(variable(label));
1744
+ // `has $.x` also makes the private `$!x`, and `$^a` can be written `$a`.
1745
+ if (label[1] == ".")
1746
+ this.names.push(variable(label[0] + "!" + label.slice(2)));
1747
+ else if (isPlaceholder(label))
1748
+ this.names.push(variable(label[0] + label.slice(2)));
1749
+ }
1750
+ // Declares the name after `node`, when `node` is the backslash of a
1751
+ // variable without a sigil: my \x = 1, sub f(\x) { }
1752
+ declareSigilless(node) {
1753
+ let name = sigillessName(this.state, node);
1754
+ if (name)
1755
+ this.declare(name);
1756
+ return name != null;
1757
+ }
1758
+ // The variables of a signature, or of the parentheses of `my (...)`.
1759
+ // What follows a `=` or a `where`, up to the next comma, is a default
1760
+ // value or a constraint, and uses variables rather than declaring them.
1761
+ declareAll(node) {
1762
+ let uses = false;
1763
+ for (let child = node.firstChild; child; child = child.nextSibling) {
1764
+ let { name } = child;
1765
+ if (name == ",")
1766
+ uses = false;
1767
+ else if (name == "where" || name == "Operator" && this.text(child) == "=")
1768
+ uses = true;
1769
+ else if (uses)
1770
+ continue;
1771
+ else if (this.declareSigilless(child))
1772
+ continue;
1773
+ else if (variableNodes.test(name))
1774
+ this.declare(child);
1775
+ else if (name == "Parens" || name == "Brackets")
1776
+ this.declareAll(child);
1777
+ }
1778
+ }
1779
+ addMethods(scope) {
1780
+ for (let method of scopeOf(scope, this.state).methods)
1781
+ this.methods.push(method);
1782
+ }
1783
+ // Goes over the content of a node that is not a scope of its own.
1784
+ content(node) {
1785
+ // Whether a declarator was seen, and what it declares is yet to come.
1786
+ let declaring = false;
1787
+ for (let child = node.firstChild; child; child = child.nextSibling) {
1788
+ let { name } = child;
1789
+ if (declarators.test(name)) {
1790
+ declaring = true;
1791
+ continue;
1792
+ }
1793
+ // my Int $x, my Array[Int] @y
1794
+ if (declaring && (name == "TypeName" || name == "Brackets"))
1795
+ continue;
1796
+ // A placeholder variable declares itself where it is used: { $^a + $^b }
1797
+ if (name == "VariableName" && isPlaceholder(this.text(child)))
1798
+ this.declare(child);
1799
+ else if (declaring && this.declareSigilless(child))
1800
+ continue;
1801
+ else if (declaring && variableNodes.test(name))
1802
+ this.declare(child);
1803
+ else if (declaring && name == "Parens")
1804
+ this.declareAll(child);
1805
+ else if (scopeNodes.test(name)) {
1806
+ // The placeholders in a subscript are those of the block around it.
1807
+ if (isSubscript(child))
1808
+ this.placeholders(child);
1809
+ this.addMethods(child);
1810
+ }
1811
+ else if (/Declaration$/.test(name))
1812
+ this.declaration(child);
1813
+ else if (child.firstChild)
1814
+ this.content(child);
1815
+ // The name of a constant with a sigil is a variable after the
1816
+ // declaration node: constant $LIMIT = 3
1817
+ declaring = name == "ConstantDeclaration" && child.lastChild.name == "constant";
1818
+ }
1819
+ }
1820
+ // The placeholder variables in a node, and in the subscripts in it.
1821
+ placeholders(node) {
1822
+ for (let child = node.firstChild; child; child = child.nextSibling) {
1823
+ if (child.name == "VariableName") {
1824
+ if (isPlaceholder(this.text(child)))
1825
+ this.declare(child);
1826
+ }
1827
+ else if (child.firstChild && (!scopeNodes.test(child.name) || isSubscript(child)))
1828
+ this.placeholders(child);
1829
+ }
1830
+ }
1831
+ declaration(node) {
1832
+ let kind = node.firstChild.name;
1833
+ for (let child = node.firstChild; child; child = child.nextSibling) {
1834
+ let { name } = child;
1835
+ if (name == "RoutineName") {
1836
+ let label = this.text(child);
1837
+ // An operator is not called by its name: infix:<+>
1838
+ if (/:[<«\[]/.test(label))
1839
+ continue;
1840
+ // `multi foo` has no declarator, and declares a sub.
1841
+ if (kind == "sub" || kind == "RoutineName")
1842
+ this.names.push({ label, type: "function", boost: 1 }, variable("&" + label));
1843
+ // A private method is called as self!name, where nothing is completed.
1844
+ else if (/^[^!^]/.test(label))
1845
+ this.methods.push({ label, type: "method", boost: 1 });
1846
+ }
1847
+ else if (name == "PackageName") {
1848
+ this.names.push({ label: this.text(child), type: "class", boost: 1 });
1849
+ }
1850
+ else if (name == "EnumName" || name == "SubsetName") {
1851
+ this.names.push({ label: this.text(child), type: "type", boost: 1 });
1852
+ }
1853
+ else if (name == "ConstantName") {
1854
+ let label = this.text(child);
1855
+ this.names.push(/^[$@%&]/.test(label) ? variable(label) : { label, type: "constant", boost: 1 });
1856
+ }
1857
+ else if (scopeNodes.test(name)) {
1858
+ this.addMethods(child);
1859
+ }
1860
+ else if (name != "Parens" && child.firstChild) {
1861
+ // The signature belongs to the scope of the body.
1862
+ this.content(child);
1863
+ }
1864
+ }
1865
+ }
1866
+ // The parameters of a block: those of the routine that it is the body
1867
+ // of, or the ones after the arrow of a pointy block.
1868
+ parameters(block) {
1869
+ let parent = block.parent;
1870
+ if (parent && parent.name == "RoutineDeclaration") {
1871
+ for (let child = parent.firstChild; child; child = child.nextSibling)
1872
+ if (child.name == "Parens")
1873
+ this.declareAll(child);
1874
+ return;
1875
+ }
1876
+ // Going backwards, the variables of a parameter come before the
1877
+ // `=` of its default value.
1878
+ let found = [], parameter = [];
1879
+ for (let prev = block.prevSibling; prev; prev = prev.prevSibling) {
1880
+ let { name } = prev;
1881
+ if (name == ";" || name == "Block" || /Declaration$/.test(name))
1882
+ return;
1883
+ if (name == "VariableName") {
1884
+ parameter.push(prev);
1885
+ }
1886
+ else if (prev.prevSibling && sigillessName(this.state, prev.prevSibling)) {
1887
+ // -> \item { }
1888
+ parameter.push(prev);
1889
+ }
1890
+ else if (name == ",") {
1891
+ found = found.concat(parameter);
1892
+ parameter = [];
1893
+ }
1894
+ else if (name == "Operator") {
1895
+ let text = this.text(prev);
1896
+ if (text == "=")
1897
+ parameter = [];
1898
+ else if (isArrow(text)) {
1899
+ for (let node of found.concat(parameter))
1900
+ this.declare(node);
1901
+ return;
1902
+ }
1903
+ }
1904
+ }
1905
+ }
1906
+ }
1907
+ // The names that the scope node `node` declares in its content. The
1908
+ // parameters of a block are not part of its node, and are left out.
1909
+ function scopeOf(node, state) {
1910
+ let scope = scopes.get(node);
1911
+ if (scope)
1912
+ return scope;
1913
+ let gatherer = new Gatherer(state);
1914
+ gatherer.content(node);
1915
+ scope = { names: gatherer.names, methods: gatherer.methods };
1916
+ scopes.set(node, scope);
1917
+ return scope;
1918
+ }
1919
+ /// The names that are in scope at `node`, innermost scope first, and
1920
+ /// the methods of the whole document.
1921
+ function localNames(node, state) {
1922
+ let names = [], methods = [];
1923
+ for (let cur = node; cur; cur = cur.parent) {
1924
+ if (!scopeNodes.test(cur.name))
1925
+ continue;
1926
+ let scope = scopeOf(cur, state);
1927
+ // An edit to the parameters does not replace the block's node, so
1928
+ // these are read every time.
1929
+ let parameters = new Gatherer(state);
1930
+ parameters.parameters(cur);
1931
+ for (let name of parameters.names)
1932
+ names.push(name);
1933
+ for (let name of scope.names)
1934
+ names.push(name);
1935
+ methods = scope.methods;
1936
+ }
1937
+ return { names, methods };
1938
+ }
1939
+ /// Whether a variable is in a place where variables are declared, so
1940
+ /// that its name is a new one. The variable is a child of `parent`, and
1941
+ /// comes after the sibling `prev`.
1942
+ function declaresVariable(state, parent, prev) {
1943
+ let text = (node) => state.sliceDoc(node.from, node.to);
1944
+ // A signature, or the list of `my ($a, $b)`, unless the variable is
1945
+ // in a default value or in a constraint.
1946
+ if (parent.name == "Parens") {
1947
+ let before = parent.prevSibling;
1948
+ if (parent.parent && parent.parent.name == "RoutineDeclaration" || before && declarators.test(before.name)) {
1949
+ for (let node = prev; node && node.name != ","; node = node.prevSibling)
1950
+ if (node.name == "where" || node.name == "Operator" && text(node) == "=")
1951
+ return false;
1952
+ return true;
1953
+ }
1954
+ }
1955
+ // After a declarator, or after the arrow of a pointy block.
1956
+ let first = true;
1957
+ for (let node = prev; node; node = node.prevSibling) {
1958
+ let { name } = node;
1959
+ // `my $a, $b` declares the first one only.
1960
+ if (declarators.test(name))
1961
+ return first;
1962
+ if (name == ";" || name == "Block" || name == "{" || /Declaration$/.test(name))
1963
+ return false;
1964
+ if (name == "Operator") {
1965
+ let operator = text(node);
1966
+ if (isArrow(operator))
1967
+ return true;
1968
+ if (operator == "=")
1969
+ return false;
1970
+ }
1971
+ // Only a type can stand between a declarator and its variable.
1972
+ if (name != "TypeName" && name != "Brackets")
1973
+ first = false;
1974
+ }
1975
+ return false;
1976
+ }
1977
+
926
1978
  function completions(type, ...labels) {
927
1979
  return labels.join(" ").split(" ").map(label => ({ label, type }));
928
1980
  }
@@ -939,6 +1991,7 @@ const globals = [...keywords, ...constants, ...types, ...routines];
939
1991
  // `:key` is not a name from the list.
940
1992
  const nameTail = /^(\w[\w:'\-]*)?$/;
941
1993
  const specialVariableTail = /^[$@%&][*?][\w\-]*$/;
1994
+ const variableTail = /^[$@%&][!.^:]?[\w'\-]*$/;
942
1995
  // Whether the position of `node` holds code, as opposed to the text of
943
1996
  // a string, a regex, a comment or Pod. An interpolation is code again.
944
1997
  function inCode(node) {
@@ -965,8 +2018,26 @@ function isPrivateMethodName(tree, state, node) {
965
2018
  return invocant.to == mark.from &&
966
2019
  /^(self|VariableName|AttributeName|SpecialVariable|Identifier|TypeName|Parens|Brackets|[)\]])$/.test(invocant.name);
967
2020
  }
968
- /// A completion source for Raku keywords and for the commonly used
969
- /// built-in types, routines, methods and special variables.
2021
+ // The names declared in the document, followed by the built-in ones
2022
+ // that they do not hide.
2023
+ function withLocal(local, builtin) {
2024
+ if (!local.length)
2025
+ return builtin;
2026
+ let labels = new Set(), result = [];
2027
+ for (let completion of local) {
2028
+ if (labels.has(completion.label))
2029
+ continue;
2030
+ labels.add(completion.label);
2031
+ result.push(completion);
2032
+ }
2033
+ for (let completion of builtin)
2034
+ if (!labels.has(completion.label))
2035
+ result.push(completion);
2036
+ return result;
2037
+ }
2038
+ /// A completion source for Raku keywords, for the commonly used
2039
+ /// built-in types, routines, methods and special variables, and for the
2040
+ /// names that the document declares.
970
2041
  const rakuCompletionSource = context => {
971
2042
  let { state, pos } = context, tree = language.syntaxTree(state), node = tree.resolveInner(pos, -1);
972
2043
  if (!inCode(node))
@@ -975,46 +2046,337 @@ const rakuCompletionSource = context => {
975
2046
  let special = node.name == "SpecialVariable" ? node : context.matchBefore(/[$@%&][*?]$/);
976
2047
  if (special)
977
2048
  return { from: special.from, options: specialVariables, validFor: specialVariableTail };
2049
+ // A variable, or a sigil that is about to be one. A lone `%` or `&`
2050
+ // is as often an operator, and has to be followed by a name first.
2051
+ let isVariableNode = node.name == "VariableName" || node.name == "AttributeName";
2052
+ let sigil = isVariableNode ? null : context.matchBefore(/[$@]$|[$@%&][!.^:]$/);
2053
+ if (isVariableNode || sigil) {
2054
+ let from = isVariableNode ? node.from : sigil.from;
2055
+ // A lone sigil is not a node. It lies in the node around it.
2056
+ let parent = isVariableNode ? node.parent : tree.resolveInner(from, 0);
2057
+ let prev = isVariableNode ? node.prevSibling : parent.childBefore(from);
2058
+ if (declaresVariable(state, parent, prev))
2059
+ return null;
2060
+ // A placeholder variable is declared by being used, also by the
2061
+ // one that is being typed, which is not offered for itself.
2062
+ let typed = isVariableNode ? state.sliceDoc(from, node.to) : "";
2063
+ let options = withLocal(localNames(parent, state).names.filter(hasSigil), []);
2064
+ if (isPlaceholder(typed))
2065
+ options = options.filter(completion => completion.label != typed);
2066
+ return options.length ? { from, options, validFor: variableTail } : null;
2067
+ }
2068
+ let local = localNames(node, state), localMethods = () => withLocal(local.methods, methods);
978
2069
  if (node.name == "MethodName")
979
- return { from: node.from, options: methods, validFor: nameTail };
2070
+ return { from: node.from, options: localMethods(), validFor: nameTail };
980
2071
  // A dot or `.=` with no name after it yet. Two dots are a range operator.
981
2072
  let before = state.sliceDoc(Math.max(0, pos - 2), pos);
982
2073
  if (before == ".=")
983
- return { from: pos, options: methods, validFor: nameTail };
2074
+ return { from: pos, options: localMethods(), validFor: nameTail };
984
2075
  if (/(^|[^.])\.$/.test(before)) {
985
2076
  // The dot of `1.5` and of `v6.d` is far more often typed than a
986
2077
  // method call on a number.
987
2078
  let numeric = /^(Number|Version)$/.test(tree.resolveInner(pos - 1, -1).name);
988
- return numeric && !context.explicit ? null : { from: pos, options: methods, validFor: nameTail };
2079
+ return numeric && !context.explicit ? null : { from: pos, options: localMethods(), validFor: nameTail };
989
2080
  }
2081
+ let localGlobals = () => withLocal(local.names.filter(completion => !hasSigil(completion)), globals);
990
2082
  // A keyword's node is named after the keyword, as are those of `,` and `;`.
991
2083
  let isKeyword = /^\w/.test(node.name) && node.name == state.sliceDoc(node.from, node.to);
992
2084
  if (isKeyword || node.name == "Identifier" || node.name == "TypeName") {
993
2085
  if (isPrivateMethodName(tree, state, node))
994
2086
  return null;
995
- // `$x .= trim` calls a method.
996
2087
  let prev = node.prevSibling;
2088
+ // The name of a variable without a sigil, where it is declared: my \x
2089
+ if (prev && prev.to == node.from && state.sliceDoc(prev.from, prev.to) == "\\" &&
2090
+ declaresVariable(state, node.parent, prev.prevSibling))
2091
+ return null;
2092
+ // `$x .= trim` calls a method.
997
2093
  let afterDotAssign = prev != null && prev.name == "Operator" && state.sliceDoc(prev.from, prev.to) == ".=";
998
- return { from: node.from, options: afterDotAssign ? methods : globals, validFor: nameTail };
2094
+ return { from: node.from, options: afterDotAssign ? localMethods() : localGlobals(), validFor: nameTail };
999
2095
  }
1000
- // Other names (variables, pair keys, names being declared) are made up
1001
- // by the user, so only a position where no token has been started
1002
- // gets the whole list, and only on request.
2096
+ // Other names (pair keys, names being declared) are made up by the
2097
+ // user, so only a position where no token has been started gets the
2098
+ // whole list, and only on request.
1003
2099
  if (context.explicit && /^[\s(\[{,;=]?$/.test(state.sliceDoc(Math.max(0, pos - 1), pos)))
1004
- return { from: pos, options: globals, validFor: nameTail };
2100
+ return { from: pos, options: localGlobals(), validFor: nameTail };
1005
2101
  return null;
1006
2102
  };
1007
2103
 
2104
+ // The grammar has no statement nodes, so whether a line continues the
2105
+ // statement before it is worked out here, from the token that precedes
2106
+ // the line and from what the line starts with.
2107
+ const skipped = /^(LineComment|DocComment|BlockComment|Pod|Heredoc)$/;
2108
+ const brackets = /^(Block|Parens|Brackets|Interpolation|Program)$/;
2109
+ const wordOperators = /^(and|or|xor|andthen|orelse|notandthen|div|mod|gcd|lcm|eq|ne|lt|gt|le|ge|cmp|leg|eqv|but)$/;
2110
+ // Operators that end a term or stand for a whole statement.
2111
+ const closingOperators = /^(\+\+|--|\.\.\.|!!!|\?\?\?)$/;
2112
+ // The words that start a trait. `of` is left out: it is as often a
2113
+ // name of one's own.
2114
+ const traits = "is|does|returns|handles|where|will";
2115
+ /// The lines that are indented again when they are typed: one that
2116
+ /// closes a bracket, and one that starts with a trait, which is only
2117
+ /// known to continue a statement once the trait's word is there.
2118
+ const indentOnInput = new RegExp("^\\s*(?:[\\}\\]\\)]|(?:" + traits + ")\\s)$");
2119
+ // A line that starts with an infix: an operator that has a space after
2120
+ // it and more on the line, an operator that is a word, a statement
2121
+ // modifier, or a trait (`is export`). A prefix operator touches its
2122
+ // operand, and `...` stands alone.
2123
+ const startsWithInfix = new RegExp("^\\s*(?:[~+\\-*/%<>=|&^?!]+[ \\t]+\\S|(?:" + wordOperators.source.slice(2, -2) +
2124
+ "|if|unless|for|while|until|given|when|with|without" +
2125
+ "|" + traits + ")(?![\\w'-]))");
2126
+ const startsWithMethod = /^\s*\.[^\s\d.]/;
2127
+ // The last token of `node`. A string, a regex, a heredoc and a Pod
2128
+ // block count as one token: what they end in is not code.
2129
+ const wholeTokens = /^(StringLiteral|Regex|Heredoc|Pod)$/;
2130
+ function lastToken(node) {
2131
+ while (node.lastChild && !wholeTokens.test(node.name))
2132
+ node = node.lastChild;
2133
+ return node;
2134
+ }
2135
+ // The last token that ends at or before `pos` in `bracket`, not
2136
+ // counting comments.
2137
+ function tokenBefore(bracket, pos) {
2138
+ let node = bracket.resolveInner(pos, -1);
2139
+ // Either the node that ends there, or the one around the position.
2140
+ if (node.to > pos)
2141
+ node = node.childBefore(pos);
2142
+ while (node) {
2143
+ let token = lastToken(node);
2144
+ if (!skipped.test(token.name))
2145
+ return token;
2146
+ // Go to what comes before the comment, in this node or around it.
2147
+ while (node && !node.prevSibling)
2148
+ node = node.parent;
2149
+ node = node && node.prevSibling;
2150
+ }
2151
+ return null;
2152
+ }
2153
+ function bracketAround(node) {
2154
+ for (let parent = node.parent; parent; parent = parent.parent)
2155
+ if (brackets.test(parent.name))
2156
+ return parent;
2157
+ return null;
2158
+ }
2159
+ // The bracket node whose content a token is part of. The brackets of a
2160
+ // node are part of the content around that node.
2161
+ function bracketOf(token) {
2162
+ let around = bracketAround(token);
2163
+ return around && around == token.parent && /^[()\[\]{}]$/.test(token.name) ? bracketAround(around) : around;
2164
+ }
2165
+ // The first node after `node` that is not a comment.
2166
+ function nextCode(node) {
2167
+ do
2168
+ node = node && node.nextSibling;
2169
+ while (node && skipped.test(node.name));
2170
+ return node;
2171
+ }
2172
+ // Whether a block in braces holds the pairs of a hash, in which a comma
2173
+ // separates items that line up.
2174
+ function holdsPairs(block, state) {
2175
+ let first = block.name == "Block" ? nextCode(block.firstChild) : null;
2176
+ if (!first)
2177
+ return false;
2178
+ if (first.name == "PairKey")
2179
+ return true;
2180
+ let second = nextCode(first);
2181
+ return second != null && second.name == "Operator" && state.sliceDoc(second.from, second.to) == "=>";
2182
+ }
2183
+ // Whether a line continues a statement of `bracket`. The line starts at
2184
+ // `pos` with the text `after`.
2185
+ function continuesStatement(state, bracket, pos, after) {
2186
+ // The lines of a regex are not statements: its `+` and `|` are not
2187
+ // the operators of an expression.
2188
+ for (let node = bracket.resolveInner(pos, -1); node && node.from >= bracket.from; node = node.parent) {
2189
+ if (node.name == "Regex")
2190
+ return false;
2191
+ if (brackets.test(node.name))
2192
+ break;
2193
+ }
2194
+ let before = tokenBefore(bracket, pos);
2195
+ if (!before || bracketOf(before) != bracket)
2196
+ return false;
2197
+ let name = before.name, text = state.sliceDoc(before.from, before.to);
2198
+ if (name == "Operator")
2199
+ return !closingOperators.test(text);
2200
+ if (wordOperators.test(name) && name == text)
2201
+ return true;
2202
+ if (name == ",")
2203
+ return !holdsPairs(bracket, state);
2204
+ if (name == ";" || name == "{")
2205
+ return false;
2206
+ if (name == "}") {
2207
+ // A block ends its statement. A subscript, which touches the term
2208
+ // that it follows, does not: %h{$key}
2209
+ let block = before.parent;
2210
+ return block.from > 0 && !/\s/.test(state.sliceDoc(block.from - 1, block.from)) && startsWithInfix.test(after);
2211
+ }
2212
+ // After the end of a statement, a `.` calls a method on the topic.
2213
+ return startsWithInfix.test(after) || startsWithMethod.test(after);
2214
+ }
2215
+ // Whether the content of a bracket node starts on the line of its
2216
+ // opening bracket, which `delimitedIndent` then aligns the rest with.
2217
+ function isAligned(node, state) {
2218
+ let open = node.firstChild, next = nextCode(open);
2219
+ return open != null && next != null && next != node.lastChild && next.from < state.doc.lineAt(open.from).to;
2220
+ }
2221
+ const bodyKeywords = /^(if|elsif|else|unless|with|orwith|without|for|while|until|loop|repeat|given|when|default|whenever|react|supply|gather|do|try|start)$/;
2222
+ const declarationPrefixes = /^(my|our|has|state|anon|augment|supersede|unit|multi|proto|only)$/;
2223
+ // The first node of the statement that a block is the body of, when it
2224
+ // is the body of a control statement or of a declaration. A block that
2225
+ // is a term in an expression has none: `my $f = sub { ... }`
2226
+ function statementOfBody(block, state) {
2227
+ let declaration = block.parent && /Declaration$/.test(block.parent.name) ? block.parent : null;
2228
+ let first = declaration || block;
2229
+ for (let prev = first.prevSibling; prev; prev = prev.prevSibling) {
2230
+ if (skipped.test(prev.name))
2231
+ continue;
2232
+ if (prev.name == ";" || prev.name == "{")
2233
+ break;
2234
+ // A closing brace that is followed by a line break ends a statement.
2235
+ if (lastToken(prev).name == "}" && /\n/.test(state.sliceDoc(prev.to, first.from)))
2236
+ break;
2237
+ if (declaration && !declarationPrefixes.test(prev.name))
2238
+ return null;
2239
+ first = prev;
2240
+ }
2241
+ return declaration || bodyKeywords.test(first.name) ? first : null;
2242
+ }
2243
+ /// The indentation of the lines in a node that holds statements between
2244
+ /// braces: that of `delimitedIndent`, and one unit more for a line that
2245
+ /// continues a statement.
2246
+ function statementIndent(closing) {
2247
+ let delimited = language.delimitedIndent({ closing });
2248
+ return (context) => {
2249
+ let { node, state, unit } = context, after = context.textAfter;
2250
+ let closed = after.slice(/^\s*/.exec(after)[0].length).startsWith(closing);
2251
+ // The body of a statement is indented from the line where the
2252
+ // statement starts, which need not be the line of its brace.
2253
+ // if $a
2254
+ // && $b {
2255
+ // say 1;
2256
+ // }
2257
+ let statement = isAligned(node, state) ? null : statementOfBody(node, state);
2258
+ let indent = statement ? context.lineIndent(statement.from) + (closed ? 0 : unit) : delimited(context);
2259
+ return !closed && continuesStatement(state, node, context.pos, after) ? indent + unit : indent;
2260
+ };
2261
+ }
2262
+ /// The indentation of the lines at the top level.
2263
+ function topIndent(context) {
2264
+ return continuesStatement(context.state, context.node, context.pos, context.textAfter) ? context.unit : 0;
2265
+ }
2266
+
2267
+ function closing(open) { return String.fromCharCode(brackets$1[open.charCodeAt(0)]); }
2268
+ // The brackets to try, in this order. A bracket that is repeated has
2269
+ // to be closed as many times.
2270
+ const pairs = ["(", "[", "{", "<", "«", "「", "((", "[[", "{{", "(((", "[[[", "{{{"].map(open => {
2271
+ return { open, close: closing(open).repeat(open.length) };
2272
+ });
2273
+ // Whether `text` can stand between the delimiters: none of them is
2274
+ // left open in it, and none closes more than were opened.
2275
+ function fits(text, { open, close }) {
2276
+ let depth = 0;
2277
+ for (let pos = 0; pos < text.length;) {
2278
+ if (text.startsWith(close, pos)) {
2279
+ if (--depth < 0)
2280
+ return false;
2281
+ pos += close.length;
2282
+ }
2283
+ else if (text.startsWith(open, pos)) {
2284
+ depth++;
2285
+ pos += open.length;
2286
+ }
2287
+ else {
2288
+ pos++;
2289
+ }
2290
+ }
2291
+ return depth == 0;
2292
+ }
2293
+ // The delimiters of the comment that a block comment command would
2294
+ // remove for the range, if there is one: the range is that comment, or
2295
+ // all of its text, give or take whitespace.
2296
+ function commentAt(state, from, to) {
2297
+ let start = from + /^\s*/.exec(state.sliceDoc(from, to))[0].length;
2298
+ let node = language.syntaxTree(state).resolveInner(start, 1);
2299
+ if (node.name != "BlockComment")
2300
+ return null;
2301
+ let text = state.sliceDoc(node.from, node.to), open = /^#`(.)\1*/.exec(text);
2302
+ if (!open || brackets$1[open[1].charCodeAt(0)] == null)
2303
+ return null;
2304
+ let close = closing(open[1]).repeat(open[0].length - 2);
2305
+ if (!text.endsWith(close))
2306
+ return null;
2307
+ let blank = (a, b) => a >= b || !/\S/.test(state.sliceDoc(a, b));
2308
+ let isComment = start == node.from && blank(node.to, to);
2309
+ let isContent = blank(node.from + open[0].length, from) && blank(to, node.to - close.length) && to <= node.to;
2310
+ return isComment || isContent ? { open: open[0], close } : null;
2311
+ }
2312
+ function blockTokens(state, pos) {
2313
+ // The command asks at the start of what it works on, which is a
2314
+ // selection range, or the first text of a selected line.
2315
+ let range = state.selection.ranges.find(range => range.from == pos);
2316
+ let existing = range && commentAt(state, range.from, range.to);
2317
+ if (existing)
2318
+ return existing;
2319
+ // The command that goes by lines wraps up to the end of the line, so
2320
+ // the brackets have to fit that text as well.
2321
+ let texts = [], line = state.doc.lineAt(pos);
2322
+ if (range) {
2323
+ texts.push(state.sliceDoc(range.from, range.to));
2324
+ line = state.doc.lineAt(range.to);
2325
+ }
2326
+ else {
2327
+ let onLine = state.selection.ranges.find(range => range.from <= pos && range.from >= line.from);
2328
+ if (onLine)
2329
+ line = state.doc.lineAt(onLine.to);
2330
+ }
2331
+ if (!range || range.to < line.to)
2332
+ texts.push(state.sliceDoc(pos, line.to));
2333
+ // The spaces keep a bracket at the edge of the text from joining the delimiters.
2334
+ let pair = pairs.find(pair => texts.every(text => fits(" " + text + " ", pair))) || pairs[0];
2335
+ return { open: "#`" + pair.open, close: pair.close };
2336
+ }
2337
+ /// Language data that gives `language` block comment tokens which fit
2338
+ /// the selection. It takes precedence over the fixed tokens in the
2339
+ /// language's own data.
2340
+ function embeddedCommentTokens(language) {
2341
+ return state.Prec.high(state.EditorState.languageData.of((state, pos, side) => {
2342
+ if (!language.isActiveAt(state, pos, side))
2343
+ return [];
2344
+ // Only worked out when asked for: this is called for every kind of
2345
+ // language data, and the line comment commands do not read `block`.
2346
+ return [{ get commentTokens() {
2347
+ return { line: "#", get block() { return blockTokens(state, pos); } };
2348
+ } }];
2349
+ }));
2350
+ }
2351
+
2352
+ // A regex literal is one token to the parser of a program: whether it
2353
+ // is closed has to be known where it starts, and a token that is read
2354
+ // piece by piece cannot look that far ahead (see AGENTS.md). Its inside
2355
+ // is parsed by the same grammar, from the top rule for a regex literal,
2356
+ // and that tree takes the place of the token's node. The inner parser
2357
+ // is made from `base` so that it has the same props, among them the
2358
+ // language data that LRLanguage.define puts on top nodes.
2359
+ function nestedParsers(base) {
2360
+ // From the term of a token to the parser of its inside. The
2361
+ // generator registers a top rule under its node name.
2362
+ let parsers = new Map();
2363
+ let wrap = common.parseMixed(node => parsers.get(node.type.id) || null);
2364
+ // The inner parsers are wrapped as well: a regex can hold a block of
2365
+ // code, and that can hold a regex.
2366
+ parsers.set(regexLiteral, { parser: base.configure({ top: "Regex", wrap }) });
2367
+ parsers.set(interpolatingHeredoc, { parser: base.configure({ top: "Heredoc", wrap }) });
2368
+ parsers.set(interpolatingWordList, { parser: base.configure({ top: "StringLiteral", wrap }) });
2369
+ return wrap;
2370
+ }
1008
2371
  /// The Lezer parser for Raku, without the editor-specific node props.
1009
- const parser = parser$1;
1010
- /// A language provider based on the Lezer Raku parser, extended with
1011
- /// highlighting and indentation information.
1012
- const rakuLanguage = language.LRLanguage.define({
2372
+ const parser = parser$1.configure({ wrap: nestedParsers(parser$1) });
2373
+ const baseLanguage = language.LRLanguage.define({
1013
2374
  name: "raku",
1014
- parser: parser.configure({
2375
+ parser: parser$1.configure({
1015
2376
  props: [
1016
2377
  language.indentNodeProp.add({
1017
- "Block Interpolation": language.delimitedIndent({ closing: "}" }),
2378
+ Program: topIndent,
2379
+ "Block Interpolation": statementIndent("}"),
1018
2380
  Parens: language.delimitedIndent({ closing: ")" }),
1019
2381
  Brackets: language.delimitedIndent({ closing: "]" }),
1020
2382
  // The lines of these are text, which keeps its indentation.
@@ -1028,22 +2390,30 @@ const rakuLanguage = language.LRLanguage.define({
1028
2390
  // A heredoc starts with the line break before its first line.
1029
2391
  Heredoc(tree) { return { from: tree.from, to: tree.to }; }
1030
2392
  }),
1031
- 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, "StringLiteral Heredoc": highlight.tags.string, Regex: highlight.tags.regexp, Pod: highlight.tags.docComment, 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 }))
2393
+ 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, "StringLiteral Heredoc": 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,
2394
+ // These are still part of a comment, and are styled as one where
2395
+ // a theme has no style for the second tag.
2396
+ 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 }))
1032
2397
  ]
1033
2398
  }),
1034
2399
  languageData: {
1035
2400
  // An embedded comment can use any bracket. Parentheses are the usual choice.
1036
2401
  commentTokens: { line: "#", block: { open: "#`(", close: ")" } },
1037
2402
  closeBrackets: { brackets: ["(", "[", "{", "'", '"', "「"] },
1038
- indentOnInput: /^\s*[\}\]\)]$/
2403
+ indentOnInput
1039
2404
  }
1040
2405
  });
1041
- /// Completion of Raku keywords and of the commonly used built-in types,
1042
- /// routines, methods and special variables.
2406
+ /// A language provider based on the Lezer Raku parser, extended with
2407
+ /// highlighting and indentation information.
2408
+ const rakuLanguage = baseLanguage.configure({ wrap: nestedParsers(baseLanguage.parser) });
2409
+ /// Completion of Raku keywords, of the commonly used built-in types,
2410
+ /// routines, methods and special variables, and of the names that the
2411
+ /// document declares.
1043
2412
  const rakuCompletion = rakuLanguage.data.of({ autocomplete: rakuCompletionSource });
1044
- /// Raku language support, with completion.
2413
+ /// Raku language support, with completion, and with block comment
2414
+ /// tokens that fit the selection.
1045
2415
  function raku() {
1046
- return new language.LanguageSupport(rakuLanguage, [rakuCompletion]);
2416
+ return new language.LanguageSupport(rakuLanguage, [rakuCompletion, embeddedCommentTokens(rakuLanguage)]);
1047
2417
  }
1048
2418
 
1049
2419
  exports.parser = parser;