@exercism/codemirror-lang-lua 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 +77 -0
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/index.cjs +549 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +542 -0
- package/package.json +52 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import { ExternalTokenizer, LRParser } from '@lezer/lr';
|
|
2
|
+
import { syntaxTree, LRLanguage, indentNodeProp, delimitedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
import { snippetCompletion, ifNotIn, completeFromList } from '@codemirror/autocomplete';
|
|
5
|
+
|
|
6
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
|
+
const LongString = 1,
|
|
8
|
+
Comment = 2;
|
|
9
|
+
|
|
10
|
+
const dash = 45, bracketL = 91, bracketR = 93, eq = 61, newline = 10, hash = 35, bang = 33;
|
|
11
|
+
// A long bracket is `[`, then any number of `=`, then `[`. Returns how many
|
|
12
|
+
// `=` it carries, which is the level the closing bracket has to match, or -1
|
|
13
|
+
// when what starts here is an ordinary `[`.
|
|
14
|
+
function openingLevel(input, offset) {
|
|
15
|
+
if (input.peek(offset) != bracketL)
|
|
16
|
+
return -1;
|
|
17
|
+
let level = 0;
|
|
18
|
+
while (input.peek(offset + 1 + level) == eq)
|
|
19
|
+
level++;
|
|
20
|
+
return input.peek(offset + 1 + level) == bracketL ? level : -1;
|
|
21
|
+
}
|
|
22
|
+
// Consumes the opening bracket and everything up to and including the matching
|
|
23
|
+
// close. An unterminated one runs to the end of the file on purpose: half a
|
|
24
|
+
// long string is what every one of them looks like while it is being typed,
|
|
25
|
+
// and an editor should colour it as a string rather than as the rest of the
|
|
26
|
+
// program.
|
|
27
|
+
function consumeLong(input, opening, level) {
|
|
28
|
+
for (let i = 0; i < opening; i++)
|
|
29
|
+
input.advance();
|
|
30
|
+
for (;;) {
|
|
31
|
+
if (input.next < 0)
|
|
32
|
+
return;
|
|
33
|
+
if (input.next == bracketR) {
|
|
34
|
+
let seen = 0;
|
|
35
|
+
while (input.peek(1 + seen) == eq)
|
|
36
|
+
seen++;
|
|
37
|
+
if (seen == level && input.peek(1 + seen) == bracketR) {
|
|
38
|
+
for (let i = 0; i < level + 2; i++)
|
|
39
|
+
input.advance();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
input.advance();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function consumeLine(input) {
|
|
47
|
+
while (input.next != newline && input.next >= 0)
|
|
48
|
+
input.advance();
|
|
49
|
+
}
|
|
50
|
+
const longTokens = /*@__PURE__*/new ExternalTokenizer((input) => {
|
|
51
|
+
// `#!/usr/bin/lua`. The standalone interpreter drops a first line starting
|
|
52
|
+
// with `#`, and Rosetta Code is full of scripts that rely on it.
|
|
53
|
+
if (input.next == hash && input.pos == 0 && input.peek(1) == bang) {
|
|
54
|
+
consumeLine(input);
|
|
55
|
+
input.acceptToken(Comment);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (input.next == dash && input.peek(1) == dash) {
|
|
59
|
+
let level = openingLevel(input, 2);
|
|
60
|
+
if (level < 0)
|
|
61
|
+
consumeLine(input);
|
|
62
|
+
else
|
|
63
|
+
consumeLong(input, 2 + level + 2, level);
|
|
64
|
+
input.acceptToken(Comment);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let level = openingLevel(input, 0);
|
|
68
|
+
if (level >= 0) {
|
|
69
|
+
consumeLong(input, level + 2, level);
|
|
70
|
+
input.acceptToken(LongString);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
75
|
+
const spec_identifier = {__proto__:null,break:22, goto:26, do:30, end:32, while:36, nil:40, true:44, false:48, function:58, not:110, or:120, and:122, repeat:142, until:144, if:148, then:150, elseif:152, else:154, for:158, in:162, local:170, return:186};
|
|
76
|
+
const parser = /*@__PURE__*/LRParser.deserialize({
|
|
77
|
+
version: 14,
|
|
78
|
+
states: "<hO!WQROOOOQP'#Ca'#CaO!_QRO'#CdOOQP'#DY'#DYO!dQRO'#DZO#|QRO'#F[OOQP'#Eq'#EqO%`QRO'#EYOOQP'#Ej'#EjOOQP'#E^'#E^O%eQRO'#C`OOQP'#C`'#C`QOQROOOOQP'#Cf'#CfO!_QRO'#ChO%xQRO'#CjO!dQRO'#CmO&PQRO'#DtO!dQRO'#DwO&WQRO'#EOO!RQRO'#EQO&]QRO'#EUO&eQRO'#E[OOQP'#Ce'#CeO&{QRO,59OOOQP'#Co'#CoOOQP'#Cq'#CqOOQP'#Cs'#CsO(UQRO'#DRO)pQRO,59uO)wQRO'#ElOOQP'#Df'#DfOOQP'#Dg'#DgOOQP'#Dh'#DhO!dQRO'#DdOOQP'#El'#ElO,uQRO'#CxO,zQRO,59vO!dQRO,59xO-PQRO'#D`OOQP'#Er'#ErOOQP,59y,59yO-WQRO,59{O-]QRO'#EfO-eQRO,5;vO!dQRO,5:tOOQP-E8[-E8[OOQP,58z,58zOOQP,59S,59SO-mQRO,59UO-rQRO,59XO-yQRO,5:`O.OQRO,5:cOOQP'#C}'#C}O.VQRO,5:hO.bQRO,5:jO.gQRO'#ERO,uQRO,5:lO.rQRO'#EVO0YQRO'#FZO&WQRO,5:nO1mQRO,5:pO2}QRO'#EsO3kQRO,5:vOOQP1G.j1G.jO!dQRO'#DSO4PQRO'#DXO6VQRO'#DWOOQP'#Eo'#EoO6[QRO'#EoOOQP,59m,59mO6iQRO,59mOOQP1G/a1G/aOOQP'#Dl'#DlOOQP'#Dm'#DmOOQP'#Dn'#DnOOQP'#Do'#DoOOQP'#Dq'#DqOOQP'#Dr'#DrOO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O$X$]$i$l%W%Y%[%f!P!wm!S!U!`!g#R#X#p#v#w#x#y#z#}$O$X$]$i$l%W%Y%[%f!R!xm!S!U!`!g#R#X#p#v#w#x#y#z#{#}$O$X$]$i$l%W%Y%[%f!V!xm!S!U!`!g!{#R#X#p#v#w#x#y#z#{#|#}$O$X$]$i$l%W%Y%[%fR!ZdQ!]eR$e#iR#h![R$d#ghZO_a!}#[#^$y${%V%^%`%hR!PYhYO_a!}#[#^$y${%V%^%`%hR!OYQ$r$PR%S$rQ#t!iR$p#tQ#n!`Q$V#XT$j#n$VQ$v$YR%T$vQ#`!WR$[#`Q#d!YR$`#dQ#j!]R$f#jQ|TR#W|kXOY_a!}#[#^$y${%V%^%`%hQmSQ!S`Q!UbS!`fwW!gl#s$o%QQ!{rQ#RvU#X}#b#lQ#p!cQ#v!rQ#w!sQ#x!tQ#y!uQ#z!vQ#{!wQ#|!xQ#}!yQ$O!zQ$X#]Q$]#aQ$i#mQ$l#qQ%W$wQ%Y$zQ%[%OR%f%aQ#OtQ#f!ZR$g#kR$Q!|Q!ilV$m#s$o%QQ#s!iR$o#tjTOY_a!}#[#^$y${%V%^%`%h!bnS`bflrvw}!c!r!s!t!u!v!w!x!y!z#]#a#b#l#m#q#s$o$w$z%O%Q%aR#V{UyTn#VR$U#UQ!afR#SwR!XcQ#Y}Q$^#bR$h#lR!_ekVOY_a!}#[#^$y${%V%^%`%h",
|
|
81
|
+
nodeNames: "⚠ LongString Comment Chunk Block EmptyStatement ; :: Label LabelName BreakStatement break GotoStatement goto DoStatement do end WhileStatement while Nil nil True true False false Number String Vararg FunctionExpression function ) ( ParamList VariableDefinition , } { TableExpression Property [ ] = Property PropertyName Name ParenthesizedExpression MemberExpression . IndexExpression CallExpression ArgList MethodCallExpression : MethodName UnaryExpression not ArithOp LengthOp BitOp BinaryExpression or and CompareOp BitOp BitOp BitOp ConcatOp ArithOp ArithOp ArithOp RepeatStatement repeat until IfStatement if then elseif else ForNumericStatement for ForGenericStatement in FunctionDeclaration FunctionName LocalFunctionDeclaration local LocalStatement AttribName Attrib AttributeName AssignStatement ExpressionStatement ReturnStatement return",
|
|
82
|
+
maxTerm: 138,
|
|
83
|
+
nodeProps: [
|
|
84
|
+
["group", -17,1,19,21,23,25,26,27,28,37,44,45,46,48,49,51,54,59,"Expression",-15,5,8,10,12,14,17,70,73,78,80,82,84,86,90,91,"Statement"],
|
|
85
|
+
["openedBy", 30,"(",35,"{"],
|
|
86
|
+
["closedBy", 31,")",36,"}"]
|
|
87
|
+
],
|
|
88
|
+
skippedNodes: [0,2],
|
|
89
|
+
repeatNodeCount: 9,
|
|
90
|
+
tokenData: "0j~RuXY#fYZ#f]^#fpq#frs#wst&Uuv&Zvw&`wx&exy(myz(rz{(w{|(||})R}!O)W!O!P)]!P!Q*o!Q!R*|!R![+e![!]-`!]!^-m!^!_-r!_!`.X!`!a.f!c!}.{!}#O/m#P#Q/r#Q#R/w#R#S.{#T#o.{#o#p/|#p#q0R#q#r0W#r#s0]#t;'S.{;'S;=`/g<%lO.{~#kS#]~XY#fYZ#f]^#fpq#f~#|Wj~OY#wZr#wrs$fs#O#w#O#P$k#P;'S#w;'S;=`&O<%lO#w~$kOj~~$nTO#n#w#n#o$}#o;'S#w;'S;=`&O<%lO#w~%S^j~OX#wXY$}YZ$}Z]#w]^$}^p#wpq$}qr#wrs$fs#O#w#O#P$k#P;'S#w;'S;=`&O<%lO#w~&RP;=`<%l#w~&ZO#i~~&`O#y~~&eO#r~~&jWj~OY&eZw&ewx$fx#O&e#O#P'S#P;'S&e;'S;=`(g<%lO&e~'VTO#n&e#n#o'f#o;'S&e;'S;=`(g<%lO&e~'k^j~OX&eXY'fYZ'fZ]&e]^'f^p&epq'fqw&ewx$fx#O&e#O#P'S#P;'S&e;'S;=`(g<%lO&e~(jP;=`<%l&e~(rOo~~(wOn~~(|O#v~~)RO#u~~)WOr~~)]O#h~~)bQ!P~!O!P)h!Q![)u~)mP!d~!O!P)p~)uOk~~)zRi~!Q![)u!g!h*T#X#Y*T~*WR{|*a}!O*a!Q![*g~*dP!Q![*g~*lPi~!Q![*g~*tP#w~!P!Q*w~*|O#x~~+RUi~!O!P)u!Q![+e!g!h*T!z!{+v#X#Y*T#l#m+v~+jSi~!O!P)u!Q![+e!g!h*T#X#Y*T~+yS!O!P,V!Q![,w!c!i,w#T#Z,w~,YR!Q![,c!c!i,c#T#Z,c~,hTi~!Q![,c!c!i,c!r!s*T#T#Z,c#d#e*T~,|Ui~!O!P,c!Q![,w!c!i,w!r!s*T#T#Z,w#d#e*T~-eP!U~![!]-h~-mOV~~-rOU~~-wQ#k~!^!_-}!_!`.S~.SO#s~~.XO#l~~.^Py~!_!`.a~.fO#o~~.kQ#m~!_!`.q!`!a.v~.vO#n~~.{O#t~~/QV#_~!Q![.{!c!}.{#R#S.{#T#o.{#t;'S.{;'S;=`/g<%lO.{~/jP;=`<%l.{~/rOw~~/wOx~~/|O#z~~0ROt~~0WO#q~~0]Os~~0bP#j~!_!`0e~0jO#p~",
|
|
91
|
+
tokenizers: [longTokens, 0],
|
|
92
|
+
topRules: {"Chunk":[0,3]},
|
|
93
|
+
specialized: [{term: 107, get: (value) => spec_identifier[value] || -1}],
|
|
94
|
+
tokenPrec: 2497
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
Snippets for the constructs people type most: functions, conditionals,
|
|
99
|
+
loops, and the metatable pattern Lua uses in place of classes.
|
|
100
|
+
*/
|
|
101
|
+
const snippets = [
|
|
102
|
+
/*@__PURE__*/snippetCompletion("function ${name}(${params})\n\t${}\nend", {
|
|
103
|
+
label: "function",
|
|
104
|
+
detail: "definition",
|
|
105
|
+
type: "keyword"
|
|
106
|
+
}),
|
|
107
|
+
/*@__PURE__*/snippetCompletion("local function ${name}(${params})\n\t${}\nend", {
|
|
108
|
+
label: "local function",
|
|
109
|
+
detail: "definition",
|
|
110
|
+
type: "keyword"
|
|
111
|
+
}),
|
|
112
|
+
/*@__PURE__*/snippetCompletion("local ${name} = ${value}", {
|
|
113
|
+
label: "local",
|
|
114
|
+
detail: "declaration",
|
|
115
|
+
type: "keyword"
|
|
116
|
+
}),
|
|
117
|
+
/*@__PURE__*/snippetCompletion("if ${condition} then\n\t${}\nend", {
|
|
118
|
+
label: "if",
|
|
119
|
+
detail: "block",
|
|
120
|
+
type: "keyword"
|
|
121
|
+
}),
|
|
122
|
+
/*@__PURE__*/snippetCompletion("if ${condition} then\n\t${}\nelse\n\t${}\nend", {
|
|
123
|
+
label: "if",
|
|
124
|
+
detail: "/ else block",
|
|
125
|
+
type: "keyword"
|
|
126
|
+
}),
|
|
127
|
+
/*@__PURE__*/snippetCompletion("elseif ${condition} then\n\t${}", {
|
|
128
|
+
label: "elseif",
|
|
129
|
+
detail: "branch",
|
|
130
|
+
type: "keyword"
|
|
131
|
+
}),
|
|
132
|
+
/*@__PURE__*/snippetCompletion("for ${i} = ${1}, ${n} do\n\t${}\nend", {
|
|
133
|
+
label: "for",
|
|
134
|
+
detail: "numeric loop",
|
|
135
|
+
type: "keyword"
|
|
136
|
+
}),
|
|
137
|
+
/*@__PURE__*/snippetCompletion("for ${i}, ${value} in ipairs(${list}) do\n\t${}\nend", {
|
|
138
|
+
label: "for",
|
|
139
|
+
detail: "ipairs loop",
|
|
140
|
+
type: "keyword"
|
|
141
|
+
}),
|
|
142
|
+
/*@__PURE__*/snippetCompletion("for ${key}, ${value} in pairs(${table}) do\n\t${}\nend", {
|
|
143
|
+
label: "for",
|
|
144
|
+
detail: "pairs loop",
|
|
145
|
+
type: "keyword"
|
|
146
|
+
}),
|
|
147
|
+
/*@__PURE__*/snippetCompletion("while ${condition} do\n\t${}\nend", {
|
|
148
|
+
label: "while",
|
|
149
|
+
detail: "loop",
|
|
150
|
+
type: "keyword"
|
|
151
|
+
}),
|
|
152
|
+
/*@__PURE__*/snippetCompletion("repeat\n\t${}\nuntil ${condition}", {
|
|
153
|
+
label: "repeat",
|
|
154
|
+
detail: "loop",
|
|
155
|
+
type: "keyword"
|
|
156
|
+
}),
|
|
157
|
+
/*@__PURE__*/snippetCompletion("local ${Name} = {}\n${Name}.__index = ${Name}\n\nfunction ${Name}.new(${params})\n\tlocal self = setmetatable({}, ${Name})\n\t${}\n\treturn self\nend", { label: "class", detail: "metatable", type: "keyword" })
|
|
158
|
+
];
|
|
159
|
+
const keywords = /*@__PURE__*/("and break do else elseif end false for function goto if in local nil not or repeat return then true until while")
|
|
160
|
+
.split(" ")
|
|
161
|
+
.map(label => ({ label, type: "keyword" }));
|
|
162
|
+
const globals = /*@__PURE__*/[
|
|
163
|
+
"assert", "collectgarbage", "dofile", "error", "getmetatable", "ipairs", "load",
|
|
164
|
+
"loadstring", "next", "pairs", "pcall", "print", "rawequal", "rawget", "rawlen",
|
|
165
|
+
"rawset", "require", "select", "setmetatable", "tonumber", "tostring", "type",
|
|
166
|
+
"unpack", "xpcall", "warn"
|
|
167
|
+
].map(label => ({ label, type: "function" }));
|
|
168
|
+
const constants = /*@__PURE__*/["_G", "_VERSION"].map(label => ({ label, type: "variable" }));
|
|
169
|
+
function members(names, type = "function") {
|
|
170
|
+
return names.split(" ").map(label => ({ label, type }));
|
|
171
|
+
}
|
|
172
|
+
// The standard library tables of Lua 5.4. These are offered after `string.`,
|
|
173
|
+
// `math.` and so on, and the string functions are also offered after `s:`,
|
|
174
|
+
// because a method call on a string is the most common `:` in small programs.
|
|
175
|
+
const library = {
|
|
176
|
+
string: /*@__PURE__*/members("byte char dump find format gmatch gsub len lower match pack packsize rep reverse sub unpack upper"),
|
|
177
|
+
table: /*@__PURE__*/members("concat insert move pack remove sort unpack"),
|
|
178
|
+
math: [
|
|
179
|
+
.../*@__PURE__*/members("abs acos asin atan ceil cos deg exp floor fmod log max min modf rad random randomseed sin sqrt tan tointeger type ult"),
|
|
180
|
+
.../*@__PURE__*/members("huge maxinteger mininteger pi", "constant")
|
|
181
|
+
],
|
|
182
|
+
io: [
|
|
183
|
+
.../*@__PURE__*/members("close flush input lines open output popen read tmpfile type write"),
|
|
184
|
+
.../*@__PURE__*/members("stderr stdin stdout", "constant")
|
|
185
|
+
],
|
|
186
|
+
os: /*@__PURE__*/members("clock date difftime execute exit getenv remove rename setlocale time tmpname"),
|
|
187
|
+
coroutine: /*@__PURE__*/members("close create isyieldable resume running status wrap yield"),
|
|
188
|
+
utf8: [.../*@__PURE__*/members("char codes codepoint len offset"), .../*@__PURE__*/members("charpattern", "constant")],
|
|
189
|
+
debug: /*@__PURE__*/members("debug gethook getinfo getlocal getmetatable getregistry getupvalue getuservalue sethook setlocal setmetatable setupvalue setuservalue traceback upvalueid upvaluejoin"),
|
|
190
|
+
package: /*@__PURE__*/members("config cpath loaded loadlib path preload searchers searchpath", "property")
|
|
191
|
+
};
|
|
192
|
+
const libraryTables = /*@__PURE__*/Object.keys(library).map(label => ({ label, type: "namespace" }));
|
|
193
|
+
// Nothing is offered inside these nodes. A VariableDefinition, a label or an
|
|
194
|
+
// attribute is a new name being typed, and after a `.` or `:` the member
|
|
195
|
+
// source below takes over.
|
|
196
|
+
const dontComplete = [
|
|
197
|
+
"String", "LongString", "Comment",
|
|
198
|
+
"VariableDefinition", "LabelName", "AttributeName",
|
|
199
|
+
"PropertyName", "MethodName", "FunctionName"
|
|
200
|
+
];
|
|
201
|
+
/**
|
|
202
|
+
Keywords, snippets, global functions and the standard library tables.
|
|
203
|
+
*/
|
|
204
|
+
const luaKeywordCompletion = /*@__PURE__*/ifNotIn(dontComplete, /*@__PURE__*/completeFromList([...snippets, ...keywords, ...globals, ...libraryTables, ...constants]));
|
|
205
|
+
const cache = /*@__PURE__*/new WeakMap();
|
|
206
|
+
function text(state, node) {
|
|
207
|
+
return state.sliceDoc(node.from, node.to);
|
|
208
|
+
}
|
|
209
|
+
// A local declared in a block lasts until the block ends. The block node
|
|
210
|
+
// stops at its last statement, so the scope runs on to whatever closes it
|
|
211
|
+
// (`end`, `else`, `until`), which also covers a cursor in trailing blank
|
|
212
|
+
// lines. The body of a `repeat` is still in scope in its `until` condition.
|
|
213
|
+
function blockEnd(block, state) {
|
|
214
|
+
const parent = block.parent;
|
|
215
|
+
if (!parent || parent.name == "Chunk")
|
|
216
|
+
return state.doc.length;
|
|
217
|
+
if (parent.name == "RepeatStatement")
|
|
218
|
+
return parent.to;
|
|
219
|
+
return block.nextSibling ? block.nextSibling.from : parent.to;
|
|
220
|
+
}
|
|
221
|
+
// The end of a function or loop body, which is where its `end` keyword
|
|
222
|
+
// starts. While the closing `end` is still missing, that is the node's end.
|
|
223
|
+
function bodyEnd(node) {
|
|
224
|
+
const last = node.lastChild;
|
|
225
|
+
return last && last.name == "end" ? last.from : node.to;
|
|
226
|
+
}
|
|
227
|
+
function addField(names, table, field, type) {
|
|
228
|
+
let fields = names.fields.get(table);
|
|
229
|
+
if (!fields)
|
|
230
|
+
names.fields.set(table, (fields = new Map()));
|
|
231
|
+
if (!fields.has(field))
|
|
232
|
+
fields.set(field, type);
|
|
233
|
+
}
|
|
234
|
+
function addTableFields(names, state, table, value) {
|
|
235
|
+
var _a;
|
|
236
|
+
if (!value || value.name != "TableExpression")
|
|
237
|
+
return;
|
|
238
|
+
for (const prop of value.getChildren("Property")) {
|
|
239
|
+
const key = prop.firstChild;
|
|
240
|
+
if ((key === null || key === void 0 ? void 0 : key.name) != "PropertyName")
|
|
241
|
+
continue;
|
|
242
|
+
const isFunction = ((_a = prop.lastChild) === null || _a === void 0 ? void 0 : _a.name) == "FunctionExpression";
|
|
243
|
+
addField(names, table, text(state, key), isFunction ? "function" : "property");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// Pairs each target of `a, b = x, y` or `local a, b = x, y` with its value.
|
|
247
|
+
function targetsAndValues(node, target) {
|
|
248
|
+
const targets = [], values = [];
|
|
249
|
+
let afterEquals = false;
|
|
250
|
+
for (let child = node.firstChild; child; child = child.nextSibling) {
|
|
251
|
+
if (child.name == "=")
|
|
252
|
+
afterEquals = true;
|
|
253
|
+
else if (afterEquals) {
|
|
254
|
+
if (child.name != ",")
|
|
255
|
+
values.push(child);
|
|
256
|
+
}
|
|
257
|
+
else if (child.name == target)
|
|
258
|
+
targets.push(child);
|
|
259
|
+
}
|
|
260
|
+
return targets.map((t, i) => { var _a; return [t, (_a = values[i]) !== null && _a !== void 0 ? _a : null]; });
|
|
261
|
+
}
|
|
262
|
+
function gather(state, tree) {
|
|
263
|
+
const cached = cache.get(tree);
|
|
264
|
+
if (cached)
|
|
265
|
+
return cached;
|
|
266
|
+
const names = { definitions: [], fields: new Map() };
|
|
267
|
+
const end = state.doc.length;
|
|
268
|
+
const def = (node, type, from, to) => names.definitions.push({ label: text(state, node), type, at: node.from, from, to });
|
|
269
|
+
tree.iterate({
|
|
270
|
+
enter: ref => {
|
|
271
|
+
var _a, _b;
|
|
272
|
+
const node = ref.node;
|
|
273
|
+
switch (node.name) {
|
|
274
|
+
case "LocalStatement": {
|
|
275
|
+
const block = node.parent;
|
|
276
|
+
if (!block)
|
|
277
|
+
break;
|
|
278
|
+
const scopeEnd = blockEnd(block, state);
|
|
279
|
+
for (const [attrib, value] of targetsAndValues(node, "AttribName")) {
|
|
280
|
+
const name = attrib.getChild("VariableDefinition");
|
|
281
|
+
if (!name)
|
|
282
|
+
continue;
|
|
283
|
+
const isFunction = (value === null || value === void 0 ? void 0 : value.name) == "FunctionExpression";
|
|
284
|
+
// `local x = x + 1` reads the outer x, so the new one starts
|
|
285
|
+
// after the statement.
|
|
286
|
+
def(name, isFunction ? "function" : "variable", node.to, scopeEnd);
|
|
287
|
+
addTableFields(names, state, text(state, name), value);
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case "LocalFunctionDeclaration": {
|
|
292
|
+
const name = node.getChild("VariableDefinition");
|
|
293
|
+
// A local function can call itself, so it is in scope from its name.
|
|
294
|
+
if (name && node.parent)
|
|
295
|
+
def(name, "function", name.to, blockEnd(node.parent, state));
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case "FunctionDeclaration": {
|
|
299
|
+
const fname = node.getChild("FunctionName");
|
|
300
|
+
const table = fname === null || fname === void 0 ? void 0 : fname.firstChild;
|
|
301
|
+
if (!fname || !table)
|
|
302
|
+
break;
|
|
303
|
+
const field = (_a = table.nextSibling) === null || _a === void 0 ? void 0 : _a.nextSibling;
|
|
304
|
+
if (!field)
|
|
305
|
+
def(table, "function", 0, end);
|
|
306
|
+
else if (field.nextSibling == null) {
|
|
307
|
+
addField(names, text(state, table), text(state, field), field.name == "MethodName" ? "method" : "function");
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case "AssignStatement": {
|
|
312
|
+
for (const [target, value] of targetsAndValues(node, "Name")) {
|
|
313
|
+
const isFunction = (value === null || value === void 0 ? void 0 : value.name) == "FunctionExpression";
|
|
314
|
+
def(target, isFunction ? "function" : "variable", 0, end);
|
|
315
|
+
addTableFields(names, state, text(state, target), value);
|
|
316
|
+
}
|
|
317
|
+
for (const target of node.getChildren("MemberExpression")) {
|
|
318
|
+
const table = target.firstChild, field = target.lastChild;
|
|
319
|
+
if ((table === null || table === void 0 ? void 0 : table.name) != "Name" || (field === null || field === void 0 ? void 0 : field.name) != "PropertyName")
|
|
320
|
+
continue;
|
|
321
|
+
// `self.balance = 0` inside `function Account:open()` is a field of Account.
|
|
322
|
+
const owner = text(state, table) == "self" ? selfTable(state, node) : text(state, table);
|
|
323
|
+
if (owner)
|
|
324
|
+
addField(names, owner, text(state, field), "property");
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
case "ParamList": {
|
|
329
|
+
const fn = node.parent;
|
|
330
|
+
if (!fn)
|
|
331
|
+
break;
|
|
332
|
+
const scopeEnd = bodyEnd(fn);
|
|
333
|
+
for (const param of node.getChildren("VariableDefinition"))
|
|
334
|
+
def(param, "variable", node.to, scopeEnd);
|
|
335
|
+
if ((_b = fn.getChild("FunctionName")) === null || _b === void 0 ? void 0 : _b.getChild(":"))
|
|
336
|
+
names.definitions.push({ label: "self", type: "variable", at: -1, from: node.to, to: scopeEnd });
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
case "ForNumericStatement":
|
|
340
|
+
case "ForGenericStatement": {
|
|
341
|
+
const doKeyword = node.getChild("do");
|
|
342
|
+
if (!doKeyword)
|
|
343
|
+
break;
|
|
344
|
+
const scopeEnd = bodyEnd(node);
|
|
345
|
+
for (const name of node.getChildren("VariableDefinition"))
|
|
346
|
+
def(name, "variable", doKeyword.to, scopeEnd);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
cache.set(tree, names);
|
|
353
|
+
return names;
|
|
354
|
+
}
|
|
355
|
+
const identifier = /^[a-zA-Z_\u{80}-\u{10ffff}][a-zA-Z_0-9\u{80}-\u{10ffff}]*$/u;
|
|
356
|
+
function inStringOrComment(node) {
|
|
357
|
+
for (; node; node = node.parent)
|
|
358
|
+
if (node.name == "String" || node.name == "LongString" || node.name == "Comment")
|
|
359
|
+
return true;
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
// Inside `function M:add()` or `function M.add()`, `self` stands for M.
|
|
363
|
+
function selfTable(state, node) {
|
|
364
|
+
for (; node; node = node.parent) {
|
|
365
|
+
if (node.name != "FunctionDeclaration")
|
|
366
|
+
continue;
|
|
367
|
+
const fname = node.getChild("FunctionName");
|
|
368
|
+
if (fname && fname.firstChild && fname.firstChild.nextSibling)
|
|
369
|
+
return text(state, fname.firstChild);
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
function completeMember(context, names, inner) {
|
|
374
|
+
var _a;
|
|
375
|
+
const match = context.matchBefore(/(?:^|[^.:\w\u{80}-\u{10ffff}])([a-zA-Z_][\w]*)\s*([.:])\s*\w*$/u);
|
|
376
|
+
if (!match)
|
|
377
|
+
return null;
|
|
378
|
+
const [, receiver, operator] = /([a-zA-Z_]\w*)\s*([.:])\s*\w*$/.exec(match.text);
|
|
379
|
+
const word = context.matchBefore(/\w*$/);
|
|
380
|
+
// Naming a new field in `function M.add` is not a place to suggest names.
|
|
381
|
+
if (((_a = inner.parent) === null || _a === void 0 ? void 0 : _a.name) == "FunctionName" && inner.name != "Name")
|
|
382
|
+
return null;
|
|
383
|
+
const table = receiver == "self" ? selfTable(context.state, inner) : receiver;
|
|
384
|
+
const options = [];
|
|
385
|
+
const seen = new Set();
|
|
386
|
+
const add = (option) => {
|
|
387
|
+
if (seen.has(option.label))
|
|
388
|
+
return;
|
|
389
|
+
seen.add(option.label);
|
|
390
|
+
options.push(option);
|
|
391
|
+
};
|
|
392
|
+
const declared = table ? names.fields.get(table) : undefined;
|
|
393
|
+
if (declared)
|
|
394
|
+
for (const [label, type] of declared)
|
|
395
|
+
add({ label, type });
|
|
396
|
+
if (operator == "." && library[receiver])
|
|
397
|
+
library[receiver].forEach(add);
|
|
398
|
+
if (operator == ":" && !library[receiver])
|
|
399
|
+
library.string.forEach(option => add(Object.assign(Object.assign({}, option), { detail: "string" })));
|
|
400
|
+
if (!options.length)
|
|
401
|
+
return null;
|
|
402
|
+
return { from: word.from, options, validFor: /^\w*$/ };
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
Completes the names declared in the file. A local is offered from the
|
|
406
|
+
end of its declaration to the end of its block, a parameter inside its
|
|
407
|
+
function and a loop variable inside its loop. Globals and global
|
|
408
|
+
functions are offered everywhere. After `name.` or `name:` it offers the
|
|
409
|
+
fields declared on that table, or the standard library's members.
|
|
410
|
+
*/
|
|
411
|
+
const localCompletionSource = context => {
|
|
412
|
+
const tree = syntaxTree(context.state);
|
|
413
|
+
const inner = tree.resolveInner(context.pos, -1);
|
|
414
|
+
if (inStringOrComment(inner))
|
|
415
|
+
return null;
|
|
416
|
+
const names = gather(context.state, tree);
|
|
417
|
+
const member = completeMember(context, names, inner);
|
|
418
|
+
if (member)
|
|
419
|
+
return member;
|
|
420
|
+
if (dontComplete.indexOf(inner.name) > -1)
|
|
421
|
+
return null;
|
|
422
|
+
if (context.matchBefore(/[.:]\s*\w*$/))
|
|
423
|
+
return null;
|
|
424
|
+
const word = context.matchBefore(/[a-zA-Z_\u{80}-\u{10ffff}][\w\u{80}-\u{10ffff}]*$/u);
|
|
425
|
+
if (!word && !context.explicit)
|
|
426
|
+
return null;
|
|
427
|
+
const options = [];
|
|
428
|
+
const seen = new Set();
|
|
429
|
+
// Later definitions are closer to the cursor, so they win on a name clash.
|
|
430
|
+
for (let i = names.definitions.length - 1; i >= 0; i--) {
|
|
431
|
+
const d = names.definitions[i];
|
|
432
|
+
if (d.from > context.pos || d.to < context.pos || seen.has(d.label))
|
|
433
|
+
continue;
|
|
434
|
+
if (word && d.at == word.from)
|
|
435
|
+
continue;
|
|
436
|
+
seen.add(d.label);
|
|
437
|
+
options.push({ label: d.label, type: d.type });
|
|
438
|
+
}
|
|
439
|
+
return { from: word ? word.from : context.pos, options, validFor: identifier };
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// A block indents its body by one unit, and pulls the line that closes it back
|
|
443
|
+
// out again. Lua closes four different constructs with `end` and one with
|
|
444
|
+
// `until`, and `else` and `elseif` sit at the indentation of their `if`.
|
|
445
|
+
const closesBlock = /^\s*(end|else|elseif|until)\b/;
|
|
446
|
+
function blockIndent(context) {
|
|
447
|
+
const base = context.lineIndent(context.node.from);
|
|
448
|
+
return closesBlock.test(context.textAfter) ? base : base + context.unit;
|
|
449
|
+
}
|
|
450
|
+
// A fold has to start on the line where the block opens, so it runs from the
|
|
451
|
+
// end of the header (`then`, `do`, the parameter list or `repeat`) to the
|
|
452
|
+
// keyword that closes the block. An `if` with `else` branches folds as one.
|
|
453
|
+
function foldBody(node) {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
const open = (_a = node.getChild("Block")) === null || _a === void 0 ? void 0 : _a.prevSibling;
|
|
456
|
+
const close = ((_b = node.lastChild) === null || _b === void 0 ? void 0 : _b.name) == "end" ? node.lastChild : node.getChild("until");
|
|
457
|
+
if (!open || !close)
|
|
458
|
+
return null;
|
|
459
|
+
return open.to < close.from ? { from: open.to, to: close.from } : null;
|
|
460
|
+
}
|
|
461
|
+
const blockStatements = "IfStatement WhileStatement RepeatStatement DoStatement " +
|
|
462
|
+
"ForNumericStatement ForGenericStatement " +
|
|
463
|
+
"FunctionDeclaration LocalFunctionDeclaration FunctionExpression";
|
|
464
|
+
/**
|
|
465
|
+
A language provider based on the Lezer Lua parser in this package,
|
|
466
|
+
extended with highlighting, folding and indentation information.
|
|
467
|
+
*/
|
|
468
|
+
const luaLanguage = /*@__PURE__*/LRLanguage.define({
|
|
469
|
+
name: "lua",
|
|
470
|
+
parser: /*@__PURE__*/parser.configure({
|
|
471
|
+
props: [
|
|
472
|
+
/*@__PURE__*/indentNodeProp.add({
|
|
473
|
+
[blockStatements]: blockIndent,
|
|
474
|
+
TableExpression: /*@__PURE__*/delimitedIndent({ closing: "}" }),
|
|
475
|
+
ArgList: /*@__PURE__*/delimitedIndent({ closing: ")" }),
|
|
476
|
+
ParamList: /*@__PURE__*/delimitedIndent({ closing: ")" })
|
|
477
|
+
}),
|
|
478
|
+
/*@__PURE__*/foldNodeProp.add({
|
|
479
|
+
[blockStatements]: foldBody,
|
|
480
|
+
TableExpression: foldInside,
|
|
481
|
+
ArgList: foldInside
|
|
482
|
+
}),
|
|
483
|
+
/*@__PURE__*/styleTags({
|
|
484
|
+
"function local": tags.definitionKeyword,
|
|
485
|
+
"if then else elseif end do while repeat until for in": tags.controlKeyword,
|
|
486
|
+
"break goto return": tags.controlKeyword,
|
|
487
|
+
"and or not": tags.logicOperator,
|
|
488
|
+
nil: tags.null,
|
|
489
|
+
"true false": tags.bool,
|
|
490
|
+
Number: tags.number,
|
|
491
|
+
"String LongString": tags.string,
|
|
492
|
+
Comment: tags.comment,
|
|
493
|
+
Name: tags.variableName,
|
|
494
|
+
VariableDefinition: /*@__PURE__*/tags.definition(tags.variableName),
|
|
495
|
+
PropertyName: tags.propertyName,
|
|
496
|
+
MethodName: /*@__PURE__*/tags.function(tags.propertyName),
|
|
497
|
+
LabelName: tags.labelName,
|
|
498
|
+
AttributeName: tags.modifier,
|
|
499
|
+
"FunctionName/Name": /*@__PURE__*/tags.function(/*@__PURE__*/tags.definition(tags.variableName)),
|
|
500
|
+
"FunctionName/PropertyName": /*@__PURE__*/tags.function(/*@__PURE__*/tags.definition(tags.propertyName)),
|
|
501
|
+
"FunctionName/MethodName": /*@__PURE__*/tags.function(/*@__PURE__*/tags.definition(tags.propertyName)),
|
|
502
|
+
"CallExpression/Name": /*@__PURE__*/tags.function(tags.variableName),
|
|
503
|
+
"CallExpression/MemberExpression/PropertyName": /*@__PURE__*/tags.function(tags.propertyName),
|
|
504
|
+
Vararg: tags.keyword,
|
|
505
|
+
ArithOp: tags.arithmeticOperator,
|
|
506
|
+
BitOp: tags.bitwiseOperator,
|
|
507
|
+
CompareOp: tags.compareOperator,
|
|
508
|
+
ConcatOp: tags.operator,
|
|
509
|
+
LengthOp: tags.operator,
|
|
510
|
+
"=": tags.definitionOperator,
|
|
511
|
+
"( )": tags.paren,
|
|
512
|
+
"[ ]": tags.squareBracket,
|
|
513
|
+
"{ }": tags.brace,
|
|
514
|
+
"::": tags.punctuation,
|
|
515
|
+
", ;": tags.separator,
|
|
516
|
+
". :": tags.derefOperator
|
|
517
|
+
})
|
|
518
|
+
]
|
|
519
|
+
}),
|
|
520
|
+
languageData: {
|
|
521
|
+
commentTokens: { line: "--", block: { open: "--[[", close: "]]" } },
|
|
522
|
+
closeBrackets: { brackets: ["(", "[", "{", "'", '"'] },
|
|
523
|
+
indentOnInput: /^\s*(end|else|elseif|until|\})$/
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
/**
|
|
527
|
+
Autocompletion for Lua's keywords, snippets, globals and standard library
|
|
528
|
+
tables. It offers nothing inside strings and comments.
|
|
529
|
+
*/
|
|
530
|
+
const luaCompletion = luaKeywordCompletion;
|
|
531
|
+
/**
|
|
532
|
+
Lua language support, with completion for keywords, snippets, the standard
|
|
533
|
+
library and the names declared in the file.
|
|
534
|
+
*/
|
|
535
|
+
function lua() {
|
|
536
|
+
return new LanguageSupport(luaLanguage, [
|
|
537
|
+
luaLanguage.data.of({ autocomplete: luaKeywordCompletion }),
|
|
538
|
+
luaLanguage.data.of({ autocomplete: localCompletionSource })
|
|
539
|
+
]);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export { localCompletionSource, lua, luaCompletion, luaLanguage, parser, snippets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exercism/codemirror-lang-lua",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lua language support for the CodeMirror code editor",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"editor",
|
|
7
|
+
"code"
|
|
8
|
+
],
|
|
9
|
+
"author": "CodinCod <hello@codincod.com>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.cjs",
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"CHANGELOG.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rm -rf dist && lezer-generator src/lua.grammar -o src/parser.js && cm-buildhelper src/lua.ts",
|
|
26
|
+
"build-debug": "lezer-generator src/lua.grammar --names -o src/parser.js && cm-buildhelper src/lua.ts",
|
|
27
|
+
"prepare": "npm run build",
|
|
28
|
+
"test": "npm run build && node --test \"test/*.test.ts\""
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@codemirror/autocomplete": "^6.0.0",
|
|
32
|
+
"@codemirror/language": "^6.0.0",
|
|
33
|
+
"@codemirror/state": "^6.7.1",
|
|
34
|
+
"@lezer/common": "^1.0.0",
|
|
35
|
+
"@lezer/highlight": "^1.0.0",
|
|
36
|
+
"@lezer/lr": "^1.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@codemirror/buildhelper": "^1.0.2",
|
|
40
|
+
"@lezer/generator": "^1.7.0",
|
|
41
|
+
"typescript": "^5.6.0"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/exercism/codemirror-lang-lua",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/exercism/codemirror-lang-lua"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/exercism/codemirror-lang-lua/issues"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|