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