rufus-lua-moon 0.2.5.0 → 0.2.6.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: a7190b583c1d9cf355c5ce5f685513fc19111d18
4
- data.tar.gz: 3abbedc70d9db04e7b0b7f5f018d09651d147e48
3
+ metadata.gz: ec64394e84ba8c8288134cf012d62151406b8a1d
4
+ data.tar.gz: 1217bea89d96bed46de5accb1d54a2197182ed8a
5
5
  SHA512:
6
- metadata.gz: e70ba8a5a494e8ee3ff55dc5cf46570b3dd80b91a0261a45525ab9b9dde0730e457454e1381508155ec5a88fffe3acea110051d761b3ff0aef646580b3a6f6a0
7
- data.tar.gz: b465395ebe85e03185b25c7d1e50178f8cb2b3d1552c9716f939d30262e7ea16f0c268e1dadcfa03e8906465c4358cb1ec9475c2775eb4c39fc372d5b55c6607
6
+ metadata.gz: 18b5ef94e1185a6e24e9a01da1d35fc767d83c24e9a2d99e51bf615b3a6ba4b97469404c0c347acb30eb793ee14b67319089efbb8930257761e396a71391f0d8
7
+ data.tar.gz: ef43c5d6c538fce5f2c61f04dd4aff8b1277c2aae791512656b2eb97242c8ab3961a3e47f9f6d5c1c43871502fc2e863838250b66552bf9cfff1fae0a482ee92
@@ -33,7 +33,7 @@ to_lua = function(text, options)
33
33
  end
34
34
  if "string" ~= type(text) then
35
35
  local t = type(text)
36
- return nil, "expecting string (got " .. t .. ")", 2
36
+ return nil, "expecting string (got " .. t .. ")"
37
37
  end
38
38
  local tree, err = parse.string(text)
39
39
  if not tree then
@@ -41,7 +41,7 @@ to_lua = function(text, options)
41
41
  end
42
42
  local code, ltable, pos = compile.tree(tree, options)
43
43
  if not code then
44
- return nil, compile.format_error(ltable, pos, text), 2
44
+ return nil, compile.format_error(ltable, pos, text)
45
45
  end
46
46
  return code, ltable
47
47
  end
@@ -60,7 +60,7 @@ moon_loader = function(name)
60
60
  if file then
61
61
  local text = file:read("*a")
62
62
  file:close()
63
- local res, err = loadstring(text, file_path)
63
+ local res, err = loadstring(text, "@" .. tostring(file_path))
64
64
  if not res then
65
65
  error(file_path .. ": " .. err)
66
66
  end
@@ -90,7 +90,7 @@ loadfile = function(fname, ...)
90
90
  end
91
91
  local text = assert(file:read("*a"))
92
92
  file:close()
93
- return loadstring(text, fname, ...)
93
+ return loadstring(text, "@" .. tostring(fname), ...)
94
94
  end
95
95
  dofile = function(...)
96
96
  local f = assert(loadfile(...))
@@ -128,7 +128,6 @@ return {
128
128
  insert_loader = insert_loader,
129
129
  remove_loader = remove_loader,
130
130
  to_lua = to_lua,
131
- moon_chunk = moon_chunk,
132
131
  moon_loader = moon_loader,
133
132
  dirsep = dirsep,
134
133
  dofile = dofile,
@@ -0,0 +1,198 @@
1
+ local lfs = require("lfs")
2
+ local split
3
+ do
4
+ local _obj_0 = require("moonscript.util")
5
+ split = _obj_0.split
6
+ end
7
+ local dirsep, dirsep_chars, mkdir, normalize_dir, parse_dir, parse_file, convert_path, format_time, gettime, compile_file_text, write_file, compile_and_write, is_abs_path, path_to_target
8
+ dirsep = package.config:sub(1, 1)
9
+ if dirsep == "\\" then
10
+ dirsep_chars = "\\/"
11
+ else
12
+ dirsep_chars = dirsep
13
+ end
14
+ mkdir = function(path)
15
+ local chunks = split(path, dirsep)
16
+ local accum
17
+ for _index_0 = 1, #chunks do
18
+ local dir = chunks[_index_0]
19
+ accum = accum and tostring(accum) .. tostring(dirsep) .. tostring(dir) or dir
20
+ lfs.mkdir(accum)
21
+ end
22
+ return lfs.attributes(path, "mode")
23
+ end
24
+ normalize_dir = function(path)
25
+ return path:match("^(.-)[" .. tostring(dirsep_chars) .. "]*$") .. dirsep
26
+ end
27
+ parse_dir = function(path)
28
+ return (path:match("^(.-)[^" .. tostring(dirsep_chars) .. "]*$"))
29
+ end
30
+ parse_file = function(path)
31
+ return (path:match("^.-([^" .. tostring(dirsep_chars) .. "]*)$"))
32
+ end
33
+ convert_path = function(path)
34
+ local new_path = path:gsub("%.moon$", ".lua")
35
+ if new_path == path then
36
+ new_path = path .. ".lua"
37
+ end
38
+ return new_path
39
+ end
40
+ format_time = function(time)
41
+ return ("%.3fms"):format(time * 1000)
42
+ end
43
+ do
44
+ local socket
45
+ gettime = function()
46
+ if socket == nil then
47
+ pcall(function()
48
+ socket = require("socket")
49
+ end)
50
+ if not (socket) then
51
+ socket = false
52
+ end
53
+ end
54
+ if socket then
55
+ return socket.gettime()
56
+ else
57
+ return nil, "LuaSocket needed for benchmark"
58
+ end
59
+ end
60
+ end
61
+ compile_file_text = function(text, fname, opts)
62
+ if opts == nil then
63
+ opts = { }
64
+ end
65
+ local parse = require("moonscript.parse")
66
+ local compile = require("moonscript.compile")
67
+ local parse_time
68
+ if opts.benchmark then
69
+ parse_time = assert(gettime())
70
+ end
71
+ local tree, err = parse.string(text)
72
+ if not (tree) then
73
+ return nil, err
74
+ end
75
+ if parse_time then
76
+ parse_time = gettime() - parse_time
77
+ end
78
+ if opts.show_parse_tree then
79
+ local dump = require("moonscript.dump")
80
+ dump.tree(tree)
81
+ return true
82
+ end
83
+ local compile_time
84
+ if opts.benchmark then
85
+ compile_time = gettime()
86
+ end
87
+ local code, posmap_or_err, err_pos = compile.tree(tree)
88
+ if not (code) then
89
+ return nil, compile.format_error(posmap_or_err, err_pos, text)
90
+ end
91
+ if compile_time then
92
+ compile_time = gettime() - compile_time
93
+ end
94
+ if opts.show_posmap then
95
+ local debug_posmap
96
+ do
97
+ local _obj_0 = require("moonscript.util")
98
+ debug_posmap = _obj_0.debug_posmap
99
+ end
100
+ print("Pos", "Lua", ">>", "Moon")
101
+ print(debug_posmap(posmap_or_err, text, code))
102
+ return true
103
+ end
104
+ if opts.benchmark then
105
+ print(table.concat({
106
+ fname,
107
+ "Parse time \t" .. format_time(parse_time),
108
+ "Compile time\t" .. format_time(compile_time),
109
+ ""
110
+ }, "\n"))
111
+ return nil
112
+ end
113
+ return code
114
+ end
115
+ write_file = function(fname, code)
116
+ mkdir(parse_dir(fname))
117
+ local f, err = io.open(fname, "w")
118
+ if not (f) then
119
+ return nil, err
120
+ end
121
+ assert(f:write(code))
122
+ assert(f:write("\n"))
123
+ f:close()
124
+ return "build"
125
+ end
126
+ compile_and_write = function(src, dest, opts)
127
+ if opts == nil then
128
+ opts = { }
129
+ end
130
+ local f = io.open(src)
131
+ if not (f) then
132
+ return nil, "Can't find file"
133
+ end
134
+ local text = assert(f:read("*a"))
135
+ f:close()
136
+ local code, err = compile_file_text(text, opts)
137
+ if not code then
138
+ return nil, err
139
+ end
140
+ if code == true then
141
+ return true
142
+ end
143
+ if opts.print then
144
+ print(text)
145
+ return true
146
+ end
147
+ return write_file(dest, code)
148
+ end
149
+ is_abs_path = function(path)
150
+ local first = path:sub(1, 1)
151
+ if dirsep == "\\" then
152
+ return first == "/" or first == "\\" or path:sub(2, 1) == ":"
153
+ else
154
+ return first == dirsep
155
+ end
156
+ end
157
+ path_to_target = function(path, target_dir, base_dir)
158
+ if target_dir == nil then
159
+ target_dir = nil
160
+ end
161
+ if base_dir == nil then
162
+ base_dir = nil
163
+ end
164
+ local target = convert_path(path)
165
+ if target_dir then
166
+ target_dir = normalize_dir(target_dir)
167
+ end
168
+ if base_dir and target_dir then
169
+ local head = base_dir:match("^(.-)[^" .. tostring(dirsep_chars) .. "]*[" .. tostring(dirsep_chars) .. "]?$")
170
+ if head then
171
+ local start, stop = target:find(head, 1, true)
172
+ if start == 1 then
173
+ target = target:sub(stop + 1)
174
+ end
175
+ end
176
+ end
177
+ if target_dir then
178
+ if is_abs_path(target) then
179
+ target = parse_file(target)
180
+ end
181
+ target = target_dir .. target
182
+ end
183
+ return target
184
+ end
185
+ return {
186
+ dirsep = dirsep,
187
+ mkdir = mkdir,
188
+ normalize_dir = normalize_dir,
189
+ parse_dir = parse_dir,
190
+ parse_file = parse_file,
191
+ new_path = new_path,
192
+ convert_path = convert_path,
193
+ gettime = gettime,
194
+ format_time = format_time,
195
+ path_to_target = path_to_target,
196
+ compile_file_text = compile_file_text,
197
+ compile_and_write = compile_and_write
198
+ }
@@ -1,5 +1,4 @@
1
1
  local util = require("moonscript.util")
2
- local data = require("moonscript.data")
3
2
  local reversed, unpack
4
3
  reversed, unpack = util.reversed, util.unpack
5
4
  local ntype
@@ -79,7 +78,7 @@ return {
79
78
  _with_0:append(declare)
80
79
  else
81
80
  if #undeclared > 0 then
82
- self:add(declare)
81
+ self:add(declare, node[-1])
83
82
  end
84
83
  _with_0:append_list((function()
85
84
  local _accum_0 = { }
@@ -61,6 +61,7 @@ do
61
61
  local _exp_0 = mtype(l)
62
62
  if "string" == _exp_0 or DelayedLine == _exp_0 then
63
63
  line_no = line_no + 1
64
+ out[line_no] = posmap[i]
64
65
  for _ in l:gmatch("\n") do
65
66
  line_no = line_no + 1
66
67
  end
@@ -101,7 +102,6 @@ do
101
102
  end
102
103
  end
103
104
  insert(buffer, "\n")
104
- local last = l
105
105
  elseif Lines == _exp_0 then
106
106
  l:flatten(indent and indent .. indent_char or indent_char, buffer)
107
107
  else
@@ -150,38 +150,30 @@ end
150
150
  do
151
151
  local _base_0 = {
152
152
  pos = nil,
153
- _append_single = function(self, item)
154
- if Line == mtype(item) then
155
- if not (self.pos) then
156
- self.pos = item.pos
157
- end
158
- for _index_0 = 1, #item do
159
- local value = item[_index_0]
160
- self:_append_single(value)
161
- end
162
- else
163
- insert(self, item)
164
- end
165
- return nil
166
- end,
167
153
  append_list = function(self, items, delim)
168
154
  for i = 1, #items do
169
- self:_append_single(items[i])
155
+ self:append(items[i])
170
156
  if i < #items then
171
157
  insert(self, delim)
172
158
  end
173
159
  end
174
160
  return nil
175
161
  end,
176
- append = function(self, ...)
177
- local _list_0 = {
178
- ...
179
- }
180
- for _index_0 = 1, #_list_0 do
181
- local item = _list_0[_index_0]
182
- self:_append_single(item)
162
+ append = function(self, first, ...)
163
+ if Line == mtype(first) then
164
+ if not (self.pos) then
165
+ self.pos = first.pos
166
+ end
167
+ for _index_0 = 1, #first do
168
+ local value = first[_index_0]
169
+ self:append(value)
170
+ end
171
+ else
172
+ insert(self, first)
173
+ end
174
+ if ... then
175
+ return self:append(...)
183
176
  end
184
- return nil
185
177
  end,
186
178
  render = function(self, buffer)
187
179
  local current = { }
@@ -209,7 +201,7 @@ do
209
201
  insert(current, chunk)
210
202
  end
211
203
  end
212
- if #current > 0 then
204
+ if current[1] then
213
205
  add_current()
214
206
  end
215
207
  return buffer
@@ -423,8 +415,14 @@ do
423
415
  })
424
416
  return name
425
417
  end,
426
- add = function(self, item)
427
- self._lines:add(item)
418
+ add = function(self, item, pos)
419
+ do
420
+ local _with_0 = self._lines
421
+ _with_0:add(item)
422
+ if pos then
423
+ _with_0:mark_pos(pos)
424
+ end
425
+ end
428
426
  return item
429
427
  end,
430
428
  render = function(self, buffer)
@@ -703,7 +701,6 @@ tree = function(tree, options)
703
701
  if not (success) then
704
702
  local error_msg, error_pos
705
703
  if type(err) == "table" then
706
- local error_type = err[1]
707
704
  local _exp_0 = err[1]
708
705
  if "user-error" == _exp_0 or "compile-error" == _exp_0 then
709
706
  error_msg, error_pos = unpack(err, 2)
@@ -78,8 +78,8 @@ rewrite_traceback = function(text, err)
78
78
  local cache = { }
79
79
  local rewrite_single
80
80
  rewrite_single = function(trace)
81
- local fname, line, msg = trace:match('^%[string "(.-)"]:(%d+): (.*)$')
82
- local tbl = line_tables[fname]
81
+ local fname, line, msg = trace:match('^(.-):(%d+): (.*)$')
82
+ local tbl = line_tables["@" .. tostring(fname)]
83
83
  if fname and tbl then
84
84
  return concat({
85
85
  fname,
@@ -10,7 +10,6 @@ local types = require"moonscript.types"
10
10
 
11
11
  local ntype = types.ntype
12
12
 
13
- local dump = util.dump
14
13
  local trim = util.trim
15
14
 
16
15
  local getfenv = util.getfenv
@@ -126,7 +125,7 @@ end
126
125
 
127
126
  local function extract_line(str, start_pos)
128
127
  str = str:sub(start_pos)
129
- m = str:match"^(.-)\n"
128
+ local m = str:match"^(.-)\n"
130
129
  if m then return m end
131
130
  return str:match"^.-$"
132
131
  end
@@ -156,13 +155,6 @@ local function got(what)
156
155
  end)
157
156
  end
158
157
 
159
- local function flatten(tbl)
160
- if #tbl == 1 then
161
- return tbl[1]
162
- end
163
- return tbl
164
- end
165
-
166
158
  local function flatten_or_mark(name)
167
159
  return function(tbl)
168
160
  if #tbl == 1 then return tbl[1] end
@@ -234,7 +226,7 @@ end
234
226
  local function simple_string(delim, allow_interpolation)
235
227
  local inner = P('\\'..delim) + "\\\\" + (1 - P(delim))
236
228
  if allow_interpolation then
237
- inter = symx"#{" * V"Exp" * sym"}"
229
+ local inter = symx"#{" * V"Exp" * sym"}"
238
230
  inner = (C((inner - inter)^1) + inter / mark"interpolate")^0
239
231
  else
240
232
  inner = C(inner^0)
@@ -280,16 +272,6 @@ local function wrap_decorator(stm, dec)
280
272
  return { "decorated", stm, dec }
281
273
  end
282
274
 
283
- -- wrap if statement if there is a conditional decorator
284
- local function wrap_if(stm, cond)
285
- if cond then
286
- local pass, fail = unpack(cond)
287
- if fail then fail = {"else", {fail}} end
288
- return {"if", cond[2], {stm}, fail}
289
- end
290
- return stm
291
- end
292
-
293
275
  local function check_lua_string(str, pos, right, left)
294
276
  return #left == #right
295
277
  end
@@ -343,18 +325,12 @@ local build_grammar = wrap_env(function()
343
325
  return true
344
326
  end
345
327
 
346
- local function enable_do(str_pos)
347
- _do_stack:push(true)
348
- return true
349
- end
350
-
351
328
  local function pop_do(str, pos)
352
329
  if nil == _do_stack:pop() then error("unexpected do pop") end
353
330
  return true
354
331
  end
355
332
 
356
333
  local DisableDo = Cmt("", disable_do)
357
- local EnableDo = Cmt("", enable_do)
358
334
  local PopDo = Cmt("", pop_do)
359
335
 
360
336
  local keywords = {}
@@ -23,7 +23,6 @@ do
23
23
  local _obj_0 = require("moonscript.errors")
24
24
  user_error = _obj_0.user_error
25
25
  end
26
- local util = require("moonscript.util")
27
26
  local join
28
27
  join = function(...)
29
28
  do
@@ -1,7 +1,7 @@
1
-
2
- module("moonscript.version", package.seeall)
3
-
4
- version = "0.2.5"
5
- function print_version()
6
- print("MoonScript version "..version)
7
- end
1
+ local version = "0.2.6"
2
+ return {
3
+ version = version,
4
+ print_version = function()
5
+ return print("MoonScript version " .. tostring(version))
6
+ end
7
+ }
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.5.0
4
+ version: 0.2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov
@@ -72,6 +72,7 @@ files:
72
72
  - vendor/lua/moonscript/base.lua
73
73
  - vendor/lua/moonscript/cmd/coverage.lua
74
74
  - vendor/lua/moonscript/cmd/lint.lua
75
+ - vendor/lua/moonscript/cmd/moonc.lua
75
76
  - vendor/lua/moonscript/compile.lua
76
77
  - vendor/lua/moonscript/compile/statement.lua
77
78
  - vendor/lua/moonscript/compile/value.lua