rufus-lua-moon 0.2.4.0 → 0.2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c432105ec4dd74d5e144bda27c32f6ef821b6182
4
- data.tar.gz: f31a4a954e0f48ab813568b16063d26e2cc27258
3
+ metadata.gz: a7190b583c1d9cf355c5ce5f685513fc19111d18
4
+ data.tar.gz: 3abbedc70d9db04e7b0b7f5f018d09651d147e48
5
5
  SHA512:
6
- metadata.gz: 2969e129ef6740d431a6b971a371c5502e8920f20fd37e2278def0ca087c25bb03ecee884a990a21d9b52ffac5d07320537261e79a404fd1da7e1e9b3dd8db35
7
- data.tar.gz: 3a9333b3cbacb4ee8f95d10abf195ed80775f6bd8fe45b6304e0a39367a088344b419656ba1f553cd42ad3883602bf75bdb36a565b1dfcb44f88df5531c3a5a4
6
+ metadata.gz: e70ba8a5a494e8ee3ff55dc5cf46570b3dd80b91a0261a45525ab9b9dde0730e457454e1381508155ec5a88fffe3acea110051d761b3ff0aef646580b3a6f6a0
7
+ data.tar.gz: b465395ebe85e03185b25c7d1e50178f8cb2b3d1552c9716f939d30262e7ea16f0c268e1dadcfa03e8906465c4358cb1ec9475c2775eb4c39fc372d5b55c6607
@@ -1,2 +1,137 @@
1
- _G.moon_no_loader = true
2
- return require("moonscript")
1
+ local compile = require("moonscript.compile")
2
+ local parse = require("moonscript.parse")
3
+ local concat, insert, remove
4
+ do
5
+ local _obj_0 = table
6
+ concat, insert, remove = _obj_0.concat, _obj_0.insert, _obj_0.remove
7
+ end
8
+ local split, dump, get_options, unpack
9
+ do
10
+ local _obj_0 = require("moonscript.util")
11
+ split, dump, get_options, unpack = _obj_0.split, _obj_0.dump, _obj_0.get_options, _obj_0.unpack
12
+ end
13
+ local lua = {
14
+ loadstring = loadstring,
15
+ load = load
16
+ }
17
+ local dirsep, line_tables, create_moonpath, to_lua, moon_loader, loadstring, loadfile, dofile, insert_loader, remove_loader
18
+ dirsep = "/"
19
+ line_tables = require("moonscript.line_tables")
20
+ create_moonpath = function(package_path)
21
+ local paths = split(package_path, ";")
22
+ for i, path in ipairs(paths) do
23
+ local p = path:match("^(.-)%.lua$")
24
+ if p then
25
+ paths[i] = p .. ".moon"
26
+ end
27
+ end
28
+ return concat(paths, ";")
29
+ end
30
+ to_lua = function(text, options)
31
+ if options == nil then
32
+ options = { }
33
+ end
34
+ if "string" ~= type(text) then
35
+ local t = type(text)
36
+ return nil, "expecting string (got " .. t .. ")", 2
37
+ end
38
+ local tree, err = parse.string(text)
39
+ if not tree then
40
+ return nil, err
41
+ end
42
+ local code, ltable, pos = compile.tree(tree, options)
43
+ if not code then
44
+ return nil, compile.format_error(ltable, pos, text), 2
45
+ end
46
+ return code, ltable
47
+ end
48
+ moon_loader = function(name)
49
+ local name_path = name:gsub("%.", dirsep)
50
+ local file, file_path
51
+ local _list_0 = split(package.moonpath, ";")
52
+ for _index_0 = 1, #_list_0 do
53
+ local path = _list_0[_index_0]
54
+ file_path = path:gsub("?", name_path)
55
+ file = io.open(file_path)
56
+ if file then
57
+ break
58
+ end
59
+ end
60
+ if file then
61
+ local text = file:read("*a")
62
+ file:close()
63
+ local res, err = loadstring(text, file_path)
64
+ if not res then
65
+ error(file_path .. ": " .. err)
66
+ end
67
+ return res
68
+ end
69
+ return nil, "Could not find moon file"
70
+ end
71
+ loadstring = function(...)
72
+ local options, str, chunk_name, mode, env = get_options(...)
73
+ chunk_name = chunk_name or "=(moonscript.loadstring)"
74
+ local code, ltable_or_err = to_lua(str, options)
75
+ if not (code) then
76
+ return nil, ltable_or_err
77
+ end
78
+ if chunk_name then
79
+ line_tables[chunk_name] = ltable_or_err
80
+ end
81
+ return (lua.loadstring or lua.load)(code, chunk_name, unpack({
82
+ mode,
83
+ env
84
+ }))
85
+ end
86
+ loadfile = function(fname, ...)
87
+ local file, err = io.open(fname)
88
+ if not (file) then
89
+ return nil, err
90
+ end
91
+ local text = assert(file:read("*a"))
92
+ file:close()
93
+ return loadstring(text, fname, ...)
94
+ end
95
+ dofile = function(...)
96
+ local f = assert(loadfile(...))
97
+ return f()
98
+ end
99
+ insert_loader = function(pos)
100
+ if pos == nil then
101
+ pos = 2
102
+ end
103
+ if not package.moonpath then
104
+ package.moonpath = create_moonpath(package.path)
105
+ end
106
+ local loaders = package.loaders or package.searchers
107
+ for _index_0 = 1, #loaders do
108
+ local loader = loaders[_index_0]
109
+ if loader == moon_loader then
110
+ return false
111
+ end
112
+ end
113
+ insert(loaders, pos, moon_loader)
114
+ return true
115
+ end
116
+ remove_loader = function()
117
+ local loaders = package.loaders or package.searchers
118
+ for i, loader in ipairs(loaders) do
119
+ if loader == moon_loader then
120
+ remove(loaders, i)
121
+ return true
122
+ end
123
+ end
124
+ return false
125
+ end
126
+ return {
127
+ _NAME = "moonscript",
128
+ insert_loader = insert_loader,
129
+ remove_loader = remove_loader,
130
+ to_lua = to_lua,
131
+ moon_chunk = moon_chunk,
132
+ moon_loader = moon_loader,
133
+ dirsep = dirsep,
134
+ dofile = dofile,
135
+ loadfile = loadfile,
136
+ loadstring = loadstring
137
+ }
@@ -0,0 +1,142 @@
1
+ local log
2
+ log = function(str)
3
+ if str == nil then
4
+ str = ""
5
+ end
6
+ return io.stderr:write(str .. "\n")
7
+ end
8
+ local create_counter
9
+ create_counter = function()
10
+ return setmetatable({ }, {
11
+ __index = function(self, name)
12
+ do
13
+ local tbl = setmetatable({ }, {
14
+ __index = function(self)
15
+ return 0
16
+ end
17
+ })
18
+ self[name] = tbl
19
+ return tbl
20
+ end
21
+ end
22
+ })
23
+ end
24
+ local position_to_lines
25
+ position_to_lines = function(file_content, positions)
26
+ local lines = { }
27
+ local current_pos = 0
28
+ local line_no = 1
29
+ for char in file_content:gmatch(".") do
30
+ do
31
+ local count = rawget(positions, current_pos)
32
+ if count then
33
+ lines[line_no] = count
34
+ end
35
+ end
36
+ if char == "\n" then
37
+ line_no = line_no + 1
38
+ end
39
+ current_pos = current_pos + 1
40
+ end
41
+ return lines
42
+ end
43
+ local format_file
44
+ format_file = function(fname, positions)
45
+ local file = assert(io.open(fname))
46
+ local content = file:read("*a")
47
+ file:close()
48
+ local lines = position_to_lines(content, positions)
49
+ log("------| @" .. tostring(fname))
50
+ local line_no = 1
51
+ for line in (content .. "\n"):gmatch("(.-)\n") do
52
+ local foramtted_no = ("% 5d"):format(line_no)
53
+ local sym = lines[line_no] and "*" or " "
54
+ log(tostring(sym) .. tostring(foramtted_no) .. "| " .. tostring(line))
55
+ line_no = line_no + 1
56
+ end
57
+ return log()
58
+ end
59
+ local CodeCoverage
60
+ do
61
+ local _base_0 = {
62
+ reset = function(self)
63
+ self.line_counts = create_counter()
64
+ end,
65
+ start = function(self)
66
+ return debug.sethook((function()
67
+ local _base_1 = self
68
+ local _fn_0 = _base_1.process_line
69
+ return function(...)
70
+ return _fn_0(_base_1, ...)
71
+ end
72
+ end)(), "l")
73
+ end,
74
+ stop = function(self)
75
+ return debug.sethook()
76
+ end,
77
+ print_results = function(self)
78
+ return self:format_results()
79
+ end,
80
+ process_line = function(self, _, line_no)
81
+ local debug_data = debug.getinfo(2, "S")
82
+ local source = debug_data.source
83
+ self.line_counts[source][line_no] = self.line_counts[source][line_no] + 1
84
+ end,
85
+ format_results = function(self)
86
+ local line_table = require("moonscript.line_tables")
87
+ local positions = create_counter()
88
+ for file, lines in pairs(self.line_counts) do
89
+ local _continue_0 = false
90
+ repeat
91
+ local file_table = line_table[file]
92
+ if not (file_table) then
93
+ _continue_0 = true
94
+ break
95
+ end
96
+ for line, count in pairs(lines) do
97
+ local _continue_1 = false
98
+ repeat
99
+ local position = file_table[line]
100
+ if not (position) then
101
+ _continue_1 = true
102
+ break
103
+ end
104
+ positions[file][position] = positions[file][position] + count
105
+ _continue_1 = true
106
+ until true
107
+ if not _continue_1 then
108
+ break
109
+ end
110
+ end
111
+ _continue_0 = true
112
+ until true
113
+ if not _continue_0 then
114
+ break
115
+ end
116
+ end
117
+ for file, ps in pairs(positions) do
118
+ format_file(file, ps)
119
+ end
120
+ end
121
+ }
122
+ _base_0.__index = _base_0
123
+ local _class_0 = setmetatable({
124
+ __init = function(self)
125
+ return self:reset()
126
+ end,
127
+ __base = _base_0,
128
+ __name = "CodeCoverage"
129
+ }, {
130
+ __index = _base_0,
131
+ __call = function(cls, ...)
132
+ local _self_0 = setmetatable({}, _base_0)
133
+ cls.__init(_self_0, ...)
134
+ return _self_0
135
+ end
136
+ })
137
+ _base_0.__class = _class_0
138
+ CodeCoverage = _class_0
139
+ end
140
+ return {
141
+ CodeCoverage = CodeCoverage
142
+ }
@@ -0,0 +1,214 @@
1
+ local insert
2
+ do
3
+ local _obj_0 = table
4
+ insert = _obj_0.insert
5
+ end
6
+ local Set
7
+ do
8
+ local _obj_0 = require("moonscript.data")
9
+ Set = _obj_0.Set
10
+ end
11
+ local Block
12
+ do
13
+ local _obj_0 = require("moonscript.compile")
14
+ Block = _obj_0.Block
15
+ end
16
+ local default_whitelist = Set({
17
+ '_G',
18
+ '_VERSION',
19
+ 'assert',
20
+ 'bit32',
21
+ 'collectgarbage',
22
+ 'coroutine',
23
+ 'debug',
24
+ 'dofile',
25
+ 'error',
26
+ 'getfenv',
27
+ 'getmetatable',
28
+ 'io',
29
+ 'ipairs',
30
+ 'load',
31
+ 'loadfile',
32
+ 'loadstring',
33
+ 'math',
34
+ 'module',
35
+ 'next',
36
+ 'os',
37
+ 'package',
38
+ 'pairs',
39
+ 'pcall',
40
+ 'print',
41
+ 'rawequal',
42
+ 'rawget',
43
+ 'rawlen',
44
+ 'rawset',
45
+ 'require',
46
+ 'select',
47
+ 'setfenv',
48
+ 'setmetatable',
49
+ 'string',
50
+ 'table',
51
+ 'tonumber',
52
+ 'tostring',
53
+ 'type',
54
+ 'unpack',
55
+ 'xpcall',
56
+ "nil",
57
+ "true",
58
+ "false"
59
+ })
60
+ local LinterBlock
61
+ do
62
+ local _parent_0 = Block
63
+ local _base_0 = {
64
+ block = function(self, ...)
65
+ do
66
+ local _with_0 = _parent_0.block(self, ...)
67
+ _with_0.block = self.block
68
+ _with_0.value_compilers = self.value_compilers
69
+ return _with_0
70
+ end
71
+ end
72
+ }
73
+ _base_0.__index = _base_0
74
+ setmetatable(_base_0, _parent_0.__base)
75
+ local _class_0 = setmetatable({
76
+ __init = function(self, whitelist_globals, ...)
77
+ if whitelist_globals == nil then
78
+ whitelist_globals = default_whitelist
79
+ end
80
+ _parent_0.__init(self, ...)
81
+ self.lint_errors = { }
82
+ local vc = self.value_compilers
83
+ self.value_compilers = setmetatable({
84
+ ref = function(block, val)
85
+ local name = val[2]
86
+ if not (block:has_name(name) or whitelist_globals[name] or name:match("%.")) then
87
+ insert(self.lint_errors, {
88
+ "accessing global " .. tostring(name),
89
+ val[-1]
90
+ })
91
+ end
92
+ return vc.ref(block, val)
93
+ end
94
+ }, {
95
+ __index = vc
96
+ })
97
+ end,
98
+ __base = _base_0,
99
+ __name = "LinterBlock",
100
+ __parent = _parent_0
101
+ }, {
102
+ __index = function(cls, name)
103
+ local val = rawget(_base_0, name)
104
+ if val == nil then
105
+ return _parent_0[name]
106
+ else
107
+ return val
108
+ end
109
+ end,
110
+ __call = function(cls, ...)
111
+ local _self_0 = setmetatable({}, _base_0)
112
+ cls.__init(_self_0, ...)
113
+ return _self_0
114
+ end
115
+ })
116
+ _base_0.__class = _class_0
117
+ if _parent_0.__inherited then
118
+ _parent_0.__inherited(_parent_0, _class_0)
119
+ end
120
+ LinterBlock = _class_0
121
+ end
122
+ local format_lint
123
+ format_lint = function(errors, code, header)
124
+ if not (next(errors)) then
125
+ return
126
+ end
127
+ local pos_to_line, get_line
128
+ do
129
+ local _obj_0 = require("moonscript.util")
130
+ pos_to_line, get_line = _obj_0.pos_to_line, _obj_0.get_line
131
+ end
132
+ local formatted
133
+ do
134
+ local _accum_0 = { }
135
+ local _len_0 = 1
136
+ for _index_0 = 1, #errors do
137
+ local _des_0 = errors[_index_0]
138
+ local msg, pos
139
+ msg, pos = _des_0[1], _des_0[2]
140
+ if pos then
141
+ local line = pos_to_line(code, pos)
142
+ msg = "line " .. tostring(line) .. ": " .. tostring(msg)
143
+ local line_text = "> " .. get_line(code, line)
144
+ local sep_len = math.max(#msg, #line_text)
145
+ _accum_0[_len_0] = table.concat({
146
+ msg,
147
+ ("="):rep(sep_len),
148
+ line_text
149
+ }, "\n")
150
+ else
151
+ _accum_0[_len_0] = msg
152
+ end
153
+ _len_0 = _len_0 + 1
154
+ end
155
+ formatted = _accum_0
156
+ end
157
+ if header then
158
+ table.insert(formatted, 1, header)
159
+ end
160
+ return table.concat(formatted, "\n\n")
161
+ end
162
+ local whitelist_for_file
163
+ do
164
+ local lint_config
165
+ whitelist_for_file = function(fname)
166
+ if not (lint_config) then
167
+ lint_config = { }
168
+ pcall(function()
169
+ lint_config = require("lint_config")
170
+ end)
171
+ end
172
+ if not (lint_config.whitelist_globals) then
173
+ return default_whitelist
174
+ end
175
+ local final_list = { }
176
+ for pattern, list in pairs(lint_config.whitelist_globals) do
177
+ if fname:match(pattern) then
178
+ for _index_0 = 1, #list do
179
+ local item = list[_index_0]
180
+ insert(final_list, item)
181
+ end
182
+ end
183
+ end
184
+ return setmetatable(Set(final_list), {
185
+ __index = default_whitelist
186
+ })
187
+ end
188
+ end
189
+ local lint_code
190
+ lint_code = function(code, name, whitelist_globals)
191
+ if name == nil then
192
+ name = "string input"
193
+ end
194
+ local parse = require("moonscript.parse")
195
+ local tree, err = parse.string(code)
196
+ if not (tree) then
197
+ return nil, err
198
+ end
199
+ local scope = LinterBlock(whitelist_globals)
200
+ scope:stms(tree)
201
+ return format_lint(scope.lint_errors, code, name)
202
+ end
203
+ local lint_file
204
+ lint_file = function(fname)
205
+ local f, err = io.open(fname)
206
+ if not (f) then
207
+ return nil, err
208
+ end
209
+ return lint_code(f:read("*a"), fname, whitelist_for_file(fname))
210
+ end
211
+ return {
212
+ lint_code = lint_code,
213
+ lint_file = lint_file
214
+ }
@@ -16,16 +16,8 @@ do
16
16
  local _obj_0 = require("moonscript.types")
17
17
  ntype, has_value = _obj_0.ntype, _obj_0.has_value
18
18
  end
19
- local statement_compilers
20
- do
21
- local _obj_0 = require("moonscript.compile.statement")
22
- statement_compilers = _obj_0.statement_compilers
23
- end
24
- local value_compilers
25
- do
26
- local _obj_0 = require("moonscript.compile.value")
27
- value_compilers = _obj_0.value_compilers
28
- end
19
+ local statement_compilers = require("moonscript.compile.statement")
20
+ local value_compilers = require("moonscript.compile.value")
29
21
  local concat, insert
30
22
  do
31
23
  local _obj_0 = table
@@ -69,6 +61,9 @@ do
69
61
  local _exp_0 = mtype(l)
70
62
  if "string" == _exp_0 or DelayedLine == _exp_0 then
71
63
  line_no = line_no + 1
64
+ for _ in l:gmatch("\n") do
65
+ line_no = line_no + 1
66
+ end
72
67
  out[line_no] = posmap[i]
73
68
  elseif Lines == _exp_0 then
74
69
  local _
@@ -271,6 +266,7 @@ do
271
266
  footer = "end",
272
267
  export_all = false,
273
268
  export_proper = false,
269
+ value_compilers = value_compilers,
274
270
  __tostring = function(self)
275
271
  local h
276
272
  if "string" == type(self.header) then
@@ -320,6 +316,8 @@ do
320
316
  real_name = name:get_name(self)
321
317
  elseif NameProxy == _exp_0 then
322
318
  real_name = name:get_name(self)
319
+ elseif "table" == _exp_0 then
320
+ real_name = name[1] == "ref" and name[2]
323
321
  elseif "string" == _exp_0 then
324
322
  real_name = name
325
323
  end
@@ -387,8 +385,10 @@ do
387
385
  if t == NameProxy or t == LocalName then
388
386
  return true
389
387
  end
390
- if t == "table" and node[1] == "chain" and #node == 2 then
391
- return self:is_local(node[2])
388
+ if t == "table" then
389
+ if node[1] == "ref" or (node[1] == "chain" and #node == 2) then
390
+ return self:is_local(node[2])
391
+ end
392
392
  end
393
393
  return false
394
394
  end,
@@ -459,10 +459,14 @@ do
459
459
  end,
460
460
  is_value = function(self, node)
461
461
  local t = ntype(node)
462
- return value_compilers[t] ~= nil or t == "value"
462
+ return self.value_compilers[t] ~= nil or t == "value"
463
463
  end,
464
464
  name = function(self, node, ...)
465
- return self:value(node, ...)
465
+ if type(node) == "string" then
466
+ return node
467
+ else
468
+ return self:value(node, ...)
469
+ end
466
470
  end,
467
471
  value = function(self, node, ...)
468
472
  node = self.transform.value(node)
@@ -472,9 +476,13 @@ do
472
476
  else
473
477
  action = node[1]
474
478
  end
475
- local fn = value_compilers[action]
476
- if not fn then
477
- error("Failed to compile value: " .. dump.value(node))
479
+ local fn = self.value_compilers[action]
480
+ if not (fn) then
481
+ error({
482
+ "compile-error",
483
+ "Failed to find value compiler for: " .. dump.value(node),
484
+ node[-1]
485
+ })
478
486
  end
479
487
  local out = fn(self, node, ...)
480
488
  if type(node) == "table" and node[-1] then
@@ -658,13 +666,17 @@ do
658
666
  end
659
667
  local format_error
660
668
  format_error = function(msg, pos, file_str)
661
- local line = pos_to_line(file_str, pos)
662
- local line_str
663
- line_str, line = get_closest_line(file_str, line)
664
- line_str = line_str or ""
669
+ local line_message
670
+ if pos then
671
+ local line = pos_to_line(file_str, pos)
672
+ local line_str
673
+ line_str, line = get_closest_line(file_str, line)
674
+ line_str = line_str or ""
675
+ line_message = (" [%d] >> %s"):format(line, trim(line_str))
676
+ end
665
677
  return concat({
666
678
  "Compile error: " .. msg,
667
- (" [%d] >> %s"):format(line, trim(line_str))
679
+ line_message
668
680
  }, "\n")
669
681
  end
670
682
  local value
@@ -688,27 +700,27 @@ tree = function(tree, options)
688
700
  return scope:root_stms(tree)
689
701
  end)
690
702
  local success, err = coroutine.resume(runner)
691
- if not success then
692
- local error_msg
703
+ if not (success) then
704
+ local error_msg, error_pos
693
705
  if type(err) == "table" then
694
706
  local error_type = err[1]
695
- if error_type == "user-error" then
696
- error_msg = err[2]
707
+ local _exp_0 = err[1]
708
+ if "user-error" == _exp_0 or "compile-error" == _exp_0 then
709
+ error_msg, error_pos = unpack(err, 2)
697
710
  else
698
- error_msg = error("Unknown error thrown", util.dump(error_msg))
711
+ error_msg, error_pos = error("Unknown error thrown", util.dump(error_msg))
699
712
  end
700
713
  else
701
- error_msg = concat({
714
+ error_msg, error_pos = concat({
702
715
  err,
703
716
  debug.traceback(runner)
704
717
  }, "\n")
705
718
  end
706
- return nil, error_msg, scope.last_pos
707
- else
708
- local lua_code = scope:render()
709
- local posmap = scope._lines:flatten_posmap()
710
- return lua_code, posmap
719
+ return nil, error_msg, error_pos or scope.last_pos
711
720
  end
721
+ local lua_code = scope:render()
722
+ local posmap = scope._lines:flatten_posmap()
723
+ return lua_code, posmap
712
724
  end
713
725
  do
714
726
  local data = require("moonscript.data")
@@ -12,7 +12,7 @@ do
12
12
  local _obj_0 = table
13
13
  concat, insert = _obj_0.concat, _obj_0.insert
14
14
  end
15
- local statement_compilers = {
15
+ return {
16
16
  raw = function(self, node)
17
17
  return self:add(node[2])
18
18
  end,
@@ -243,6 +243,3 @@ local statement_compilers = {
243
243
  end,
244
244
  noop = function(self) end
245
245
  }
246
- return {
247
- statement_compilers = statement_compilers
248
- }
@@ -22,7 +22,7 @@ local string_chars = {
22
22
  ["\r"] = "\\r",
23
23
  ["\n"] = "\\n"
24
24
  }
25
- local value_compilers = {
25
+ return {
26
26
  exp = function(self, node)
27
27
  local _comp
28
28
  _comp = function(i, value)
@@ -76,15 +76,20 @@ local value_compilers = {
76
76
  end,
77
77
  chain = function(self, node)
78
78
  local callee = node[2]
79
+ local callee_type = ntype(callee)
79
80
  if callee == -1 then
80
81
  callee = self:get("scope_var")
81
82
  if not callee then
82
83
  user_error("Short-dot syntax must be called within a with block")
83
84
  end
84
85
  end
85
- local sup = self:get("super")
86
- if callee == "super" and sup then
87
- return self:value(sup(self, node))
86
+ if callee_type == "ref" and callee[2] == "super" or callee == "super" then
87
+ do
88
+ local sup = self:get("super")
89
+ if sup then
90
+ return self:value(sup(self, node))
91
+ end
92
+ end
88
93
  end
89
94
  local chain_item
90
95
  chain_item = function(node)
@@ -100,12 +105,11 @@ local value_compilers = {
100
105
  elseif t == "colon_stub" then
101
106
  return user_error("Uncalled colon stub")
102
107
  else
103
- return error("Unknown chain action: " .. t)
108
+ return error("Unknown chain action: " .. tostring(t))
104
109
  end
105
110
  end
106
- local t = ntype(callee)
107
- if (t == "self" or t == "self_class") and node[3] and ntype(node[3]) == "call" then
108
- callee[1] = t .. "_colon"
111
+ if (callee_type == "self" or callee_type == "self_class") and node[3] and ntype(node[3]) == "call" then
112
+ callee[1] = callee_type .. "_colon"
109
113
  end
110
114
  local callee_value = self:value(callee)
111
115
  if ntype(callee) == "exp" then
@@ -172,7 +176,10 @@ local value_compilers = {
172
176
  'if',
173
177
  {
174
178
  'exp',
175
- name,
179
+ {
180
+ "ref",
181
+ name
182
+ },
176
183
  '==',
177
184
  'nil'
178
185
  },
@@ -282,28 +289,30 @@ local value_compilers = {
282
289
  return self:line("not ", self:value(node[2]))
283
290
  end,
284
291
  self = function(self, node)
285
- return "self." .. self:value(node[2])
292
+ return "self." .. self:name(node[2])
286
293
  end,
287
294
  self_class = function(self, node)
288
- return "self.__class." .. self:value(node[2])
295
+ return "self.__class." .. self:name(node[2])
289
296
  end,
290
297
  self_colon = function(self, node)
291
- return "self:" .. self:value(node[2])
298
+ return "self:" .. self:name(node[2])
292
299
  end,
293
300
  self_class_colon = function(self, node)
294
- return "self.__class:" .. self:value(node[2])
301
+ return "self.__class:" .. self:name(node[2])
295
302
  end,
296
- raw_value = function(self, value)
297
- local sup = self:get("super")
298
- if value == "super" and sup then
299
- return self:value(sup(self))
303
+ ref = function(self, value)
304
+ do
305
+ local sup = value[2] == "super" and self:get("super")
306
+ if sup then
307
+ return self:value(sup(self))
308
+ end
300
309
  end
310
+ return tostring(value[2])
311
+ end,
312
+ raw_value = function(self, value)
301
313
  if value == "..." then
302
314
  self:send("varargs")
303
315
  end
304
316
  return tostring(value)
305
317
  end
306
318
  }
307
- return {
308
- value_compilers = value_compilers
309
- }
@@ -5,12 +5,12 @@ do
5
5
  end
6
6
  local Set
7
7
  Set = function(items)
8
- local self = { }
8
+ local _tbl_0 = { }
9
9
  for _index_0 = 1, #items do
10
- local key = items[_index_0]
11
- self[key] = true
10
+ local k = items[_index_0]
11
+ _tbl_0[k] = true
12
12
  end
13
- return self
13
+ return _tbl_0
14
14
  end
15
15
  local Stack
16
16
  do
@@ -21,9 +21,13 @@ do
21
21
  pop = function(self)
22
22
  return remove(self)
23
23
  end,
24
- push = function(self, value)
24
+ push = function(self, value, ...)
25
25
  insert(self, value)
26
- return value
26
+ if ... then
27
+ return self:push(...)
28
+ else
29
+ return value
30
+ end
27
31
  end,
28
32
  top = function(self)
29
33
  return self[#self]
@@ -32,13 +36,7 @@ do
32
36
  _base_0.__index = _base_0
33
37
  local _class_0 = setmetatable({
34
38
  __init = function(self, ...)
35
- local _list_0 = {
36
- ...
37
- }
38
- for _index_0 = 1, #_list_0 do
39
- local v = _list_0[_index_0]
40
- self:push(v)
41
- end
39
+ self:push(...)
42
40
  return nil
43
41
  end,
44
42
  __base = _base_0,
@@ -1,114 +1,5 @@
1
- local compile = require("moonscript.compile")
2
- local parse = require("moonscript.parse")
3
- local concat, insert
4
1
  do
5
- local _obj_0 = table
6
- concat, insert = _obj_0.concat, _obj_0.insert
2
+ local _with_0 = require("moonscript.base")
3
+ _with_0.insert_loader()
4
+ return _with_0
7
5
  end
8
- local split, dump, get_options, unpack
9
- do
10
- local _obj_0 = require("moonscript.util")
11
- split, dump, get_options, unpack = _obj_0.split, _obj_0.dump, _obj_0.get_options, _obj_0.unpack
12
- end
13
- local lua = {
14
- loadstring = loadstring,
15
- load = load
16
- }
17
- local dirsep, line_tables, create_moonpath, to_lua, moon_loader, init_loader, loadstring, loadfile, dofile
18
- dirsep = "/"
19
- line_tables = require("moonscript.line_tables")
20
- create_moonpath = function(package_path)
21
- local paths = split(package_path, ";")
22
- for i, path in ipairs(paths) do
23
- local p = path:match("^(.-)%.lua$")
24
- if p then
25
- paths[i] = p .. ".moon"
26
- end
27
- end
28
- return concat(paths, ";")
29
- end
30
- to_lua = function(text, options)
31
- if options == nil then
32
- options = { }
33
- end
34
- if "string" ~= type(text) then
35
- local t = type(text)
36
- return nil, "expecting string (got " .. t .. ")", 2
37
- end
38
- local tree, err = parse.string(text)
39
- if not tree then
40
- return nil, err
41
- end
42
- local code, ltable, pos = compile.tree(tree, options)
43
- if not code then
44
- return nil, compile.format_error(ltable, pos, text), 2
45
- end
46
- return code, ltable
47
- end
48
- moon_loader = function(name)
49
- local name_path = name:gsub("%.", dirsep)
50
- local file, file_path
51
- local _list_0 = split(package.moonpath, ";")
52
- for _index_0 = 1, #_list_0 do
53
- local path = _list_0[_index_0]
54
- file_path = path:gsub("?", name_path)
55
- file = io.open(file_path)
56
- if file then
57
- break
58
- end
59
- end
60
- if file then
61
- local text = file:read("*a")
62
- file:close()
63
- return loadstring(text, file_path)
64
- else
65
- return nil, "Could not find moon file"
66
- end
67
- end
68
- if not package.moonpath then
69
- package.moonpath = create_moonpath(package.path)
70
- end
71
- init_loader = function()
72
- return insert(package.loaders or package.searchers, 2, moon_loader)
73
- end
74
- if not (_G.moon_no_loader) then
75
- init_loader()
76
- end
77
- loadstring = function(...)
78
- local options, str, chunk_name, mode, env = get_options(...)
79
- chunk_name = chunk_name or "=(moonscript.loadstring)"
80
- local code, ltable_or_err = to_lua(str, options)
81
- if not (code) then
82
- return nil, ltable_or_err
83
- end
84
- if chunk_name then
85
- line_tables[chunk_name] = ltable_or_err
86
- end
87
- return (lua.loadstring or lua.load)(code, chunk_name, unpack({
88
- mode,
89
- env
90
- }))
91
- end
92
- loadfile = function(fname, ...)
93
- local file, err = io.open(fname)
94
- if not (file) then
95
- return nil, err
96
- end
97
- local text = assert(file:read("*a"))
98
- file:close()
99
- return loadstring(text, fname, ...)
100
- end
101
- dofile = function(...)
102
- local f = assert(loadfile(...))
103
- return f()
104
- end
105
- return {
106
- _NAME = "moonscript",
107
- to_lua = to_lua,
108
- moon_chunk = moon_chunk,
109
- moon_loader = moon_loader,
110
- dirsep = dirsep,
111
- dofile = dofile,
112
- loadfile = loadfile,
113
- loadstring = loadstring
114
- }
@@ -51,7 +51,8 @@ local AlphaNum = R("az", "AZ", "09", "__")
51
51
  local _Name = C(R("az", "AZ", "__") * AlphaNum^0)
52
52
  local Name = Space * _Name
53
53
 
54
- local Num = P"0x" * R("09", "af", "AF")^1 +
54
+ local Num = P"0x" * R("09", "af", "AF")^1 * (S"uU"^-1 * S"lL"^2)^-1 +
55
+ R"09"^1 * (S"uU"^-1 * S"lL"^2) +
55
56
  (
56
57
  R"09"^1 * (P"." * R"09"^1)^-1 +
57
58
  P"." * R"09"^1
@@ -174,8 +175,12 @@ end
174
175
  local _chain_assignable = { index = true, dot = true, slice = true }
175
176
 
176
177
  local function is_assignable(node)
178
+ if node == "..." then
179
+ return false
180
+ end
181
+
177
182
  local t = ntype(node)
178
- return t == "self" or t == "value" or t == "self_class" or
183
+ return t == "ref" or t == "self" or t == "value" or t == "self_class" or
179
184
  t == "chain" and _chain_assignable[ntype(node[#node])] or
180
185
  t == "table"
181
186
  end
@@ -378,8 +383,7 @@ local build_grammar = wrap_env(function()
378
383
  _Name / mark"self" + Cc"self")
379
384
 
380
385
  local KeyName = SelfName + Space * _Name / mark"key_literal"
381
-
382
- local Name = SelfName + Name + Space * "..." / trim
386
+ local VarArg = Space * P"..." / trim
383
387
 
384
388
  local g = lpeg.P{
385
389
  File,
@@ -413,8 +417,6 @@ local build_grammar = wrap_env(function()
413
417
  ImportName = (sym"\\" * Ct(Cc"colon_stub" * Name) + Name),
414
418
  ImportNameList = SpaceBreak^0 * ImportName * ((SpaceBreak^1 + sym"," * SpaceBreak^0) * ImportName)^0,
415
419
 
416
- NameList = Name * (sym"," * Name)^0,
417
-
418
420
  BreakLoop = Ct(key"break"/trim) + Ct(key"continue"/trim),
419
421
 
420
422
  Return = key"return" * (ExpListLow/mark"explist" + C"") / mark"return",
@@ -461,8 +463,7 @@ local build_grammar = wrap_env(function()
461
463
  -- we can ignore precedence for now
462
464
  OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",
463
465
 
464
- Assignable = Cmt(DotChain + Chain, check_assignable) + Name,
465
- AssignableList = Assignable * (sym"," * Assignable)^0,
466
+ Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
466
467
 
467
468
  Exp = Ct(Value * ((OtherOps + FactorOp + TermOp) * Value)^0) / flatten_or_mark"exp",
468
469
 
@@ -511,7 +512,7 @@ local build_grammar = wrap_env(function()
511
512
  LuaStringOpen = sym"[" * P"="^0 * "[" / trim,
512
513
  LuaStringClose = "]" * P"="^0 * "]",
513
514
 
514
- Callable = Name + Parens / mark"parens",
515
+ Callable = pos(Name / mark"ref") + SelfName + VarArg + Parens / mark"parens",
515
516
  Parens = sym"(" * Exp * sym")",
516
517
 
517
518
  FnArgs = symx"(" * Ct(ExpList^-1) * sym")" + sym"!" * -P"=" * Ct"",
@@ -583,8 +584,8 @@ local build_grammar = wrap_env(function()
583
584
  (key"using" * Ct(NameList + Space * "nil") + Ct"") *
584
585
  sym")" + Ct"" * Ct"",
585
586
 
586
- FnArgDefList = FnArgDef * (sym"," * FnArgDef)^0,
587
- FnArgDef = Ct(Name * (sym"=" * Exp)^-1),
587
+ FnArgDefList = FnArgDef * (sym"," * FnArgDef)^0 * (sym"," * Ct(VarArg))^0 + Ct(VarArg),
588
+ FnArgDef = Ct((Name + SelfName) * (sym"=" * Exp)^-1),
588
589
 
589
590
  FunLit = FnArgsDef *
590
591
  (sym"->" * Cc"slim" + sym"=>" * Cc"fat") *
@@ -615,13 +616,17 @@ local build_grammar = wrap_env(function()
615
616
  end
616
617
 
617
618
  local tree
618
- local pass, err = pcall(function(...)
619
- tree = self._g:match(str, ...)
620
- end, ...)
619
+ local parse_args = {...}
620
+
621
+ local pass, err = xpcall(function()
622
+ tree = self._g:match(str, unpack(parse_args))
623
+ end, function(err)
624
+ return debug.traceback(err, 2)
625
+ end)
621
626
 
622
627
  -- regular error, let it bubble up
623
628
  if type(err) == "string" then
624
- error(err)
629
+ return nil, err
625
630
  end
626
631
 
627
632
  if not tree then
@@ -107,7 +107,9 @@ extract_declarations = function(self, body, start, out)
107
107
  local _list_0 = stm[2]
108
108
  for _index_0 = 1, #_list_0 do
109
109
  local name = _list_0[_index_0]
110
- if type(name) == "string" then
110
+ if ntype(name) == "ref" then
111
+ insert(out, name)
112
+ elseif type(name) == "string" then
111
113
  insert(out, name)
112
114
  end
113
115
  end
@@ -327,15 +329,27 @@ Statement = Transformer({
327
329
  return apply_to_last(body, implicitly_return(self))
328
330
  end,
329
331
  ["return"] = function(self, node)
330
- node[2] = Value:transform_once(self, node[2])
331
- if "block_exp" == ntype(node[2]) then
332
- local block_exp = node[2]
333
- local block_body = block_exp[2]
334
- local idx = #block_body
335
- node[2] = block_body[idx]
336
- block_body[idx] = node
337
- return build.group(block_body)
332
+ local ret_val = node[2]
333
+ local ret_val_type = ntype(ret_val)
334
+ if ret_val_type == "explist" and #ret_val == 2 then
335
+ ret_val = ret_val[2]
336
+ ret_val_type = ntype(ret_val)
337
+ end
338
+ if types.cascading[ret_val_type] then
339
+ return implicitly_return(self)(ret_val)
340
+ end
341
+ if ret_val_type == "chain" or ret_val_type == "comprehension" or ret_val_type == "tblcomprehension" then
342
+ ret_val = Value:transform_once(self, ret_val)
343
+ if ntype(ret_val) == "block_exp" then
344
+ return build.group(apply_to_last(ret_val[2], function(stm)
345
+ return {
346
+ "return",
347
+ stm
348
+ }
349
+ end))
350
+ end
338
351
  end
352
+ node[2] = ret_val
339
353
  return node
340
354
  end,
341
355
  declare_glob = function(self, node)
@@ -348,7 +362,7 @@ Statement = Transformer({
348
362
  local _continue_0 = false
349
363
  repeat
350
364
  local name = names[_index_0]
351
- if not (name:match("^%u")) then
365
+ if not (name[2]:match("^%u")) then
352
366
  _continue_0 = true
353
367
  break
354
368
  end
@@ -376,6 +390,11 @@ Statement = Transformer({
376
390
  if num_names == 1 and num_values == 1 then
377
391
  local first_value = values[1]
378
392
  local first_name = names[1]
393
+ local first_type = ntype(first_value)
394
+ if first_type == "chain" then
395
+ first_value = Value:transform_once(self, first_value)
396
+ first_type = ntype(first_value)
397
+ end
379
398
  local _exp_0 = ntype(first_value)
380
399
  if "block_exp" == _exp_0 then
381
400
  local block_body = first_value[2]
@@ -395,6 +414,8 @@ Statement = Transformer({
395
414
  })
396
415
  elseif "comprehension" == _exp_0 or "tblcomprehension" == _exp_0 or "foreach" == _exp_0 or "for" == _exp_0 or "while" == _exp_0 then
397
416
  return build.assign_one(first_name, Value:transform_once(self, first_value))
417
+ else
418
+ values[1] = first_value
398
419
  end
399
420
  end
400
421
  local transformed
@@ -599,7 +620,7 @@ Statement = Transformer({
599
620
  local _list_0 = stm[2]
600
621
  for _index_0 = 1, #_list_0 do
601
622
  local name = _list_0[_index_0]
602
- if type(name) == "string" then
623
+ if ntype(name) == "ref" then
603
624
  _accum_0[_len_0] = name
604
625
  _len_0 = _len_0 + 1
605
626
  end
@@ -674,7 +695,7 @@ Statement = Transformer({
674
695
  if ntype(exp) == "assign" then
675
696
  local names, values = unpack(exp, 2)
676
697
  local first_name = names[1]
677
- if ntype(first_name) == "value" then
698
+ if ntype(first_name) == "ref" then
678
699
  scope_name = first_name
679
700
  named_assign = exp
680
701
  exp = values[1]
@@ -966,10 +987,19 @@ Statement = Transformer({
966
987
  elseif "nil" == _exp_0 then
967
988
  real_name = "nil"
968
989
  else
990
+ local name_t = type(real_name)
991
+ local flattened_name
992
+ if name_t == "string" then
993
+ flattened_name = real_name
994
+ elseif name_t == "table" and real_name[1] == "ref" then
995
+ flattened_name = real_name[2]
996
+ else
997
+ flattened_name = error("don't know how to extract name from " .. tostring(name_t))
998
+ end
969
999
  real_name = {
970
1000
  "string",
971
1001
  '"',
972
- real_name
1002
+ flattened_name
973
1003
  }
974
1004
  end
975
1005
  local cls = build.table({
@@ -995,7 +1025,10 @@ Statement = Transformer({
995
1025
  local class_lookup = build["if"]({
996
1026
  cond = {
997
1027
  "exp",
998
- "val",
1028
+ {
1029
+ "ref",
1030
+ "val"
1031
+ },
999
1032
  "==",
1000
1033
  "nil"
1001
1034
  },
@@ -1025,7 +1058,10 @@ Statement = Transformer({
1025
1058
  "call",
1026
1059
  {
1027
1060
  base_name,
1028
- "name"
1061
+ {
1062
+ "ref",
1063
+ "name"
1064
+ }
1029
1065
  }
1030
1066
  }
1031
1067
  })),
@@ -1394,13 +1430,11 @@ Value = Transformer({
1394
1430
  end
1395
1431
  end
1396
1432
  if #node <= 3 then
1397
- return (function()
1398
- if type(node[3]) == "string" then
1399
- return node
1400
- else
1401
- return convert_part(node[3])
1402
- end
1403
- end)()
1433
+ if type(node[3]) == "string" then
1434
+ return node
1435
+ else
1436
+ return convert_part(node[3])
1437
+ end
1404
1438
  end
1405
1439
  local e = {
1406
1440
  "exp",
@@ -1520,8 +1554,8 @@ Value = Transformer({
1520
1554
  table.remove(node, #node)
1521
1555
  local base_name = NameProxy("base")
1522
1556
  local fn_name = NameProxy("fn")
1523
- local is_super = node[2] == "super"
1524
- return self.transform.value(build.block_exp({
1557
+ local is_super = ntype(node[2]) == "ref" and node[2][2] == "super"
1558
+ return build.block_exp({
1525
1559
  build.assign({
1526
1560
  names = {
1527
1561
  base_name
@@ -1563,7 +1597,7 @@ Value = Transformer({
1563
1597
  })
1564
1598
  }
1565
1599
  })
1566
- }))
1600
+ })
1567
1601
  end
1568
1602
  end,
1569
1603
  block_exp = function(self, node)
@@ -100,13 +100,13 @@ extract_assign_names = function(name, accum, prefix)
100
100
  suffix = join(prefix, {
101
101
  suffix
102
102
  })
103
- local t = ntype(value)
104
- if t == "value" or t == "chain" or t == "self" then
103
+ local _exp_0 = ntype(value)
104
+ if "value" == _exp_0 or "ref" == _exp_0 or "chain" == _exp_0 or "self" == _exp_0 then
105
105
  insert(accum, {
106
106
  value,
107
107
  suffix
108
108
  })
109
- elseif t == "table" then
109
+ elseif "table" == _exp_0 then
110
110
  extract_assign_names(value, accum, suffix)
111
111
  else
112
112
  user_error("Can't destructure value of type: " .. tostring(ntype(value)))
@@ -47,33 +47,29 @@ do
47
47
  return self.name
48
48
  end,
49
49
  chain = function(self, ...)
50
- local items
51
- do
52
- local _accum_0 = { }
53
- local _len_0 = 1
54
- local _list_0 = {
55
- ...
56
- }
57
- for _index_0 = 1, #_list_0 do
58
- local i = _list_0[_index_0]
59
- if type(i) == "string" then
60
- _accum_0[_len_0] = {
61
- "dot",
62
- i
63
- }
64
- else
65
- _accum_0[_len_0] = i
66
- end
67
- _len_0 = _len_0 + 1
50
+ local items = {
51
+ base = self,
52
+ ...
53
+ }
54
+ for k, v in ipairs(items) do
55
+ if type(v) == "string" then
56
+ items[k] = {
57
+ "dot",
58
+ v
59
+ }
60
+ else
61
+ items[k] = v
68
62
  end
69
- items = _accum_0
70
63
  end
71
- return build.chain({
72
- base = self,
73
- unpack(items)
74
- })
64
+ return build.chain(items)
75
65
  end,
76
66
  index = function(self, key)
67
+ if type(key) == "string" then
68
+ key = {
69
+ "ref",
70
+ key
71
+ }
72
+ end
77
73
  return build.chain({
78
74
  base = self,
79
75
  {
@@ -263,6 +263,12 @@ build = setmetatable({
263
263
  end,
264
264
  chain = function(parts)
265
265
  local base = parts.base or error("expecting base property for chain")
266
+ if type(base) == "string" then
267
+ base = {
268
+ "ref",
269
+ base
270
+ }
271
+ end
266
272
  local node = {
267
273
  "chain",
268
274
  base
@@ -1,7 +1,7 @@
1
1
 
2
2
  module("moonscript.version", package.seeall)
3
3
 
4
- version = "0.2.4"
4
+ version = "0.2.5"
5
5
  function print_version()
6
6
  print("MoonScript version "..version)
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-lua-moon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4.0
4
+ version: 0.2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov
@@ -70,6 +70,8 @@ files:
70
70
  - vendor/lua/moon/all.moon
71
71
  - vendor/lua/moon/init.moon
72
72
  - vendor/lua/moonscript/base.lua
73
+ - vendor/lua/moonscript/cmd/coverage.lua
74
+ - vendor/lua/moonscript/cmd/lint.lua
73
75
  - vendor/lua/moonscript/compile.lua
74
76
  - vendor/lua/moonscript/compile/statement.lua
75
77
  - vendor/lua/moonscript/compile/value.lua