rufus-lua-moon 0.2.0 → 0.2.2
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.
- checksums.yaml +4 -4
- data/vendor/lua/moon/init.moon +1 -0
- data/vendor/lua/moonscript/compile.lua +317 -175
- data/vendor/lua/moonscript/compile/format.lua +0 -6
- data/vendor/lua/moonscript/compile/statement.lua +60 -28
- data/vendor/lua/moonscript/compile/value.lua +27 -48
- data/vendor/lua/moonscript/data.lua +7 -3
- data/vendor/lua/moonscript/dump.lua +5 -11
- data/vendor/lua/moonscript/errors.lua +35 -1
- data/vendor/lua/moonscript/init.lua +18 -7
- data/vendor/lua/moonscript/parse.lua +202 -63
- data/vendor/lua/moonscript/transform.lua +603 -117
- data/vendor/lua/moonscript/types.lua +42 -9
- data/vendor/lua/moonscript/util.lua +38 -1
- data/vendor/lua/moonscript/version.lua +1 -1
- metadata +1 -1
@@ -32,9 +32,6 @@ moonlib = {
|
|
32
32
|
})
|
33
33
|
end
|
34
34
|
}
|
35
|
-
non_atomic = Set({
|
36
|
-
"update"
|
37
|
-
})
|
38
35
|
has_value = function(node)
|
39
36
|
if ntype(node) == "chain" then
|
40
37
|
local ctype = ntype(node[#node])
|
@@ -43,9 +40,6 @@ has_value = function(node)
|
|
43
40
|
return true
|
44
41
|
end
|
45
42
|
end
|
46
|
-
is_non_atomic = function(node)
|
47
|
-
return non_atomic[ntype(node)]
|
48
|
-
end
|
49
43
|
count_lines = function(str)
|
50
44
|
local count = 1
|
51
45
|
for _ in str:gmatch("\n") do
|
@@ -2,6 +2,7 @@ module("moonscript.compile", package.seeall)
|
|
2
2
|
local util = require("moonscript.util")
|
3
3
|
require("moonscript.compile.format")
|
4
4
|
local dump = require("moonscript.dump")
|
5
|
+
local transform = require("moonscript.transform")
|
5
6
|
local reversed = util.reversed
|
6
7
|
local ntype
|
7
8
|
do
|
@@ -11,11 +12,17 @@ end
|
|
11
12
|
local concat, insert = table.concat, table.insert
|
12
13
|
line_compile = {
|
13
14
|
raw = function(self, node)
|
14
|
-
|
15
|
-
|
15
|
+
return self:add(node[2])
|
16
|
+
end,
|
17
|
+
lines = function(self, node)
|
18
|
+
local _list_0 = node[2]
|
19
|
+
for _index_0 = 1, #_list_0 do
|
20
|
+
local line = _list_0[_index_0]
|
21
|
+
self:add(line)
|
22
|
+
end
|
16
23
|
end,
|
17
24
|
declare = function(self, node)
|
18
|
-
local
|
25
|
+
local names = node[2]
|
19
26
|
local undeclared = self:declare(names)
|
20
27
|
if #undeclared > 0 then
|
21
28
|
do
|
@@ -23,7 +30,7 @@ line_compile = {
|
|
23
30
|
_with_0:append_list((function()
|
24
31
|
local _accum_0 = { }
|
25
32
|
local _len_0 = 0
|
26
|
-
local _list_0 =
|
33
|
+
local _list_0 = undeclared
|
27
34
|
for _index_0 = 1, #_list_0 do
|
28
35
|
local name = _list_0[_index_0]
|
29
36
|
_len_0 = _len_0 + 1
|
@@ -35,6 +42,25 @@ line_compile = {
|
|
35
42
|
end
|
36
43
|
end
|
37
44
|
end,
|
45
|
+
declare_with_shadows = function(self, node)
|
46
|
+
local names = node[2]
|
47
|
+
self:declare(names)
|
48
|
+
do
|
49
|
+
local _with_0 = self:line("local ")
|
50
|
+
_with_0:append_list((function()
|
51
|
+
local _accum_0 = { }
|
52
|
+
local _len_0 = 0
|
53
|
+
local _list_0 = names
|
54
|
+
for _index_0 = 1, #_list_0 do
|
55
|
+
local name = _list_0[_index_0]
|
56
|
+
_len_0 = _len_0 + 1
|
57
|
+
_accum_0[_len_0] = self:name(name)
|
58
|
+
end
|
59
|
+
return _accum_0
|
60
|
+
end)(), ", ")
|
61
|
+
return _with_0
|
62
|
+
end
|
63
|
+
end,
|
38
64
|
assign = function(self, node)
|
39
65
|
local _, names, values = unpack(node)
|
40
66
|
local undeclared = self:declare(names)
|
@@ -123,31 +149,21 @@ line_compile = {
|
|
123
149
|
end
|
124
150
|
return root
|
125
151
|
end,
|
152
|
+
["repeat"] = function(self, node)
|
153
|
+
local cond, block = unpack(node, 2)
|
154
|
+
do
|
155
|
+
local _with_0 = self:block("repeat", self:line("until ", self:value(cond)))
|
156
|
+
_with_0:stms(block)
|
157
|
+
return _with_0
|
158
|
+
end
|
159
|
+
end,
|
126
160
|
["while"] = function(self, node)
|
127
161
|
local _, cond, block = unpack(node)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
_with_0:stm({
|
133
|
-
"if",
|
134
|
-
{
|
135
|
-
"not",
|
136
|
-
cond
|
137
|
-
},
|
138
|
-
{
|
139
|
-
{
|
140
|
-
"break"
|
141
|
-
}
|
142
|
-
}
|
143
|
-
})
|
144
|
-
out = _with_0
|
145
|
-
end
|
146
|
-
else
|
147
|
-
out = self:block(self:line("while ", self:value(cond), " do"))
|
162
|
+
do
|
163
|
+
local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
|
164
|
+
_with_0:stms(block)
|
165
|
+
return _with_0
|
148
166
|
end
|
149
|
-
out:stms(block)
|
150
|
-
return out
|
151
167
|
end,
|
152
168
|
["for"] = function(self, node)
|
153
169
|
local _, name, bounds, block = unpack(node)
|
@@ -157,12 +173,15 @@ line_compile = {
|
|
157
173
|
}), " do")
|
158
174
|
do
|
159
175
|
local _with_0 = self:block(loop)
|
176
|
+
_with_0:declare({
|
177
|
+
name
|
178
|
+
})
|
160
179
|
_with_0:stms(block)
|
161
180
|
return _with_0
|
162
181
|
end
|
163
182
|
end,
|
164
183
|
foreach = function(self, node)
|
165
|
-
local _, names,
|
184
|
+
local _, names, exps, block = unpack(node)
|
166
185
|
local loop
|
167
186
|
do
|
168
187
|
local _with_0 = self:line()
|
@@ -178,11 +197,24 @@ line_compile = {
|
|
178
197
|
end
|
179
198
|
return _accum_0
|
180
199
|
end)(), ", ")
|
181
|
-
_with_0:append(" in "
|
200
|
+
_with_0:append(" in ")
|
201
|
+
_with_0:append_list((function()
|
202
|
+
local _accum_0 = { }
|
203
|
+
local _len_0 = 0
|
204
|
+
local _list_0 = exps
|
205
|
+
for _index_0 = 1, #_list_0 do
|
206
|
+
local exp = _list_0[_index_0]
|
207
|
+
_len_0 = _len_0 + 1
|
208
|
+
_accum_0[_len_0] = self:value(exp)
|
209
|
+
end
|
210
|
+
return _accum_0
|
211
|
+
end)(), ",")
|
212
|
+
_with_0:append(" do")
|
182
213
|
loop = _with_0
|
183
214
|
end
|
184
215
|
do
|
185
216
|
local _with_0 = self:block(loop)
|
217
|
+
_with_0:declare(names)
|
186
218
|
_with_0:stms(block)
|
187
219
|
return _with_0
|
188
220
|
end
|
@@ -8,33 +8,7 @@ do
|
|
8
8
|
ntype = _table_0.ntype
|
9
9
|
end
|
10
10
|
local concat, insert = table.concat, table.insert
|
11
|
-
local
|
12
|
-
table_append = function(name, len, value)
|
13
|
-
return {
|
14
|
-
{
|
15
|
-
"update",
|
16
|
-
len,
|
17
|
-
"+=",
|
18
|
-
1
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"assign",
|
22
|
-
{
|
23
|
-
{
|
24
|
-
"chain",
|
25
|
-
name,
|
26
|
-
{
|
27
|
-
"index",
|
28
|
-
len
|
29
|
-
}
|
30
|
-
}
|
31
|
-
},
|
32
|
-
{
|
33
|
-
value
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
end
|
11
|
+
local table_delim = ","
|
38
12
|
value_compile = {
|
39
13
|
exp = function(self, node)
|
40
14
|
local _comp
|
@@ -60,11 +34,6 @@ value_compile = {
|
|
60
34
|
return _with_0
|
61
35
|
end
|
62
36
|
end,
|
63
|
-
update = function(self, node)
|
64
|
-
local _, name = unpack(node)
|
65
|
-
self:stm(node)
|
66
|
-
return self:name(name)
|
67
|
-
end,
|
68
37
|
explist = function(self, node)
|
69
38
|
do
|
70
39
|
local _with_0 = self:line()
|
@@ -86,8 +55,9 @@ value_compile = {
|
|
86
55
|
return self:line("(", self:value(node[2]), ")")
|
87
56
|
end,
|
88
57
|
string = function(self, node)
|
89
|
-
local _, delim, inner
|
90
|
-
|
58
|
+
local _, delim, inner = unpack(node)
|
59
|
+
local end_delim = delim:gsub("%[", "]")
|
60
|
+
return delim .. inner .. end_delim
|
91
61
|
end,
|
92
62
|
chain = function(self, node)
|
93
63
|
local callee = node[2]
|
@@ -118,8 +88,9 @@ value_compile = {
|
|
118
88
|
return error("Unknown chain action: " .. t)
|
119
89
|
end
|
120
90
|
end
|
121
|
-
|
122
|
-
|
91
|
+
local t = ntype(callee)
|
92
|
+
if (t == "self" or t == "self_class") and node[3] and ntype(node[3]) == "call" then
|
93
|
+
callee[1] = t .. "_colon"
|
123
94
|
end
|
124
95
|
local callee_value = self:value(callee)
|
125
96
|
if ntype(callee) == "exp" then
|
@@ -151,7 +122,7 @@ value_compile = {
|
|
151
122
|
if type(name) == "string" then
|
152
123
|
name = name
|
153
124
|
else
|
154
|
-
if name[1] == "self" then
|
125
|
+
if name[1] == "self" or name[1] == "self_class" then
|
155
126
|
insert(self_args, name)
|
156
127
|
end
|
157
128
|
name = name[2]
|
@@ -251,23 +222,22 @@ value_compile = {
|
|
251
222
|
local _, items = unpack(node)
|
252
223
|
do
|
253
224
|
local _with_0 = self:block("{", "}")
|
254
|
-
_with_0.delim = ","
|
255
225
|
local format_line
|
256
226
|
format_line = function(tuple)
|
257
227
|
if #tuple == 2 then
|
258
228
|
local key, value = unpack(tuple)
|
259
|
-
if
|
229
|
+
if ntype(key) == "key_literal" and data.lua_keywords[key[2]] then
|
260
230
|
key = {
|
261
231
|
"string",
|
262
232
|
'"',
|
263
|
-
key
|
233
|
+
key[2]
|
264
234
|
}
|
265
235
|
end
|
266
236
|
local assign
|
267
|
-
if
|
268
|
-
assign =
|
237
|
+
if ntype(key) == "key_literal" then
|
238
|
+
assign = key[2]
|
269
239
|
else
|
270
|
-
assign = key
|
240
|
+
assign = self:line("[", _with_0:value(key), "]")
|
271
241
|
end
|
272
242
|
_with_0:set("current_block", key)
|
273
243
|
local out = self:line(assign, " = ", _with_0:value(value))
|
@@ -278,10 +248,13 @@ value_compile = {
|
|
278
248
|
end
|
279
249
|
end
|
280
250
|
if items then
|
281
|
-
local
|
282
|
-
for
|
283
|
-
local line =
|
284
|
-
|
251
|
+
local count = #items
|
252
|
+
for i, tuple in ipairs(items) do
|
253
|
+
local line = format_line(tuple)
|
254
|
+
if not (count == i) then
|
255
|
+
line:append(table_delim)
|
256
|
+
end
|
257
|
+
_with_0:add(line)
|
285
258
|
end
|
286
259
|
end
|
287
260
|
return _with_0
|
@@ -305,16 +278,22 @@ value_compile = {
|
|
305
278
|
self = function(self, node)
|
306
279
|
return "self." .. self:value(node[2])
|
307
280
|
end,
|
281
|
+
self_class = function(self, node)
|
282
|
+
return "self.__class." .. self:value(node[2])
|
283
|
+
end,
|
308
284
|
self_colon = function(self, node)
|
309
285
|
return "self:" .. self:value(node[2])
|
310
286
|
end,
|
287
|
+
self_class_colon = function(self, node)
|
288
|
+
return "self.__class:" .. self:value(node[2])
|
289
|
+
end,
|
311
290
|
raw_value = function(self, value)
|
312
291
|
local sup = self:get("super")
|
313
292
|
if value == "super" and sup then
|
314
293
|
return self:value(sup(self))
|
315
294
|
end
|
316
295
|
if value == "..." then
|
317
|
-
self
|
296
|
+
self:send("varargs")
|
318
297
|
end
|
319
298
|
return tostring(value)
|
320
299
|
end
|
@@ -9,7 +9,7 @@ Set = function(items)
|
|
9
9
|
end
|
10
10
|
return self
|
11
11
|
end
|
12
|
-
|
12
|
+
do
|
13
13
|
local _parent_0 = nil
|
14
14
|
local _base_0 = {
|
15
15
|
__tostring = function(self)
|
@@ -60,8 +60,11 @@ Stack = (function()
|
|
60
60
|
end
|
61
61
|
})
|
62
62
|
_base_0.__class = _class_0
|
63
|
-
|
64
|
-
|
63
|
+
if _parent_0 and _parent_0.__inherited then
|
64
|
+
_parent_0.__inherited(_parent_0, _class_0)
|
65
|
+
end
|
66
|
+
Stack = _class_0
|
67
|
+
end
|
65
68
|
lua_keywords = Set({
|
66
69
|
'and',
|
67
70
|
'break',
|
@@ -85,3 +88,4 @@ lua_keywords = Set({
|
|
85
88
|
'until',
|
86
89
|
'while'
|
87
90
|
})
|
91
|
+
return nil
|
@@ -28,15 +28,9 @@ value = function(op)
|
|
28
28
|
return flat_value(op)
|
29
29
|
end
|
30
30
|
tree = function(block)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
value = _list_0[_index_0]
|
37
|
-
_len_0 = _len_0 + 1
|
38
|
-
_accum_0[_len_0] = print(flat_value(value))
|
39
|
-
end
|
40
|
-
return _accum_0
|
41
|
-
end)()
|
31
|
+
local _list_0 = block
|
32
|
+
for _index_0 = 1, #_list_0 do
|
33
|
+
value = _list_0[_index_0]
|
34
|
+
print(flat_value(value))
|
35
|
+
end
|
42
36
|
end
|
@@ -24,6 +24,34 @@ reverse_line_number = function(fname, line_table, line_num, cache)
|
|
24
24
|
end
|
25
25
|
return "unknown"
|
26
26
|
end
|
27
|
+
truncate_traceback = function(traceback, chunk_func)
|
28
|
+
if chunk_func == nil then
|
29
|
+
chunk_func = "moonscript_chunk"
|
30
|
+
end
|
31
|
+
traceback = split(traceback, "\n")
|
32
|
+
local stop = #traceback
|
33
|
+
while stop > 1 do
|
34
|
+
if traceback[stop]:match(chunk_func) then
|
35
|
+
break
|
36
|
+
end
|
37
|
+
stop = stop - 1
|
38
|
+
end
|
39
|
+
traceback = (function()
|
40
|
+
local _accum_0 = { }
|
41
|
+
local _len_0 = 0
|
42
|
+
local _list_0 = traceback
|
43
|
+
local _max_0 = stop
|
44
|
+
for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do
|
45
|
+
local t = _list_0[_index_0]
|
46
|
+
_len_0 = _len_0 + 1
|
47
|
+
_accum_0[_len_0] = t
|
48
|
+
end
|
49
|
+
return _accum_0
|
50
|
+
end)()
|
51
|
+
local rep = "function '" .. chunk_func .. "'"
|
52
|
+
traceback[#traceback] = traceback[#traceback]:gsub(rep, "main chunk")
|
53
|
+
return concat(traceback, "\n")
|
54
|
+
end
|
27
55
|
rewrite_traceback = function(text, err)
|
28
56
|
local line_tables = moon.line_tables
|
29
57
|
local V, S, Ct, C = lpeg.V, lpeg.S, lpeg.Ct, lpeg.C
|
@@ -45,6 +73,9 @@ rewrite_traceback = function(text, err)
|
|
45
73
|
fname,
|
46
74
|
":",
|
47
75
|
reverse_line_number(fname, tbl, line, cache),
|
76
|
+
"(",
|
77
|
+
line,
|
78
|
+
")",
|
48
79
|
": ",
|
49
80
|
msg
|
50
81
|
})
|
@@ -54,11 +85,14 @@ rewrite_traceback = function(text, err)
|
|
54
85
|
end
|
55
86
|
err = rewrite_single(err)
|
56
87
|
local match = g:match(text)
|
88
|
+
if not (match) then
|
89
|
+
return nil
|
90
|
+
end
|
57
91
|
for i, trace in ipairs(match) do
|
58
92
|
match[i] = rewrite_single(trace)
|
59
93
|
end
|
60
94
|
return concat({
|
61
|
-
"moon:" .. err,
|
95
|
+
"moon: " .. err,
|
62
96
|
header_text,
|
63
97
|
"\t" .. concat(match, "\n\t")
|
64
98
|
}, "\n")
|
@@ -20,7 +20,10 @@ create_moonpath = function(package_path)
|
|
20
20
|
end
|
21
21
|
return concat(paths, ";")
|
22
22
|
end
|
23
|
-
to_lua = function(text)
|
23
|
+
to_lua = function(text, options)
|
24
|
+
if options == nil then
|
25
|
+
options = { }
|
26
|
+
end
|
24
27
|
if "string" ~= type(text) then
|
25
28
|
local t = type(text)
|
26
29
|
error("expecting string (got " .. t .. ")", 2)
|
@@ -29,7 +32,7 @@ to_lua = function(text)
|
|
29
32
|
if not tree then
|
30
33
|
error(err, 2)
|
31
34
|
end
|
32
|
-
local code, ltable, pos = compile.tree(tree)
|
35
|
+
local code, ltable, pos = compile.tree(tree, options)
|
33
36
|
if not code then
|
34
37
|
error(compile.format_error(ltable, pos, text), 2)
|
35
38
|
end
|
@@ -49,6 +52,7 @@ moon_loader = function(name)
|
|
49
52
|
end
|
50
53
|
if file then
|
51
54
|
local text = file:read("*a")
|
55
|
+
file:close()
|
52
56
|
return loadstring(text, file_path)
|
53
57
|
else
|
54
58
|
return nil, "Could not find moon file"
|
@@ -64,9 +68,12 @@ end
|
|
64
68
|
if not _G.moon_no_loader then
|
65
69
|
init_loader()
|
66
70
|
end
|
67
|
-
loadstring = function(str, chunk_name)
|
71
|
+
loadstring = function(str, chunk_name, options)
|
72
|
+
if options == nil then
|
73
|
+
options = nil
|
74
|
+
end
|
68
75
|
local passed, code, ltable = pcall(function()
|
69
|
-
return to_lua(str)
|
76
|
+
return to_lua(str, options)
|
70
77
|
end)
|
71
78
|
if not passed then
|
72
79
|
error(chunk_name .. ": " .. code, 2)
|
@@ -76,15 +83,19 @@ loadstring = function(str, chunk_name)
|
|
76
83
|
end
|
77
84
|
return lua.loadstring(code, chunk_name or "=(moonscript.loadstring)")
|
78
85
|
end
|
79
|
-
loadfile = function(fname)
|
86
|
+
loadfile = function(fname, options)
|
87
|
+
if options == nil then
|
88
|
+
options = nil
|
89
|
+
end
|
80
90
|
local file, err = io.open(fname)
|
81
91
|
if not file then
|
82
92
|
return nil, err
|
83
93
|
end
|
84
94
|
local text = assert(file:read("*a"))
|
85
|
-
|
95
|
+
file:close()
|
96
|
+
return loadstring(text, fname, options)
|
86
97
|
end
|
87
|
-
dofile = function(fname)
|
98
|
+
dofile = function(fname, options)
|
88
99
|
local f = assert(loadfile(fname))
|
89
100
|
return f()
|
90
101
|
end
|