rufus-lua-moon 0.3.2 → 0.4.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: b9ac2290802ee13f83bf597434e4c19bd50a4517
4
- data.tar.gz: 495d4d7419f763778794c0475f9285e1936c57bc
3
+ metadata.gz: 59faaa1677c7e57480d6a18470b0dec01f916d9c
4
+ data.tar.gz: 15ccf6ad23a02d98574f68aa0a2139a912d59669
5
5
  SHA512:
6
- metadata.gz: b78d65cffbcfe8a00d5a6b3d3b4cbde831f1edd7fffa3e9fc417dfeda319186d2b89032911dec16fc12c51d5b28ce33fb85ee25422a81cce860ad05bda9e8f47
7
- data.tar.gz: 4e0b5ce5fd0e1cc5507f1baf9bc2ddde199d0dd60542f750786baa06e4c105c6e19e98980f4fd3482409ac9caecaecf029d0d25fa68c7a12a04b3c38ceb83794
6
+ metadata.gz: 4d7f498e85e7a08aebf7b14f5c60862e13b2894674219f694ef60a3d8d018ab55603c72624f82e3b01505c7471dfde19859a8049c67794d49752c143bbd9a7bd
7
+ data.tar.gz: 27128fdaffadc31ba248b4574d1fef272daf25c1019fd66c031f39ba737f55f4cc03928d3b15cc8b1d3b62b654b3bbfc1042ae0f0bbea47f896c57858c32821f
@@ -1,11 +1,9 @@
1
1
 
2
- util = require "moonscript.util"
3
2
  lua = { :debug, :type }
3
+ import getfenv, setfenv, dump from require "moonscript.util"
4
4
 
5
5
  local *
6
6
 
7
- dump = util.dump
8
-
9
7
  p = (...) ->
10
8
  print dump ...
11
9
 
@@ -66,9 +66,7 @@ end
66
66
  moon_loader = function(name)
67
67
  local name_path = name:gsub("%.", dirsep)
68
68
  local file, file_path
69
- local _list_0 = split(package.moonpath, ";")
70
- for _index_0 = 1, #_list_0 do
71
- local path = _list_0[_index_0]
69
+ for path in package.moonpath:gmatch("[^;]+") do
72
70
  file_path = path:gsub("?", name_path)
73
71
  file = io.open(file_path)
74
72
  if file then
@@ -58,6 +58,7 @@ format_file = function(fname, positions)
58
58
  end
59
59
  local CodeCoverage
60
60
  do
61
+ local _class_0
61
62
  local _base_0 = {
62
63
  reset = function(self)
63
64
  self.line_counts = create_counter()
@@ -120,7 +121,7 @@ do
120
121
  end
121
122
  }
122
123
  _base_0.__index = _base_0
123
- local _class_0 = setmetatable({
124
+ _class_0 = setmetatable({
124
125
  __init = function(self)
125
126
  return self:reset()
126
127
  end,
@@ -52,6 +52,7 @@ local default_whitelist = Set({
52
52
  })
53
53
  local LinterBlock
54
54
  do
55
+ local _class_0
55
56
  local _parent_0 = Block
56
57
  local _base_0 = {
57
58
  lint_mark_used = function(self, name)
@@ -120,11 +121,11 @@ do
120
121
  end,
121
122
  render = function(self, ...)
122
123
  self:lint_check_unused()
123
- return _parent_0.render(self, ...)
124
+ return _class_0.__parent.__base.render(self, ...)
124
125
  end,
125
126
  block = function(self, ...)
126
127
  do
127
- local _with_0 = _parent_0.block(self, ...)
128
+ local _with_0 = _class_0.__parent.__base.block(self, ...)
128
129
  _with_0.block = self.block
129
130
  _with_0.render = self.render
130
131
  _with_0.get_root_block = self.get_root_block
@@ -138,12 +139,12 @@ do
138
139
  }
139
140
  _base_0.__index = _base_0
140
141
  setmetatable(_base_0, _parent_0.__base)
141
- local _class_0 = setmetatable({
142
+ _class_0 = setmetatable({
142
143
  __init = function(self, whitelist_globals, ...)
143
144
  if whitelist_globals == nil then
144
145
  whitelist_globals = default_whitelist
145
146
  end
146
- _parent_0.__init(self, ...)
147
+ _class_0.__parent.__init(self, ...)
147
148
  self.get_root_block = function()
148
149
  return self
149
150
  end
@@ -206,7 +207,10 @@ do
206
207
  __index = function(cls, name)
207
208
  local val = rawget(_base_0, name)
208
209
  if val == nil then
209
- return _parent_0[name]
210
+ local parent = rawget(cls, "__parent")
211
+ if parent then
212
+ return parent[name]
213
+ end
210
214
  else
211
215
  return val
212
216
  end
@@ -8,10 +8,10 @@ do
8
8
  end
9
9
  local Set
10
10
  Set = require("moonscript.data").Set
11
- local ntype, has_value
11
+ local ntype, value_can_be_statement
12
12
  do
13
13
  local _obj_0 = require("moonscript.types")
14
- ntype, has_value = _obj_0.ntype, _obj_0.has_value
14
+ ntype, value_can_be_statement = _obj_0.ntype, _obj_0.value_can_be_statement
15
15
  end
16
16
  local statement_compilers = require("moonscript.compile.statement")
17
17
  local value_compilers = require("moonscript.compile.value")
@@ -26,6 +26,7 @@ local mtype = util.moon.type
26
26
  local indent_char = " "
27
27
  local Line, DelayedLine, Lines, Block, RootBlock
28
28
  do
29
+ local _class_0
29
30
  local _base_0 = {
30
31
  mark_pos = function(self, pos, line)
31
32
  if line == nil then
@@ -127,7 +128,7 @@ do
127
128
  end
128
129
  }
129
130
  _base_0.__index = _base_0
130
- local _class_0 = setmetatable({
131
+ _class_0 = setmetatable({
131
132
  __init = function(self)
132
133
  self.posmap = { }
133
134
  end,
@@ -145,6 +146,7 @@ do
145
146
  Lines = _class_0
146
147
  end
147
148
  do
149
+ local _class_0
148
150
  local _base_0 = {
149
151
  pos = nil,
150
152
  append_list = function(self, items, delim)
@@ -208,7 +210,7 @@ do
208
210
  end
209
211
  }
210
212
  _base_0.__index = _base_0
211
- local _class_0 = setmetatable({
213
+ _class_0 = setmetatable({
212
214
  __init = function() end,
213
215
  __base = _base_0,
214
216
  __name = "Line"
@@ -224,6 +226,7 @@ do
224
226
  Line = _class_0
225
227
  end
226
228
  do
229
+ local _class_0
227
230
  local _base_0 = {
228
231
  prepare = function() end,
229
232
  render = function(self)
@@ -232,7 +235,7 @@ do
232
235
  end
233
236
  }
234
237
  _base_0.__index = _base_0
235
- local _class_0 = setmetatable({
238
+ _class_0 = setmetatable({
236
239
  __init = function(self, fn)
237
240
  self.prepare = fn
238
241
  end,
@@ -250,6 +253,7 @@ do
250
253
  DelayedLine = _class_0
251
254
  end
252
255
  do
256
+ local _class_0
253
257
  local _base_0 = {
254
258
  header = "do",
255
259
  footer = "end",
@@ -525,7 +529,9 @@ do
525
529
  if fn then
526
530
  result = fn(self, node, ...)
527
531
  else
528
- if has_value(node) then
532
+ if value_can_be_statement(node) then
533
+ result = self:value(node)
534
+ else
529
535
  result = self:stm({
530
536
  "assign",
531
537
  {
@@ -535,8 +541,6 @@ do
535
541
  node
536
542
  }
537
543
  })
538
- else
539
- result = self:value(node)
540
544
  end
541
545
  end
542
546
  end
@@ -573,7 +577,7 @@ do
573
577
  end
574
578
  }
575
579
  _base_0.__index = _base_0
576
- local _class_0 = setmetatable({
580
+ _class_0 = setmetatable({
577
581
  __init = function(self, parent, header, footer)
578
582
  self.parent, self.header, self.footer = parent, header, footer
579
583
  self._lines = Lines()
@@ -613,6 +617,7 @@ do
613
617
  Block = _class_0
614
618
  end
615
619
  do
620
+ local _class_0
616
621
  local _parent_0 = Block
617
622
  local _base_0 = {
618
623
  __tostring = function(self)
@@ -634,11 +639,11 @@ do
634
639
  }
635
640
  _base_0.__index = _base_0
636
641
  setmetatable(_base_0, _parent_0.__base)
637
- local _class_0 = setmetatable({
642
+ _class_0 = setmetatable({
638
643
  __init = function(self, options)
639
644
  self.options = options
640
645
  self.root = self
641
- return _parent_0.__init(self)
646
+ return _class_0.__parent.__init(self)
642
647
  end,
643
648
  __base = _base_0,
644
649
  __name = "RootBlock",
@@ -647,7 +652,10 @@ do
647
652
  __index = function(cls, name)
648
653
  local val = rawget(_base_0, name)
649
654
  if val == nil then
650
- return _parent_0[name]
655
+ local parent = rawget(cls, "__parent")
656
+ if parent then
657
+ return parent[name]
658
+ end
651
659
  else
652
660
  return val
653
661
  end
@@ -1,6 +1,3 @@
1
- local util = require("moonscript.util")
2
- local reversed, unpack
3
- reversed, unpack = util.reversed, util.unpack
4
1
  local ntype
5
2
  ntype = require("moonscript.types").ntype
6
3
  local concat, insert
@@ -8,6 +5,8 @@ do
8
5
  local _obj_0 = table
9
6
  concat, insert = _obj_0.concat, _obj_0.insert
10
7
  end
8
+ local unpack
9
+ unpack = require("moonscript.util").unpack
11
10
  return {
12
11
  raw = function(self, node)
13
12
  return self:add(node[2])
@@ -17,6 +17,16 @@ local string_chars = {
17
17
  ["\n"] = "\\n"
18
18
  }
19
19
  return {
20
+ scoped = function(self, node)
21
+ local _, before, value, after
22
+ _, before, value, after = node[1], node[2], node[3], node[4]
23
+ _ = before and before:call(self)
24
+ do
25
+ local _with_0 = self:value(value)
26
+ _ = after and after:call(self)
27
+ return _with_0
28
+ end
29
+ end,
20
30
  exp = function(self, node)
21
31
  local _comp
22
32
  _comp = function(i, value)
@@ -71,11 +81,13 @@ return {
71
81
  chain = function(self, node)
72
82
  local callee = node[2]
73
83
  local callee_type = ntype(callee)
74
- if callee == -1 then
84
+ local item_offset = 3
85
+ if callee_type == "dot" or callee_type == "colon" or callee_type == "index" then
75
86
  callee = self:get("scope_var")
76
- if not callee then
87
+ if not (callee) then
77
88
  user_error("Short-dot syntax must be called within a with block")
78
89
  end
90
+ item_offset = 2
79
91
  end
80
92
  if callee_type == "ref" and callee[2] == "super" or callee == "super" then
81
93
  do
@@ -95,7 +107,7 @@ return {
95
107
  elseif t == "dot" then
96
108
  return ".", tostring(arg)
97
109
  elseif t == "colon" then
98
- return ":", arg, chain_item(node[3])
110
+ return ":", tostring(arg)
99
111
  elseif t == "colon_stub" then
100
112
  return user_error("Uncalled colon stub")
101
113
  else
@@ -112,7 +124,7 @@ return {
112
124
  local actions
113
125
  do
114
126
  local _with_0 = self:line()
115
- for _index_0 = 3, #node do
127
+ for _index_0 = item_offset, #node do
116
128
  local action = node[_index_0]
117
129
  _with_0:append(chain_item(action))
118
130
  end
@@ -246,9 +258,7 @@ return {
246
258
  else
247
259
  assign = self:line("[", _with_0:value(key), "]")
248
260
  end
249
- _with_0:set("current_block", key)
250
261
  local out = self:line(assign, " = ", _with_0:value(value))
251
- _with_0:set("current_block", nil)
252
262
  return out
253
263
  else
254
264
  return self:line(_with_0:value(tuple[1]))
@@ -14,6 +14,7 @@ Set = function(items)
14
14
  end
15
15
  local Stack
16
16
  do
17
+ local _class_0
17
18
  local _base_0 = {
18
19
  __tostring = function(self)
19
20
  return "<Stack {" .. concat(self, ", ") .. "}>"
@@ -34,7 +35,7 @@ do
34
35
  end
35
36
  }
36
37
  _base_0.__index = _base_0
37
- local _class_0 = setmetatable({
38
+ _class_0 = setmetatable({
38
39
  __init = function(self, ...)
39
40
  self:push(...)
40
41
  return nil
@@ -27,18 +27,20 @@ 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, flatten_func, flatten_string_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
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, flatten_func, flatten_string_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.flatten_func, _obj_0.flatten_string_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 = _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
34
34
  end
35
- local build_grammar = wrap_env(debug_grammar, function()
35
+ local build_grammar = wrap_env(debug_grammar, function(root)
36
36
  local _indent = Stack(0)
37
37
  local _do_stack = Stack(0)
38
- local last_pos = 0
38
+ local state = {
39
+ last_pos = 0
40
+ }
39
41
  local check_indent
40
42
  check_indent = function(str, pos, indent)
41
- last_pos = pos
43
+ state.last_pos = pos
42
44
  return _indent:top() == indent
43
45
  end
44
46
  local advance_indent
@@ -104,7 +106,7 @@ local build_grammar = wrap_env(debug_grammar, function()
104
106
  local KeyName = SelfName + Space * _Name / mark("key_literal")
105
107
  local VarArg = Space * P("...") / trim
106
108
  local g = P({
107
- File,
109
+ root or File,
108
110
  File = Shebang ^ -1 * (Block + Ct("")),
109
111
  Block = Ct(Line * (Break ^ 1 * Line) ^ 0),
110
112
  CheckIndent = Cmt(Indent, check_indent),
@@ -118,7 +120,7 @@ local build_grammar = wrap_env(debug_grammar, function()
118
120
  InBlock = Advance * Block * PopIndent,
119
121
  Local = key("local") * ((op("*") + op("^")) / mark("declare_glob") + Ct(NameList) / mark("declare_with_shadows")),
120
122
  Import = key("import") * Ct(ImportNameList) * SpaceBreak ^ 0 * key("from") * Exp / mark("import"),
121
- ImportName = (sym("\\") * Ct(Cc("colon_stub") * Name) + Name),
123
+ ImportName = (sym("\\") * Ct(Cc("colon") * Name) + Name),
122
124
  ImportNameList = SpaceBreak ^ 0 * ImportName * ((SpaceBreak ^ 1 + sym(",") * SpaceBreak ^ 0) * ImportName) ^ 0,
123
125
  BreakLoop = Ct(key("break") / trim) + Ct(key("continue") / trim),
124
126
  Return = key("return") * (ExpListLow / mark("explist") + C("")) / mark("return"),
@@ -146,13 +148,12 @@ local build_grammar = wrap_env(debug_grammar, function()
146
148
  CharOperators = Space * C(S("+-*/%^><")),
147
149
  WordOperators = op("or") + op("and") + op("<=") + op(">=") + op("~=") + op("!=") + op("==") + op(".."),
148
150
  BinaryOperator = (WordOperators + CharOperators) * SpaceBreak ^ 0,
149
- Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
151
+ Assignable = Cmt(Chain, check_assignable) + Name + SelfName,
150
152
  Exp = Ct(Value * (BinaryOperator * Value) ^ 0) / flatten_or_mark("exp"),
151
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,
152
- ChainValue = StringChain + ((Chain + DotChain + Callable) * Ct(InvokeArgs ^ -1)) / flatten_func,
153
- Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue),
154
+ ChainValue = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain,
155
+ Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String),
154
156
  SliceValue = SimpleValue + ChainValue,
155
- StringChain = String * (Ct((ColonCall + ColonSuffix) * ChainTail ^ -1) * Ct(InvokeArgs ^ -1)) ^ -1 / flatten_string_chain,
156
157
  String = Space * DoubleString + Space * SingleString + LuaString,
157
158
  SingleString = simple_string("'"),
158
159
  DoubleString = simple_string('"', true),
@@ -162,14 +163,14 @@ local build_grammar = wrap_env(debug_grammar, function()
162
163
  Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
163
164
  Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
164
165
  FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
165
- ChainTail = ChainItem ^ 1 * ColonSuffix ^ -1 + ColonSuffix,
166
- Chain = Callable * ChainTail / mark("chain"),
167
- DotChain = (sym(".") * Cc(-1) * (_Name / mark("dot")) * ChainTail ^ -1) / mark("chain") + (sym("\\") * Cc(-1) * ((_Name * Invoke / mark("colon")) * ChainTail ^ -1 + (_Name / mark("colon_stub")))) / mark("chain"),
168
- ChainItem = Invoke + Slice + symx("[") * Exp / mark("index") * sym("]") + symx(".") * _Name / mark("dot") + ColonCall,
166
+ Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain") + Space * (DotChainItem * ChainItems ^ -1 + ColonChain) / mark("chain"),
167
+ ChainItems = ChainItem ^ 1 * ColonChain ^ -1 + ColonChain,
168
+ ChainItem = Invoke + DotChainItem + Slice + symx("[") * Exp / mark("index") * sym("]"),
169
+ DotChainItem = symx(".") * _Name / mark("dot"),
170
+ ColonChainItem = symx("\\") * _Name / mark("colon"),
171
+ ColonChain = ColonChainItem * (Invoke * ChainItems ^ -1) ^ -1,
169
172
  Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"),
170
- ColonCall = symx("\\") * (_Name * Invoke) / mark("colon"),
171
- ColonSuffix = symx("\\") * _Name / mark("colon_stub"),
172
- Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg,
173
+ Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + #P("[") * LuaString / wrap_func_arg,
173
174
  TableValue = KeyValue + Ct(Exp),
174
175
  TableLit = sym("{") * Ct(TableValueList ^ -1 * sym(",") ^ -1 * (SpaceBreak * TableLitLine * (sym(",") ^ -1 * SpaceBreak * TableLitLine) ^ 0 * sym(",") ^ -1) ^ -1) * White * sym("}") / mark("table"),
175
176
  TableValueList = TableValue * (sym(",") * TableValue) ^ 0,
@@ -196,6 +197,11 @@ local build_grammar = wrap_env(debug_grammar, function()
196
197
  ArgBlock = ArgLine * (sym(",") * SpaceBreak * ArgLine) ^ 0 * PopIndent,
197
198
  ArgLine = CheckIndent * ExpList
198
199
  })
200
+ return g, state
201
+ end)
202
+ local file_parser
203
+ file_parser = function()
204
+ local g, state = build_grammar()
199
205
  local file_grammar = White * g * White * -1
200
206
  return {
201
207
  match = function(self, str)
@@ -210,7 +216,7 @@ local build_grammar = wrap_env(debug_grammar, function()
210
216
  end
211
217
  if not (tree) then
212
218
  local msg
213
- local err_pos = last_pos
219
+ local err_pos = state.last_pos
214
220
  if err then
215
221
  local node
216
222
  node, msg = unpack(err)
@@ -226,10 +232,11 @@ local build_grammar = wrap_env(debug_grammar, function()
226
232
  return tree
227
233
  end
228
234
  }
229
- end)
235
+ end
230
236
  return {
231
237
  extract_line = extract_line,
238
+ build_grammar = build_grammar,
232
239
  string = function(str)
233
- return build_grammar():match(str)
240
+ return file_parser():match(str)
234
241
  end
235
242
  }
@@ -34,8 +34,9 @@ wrap_env = function(debug, fn)
34
34
  end
35
35
  wrap_name = function(name)
36
36
  local v = V(name)
37
- v = Cmt("", function()
38
- iprint("* " .. name)
37
+ v = Cmt("", function(str, pos)
38
+ local rest = str:sub(pos, -1):match("^([^\n]*)")
39
+ iprint("* " .. tostring(name) .. " (" .. tostring(rest) .. ")")
39
40
  indent = indent + 1
40
41
  return true
41
42
  end) * Cmt(v, function(str, pos, ...)