rufus-lua-moon 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,237 @@
1
+ module("moonscript.types", package.seeall)
2
+ local util = require("moonscript.util")
3
+ local data = require("moonscript.data")
4
+ local insert = table.insert
5
+ manual_return = data.Set({
6
+ "foreach",
7
+ "for",
8
+ "while",
9
+ "return"
10
+ })
11
+ cascading = data.Set({
12
+ "if",
13
+ "with",
14
+ "switch"
15
+ })
16
+ is_value = function(stm)
17
+ local compile, transform = moonscript.compile, moonscript.transform
18
+ return compile.Block:is_value(stm) or transform.Value:can_transform(stm)
19
+ end
20
+ comprehension_has_value = function(comp)
21
+ return is_value(comp[2])
22
+ end
23
+ ntype = function(node)
24
+ if type(node) ~= "table" then
25
+ return "value"
26
+ else
27
+ return node[1]
28
+ end
29
+ end
30
+ is_slice = function(node)
31
+ return ntype(node) == "chain" and ntype(node[#node]) == "slice"
32
+ end
33
+ local t = { }
34
+ local node_types = {
35
+ class = {
36
+ {
37
+ "name",
38
+ "Tmp"
39
+ },
40
+ {
41
+ "body",
42
+ t
43
+ }
44
+ },
45
+ fndef = {
46
+ {
47
+ "args",
48
+ t
49
+ },
50
+ {
51
+ "whitelist",
52
+ t
53
+ },
54
+ {
55
+ "arrow",
56
+ "slim"
57
+ },
58
+ {
59
+ "body",
60
+ t
61
+ }
62
+ },
63
+ foreach = {
64
+ {
65
+ "names",
66
+ t
67
+ },
68
+ {
69
+ "iter"
70
+ },
71
+ {
72
+ "body",
73
+ { }
74
+ }
75
+ },
76
+ ["for"] = {
77
+ {
78
+ "name"
79
+ },
80
+ {
81
+ "bounds",
82
+ t
83
+ },
84
+ {
85
+ "body",
86
+ t
87
+ }
88
+ },
89
+ assign = {
90
+ {
91
+ "names",
92
+ t
93
+ },
94
+ {
95
+ "values",
96
+ t
97
+ }
98
+ },
99
+ declare = {
100
+ {
101
+ "names",
102
+ t
103
+ }
104
+ },
105
+ ["if"] = {
106
+ {
107
+ "cond",
108
+ t
109
+ },
110
+ {
111
+ "then",
112
+ t
113
+ }
114
+ }
115
+ }
116
+ local build_table
117
+ build_table = function()
118
+ local key_table = { }
119
+ for name, args in pairs(node_types) do
120
+ local index = { }
121
+ for i, tuple in ipairs(args) do
122
+ local name = tuple[1]
123
+ index[name] = i + 1
124
+ end
125
+ key_table[name] = index
126
+ end
127
+ return key_table
128
+ end
129
+ local key_table = build_table()
130
+ local make_builder
131
+ make_builder = function(name)
132
+ local spec = node_types[name]
133
+ if not spec then
134
+ error("don't know how to build node: " .. name)
135
+ end
136
+ return function(props)
137
+ if props == nil then
138
+ props = { }
139
+ end
140
+ local node = {
141
+ name
142
+ }
143
+ for i, arg in ipairs(spec) do
144
+ local key, default_value = unpack(arg)
145
+ local val
146
+ if props[key] then
147
+ val = props[key]
148
+ else
149
+ val = default_value
150
+ end
151
+ if val == t then
152
+ val = { }
153
+ end
154
+ node[i + 1] = val
155
+ end
156
+ return node
157
+ end
158
+ end
159
+ build = nil
160
+ build = setmetatable({
161
+ group = function(body)
162
+ return {
163
+ "group",
164
+ body
165
+ }
166
+ end,
167
+ ["do"] = function(body)
168
+ return {
169
+ "do",
170
+ body
171
+ }
172
+ end,
173
+ assign_one = function(name, value)
174
+ return build.assign({
175
+ names = {
176
+ name
177
+ },
178
+ values = {
179
+ value
180
+ }
181
+ })
182
+ end,
183
+ table = function(tbl)
184
+ if tbl == nil then
185
+ tbl = { }
186
+ end
187
+ return {
188
+ "table",
189
+ tbl
190
+ }
191
+ end,
192
+ block_exp = function(body)
193
+ return {
194
+ "block_exp",
195
+ body
196
+ }
197
+ end,
198
+ chain = function(parts)
199
+ local base = parts.base or error("expecting base property for chain")
200
+ local node = {
201
+ "chain",
202
+ base
203
+ }
204
+ local _list_0 = parts
205
+ for _index_0 = 1, #_list_0 do
206
+ local part = _list_0[_index_0]
207
+ insert(node, part)
208
+ end
209
+ return node
210
+ end
211
+ }, {
212
+ __index = function(self, name)
213
+ self[name] = make_builder(name)
214
+ return rawget(self, name)
215
+ end
216
+ })
217
+ smart_node = function(node)
218
+ local index = key_table[ntype(node)]
219
+ if not index then
220
+ return node
221
+ end
222
+ return setmetatable(node, {
223
+ __index = function(node, key)
224
+ if index[key] then
225
+ return rawget(node, index[key])
226
+ elseif type(key) == "string" then
227
+ return error("unknown key: `" .. key .. "` on node type: `" .. ntype(node) .. "`")
228
+ end
229
+ end,
230
+ __newindex = function(node, key, value)
231
+ if index[key] then
232
+ key = index[key]
233
+ end
234
+ return rawset(node, key, value)
235
+ end
236
+ })
237
+ end
@@ -0,0 +1,101 @@
1
+ module("moonscript.util", package.seeall)
2
+ local concat = table.concat
3
+ moon = {
4
+ is_object = function(value)
5
+ return type(value) == "table" and value.__class
6
+ end,
7
+ type = function(value)
8
+ local base_type = type(value)
9
+ if base_type == "table" then
10
+ local cls = value.__class
11
+ if cls then
12
+ return cls
13
+ end
14
+ end
15
+ return base_type
16
+ end
17
+ }
18
+ pos_to_line = function(str, pos)
19
+ local line = 1
20
+ for _ in str:sub(1, pos):gmatch("\n") do
21
+ line = line + 1
22
+ end
23
+ return line
24
+ end
25
+ get_closest_line = function(str, line_num)
26
+ local line = get_line(str, line_num)
27
+ if (not line or trim(line) == "") and line_num > 1 then
28
+ return get_closest_line(str, line_num - 1)
29
+ else
30
+ return line, line_num
31
+ end
32
+ end
33
+ get_line = function(str, line_num)
34
+ for line in str:gmatch("(.-)[\n$]") do
35
+ if line_num == 1 then
36
+ return line
37
+ end
38
+ line_num = line_num - 1
39
+ end
40
+ end
41
+ reversed = function(seq)
42
+ return coroutine.wrap(function()
43
+ for i = #seq, 1, -1 do
44
+ coroutine.yield(i, seq[i])
45
+ end
46
+ end)
47
+ end
48
+ trim = function(str)
49
+ return str:match("^%s*(.-)%s*$")
50
+ end
51
+ split = function(str, delim)
52
+ if str == "" then
53
+ return { }
54
+ end
55
+ str = str .. delim
56
+ return (function()
57
+ local _accum_0 = { }
58
+ local _len_0 = 0
59
+ for m in str:gmatch("(.-)" .. delim) do
60
+ _len_0 = _len_0 + 1
61
+ _accum_0[_len_0] = m
62
+ end
63
+ return _accum_0
64
+ end)()
65
+ end
66
+ dump = function(what)
67
+ local seen = { }
68
+ local _dump
69
+ _dump = function(what, depth)
70
+ if depth == nil then
71
+ depth = 0
72
+ end
73
+ local t = type(what)
74
+ if t == "string" then
75
+ return '"' .. what .. '"\n'
76
+ elseif t == "table" then
77
+ if seen[what] then
78
+ return "recursion(" .. tostring(what) .. ")...\n"
79
+ end
80
+ seen[what] = true
81
+ depth = depth + 1
82
+ local lines = (function()
83
+ local _accum_0 = { }
84
+ local _len_0 = 0
85
+ for k, v in pairs(what) do
86
+ local _value_0 = (" "):rep(depth * 4) .. "[" .. tostring(k) .. "] = " .. _dump(v, depth)
87
+ if _value_0 ~= nil then
88
+ _len_0 = _len_0 + 1
89
+ _accum_0[_len_0] = _value_0
90
+ end
91
+ end
92
+ return _accum_0
93
+ end)()
94
+ seen[what] = false
95
+ return "{\n" .. concat(lines) .. (" "):rep((depth - 1) * 4) .. "}\n"
96
+ else
97
+ return tostring(what) .. "\n"
98
+ end
99
+ end
100
+ return _dump(what)
101
+ end
@@ -0,0 +1,7 @@
1
+
2
+ module("moonscript.version", package.seeall)
3
+
4
+ version = "0.2.0"
5
+ function print_version()
6
+ print("MoonScript version "..version)
7
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rufus-lua-moon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Stas Ukolov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rufus-lua
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Provides MoonScript for Rufus::Lua interpreter
56
+ email:
57
+ - ukoloff@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rufus/lua/moon.rb
68
+ - lib/rufus/lua/moon/version.rb
69
+ - rufus-lua-moon.gemspec
70
+ - vendor/lua/moon/all.moon
71
+ - vendor/lua/moon/init.moon
72
+ - vendor/lua/moonscript/compile.lua
73
+ - vendor/lua/moonscript/compile/format.lua
74
+ - vendor/lua/moonscript/compile/statement.lua
75
+ - vendor/lua/moonscript/compile/value.lua
76
+ - vendor/lua/moonscript/data.lua
77
+ - vendor/lua/moonscript/dump.lua
78
+ - vendor/lua/moonscript/errors.lua
79
+ - vendor/lua/moonscript/init.lua
80
+ - vendor/lua/moonscript/parse.lua
81
+ - vendor/lua/moonscript/transform.lua
82
+ - vendor/lua/moonscript/types.lua
83
+ - vendor/lua/moonscript/util.lua
84
+ - vendor/lua/moonscript/version.lua
85
+ homepage: https://github.com/ukoloff/rufus-lua-moon
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: ''
109
+ test_files: []