aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-03-04 14:30:38 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-03-04 14:30:44 -0800
commit58707b18f7d0e1c7526d7c6d39110b52d25a9e4f (patch)
tree403f0ebd313fd18a3e1d484f6e5efe8d65faff83
parentde1f80fe51ea3a760966a304500de75325e1b70b (diff)
Fixed a shebang issue
-rw-r--r--nomsu_environment.lua15
-rw-r--r--nomsu_environment.moon12
2 files changed, 25 insertions, 2 deletions
diff --git a/nomsu_environment.lua b/nomsu_environment.lua
index 08993ea..08face7 100644
--- a/nomsu_environment.lua
+++ b/nomsu_environment.lua
@@ -170,7 +170,18 @@ nomsu_environment = Importer({
assert(parse, "No parser found for Nomsu syntax version " .. tostring(syntax_version))
local tree = parse(nomsu_code, source.filename)
if tree.shebang then
- tree.version = tree.version or tree.shebang:match("nomsu %-V[ ]*([%d.]*)")
+ local shebang_version = tree.shebang:match("nomsu %-V[ ]*([%d.]+)")
+ if shebang_version and shebang_version ~= "" then
+ tree.version = tree.version or List((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ for v in shebang_version:gmatch("%d+") do
+ _accum_0[_len_0] = tonumber(v)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())
+ end
end
return tree
end,
@@ -288,6 +299,7 @@ nomsu_environment = Importer({
return self:run(tree)
elseif SyntaxTree:is_instance(to_run) then
local filename = to_run.source.filename:gsub("\n.*", "...")
+ local version = to_run.version
if to_run.type ~= "FileChunks" then
to_run = {
to_run
@@ -295,6 +307,7 @@ nomsu_environment = Importer({
end
local ret = nil
for chunk_no, chunk in ipairs(to_run) do
+ chunk.version = version
local lua = self:compile(chunk)
lua:declare_locals()
lua:prepend("-- File: " .. tostring(filename) .. " chunk #" .. tostring(chunk_no) .. "\n")
diff --git a/nomsu_environment.moon b/nomsu_environment.moon
index 7e248c9..7066be1 100644
--- a/nomsu_environment.moon
+++ b/nomsu_environment.moon
@@ -91,7 +91,15 @@ nomsu_environment = Importer{
assert parse, "No parser found for Nomsu syntax version #{syntax_version}"
tree = parse(nomsu_code, source.filename)
if tree.shebang
- tree.version or= tree.shebang\match("nomsu %-V[ ]*([%d.]*)")
+ shebang_version = tree.shebang\match("nomsu %-V[ ]*([%d.]+)")
+ if shebang_version and shebang_version != ""
+ tree.version or= List[tonumber(v) for v in shebang_version\gmatch("%d+")]
+ --if tree.version and tree.version < NOMSU_VERSION\up_to(#tree.version) and not package.nomsuloaded["compatibility"]
+ -- export loading_compat
+ -- unless loading_compat
+ -- loading_compat = true
+ -- nomsu_environment\export "compatibility"
+ -- loading_compat = false
return tree
Module: (package_name)=>
@@ -184,6 +192,7 @@ nomsu_environment = Importer{
return @run(tree)
elseif SyntaxTree\is_instance(to_run)
filename = to_run.source.filename\gsub("\n.*", "...")
+ version = to_run.version
if to_run.type != "FileChunks"
to_run = {to_run}
-- Each chunk's compilation is affected by the code in the previous chunks
@@ -191,6 +200,7 @@ nomsu_environment = Importer{
-- compiles.
ret = nil
for chunk_no, chunk in ipairs to_run
+ chunk.version = version
lua = @compile(chunk)
lua\declare_locals!
lua\prepend "-- File: #{filename} chunk ##{chunk_no}\n"