rufus-lua-moon 0.2.6.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +9 -0
  4. data/FarMenu.ini +16 -0
  5. data/README.md +10 -4
  6. data/Rakefile +13 -0
  7. data/lib/rufus/lua/moon/version.rb +2 -2
  8. data/rufus-lua-moon.gemspec +5 -1
  9. data/test/chain.rb +6 -0
  10. data/test/compile.rb +12 -0
  11. data/test/path.rb +15 -0
  12. data/test/path27.moon +3 -0
  13. data/test/req.rb +17 -0
  14. data/test/ver.rb +23 -0
  15. data/vendor/{lua → leafo}/moon/all.moon +0 -0
  16. data/vendor/{lua → leafo}/moon/init.moon +0 -0
  17. data/vendor/{lua → leafo}/moonscript/base.lua +0 -0
  18. data/vendor/{lua → leafo}/moonscript/cmd/coverage.lua +0 -0
  19. data/vendor/{lua → leafo}/moonscript/cmd/lint.lua +118 -13
  20. data/vendor/{lua → leafo}/moonscript/cmd/moonc.lua +5 -12
  21. data/vendor/{lua → leafo}/moonscript/compile/statement.lua +1 -4
  22. data/vendor/{lua → leafo}/moonscript/compile/value.lua +2 -8
  23. data/vendor/{lua → leafo}/moonscript/compile.lua +21 -19
  24. data/vendor/{lua → leafo}/moonscript/data.lua +0 -0
  25. data/vendor/{lua → leafo}/moonscript/dump.lua +0 -0
  26. data/vendor/{lua → leafo}/moonscript/errors.lua +1 -1
  27. data/vendor/{lua → leafo}/moonscript/init.lua +0 -0
  28. data/vendor/{lua → leafo}/moonscript/line_tables.lua +0 -0
  29. data/vendor/leafo/moonscript/parse/env.lua +69 -0
  30. data/vendor/leafo/moonscript/parse/literals.lua +34 -0
  31. data/vendor/leafo/moonscript/parse/util.lua +267 -0
  32. data/vendor/leafo/moonscript/parse.lua +235 -0
  33. data/vendor/{lua → leafo}/moonscript/transform/destructure.lua +12 -18
  34. data/vendor/{lua → leafo}/moonscript/transform/names.lua +2 -8
  35. data/vendor/{lua → leafo}/moonscript/transform.lua +1 -4
  36. data/vendor/{lua → leafo}/moonscript/types.lua +2 -8
  37. data/vendor/{lua → leafo}/moonscript/util.lua +11 -5
  38. data/vendor/{lua → leafo}/moonscript/version.lua +1 -1
  39. metadata +71 -25
  40. data/vendor/lua/moonscript/parse.lua +0 -639
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec64394e84ba8c8288134cf012d62151406b8a1d
4
- data.tar.gz: 1217bea89d96bed46de5accb1d54a2197182ed8a
3
+ metadata.gz: c10815a43366dd3f11d5f5f3c008ae1e795f8f27
4
+ data.tar.gz: 07f58017264a9722f153d68b050c6a29a5cebba3
5
5
  SHA512:
6
- metadata.gz: 18b5ef94e1185a6e24e9a01da1d35fc767d83c24e9a2d99e51bf615b3a6ba4b97469404c0c347acb30eb793ee14b67319089efbb8930257761e396a71391f0d8
7
- data.tar.gz: ef43c5d6c538fce5f2c61f04dd4aff8b1277c2aae791512656b2eb97242c8ab3961a3e47f9f6d5c1c43871502fc2e863838250b66552bf9cfff1fae0a482ee92
6
+ metadata.gz: b52737e4a0908426294696826e1fe411c1e2685d0ec6369f0d00bc6328a305c0ac754394a4bf31e7b5e8921e908d8893bee91428b7e6afef25de734d05c65e64
7
+ data.tar.gz: 86a05962373f5d4fc9111a144cc20ba5e660ce84e091cb915d4b42ec477d7d64ca11062cd79b681fd8085738dbce1ee61a7430fe254cfa8a91558a981084ce72
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/leafo"]
2
+ path = vendor/leafo
3
+ url = https://github.com/leafo/moonscript.git
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
7
+ before_install:
8
+ - sudo apt-get update -qq
9
+ - sudo apt-get install -y liblua5.1-0-dev liblua5.1-lpeg2
data/FarMenu.ini ADDED
@@ -0,0 +1,16 @@
1
+ I: Install dependencies
2
+ bundle install
3
+ --:
4
+ B: Build gem
5
+ bundle exec rake build
6
+ L: Install gem locally
7
+ bundle exec rake install
8
+ U: Uninstall gem
9
+ gem uninstall -a rufus-lua-moon
10
+ P: Publish gem
11
+ bundle exec rake release
12
+ --:
13
+ T: Run tests
14
+ bundle exec rake
15
+ C: Open console
16
+ bundle console -new_console:c
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Rufus::Lua::Moon
2
2
 
3
+ [![Build Status](https://travis-ci.org/ukoloff/rufus-lua-moon.svg?branch=master)](https://travis-ci.org/ukoloff/rufus-lua-moon)
3
4
  [![Gem Version](https://badge.fury.io/rb/rufus-lua-moon.svg)](http://badge.fury.io/rb/rufus-lua-moon)
4
5
 
5
6
  Provides MoonScript for Rufus::Lua interpreter
@@ -40,12 +41,17 @@ s.eval <<EOL
40
41
  EOL
41
42
  ```
42
43
 
44
+ ## Dependencies
45
+
46
+ On Linux you should have Lua and Lpeg installed
47
+ (eg. for [Ubuntu](.travis.yml)).
48
+
49
+ On Windows simply use
50
+ [Rufus::Lua::Win](https://github.com/ukoloff/rufus-lua-win).
51
+
43
52
  ## Credits
44
53
 
45
54
  * [Lua](http://www.lua.org/)
46
55
  * [MoonScript](http://moonscript.org/)
47
56
  * [Rufus::Lua](https://github.com/jmettraux/rufus-lua)
48
-
49
- ## See also
50
-
51
- * [Rufus::Lua::Win](https://github.com/ukoloff/rufus-lua-win) if you run Rufus::Lua on Windows
57
+ * [Travis CI](https://travis-ci.org/)
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ desc 'Run tests'
4
+ task :test do
5
+ require "minitest/autorun"
6
+
7
+ require 'rufus/lua/win' if Gem.win_platform?
8
+ require 'rufus/lua'
9
+ require 'rufus/lua/moon'
10
+
11
+ Dir.glob('./test/*.rb'){|f| require f}
12
+ end
13
+
14
+ task default: :test
@@ -4,9 +4,9 @@ module Rufus
4
4
  root=File.expand_path '../../../../..', __FILE__
5
5
  subV=File.read(File.expand_path '.subversion', root).strip rescue ''
6
6
  subV="."+subV.gsub(/\W+/, '.') if subV.length>0
7
- Path=File.expand_path 'vendor/lua', root
7
+ Path=File.expand_path 'vendor/leafo', root
8
8
  m=/(["'])(\d+(\.\d+){1,3}(-(?!0)[\da-z])*)\1/i.match File.read File.expand_path 'moonscript/version.lua', Path
9
- VERSION = m ? m[2].gsub('-', '.')+subV : '0.0.?'
9
+ VERSION = m ? (Version=m[2]).gsub('-', '.')+subV : '0.0.?'
10
10
  end
11
11
  end
12
12
  end
@@ -13,13 +13,17 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/ukoloff/rufus-lua-moon"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($/) +
17
+ Dir.glob('vendor/leafo/moon/*.moon')+
18
+ Dir.glob('vendor/leafo/moonscript/**/*.lua')
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
21
  spec.require_paths = ["lib"]
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "rufus-lua-win" if Gem.win_platform?
23
27
 
24
28
  spec.add_dependency "rufus-lua"
25
29
  end
data/test/chain.rb ADDED
@@ -0,0 +1,6 @@
1
+ class TestC < Minitest::Test
2
+ def test_chain
3
+ s=Rufus::Lua::State.new
4
+ assert_equal s, s.moon!
5
+ end
6
+ end
data/test/compile.rb ADDED
@@ -0,0 +1,12 @@
1
+ class TestC < Minitest::Test
2
+ def test_compile
3
+ s=Rufus::Lua::State.new.moon!
4
+ assert s.eval("return require('moonscript').to_lua('x = a b c')")[0]
5
+ .gsub(/\s+/, '')['=a(b(c))']
6
+ end
7
+
8
+ def test_fail
9
+ s=Rufus::Lua::State.new.moon!
10
+ refute s.eval("return require('moonscript').to_lua 'a=b:'")[0] rescue nil
11
+ end
12
+ end
data/test/path.rb ADDED
@@ -0,0 +1,15 @@
1
+ class TestC < Minitest::Test
2
+ def test_path
3
+ skip if '0.2.3'==Rufus::Lua::Moon::Version
4
+ s=Rufus::Lua::State.new.moon!
5
+ s['package']['moonpath']=File.expand_path '../?.moon', __FILE__
6
+ assert_equal 3.0, s.eval("return require 'path27'")
7
+ end
8
+
9
+ def test_fail
10
+ s=Rufus::Lua::State.new.moon!
11
+ assert_raises(Rufus::Lua::LuaError) do
12
+ s.eval "require 'path27'"
13
+ end
14
+ end
15
+ end
data/test/path27.moon ADDED
@@ -0,0 +1,3 @@
1
+ a=x: 1+2
2
+
3
+ return a.x
data/test/req.rb ADDED
@@ -0,0 +1,17 @@
1
+ class TestV < Minitest::Test
2
+ def test_require
3
+ s=Rufus::Lua::State.new.moon!
4
+ {
5
+ moonscript: %w(util version),
6
+ moon: %w(all),
7
+ }.map{|k, v|([nil]+v).map{|i| [k, i].compact*'.'}}
8
+ .flatten.each {|f| s.eval "require '#{f}'"}
9
+ end
10
+
11
+ def test_missing
12
+ assert_raises(Rufus::Lua::LuaError) do
13
+ s=Rufus::Lua::State.new.moon!
14
+ s.eval "require 'moonscript.oops'"
15
+ end
16
+ end
17
+ end
data/test/ver.rb ADDED
@@ -0,0 +1,23 @@
1
+ class TestV < Minitest::Test
2
+ def test_ver
3
+ s=Rufus::Lua::State.new.moon!
4
+ luav=s.eval 'return _VERSION'
5
+ rufv=Rufus::Lua::VERSION
6
+ moonv=s.eval 'return require("moonscript.version").version'
7
+ gemv=Rufus::Lua::Moon::VERSION
8
+
9
+ len=moonv.length
10
+
11
+ assert_equal gemv[0...len], moonv.gsub('-', '.')
12
+ c=gemv[len]
13
+ assert(c.nil? || '.'==c)
14
+
15
+ at_exit do
16
+ puts
17
+ puts "Lua version #{luav}"
18
+ puts "Rufus::Lua version #{rufv}"
19
+ puts "MoonScript version #{moonv}"
20
+ puts "Rufus::Lua::Moon version #{gemv}"
21
+ end
22
+ end
23
+ end
File without changes
File without changes
File without changes
File without changes
@@ -1,18 +1,11 @@
1
1
  local insert
2
- do
3
- local _obj_0 = table
4
- insert = _obj_0.insert
5
- end
2
+ insert = table.insert
6
3
  local Set
7
- do
8
- local _obj_0 = require("moonscript.data")
9
- Set = _obj_0.Set
10
- end
4
+ Set = require("moonscript.data").Set
11
5
  local Block
12
- do
13
- local _obj_0 = require("moonscript.compile")
14
- Block = _obj_0.Block
15
- end
6
+ Block = require("moonscript.compile").Block
7
+ local mtype
8
+ mtype = require("moonscript.util").moon.type
16
9
  local default_whitelist = Set({
17
10
  '_G',
18
11
  '_VERSION',
@@ -61,11 +54,84 @@ local LinterBlock
61
54
  do
62
55
  local _parent_0 = Block
63
56
  local _base_0 = {
57
+ lint_mark_used = function(self, name)
58
+ if self.lint_unused_names and self.lint_unused_names[name] then
59
+ self.lint_unused_names[name] = false
60
+ return
61
+ end
62
+ if self.parent then
63
+ return self.parent:lint_mark_used(name)
64
+ end
65
+ end,
66
+ lint_check_unused = function(self)
67
+ if not (self.lint_unused_names and next(self.lint_unused_names)) then
68
+ return
69
+ end
70
+ local names_by_position = { }
71
+ for name, pos in pairs(self.lint_unused_names) do
72
+ local _continue_0 = false
73
+ repeat
74
+ if not (pos) then
75
+ _continue_0 = true
76
+ break
77
+ end
78
+ names_by_position[pos] = names_by_position[pos] or { }
79
+ insert(names_by_position[pos], name)
80
+ _continue_0 = true
81
+ until true
82
+ if not _continue_0 then
83
+ break
84
+ end
85
+ end
86
+ local tuples
87
+ do
88
+ local _accum_0 = { }
89
+ local _len_0 = 1
90
+ for pos, names in pairs(names_by_position) do
91
+ _accum_0[_len_0] = {
92
+ pos,
93
+ names
94
+ }
95
+ _len_0 = _len_0 + 1
96
+ end
97
+ tuples = _accum_0
98
+ end
99
+ table.sort(tuples, function(a, b)
100
+ return a[1] < b[1]
101
+ end)
102
+ for _index_0 = 1, #tuples do
103
+ local _des_0 = tuples[_index_0]
104
+ local pos, names
105
+ pos, names = _des_0[1], _des_0[2]
106
+ insert(self:get_root_block().lint_errors, {
107
+ "assigned but unused " .. tostring(table.concat((function()
108
+ local _accum_0 = { }
109
+ local _len_0 = 1
110
+ for _index_1 = 1, #names do
111
+ local n = names[_index_1]
112
+ _accum_0[_len_0] = "`" .. tostring(n) .. "`"
113
+ _len_0 = _len_0 + 1
114
+ end
115
+ return _accum_0
116
+ end)(), ", ")),
117
+ pos
118
+ })
119
+ end
120
+ end,
121
+ render = function(self, ...)
122
+ self:lint_check_unused()
123
+ return _parent_0.render(self, ...)
124
+ end,
64
125
  block = function(self, ...)
65
126
  do
66
127
  local _with_0 = _parent_0.block(self, ...)
67
128
  _with_0.block = self.block
129
+ _with_0.render = self.render
130
+ _with_0.get_root_block = self.get_root_block
131
+ _with_0.lint_check_unused = self.lint_check_unused
132
+ _with_0.lint_mark_used = self.lint_mark_used
68
133
  _with_0.value_compilers = self.value_compilers
134
+ _with_0.statement_compilers = self.statement_compilers
69
135
  return _with_0
70
136
  end
71
137
  end
@@ -78,6 +144,9 @@ do
78
144
  whitelist_globals = default_whitelist
79
145
  end
80
146
  _parent_0.__init(self, ...)
147
+ self.get_root_block = function()
148
+ return self
149
+ end
81
150
  self.lint_errors = { }
82
151
  local vc = self.value_compilers
83
152
  self.value_compilers = setmetatable({
@@ -85,15 +154,50 @@ do
85
154
  local name = val[2]
86
155
  if not (block:has_name(name) or whitelist_globals[name] or name:match("%.")) then
87
156
  insert(self.lint_errors, {
88
- "accessing global " .. tostring(name),
157
+ "accessing global `" .. tostring(name) .. "`",
89
158
  val[-1]
90
159
  })
91
160
  end
161
+ block:lint_mark_used(name)
92
162
  return vc.ref(block, val)
93
163
  end
94
164
  }, {
95
165
  __index = vc
96
166
  })
167
+ local sc = self.statement_compilers
168
+ self.statement_compilers = setmetatable({
169
+ assign = function(block, node)
170
+ local names = node[2]
171
+ for _index_0 = 1, #names do
172
+ local _continue_0 = false
173
+ repeat
174
+ local name = names[_index_0]
175
+ if type(name) == "table" and name[1] == "temp_name" then
176
+ _continue_0 = true
177
+ break
178
+ end
179
+ local real_name, is_local = block:extract_assign_name(name)
180
+ if not (is_local or real_name and not block:has_name(real_name, true)) then
181
+ _continue_0 = true
182
+ break
183
+ end
184
+ if real_name == "_" then
185
+ _continue_0 = true
186
+ break
187
+ end
188
+ block.lint_unused_names = block.lint_unused_names or { }
189
+ block.lint_unused_names[real_name] = node[-1] or 0
190
+ _continue_0 = true
191
+ until true
192
+ if not _continue_0 then
193
+ break
194
+ end
195
+ end
196
+ return sc.assign(block, node)
197
+ end
198
+ }, {
199
+ __index = sc
200
+ })
97
201
  end,
98
202
  __base = _base_0,
99
203
  __name = "LinterBlock",
@@ -198,6 +302,7 @@ lint_code = function(code, name, whitelist_globals)
198
302
  end
199
303
  local scope = LinterBlock(whitelist_globals)
200
304
  scope:stms(tree)
305
+ scope:lint_check_unused()
201
306
  return format_lint(scope.lint_errors, code, name)
202
307
  end
203
308
  local lint_file
@@ -1,9 +1,6 @@
1
1
  local lfs = require("lfs")
2
2
  local split
3
- do
4
- local _obj_0 = require("moonscript.util")
5
- split = _obj_0.split
6
- end
3
+ split = require("moonscript.util").split
7
4
  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
5
  dirsep = package.config:sub(1, 1)
9
6
  if dirsep == "\\" then
@@ -58,7 +55,7 @@ do
58
55
  end
59
56
  end
60
57
  end
61
- compile_file_text = function(text, fname, opts)
58
+ compile_file_text = function(text, opts)
62
59
  if opts == nil then
63
60
  opts = { }
64
61
  end
@@ -93,17 +90,14 @@ compile_file_text = function(text, fname, opts)
93
90
  end
94
91
  if opts.show_posmap then
95
92
  local debug_posmap
96
- do
97
- local _obj_0 = require("moonscript.util")
98
- debug_posmap = _obj_0.debug_posmap
99
- end
93
+ debug_posmap = require("moonscript.util").debug_posmap
100
94
  print("Pos", "Lua", ">>", "Moon")
101
95
  print(debug_posmap(posmap_or_err, text, code))
102
96
  return true
103
97
  end
104
98
  if opts.benchmark then
105
99
  print(table.concat({
106
- fname,
100
+ opts.fname or "stdin",
107
101
  "Parse time \t" .. format_time(parse_time),
108
102
  "Compile time\t" .. format_time(compile_time),
109
103
  ""
@@ -141,7 +135,7 @@ compile_and_write = function(src, dest, opts)
141
135
  return true
142
136
  end
143
137
  if opts.print then
144
- print(text)
138
+ print(code)
145
139
  return true
146
140
  end
147
141
  return write_file(dest, code)
@@ -188,7 +182,6 @@ return {
188
182
  normalize_dir = normalize_dir,
189
183
  parse_dir = parse_dir,
190
184
  parse_file = parse_file,
191
- new_path = new_path,
192
185
  convert_path = convert_path,
193
186
  gettime = gettime,
194
187
  format_time = format_time,
@@ -2,10 +2,7 @@ local util = require("moonscript.util")
2
2
  local reversed, unpack
3
3
  reversed, unpack = util.reversed, util.unpack
4
4
  local ntype
5
- do
6
- local _obj_0 = require("moonscript.types")
7
- ntype = _obj_0.ntype
8
- end
5
+ ntype = require("moonscript.types").ntype
9
6
  local concat, insert
10
7
  do
11
8
  local _obj_0 = table
@@ -1,15 +1,9 @@
1
1
  local util = require("moonscript.util")
2
2
  local data = require("moonscript.data")
3
3
  local ntype
4
- do
5
- local _obj_0 = require("moonscript.types")
6
- ntype = _obj_0.ntype
7
- end
4
+ ntype = require("moonscript.types").ntype
8
5
  local user_error
9
- do
10
- local _obj_0 = require("moonscript.errors")
11
- user_error = _obj_0.user_error
12
- end
6
+ user_error = require("moonscript.errors").user_error
13
7
  local concat, insert
14
8
  do
15
9
  local _obj_0 = table
@@ -7,10 +7,7 @@ do
7
7
  NameProxy, LocalName = _obj_0.NameProxy, _obj_0.LocalName
8
8
  end
9
9
  local Set
10
- do
11
- local _obj_0 = require("moonscript.data")
12
- Set = _obj_0.Set
13
- end
10
+ Set = require("moonscript.data").Set
14
11
  local ntype, has_value
15
12
  do
16
13
  local _obj_0 = require("moonscript.types")
@@ -259,6 +256,7 @@ do
259
256
  export_all = false,
260
257
  export_proper = false,
261
258
  value_compilers = value_compilers,
259
+ statement_compilers = statement_compilers,
262
260
  __tostring = function(self)
263
261
  local h
264
262
  if "string" == type(self.header) then
@@ -291,6 +289,22 @@ do
291
289
  end
292
290
  end
293
291
  end,
292
+ extract_assign_name = function(self, node)
293
+ local is_local = false
294
+ local real_name
295
+ local _exp_0 = mtype(node)
296
+ if LocalName == _exp_0 then
297
+ is_local = true
298
+ real_name = node:get_name(self)
299
+ elseif NameProxy == _exp_0 then
300
+ real_name = node:get_name(self)
301
+ elseif "table" == _exp_0 then
302
+ real_name = node[1] == "ref" and node[2]
303
+ elseif "string" == _exp_0 then
304
+ real_name = node
305
+ end
306
+ return real_name, is_local
307
+ end,
294
308
  declare = function(self, names)
295
309
  local undeclared
296
310
  do
@@ -300,19 +314,7 @@ do
300
314
  local _continue_0 = false
301
315
  repeat
302
316
  local name = names[_index_0]
303
- local is_local = false
304
- local real_name
305
- local _exp_0 = mtype(name)
306
- if LocalName == _exp_0 then
307
- is_local = true
308
- real_name = name:get_name(self)
309
- elseif NameProxy == _exp_0 then
310
- real_name = name:get_name(self)
311
- elseif "table" == _exp_0 then
312
- real_name = name[1] == "ref" and name[2]
313
- elseif "string" == _exp_0 then
314
- real_name = name
315
- end
317
+ local real_name, is_local = self:extract_assign_name(name)
316
318
  if not (is_local or real_name and not self:has_name(real_name, true)) then
317
319
  _continue_0 = true
318
320
  break
@@ -453,7 +455,7 @@ do
453
455
  end
454
456
  end,
455
457
  is_stm = function(self, node)
456
- return statement_compilers[ntype(node)] ~= nil
458
+ return self.statement_compilers[ntype(node)] ~= nil
457
459
  end,
458
460
  is_value = function(self, node)
459
461
  local t = ntype(node)
@@ -519,7 +521,7 @@ do
519
521
  node = self.transform.statement(node)
520
522
  local result
521
523
  do
522
- local fn = statement_compilers[ntype(node)]
524
+ local fn = self.statement_compilers[ntype(node)]
523
525
  if fn then
524
526
  result = fn(self, node, ...)
525
527
  else
File without changes
File without changes
@@ -18,7 +18,7 @@ local lookup_line
18
18
  lookup_line = function(fname, pos, cache)
19
19
  if not cache[fname] then
20
20
  do
21
- local _with_0 = io.open(fname)
21
+ local _with_0 = assert(io.open(fname))
22
22
  cache[fname] = _with_0:read("*a")
23
23
  _with_0:close()
24
24
  end
File without changes
File without changes
@@ -0,0 +1,69 @@
1
+ local getfenv, setfenv
2
+ do
3
+ local _obj_0 = require("moonscript.util")
4
+ getfenv, setfenv = _obj_0.getfenv, _obj_0.setfenv
5
+ end
6
+ local wrap_env
7
+ wrap_env = function(debug, fn)
8
+ local V, Cmt
9
+ do
10
+ local _obj_0 = require("lpeg")
11
+ V, Cmt = _obj_0.V, _obj_0.Cmt
12
+ end
13
+ local env = getfenv(fn)
14
+ local wrap_name = V
15
+ if debug then
16
+ local indent = 0
17
+ local indent_char = " "
18
+ local iprint
19
+ iprint = function(...)
20
+ local args = table.concat((function(...)
21
+ local _accum_0 = { }
22
+ local _len_0 = 1
23
+ local _list_0 = {
24
+ ...
25
+ }
26
+ for _index_0 = 1, #_list_0 do
27
+ local a = _list_0[_index_0]
28
+ _accum_0[_len_0] = tostring(a)
29
+ _len_0 = _len_0 + 1
30
+ end
31
+ return _accum_0
32
+ end)(...), ", ")
33
+ return io.stderr:write(tostring(indent_char:rep(indent)) .. tostring(args) .. "\n")
34
+ end
35
+ wrap_name = function(name)
36
+ local v = V(name)
37
+ v = Cmt("", function()
38
+ iprint("* " .. name)
39
+ indent = indent + 1
40
+ return true
41
+ end) * Cmt(v, function(str, pos, ...)
42
+ iprint(name, true)
43
+ indent = indent - 1
44
+ return true, ...
45
+ end) + Cmt("", function()
46
+ iprint(name, false)
47
+ indent = indent - 1
48
+ return false
49
+ end)
50
+ return v
51
+ end
52
+ end
53
+ return setfenv(fn, setmetatable({ }, {
54
+ __index = function(self, name)
55
+ local value = env[name]
56
+ if value ~= nil then
57
+ return value
58
+ end
59
+ if name:match("^[A-Z][A-Za-z0-9]*$") then
60
+ local v = wrap_name(name)
61
+ return v
62
+ end
63
+ return error("unknown variable referenced: " .. tostring(name))
64
+ end
65
+ }))
66
+ end
67
+ return {
68
+ wrap_env = wrap_env
69
+ }