rufus-lua-moon 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,8 +10,11 @@ manual_return = data.Set({
10
10
  })
11
11
  cascading = data.Set({
12
12
  "if",
13
+ "unless",
13
14
  "with",
14
- "switch"
15
+ "switch",
16
+ "class",
17
+ "do"
15
18
  })
16
19
  is_value = function(stm)
17
20
  local compile, transform = moonscript.compile, moonscript.transform
@@ -21,12 +24,18 @@ comprehension_has_value = function(comp)
21
24
  return is_value(comp[2])
22
25
  end
23
26
  ntype = function(node)
24
- if type(node) ~= "table" then
25
- return "value"
26
- else
27
+ local _exp_0 = type(node)
28
+ if "nil" == _exp_0 then
29
+ return "nil"
30
+ elseif "table" == _exp_0 then
27
31
  return node[1]
32
+ else
33
+ return "value"
28
34
  end
29
35
  end
36
+ value_is_singular = function(node)
37
+ return type(node) ~= "table" or node[1] ~= "exp" or #node == 2
38
+ end
30
39
  is_slice = function(node)
31
40
  return ntype(node) == "chain" and ntype(node[#node]) == "slice"
32
41
  end
@@ -70,7 +79,7 @@ local node_types = {
70
79
  },
71
80
  {
72
81
  "body",
73
- { }
82
+ t
74
83
  }
75
84
  },
76
85
  ["for"] = {
@@ -86,6 +95,16 @@ local node_types = {
86
95
  t
87
96
  }
88
97
  },
98
+ ["while"] = {
99
+ {
100
+ "cond",
101
+ t
102
+ },
103
+ {
104
+ "body",
105
+ t
106
+ }
107
+ },
89
108
  assign = {
90
109
  {
91
110
  "names",
@@ -116,13 +135,13 @@ local node_types = {
116
135
  local build_table
117
136
  build_table = function()
118
137
  local key_table = { }
119
- for name, args in pairs(node_types) do
138
+ for node_name, args in pairs(node_types) do
120
139
  local index = { }
121
140
  for i, tuple in ipairs(args) do
122
- local name = tuple[1]
123
- index[name] = i + 1
141
+ local prop_name = tuple[1]
142
+ index[prop_name] = i + 1
124
143
  end
125
- key_table[name] = index
144
+ key_table[node_name] = index
126
145
  end
127
146
  return key_table
128
147
  end
@@ -159,6 +178,9 @@ end
159
178
  build = nil
160
179
  build = setmetatable({
161
180
  group = function(body)
181
+ if body == nil then
182
+ body = { }
183
+ end
162
184
  return {
163
185
  "group",
164
186
  body
@@ -184,6 +206,16 @@ build = setmetatable({
184
206
  if tbl == nil then
185
207
  tbl = { }
186
208
  end
209
+ local _list_0 = tbl
210
+ for _index_0 = 1, #_list_0 do
211
+ local tuple = _list_0[_index_0]
212
+ if type(tuple[1]) == "string" then
213
+ tuple[1] = {
214
+ "key_literal",
215
+ tuple[1]
216
+ }
217
+ end
218
+ end
187
219
  return {
188
220
  "table",
189
221
  tbl
@@ -235,3 +267,4 @@ smart_node = function(node)
235
267
  end
236
268
  })
237
269
  end
270
+ return nil
@@ -31,7 +31,7 @@ get_closest_line = function(str, line_num)
31
31
  end
32
32
  end
33
33
  get_line = function(str, line_num)
34
- for line in str:gmatch("(.-)[\n$]") do
34
+ for line in str:gmatch("([^\n]*)\n?") do
35
35
  if line_num == 1 then
36
36
  return line
37
37
  end
@@ -99,3 +99,40 @@ dump = function(what)
99
99
  end
100
100
  return _dump(what)
101
101
  end
102
+ debug_posmap = function(posmap, moon_code, lua_code)
103
+ local tuples = (function()
104
+ local _accum_0 = { }
105
+ local _len_0 = 0
106
+ for k, v in pairs(posmap) do
107
+ _len_0 = _len_0 + 1
108
+ _accum_0[_len_0] = {
109
+ k,
110
+ v
111
+ }
112
+ end
113
+ return _accum_0
114
+ end)()
115
+ table.sort(tuples, function(a, b)
116
+ return a[1] < b[1]
117
+ end)
118
+ local lines = (function()
119
+ local _accum_0 = { }
120
+ local _len_0 = 0
121
+ local _list_0 = tuples
122
+ for _index_0 = 1, #_list_0 do
123
+ local pair = _list_0[_index_0]
124
+ local lua_line, pos = unpack(pair)
125
+ local moon_line = pos_to_line(moon_code, pos)
126
+ local lua_text = get_line(lua_code, lua_line)
127
+ local moon_text = get_closest_line(moon_code, moon_line)
128
+ local _value_0 = tostring(pos) .. "\t " .. tostring(lua_line) .. ":[ " .. tostring(trim(lua_text)) .. " ] >> " .. tostring(moon_line) .. ":[ " .. tostring(trim(moon_text)) .. " ]"
129
+ if _value_0 ~= nil then
130
+ _len_0 = _len_0 + 1
131
+ _accum_0[_len_0] = _value_0
132
+ end
133
+ end
134
+ return _accum_0
135
+ end)()
136
+ return concat(lines, "\n")
137
+ end
138
+ return nil
@@ -1,7 +1,7 @@
1
1
 
2
2
  module("moonscript.version", package.seeall)
3
3
 
4
- version = "0.2.0"
4
+ version = "0.2.2"
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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov