Adding some compatibility stuff.
This commit is contained in:
parent
0d70332ccf
commit
de34592dbe
@ -59,7 +59,7 @@ if ok then
|
||||
local raw_file_exists
|
||||
raw_file_exists = function(filename)
|
||||
local mode = lfs.attributes(filename, 'mode')
|
||||
if mode == 'file' or mode == 'directory' then
|
||||
if mode == 'file' or mode == 'directory' or mode == 'link' then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
@ -80,15 +80,15 @@ if ok then
|
||||
end
|
||||
local browse
|
||||
browse = function(filename)
|
||||
local file_type = lfs.attributes(filename, 'mode')
|
||||
local file_type, err = lfs.attributes(filename, 'mode')
|
||||
if file_type == 'file' then
|
||||
if match(filename, "%.nom$") or match(filename, "%.lua$") then
|
||||
coroutine.yield(filename)
|
||||
return true
|
||||
end
|
||||
elseif file_type == 'directory' then
|
||||
elseif file_type == 'directory' or file_type == 'link' then
|
||||
for subfile in lfs.dir(filename) do
|
||||
if not (subfile == "." or subfile == ".." or not subfile:match("%.nom$")) then
|
||||
if not (subfile == "." or subfile == "..") then
|
||||
browse(filename .. "/" .. subfile)
|
||||
end
|
||||
end
|
||||
|
10
files.moon
10
files.moon
@ -37,7 +37,7 @@ ok, lfs = pcall(require, "lfs")
|
||||
if ok
|
||||
raw_file_exists = (filename)->
|
||||
mode = lfs.attributes(filename, 'mode')
|
||||
return if mode == 'file' or mode == 'directory' then true else false
|
||||
return if mode == 'file' or mode == 'directory' or mode == 'link' then true else false
|
||||
files.exists = (path)->
|
||||
return true if path == 'stdin' or raw_file_exists(path)
|
||||
if package.nomsupath
|
||||
@ -46,20 +46,20 @@ if ok
|
||||
return false
|
||||
-- Return 'true' if any files or directories are found, otherwise 'false', and yield every filename
|
||||
browse = (filename)->
|
||||
file_type = lfs.attributes(filename, 'mode')
|
||||
file_type, err = lfs.attributes(filename, 'mode')
|
||||
if file_type == 'file'
|
||||
if match(filename, "%.nom$") or match(filename, "%.lua$")
|
||||
coroutine.yield filename
|
||||
return true
|
||||
elseif file_type == 'directory'
|
||||
elseif file_type == 'directory' or file_type == 'link'
|
||||
for subfile in lfs.dir(filename)
|
||||
-- Only include .nom files unless directly specified
|
||||
unless subfile == "." or subfile == ".." or not subfile\match("%.nom$")
|
||||
unless subfile == "." or subfile == ".."
|
||||
browse(filename.."/"..subfile)
|
||||
return true
|
||||
elseif file_type == 'char device'
|
||||
coroutine.yield(filename)
|
||||
return true
|
||||
|
||||
return false
|
||||
files.walk = (path)->
|
||||
if match(path, "%.nom$") or match(path, "%.lua$") or path == 'stdin'
|
||||
|
@ -1,10 +1,14 @@
|
||||
-- Nomsu version 1
|
||||
file:
|
||||
shebang?
|
||||
(ignored_line %nl)*
|
||||
(file_chunks / block / action / expression)?
|
||||
(%nl ignored_line)*
|
||||
(!. / (({} (.* -> "Parse error") %userdata) => error))
|
||||
|
||||
shebang:
|
||||
("#!" (!"nomsu" !%nl .)* "nomsu" ((%ws* "-V" %ws* {[0-9]+ ("." [0-9]+)*}) / {''}) %ws* (%nl / !.) %userdata) => Version
|
||||
|
||||
file_chunks (FileChunks):
|
||||
{| (block/action/expression) (nodent chunk_delimeter nodent (block/action/expression))+ |}
|
||||
chunk_delimeter: "~~~" (("~")*)
|
||||
|
@ -486,6 +486,14 @@ do
|
||||
return run_lua_fn()
|
||||
end
|
||||
NomsuCompiler.compile = function(self, tree)
|
||||
if tree.version then
|
||||
do
|
||||
local upgrade = self['A' .. string.as_lua_id("upgrade 1 from 2")]
|
||||
if upgrade then
|
||||
tree = upgrade(tree, tree.version)
|
||||
end
|
||||
end
|
||||
end
|
||||
local _exp_0 = tree.type
|
||||
if "Action" == _exp_0 then
|
||||
local stub = tree.stub
|
||||
|
@ -321,6 +321,9 @@ with NomsuCompiler
|
||||
return run_lua_fn!
|
||||
|
||||
.compile = (tree)=>
|
||||
if tree.version
|
||||
if upgrade = @['A'..string.as_lua_id("upgrade 1 from 2")]
|
||||
tree = upgrade(tree, tree.version)
|
||||
switch tree.type
|
||||
when "Action"
|
||||
stub = tree.stub
|
||||
|
@ -97,6 +97,10 @@ do
|
||||
userdata.comments[start_pos] = value
|
||||
return true
|
||||
end
|
||||
_with_0.Version = function(src, end_pos, version, userdata)
|
||||
userdata.version = version
|
||||
return true
|
||||
end
|
||||
NOMSU_DEFS = _with_0
|
||||
end
|
||||
setmetatable(NOMSU_DEFS, {
|
||||
@ -195,6 +199,7 @@ Parser.parse = function(nomsu_code, source)
|
||||
error("Errors occurred while parsing:\n\n" .. table.concat(errors, "\n\n"), 0)
|
||||
end
|
||||
tree.comments = userdata.comments
|
||||
tree.version = userdata.version
|
||||
return tree
|
||||
end
|
||||
return Parser
|
||||
|
@ -76,6 +76,10 @@ NOMSU_DEFS = with {}
|
||||
userdata.comments[start_pos] = value
|
||||
return true
|
||||
|
||||
.Version = (src,end_pos,version,userdata)->
|
||||
userdata.version = version
|
||||
return true
|
||||
|
||||
setmetatable(NOMSU_DEFS, {__index:(key)=>
|
||||
make_node = (start, value, stop, userdata)->
|
||||
if userdata.source
|
||||
@ -133,6 +137,7 @@ Parser.parse = (nomsu_code, source=nil)->
|
||||
error("Errors occurred while parsing:\n\n"..table.concat(errors, "\n\n"), 0)
|
||||
|
||||
tree.comments = userdata.comments
|
||||
tree.version = userdata.version
|
||||
return tree
|
||||
|
||||
return Parser
|
||||
|
Loading…
Reference in New Issue
Block a user