aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files.lua22
-rw-r--r--files.moon10
-rw-r--r--nomsu.lua15
-rwxr-xr-xnomsu.moon15
-rw-r--r--nomsu_compiler.lua22
-rw-r--r--nomsu_compiler.moon16
6 files changed, 42 insertions, 58 deletions
diff --git a/files.lua b/files.lua
index c04f703..48e047f 100644
--- a/files.lua
+++ b/files.lua
@@ -191,20 +191,18 @@ Files.walk = function(path, flush_cache)
end
end
end
- local iter
- iter = function(files, i)
- if not (files) then
- return
- end
- i = i + 1
- do
- local f = files[i]
- if f then
- return i, f
- end
+ files = files or { }
+ do
+ local _accum_0 = { }
+ local _len_0 = 1
+ for _index_0 = 1, #files do
+ local f = files[_index_0]
+ _accum_0[_len_0] = gsub(f, "^%./", "")
+ _len_0 = _len_0 + 1
end
+ files = _accum_0
end
- return iter, files, 0
+ return ipairs(files)
end
local line_counter = re.compile([[ lines <- {| line (%nl line)* |}
line <- {} (!%nl .)*
diff --git a/files.moon b/files.moon
index becc3fb..e0fe02b 100644
--- a/files.moon
+++ b/files.moon
@@ -33,7 +33,6 @@ Files.read = (filename)->
_FILE_CACHE[filename] = contents
return contents
--- `walk` returns an iterator over all files matching a path.
{:match, :gsub} = string
-- TODO: improve sanitization
@@ -108,12 +107,9 @@ Files.walk = (path, flush_cache=false)->
else
for nomsupath in package.nomsupath\gmatch("[^;]+")
if files = browse(nomsupath.."/"..path) then break
- iter = (files, i)->
- return unless files
- i += 1
- if f = files[i]
- return i, f
- return iter, files, 0
+ files or= {}
+ files = [gsub(f, "^%./", "") for f in *files]
+ return ipairs(files)
line_counter = re.compile([[
lines <- {| line (%nl line)* |}
diff --git a/nomsu.lua b/nomsu.lua
index fa6a6ce..bd1ee85 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -133,8 +133,7 @@ end
local nomsu = NomsuCompiler
nomsu.environment.arg = NomsuCompiler.environment._List(args.nomsu_args)
if args.version then
- nomsu:run([[use "core"
-say (Nomsu version)]])
+ nomsu:run([[(: use "core"; say (Nomsu version))]])
os.exit(EXIT_SUCCESS)
end
FILE_CACHE = setmetatable({ }, {
@@ -183,11 +182,7 @@ run = function()
return true
end
if not (args.no_core) then
- for _, filename in Files.walk('core') do
- if filename:match("%.nom$") then
- nomsu:import(nomsu:run_file(filename))
- end
- end
+ nomsu:import_file('core')
end
local get_file_and_source
get_file_and_source = function(filename)
@@ -280,8 +275,8 @@ run = function()
if not (args.primary_file or args.exec_strings) then
nomsu:run([[#!/usr/bin/env nomsu -V4
use "lib/consolecolor.nom"
-action [quit, exit]: lua> "os.exit(0)"
-action [help]:
+[quit, exit] all mean: lua> "os.exit(0)"
+(help) means:
say "\
..This is the Nomsu v\(Nomsu version) interactive console.
You can type in Nomsu code here and hit 'enter' twice to run it.
@@ -320,7 +315,7 @@ say "\
return Errhand.print_error(error_message)
end
local ret
- ok, ret = xpcall(nomsu.run, err_hand, nomsu, buff, Source(pseudo_filename, 1, #buff))
+ ok, ret = xpcall(nomsu.run, err_hand, nomsu, NomsuCode(Source(pseudo_filename, 1, #buff), buff))
if ok and ret ~= nil then
if type(ret) == 'number' then
print("= " .. tostring(ret))
diff --git a/nomsu.moon b/nomsu.moon
index 1ab9637..c4a96f1 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -89,9 +89,7 @@ nomsu = NomsuCompiler
nomsu.environment.arg = NomsuCompiler.environment._List(args.nomsu_args)
if args.version
- nomsu\run [[
-use "core"
-say (Nomsu version)]]
+ nomsu\run [[(: use "core"; say (Nomsu version))]]
os.exit(EXIT_SUCCESS)
export FILE_CACHE
@@ -123,9 +121,7 @@ run = ->
return true
unless args.no_core
- for _,filename in Files.walk('core')
- if filename\match "%.nom$"
- nomsu\import(nomsu\run_file(filename))
+ nomsu\import_file('core')
get_file_and_source = (filename)->
local file, source
@@ -185,8 +181,8 @@ run = ->
nomsu\run [[
#!/usr/bin/env nomsu -V4
use "lib/consolecolor.nom"
-action [quit, exit]: lua> "os.exit(0)"
-action [help]:
+[quit, exit] all mean: lua> "os.exit(0)"
+(help) means:
say "\
..This is the Nomsu v\(Nomsu version) interactive console.
You can type in Nomsu code here and hit 'enter' twice to run it.
@@ -215,11 +211,12 @@ say "\
break -- Exit
buff = table.concat(buff)
+
pseudo_filename = "user input #"..repl_line
Files.spoof(pseudo_filename, buff)
err_hand = (error_message)->
Errhand.print_error error_message
- ok, ret = xpcall(nomsu.run, err_hand, nomsu, buff, Source(pseudo_filename, 1, #buff))
+ ok, ret = xpcall nomsu.run, err_hand, nomsu, NomsuCode(Source(pseudo_filename,1,#buff), buff)
if ok and ret != nil
if type(ret) == 'number'
print "= #{ret}"
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index dff7eb7..8c2d90b 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -157,7 +157,7 @@ do
return false
end
NomsuCompiler.environment = {
- NOMSU_COMPILER_VERSION = 9,
+ NOMSU_COMPILER_VERSION = 10,
NOMSU_SYNTAX_VERSION = max_parser_version,
next = next,
unpack = unpack,
@@ -459,19 +459,10 @@ do
return add_lua_bits(self, "value", code)
end,
["use 1"] = function(self, tree, path)
- local lua = LuaCode(tree.source)
if path.type == 'Text' and #path == 1 and type(path[1]) == 'string' then
- for _, f in Files.walk(path[1]) do
- if match(f, "%.lua$") or match(f, "%.nom$") or match(f, "^/dev/fd/[012]$") then
- self:import(self:run_file(f))
- if #lua.bits > 0 then
- lua:append("\n")
- end
- lua:append("nomsu:import(nomsu:run_file(" .. tostring(f:as_lua()) .. "))")
- end
- end
+ self:import_file(path[1])
end
- return lua
+ return LuaCode(tree.source, "nomsu:import_file(" .. tostring(self:compile(path)) .. ")")
end,
["tests"] = function(self, tree)
return LuaCode.Value(tree.source, "TESTS")
@@ -533,6 +524,13 @@ do
end
end
end
+ NomsuCompiler.import_file = function(self, path)
+ for _, f in Files.walk(path) do
+ if match(f, "%.lua$") or match(f, "%.nom$") or match(f, "^/dev/fd/[012]$") then
+ self:import(self:run_file(f))
+ end
+ end
+ end
NomsuCompiler.run = function(self, to_run, compile_actions)
local source = to_run.source or Source(to_run, 1, #to_run)
if type(source) == 'string' then
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 4746e10..304f6b9 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -97,7 +97,7 @@ with NomsuCompiler
-- Discretionary/convenience stuff
.environment = {
- NOMSU_COMPILER_VERSION: 9, NOMSU_SYNTAX_VERSION: max_parser_version
+ NOMSU_COMPILER_VERSION: 10, NOMSU_SYNTAX_VERSION: max_parser_version
-- Lua stuff:
:next, :unpack, :setmetatable, :coroutine, :rawequal, :getmetatable, :pcall,
:error, :package, :os, :require, :tonumber, :tostring, :string, :xpcall, :module,
@@ -264,14 +264,9 @@ with NomsuCompiler
return add_lua_bits(@, "value", code)
["use 1"]: (tree, path)=>
- lua = LuaCode(tree.source)
if path.type == 'Text' and #path == 1 and type(path[1]) == 'string'
- for _,f in Files.walk(path[1])
- if match(f, "%.lua$") or match(f, "%.nom$") or match(f, "^/dev/fd/[012]$")
- @import(@run_file(f))
- if #lua.bits > 0 then lua\append "\n"
- lua\append "nomsu:import(nomsu:run_file(#{f\as_lua!}))"
- return lua
+ @import_file(path[1])
+ return LuaCode(tree.source, "nomsu:import_file(#{@compile(path)})")
["tests"]: (tree)=> LuaCode.Value(tree.source, "TESTS")
["test 1"]: (tree, body)=>
@@ -299,6 +294,11 @@ with NomsuCompiler
continue if k == "__imported" or k == "__parent"
@environment.COMPILE_ACTIONS.__imported[k] or= v
+ .import_file = (path)=>
+ for _,f in Files.walk(path)
+ if match(f, "%.lua$") or match(f, "%.nom$") or match(f, "^/dev/fd/[012]$")
+ @import(@run_file(f))
+
.run = (to_run, compile_actions)=>
source = to_run.source or Source(to_run, 1, #to_run)
if type(source) == 'string' then source = Source\from_string(source)