aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files.lua22
-rw-r--r--files.moon11
-rw-r--r--nomsu.lua30
-rwxr-xr-xnomsu.moon9
4 files changed, 47 insertions, 25 deletions
diff --git a/files.lua b/files.lua
index cda361d..0504faf 100644
--- a/files.lua
+++ b/files.lua
@@ -26,6 +26,7 @@ local _FILE_CACHE = setmetatable({ }, {
})
local _BROWSE_CACHE = { }
Files.spoof = function(filename, contents)
+ print("SPOOFING " .. tostring(filename))
_SPOOFED_FILES[filename] = contents
return contents
end
@@ -65,6 +66,9 @@ Files.exists = function(path)
if _SPOOFED_FILES[path] then
return true
end
+ if path == 'stdin' then
+ return true
+ end
if run_cmd("ls " .. tostring(sanitize(path))) then
return true
end
@@ -116,7 +120,7 @@ if ok then
end
browse = function(filename)
if not (_BROWSE_CACHE[filename]) then
- if _SPOOFED_FILES[filename] then
+ if _SPOOFED_FILES[filename] or filename == 'stdin' then
_BROWSE_CACHE[filename] = {
filename
}
@@ -174,11 +178,17 @@ Files.walk = function(path, flush_cache)
_BROWSE_CACHE = { }
end
local files
- for nomsupath in package.nomsupath:gmatch("[^;]+") do
- do
- files = browse(nomsupath .. "/" .. path)
- if files then
- break
+ if path == 'stdin' then
+ files = {
+ path
+ }
+ else
+ for nomsupath in package.nomsupath:gmatch("[^;]+") do
+ do
+ files = browse(nomsupath .. "/" .. path)
+ if files then
+ break
+ end
end
end
end
diff --git a/files.moon b/files.moon
index ceb24e8..1a9c50a 100644
--- a/files.moon
+++ b/files.moon
@@ -17,6 +17,7 @@ _BROWSE_CACHE = {}
-- Create a fake file and put it in the cache
Files.spoof = (filename, contents)->
+ print("SPOOFING #{filename}")
_SPOOFED_FILES[filename] = contents
return contents
@@ -46,6 +47,7 @@ sanitize = (path)->
Files.exists = (path)->
return true if _SPOOFED_FILES[path]
+ return true if path == 'stdin'
return true if run_cmd("ls #{sanitize(path)}")
for nomsupath in package.nomsupath\gmatch("[^;]+")
return true if run_cmd("ls #{nomsupath}/#{sanitize(path)}")
@@ -74,7 +76,7 @@ if ok
export browse
browse = (filename)->
unless _BROWSE_CACHE[filename]
- _BROWSE_CACHE[filename] = if _SPOOFED_FILES[filename]
+ _BROWSE_CACHE[filename] = if _SPOOFED_FILES[filename] or filename == 'stdin'
{filename}
else
file_type, err = lfs.attributes(filename, 'mode')
@@ -102,8 +104,11 @@ Files.walk = (path, flush_cache=false)->
export _BROWSE_CACHE
_BROWSE_CACHE = {}
local files
- for nomsupath in package.nomsupath\gmatch("[^;]+")
- if files = browse(nomsupath.."/"..path) then break
+ if path == 'stdin'
+ files = {path}
+ else
+ for nomsupath in package.nomsupath\gmatch("[^;]+")
+ if files = browse(nomsupath.."/"..path) then break
iter = (files, i)->
return unless files
i += 1
diff --git a/nomsu.lua b/nomsu.lua
index cfb243d..ab04883 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -159,12 +159,24 @@ local run
run = function()
local input_files = { }
for _index_0 = 1, #file_queue do
- local f = file_queue[_index_0]
- if not (Files.exists(f)) then
- error("Could not find: '" .. tostring(f) .. "'")
- end
- for _, filename in Files.walk(f) do
- input_files[filename] = true
+ local _continue_0 = false
+ repeat
+ local f = file_queue[_index_0]
+ if f == 'stdin' then
+ input_files[f] = true
+ _continue_0 = true
+ break
+ end
+ if not (Files.exists(f)) then
+ error("Could not find: '" .. tostring(f) .. "'")
+ end
+ for _, filename in Files.walk(f) do
+ input_files[filename] = true
+ end
+ _continue_0 = true
+ until true
+ if not _continue_0 then
+ break
end
end
nomsu.can_optimize = function(f)
@@ -186,11 +198,7 @@ run = function()
local get_file_and_source
get_file_and_source = function(filename)
local file, source
- if filename == 'stdin' then
- file = io.read("*a")
- Files.spoof('stdin', file)
- source = Source('stdin', 1, #file)
- elseif filename:match("%.nom$") then
+ if filename == 'stdin' or filename:match("%.nom$") then
file = Files.read(filename)
if not file then
error("File does not exist: " .. tostring(filename), 0)
diff --git a/nomsu.moon b/nomsu.moon
index bf6a1f6..c0c1ed2 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -110,6 +110,9 @@ FILE_CACHE = setmetatable {}, {
run = ->
input_files = {}
for f in *file_queue
+ if f == 'stdin'
+ input_files[f] = true
+ continue
unless Files.exists(f)
error("Could not find: '#{f}'")
for _,filename in Files.walk(f)
@@ -127,11 +130,7 @@ run = ->
get_file_and_source = (filename)->
local file, source
- if filename == 'stdin'
- file = io.read("*a")
- Files.spoof('stdin', file)
- source = Source('stdin', 1, #file)
- elseif filename\match("%.nom$")
+ if filename == 'stdin' or filename\match("%.nom$")
file = Files.read(filename)
if not file
error("File does not exist: #{filename}", 0)