@exercism/codemirror-lang-awk 0.0.0-stage → 2.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 +71 -0
- package/CODE_OF_CONDUCT.md +93 -0
- package/LICENSE +21 -0
- package/README.md +153 -2
- package/dist/completion.d.ts +5 -0
- package/dist/grammar.d.ts +11 -0
- package/dist/highlight.d.ts +7 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +852 -0
- package/dist/linter.d.ts +5 -0
- package/dist/theme.d.ts +9 -0
- package/dist/tokens.d.ts +27 -0
- package/package.json +54 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import { syntaxHighlighting as F, HighlightStyle as M, StreamLanguage as D, LanguageSupport as B } from "@codemirror/language";
|
|
2
|
+
import { snippet as d, autocompletion as O } from "@codemirror/autocomplete";
|
|
3
|
+
import { tags as n } from "@lezer/highlight";
|
|
4
|
+
import { linter as G } from "@codemirror/lint";
|
|
5
|
+
import { EditorView as _ } from "@codemirror/view";
|
|
6
|
+
const R = /* @__PURE__ */ new Set(["BEGIN", "END", "BEGINFILE", "ENDFILE"]), v = /* @__PURE__ */ new Set([
|
|
7
|
+
"if",
|
|
8
|
+
"else",
|
|
9
|
+
"while",
|
|
10
|
+
"do",
|
|
11
|
+
"for",
|
|
12
|
+
"in",
|
|
13
|
+
"break",
|
|
14
|
+
"continue",
|
|
15
|
+
"next",
|
|
16
|
+
"nextfile",
|
|
17
|
+
"exit",
|
|
18
|
+
"return",
|
|
19
|
+
"delete",
|
|
20
|
+
"function",
|
|
21
|
+
"func"
|
|
22
|
+
]), S = /* @__PURE__ */ new Set(["@include", "@load", "@namespace"]), N = /* @__PURE__ */ new Set([
|
|
23
|
+
// Standard AWK
|
|
24
|
+
"ARGC",
|
|
25
|
+
"ARGV",
|
|
26
|
+
"CONVFMT",
|
|
27
|
+
"ENVIRON",
|
|
28
|
+
"FILENAME",
|
|
29
|
+
"FNR",
|
|
30
|
+
"FS",
|
|
31
|
+
"NF",
|
|
32
|
+
"NR",
|
|
33
|
+
"OFMT",
|
|
34
|
+
"OFS",
|
|
35
|
+
"ORS",
|
|
36
|
+
"RLENGTH",
|
|
37
|
+
"RS",
|
|
38
|
+
"RSTART",
|
|
39
|
+
"SUBSEP",
|
|
40
|
+
// GNU AWK Extensions
|
|
41
|
+
"ARGIND",
|
|
42
|
+
"BINMODE",
|
|
43
|
+
"ERRNO",
|
|
44
|
+
"FIELDWIDTHS",
|
|
45
|
+
"FPAT",
|
|
46
|
+
"FUNCTAB",
|
|
47
|
+
"LINT",
|
|
48
|
+
"PREC",
|
|
49
|
+
"ROUNDMODE",
|
|
50
|
+
"RT",
|
|
51
|
+
"STRTAB",
|
|
52
|
+
"SYMTAB",
|
|
53
|
+
"TEXTDOMAIN"
|
|
54
|
+
]), k = {
|
|
55
|
+
// Math Functions
|
|
56
|
+
atan2: {
|
|
57
|
+
name: "atan2",
|
|
58
|
+
signature: "atan2(y, x)",
|
|
59
|
+
detail: "Math function",
|
|
60
|
+
doc: "Returns the arctangent of y/x in radians.",
|
|
61
|
+
type: "math"
|
|
62
|
+
},
|
|
63
|
+
cos: {
|
|
64
|
+
name: "cos",
|
|
65
|
+
signature: "cos(x)",
|
|
66
|
+
detail: "Math function",
|
|
67
|
+
doc: "Returns the cosine of x (x in radians).",
|
|
68
|
+
type: "math"
|
|
69
|
+
},
|
|
70
|
+
exp: {
|
|
71
|
+
name: "exp",
|
|
72
|
+
signature: "exp(x)",
|
|
73
|
+
detail: "Math function",
|
|
74
|
+
doc: "Returns the exponential function of x (e^x).",
|
|
75
|
+
type: "math"
|
|
76
|
+
},
|
|
77
|
+
int: {
|
|
78
|
+
name: "int",
|
|
79
|
+
signature: "int(x)",
|
|
80
|
+
detail: "Math function",
|
|
81
|
+
doc: "Truncates x to an integer value towards zero.",
|
|
82
|
+
type: "math"
|
|
83
|
+
},
|
|
84
|
+
log: {
|
|
85
|
+
name: "log",
|
|
86
|
+
signature: "log(x)",
|
|
87
|
+
detail: "Math function",
|
|
88
|
+
doc: "Returns the natural logarithm of x.",
|
|
89
|
+
type: "math"
|
|
90
|
+
},
|
|
91
|
+
rand: {
|
|
92
|
+
name: "rand",
|
|
93
|
+
signature: "rand()",
|
|
94
|
+
detail: "Math function",
|
|
95
|
+
doc: "Returns a random floating point number r such that 0 <= r < 1.",
|
|
96
|
+
type: "math"
|
|
97
|
+
},
|
|
98
|
+
sin: {
|
|
99
|
+
name: "sin",
|
|
100
|
+
signature: "sin(x)",
|
|
101
|
+
detail: "Math function",
|
|
102
|
+
doc: "Returns the sine of x (x in radians).",
|
|
103
|
+
type: "math"
|
|
104
|
+
},
|
|
105
|
+
sqrt: {
|
|
106
|
+
name: "sqrt",
|
|
107
|
+
signature: "sqrt(x)",
|
|
108
|
+
detail: "Math function",
|
|
109
|
+
doc: "Returns the square root of x.",
|
|
110
|
+
type: "math"
|
|
111
|
+
},
|
|
112
|
+
srand: {
|
|
113
|
+
name: "srand",
|
|
114
|
+
signature: "srand([x])",
|
|
115
|
+
detail: "Math function",
|
|
116
|
+
doc: "Sets the seed for rand() to x and returns the previous seed. If x omitted, uses current time.",
|
|
117
|
+
type: "math"
|
|
118
|
+
},
|
|
119
|
+
// String Functions
|
|
120
|
+
asort: {
|
|
121
|
+
name: "asort",
|
|
122
|
+
signature: "asort(source [, dest [, how]])",
|
|
123
|
+
detail: "gawk String / Array function",
|
|
124
|
+
doc: "Sorts array source by values. If dest given, source is duplicated into dest before sorting.",
|
|
125
|
+
type: "string"
|
|
126
|
+
},
|
|
127
|
+
asorti: {
|
|
128
|
+
name: "asorti",
|
|
129
|
+
signature: "asorti(source [, dest [, how]])",
|
|
130
|
+
detail: "gawk String / Array function",
|
|
131
|
+
doc: "Sorts array source by indices instead of values into dest array.",
|
|
132
|
+
type: "string"
|
|
133
|
+
},
|
|
134
|
+
gensub: {
|
|
135
|
+
name: "gensub",
|
|
136
|
+
signature: "gensub(regex, replacement, how [, target])",
|
|
137
|
+
detail: "gawk String function",
|
|
138
|
+
doc: 'Substitutes replacement for regex in target (or $0). how can be "g", "G", or a number N for Nth match.',
|
|
139
|
+
type: "string"
|
|
140
|
+
},
|
|
141
|
+
gsub: {
|
|
142
|
+
name: "gsub",
|
|
143
|
+
signature: "gsub(regex, replacement [, target])",
|
|
144
|
+
detail: "String function",
|
|
145
|
+
doc: "Globally substitutes replacement for regex in target (or $0). Returns number of substitutions made.",
|
|
146
|
+
type: "string"
|
|
147
|
+
},
|
|
148
|
+
index: {
|
|
149
|
+
name: "index",
|
|
150
|
+
signature: "index(str, target)",
|
|
151
|
+
detail: "String function",
|
|
152
|
+
doc: "Returns the 1-based position of target substring in str, or 0 if not found.",
|
|
153
|
+
type: "string"
|
|
154
|
+
},
|
|
155
|
+
length: {
|
|
156
|
+
name: "length",
|
|
157
|
+
signature: "length([str_or_arr])",
|
|
158
|
+
detail: "String / Array function",
|
|
159
|
+
doc: "Returns the length of string str or number of elements in array. Defaults to length($0).",
|
|
160
|
+
type: "string"
|
|
161
|
+
},
|
|
162
|
+
match: {
|
|
163
|
+
name: "match",
|
|
164
|
+
signature: "match(str, regex [, array])",
|
|
165
|
+
detail: "String function",
|
|
166
|
+
doc: "Searches str for regex match. Sets RSTART, RLENGTH, and populates submatch array in gawk.",
|
|
167
|
+
type: "string"
|
|
168
|
+
},
|
|
169
|
+
patsplit: {
|
|
170
|
+
name: "patsplit",
|
|
171
|
+
signature: "patsplit(str, arr [, regex [, seps]])",
|
|
172
|
+
detail: "gawk String function",
|
|
173
|
+
doc: "Splits str into arr matching regex pattern instead of field separators.",
|
|
174
|
+
type: "string"
|
|
175
|
+
},
|
|
176
|
+
split: {
|
|
177
|
+
name: "split",
|
|
178
|
+
signature: "split(str, arr [, regex [, seps]])",
|
|
179
|
+
detail: "String function",
|
|
180
|
+
doc: "Splits str into arr elements indexed from 1 using field separator regex (or FS).",
|
|
181
|
+
type: "string"
|
|
182
|
+
},
|
|
183
|
+
sprintf: {
|
|
184
|
+
name: "sprintf",
|
|
185
|
+
signature: "sprintf(fmt, expr1, ...)",
|
|
186
|
+
detail: "String function",
|
|
187
|
+
doc: "Formats expressions according to printf format specifier fmt and returns string.",
|
|
188
|
+
type: "string"
|
|
189
|
+
},
|
|
190
|
+
strtonum: {
|
|
191
|
+
name: "strtonum",
|
|
192
|
+
signature: "strtonum(str)",
|
|
193
|
+
detail: "gawk String function",
|
|
194
|
+
doc: "Examines str and returns numeric value. Supports decimal, octal (leading 0), and hex (leading 0x/0X).",
|
|
195
|
+
type: "string"
|
|
196
|
+
},
|
|
197
|
+
sub: {
|
|
198
|
+
name: "sub",
|
|
199
|
+
signature: "sub(regex, replacement [, target])",
|
|
200
|
+
detail: "String function",
|
|
201
|
+
doc: "Substitutes first match of regex with replacement in target (or $0). Returns 1 if matched, else 0.",
|
|
202
|
+
type: "string"
|
|
203
|
+
},
|
|
204
|
+
substr: {
|
|
205
|
+
name: "substr",
|
|
206
|
+
signature: "substr(str, start [, length])",
|
|
207
|
+
detail: "String function",
|
|
208
|
+
doc: "Returns substring of str starting at 1-based start index up to length characters.",
|
|
209
|
+
type: "string"
|
|
210
|
+
},
|
|
211
|
+
tolower: {
|
|
212
|
+
name: "tolower",
|
|
213
|
+
signature: "tolower(str)",
|
|
214
|
+
detail: "String function",
|
|
215
|
+
doc: "Returns copy of str converted to lowercase.",
|
|
216
|
+
type: "string"
|
|
217
|
+
},
|
|
218
|
+
toupper: {
|
|
219
|
+
name: "toupper",
|
|
220
|
+
signature: "toupper(str)",
|
|
221
|
+
detail: "String function",
|
|
222
|
+
doc: "Returns copy of str converted to uppercase.",
|
|
223
|
+
type: "string"
|
|
224
|
+
},
|
|
225
|
+
// Time Functions (GNU AWK)
|
|
226
|
+
mktime: {
|
|
227
|
+
name: "mktime",
|
|
228
|
+
signature: "mktime(datespec [, utc])",
|
|
229
|
+
detail: "gawk Time function",
|
|
230
|
+
doc: 'Converts "YYYY MM DD HH MM SS [DST]" datespec into epoch timestamp in seconds.',
|
|
231
|
+
type: "time"
|
|
232
|
+
},
|
|
233
|
+
strftime: {
|
|
234
|
+
name: "strftime",
|
|
235
|
+
signature: "strftime([fmt [, timestamp [, utc]]])",
|
|
236
|
+
detail: "gawk Time function",
|
|
237
|
+
doc: "Formats timestamp (or current time) using strftime format specifier fmt.",
|
|
238
|
+
type: "time"
|
|
239
|
+
},
|
|
240
|
+
systime: {
|
|
241
|
+
name: "systime",
|
|
242
|
+
signature: "systime()",
|
|
243
|
+
detail: "gawk Time function",
|
|
244
|
+
doc: "Returns current time as number of seconds since POSIX epoch.",
|
|
245
|
+
type: "time"
|
|
246
|
+
},
|
|
247
|
+
// Bitwise Functions (GNU AWK)
|
|
248
|
+
and: {
|
|
249
|
+
name: "and",
|
|
250
|
+
signature: "and(v1, v2, ...)",
|
|
251
|
+
detail: "gawk Bitwise function",
|
|
252
|
+
doc: "Returns bitwise AND of arguments.",
|
|
253
|
+
type: "bitwise"
|
|
254
|
+
},
|
|
255
|
+
compl: {
|
|
256
|
+
name: "compl",
|
|
257
|
+
signature: "compl(val)",
|
|
258
|
+
detail: "gawk Bitwise function",
|
|
259
|
+
doc: "Returns bitwise complement (NOT) of val.",
|
|
260
|
+
type: "bitwise"
|
|
261
|
+
},
|
|
262
|
+
lshift: {
|
|
263
|
+
name: "lshift",
|
|
264
|
+
signature: "lshift(val, count)",
|
|
265
|
+
detail: "gawk Bitwise function",
|
|
266
|
+
doc: "Returns val shifted left by count bits.",
|
|
267
|
+
type: "bitwise"
|
|
268
|
+
},
|
|
269
|
+
rshift: {
|
|
270
|
+
name: "rshift",
|
|
271
|
+
signature: "rshift(val, count)",
|
|
272
|
+
detail: "gawk Bitwise function",
|
|
273
|
+
doc: "Returns val shifted right by count bits.",
|
|
274
|
+
type: "bitwise"
|
|
275
|
+
},
|
|
276
|
+
or: {
|
|
277
|
+
name: "or",
|
|
278
|
+
signature: "or(v1, v2, ...)",
|
|
279
|
+
detail: "gawk Bitwise function",
|
|
280
|
+
doc: "Returns bitwise OR of arguments.",
|
|
281
|
+
type: "bitwise"
|
|
282
|
+
},
|
|
283
|
+
xor: {
|
|
284
|
+
name: "xor",
|
|
285
|
+
signature: "xor(v1, v2, ...)",
|
|
286
|
+
detail: "gawk Bitwise function",
|
|
287
|
+
doc: "Returns bitwise exclusive OR (XOR) of arguments.",
|
|
288
|
+
type: "bitwise"
|
|
289
|
+
},
|
|
290
|
+
// Type & I/O Functions
|
|
291
|
+
isarray: {
|
|
292
|
+
name: "isarray",
|
|
293
|
+
signature: "isarray(x)",
|
|
294
|
+
detail: "gawk Type function",
|
|
295
|
+
doc: "Returns 1 if x is an array, else 0.",
|
|
296
|
+
type: "gawk"
|
|
297
|
+
},
|
|
298
|
+
typeof: {
|
|
299
|
+
name: "typeof",
|
|
300
|
+
signature: "typeof(x)",
|
|
301
|
+
detail: "gawk Type function",
|
|
302
|
+
doc: 'Returns string indicating type of x ("array", "number", "string", "regexp", "unassigned", "untyped").',
|
|
303
|
+
type: "gawk"
|
|
304
|
+
},
|
|
305
|
+
close: {
|
|
306
|
+
name: "close",
|
|
307
|
+
signature: "close(filename_or_cmd [, how])",
|
|
308
|
+
detail: "I/O function",
|
|
309
|
+
doc: "Closes an open file or pipe connection.",
|
|
310
|
+
type: "io"
|
|
311
|
+
},
|
|
312
|
+
fflush: {
|
|
313
|
+
name: "fflush",
|
|
314
|
+
signature: "fflush([filename_or_cmd])",
|
|
315
|
+
detail: "I/O function",
|
|
316
|
+
doc: "Flushes pending output buffers for file/pipe or stdout if omitted.",
|
|
317
|
+
type: "io"
|
|
318
|
+
},
|
|
319
|
+
system: {
|
|
320
|
+
name: "system",
|
|
321
|
+
signature: "system(command)",
|
|
322
|
+
detail: "I/O function",
|
|
323
|
+
doc: "Executes operating system shell command and returns its exit status.",
|
|
324
|
+
type: "io"
|
|
325
|
+
},
|
|
326
|
+
// Internationalization (GNU AWK)
|
|
327
|
+
bindtextdomain: {
|
|
328
|
+
name: "bindtextdomain",
|
|
329
|
+
signature: "bindtextdomain(dir [, domain])",
|
|
330
|
+
detail: "gawk i18n function",
|
|
331
|
+
doc: "Specifies directory for searching text domain MO files.",
|
|
332
|
+
type: "gawk"
|
|
333
|
+
},
|
|
334
|
+
dcgettext: {
|
|
335
|
+
name: "dcgettext",
|
|
336
|
+
signature: "dcgettext(string [, domain [, category]])",
|
|
337
|
+
detail: "gawk i18n function",
|
|
338
|
+
doc: "Returns localized translation of string for domain and category.",
|
|
339
|
+
type: "gawk"
|
|
340
|
+
},
|
|
341
|
+
dcngettext: {
|
|
342
|
+
name: "dcngettext",
|
|
343
|
+
signature: "dcngettext(string1, string2, number [, domain [, category]])",
|
|
344
|
+
detail: "gawk i18n function",
|
|
345
|
+
doc: "Returns plural-aware localized translation of string for number.",
|
|
346
|
+
type: "gawk"
|
|
347
|
+
}
|
|
348
|
+
}, L = {
|
|
349
|
+
name: "awk",
|
|
350
|
+
tokenTable: {
|
|
351
|
+
"special(keyword)": n.special(n.keyword),
|
|
352
|
+
"special(variableName)": n.special(n.variableName),
|
|
353
|
+
"standard(variableName)": n.standard(n.variableName),
|
|
354
|
+
"standard(name)": n.standard(n.name),
|
|
355
|
+
"function(definition)": n.definition(n.function(n.variableName)),
|
|
356
|
+
"function(call)": n.function(n.variableName)
|
|
357
|
+
},
|
|
358
|
+
startState() {
|
|
359
|
+
return {
|
|
360
|
+
inString: !1,
|
|
361
|
+
stringQuote: '"',
|
|
362
|
+
inRegex: !1,
|
|
363
|
+
expectRegex: !0,
|
|
364
|
+
inComment: !1,
|
|
365
|
+
inDirective: !1,
|
|
366
|
+
lastToken: ""
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
token(t, e) {
|
|
370
|
+
if (t.eatSpace())
|
|
371
|
+
return null;
|
|
372
|
+
if (t.peek() === "#")
|
|
373
|
+
return t.skipToEnd(), e.expectRegex = !0, "comment";
|
|
374
|
+
if (e.inString) {
|
|
375
|
+
let i = !1;
|
|
376
|
+
for (; !t.eol(); ) {
|
|
377
|
+
const c = t.next();
|
|
378
|
+
if (i)
|
|
379
|
+
i = !1;
|
|
380
|
+
else if (c === "\\")
|
|
381
|
+
i = !0;
|
|
382
|
+
else if (c === e.stringQuote)
|
|
383
|
+
return e.inString = !1, e.expectRegex = !1, "string";
|
|
384
|
+
}
|
|
385
|
+
return i || (e.inString = !1), "string";
|
|
386
|
+
}
|
|
387
|
+
if (e.inRegex) {
|
|
388
|
+
let i = !1;
|
|
389
|
+
for (; !t.eol(); ) {
|
|
390
|
+
const c = t.next();
|
|
391
|
+
if (i)
|
|
392
|
+
i = !1;
|
|
393
|
+
else if (c === "\\")
|
|
394
|
+
i = !0;
|
|
395
|
+
else if (c === "/")
|
|
396
|
+
return e.inRegex = !1, e.expectRegex = !1, "regexp";
|
|
397
|
+
}
|
|
398
|
+
return i || (e.inRegex = !1), "regexp";
|
|
399
|
+
}
|
|
400
|
+
if (t.peek() === "@") {
|
|
401
|
+
t.eat("@"), t.eatWhile(/[\w_]/);
|
|
402
|
+
const i = t.current();
|
|
403
|
+
return e.expectRegex = !0, S.has(i) ? (e.lastToken = i, "processingInstruction") : "keyword";
|
|
404
|
+
}
|
|
405
|
+
if (t.peek() === '"')
|
|
406
|
+
return t.next(), e.inString = !0, e.stringQuote = '"', "string";
|
|
407
|
+
if (t.peek() === "/")
|
|
408
|
+
return e.expectRegex ? (t.next(), e.inRegex = !0, "regexp") : (t.next(), t.peek() === "=" ? (t.next(), e.lastToken = "/=") : e.lastToken = "/", e.expectRegex = !0, "operator");
|
|
409
|
+
if (t.peek() === "$")
|
|
410
|
+
return t.next(), t.match(/^\d+/) || t.match(/^[A-Za-z_][A-Za-z0-9_]*/) ? (e.expectRegex = !1, "special(variableName)") : (e.expectRegex = !0, "operator");
|
|
411
|
+
if (t.match(/^0[xX][0-9a-fA-F]+/) || t.match(/^\d+(\.\d+)?([eE][+-]?\d+)?/))
|
|
412
|
+
return e.expectRegex = !1, "number";
|
|
413
|
+
if (t.match(/^(~|!~|\+\+|--|&&|\|\||\|&|==|!=|<=|>=|\+=|-=|\*=|\/=|%=|\^=|\*\*=|<<|>>|\*\*)/))
|
|
414
|
+
return e.expectRegex = !0, "operator";
|
|
415
|
+
const u = t.next();
|
|
416
|
+
if ("+-*%^=<>!~|&".includes(u))
|
|
417
|
+
return e.expectRegex = !0, "operator";
|
|
418
|
+
if ("{}()[];,".includes(u))
|
|
419
|
+
return u === ")" || u === "}" ? e.expectRegex = !1 : e.expectRegex = !0, "punctuation";
|
|
420
|
+
if (/[A-Za-z_]/.test(u)) {
|
|
421
|
+
t.eatWhile(/[\w_]/);
|
|
422
|
+
const i = t.current();
|
|
423
|
+
return R.has(i) ? (e.expectRegex = !0, e.lastToken = i, "special(keyword)") : v.has(i) ? (e.expectRegex = !0, e.lastToken = i, "keyword") : N.has(i) ? (e.expectRegex = !1, e.lastToken = i, "standard(variableName)") : k[i] ? (e.expectRegex = !0, e.lastToken = i, "standard(name)") : e.lastToken === "function" || e.lastToken === "func" ? (e.expectRegex = !1, "function(definition)") : t.peek() === "(" ? (e.expectRegex = !0, "function(call)") : (e.expectRegex = !1, e.lastToken = i, "variableName");
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
},
|
|
427
|
+
indent(t, e) {
|
|
428
|
+
return e.startsWith("}") ? 0 : 2;
|
|
429
|
+
}
|
|
430
|
+
}, U = [
|
|
431
|
+
{ tag: n.keyword, class: "cm-awk-keyword" },
|
|
432
|
+
{ tag: n.special(n.keyword), class: "cm-awk-pattern" },
|
|
433
|
+
{ tag: n.processingInstruction, class: "cm-awk-directive" },
|
|
434
|
+
{ tag: n.meta, class: "cm-awk-directive" },
|
|
435
|
+
{ tag: n.standard(n.variableName), class: "cm-awk-builtin-var" },
|
|
436
|
+
{ tag: n.special(n.variableName), class: "cm-awk-field" },
|
|
437
|
+
{ tag: n.standard(n.name), class: "cm-awk-builtin-func" },
|
|
438
|
+
{ tag: n.definition(n.function(n.variableName)), class: "cm-awk-func-def" },
|
|
439
|
+
{ tag: n.function(n.variableName), class: "cm-awk-func-call" },
|
|
440
|
+
{ tag: n.string, class: "cm-awk-string" },
|
|
441
|
+
{ tag: n.regexp, class: "cm-awk-regex" },
|
|
442
|
+
{ tag: n.number, class: "cm-awk-number" },
|
|
443
|
+
{ tag: n.comment, class: "cm-awk-comment" },
|
|
444
|
+
{ tag: n.operator, class: "cm-awk-operator" },
|
|
445
|
+
{ tag: n.punctuation, class: "cm-awk-punctuation" }
|
|
446
|
+
], E = Array.from(S).map((t) => ({
|
|
447
|
+
label: t,
|
|
448
|
+
type: "keyword",
|
|
449
|
+
detail: "GNU AWK Directive",
|
|
450
|
+
boost: 10
|
|
451
|
+
})), z = Array.from(R).map((t) => ({
|
|
452
|
+
label: t,
|
|
453
|
+
type: "type",
|
|
454
|
+
detail: "Pattern Block",
|
|
455
|
+
boost: 8
|
|
456
|
+
})), P = Array.from(v).map((t) => ({
|
|
457
|
+
label: t,
|
|
458
|
+
type: "keyword",
|
|
459
|
+
detail: "Control Keyword"
|
|
460
|
+
})), Z = Array.from(N).map((t) => ({
|
|
461
|
+
label: t,
|
|
462
|
+
type: "variable",
|
|
463
|
+
detail: "GNU AWK Built-in Variable",
|
|
464
|
+
boost: 2
|
|
465
|
+
})), K = Object.values(k).map((t) => ({
|
|
466
|
+
label: t.name,
|
|
467
|
+
type: "function",
|
|
468
|
+
detail: t.signature,
|
|
469
|
+
info: `${t.detail}
|
|
470
|
+
|
|
471
|
+
${t.doc}`,
|
|
472
|
+
boost: 3
|
|
473
|
+
})), I = [
|
|
474
|
+
{
|
|
475
|
+
label: "BEGIN",
|
|
476
|
+
type: "snippet",
|
|
477
|
+
detail: "BEGIN pattern block",
|
|
478
|
+
apply: d(`BEGIN {
|
|
479
|
+
\${1}
|
|
480
|
+
}`),
|
|
481
|
+
boost: 9
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
label: "END",
|
|
485
|
+
type: "snippet",
|
|
486
|
+
detail: "END pattern block",
|
|
487
|
+
apply: d(`END {
|
|
488
|
+
\${1}
|
|
489
|
+
}`),
|
|
490
|
+
boost: 9
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
label: "function",
|
|
494
|
+
type: "snippet",
|
|
495
|
+
detail: "User-defined function definition",
|
|
496
|
+
apply: d("function ${1:name}(${2:args}) {\n ${3}\n}"),
|
|
497
|
+
boost: 9
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
label: "for (in)",
|
|
501
|
+
type: "snippet",
|
|
502
|
+
detail: "Array iteration loop",
|
|
503
|
+
apply: d("for (${1:key} in ${2:array}) {\n ${3}\n}"),
|
|
504
|
+
boost: 8
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
label: "for (i=1..n)",
|
|
508
|
+
type: "snippet",
|
|
509
|
+
detail: "Numeric count loop",
|
|
510
|
+
apply: d("for (${1:i} = 1; ${1:i} <= ${2:n}; ${1:i}++) {\n ${3}\n}"),
|
|
511
|
+
boost: 8
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
label: "if",
|
|
515
|
+
type: "snippet",
|
|
516
|
+
detail: "Conditional statement",
|
|
517
|
+
apply: d("if (${1:condition}) {\n ${2}\n}"),
|
|
518
|
+
boost: 8
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
label: "if-else",
|
|
522
|
+
type: "snippet",
|
|
523
|
+
detail: "If-else statement",
|
|
524
|
+
apply: d(`if (\${1:condition}) {
|
|
525
|
+
\${2}
|
|
526
|
+
} else {
|
|
527
|
+
\${3}
|
|
528
|
+
}`),
|
|
529
|
+
boost: 8
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
label: "@include",
|
|
533
|
+
type: "snippet",
|
|
534
|
+
detail: "Include AWK source file",
|
|
535
|
+
apply: d('@include "${1:filename.awk}"'),
|
|
536
|
+
boost: 10
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
label: "@namespace",
|
|
540
|
+
type: "snippet",
|
|
541
|
+
detail: "GNU AWK Namespace definition",
|
|
542
|
+
apply: d('@namespace "${1:name}"'),
|
|
543
|
+
boost: 10
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
label: "@load",
|
|
547
|
+
type: "snippet",
|
|
548
|
+
detail: "Load shared extension library",
|
|
549
|
+
apply: d('@load "${1:extension}"'),
|
|
550
|
+
boost: 10
|
|
551
|
+
}
|
|
552
|
+
];
|
|
553
|
+
function H(t) {
|
|
554
|
+
const e = /* @__PURE__ */ new Map(), u = /\b(?:function|func)\s+([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
555
|
+
let i;
|
|
556
|
+
for (; (i = u.exec(t)) !== null; ) {
|
|
557
|
+
const a = i[1];
|
|
558
|
+
k[a] || e.set(a, {
|
|
559
|
+
label: a,
|
|
560
|
+
type: "function",
|
|
561
|
+
detail: "User Function",
|
|
562
|
+
boost: 5
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
const c = /\b([A-Za-z_][A-Za-z0-9_]*)\b/g;
|
|
566
|
+
for (; (i = c.exec(t)) !== null; ) {
|
|
567
|
+
const a = i[1];
|
|
568
|
+
!v.has(a) && !R.has(a) && !N.has(a) && !k[a] && !e.has(a) && e.set(a, {
|
|
569
|
+
label: a,
|
|
570
|
+
type: "variable",
|
|
571
|
+
detail: "Document Variable"
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
return Array.from(e.values());
|
|
575
|
+
}
|
|
576
|
+
function V(t) {
|
|
577
|
+
const e = t.matchBefore(/@[\w_]*|[A-Za-z_][A-Za-z0-9_]*/);
|
|
578
|
+
if (!e || e.from === e.to && !t.explicit)
|
|
579
|
+
return null;
|
|
580
|
+
if (e.text.startsWith("@"))
|
|
581
|
+
return {
|
|
582
|
+
from: e.from,
|
|
583
|
+
options: [...E, ...I.filter((a) => a.label.startsWith("@"))],
|
|
584
|
+
validFor: /^@[\w_]*$/
|
|
585
|
+
};
|
|
586
|
+
const i = t.state.doc.toString(), c = H(i);
|
|
587
|
+
return {
|
|
588
|
+
from: e.from,
|
|
589
|
+
options: [
|
|
590
|
+
...I,
|
|
591
|
+
...z,
|
|
592
|
+
...E,
|
|
593
|
+
...P,
|
|
594
|
+
...K,
|
|
595
|
+
...Z,
|
|
596
|
+
...c
|
|
597
|
+
],
|
|
598
|
+
validFor: /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function q() {
|
|
602
|
+
return G((t) => {
|
|
603
|
+
const e = [], u = t.state.doc, i = u.lines;
|
|
604
|
+
let c = [], a = [];
|
|
605
|
+
for (let f = 1; f <= i; f++) {
|
|
606
|
+
const s = u.line(f), b = s.text, T = b.indexOf("#"), l = T !== -1 ? b.slice(0, T) : b, A = b.match(/@([a-zA-Z0-9_]+)/g);
|
|
607
|
+
if (A) {
|
|
608
|
+
for (const r of A)
|
|
609
|
+
if (!S.has(r)) {
|
|
610
|
+
const o = s.from + b.indexOf(r);
|
|
611
|
+
e.push({
|
|
612
|
+
from: o,
|
|
613
|
+
to: o + r.length,
|
|
614
|
+
severity: "error",
|
|
615
|
+
message: `Unknown GNU AWK directive '${r}'. Valid directives: @include, @load, @namespace.`
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (/@include\s*(?!["<])/.test(l)) {
|
|
620
|
+
const r = s.from + l.indexOf("@include");
|
|
621
|
+
e.push({
|
|
622
|
+
from: r,
|
|
623
|
+
to: r + 8,
|
|
624
|
+
severity: "warning",
|
|
625
|
+
message: '@include directive expects a quoted filename e.g. @include "filename.awk"'
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
if (/@namespace\s*(?!["<])/.test(l)) {
|
|
629
|
+
const r = s.from + l.indexOf("@namespace");
|
|
630
|
+
e.push({
|
|
631
|
+
from: r,
|
|
632
|
+
to: r + 10,
|
|
633
|
+
severity: "warning",
|
|
634
|
+
message: '@namespace directive expects a quoted string e.g. @namespace "my_module"'
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
const h = l.match(/\b(?:function|func)\b/);
|
|
638
|
+
if (h) {
|
|
639
|
+
const r = l.slice(h.index + h[0].length).trim();
|
|
640
|
+
if (r === "" || r.startsWith("{") || r.startsWith("(")) {
|
|
641
|
+
const o = s.from + h.index;
|
|
642
|
+
e.push({
|
|
643
|
+
from: o,
|
|
644
|
+
to: o + h[0].length,
|
|
645
|
+
severity: "error",
|
|
646
|
+
message: "Function definition missing function name."
|
|
647
|
+
});
|
|
648
|
+
} else {
|
|
649
|
+
const o = l.match(/\b(?:function|func)\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
650
|
+
if (o) {
|
|
651
|
+
const p = o[1];
|
|
652
|
+
if (!l.slice(o.index + o[0].length).trim().startsWith("(")) {
|
|
653
|
+
const m = s.from + o.index;
|
|
654
|
+
e.push({
|
|
655
|
+
from: m,
|
|
656
|
+
to: m + o[0].length,
|
|
657
|
+
severity: "error",
|
|
658
|
+
message: `Function definition '${p}' missing parameter parentheses '()'.`
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
let x = !1, C = "", W = 0, y = !1, $ = 0, w = !1;
|
|
665
|
+
for (let r = 0; r < l.length; r++) {
|
|
666
|
+
const o = l[r], p = r > 0 ? l[r - 1] : "";
|
|
667
|
+
if (x)
|
|
668
|
+
o === C && p !== "\\" && (x = !1);
|
|
669
|
+
else if (y)
|
|
670
|
+
o === "[" && p !== "\\" ? w = !0 : o === "]" && p !== "\\" ? w = !1 : o === "/" && p !== "\\" && !w && (y = !1);
|
|
671
|
+
else if (o === '"')
|
|
672
|
+
x = !0, C = '"', W = s.from + r;
|
|
673
|
+
else if (o === "/") {
|
|
674
|
+
const g = l.slice(0, r).trim();
|
|
675
|
+
(g === "" || /[=~,\(\!\?\:\{\;\+\-\*\%\&\|]$/.test(g) || /\b(print|printf|return|match|sub|gsub|gensub|patsplit|split|if|while)\s*$/i.test(g)) && (y = !0, w = !1, $ = s.from + r);
|
|
676
|
+
} else if (o === "{") {
|
|
677
|
+
const g = a.filter((m) => m.line === f);
|
|
678
|
+
for (const m of g)
|
|
679
|
+
e.push({
|
|
680
|
+
from: m.pos,
|
|
681
|
+
to: m.pos + 1,
|
|
682
|
+
severity: "error",
|
|
683
|
+
message: 'Unclosed parenthesis "(" in condition before brace.'
|
|
684
|
+
});
|
|
685
|
+
a = a.filter((m) => m.line !== f), c.push({ pos: s.from + r, line: f });
|
|
686
|
+
} else o === "}" ? c.length > 0 ? c.pop() : e.push({
|
|
687
|
+
from: s.from + r,
|
|
688
|
+
to: s.from + r + 1,
|
|
689
|
+
severity: "error",
|
|
690
|
+
message: 'Unmatched closing brace "}".'
|
|
691
|
+
}) : o === "(" ? a.push({ pos: s.from + r, line: f }) : o === ")" && (a.length > 0 ? a.pop() : e.push({
|
|
692
|
+
from: s.from + r,
|
|
693
|
+
to: s.from + r + 1,
|
|
694
|
+
severity: "error",
|
|
695
|
+
message: 'Unmatched closing parenthesis ")".'
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
x && !l.endsWith("\\") && e.push({
|
|
699
|
+
from: W,
|
|
700
|
+
to: s.to,
|
|
701
|
+
severity: "error",
|
|
702
|
+
message: "Unterminated string literal."
|
|
703
|
+
}), y && !l.endsWith("\\") && e.push({
|
|
704
|
+
from: $,
|
|
705
|
+
to: s.to,
|
|
706
|
+
severity: "error",
|
|
707
|
+
message: "Unterminated regular expression."
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
for (const f of c)
|
|
711
|
+
e.push({
|
|
712
|
+
from: f.pos,
|
|
713
|
+
to: f.pos + 1,
|
|
714
|
+
severity: "error",
|
|
715
|
+
message: 'Unclosed brace "{"'
|
|
716
|
+
});
|
|
717
|
+
for (const f of a)
|
|
718
|
+
e.push({
|
|
719
|
+
from: f.pos,
|
|
720
|
+
to: f.pos + 1,
|
|
721
|
+
severity: "error",
|
|
722
|
+
message: 'Unclosed parenthesis "("'
|
|
723
|
+
});
|
|
724
|
+
return e;
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
const ne = _.theme(
|
|
728
|
+
{
|
|
729
|
+
"&": {
|
|
730
|
+
backgroundColor: "#0f172a",
|
|
731
|
+
color: "#f8fafc",
|
|
732
|
+
fontFamily: "'Fira Code', 'JetBrains Mono', 'Source Code Pro', monospace",
|
|
733
|
+
fontSize: "14px",
|
|
734
|
+
borderRadius: "8px"
|
|
735
|
+
},
|
|
736
|
+
".cm-content": {
|
|
737
|
+
caretColor: "#38bdf8"
|
|
738
|
+
},
|
|
739
|
+
".cm-cursor, .cm-dropCursor": {
|
|
740
|
+
borderLeftColor: "#38bdf8"
|
|
741
|
+
},
|
|
742
|
+
"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
|
|
743
|
+
backgroundColor: "#1e293b"
|
|
744
|
+
},
|
|
745
|
+
".cm-activeLine": {
|
|
746
|
+
backgroundColor: "rgba(51, 65, 85, 0.4)"
|
|
747
|
+
},
|
|
748
|
+
".cm-gutters": {
|
|
749
|
+
backgroundColor: "#0b1329",
|
|
750
|
+
color: "#64748b",
|
|
751
|
+
borderRight: "1px solid #1e293b"
|
|
752
|
+
},
|
|
753
|
+
".cm-activeLineGutter": {
|
|
754
|
+
backgroundColor: "#1e293b",
|
|
755
|
+
color: "#38bdf8"
|
|
756
|
+
},
|
|
757
|
+
".cm-foldPlaceholder": {
|
|
758
|
+
backgroundColor: "#1e293b",
|
|
759
|
+
color: "#94a3b8",
|
|
760
|
+
border: "none",
|
|
761
|
+
borderRadius: "4px",
|
|
762
|
+
padding: "0 4px"
|
|
763
|
+
},
|
|
764
|
+
// GNU AWK Syntax Highlighting Classes
|
|
765
|
+
".cm-awk-directive": { color: "#c084fc", fontWeight: "bold" },
|
|
766
|
+
// @include, @namespace
|
|
767
|
+
".cm-awk-pattern": { color: "#f59e0b", fontWeight: "bold" },
|
|
768
|
+
// BEGIN, END
|
|
769
|
+
".cm-awk-keyword": { color: "#f43f5e", fontWeight: "bold" },
|
|
770
|
+
// if, else, for, while
|
|
771
|
+
".cm-awk-builtin-var": { color: "#38bdf8", fontWeight: "600" },
|
|
772
|
+
// FS, NF, NR, ARGIND
|
|
773
|
+
".cm-awk-field": { color: "#4ade80", fontWeight: "bold" },
|
|
774
|
+
// $0, $1, $NF
|
|
775
|
+
".cm-awk-builtin-func": { color: "#60a5fa" },
|
|
776
|
+
// gensub, patsplit, strftime
|
|
777
|
+
".cm-awk-func-def": { color: "#a78bfa", fontWeight: "bold" },
|
|
778
|
+
".cm-awk-func-call": { color: "#38bdf8" },
|
|
779
|
+
".cm-awk-string": { color: "#a3e635" },
|
|
780
|
+
".cm-awk-regex": { color: "#fb923c" },
|
|
781
|
+
".cm-awk-number": { color: "#facc15" },
|
|
782
|
+
".cm-awk-comment": { color: "#64748b", fontStyle: "italic" },
|
|
783
|
+
".cm-awk-operator": { color: "#cbd5e1" },
|
|
784
|
+
".cm-awk-punctuation": { color: "#94a3b8" }
|
|
785
|
+
},
|
|
786
|
+
{ dark: !0 }
|
|
787
|
+
), ie = _.theme(
|
|
788
|
+
{
|
|
789
|
+
"&": {
|
|
790
|
+
backgroundColor: "#ffffff",
|
|
791
|
+
color: "#0f172a",
|
|
792
|
+
fontFamily: "'Fira Code', 'JetBrains Mono', 'Source Code Pro', monospace",
|
|
793
|
+
fontSize: "14px",
|
|
794
|
+
borderRadius: "8px"
|
|
795
|
+
},
|
|
796
|
+
".cm-content": {
|
|
797
|
+
caretColor: "#0284c7"
|
|
798
|
+
},
|
|
799
|
+
".cm-gutters": {
|
|
800
|
+
backgroundColor: "#f8fafc",
|
|
801
|
+
color: "#94a3b8",
|
|
802
|
+
borderRight: "1px solid #e2e8f0"
|
|
803
|
+
},
|
|
804
|
+
".cm-activeLine": {
|
|
805
|
+
backgroundColor: "#f1f5f9"
|
|
806
|
+
},
|
|
807
|
+
".cm-activeLineGutter": {
|
|
808
|
+
backgroundColor: "#e2e8f0",
|
|
809
|
+
color: "#0284c7"
|
|
810
|
+
},
|
|
811
|
+
// Light mode syntax highlighting
|
|
812
|
+
".cm-awk-directive": { color: "#7e22ce", fontWeight: "bold" },
|
|
813
|
+
".cm-awk-pattern": { color: "#d97706", fontWeight: "bold" },
|
|
814
|
+
".cm-awk-keyword": { color: "#be123c", fontWeight: "bold" },
|
|
815
|
+
".cm-awk-builtin-var": { color: "#0369a1", fontWeight: "600" },
|
|
816
|
+
".cm-awk-field": { color: "#15803d", fontWeight: "bold" },
|
|
817
|
+
".cm-awk-builtin-func": { color: "#1d4ed8" },
|
|
818
|
+
".cm-awk-func-def": { color: "#6d28d9", fontWeight: "bold" },
|
|
819
|
+
".cm-awk-func-call": { color: "#0284c7" },
|
|
820
|
+
".cm-awk-string": { color: "#4d7c0f" },
|
|
821
|
+
".cm-awk-regex": { color: "#c2410c" },
|
|
822
|
+
".cm-awk-number": { color: "#b45309" },
|
|
823
|
+
".cm-awk-comment": { color: "#64748b", fontStyle: "italic" },
|
|
824
|
+
".cm-awk-operator": { color: "#334155" },
|
|
825
|
+
".cm-awk-punctuation": { color: "#475569" }
|
|
826
|
+
},
|
|
827
|
+
{ dark: !1 }
|
|
828
|
+
), Y = F(M.define(U)), X = D.define(L);
|
|
829
|
+
function re(t = {}) {
|
|
830
|
+
const e = [Y];
|
|
831
|
+
return t.autocomplete !== !1 && e.push(
|
|
832
|
+
O({
|
|
833
|
+
override: [V]
|
|
834
|
+
})
|
|
835
|
+
), t.lint !== !1 && e.push(q()), new B(X, e);
|
|
836
|
+
}
|
|
837
|
+
export {
|
|
838
|
+
k as GAWK_BUILTIN_FUNCTIONS,
|
|
839
|
+
N as GAWK_BUILTIN_VARS,
|
|
840
|
+
S as GAWK_DIRECTIVES,
|
|
841
|
+
v as GAWK_KEYWORDS,
|
|
842
|
+
R as GAWK_PATTERNS,
|
|
843
|
+
re as awk,
|
|
844
|
+
V as awkCompletionSource,
|
|
845
|
+
ne as awkDarkTheme,
|
|
846
|
+
U as awkHighlightStyle,
|
|
847
|
+
Y as awkHighlighting,
|
|
848
|
+
X as awkLanguage,
|
|
849
|
+
ie as awkLightTheme,
|
|
850
|
+
q as awkLinter,
|
|
851
|
+
L as awkStreamParser
|
|
852
|
+
};
|