Cleanup of some metaprogramming stuff, as well as adding support for
"package.nomsupath" to search for files in different locations, and prioritizing use of "luafilesystem" over system calls.
This commit is contained in:
parent
7761f715f7
commit
86a3219e7f
@ -383,3 +383,18 @@ compile [do %action then always %final_action] to
|
|||||||
# Inline thunk:
|
# Inline thunk:
|
||||||
compile [result of %body] to
|
compile [result of %body] to
|
||||||
Lua value "(\(compile as: [] -> %body))()"
|
Lua value "(\(compile as: [] -> %body))()"
|
||||||
|
|
||||||
|
# Recurion control flow
|
||||||
|
using
|
||||||
|
compile [%var's stack] to: Lua value "stack\(%var as lua id)"
|
||||||
|
..compile
|
||||||
|
parse [for %var in recursive %structure %body] as
|
||||||
|
with local {(%var's stack): [%structure], action: recurse % on %}
|
||||||
|
action [recurse %v on %x]
|
||||||
|
add %x to (%v's stack)
|
||||||
|
repeat while: (length of (%var's stack)) > 0
|
||||||
|
%var <- (remove 1 from (%var's stack))
|
||||||
|
%body
|
||||||
|
=== next %var ==
|
||||||
|
=== stop %var ===
|
||||||
|
|
||||||
|
@ -52,6 +52,20 @@ lua> ".."
|
|||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
compile [using %defs compile %body] to
|
||||||
|
lua> ".."
|
||||||
|
local lua = LuaCode(tree.source)
|
||||||
|
lua:append(
|
||||||
|
"local old_nomsu = nomsu\n",
|
||||||
|
"local nomsu = table.fork(old_nomsu, {COMPILE_ACTIONS=table.fork(old_nomsu.COMPILE_ACTIONS)})")
|
||||||
|
lua:append(nomsu:compile(\%defs))
|
||||||
|
lua:append("\n")
|
||||||
|
lua:append("local ret = nomsu:compile(tree)\n")
|
||||||
|
lua:append("return ret")
|
||||||
|
nomsu = table.fork(nomsu, {tree=\%body})
|
||||||
|
local output = nomsu:run_lua(lua)
|
||||||
|
return output
|
||||||
|
|
||||||
compile [local action %actions %body] to
|
compile [local action %actions %body] to
|
||||||
lua> ".."
|
lua> ".."
|
||||||
local fn_name = "A"..string.as_lua_id(\%actions[1].stub)
|
local fn_name = "A"..string.as_lua_id(\%actions[1].stub)
|
||||||
@ -84,6 +98,9 @@ compile [action %actions %body] to
|
|||||||
lua:remove_free_vars(table.map(\%actions, function(a) return "A"..string.as_lua_id(a.stub) end))
|
lua:remove_free_vars(table.map(\%actions, function(a) return "A"..string.as_lua_id(a.stub) end))
|
||||||
return lua
|
return lua
|
||||||
|
|
||||||
|
compile [action %action] to
|
||||||
|
Lua value "A\(%action.stub as lua id)"
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
compile [parse %actions as %body] to
|
compile [parse %actions as %body] to
|
||||||
@ -160,6 +177,9 @@ compile [declare locals in %code] to
|
|||||||
compile [declare locals %locals in %code] to
|
compile [declare locals %locals in %code] to
|
||||||
Lua value "\(%code as lua expr):declare_locals(\(%locals as lua expr))"
|
Lua value "\(%code as lua expr):declare_locals(\(%locals as lua expr))"
|
||||||
|
|
||||||
|
compile [add free vars %vars to %code] to
|
||||||
|
Lua "\(%code as lua expr):add_free_vars(\(%vars as lua expr));"
|
||||||
|
|
||||||
compile [remove free vars %vars from %code] to
|
compile [remove free vars %vars from %code] to
|
||||||
Lua "\(%code as lua expr):remove_free_vars(\(%vars as lua expr));"
|
Lua "\(%code as lua expr):remove_free_vars(\(%vars as lua expr));"
|
||||||
|
|
||||||
|
@ -130,16 +130,6 @@ compile [with %assignments %body] to
|
|||||||
\%lua
|
\%lua
|
||||||
end -- 'with' block
|
end -- 'with' block
|
||||||
|
|
||||||
compile [local %var_or_vars] to
|
|
||||||
%lua <- (Lua "")
|
|
||||||
lua> ".."
|
|
||||||
if \%var_or_vars.type == "List" then
|
|
||||||
\%lua:add_free_vars(table.map(\%var_or_vars, function(v) return tostring(nomsu:compile(v)) end))
|
|
||||||
else
|
|
||||||
\%lua:add_free_vars({tostring(nomsu:compile(\%var_or_vars))})
|
|
||||||
end
|
|
||||||
return %lua
|
|
||||||
|
|
||||||
# Math Operators
|
# Math Operators
|
||||||
compile [%x wrapped around %y, %x mod %y] to: Lua value "(\(%x as lua expr) % \(%y as lua expr))"
|
compile [%x wrapped around %y, %x mod %y] to: Lua value "(\(%x as lua expr) % \(%y as lua expr))"
|
||||||
|
|
||||||
|
@ -9,18 +9,18 @@ compile [with local %locals %body, with local %locals do %body] to
|
|||||||
* "Dict"
|
* "Dict"
|
||||||
%body_lua <-
|
%body_lua <-
|
||||||
Lua ".."
|
Lua ".."
|
||||||
\(=lua "A_assign_1(\%locals, \%locals)")
|
\(compile as: <- %locals)
|
||||||
\%body_lua
|
\%body_lua
|
||||||
declare locals
|
declare locals
|
||||||
(%.1 as lua id) for % in %locals
|
"\(%.1 as lua)" for % in %locals
|
||||||
.. in %body_lua
|
.. in %body_lua
|
||||||
* "List"
|
* "List"
|
||||||
declare locals
|
declare locals
|
||||||
(% as lua id) for % in %locals
|
"\(% as lua)" for % in %locals
|
||||||
.. in %body_lua
|
.. in %body_lua
|
||||||
* "Var"
|
* "Var"
|
||||||
* "Action"
|
* "Action"
|
||||||
declare locals [%locals as lua id] in %body_lua
|
declare locals ["\(%locals as lua)"] in %body_lua
|
||||||
* else
|
* else
|
||||||
barf "Unexpected local: \(%locals as nomsu)"
|
barf "Unexpected local: \(%locals as nomsu)"
|
||||||
return
|
return
|
||||||
|
@ -197,7 +197,8 @@ end
|
|||||||
local error_handler
|
local error_handler
|
||||||
error_handler = function(error_message)
|
error_handler = function(error_message)
|
||||||
print_error(error_message)
|
print_error(error_message)
|
||||||
return os.exit(false, true)
|
local EXIT_FAILURE = 1
|
||||||
|
return os.exit(EXIT_FAILURE)
|
||||||
end
|
end
|
||||||
local run_safely
|
local run_safely
|
||||||
run_safely = function(fn)
|
run_safely = function(fn)
|
||||||
|
@ -123,7 +123,8 @@ print_error = (error_message, stack_offset=3)->
|
|||||||
|
|
||||||
error_handler = (error_message)->
|
error_handler = (error_message)->
|
||||||
print_error error_message
|
print_error error_message
|
||||||
os.exit(false, true)
|
EXIT_FAILURE = 1
|
||||||
|
os.exit(EXIT_FAILURE)
|
||||||
|
|
||||||
run_safely = (fn)->
|
run_safely = (fn)->
|
||||||
xpcall(fn, error_handler)
|
xpcall(fn, error_handler)
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
use "core"
|
use "core"
|
||||||
|
|
||||||
compile [@, me] to: Lua value "self"
|
compile [@, me] to: Lua value "self"
|
||||||
compile [set methods %methods] to
|
|
||||||
%lua <- (Lua "")
|
|
||||||
for %m in %methods
|
|
||||||
to %lua write "\nclass.\(%m as lua id) = \(%m as lua id)"
|
|
||||||
return %lua
|
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
compile [method %actions %body] to
|
||||||
|
%lua <- (compile as: action %actions %body)
|
||||||
parse [method %actions %body] as
|
add free vars ((% as lua id) for % in %actions) to %lua
|
||||||
with local %actions
|
declare locals in %lua
|
||||||
action %actions %body
|
for % in %actions
|
||||||
set methods %actions
|
to %lua write "\nclass.\(% as lua id) = \(% as lua id)"
|
||||||
|
return
|
||||||
|
Lua ".."
|
||||||
|
do -- Method: \(%actions.1.stub)
|
||||||
|
\%lua
|
||||||
|
end
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
parse [as %instance %body] as
|
parse [as %instance %body] as
|
||||||
|
114
nomsu.lua
114
nomsu.lua
@ -1,3 +1,4 @@
|
|||||||
|
local EXIT_SUCCESS, EXIT_FAILURE = 0, 1
|
||||||
local usage = [=[Nomsu Compiler
|
local usage = [=[Nomsu Compiler
|
||||||
|
|
||||||
Usage: (lua nomsu.lua | moon nomsu.moon) [-i] [-O] [-v] [-c] [-f] [-s] [--help] [-p print_file] file1 file2... [-- nomsu args...]
|
Usage: (lua nomsu.lua | moon nomsu.moon) [-i] [-O] [-v] [-c] [-f] [-s] [--help] [-p print_file] file1 file2... [-- nomsu args...]
|
||||||
@ -13,8 +14,14 @@ OPTIONS
|
|||||||
-p <file> Print to the specified file instead of stdout.
|
-p <file> Print to the specified file instead of stdout.
|
||||||
<input> Input file can be "-" to use stdin.
|
<input> Input file can be "-" to use stdin.
|
||||||
]=]
|
]=]
|
||||||
local lpeg = require('lpeg')
|
local ok, _ = pcall(function()
|
||||||
local re = require('re')
|
lpeg = require('lpeg')
|
||||||
|
re = require('re')
|
||||||
|
end)
|
||||||
|
if not ok then
|
||||||
|
print("Error: unable to find the 'lpeg' Lua module. Please install LPEG either from http://www.inf.puc-rio.br/~roberto/lpeg/re.html or, if you use luarocks: `luarocks install lpeg`")
|
||||||
|
os.exit(EXIT_FAILURE)
|
||||||
|
end
|
||||||
local Errhand = require("error_handling")
|
local Errhand = require("error_handling")
|
||||||
local NomsuCompiler = require("nomsu_compiler")
|
local NomsuCompiler = require("nomsu_compiler")
|
||||||
local NomsuCode, LuaCode, Source
|
local NomsuCode, LuaCode, Source
|
||||||
@ -46,10 +53,101 @@ local args = table.concat(arg, ";") .. ";"
|
|||||||
args = parser:match(args)
|
args = parser:match(args)
|
||||||
if not args or args.help then
|
if not args or args.help then
|
||||||
print(usage)
|
print(usage)
|
||||||
os.exit()
|
os.exit(EXIT_FAILURE)
|
||||||
end
|
end
|
||||||
local nomsu = NomsuCompiler
|
local nomsu = NomsuCompiler
|
||||||
nomsu.arg = args.nomsu_args
|
nomsu.arg = args.nomsu_args
|
||||||
|
FILE_CACHE = setmetatable({ }, {
|
||||||
|
__index = function(self, filename)
|
||||||
|
local file = io.open(filename)
|
||||||
|
if not (file) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local contents = file:read("*a")
|
||||||
|
file:close()
|
||||||
|
self[filename] = contents
|
||||||
|
return contents
|
||||||
|
end
|
||||||
|
})
|
||||||
|
local match, sub, rep, gsub, format, byte, find
|
||||||
|
do
|
||||||
|
local _obj_0 = string
|
||||||
|
match, sub, rep, gsub, format, byte, match, find = _obj_0.match, _obj_0.sub, _obj_0.rep, _obj_0.gsub, _obj_0.format, _obj_0.byte, _obj_0.match, _obj_0.find
|
||||||
|
end
|
||||||
|
local iterate_single
|
||||||
|
iterate_single = function(item, prev)
|
||||||
|
if item == prev then
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
return item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local lfs
|
||||||
|
ok, lfs = pcall(require, "lfs")
|
||||||
|
if ok then
|
||||||
|
all_files = function(path)
|
||||||
|
local browse
|
||||||
|
browse = function(filename)
|
||||||
|
local file_type = 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
|
||||||
|
for subfile in lfs.dir(filename) do
|
||||||
|
if not (subfile == "." or subfile == "..") then
|
||||||
|
browse(filename .. "/" .. subfile)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
elseif file_type == 'char device' then
|
||||||
|
coroutine.yield(filename)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return coroutine.wrap(function()
|
||||||
|
if not browse(path) and package.nomsupath then
|
||||||
|
browse(package.nomsupath .. "/" .. path)
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local ret = os.execute('find . -maxdepth 0')
|
||||||
|
if not (ret == true or ret == 0) then
|
||||||
|
error("Could not find 'luafilesystem' module and couldn't run system command `find` (this might happen on Windows). Please install `luafilesystem` (which can be found at: http://keplerproject.github.io/luafilesystem/ or `luarocks install luafilesystem`)", 0)
|
||||||
|
end
|
||||||
|
all_files = function(path)
|
||||||
|
if match(path, "%.nom$") or match(path, "%.lua$") or match(path, "^/dev/fd/[012]$") then
|
||||||
|
return iterate_single, path
|
||||||
|
end
|
||||||
|
path = gsub(path, "\\", "\\\\")
|
||||||
|
path = gsub(path, "`", "")
|
||||||
|
path = gsub(path, '"', '\\"')
|
||||||
|
path = gsub(path, "$", "")
|
||||||
|
return coroutine.wrap(function()
|
||||||
|
local f = io.popen('find -L "' .. path .. '" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||||
|
local found = false
|
||||||
|
for line in f:lines() do
|
||||||
|
found = true
|
||||||
|
coroutine.yield(line)
|
||||||
|
end
|
||||||
|
if not found and package.nomsupath then
|
||||||
|
f:close()
|
||||||
|
f = io.popen('find -L "' .. package.nomsupath .. '/' .. path .. '" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||||
|
for line in f:lines() do
|
||||||
|
coroutine.yield(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local success = f:close()
|
||||||
|
if not (success) then
|
||||||
|
return error("Invalid file path: " .. tostring(path))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
local run
|
local run
|
||||||
run = function()
|
run = function()
|
||||||
for i, input in ipairs(args.inputs) do
|
for i, input in ipairs(args.inputs) do
|
||||||
@ -120,7 +218,8 @@ run = function()
|
|||||||
local filename = input_files[_index_0]
|
local filename = input_files[_index_0]
|
||||||
if args.syntax then
|
if args.syntax then
|
||||||
local file_contents = io.open(filename):read('*a')
|
local file_contents = io.open(filename):read('*a')
|
||||||
local ok, err = pcall(nomsu.parse, nomsu, file_contents, Source(filename, 1, #file_contents))
|
local err
|
||||||
|
ok, err = pcall(nomsu.parse, nomsu, file_contents, Source(filename, 1, #file_contents))
|
||||||
if not ok then
|
if not ok then
|
||||||
table.insert(parse_errs, err)
|
table.insert(parse_errs, err)
|
||||||
elseif print_file then
|
elseif print_file then
|
||||||
@ -149,9 +248,9 @@ run = function()
|
|||||||
if #parse_errs > 0 then
|
if #parse_errs > 0 then
|
||||||
io.stderr:write(table.concat(parse_errs, "\n\n"))
|
io.stderr:write(table.concat(parse_errs, "\n\n"))
|
||||||
io.stderr:flush()
|
io.stderr:flush()
|
||||||
os.exit(false, true)
|
os.exit(EXIT_FAILURE)
|
||||||
elseif args.syntax then
|
elseif args.syntax then
|
||||||
os.exit(true, true)
|
os.exit(EXIT_SUCCESS)
|
||||||
end
|
end
|
||||||
if args.interactive then
|
if args.interactive then
|
||||||
for repl_line = 1, math.huge do
|
for repl_line = 1, math.huge do
|
||||||
@ -179,7 +278,8 @@ run = function()
|
|||||||
err_hand = function(error_message)
|
err_hand = function(error_message)
|
||||||
return Errhand.print_error(error_message)
|
return Errhand.print_error(error_message)
|
||||||
end
|
end
|
||||||
local ok, ret = xpcall(nomsu.run, err_hand, nomsu, buff, Source(pseudo_filename, 1, #buff))
|
local ret
|
||||||
|
ok, ret = xpcall(nomsu.run, err_hand, nomsu, buff, Source(pseudo_filename, 1, #buff))
|
||||||
if ok and ret ~= nil then
|
if ok and ret ~= nil then
|
||||||
print("= " .. repr(ret))
|
print("= " .. repr(ret))
|
||||||
elseif not ok then
|
elseif not ok then
|
||||||
|
83
nomsu.moon
83
nomsu.moon
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env moon
|
#!/usr/bin/env moon
|
||||||
-- This file contains the command-line Nomsu runner.
|
-- This file contains the command-line Nomsu runner.
|
||||||
|
EXIT_SUCCESS, EXIT_FAILURE = 0, 1
|
||||||
usage = [=[
|
usage = [=[
|
||||||
Nomsu Compiler
|
Nomsu Compiler
|
||||||
|
|
||||||
@ -17,8 +18,13 @@ OPTIONS
|
|||||||
<input> Input file can be "-" to use stdin.
|
<input> Input file can be "-" to use stdin.
|
||||||
]=]
|
]=]
|
||||||
|
|
||||||
lpeg = require 'lpeg'
|
ok, _ = pcall ->
|
||||||
re = require 're'
|
export lpeg, re
|
||||||
|
lpeg = require 'lpeg'
|
||||||
|
re = require 're'
|
||||||
|
if not ok
|
||||||
|
print("Error: unable to find the 'lpeg' Lua module. Please install LPEG either from http://www.inf.puc-rio.br/~roberto/lpeg/re.html or, if you use luarocks: `luarocks install lpeg`")
|
||||||
|
os.exit(EXIT_FAILURE)
|
||||||
Errhand = require "error_handling"
|
Errhand = require "error_handling"
|
||||||
NomsuCompiler = require "nomsu_compiler"
|
NomsuCompiler = require "nomsu_compiler"
|
||||||
{:NomsuCode, :LuaCode, :Source} = require "code_obj"
|
{:NomsuCode, :LuaCode, :Source} = require "code_obj"
|
||||||
@ -45,11 +51,78 @@ args = table.concat(arg, ";")..";"
|
|||||||
args = parser\match(args)
|
args = parser\match(args)
|
||||||
if not args or args.help
|
if not args or args.help
|
||||||
print usage
|
print usage
|
||||||
os.exit!
|
os.exit(EXIT_FAILURE)
|
||||||
|
|
||||||
nomsu = NomsuCompiler
|
nomsu = NomsuCompiler
|
||||||
nomsu.arg = args.nomsu_args
|
nomsu.arg = args.nomsu_args
|
||||||
|
|
||||||
|
export FILE_CACHE
|
||||||
|
-- FILE_CACHE is a map from filename (string) -> string of file contents
|
||||||
|
FILE_CACHE = setmetatable {}, {
|
||||||
|
__index: (filename)=>
|
||||||
|
file = io.open(filename)
|
||||||
|
return nil unless file
|
||||||
|
contents = file\read("*a")
|
||||||
|
file\close!
|
||||||
|
self[filename] = contents
|
||||||
|
return contents
|
||||||
|
}
|
||||||
|
|
||||||
|
export all_files
|
||||||
|
{:match, :sub, :rep, :gsub, :format, :byte, :match, :find} = string
|
||||||
|
iterate_single = (item, prev) -> if item == prev then nil else item
|
||||||
|
ok, lfs = pcall(require, "lfs")
|
||||||
|
if ok
|
||||||
|
all_files = (path)->
|
||||||
|
browse = (filename)->
|
||||||
|
file_type = 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'
|
||||||
|
for subfile in lfs.dir(filename)
|
||||||
|
unless subfile == "." or subfile == ".."
|
||||||
|
browse(filename.."/"..subfile)
|
||||||
|
return true
|
||||||
|
elseif file_type == 'char device'
|
||||||
|
coroutine.yield(filename)
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
return coroutine.wrap ->
|
||||||
|
if not browse(path) and package.nomsupath
|
||||||
|
browse(package.nomsupath.."/"..path)
|
||||||
|
return nil
|
||||||
|
else
|
||||||
|
ret = os.execute('find . -maxdepth 0')
|
||||||
|
unless ret == true or ret == 0
|
||||||
|
error "Could not find 'luafilesystem' module and couldn't run system command `find` (this might happen on Windows). Please install `luafilesystem` (which can be found at: http://keplerproject.github.io/luafilesystem/ or `luarocks install luafilesystem`)", 0
|
||||||
|
|
||||||
|
all_files = (path)->
|
||||||
|
-- Sanitize path
|
||||||
|
if match(path, "%.nom$") or match(path, "%.lua$") or match(path, "^/dev/fd/[012]$")
|
||||||
|
return iterate_single, path
|
||||||
|
-- TODO: improve sanitization
|
||||||
|
path = gsub(path,"\\","\\\\")
|
||||||
|
path = gsub(path,"`","")
|
||||||
|
path = gsub(path,'"','\\"')
|
||||||
|
path = gsub(path,"$","")
|
||||||
|
return coroutine.wrap ->
|
||||||
|
f = io.popen('find -L "'..path..'" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||||
|
found = false
|
||||||
|
for line in f\lines!
|
||||||
|
found = true
|
||||||
|
coroutine.yield(line)
|
||||||
|
if not found and package.nomsupath
|
||||||
|
f\close!
|
||||||
|
f = io.popen('find -L "'..package.nomsupath..'/'..path..'" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||||
|
for line in f\lines!
|
||||||
|
coroutine.yield(line)
|
||||||
|
success = f\close!
|
||||||
|
unless success
|
||||||
|
error("Invalid file path: "..tostring(path))
|
||||||
|
|
||||||
|
|
||||||
run = ->
|
run = ->
|
||||||
for i,input in ipairs args.inputs
|
for i,input in ipairs args.inputs
|
||||||
if input == "-" then args.inputs[i] = STDIN
|
if input == "-" then args.inputs[i] = STDIN
|
||||||
@ -126,9 +199,9 @@ run = ->
|
|||||||
if #parse_errs > 0
|
if #parse_errs > 0
|
||||||
io.stderr\write table.concat(parse_errs, "\n\n")
|
io.stderr\write table.concat(parse_errs, "\n\n")
|
||||||
io.stderr\flush!
|
io.stderr\flush!
|
||||||
os.exit(false, true)
|
os.exit(EXIT_FAILURE)
|
||||||
elseif args.syntax
|
elseif args.syntax
|
||||||
os.exit(true, true)
|
os.exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
if args.interactive
|
if args.interactive
|
||||||
-- REPL
|
-- REPL
|
||||||
|
@ -127,7 +127,7 @@ do
|
|||||||
ident <- [a-zA-Z_][a-zA-Z0-9_]*
|
ident <- [a-zA-Z_][a-zA-Z0-9_]*
|
||||||
comment <- "--" [^%nl]*
|
comment <- "--" [^%nl]*
|
||||||
]])
|
]])
|
||||||
local nomsu_peg = peg_tidier:match(io.open("nomsu.peg"):read('*a'))
|
local nomsu_peg = peg_tidier:match(io.open((package.nomsupath or '.') .. "/nomsu.peg"):read('*a'))
|
||||||
NOMSU_PATTERN = re.compile(nomsu_peg, NOMSU_DEFS)
|
NOMSU_PATTERN = re.compile(nomsu_peg, NOMSU_DEFS)
|
||||||
end
|
end
|
||||||
local parse
|
local parse
|
||||||
@ -162,8 +162,7 @@ parse = function(nomsu_code, source)
|
|||||||
end
|
end
|
||||||
errors = _accum_0
|
errors = _accum_0
|
||||||
end
|
end
|
||||||
io.stderr:write("Errors occurred while parsing:\n\n", table.concat(errors, "\n\n"), '\n')
|
error("Errors occurred while parsing:\n\n" .. table.concat(errors, "\n\n"), 0)
|
||||||
os.exit(1)
|
|
||||||
end
|
end
|
||||||
return tree
|
return tree
|
||||||
end
|
end
|
||||||
|
@ -98,7 +98,7 @@ NOMSU_PATTERN = do
|
|||||||
ident <- [a-zA-Z_][a-zA-Z0-9_]*
|
ident <- [a-zA-Z_][a-zA-Z0-9_]*
|
||||||
comment <- "--" [^%nl]*
|
comment <- "--" [^%nl]*
|
||||||
]]
|
]]
|
||||||
nomsu_peg = peg_tidier\match(io.open("nomsu.peg")\read('*a'))
|
nomsu_peg = peg_tidier\match(io.open((package.nomsupath or '.').."/nomsu.peg")\read('*a'))
|
||||||
re.compile(nomsu_peg, NOMSU_DEFS)
|
re.compile(nomsu_peg, NOMSU_DEFS)
|
||||||
|
|
||||||
parse = (nomsu_code, source=nil)->
|
parse = (nomsu_code, source=nil)->
|
||||||
@ -116,8 +116,7 @@ parse = (nomsu_code, source=nil)->
|
|||||||
keys = utils.keys(userdata.errors)
|
keys = utils.keys(userdata.errors)
|
||||||
table.sort(keys)
|
table.sort(keys)
|
||||||
errors = [userdata.errors[k] for k in *keys]
|
errors = [userdata.errors[k] for k in *keys]
|
||||||
io.stderr\write("Errors occurred while parsing:\n\n", table.concat(errors, "\n\n"), '\n')
|
error("Errors occurred while parsing:\n\n"..table.concat(errors, "\n\n"), 0)
|
||||||
os.exit(1)
|
|
||||||
|
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ with local %x
|
|||||||
assume: %x = "outer"
|
assume: %x = "outer"
|
||||||
|
|
||||||
action [foo] "outer foo"
|
action [foo] "outer foo"
|
||||||
with local (foo)
|
with local [action: foo]
|
||||||
action [foo] "inner foo"
|
action [foo] "inner foo"
|
||||||
assume: (foo) = "inner foo"
|
assume: (foo) = "inner foo"
|
||||||
assume: (foo) = "outer foo"
|
assume: (foo) = "outer foo"
|
||||||
|
Loading…
Reference in New Issue
Block a user