codemirror-lang-raku 0.0.0-stage → 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/CHANGELOG.md +82 -0
- package/LICENSE +23 -0
- package/README.md +238 -2
- package/dist/index.cjs +2422 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2417 -0
- package/package.json +65 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2422 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lr = require('@lezer/lr');
|
|
4
|
+
var common = require('@lezer/common');
|
|
5
|
+
var language = require('@codemirror/language');
|
|
6
|
+
var highlight = require('@lezer/highlight');
|
|
7
|
+
var state = require('@codemirror/state');
|
|
8
|
+
|
|
9
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
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;
|
|
90
|
+
|
|
91
|
+
// Opening bracket -> closing bracket, for the delimiters of quotes and
|
|
92
|
+
// embedded comments. Raku accepts any Unicode bracket pair; this lists
|
|
93
|
+
// the ones that are likely to be typed.
|
|
94
|
+
const brackets$1 = {};
|
|
95
|
+
for (let pair of ["()", "[]", "{}", "<>", "«»", "「」", "『』", "()", "[]", "{}", "【】", "〈〉", "《》", "〔〕"])
|
|
96
|
+
brackets$1[pair.charCodeAt(0)] = pair.charCodeAt(1);
|
|
97
|
+
function isAsciiLetter(ch) { return ch >= 97 /* Ch.a */ && ch <= 122 /* Ch.z */ || ch >= 65 /* Ch.A */ && ch <= 90 /* Ch.Z */; }
|
|
98
|
+
function isDigit(ch) { return ch >= 48 /* Ch._0 */ && ch <= 57 /* Ch._9 */; }
|
|
99
|
+
// The characters of the grammar's whitespace token.
|
|
100
|
+
function isSpace(ch) {
|
|
101
|
+
return ch == 32 /* Ch.Space */ || ch >= 9 /* Ch.Tab */ && ch <= 13 /* Ch.Return */ || ch == 0x85 || ch == 0xa0 || ch == 0x1680 ||
|
|
102
|
+
ch >= 0x2000 && ch <= 0x200a || ch == 0x2028 || ch == 0x2029 || ch == 0x202f || ch == 0x205f || ch == 0x3000;
|
|
103
|
+
}
|
|
104
|
+
// Keep these ranges in sync with identifierStart in syntax.grammar. The
|
|
105
|
+
// input is read in UTF-16 code units, so the astral planes show up here
|
|
106
|
+
// as the surrogate range.
|
|
107
|
+
function isIdentifierStart(ch) {
|
|
108
|
+
return isAsciiLetter(ch) || ch == 95 /* Ch.Underscore */ ||
|
|
109
|
+
ch == 0xaa || ch == 0xb5 || ch == 0xba ||
|
|
110
|
+
ch >= 0xc0 && ch <= 0x1fff && ch != 0xd7 && ch != 0xf7 && ch != 0x1680 ||
|
|
111
|
+
ch >= 0x2c00 && ch <= 0x2fef ||
|
|
112
|
+
ch >= 0x3040 && ch <= 0xdfff ||
|
|
113
|
+
ch >= 0xf900 && ch <= 0xfdff ||
|
|
114
|
+
ch >= 0xff21 && ch <= 0xff3a || ch >= 0xff41 && ch <= 0xff5a || ch >= 0xff66 && ch <= 0xffdc;
|
|
115
|
+
}
|
|
116
|
+
// The characters that Operator runs are made of in syntax.grammar,
|
|
117
|
+
// leaving out the non-ASCII ones.
|
|
118
|
+
function isOperatorChar(ch) {
|
|
119
|
+
return ch == 43 /* Ch.Plus */ || ch == 45 /* Ch.Hyphen */ || ch == 42 /* Ch.Star */ || ch == 47 /* Ch.Slash */ || ch == 126 /* Ch.Tilde */ ||
|
|
120
|
+
ch == 94 /* Ch.Caret */ || ch == 124 /* Ch.Pipe */ || ch == 60 /* Ch.Less */ || ch == 62 /* Ch.Greater */ || ch == 61 /* Ch.Equals */ ||
|
|
121
|
+
ch == 33 /* Ch.Bang */ || ch == 63 /* Ch.Question */ || ch == 37 /* Ch.Percent */ || ch == 38 /* Ch.Amp */;
|
|
122
|
+
}
|
|
123
|
+
// Whether the character at offset `pos` would continue a name that ends
|
|
124
|
+
// right before it.
|
|
125
|
+
function continuesName(input, pos) {
|
|
126
|
+
let ch = input.peek(pos);
|
|
127
|
+
return isIdentifierStart(ch) || isDigit(ch) ||
|
|
128
|
+
(ch == 45 /* Ch.Hyphen */ || ch == 39 /* Ch.Apostrophe */) && isIdentifierStart(input.peek(pos + 1));
|
|
129
|
+
}
|
|
130
|
+
// The offset after the (possibly `::`-qualified) name that starts at
|
|
131
|
+
// offset `pos`, or -1 when there is no name there.
|
|
132
|
+
function nameEnd(input, pos) {
|
|
133
|
+
if (!isIdentifierStart(input.peek(pos)))
|
|
134
|
+
return -1;
|
|
135
|
+
for (pos++;;) {
|
|
136
|
+
let ch = input.peek(pos);
|
|
137
|
+
if (continuesName(input, pos))
|
|
138
|
+
pos++;
|
|
139
|
+
else if (ch == 58 /* Ch.Colon */ && input.peek(pos + 1) == 58 /* Ch.Colon */ && isIdentifierStart(input.peek(pos + 2)))
|
|
140
|
+
pos += 3;
|
|
141
|
+
else
|
|
142
|
+
return pos;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function repeats(input, pos, ch, count) {
|
|
146
|
+
for (let i = 0; i < count; i++)
|
|
147
|
+
if (input.peek(pos + i) != ch)
|
|
148
|
+
return false;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
function word(input, from, to) {
|
|
152
|
+
let result = "";
|
|
153
|
+
for (let i = from; i < to; i++)
|
|
154
|
+
result += String.fromCharCode(input.peek(i));
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
// A quote that is being read piece by piece because it interpolates.
|
|
158
|
+
class Quote {
|
|
159
|
+
constructor(parent, open, close, count,
|
|
160
|
+
// How many nested opening delimiters are unclosed.
|
|
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) {
|
|
165
|
+
this.parent = parent;
|
|
166
|
+
this.open = open;
|
|
167
|
+
this.close = close;
|
|
168
|
+
this.count = count;
|
|
169
|
+
this.depth = depth;
|
|
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;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class Context {
|
|
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) {
|
|
228
|
+
this.mode = mode;
|
|
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);
|
|
257
|
+
}
|
|
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]);
|
|
263
|
+
// The mode after a token or a node, for those where the term settles
|
|
264
|
+
// it. Shifting a token and reusing a node both look here, so that they
|
|
265
|
+
// agree.
|
|
266
|
+
const termModes = new Map();
|
|
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])
|
|
276
|
+
termModes.set(term, 1 /* Mode.AfterTerm */);
|
|
277
|
+
for (let term of [Identifier, TypeName, smiley, noSmiley, declaredName, declaredMethodName, PackageName, RoutineName,
|
|
278
|
+
methodRoutineName, multiName, multiRoutineName, RegexName, EnumName, SubsetName, ConstantName])
|
|
279
|
+
termModes.set(term, 2 /* Mode.AfterName */);
|
|
280
|
+
// The `}` of "{...}" in a string does not take a subscript.
|
|
281
|
+
for (let term of [quoteContent, Interpolation])
|
|
282
|
+
termModes.set(term, 0 /* Mode.Term */);
|
|
283
|
+
for (let term of [multi, proto, only])
|
|
284
|
+
termModes.set(term, 4 /* Mode.AfterMulti */);
|
|
285
|
+
// The mode after an operator, from its first three characters. `after`
|
|
286
|
+
// is the mode before it.
|
|
287
|
+
function modeAfterOperator(first, second, third, after) {
|
|
288
|
+
// A lone `*` is as often the whatever star as a multiplication.
|
|
289
|
+
if (first == 42 /* Ch.Star */ && !isOperatorChar(second))
|
|
290
|
+
return 2 /* Mode.AfterName */;
|
|
291
|
+
// Postfix increment and decrement leave the term complete.
|
|
292
|
+
if ((first == 43 /* Ch.Plus */ || first == 45 /* Ch.Hyphen */) && second == first && !isOperatorChar(third) &&
|
|
293
|
+
(after == 1 /* Mode.AfterTerm */ || after == 3 /* Mode.AfterBlock */))
|
|
294
|
+
return 1 /* Mode.AfterTerm */;
|
|
295
|
+
return 0 /* Mode.Term */;
|
|
296
|
+
}
|
|
297
|
+
// The mode after a token that the terms file has no name for, from its
|
|
298
|
+
// first character. Keywords and identifiers come through here alike;
|
|
299
|
+
// an identifier gets its mode when the Identifier node is reduced,
|
|
300
|
+
// from modeAfter, which also looks at how it is spelled.
|
|
301
|
+
function modeAfterChar(first) {
|
|
302
|
+
if (first == 41 /* Ch.ParenClose */ || first == 93 /* Ch.BracketClose */ || first == 36 /* Ch.Dollar */ || first == 64 /* Ch.At */)
|
|
303
|
+
return 1 /* Mode.AfterTerm */;
|
|
304
|
+
// A capitalized name, taken to be a type.
|
|
305
|
+
if (first >= 65 /* Ch.A */ && first <= 90 /* Ch.Z */)
|
|
306
|
+
return 2 /* Mode.AfterName */;
|
|
307
|
+
return first == 125 /* Ch.BraceClose */ ? 3 /* Mode.AfterBlock */ : 0 /* Mode.Term */;
|
|
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)$/;
|
|
313
|
+
// The mode after the token of the given term at the input's position.
|
|
314
|
+
// `before` is the mode before it.
|
|
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
|
+
}
|
|
323
|
+
let mode = termModes.get(term);
|
|
324
|
+
if (mode != null)
|
|
325
|
+
return mode;
|
|
326
|
+
let first = input.peek(offset);
|
|
327
|
+
if (term == Operator || term == wordOperator)
|
|
328
|
+
return modeAfterOperator(first, input.peek(offset + 1), input.peek(offset + 2), before);
|
|
329
|
+
return modeAfterChar(first);
|
|
330
|
+
}
|
|
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
|
+
}
|
|
437
|
+
const trackContext = new lr.ContextTracker({
|
|
438
|
+
start: startContext,
|
|
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);
|
|
450
|
+
if (skippedTerms.has(term))
|
|
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
|
+
}
|
|
477
|
+
switch (term) {
|
|
478
|
+
case quoteStart: {
|
|
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));
|
|
484
|
+
}
|
|
485
|
+
case quoteNestOpen:
|
|
486
|
+
case quoteNestClose: {
|
|
487
|
+
let quote = context.quote;
|
|
488
|
+
if (!quote)
|
|
489
|
+
return context;
|
|
490
|
+
let depth = quote.depth + (term == quoteNestOpen ? 1 : -1);
|
|
491
|
+
return context.withQuote(0 /* Mode.Term */, quote.withDepth(depth));
|
|
492
|
+
}
|
|
493
|
+
case quoteEnd:
|
|
494
|
+
return context.withQuote(1 /* Mode.AfterTerm */, context.quote && context.quote.parent);
|
|
495
|
+
}
|
|
496
|
+
// The whitespace token has no term to go by. It is the only token
|
|
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);
|
|
505
|
+
return context;
|
|
506
|
+
}
|
|
507
|
+
if (term == rawString)
|
|
508
|
+
context = context.withHeredocs(withHeredocAt(context.heredocs, input, 0));
|
|
509
|
+
return context.withMode(modeAfter(term, input, 0, context.mode));
|
|
510
|
+
},
|
|
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;
|
|
515
|
+
},
|
|
516
|
+
reuse(context, node, _stack, input) {
|
|
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);
|
|
520
|
+
// What comes before a trailing `++` in a reused node is a term.
|
|
521
|
+
return last ? context.withMode(modeAfter(last.type.id, input, last.from, 1 /* Mode.AfterTerm */)) : context;
|
|
522
|
+
},
|
|
523
|
+
hash: context => context.hash
|
|
524
|
+
});
|
|
525
|
+
function context(stack) { return stack.context; }
|
|
526
|
+
// Whether a token of `size` characters at the current position is where
|
|
527
|
+
// a term starts, as opposed to an infix operator.
|
|
528
|
+
function inTermPosition(input, mode, size) {
|
|
529
|
+
if (mode == 0 /* Mode.Term */ || mode == 4 /* Mode.AfterMulti */)
|
|
530
|
+
return true;
|
|
531
|
+
if (mode == 1 /* Mode.AfterTerm */)
|
|
532
|
+
return false;
|
|
533
|
+
if (mode == 2 /* Mode.AfterName */)
|
|
534
|
+
return isSpace(input.peek(-1)) && !isSpace(input.peek(size));
|
|
535
|
+
return atLineStart(input);
|
|
536
|
+
}
|
|
537
|
+
// ---- Comments and Pod ----
|
|
538
|
+
// #`( ... ), with any bracket pair. A repeated opening bracket, as in
|
|
539
|
+
// #`(( ... )), needs the same number of closing ones. Brackets of the
|
|
540
|
+
// same kind nest. An unclosed comment runs to the end of the input.
|
|
541
|
+
const blockComment = new lr.ExternalTokenizer(input => {
|
|
542
|
+
let end = embeddedCommentEnd(input, 0);
|
|
543
|
+
if (!end)
|
|
544
|
+
return;
|
|
545
|
+
if (end < 0)
|
|
546
|
+
skipToEnd(input);
|
|
547
|
+
else
|
|
548
|
+
input.advance(end);
|
|
549
|
+
input.acceptToken(BlockComment);
|
|
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
|
+
}
|
|
564
|
+
function isBlank(ch) { return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 13 /* Ch.Return */; }
|
|
565
|
+
// The offset of the first character at or after `pos` that is not a blank.
|
|
566
|
+
function blanksEnd(input, pos) {
|
|
567
|
+
while (isBlank(input.peek(pos)))
|
|
568
|
+
pos++;
|
|
569
|
+
return pos;
|
|
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
|
+
}
|
|
583
|
+
// Whether only blanks separate the current position from the start of its line.
|
|
584
|
+
function atLineStart(input) {
|
|
585
|
+
for (let i = -1;; i--) {
|
|
586
|
+
let ch = input.peek(i);
|
|
587
|
+
if (ch == 10 /* Ch.Newline */ || ch < 0)
|
|
588
|
+
return true;
|
|
589
|
+
if (!isBlank(ch))
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
// Whether only blanks separate offset `pos` from the end of its line.
|
|
594
|
+
function isLineEnd(input, pos) {
|
|
595
|
+
let ch = input.peek(blanksEnd(input, pos));
|
|
596
|
+
return ch == 10 /* Ch.Newline */ || ch < 0;
|
|
597
|
+
}
|
|
598
|
+
function skipLine(input) {
|
|
599
|
+
while (input.next >= 0 && input.next != 10 /* Ch.Newline */)
|
|
600
|
+
input.advance();
|
|
601
|
+
}
|
|
602
|
+
function skipToEnd(input) {
|
|
603
|
+
while (input.next >= 0)
|
|
604
|
+
input.advance();
|
|
605
|
+
}
|
|
606
|
+
function skipBlanks(input) {
|
|
607
|
+
input.advance(blanksEnd(input, 0));
|
|
608
|
+
}
|
|
609
|
+
// Skips blanks, and tells whether the rest of the line starts with `text`.
|
|
610
|
+
function lineStartsWith(input, text) {
|
|
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) {
|
|
616
|
+
for (let i = 0; i < text.length; i++)
|
|
617
|
+
if (input.peek(pos + i) != text.charCodeAt(i))
|
|
618
|
+
return false;
|
|
619
|
+
return !continuesName(input, pos + text.length);
|
|
620
|
+
}
|
|
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,})$/;
|
|
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) {
|
|
626
|
+
if (input.next != 61 /* Ch.Equals */ || !isAsciiLetter(input.peek(1)) || !atLineStart(input))
|
|
627
|
+
return -1;
|
|
628
|
+
let end = 1;
|
|
629
|
+
while (isAsciiLetter(input.peek(end)) || isDigit(input.peek(end)))
|
|
630
|
+
end++;
|
|
631
|
+
let directive = word(input, 1, end);
|
|
632
|
+
if (!podDirective.test(directive) || continuesName(input, end))
|
|
633
|
+
return -1;
|
|
634
|
+
// A semantic block such as =TITLE has to start in the first column.
|
|
635
|
+
// An indented `=FOO + 1` continues an assignment.
|
|
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));
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
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);
|
|
728
|
+
}
|
|
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)) {
|
|
732
|
+
skipLine(input);
|
|
733
|
+
return input.acceptToken(podEndDirective);
|
|
734
|
+
}
|
|
735
|
+
return input.acceptToken(PodDirective, podNameEnd(input, directive));
|
|
736
|
+
}
|
|
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);
|
|
761
|
+
});
|
|
762
|
+
const quoteWords = {
|
|
763
|
+
q: "raw", Q: "raw", qw: "raw", qww: "raw", qx: "raw", Qw: "raw", Qww: "raw", Qx: "raw",
|
|
764
|
+
qq: "interpolating", qqw: "interpolating", qqww: "interpolating", qqx: "interpolating",
|
|
765
|
+
rx: "regex", m: "regex", ms: "regex",
|
|
766
|
+
s: "substitution", ss: "substitution", S: "substitution",
|
|
767
|
+
// Like a substitution, but its first part is not a regex.
|
|
768
|
+
tr: "transliteration", TR: "transliteration"
|
|
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
|
+
}
|
|
792
|
+
// The delimiters, other than brackets, that are accepted after a quote word.
|
|
793
|
+
function isQuoteDelimiter(ch) {
|
|
794
|
+
return ch == 47 /* Ch.Slash */ || ch == 33 /* Ch.Bang */ || ch == 124 /* Ch.Pipe */ || ch == 126 /* Ch.Tilde */ || ch == 94 /* Ch.Caret */ ||
|
|
795
|
+
ch == 37 /* Ch.Percent */ || ch == 64 /* Ch.At */ || ch == 34 /* Ch.DoubleQuote */ || ch == 39 /* Ch.Apostrophe */;
|
|
796
|
+
}
|
|
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);
|
|
802
|
+
if (next == 34 /* Ch.DoubleQuote */)
|
|
803
|
+
return quoteCharOpening(next, next, at, 63 /* Interpolate.All */);
|
|
804
|
+
if (next == 39 /* Ch.Apostrophe */)
|
|
805
|
+
return quoteCharOpening(next, next, at, 0);
|
|
806
|
+
if (next == 0x201c /* “ */)
|
|
807
|
+
return quoteCharOpening(next, 0x201d, at, 63 /* Interpolate.All */);
|
|
808
|
+
if (next == 0x2018 /* ‘ */)
|
|
809
|
+
return quoteCharOpening(next, 0x2019, at, 0);
|
|
810
|
+
if (next == 0x300c /* 「 */)
|
|
811
|
+
return quoteCharOpening(next, 0x300d, at, 0, false);
|
|
812
|
+
if (!isAsciiLetter(next))
|
|
813
|
+
return null;
|
|
814
|
+
let pos = at + 1;
|
|
815
|
+
while (isAsciiLetter(input.peek(pos)))
|
|
816
|
+
pos++;
|
|
817
|
+
if (pos - at > 4)
|
|
818
|
+
return null;
|
|
819
|
+
let name = word(input, at, pos), kind = quoteWords[name];
|
|
820
|
+
if (!kind)
|
|
821
|
+
return null;
|
|
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;
|
|
829
|
+
while (input.peek(pos) == 58 /* Ch.Colon */ && (isAsciiLetter(input.peek(pos + 1)) || input.peek(pos + 1) == 33 /* Ch.Bang */)) {
|
|
830
|
+
adverbs = true;
|
|
831
|
+
let negated = input.peek(pos + 1) == 33 /* Ch.Bang */, adverbStart = pos + (negated ? 2 : 1);
|
|
832
|
+
pos += 2;
|
|
833
|
+
while (isAsciiLetter(input.peek(pos)) || isDigit(input.peek(pos)))
|
|
834
|
+
pos++;
|
|
835
|
+
let adverb = word(input, adverbStart, pos);
|
|
836
|
+
// An argument that is False or 0 switches the adverb off: q:c(False)
|
|
837
|
+
if (input.peek(pos) == 40 /* Ch.ParenOpen */) {
|
|
838
|
+
let argStart = pos + 1;
|
|
839
|
+
while (input.peek(pos) != 41 /* Ch.ParenClose */) {
|
|
840
|
+
if (input.peek(pos) < 0 || input.peek(pos) == 10 /* Ch.Newline */)
|
|
841
|
+
return null;
|
|
842
|
+
pos++;
|
|
843
|
+
}
|
|
844
|
+
if (/^\s*(False|0)\s*$/.test(word(input, argStart, pos)))
|
|
845
|
+
negated = true;
|
|
846
|
+
pos++;
|
|
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
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (!adverbs && continuesName(input, pos))
|
|
859
|
+
return null;
|
|
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];
|
|
869
|
+
if (close == null) {
|
|
870
|
+
if (!isQuoteDelimiter(open))
|
|
871
|
+
return null;
|
|
872
|
+
close = open;
|
|
873
|
+
}
|
|
874
|
+
// q(...) is a call.
|
|
875
|
+
if (open == 40 /* Ch.ParenOpen */ && !adverbs)
|
|
876
|
+
return null;
|
|
877
|
+
let count = 1;
|
|
878
|
+
if (close != open)
|
|
879
|
+
while (input.peek(pos + count) == open)
|
|
880
|
+
count++;
|
|
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 };
|
|
886
|
+
}
|
|
887
|
+
// The offset after the delimiter that closes a quote whose content
|
|
888
|
+
// starts at `pos`, or -1 when it is not closed.
|
|
889
|
+
function rawEnd(input, pos, opening) {
|
|
890
|
+
let { open, close, count } = opening;
|
|
891
|
+
for (let depth = 1;;) {
|
|
892
|
+
let ch = input.peek(pos);
|
|
893
|
+
if (ch < 0)
|
|
894
|
+
return -1;
|
|
895
|
+
if (ch == 92 /* Ch.Backslash */ && opening.escapes)
|
|
896
|
+
pos += 2;
|
|
897
|
+
else if (ch == close && repeats(input, pos, close, count)) {
|
|
898
|
+
pos += count;
|
|
899
|
+
if (--depth == 0)
|
|
900
|
+
return pos;
|
|
901
|
+
}
|
|
902
|
+
else if (ch == open && repeats(input, pos, open, count)) {
|
|
903
|
+
pos += count;
|
|
904
|
+
depth++;
|
|
905
|
+
}
|
|
906
|
+
else
|
|
907
|
+
pos++;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
// The offset after a quoted string that starts at `pos`, or -1.
|
|
911
|
+
function quotedEnd(input, pos) {
|
|
912
|
+
let quote = input.peek(pos);
|
|
913
|
+
for (pos++;;) {
|
|
914
|
+
let ch = input.peek(pos);
|
|
915
|
+
if (ch < 0 || ch == 10 /* Ch.Newline */)
|
|
916
|
+
return -1;
|
|
917
|
+
if (ch == 92 /* Ch.Backslash */)
|
|
918
|
+
pos += 2;
|
|
919
|
+
else if (ch == quote)
|
|
920
|
+
return pos + 1;
|
|
921
|
+
else
|
|
922
|
+
pos++;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
// The offset of the delimiter that closes a regex whose content starts
|
|
926
|
+
// at `pos`, or -1. Delimiters do not count inside quotes, character
|
|
927
|
+
// classes, comments and code blocks.
|
|
928
|
+
function regexEnd(input, { start: pos, open, close, count }) {
|
|
929
|
+
for (let depth = 1;;) {
|
|
930
|
+
let ch = input.peek(pos);
|
|
931
|
+
if (ch < 0)
|
|
932
|
+
return -1;
|
|
933
|
+
if (ch == 92 /* Ch.Backslash */) {
|
|
934
|
+
pos += 2;
|
|
935
|
+
}
|
|
936
|
+
else if (ch == close && repeats(input, pos, close, count)) {
|
|
937
|
+
if (--depth == 0)
|
|
938
|
+
return pos;
|
|
939
|
+
pos += count;
|
|
940
|
+
}
|
|
941
|
+
else if (ch == open && repeats(input, pos, open, count)) {
|
|
942
|
+
pos += count;
|
|
943
|
+
depth++;
|
|
944
|
+
}
|
|
945
|
+
else if (ch == 39 /* Ch.Apostrophe */ || ch == 34 /* Ch.DoubleQuote */) {
|
|
946
|
+
let end = quotedEnd(input, pos);
|
|
947
|
+
pos = end < 0 ? pos + 1 : end;
|
|
948
|
+
}
|
|
949
|
+
else if (ch == 60 /* Ch.Less */ && (input.peek(pos + 1) == 91 /* Ch.BracketOpen */ ||
|
|
950
|
+
(input.peek(pos + 1) == 45 /* Ch.Hyphen */ || input.peek(pos + 1) == 43 /* Ch.Plus */) && input.peek(pos + 2) == 91 /* Ch.BracketOpen */)) {
|
|
951
|
+
// <[...]>, <-[...]>, and combinations: <+[a..z]-[aeiou]>
|
|
952
|
+
for (pos++;;) {
|
|
953
|
+
while (input.peek(pos) != 91 /* Ch.BracketOpen */) {
|
|
954
|
+
if (input.peek(pos) < 0)
|
|
955
|
+
return -1;
|
|
956
|
+
pos++;
|
|
957
|
+
}
|
|
958
|
+
for (pos++; input.peek(pos) != 93 /* Ch.BracketClose */; pos++) {
|
|
959
|
+
if (input.peek(pos) < 0)
|
|
960
|
+
return -1;
|
|
961
|
+
if (input.peek(pos) == 92 /* Ch.Backslash */)
|
|
962
|
+
pos++;
|
|
963
|
+
}
|
|
964
|
+
let more = pos + 1;
|
|
965
|
+
while (input.peek(more) == 32 /* Ch.Space */)
|
|
966
|
+
more++;
|
|
967
|
+
if (input.peek(more) != 43 /* Ch.Plus */ && input.peek(more) != 45 /* Ch.Hyphen */)
|
|
968
|
+
break;
|
|
969
|
+
do
|
|
970
|
+
more++;
|
|
971
|
+
while (input.peek(more) == 32 /* Ch.Space */);
|
|
972
|
+
if (input.peek(more) != 91 /* Ch.BracketOpen */)
|
|
973
|
+
break;
|
|
974
|
+
pos = more;
|
|
975
|
+
}
|
|
976
|
+
// The bracket that closes the class is not one of the regex: rx[ <[a]> ]
|
|
977
|
+
pos++;
|
|
978
|
+
}
|
|
979
|
+
else if (ch == 35 /* Ch.Hash */) {
|
|
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++;
|
|
987
|
+
}
|
|
988
|
+
else if (ch == 123 /* Ch.BraceOpen */ && close != 125 /* Ch.BraceClose */) {
|
|
989
|
+
let end = regexEnd(input, { start: pos + 1, open: 123 /* Ch.BraceOpen */, close: 125 /* Ch.BraceClose */, count: 1 });
|
|
990
|
+
pos = end < 0 ? pos + 1 : end + 1;
|
|
991
|
+
}
|
|
992
|
+
else {
|
|
993
|
+
pos++;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
// The offset after a regex or substitution, given its opening, or -1.
|
|
998
|
+
function regexTokenEnd(input, opening) {
|
|
999
|
+
let end = regexEnd(input, opening);
|
|
1000
|
+
if (end < 0)
|
|
1001
|
+
return -1;
|
|
1002
|
+
end += opening.count;
|
|
1003
|
+
// s/a/b/ has a second part. s{a} = 'b' does not.
|
|
1004
|
+
if (opening.kind != "regex" && opening.open == opening.close)
|
|
1005
|
+
end = rawEnd(input, end, opening);
|
|
1006
|
+
return end;
|
|
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
|
+
}
|
|
1020
|
+
// The offset after a word list that opens at the current position, or
|
|
1021
|
+
// -1. A list that spans lines has to hold plain words, so that a stray
|
|
1022
|
+
// `<` does not swallow the code up to some later `>`. `strict` is for
|
|
1023
|
+
// a subscript, which has to be on one line, and cannot hold what
|
|
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 `>>`.
|
|
1029
|
+
function wordListEnd(input, strict) {
|
|
1030
|
+
let open = input.next, close = open == 171 /* Ch.GuillemetOpen */ ? 187 /* Ch.GuillemetClose */ : 62 /* Ch.Greater */;
|
|
1031
|
+
let count = open == 60 /* Ch.Less */ && input.peek(1) == 60 /* Ch.Less */ ? 2 : 1;
|
|
1032
|
+
let codeLines = open == 171 /* Ch.GuillemetOpen */ || count == 2 ? maxCodeWordListLines : 1;
|
|
1033
|
+
for (let pos = count, lines = 1, code = false;; pos++) {
|
|
1034
|
+
let ch = input.peek(pos);
|
|
1035
|
+
if (ch == close && repeats(input, pos, close, count))
|
|
1036
|
+
return pos + count;
|
|
1037
|
+
if (ch < 0)
|
|
1038
|
+
return -1;
|
|
1039
|
+
if (ch == 10 /* Ch.Newline */)
|
|
1040
|
+
lines++;
|
|
1041
|
+
else if (ch == 59 /* Ch.Semicolon */ || ch == 123 /* Ch.BraceOpen */ || ch == 125 /* Ch.BraceClose */ ||
|
|
1042
|
+
ch == 40 /* Ch.ParenOpen */ || ch == 41 /* Ch.ParenClose */)
|
|
1043
|
+
code = true;
|
|
1044
|
+
if (lines > 1 && (code && lines > codeLines || strict))
|
|
1045
|
+
return -1;
|
|
1046
|
+
if (strict && (code || ch == 36 /* Ch.Dollar */ || ch == 64 /* Ch.At */ || ch == 37 /* Ch.Percent */ || ch == 38 /* Ch.Amp */ ||
|
|
1047
|
+
ch == 124 /* Ch.Pipe */ || ch == 61 /* Ch.Equals */ || ch == 44 /* Ch.Comma */ || ch == 63 /* Ch.Question */ ||
|
|
1048
|
+
ch == 33 /* Ch.Bang */ || ch == 34 /* Ch.DoubleQuote */ || ch == 60 /* Ch.Less */))
|
|
1049
|
+
return -1;
|
|
1050
|
+
}
|
|
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
|
+
}
|
|
1094
|
+
// A `<` subscript right after a term: %h<key>
|
|
1095
|
+
function subscriptEnd(input) {
|
|
1096
|
+
if (input.next != 60 /* Ch.Less */ || isSpace(input.peek(-1)) || input.peek(1) == 60 /* Ch.Less */)
|
|
1097
|
+
return -1;
|
|
1098
|
+
return wordListEnd(input, true);
|
|
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)$/;
|
|
1110
|
+
function isWordOperator(name) {
|
|
1111
|
+
return name == "x" || name == "xx" || name == "min" || name == "max" || name == "Z" || name == "X";
|
|
1112
|
+
}
|
|
1113
|
+
// The tokens that depend on whether a term or an operator is expected.
|
|
1114
|
+
const termToken = new lr.ExternalTokenizer((input, stack) => {
|
|
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);
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
let next = input.next, { mode } = context(stack);
|
|
1124
|
+
if (isIdentifierStart(next)) {
|
|
1125
|
+
// The Z, X and R meta operators: Z+, X~, R-, Z=>
|
|
1126
|
+
if (mode == 1 /* Mode.AfterTerm */ && (next == 90 /* Ch.Z */ || next == 88 /* Ch.X */ || next == 82 /* Ch.R */) &&
|
|
1127
|
+
isOperatorChar(input.peek(1)) && !continuesName(input, 1)) {
|
|
1128
|
+
let pos = 2;
|
|
1129
|
+
while (isOperatorChar(input.peek(pos)))
|
|
1130
|
+
pos++;
|
|
1131
|
+
return input.acceptToken(wordOperator, pos);
|
|
1132
|
+
}
|
|
1133
|
+
// A word before `=>` is a key, whatever it spells.
|
|
1134
|
+
let end = nameEnd(input, 0), after = gapEnd(input, end);
|
|
1135
|
+
if (input.peek(after) == 61 /* Ch.Equals */ && input.peek(after + 1) == 62 /* Ch.Greater */)
|
|
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);
|
|
1154
|
+
if (mode == 1 /* Mode.AfterTerm */) {
|
|
1155
|
+
// x, xx, min, max, Z and X are operators where one is expected.
|
|
1156
|
+
if (end <= 3 && isWordOperator(word(input, 0, end)))
|
|
1157
|
+
input.acceptToken(wordOperator, end);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
else if (next == 37 /* Ch.Percent */ || next == 38 /* Ch.Amp */) {
|
|
1162
|
+
// Squeezed between two terms, a sigil is the operator: $a%b. With a
|
|
1163
|
+
// space before it, it is a variable: `my Array[Int] %h`.
|
|
1164
|
+
if (mode == 1 /* Mode.AfterTerm */ && isIdentifierStart(input.peek(1)) && !isSpace(input.peek(-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
|
+
}
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
else if (next == 60 /* Ch.Less */ || next == 171 /* Ch.GuillemetOpen */) {
|
|
1178
|
+
let end, opening = wordListOpening(input, 0);
|
|
1179
|
+
if (inTermPosition(input, mode, 1)) {
|
|
1180
|
+
// [<] and [<=] are reductions, <-> starts a pointy block.
|
|
1181
|
+
let after = input.peek(1);
|
|
1182
|
+
if (after == 61 /* Ch.Equals */ || after == 93 /* Ch.BracketClose */ || after == 45 /* Ch.Hyphen */ && input.peek(2) == 62 /* Ch.Greater */)
|
|
1183
|
+
return;
|
|
1184
|
+
end = wordListEnd(input, false);
|
|
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
|
+
}
|
|
1191
|
+
else {
|
|
1192
|
+
end = subscriptEnd(input);
|
|
1193
|
+
}
|
|
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);
|
|
1204
|
+
}
|
|
1205
|
+
else if (next == 47 /* Ch.Slash */) {
|
|
1206
|
+
if (input.peek(1) == 47 /* Ch.Slash */ || !inTermPosition(input, mode, 1))
|
|
1207
|
+
return;
|
|
1208
|
+
let end = regexTokenEnd(input, slashOpening);
|
|
1209
|
+
if (end > 0)
|
|
1210
|
+
input.acceptToken(regexLiteral, end);
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
let opening = readOpening(input);
|
|
1214
|
+
if (!opening)
|
|
1215
|
+
return;
|
|
1216
|
+
if (opening.kind == "interpolating")
|
|
1217
|
+
return input.acceptToken(quoteStart, opening.start);
|
|
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);
|
|
1225
|
+
if (end > 0)
|
|
1226
|
+
input.acceptToken(rawString, end);
|
|
1227
|
+
});
|
|
1228
|
+
// Whether a sigil other than `$` interpolates: only when a subscript or
|
|
1229
|
+
// a call follows its name. `end` is the offset after the name.
|
|
1230
|
+
function hasPostfix(input, end) {
|
|
1231
|
+
let ch = input.peek(end);
|
|
1232
|
+
if (ch == 91 /* Ch.BracketOpen */ || ch == 40 /* Ch.ParenOpen */ || ch == 123 /* Ch.BraceOpen */ || ch == 60 /* Ch.Less */)
|
|
1233
|
+
return true;
|
|
1234
|
+
if (ch != 46 /* Ch.Dot */)
|
|
1235
|
+
return false;
|
|
1236
|
+
let methodEnd = nameEnd(input, end + 1);
|
|
1237
|
+
return methodEnd > 0 && input.peek(methodEnd) == 40 /* Ch.ParenOpen */;
|
|
1238
|
+
}
|
|
1239
|
+
// The pieces of a quote that interpolates.
|
|
1240
|
+
const quoteToken = new lr.ExternalTokenizer((input, stack) => {
|
|
1241
|
+
if (!stack.canShift(quoteEnd))
|
|
1242
|
+
return;
|
|
1243
|
+
let { quote, mode } = context(stack);
|
|
1244
|
+
if (!quote)
|
|
1245
|
+
return;
|
|
1246
|
+
let { open, close, count, interpolates } = quote, nests = open != close;
|
|
1247
|
+
// After a variable, a subscript or a call continues the interpolation.
|
|
1248
|
+
// `[` and `(` are left to the grammar's own tokens.
|
|
1249
|
+
if (mode == 1 /* Mode.AfterTerm */) {
|
|
1250
|
+
if (input.next == 91 /* Ch.BracketOpen */ || input.next == 40 /* Ch.ParenOpen */)
|
|
1251
|
+
return;
|
|
1252
|
+
let end = subscriptEnd(input);
|
|
1253
|
+
if (end > 0)
|
|
1254
|
+
return input.acceptToken(rawString, end);
|
|
1255
|
+
}
|
|
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);
|
|
1260
|
+
for (;;) {
|
|
1261
|
+
let next = input.next;
|
|
1262
|
+
if (next < 0)
|
|
1263
|
+
break;
|
|
1264
|
+
let atClose = next == close && repeats(input, 0, close, count);
|
|
1265
|
+
if (atClose || nests && next == open && repeats(input, 0, open, count)) {
|
|
1266
|
+
if (input.pos > start)
|
|
1267
|
+
break;
|
|
1268
|
+
input.advance(count);
|
|
1269
|
+
return input.acceptToken(!atClose ? quoteNestOpen : quote.depth ? quoteNestClose : quoteEnd);
|
|
1270
|
+
}
|
|
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 */) {
|
|
1289
|
+
let end = nameEnd(input, 1);
|
|
1290
|
+
if (end > 0 && hasPostfix(input, end))
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
input.advance();
|
|
1294
|
+
}
|
|
1295
|
+
if (input.pos > start)
|
|
1296
|
+
input.acceptToken(quoteContent);
|
|
1297
|
+
});
|
|
1298
|
+
// The text of a heredoc: the lines after the one that holds its opener,
|
|
1299
|
+
// up to the line that holds only its terminator. As a skipped token, it
|
|
1300
|
+
// leaves the rest of the opener's line to be parsed as usual. The
|
|
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;
|
|
1315
|
+
let pos = blanksEnd(input, 0);
|
|
1316
|
+
if (input.peek(pos) != 10 /* Ch.Newline */)
|
|
1317
|
+
return;
|
|
1318
|
+
input.advance(pos);
|
|
1319
|
+
for (let { terminator } of heredocs) {
|
|
1320
|
+
for (;;) {
|
|
1321
|
+
// Without its terminator, this is not taken to be a heredoc.
|
|
1322
|
+
if (input.next < 0)
|
|
1323
|
+
return;
|
|
1324
|
+
input.advance();
|
|
1325
|
+
if (lineStartsWith(input, terminator) && isLineEnd(input, terminator.length)) {
|
|
1326
|
+
input.advance(terminator.length);
|
|
1327
|
+
break;
|
|
1328
|
+
}
|
|
1329
|
+
skipLine(input);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
input.acceptToken(heredocs.every(heredoc => heredoc.interpolates) ? interpolatingHeredoc : rawHeredoc);
|
|
1333
|
+
});
|
|
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);
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
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);
|
|
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);
|
|
1544
|
+
});
|
|
1545
|
+
// ---- Names ----
|
|
1546
|
+
// The dot of a method call, with its optional `?`, `+`, `*`, `^` or `&`
|
|
1547
|
+
// modifier. It is only produced when a name follows. In a string, a
|
|
1548
|
+
// method call is only interpolated after a variable, and when it has
|
|
1549
|
+
// an argument list: "$x.foo()"
|
|
1550
|
+
const methodDotToken = new lr.ExternalTokenizer((input, stack) => {
|
|
1551
|
+
if (input.next != 46 /* Ch.Dot */)
|
|
1552
|
+
return;
|
|
1553
|
+
let size = 1, next = input.peek(1);
|
|
1554
|
+
if (next == 63 /* Ch.Question */ || next == 43 /* Ch.Plus */ || next == 42 /* Ch.Star */ || next == 94 /* Ch.Caret */ || next == 38 /* Ch.Amp */)
|
|
1555
|
+
next = input.peek(++size);
|
|
1556
|
+
if (!isIdentifierStart(next))
|
|
1557
|
+
return;
|
|
1558
|
+
let { quote, mode } = context(stack);
|
|
1559
|
+
if (quote && stack.canShift(quoteEnd) &&
|
|
1560
|
+
(mode != 1 /* Mode.AfterTerm */ || input.peek(nameEnd(input, size)) != 40 /* Ch.ParenOpen */))
|
|
1561
|
+
return;
|
|
1562
|
+
input.acceptToken(methodDot, size);
|
|
1563
|
+
});
|
|
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) {
|
|
1568
|
+
if (input.peek(pos) != 58 /* Ch.Colon */)
|
|
1569
|
+
return pos;
|
|
1570
|
+
let open = pos + 1;
|
|
1571
|
+
if (word(input, open, open + 3) == "sym")
|
|
1572
|
+
open += 3;
|
|
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;
|
|
1583
|
+
if (close < 0)
|
|
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;
|
|
1587
|
+
for (let i = open + 1;; i++) {
|
|
1588
|
+
let ch = input.peek(i);
|
|
1589
|
+
if (ch < 0 || isSpace(ch) && (ch != 32 /* Ch.Space */ || i == open + 1 || --spaces < 0))
|
|
1590
|
+
return pos;
|
|
1591
|
+
// The operator itself can be `>`, so the last closer before a break counts.
|
|
1592
|
+
if (ch == close && !(input.peek(i + 1) == close))
|
|
1593
|
+
return i + 1;
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
// A name after a method dot or a declarator. The grammar's keywords are
|
|
1597
|
+
// specialized identifiers, and specialization does not look at the
|
|
1598
|
+
// parse state, so these positions get tokens of their own.
|
|
1599
|
+
const nameToken = new lr.ExternalTokenizer((input, stack) => {
|
|
1600
|
+
// Only a method declaration takes a mark: `method !private`, `method ^meta`.
|
|
1601
|
+
let mark = input.next == 33 /* Ch.Bang */ || input.next == 94 /* Ch.Caret */ ? 1 : 0;
|
|
1602
|
+
let end = nameEnd(input, mark);
|
|
1603
|
+
if (end < 0)
|
|
1604
|
+
return;
|
|
1605
|
+
if (stack.canShift(MethodName)) {
|
|
1606
|
+
if (!mark)
|
|
1607
|
+
input.acceptToken(MethodName, end);
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
end = categoryEnd(input, mark, end);
|
|
1611
|
+
if (!mark && stack.canShift(declaredName))
|
|
1612
|
+
input.acceptToken(declaredName, end);
|
|
1613
|
+
else if (stack.canShift(declaredMethodName))
|
|
1614
|
+
input.acceptToken(declaredMethodName, end);
|
|
1615
|
+
});
|
|
1616
|
+
// The type smiley in Int:D, Str:U and Any:_. It has to touch the type
|
|
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.
|
|
1623
|
+
const smileyToken = new lr.ExternalTokenizer((input, stack) => {
|
|
1624
|
+
if (!stack.canShift(noSmiley))
|
|
1625
|
+
return;
|
|
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);
|
|
1632
|
+
});
|
|
1633
|
+
// v6, v6.d, v1.2.3, v1.2+, v1.*. A name such as v8-engine is not a version.
|
|
1634
|
+
const versionToken = new lr.ExternalTokenizer((input, stack) => {
|
|
1635
|
+
if (input.next != 118 /* Ch.v */ || !isDigit(input.peek(1)) || !stack.canShift(Version))
|
|
1636
|
+
return;
|
|
1637
|
+
let pos = 2;
|
|
1638
|
+
for (;;) {
|
|
1639
|
+
while (isDigit(input.peek(pos)))
|
|
1640
|
+
pos++;
|
|
1641
|
+
if (input.peek(pos) != 46 /* Ch.Dot */)
|
|
1642
|
+
break;
|
|
1643
|
+
let part = input.peek(pos + 1);
|
|
1644
|
+
if (part == 42 /* Ch.Star */) {
|
|
1645
|
+
pos += 2;
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
if (isDigit(part))
|
|
1649
|
+
pos++;
|
|
1650
|
+
else if (isAsciiLetter(part)) {
|
|
1651
|
+
pos += 2;
|
|
1652
|
+
while (isAsciiLetter(input.peek(pos)))
|
|
1653
|
+
pos++;
|
|
1654
|
+
}
|
|
1655
|
+
else
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
if (input.peek(pos) == 43 /* Ch.Plus */)
|
|
1659
|
+
pos++;
|
|
1660
|
+
else if (continuesName(input, pos))
|
|
1661
|
+
return;
|
|
1662
|
+
input.acceptToken(Version, pos);
|
|
1663
|
+
});
|
|
1664
|
+
|
|
1665
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
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};
|
|
1668
|
+
const parser$1 = lr.LRParser.deserialize({
|
|
1669
|
+
version: 14,
|
|
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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PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP)X)s)y*^*hPPPPPPPPPPPPPPPPPPPPPPP*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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! Y~!#{P;=`<%l! Y~!$RP![!]!!p~!$ZO!P~~!$`O!O~",
|
|
1683
|
+
tokenizers: [smileyToken, blockComment, podToken, heredocToken, methodDotToken, 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
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
// The keywords of the grammar, with the tag each is highlighted with.
|
|
1690
|
+
// Highlighting and completion both read this table. `True`, `False` and
|
|
1691
|
+
// `Nil` are values, and are not in it.
|
|
1692
|
+
const keywordTags = {
|
|
1693
|
+
"my our has state temp let constant anon augment supersede unit multi proto only": highlight.tags.definitionKeyword,
|
|
1694
|
+
"class role grammar module package sub method submethod token rule regex enum subset": highlight.tags.definitionKeyword,
|
|
1695
|
+
"if elsif else unless with orwith without for while until loop repeat given when default": highlight.tags.controlKeyword,
|
|
1696
|
+
"do gather take try return next last redo proceed succeed react whenever supply emit start": highlight.tags.controlKeyword,
|
|
1697
|
+
"BEGIN CHECK INIT END ENTER LEAVE KEEP UNDO FIRST NEXT LAST PRE POST CATCH CONTROL QUIT CLOSE DOC": highlight.tags.controlKeyword,
|
|
1698
|
+
"use need import require no": highlight.tags.moduleKeyword,
|
|
1699
|
+
"is does of returns handles where will trusts hides": highlight.tags.modifier,
|
|
1700
|
+
"and or not xor so andthen orelse notandthen div mod gcd lcm": highlight.tags.operatorKeyword,
|
|
1701
|
+
"eq ne lt gt le ge cmp leg eqv but": highlight.tags.operatorKeyword,
|
|
1702
|
+
self: highlight.tags.self
|
|
1703
|
+
};
|
|
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
|
+
|
|
1978
|
+
function completions(type, ...labels) {
|
|
1979
|
+
return labels.join(" ").split(" ").map(label => ({ label, type }));
|
|
1980
|
+
}
|
|
1981
|
+
const keywords = completions("keyword", ...Object.keys(keywordTags));
|
|
1982
|
+
const constants = completions("constant", "True False Nil Inf NaN Empty pi tau");
|
|
1983
|
+
const types = completions("type", "Mu Any Cool Bool Int UInt Num Rat FatRat Complex Str Numeric Real Rational Stringy", "int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 num num32 num64 str", "Array List Seq Slip Range Hash Map Pair Set SetHash Bag BagHash Mix MixHash", "Positional Associative Iterable Iterator Callable Code Block Routine Sub Method Signature Parameter Capture", "Regex Match Grammar Junction Whatever Order Version", "IO IO::Path IO::Handle Proc Proc::Async Buf Blob", "Promise Supply Supplier Channel Lock Thread", "Date DateTime Duration Instant", "Exception Failure X::AdHoc");
|
|
1984
|
+
const routines = completions("function", "say put print note printf sprintf prompt get lines words slurp spurt open close", "dir mkdir rmdir unlink chdir shell run exit die warn fail sleep await now time rand srand", "elems end keys values kv pairs antipairs map grep first sort reverse join split comb", "push pop shift unshift append prepend splice flat unique squish classify categorize", "min max minmax sum pick roll zip cross reduce produce", "abs sqrt floor ceiling round truncate exp log sin cos", "chars chr ord uc lc tc flip trim chomp chop index rindex substr", "defined EVAL");
|
|
1985
|
+
const methods = completions("method", "new clone defined WHAT gist raku Str Int Num Rat Bool Numeric Array List Hash Set Bag Seq", "say put print note lines words slurp spurt open close", "elems end keys values kv pairs antipairs map grep first sort reverse join split comb", "push pop shift unshift append prepend splice flat unique squish classify categorize", "min max minmax sum pick roll reduce produce head tail skip rotor batch", "abs sqrt floor ceiling round truncate", "chars ord uc lc tc flip trim chomp chop index rindex substr subst match contains", "starts-with ends-with fmt succ pred exists then tap");
|
|
1986
|
+
const specialVariables = completions("variable", "$*IN $*OUT $*ERR $*ARGFILES @*ARGS %*ENV $*CWD $*HOME $*TMPDIR $*PROGRAM $*PROGRAM-NAME", "$*EXECUTABLE $*PID $*USER $*KERNEL $*DISTRO $*VM $*RAKU $*REPO $*SPEC $*TZ", "$*THREAD $*SCHEDULER $*INIT-INSTANT", "$?FILE $?LINE $?PACKAGE $?MODULE $?CLASS $?ROLE $?DISTRIBUTION %?RESOURCES &?ROUTINE &?BLOCK");
|
|
1987
|
+
const globals = [...keywords, ...constants, ...types, ...routines];
|
|
1988
|
+
// The offered names are all ASCII, so there is no need to follow the
|
|
1989
|
+
// grammar's notion of an identifier here.
|
|
1990
|
+
// A name cannot start with a colon: after a request at `f(|`, typing
|
|
1991
|
+
// `:key` is not a name from the list.
|
|
1992
|
+
const nameTail = /^(\w[\w:'\-]*)?$/;
|
|
1993
|
+
const specialVariableTail = /^[$@%&][*?][\w\-]*$/;
|
|
1994
|
+
const variableTail = /^[$@%&][!.^:]?[\w'\-]*$/;
|
|
1995
|
+
// Whether the position of `node` holds code, as opposed to the text of
|
|
1996
|
+
// a string, a regex, a comment or Pod. An interpolation is code again.
|
|
1997
|
+
function inCode(node) {
|
|
1998
|
+
var _a;
|
|
1999
|
+
for (; node; node = node.parent) {
|
|
2000
|
+
// The body of a regex declaration, which has no Regex node when it is empty.
|
|
2001
|
+
if (node.name == "Block" && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.name) == "RegexDeclaration")
|
|
2002
|
+
return false;
|
|
2003
|
+
if (/^(Interpolation|Block|Parens|Brackets)$/.test(node.name))
|
|
2004
|
+
return true;
|
|
2005
|
+
if (/^(StringLiteral|Heredoc|Regex|Pod|LineComment|DocComment|BlockComment)$/.test(node.name))
|
|
2006
|
+
return false;
|
|
2007
|
+
}
|
|
2008
|
+
return true;
|
|
2009
|
+
}
|
|
2010
|
+
// Whether the word at `node` is the name of a private method, as in
|
|
2011
|
+
// `self!name`: it follows a `!` that is attached to a term. A `!` after
|
|
2012
|
+
// anything else negates, as in `f(!defined $x)`.
|
|
2013
|
+
function isPrivateMethodName(tree, state, node) {
|
|
2014
|
+
let mark = tree.resolveInner(node.from, -1);
|
|
2015
|
+
if (mark.name != "Operator" || mark.to != node.from || state.sliceDoc(mark.from, mark.to) != "!")
|
|
2016
|
+
return false;
|
|
2017
|
+
let invocant = tree.resolveInner(mark.from, -1);
|
|
2018
|
+
return invocant.to == mark.from &&
|
|
2019
|
+
/^(self|VariableName|AttributeName|SpecialVariable|Identifier|TypeName|Parens|Brackets|[)\]])$/.test(invocant.name);
|
|
2020
|
+
}
|
|
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.
|
|
2041
|
+
const rakuCompletionSource = context => {
|
|
2042
|
+
let { state, pos } = context, tree = language.syntaxTree(state), node = tree.resolveInner(pos, -1);
|
|
2043
|
+
if (!inCode(node))
|
|
2044
|
+
return null;
|
|
2045
|
+
// `$*` alone is not a variable token yet.
|
|
2046
|
+
let special = node.name == "SpecialVariable" ? node : context.matchBefore(/[$@%&][*?]$/);
|
|
2047
|
+
if (special)
|
|
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);
|
|
2069
|
+
if (node.name == "MethodName")
|
|
2070
|
+
return { from: node.from, options: localMethods(), validFor: nameTail };
|
|
2071
|
+
// A dot or `.=` with no name after it yet. Two dots are a range operator.
|
|
2072
|
+
let before = state.sliceDoc(Math.max(0, pos - 2), pos);
|
|
2073
|
+
if (before == ".=")
|
|
2074
|
+
return { from: pos, options: localMethods(), validFor: nameTail };
|
|
2075
|
+
if (/(^|[^.])\.$/.test(before)) {
|
|
2076
|
+
// The dot of `1.5` and of `v6.d` is far more often typed than a
|
|
2077
|
+
// method call on a number.
|
|
2078
|
+
let numeric = /^(Number|Version)$/.test(tree.resolveInner(pos - 1, -1).name);
|
|
2079
|
+
return numeric && !context.explicit ? null : { from: pos, options: localMethods(), validFor: nameTail };
|
|
2080
|
+
}
|
|
2081
|
+
let localGlobals = () => withLocal(local.names.filter(completion => !hasSigil(completion)), globals);
|
|
2082
|
+
// A keyword's node is named after the keyword, as are those of `,` and `;`.
|
|
2083
|
+
let isKeyword = /^\w/.test(node.name) && node.name == state.sliceDoc(node.from, node.to);
|
|
2084
|
+
if (isKeyword || node.name == "Identifier" || node.name == "TypeName") {
|
|
2085
|
+
if (isPrivateMethodName(tree, state, node))
|
|
2086
|
+
return null;
|
|
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.
|
|
2093
|
+
let afterDotAssign = prev != null && prev.name == "Operator" && state.sliceDoc(prev.from, prev.to) == ".=";
|
|
2094
|
+
return { from: node.from, options: afterDotAssign ? localMethods() : localGlobals(), validFor: nameTail };
|
|
2095
|
+
}
|
|
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.
|
|
2099
|
+
if (context.explicit && /^[\s(\[{,;=]?$/.test(state.sliceDoc(Math.max(0, pos - 1), pos)))
|
|
2100
|
+
return { from: pos, options: localGlobals(), validFor: nameTail };
|
|
2101
|
+
return null;
|
|
2102
|
+
};
|
|
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
|
+
}
|
|
2371
|
+
/// The Lezer parser for Raku, without the editor-specific node props.
|
|
2372
|
+
const parser = parser$1.configure({ wrap: nestedParsers(parser$1) });
|
|
2373
|
+
const baseLanguage = language.LRLanguage.define({
|
|
2374
|
+
name: "raku",
|
|
2375
|
+
parser: parser$1.configure({
|
|
2376
|
+
props: [
|
|
2377
|
+
language.indentNodeProp.add({
|
|
2378
|
+
Program: topIndent,
|
|
2379
|
+
"Block Interpolation": statementIndent("}"),
|
|
2380
|
+
Parens: language.delimitedIndent({ closing: ")" }),
|
|
2381
|
+
Brackets: language.delimitedIndent({ closing: "]" }),
|
|
2382
|
+
// The lines of these are text, which keeps its indentation.
|
|
2383
|
+
"StringLiteral Heredoc Pod BlockComment": () => null
|
|
2384
|
+
}),
|
|
2385
|
+
language.foldNodeProp.add({
|
|
2386
|
+
"Block Parens Brackets": language.foldInside,
|
|
2387
|
+
BlockComment(tree) { return { from: tree.from + 2, to: tree.to }; },
|
|
2388
|
+
// Keep the first line, which holds the directive, visible.
|
|
2389
|
+
Pod(tree, state) { return { from: state.doc.lineAt(tree.from).to, to: tree.to }; },
|
|
2390
|
+
// A heredoc starts with the line break before its first line.
|
|
2391
|
+
Heredoc(tree) { return { from: tree.from, to: tree.to }; }
|
|
2392
|
+
}),
|
|
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 }))
|
|
2397
|
+
]
|
|
2398
|
+
}),
|
|
2399
|
+
languageData: {
|
|
2400
|
+
// An embedded comment can use any bracket. Parentheses are the usual choice.
|
|
2401
|
+
commentTokens: { line: "#", block: { open: "#`(", close: ")" } },
|
|
2402
|
+
closeBrackets: { brackets: ["(", "[", "{", "'", '"', "「"] },
|
|
2403
|
+
indentOnInput
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
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.
|
|
2412
|
+
const rakuCompletion = rakuLanguage.data.of({ autocomplete: rakuCompletionSource });
|
|
2413
|
+
/// Raku language support, with completion, and with block comment
|
|
2414
|
+
/// tokens that fit the selection.
|
|
2415
|
+
function raku() {
|
|
2416
|
+
return new language.LanguageSupport(rakuLanguage, [rakuCompletion, embeddedCommentTokens(rakuLanguage)]);
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
exports.parser = parser;
|
|
2420
|
+
exports.raku = raku;
|
|
2421
|
+
exports.rakuCompletion = rakuCompletion;
|
|
2422
|
+
exports.rakuLanguage = rakuLanguage;
|