rufus-lua-moon 0.4.0.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e03b60b3d4e8f15c1430ddc04511a798237122e1
4
- data.tar.gz: 91a9e8867e4e0a0192fcd1d7f95280b0eba7a98c
3
+ metadata.gz: 0ba945cbe870fea8680be30b884f6b9c0db0468e
4
+ data.tar.gz: 57e18176d0bdfafd8e750cb0cd0ddfd58a41bce2
5
5
  SHA512:
6
- metadata.gz: 376f3ed3a64793fbbc50e7e2dcb8325d065c689fd77f83458f7e9cc1c5dff9ce235dd5fce59aa30d67c56501217fbdb3ca7674a5585cb00a57ece5b4b047fccc
7
- data.tar.gz: d2ec62bd2ecfb00d44cf11daa7cc1a0d3c1cdd621c7950c1abf1c99f7bd3fd313b08ccef4a4cb5db6444c94862fd81536298c69ea92295e2ecd012e120050232
6
+ metadata.gz: ef694a92dc32e88ec30f5f98974a451db8061e38763cc257d10ca7b3c5e7fc5b6a4046d7b29f88f35af5d93c5e166ddf91c461a5ccae8e96b646445ae090d090
7
+ data.tar.gz: 648090a519c07b3b559438c748bc7eb0f5dbbfbfe72c00c5da2624d7fd3c93d353a324658004c205f67d6faf1428cbc68b097a59a1c5758031314583c01a9cf8
@@ -0,0 +1,69 @@
1
+ local unpack
2
+ unpack = require("moonscript.util").unpack
3
+ local parse_spec
4
+ parse_spec = function(spec)
5
+ local flags, words
6
+ if type(spec) == "table" then
7
+ flags, words = unpack(spec), spec
8
+ else
9
+ flags, words = spec, { }
10
+ end
11
+ assert("no flags for arguments")
12
+ local out = { }
13
+ for part in flags:gmatch("%w:?") do
14
+ if part:match(":$") then
15
+ out[part:sub(1, 1)] = {
16
+ value = true
17
+ }
18
+ else
19
+ out[part] = { }
20
+ end
21
+ end
22
+ return out
23
+ end
24
+ local parse_arguments
25
+ parse_arguments = function(spec, args)
26
+ spec = parse_spec(spec)
27
+ local out = { }
28
+ local remaining = { }
29
+ local last_flag = nil
30
+ for _index_0 = 1, #args do
31
+ local _continue_0 = false
32
+ repeat
33
+ local arg = args[_index_0]
34
+ local group = { }
35
+ if last_flag then
36
+ out[last_flag] = arg
37
+ _continue_0 = true
38
+ break
39
+ end
40
+ do
41
+ local flag = arg:match("-(%w+)")
42
+ if flag then
43
+ do
44
+ local short_name = spec[flag]
45
+ if short_name then
46
+ out[short_name] = true
47
+ else
48
+ for char in flag:gmatch(".") do
49
+ out[char] = true
50
+ end
51
+ end
52
+ end
53
+ _continue_0 = true
54
+ break
55
+ end
56
+ end
57
+ table.insert(remaining, arg)
58
+ _continue_0 = true
59
+ until true
60
+ if not _continue_0 then
61
+ break
62
+ end
63
+ end
64
+ return out, remaining
65
+ end
66
+ return {
67
+ parse_arguments = parse_arguments,
68
+ parse_spec = parse_spec
69
+ }
@@ -42,6 +42,7 @@ position_to_lines = function(file_content, positions)
42
42
  end
43
43
  local format_file
44
44
  format_file = function(fname, positions)
45
+ fname = fname:gsub("^@", "")
45
46
  local file = assert(io.open(fname))
46
47
  local content = file:read("*a")
47
48
  file:close()
@@ -102,7 +102,7 @@ compile_file_text = function(text, opts)
102
102
  "Compile time\t" .. format_time(compile_time),
103
103
  ""
104
104
  }, "\n"))
105
- return nil
105
+ return true
106
106
  end
107
107
  return code
108
108
  end
@@ -0,0 +1,269 @@
1
+ local remove_dupes
2
+ remove_dupes = function(list, key_fn)
3
+ local seen = { }
4
+ return (function()
5
+ local _accum_0 = { }
6
+ local _len_0 = 1
7
+ for _index_0 = 1, #list do
8
+ local _continue_0 = false
9
+ repeat
10
+ local item = list[_index_0]
11
+ local key
12
+ if key_fn then
13
+ key = key_fn(item)
14
+ else
15
+ key = item
16
+ end
17
+ if seen[key] then
18
+ _continue_0 = true
19
+ break
20
+ end
21
+ seen[key] = true
22
+ local _value_0 = item
23
+ _accum_0[_len_0] = _value_0
24
+ _len_0 = _len_0 + 1
25
+ _continue_0 = true
26
+ until true
27
+ if not _continue_0 then
28
+ break
29
+ end
30
+ end
31
+ return _accum_0
32
+ end)()
33
+ end
34
+ local plural
35
+ plural = function(count, word)
36
+ return tostring(count) .. " " .. tostring(word) .. tostring(count == 1 and "" or "s")
37
+ end
38
+ local Watcher
39
+ do
40
+ local _class_0
41
+ local _base_0 = {
42
+ start_msg = "Starting watch loop (Ctrl-C to exit)",
43
+ print_start = function(self, mode, misc)
44
+ return io.stderr:write(tostring(self.start_msg) .. " with " .. tostring(mode) .. " [" .. tostring(misc) .. "]\n")
45
+ end
46
+ }
47
+ _base_0.__index = _base_0
48
+ _class_0 = setmetatable({
49
+ __init = function(self, file_list)
50
+ self.file_list = file_list
51
+ end,
52
+ __base = _base_0,
53
+ __name = "Watcher"
54
+ }, {
55
+ __index = _base_0,
56
+ __call = function(cls, ...)
57
+ local _self_0 = setmetatable({}, _base_0)
58
+ cls.__init(_self_0, ...)
59
+ return _self_0
60
+ end
61
+ })
62
+ _base_0.__class = _class_0
63
+ Watcher = _class_0
64
+ end
65
+ local InotifyWacher
66
+ do
67
+ local _class_0
68
+ local _parent_0 = Watcher
69
+ local _base_0 = {
70
+ get_dirs = function(self)
71
+ local parse_dir
72
+ parse_dir = require("moonscript.cmd.moonc").parse_dir
73
+ local dirs
74
+ do
75
+ local _accum_0 = { }
76
+ local _len_0 = 1
77
+ local _list_0 = self.file_list
78
+ for _index_0 = 1, #_list_0 do
79
+ local _des_0 = _list_0[_index_0]
80
+ local file_path
81
+ file_path = _des_0[1]
82
+ local dir = parse_dir(file_path)
83
+ if dir == "" then
84
+ dir = "./"
85
+ end
86
+ local _value_0 = dir
87
+ _accum_0[_len_0] = _value_0
88
+ _len_0 = _len_0 + 1
89
+ end
90
+ dirs = _accum_0
91
+ end
92
+ return remove_dupes(dirs)
93
+ end,
94
+ each_update = function(self)
95
+ return coroutine.wrap(function()
96
+ local dirs = self:get_dirs()
97
+ self:print_start("inotify", plural(#dirs, "dir"))
98
+ local wd_table = { }
99
+ local inotify = require("inotify")
100
+ local handle = inotify.init()
101
+ for _index_0 = 1, #dirs do
102
+ local dir = dirs[_index_0]
103
+ local wd = handle:addwatch(dir, inotify.IN_CLOSE_WRITE, inotify.IN_MOVED_TO)
104
+ wd_table[wd] = dir
105
+ end
106
+ while true do
107
+ local events = handle:read()
108
+ if not (events) then
109
+ break
110
+ end
111
+ for _index_0 = 1, #events do
112
+ local _continue_0 = false
113
+ repeat
114
+ local ev = events[_index_0]
115
+ local fname = ev.name
116
+ if not (fname:match("%.moon$")) then
117
+ _continue_0 = true
118
+ break
119
+ end
120
+ local dir = wd_table[ev.wd]
121
+ if dir ~= "./" then
122
+ fname = dir .. fname
123
+ end
124
+ coroutine.yield(fname)
125
+ _continue_0 = true
126
+ until true
127
+ if not _continue_0 then
128
+ break
129
+ end
130
+ end
131
+ end
132
+ end)
133
+ end
134
+ }
135
+ _base_0.__index = _base_0
136
+ setmetatable(_base_0, _parent_0.__base)
137
+ _class_0 = setmetatable({
138
+ __init = function(self, ...)
139
+ return _class_0.__parent.__init(self, ...)
140
+ end,
141
+ __base = _base_0,
142
+ __name = "InotifyWacher",
143
+ __parent = _parent_0
144
+ }, {
145
+ __index = function(cls, name)
146
+ local val = rawget(_base_0, name)
147
+ if val == nil then
148
+ local parent = rawget(cls, "__parent")
149
+ if parent then
150
+ return parent[name]
151
+ end
152
+ else
153
+ return val
154
+ end
155
+ end,
156
+ __call = function(cls, ...)
157
+ local _self_0 = setmetatable({}, _base_0)
158
+ cls.__init(_self_0, ...)
159
+ return _self_0
160
+ end
161
+ })
162
+ _base_0.__class = _class_0
163
+ local self = _class_0
164
+ self.available = function(self)
165
+ return pcall(function()
166
+ return require("inotify")
167
+ end)
168
+ end
169
+ if _parent_0.__inherited then
170
+ _parent_0.__inherited(_parent_0, _class_0)
171
+ end
172
+ InotifyWacher = _class_0
173
+ end
174
+ local SleepWatcher
175
+ do
176
+ local _class_0
177
+ local _parent_0 = Watcher
178
+ local _base_0 = {
179
+ polling_rate = 1.0,
180
+ get_sleep_func = function(self)
181
+ local sleep
182
+ pcall(function()
183
+ sleep = require("socket").sleep
184
+ end)
185
+ sleep = sleep or require("moonscript")._sleep
186
+ if not (sleep) then
187
+ error("Missing sleep function; install LuaSocket")
188
+ end
189
+ return sleep
190
+ end,
191
+ each_update = function(self)
192
+ return coroutine.wrap(function()
193
+ local lfs = require("lfs")
194
+ local sleep = self:get_sleep_func()
195
+ self:print_start("polling", plural(#self.file_list, "files"))
196
+ local mod_time = { }
197
+ while true do
198
+ local _list_0 = self.file_list
199
+ for _index_0 = 1, #_list_0 do
200
+ local _continue_0 = false
201
+ repeat
202
+ local _des_0 = _list_0[_index_0]
203
+ local file
204
+ file = _des_0[1]
205
+ local time = lfs.attributes(file, "modification")
206
+ print(file, time)
207
+ if not (time) then
208
+ mod_time[file] = nil
209
+ _continue_0 = true
210
+ break
211
+ end
212
+ if not (mod_time[file]) then
213
+ mod_time[file] = time
214
+ _continue_0 = true
215
+ break
216
+ end
217
+ if time > mod_time[file] then
218
+ mod_time[file] = time
219
+ coroutine.yield(file)
220
+ end
221
+ _continue_0 = true
222
+ until true
223
+ if not _continue_0 then
224
+ break
225
+ end
226
+ end
227
+ sleep(self.polling_rate)
228
+ end
229
+ end)
230
+ end
231
+ }
232
+ _base_0.__index = _base_0
233
+ setmetatable(_base_0, _parent_0.__base)
234
+ _class_0 = setmetatable({
235
+ __init = function(self, ...)
236
+ return _class_0.__parent.__init(self, ...)
237
+ end,
238
+ __base = _base_0,
239
+ __name = "SleepWatcher",
240
+ __parent = _parent_0
241
+ }, {
242
+ __index = function(cls, name)
243
+ local val = rawget(_base_0, name)
244
+ if val == nil then
245
+ local parent = rawget(cls, "__parent")
246
+ if parent then
247
+ return parent[name]
248
+ end
249
+ else
250
+ return val
251
+ end
252
+ end,
253
+ __call = function(cls, ...)
254
+ local _self_0 = setmetatable({}, _base_0)
255
+ cls.__init(_self_0, ...)
256
+ return _self_0
257
+ end
258
+ })
259
+ _base_0.__class = _class_0
260
+ if _parent_0.__inherited then
261
+ _parent_0.__inherited(_parent_0, _class_0)
262
+ end
263
+ SleepWatcher = _class_0
264
+ end
265
+ return {
266
+ Watcher = Watcher,
267
+ SleepWatcher = SleepWatcher,
268
+ InotifyWacher = InotifyWacher
269
+ }
@@ -57,7 +57,7 @@ return {
57
57
  end
58
58
  end,
59
59
  assign = function(self, node)
60
- local _, names, values = unpack(node)
60
+ local names, values = unpack(node, 2)
61
61
  local undeclared = self:declare(names)
62
62
  local declare = "local " .. concat(undeclared, ", ")
63
63
  local has_fndef = false
@@ -136,7 +136,7 @@ return {
136
136
  current = next
137
137
  end
138
138
  for _index_0 = 4, #node do
139
- cond = node[_index_0]
139
+ local cond = node[_index_0]
140
140
  add_clause(cond)
141
141
  end
142
142
  return root
@@ -150,7 +150,7 @@ return {
150
150
  end
151
151
  end,
152
152
  ["while"] = function(self, node)
153
- local _, cond, block = unpack(node)
153
+ local cond, block = unpack(node, 2)
154
154
  do
155
155
  local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
156
156
  _with_0:stms(block)
@@ -158,7 +158,7 @@ return {
158
158
  end
159
159
  end,
160
160
  ["for"] = function(self, node)
161
- local _, name, bounds, block = unpack(node)
161
+ local name, bounds, block = unpack(node, 2)
162
162
  local loop = self:line("for ", self:name(name), " = ", self:value({
163
163
  "explist",
164
164
  unpack(bounds)
@@ -173,7 +173,7 @@ return {
173
173
  end
174
174
  end,
175
175
  foreach = function(self, node)
176
- local _, names, exps, block = unpack(node)
176
+ local names, exps, block = unpack(node, 2)
177
177
  local loop
178
178
  do
179
179
  local _with_0 = self:line()
@@ -210,7 +210,7 @@ return {
210
210
  end
211
211
  end,
212
212
  export = function(self, node)
213
- local _, names = unpack(node)
213
+ local names = unpack(node, 2)
214
214
  if type(names) == "string" then
215
215
  if names == "*" then
216
216
  self.export_all = true
@@ -71,7 +71,7 @@ return {
71
71
  return self:line("(", self:value(node[2]), ")")
72
72
  end,
73
73
  string = function(self, node)
74
- local _, delim, inner = unpack(node)
74
+ local delim, inner = unpack(node, 2)
75
75
  local end_delim = delim:gsub("%[", "]")
76
76
  if delim == "'" or delim == '"' then
77
77
  inner = inner:gsub("[\r\n]", string_chars)
@@ -133,7 +133,7 @@ return {
133
133
  return self:line(callee_value, actions)
134
134
  end,
135
135
  fndef = function(self, node)
136
- local _, args, whitelist, arrow, block = unpack(node)
136
+ local args, whitelist, arrow, block = unpack(node, 2)
137
137
  local default_args = { }
138
138
  local self_args = { }
139
139
  local arg_names
@@ -238,7 +238,7 @@ return {
238
238
  end
239
239
  end,
240
240
  table = function(self, node)
241
- local _, items = unpack(node)
241
+ local items = unpack(node, 2)
242
242
  do
243
243
  local _with_0 = self:block("{", "}")
244
244
  local format_line
@@ -286,6 +286,9 @@ return {
286
286
  number = function(self, node)
287
287
  return node[2]
288
288
  end,
289
+ bitnot = function(self, node)
290
+ return self:line("~", self:value(node[2]))
291
+ end,
289
292
  length = function(self, node)
290
293
  return self:line("#", self:value(node[2]))
291
294
  end,
@@ -31,7 +31,7 @@ local tree
31
31
  tree = function(block)
32
32
  local _list_0 = block
33
33
  for _index_0 = 1, #_list_0 do
34
- value = _list_0[_index_0]
34
+ local value = _list_0[_index_0]
35
35
  print(flat_value(value))
36
36
  end
37
37
  end
@@ -15,10 +15,10 @@ local wrap_env
15
15
  wrap_env = require("moonscript.parse.env").wrap_env
16
16
  local R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc
17
17
  R, S, V, P, C, Ct, Cmt, Cg, Cb, Cc = lpeg.R, lpeg.S, lpeg.V, lpeg.P, lpeg.C, lpeg.Ct, lpeg.Cmt, lpeg.Cg, lpeg.Cb, lpeg.Cc
18
- local White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name
18
+ local White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, L, _Name
19
19
  do
20
20
  local _obj_0 = require("moonscript.parse.literals")
21
- White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, _Name = _obj_0.White, _obj_0.Break, _obj_0.Stop, _obj_0.Comment, _obj_0.Space, _obj_0.SomeSpace, _obj_0.SpaceBreak, _obj_0.EmptyLine, _obj_0.AlphaNum, _obj_0.Num, _obj_0.Shebang, _obj_0.Name
21
+ White, Break, Stop, Comment, Space, SomeSpace, SpaceBreak, EmptyLine, AlphaNum, Num, Shebang, L, _Name = _obj_0.White, _obj_0.Break, _obj_0.Stop, _obj_0.Comment, _obj_0.Space, _obj_0.SomeSpace, _obj_0.SpaceBreak, _obj_0.EmptyLine, _obj_0.AlphaNum, _obj_0.Num, _obj_0.Shebang, _obj_0.L, _obj_0.Name
22
22
  end
23
23
  local SpaceName = Space * _Name
24
24
  Num = Space * (Num / function(v)
@@ -27,10 +27,10 @@ Num = Space * (Num / function(v)
27
27
  v
28
28
  }
29
29
  end)
30
- local Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign
30
+ local Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign, got
31
31
  do
32
32
  local _obj_0 = require("moonscript.parse.util")
33
- Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign = _obj_0.Indent, _obj_0.Cut, _obj_0.ensure, _obj_0.extract_line, _obj_0.mark, _obj_0.pos, _obj_0.flatten_or_mark, _obj_0.is_assignable, _obj_0.check_assignable, _obj_0.format_assign, _obj_0.format_single_assign, _obj_0.sym, _obj_0.symx, _obj_0.simple_string, _obj_0.wrap_func_arg, _obj_0.join_chain, _obj_0.wrap_decorator, _obj_0.check_lua_string, _obj_0.self_assign
33
+ Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign, got = _obj_0.Indent, _obj_0.Cut, _obj_0.ensure, _obj_0.extract_line, _obj_0.mark, _obj_0.pos, _obj_0.flatten_or_mark, _obj_0.is_assignable, _obj_0.check_assignable, _obj_0.format_assign, _obj_0.format_single_assign, _obj_0.sym, _obj_0.symx, _obj_0.simple_string, _obj_0.wrap_func_arg, _obj_0.join_chain, _obj_0.wrap_decorator, _obj_0.check_lua_string, _obj_0.self_assign, _obj_0.got
34
34
  end
35
35
  local build_grammar = wrap_env(debug_grammar, function(root)
36
36
  local _indent = Stack(0)
@@ -110,10 +110,10 @@ local build_grammar = wrap_env(debug_grammar, function(root)
110
110
  File = Shebang ^ -1 * (Block + Ct("")),
111
111
  Block = Ct(Line * (Break ^ 1 * Line) ^ 0),
112
112
  CheckIndent = Cmt(Indent, check_indent),
113
- Line = (CheckIndent * Statement + Space * #Stop),
113
+ Line = (CheckIndent * Statement + Space * L(Stop)),
114
114
  Statement = pos(Import + While + With + For + ForEach + Switch + Return + Local + Export + BreakLoop + Ct(ExpList) * (Update + Assign) ^ -1 / format_assign) * Space * ((key("if") * Exp * (key("else") * Exp) ^ -1 * Space / mark("if") + key("unless") * Exp / mark("unless") + CompInner / mark("comprehension")) * Space) ^ -1 / wrap_decorator,
115
115
  Body = Space ^ -1 * Break * EmptyLine ^ 0 * InBlock + Ct(Statement),
116
- Advance = #Cmt(Indent, advance_indent),
116
+ Advance = L(Cmt(Indent, advance_indent)),
117
117
  PushIndent = Cmt(Indent, push_indent),
118
118
  PreventIndent = Cmt(Cc(-1), push_indent),
119
119
  PopIndent = Cmt("", pop_indent),
@@ -131,8 +131,10 @@ local build_grammar = wrap_env(debug_grammar, function(root)
131
131
  SwitchCase = key("when") * Ct(ExpList) * key("then") ^ -1 * Body / mark("case"),
132
132
  SwitchElse = key("else") * Body / mark("else"),
133
133
  IfCond = Exp * Assign ^ -1 / format_single_assign,
134
- If = key("if") * IfCond * key("then") ^ -1 * Body * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("elseif") * pos(IfCond) * key("then") ^ -1 * Body / mark("elseif")) ^ 0 * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("else") * Body / mark("else")) ^ -1 / mark("if"),
135
- Unless = key("unless") * IfCond * key("then") ^ -1 * Body * ((Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("else") * Body / mark("else")) ^ -1 / mark("unless"),
134
+ IfElse = (Break * EmptyLine ^ 0 * CheckIndent) ^ -1 * key("else") * Body / mark("else"),
135
+ IfElseIf = (Break * EmptyLine ^ 0 * CheckIndent) ^ -1 * key("elseif") * pos(IfCond) * key("then") ^ -1 * Body / mark("elseif"),
136
+ If = key("if") * IfCond * key("then") ^ -1 * Body * IfElseIf ^ 0 * IfElse ^ -1 / mark("if"),
137
+ Unless = key("unless") * IfCond * key("then") ^ -1 * Body * IfElseIf ^ 0 * IfElse ^ -1 / mark("unless"),
136
138
  While = key("while") * DisableDo * ensure(Exp, PopDo) * key("do") ^ -1 * Body / mark("while"),
137
139
  For = key("for") * DisableDo * ensure(Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1), PopDo) * key("do") ^ -1 * Body / mark("for"),
138
140
  ForEach = key("for") * Ct(AssignableNameList) * key("in") * DisableDo * ensure(Ct(sym("*") * Exp / mark("unpack") + ExpList), PopDo) * key("do") ^ -1 * Body / mark("foreach"),
@@ -140,20 +142,20 @@ local build_grammar = wrap_env(debug_grammar, function(root)
140
142
  Comprehension = sym("[") * Exp * CompInner * sym("]") / mark("comprehension"),
141
143
  TblComprehension = sym("{") * Ct(Exp * (sym(",") * Exp) ^ -1) * CompInner * sym("}") / mark("tblcomprehension"),
142
144
  CompInner = Ct((CompForEach + CompFor) * CompClause ^ 0),
143
- CompForEach = key("for") * Ct(NameList) * key("in") * (sym("*") * Exp / mark("unpack") + Exp) / mark("foreach"),
145
+ CompForEach = key("for") * Ct(AssignableNameList) * key("in") * (sym("*") * Exp / mark("unpack") + Exp) / mark("foreach"),
144
146
  CompFor = key("for" * Name * sym("=") * Ct(Exp * sym(",") * Exp * (sym(",") * Exp) ^ -1) / mark("for")),
145
147
  CompClause = CompFor + CompForEach + key("when") * Exp / mark("when"),
146
148
  Assign = sym("=") * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark("assign"),
147
- Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=")) / trim) * Exp / mark("update"),
148
- CharOperators = Space * C(S("+-*/%^><")),
149
- WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."),
149
+ Update = ((sym("..=") + sym("+=") + sym("-=") + sym("*=") + sym("/=") + sym("%=") + sym("or=") + sym("and=") + sym("&=") + sym("|=") + sym(">>=") + sym("<<=")) / trim) * Exp / mark("update"),
150
+ CharOperators = Space * C(S("+-*/%^><|&")),
151
+ WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op("..") + op("<<") + op(">>") + op("//"),
150
152
  BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,
151
153
  Assignable = Cmt(Chain, check_assignable) + Name + SelfName,
152
154
  Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"),
153
- SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num,
155
+ SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + sym("~") * Exp / mark("bitnot") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num,
154
156
  ChainValue = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain,
155
157
  Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String),
156
- SliceValue = SimpleValue + ChainValue,
158
+ SliceValue = Exp,
157
159
  String = Space * DoubleString + Space * SingleString + LuaString,
158
160
  SingleString = simple_string("'"),
159
161
  DoubleString = simple_string('"', true),
@@ -162,7 +164,8 @@ local build_grammar = wrap_env(debug_grammar, function(root)
162
164
  LuaStringClose = "]" * P("=") ^ 0 * "]",
163
165
  Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
164
166
  Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
165
- FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
167
+ FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(FnArgsExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
168
+ FnArgsExpList = Exp * ((Break + sym(",")) * White * Exp) ^ 0,
166
169
  Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain") + Space * (DotChainItem * ChainItems ^ -1 + ColonChain) / mark("chain"),
167
170
  ChainItems = ChainItem ^ 1 * ColonChain ^ -1 + ColonChain,
168
171
  ChainItem = Invoke + DotChainItem + Slice + symx("[") * Exp / mark("index") * sym("]"),
@@ -170,7 +173,7 @@ local build_grammar = wrap_env(debug_grammar, function(root)
170
173
  ColonChainItem = symx("\\") * _Name / mark("colon"),
171
174
  ColonChain = ColonChainItem * (Invoke * ChainItems ^ -1) ^ -1,
172
175
  Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"),
173
- Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + #P("[") * LuaString / wrap_func_arg,
176
+ Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + L(P("[")) * LuaString / wrap_func_arg,
174
177
  TableValue = KeyValue + Ct(Exp),
175
178
  TableLit = sym("{") * Ct(TableValueList ^ -1 * sym(",") ^ -1 * (SpaceBreak * TableLitLine * (sym(",") ^ -1 * SpaceBreak * TableLitLine) ^ 0 * sym(",") ^ -1) ^ -1) * White * sym("}") / mark("table"),
176
179
  TableValueList = TableValue * (sym(",") * TableValue) ^ 0,
@@ -181,11 +184,11 @@ local build_grammar = wrap_env(debug_grammar, function(root)
181
184
  ClassBlock = SpaceBreak ^ 1 * Advance * Ct(ClassLine * (SpaceBreak ^ 1 * ClassLine) ^ 0) * PopIndent,
182
185
  ClassLine = CheckIndent * ((KeyValueList / mark("props") + Statement / mark("stm") + Exp / mark("stm")) * sym(",") ^ -1),
183
186
  Export = key("export") * (Cc("class") * ClassDecl + op("*") + op("^") + Ct(NameList) * (sym("=") * Ct(ExpListLow)) ^ -1) / mark("export"),
184
- KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + DoubleString + SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)),
187
+ KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + Space * DoubleString + Space * SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)),
185
188
  KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0,
186
189
  KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1,
187
- FnArgsDef = sym("(") * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * sym(")") + Ct("") * Ct(""),
188
- FnArgDefList = FnArgDef * (sym(",") * FnArgDef) ^ 0 * (sym(",") * Ct(VarArg)) ^ 0 + Ct(VarArg),
190
+ FnArgsDef = sym("(") * White * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * White * sym(")") + Ct("") * Ct(""),
191
+ FnArgDefList = FnArgDef * ((sym(",") + Break) * White * FnArgDef) ^ 0 * ((sym(",") + Break) * White * Ct(VarArg)) ^ 0 + Ct(VarArg),
189
192
  FnArgDef = Ct((Name + SelfName) * (sym("=") * Exp) ^ -1),
190
193
  FunLit = FnArgsDef * (sym("->") * Cc("slim") + sym("=>") * Cc("fat")) * (Body + Ct("")) / mark("fndef"),
191
194
  NameList = Name * (sym(",") * Name) ^ 0,
@@ -5,11 +5,15 @@ do
5
5
  local _obj_0 = require("lpeg")
6
6
  S, P, R, C = _obj_0.S, _obj_0.P, _obj_0.R, _obj_0.C
7
7
  end
8
+ local lpeg = require("lpeg")
9
+ local L = lpeg.luversion and lpeg.L or function(v)
10
+ return #v
11
+ end
8
12
  local White = S(" \t\r\n") ^ 0
9
13
  local plain_space = S(" \t") ^ 0
10
14
  local Break = P("\r") ^ -1 * P("\n")
11
15
  local Stop = Break + -1
12
- local Comment = P("--") * (1 - S("\r\n")) ^ 0 * #Stop
16
+ local Comment = P("--") * (1 - S("\r\n")) ^ 0 * L(Stop)
13
17
  local Space = plain_space * Comment ^ -1
14
18
  local SomeSpace = S(" \t") ^ 1 * Comment ^ -1
15
19
  local SpaceBreak = Space * Break
@@ -19,6 +23,7 @@ local Name = C(R("az", "AZ", "__") * AlphaNum ^ 0)
19
23
  local Num = P("0x") * R("09", "af", "AF") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) ^ -1 + R("09") ^ 1 * (S("uU") ^ -1 * S("lL") ^ 2) + (R("09") ^ 1 * (P(".") * R("09") ^ 1) ^ -1 + P(".") * R("09") ^ 1) * (S("eE") * P("-") ^ -1 * R("09") ^ 1) ^ -1
20
24
  local Shebang = P("#!") * P(1 - Stop) ^ 0
21
25
  return safe_module("moonscript.parse.literals", {
26
+ L = L,
22
27
  White = White,
23
28
  Break = Break,
24
29
  Stop = Stop,
@@ -41,6 +41,58 @@ extract_line = function(str, start_pos)
41
41
  end
42
42
  return str:match("^.-$")
43
43
  end
44
+ local show_line_position
45
+ show_line_position = function(str, pos, context)
46
+ if context == nil then
47
+ context = true
48
+ end
49
+ local lines = {
50
+ { }
51
+ }
52
+ for c in str:gmatch(".") do
53
+ lines[#lines] = lines[#lines] or { }
54
+ table.insert(lines[#lines], c)
55
+ if c == "\n" then
56
+ lines[#lines + 1] = { }
57
+ end
58
+ end
59
+ for i, line in ipairs(lines) do
60
+ lines[i] = table.concat(line)
61
+ end
62
+ local out
63
+ local remaining = pos - 1
64
+ for k, line in ipairs(lines) do
65
+ if remaining < #line then
66
+ local left = line:sub(1, remaining)
67
+ local right = line:sub(remaining + 1)
68
+ out = {
69
+ tostring(left) .. "◉" .. tostring(right)
70
+ }
71
+ if context then
72
+ do
73
+ local before = lines[k - 1]
74
+ if before then
75
+ table.insert(out, 1, before)
76
+ end
77
+ end
78
+ do
79
+ local after = lines[k + 1]
80
+ if after then
81
+ table.insert(out, after)
82
+ end
83
+ end
84
+ end
85
+ break
86
+ else
87
+ remaining = remaining - #line
88
+ end
89
+ end
90
+ if not (out) then
91
+ return "-"
92
+ end
93
+ out = table.concat(out)
94
+ return (out:gsub("\n*$", ""))
95
+ end
44
96
  local mark
45
97
  mark = function(name)
46
98
  return function(...)
@@ -60,9 +112,12 @@ pos = function(patt)
60
112
  end
61
113
  end
62
114
  local got
63
- got = function(what)
115
+ got = function(what, context)
116
+ if context == nil then
117
+ context = true
118
+ end
64
119
  return Cmt("", function(str, pos)
65
- print("++ got " .. tostring(what), "[" .. tostring(extract_line(str, pos)) .. "]")
120
+ print("++ got " .. tostring(what), "[" .. tostring(show_line_position(str, pos, context)) .. "]")
66
121
  return true
67
122
  end)
68
123
  end
@@ -245,5 +300,7 @@ return {
245
300
  join_chain = join_chain,
246
301
  wrap_decorator = wrap_decorator,
247
302
  check_lua_string = check_lua_string,
248
- self_assign = self_assign
303
+ self_assign = self_assign,
304
+ got = got,
305
+ show_line_position = show_line_position
249
306
  }
@@ -106,7 +106,7 @@ super_scope = function(value, t, key)
106
106
  }
107
107
  end
108
108
  return function(self, node, ret, parent_assign)
109
- local _, name, parent_val, body = unpack(node)
109
+ local name, parent_val, body = unpack(node, 2)
110
110
  if parent_val == "" then
111
111
  parent_val = nil
112
112
  end
@@ -101,7 +101,18 @@ do
101
101
  _base_0.__class = _class_0
102
102
  NameProxy = _class_0
103
103
  end
104
+ local is_name_proxy
105
+ is_name_proxy = function(v)
106
+ if not (type(v) == "table") then
107
+ return false
108
+ end
109
+ local _exp_0 = v.__class
110
+ if LocalName == _exp_0 or NameProxy == _exp_0 then
111
+ return true
112
+ end
113
+ end
104
114
  return {
105
115
  NameProxy = NameProxy,
106
- LocalName = LocalName
116
+ LocalName = LocalName,
117
+ is_name_proxy = is_name_proxy
107
118
  }
@@ -1,7 +1,10 @@
1
1
  local Transformer
2
2
  Transformer = require("moonscript.transform.transformer").Transformer
3
- local NameProxy
4
- NameProxy = require("moonscript.transform.names").NameProxy
3
+ local NameProxy, LocalName, is_name_proxy
4
+ do
5
+ local _obj_0 = require("moonscript.transform.names")
6
+ NameProxy, LocalName, is_name_proxy = _obj_0.NameProxy, _obj_0.LocalName, _obj_0.is_name_proxy
7
+ end
5
8
  local Run, transform_last_stm, implicitly_return, last_stm
6
9
  do
7
10
  local _obj_0 = require("moonscript.transform.statements")
@@ -201,7 +204,13 @@ return Transformer({
201
204
  local _continue_0 = false
202
205
  repeat
203
206
  local name = names[_index_0]
204
- if not (name[2]:match("^%u")) then
207
+ local str_name
208
+ if ntype(name) == "ref" then
209
+ str_name = name[2]
210
+ else
211
+ str_name = name
212
+ end
213
+ if not (str_name:match("^%u")) then
205
214
  _continue_0 = true
206
215
  break
207
216
  end
@@ -339,7 +348,7 @@ return Transformer({
339
348
  end
340
349
  end,
341
350
  update = function(self, node)
342
- local _, name, op, exp = unpack(node)
351
+ local name, op, exp = unpack(node, 2)
343
352
  local op_final = op:match("^(.+)=$")
344
353
  if not op_final then
345
354
  error("Unknown op: " .. op)
@@ -358,7 +367,7 @@ return Transformer({
358
367
  })
359
368
  end,
360
369
  import = function(self, node)
361
- local _, names, source = unpack(node)
370
+ local names, source = unpack(node, 2)
362
371
  local table_values
363
372
  do
364
373
  local _accum_0 = { }
@@ -399,7 +408,7 @@ return Transformer({
399
408
  }
400
409
  end,
401
410
  comprehension = function(self, node, action)
402
- local _, exp, clauses = unpack(node)
411
+ local exp, clauses = unpack(node, 2)
403
412
  action = action or function(exp)
404
413
  return {
405
414
  exp
@@ -475,21 +484,39 @@ return Transformer({
475
484
  return wrapped
476
485
  end,
477
486
  unless = function(self, node)
478
- return {
479
- "if",
480
- {
481
- "not",
487
+ local clause = node[2]
488
+ if ntype(clause) == "assign" then
489
+ if destructure.has_destructure(clause[2]) then
490
+ error("destructure not allowed in unless assignment")
491
+ end
492
+ return build["do"]({
493
+ clause,
482
494
  {
483
- "parens",
484
- node[2]
495
+ "if",
496
+ {
497
+ "not",
498
+ clause[2][1]
499
+ },
500
+ unpack(node, 3)
485
501
  }
486
- },
487
- unpack(node, 3)
488
- }
502
+ })
503
+ else
504
+ return {
505
+ "if",
506
+ {
507
+ "not",
508
+ {
509
+ "parens",
510
+ clause
511
+ }
512
+ },
513
+ unpack(node, 3)
514
+ }
515
+ end
489
516
  end,
490
517
  ["if"] = function(self, node, ret)
491
518
  if ntype(node[2]) == "assign" then
492
- local _, assign, body = unpack(node)
519
+ local assign, body = unpack(node, 2)
493
520
  if destructure.has_destructure(assign[2]) then
494
521
  local name = NameProxy("des")
495
522
  body = {
@@ -649,6 +676,18 @@ return Transformer({
649
676
  }
650
677
  }
651
678
  end
679
+ local names
680
+ do
681
+ local _accum_0 = { }
682
+ local _len_0 = 1
683
+ local _list_0 = node.names
684
+ for _index_0 = 1, #_list_0 do
685
+ local n = _list_0[_index_0]
686
+ _accum_0[_len_0] = is_name_proxy(n) and n or LocalName(n) or n
687
+ _len_0 = _len_0 + 1
688
+ end
689
+ names = _accum_0
690
+ end
652
691
  return build.group({
653
692
  list_name ~= list and build.assign_one(list_name, list) or NOOP,
654
693
  slice_var or NOOP,
@@ -658,7 +697,7 @@ return Transformer({
658
697
  body = {
659
698
  {
660
699
  "assign",
661
- node.names,
700
+ names,
662
701
  {
663
702
  NameProxy.index(list_name, index_name)
664
703
  }
@@ -679,7 +718,7 @@ return Transformer({
679
718
  node.body = with_continue_listener(node.body)
680
719
  end,
681
720
  switch = function(self, node, ret)
682
- local _, exp, conds = unpack(node)
721
+ local exp, conds = unpack(node, 2)
683
722
  local exp_name = NameProxy("exp")
684
723
  local convert_cond
685
724
  convert_cond = function(cond)
@@ -89,7 +89,7 @@ return Transformer({
89
89
  return a:wrap(node)
90
90
  end,
91
91
  tblcomprehension = function(self, node)
92
- local _, explist, clauses = unpack(node)
92
+ local explist, clauses = unpack(node, 2)
93
93
  local key_exp, value_exp = unpack(explist)
94
94
  local accum = NameProxy("tbl")
95
95
  local inner
@@ -234,7 +234,7 @@ return Transformer({
234
234
  end
235
235
  end,
236
236
  block_exp = function(self, node)
237
- local _, body = unpack(node)
237
+ local body = unpack(node, 2)
238
238
  local fn = nil
239
239
  local arg_list = { }
240
240
  fn = smart_node(build.fndef({
@@ -1,4 +1,4 @@
1
- local version = "0.4.0"
1
+ local version = "0.5.0"
2
2
  return {
3
3
  version = version,
4
4
  print_version = function()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-lua-moon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-29 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: appveyor-worker
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rufus-lua
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,9 +92,11 @@ files:
106
92
  - vendor/leafo/moon/all.moon
107
93
  - vendor/leafo/moon/init.moon
108
94
  - vendor/leafo/moonscript/base.lua
95
+ - vendor/leafo/moonscript/cmd/args.lua
109
96
  - vendor/leafo/moonscript/cmd/coverage.lua
110
97
  - vendor/leafo/moonscript/cmd/lint.lua
111
98
  - vendor/leafo/moonscript/cmd/moonc.lua
99
+ - vendor/leafo/moonscript/cmd/watchers.lua
112
100
  - vendor/leafo/moonscript/compile.lua
113
101
  - vendor/leafo/moonscript/compile/statement.lua
114
102
  - vendor/leafo/moonscript/compile/value.lua
@@ -154,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
142
  version: '0'
155
143
  requirements: []
156
144
  rubyforge_project:
157
- rubygems_version: 2.2.3
145
+ rubygems_version: 2.6.7
158
146
  signing_key:
159
147
  specification_version: 4
160
148
  summary: ''