aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-09-14 19:45:36 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-09-14 19:45:36 -0700
commit13490a34c872f5cde6b2f094d9dda045dec066d4 (patch)
tree45891326f4067518359af245cf63a6681f50c033
parented0b5a3373add330b60b1850b8212eba681b031d (diff)
Made repr fix more flexible/correct.
-rw-r--r--nomsu.lua50
-rw-r--r--utils.lua2
-rw-r--r--utils.moon4
3 files changed, 10 insertions, 46 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 4329320..3a49af6 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -360,19 +360,13 @@ do
for _index_0 = 1, #_list_0 do
local statement = _list_0[_index_0]
local code = to_lua(statement, "Statement")
- local lua_thunk, err = load("\n local utils = require('utils')\n return (function(compiler, vars)\n" .. tostring(code) .. "\nend)")
+ local lua_code = "\n local utils = require('utils')\n return (function(compiler, vars)\n" .. tostring(code) .. "\nend)"
+ local lua_thunk, err = load(lua_code)
if not lua_thunk then
error("Failed to compile generated code:\n" .. tostring(code) .. "\n\n" .. tostring(err) .. "\n\nProduced by statement:\n" .. tostring(utils.repr(statement)))
end
- local ok, value = pcall(lua_thunk)
- if not ok then
- error(value)
- end
- ok, value = pcall(value, self, vars)
- if not ok then
- error()
- end
- return_value = value
+ local value = lua_thunk()
+ return_value = value(self, vars)
add(code)
end
add([[ return ret
@@ -672,6 +666,7 @@ do
return code, retval
end,
error = function(self, ...)
+ print("ERROR!")
print(...)
print("Callstack:")
for i = #self.callstack, 1, -1 do
@@ -717,42 +712,11 @@ do
if kind == "Expression" then
error("Expected to be in statement.")
end
- local lua_code = vars.lua_code.value
- local _exp_0 = lua_code.type
- if "List" == _exp_0 then
- return table.concat((function()
- local _accum_0 = { }
- local _len_0 = 1
- local _list_0 = lua_code.value
- for _index_0 = 1, #_list_0 do
- local i = _list_0[_index_0]
- _accum_0[_len_0] = as_lua_code(self, i.value, vars)
- _len_0 = _len_0 + 1
- end
- return _accum_0
- end)()), true
- else
- return as_lua_code(self, lua_code, vars), true
- end
+ return self:tree_to_value(vars.lua_code, vars), true
end)
self:defmacro([[lua expr %lua_code]], function(self, vars, kind)
local lua_code = vars.lua_code.value
- local _exp_0 = lua_code.type
- if "List" == _exp_0 then
- return table.concat((function()
- local _accum_0 = { }
- local _len_0 = 1
- local _list_0 = lua_code.value
- for _index_0 = 1, #_list_0 do
- local i = _list_0[_index_0]
- _accum_0[_len_0] = as_lua_code(self, i.value, vars)
- _len_0 = _len_0 + 1
- end
- return _accum_0
- end)())
- else
- return as_lua_code(self, lua_code, vars)
- end
+ return self:tree_to_value(vars.lua_code, vars)
end)
self:def("rule %spec %body", function(self, vars)
return self:def(vars.spec, vars.body)
diff --git a/utils.lua b/utils.lua
index bb5005d..548ce0d 100644
--- a/utils.lua
+++ b/utils.lua
@@ -48,7 +48,7 @@ utils = {
else
for i = 0, math.huge do
local eq = ("="):rep(i)
- if not x:find("%[" .. tostring(eq) .. "%[") and not x:find("%]" .. tostring(eq) .. "%]") then
+ if not x:find("%]" .. tostring(eq) .. "%]") and not x:match(".*]" .. tostring(eq) .. "$") then
if x:sub(1, 1) == "\n" then
return "[" .. tostring(eq) .. "[\n" .. x .. "]" .. tostring(eq) .. "]"
else
diff --git a/utils.moon b/utils.moon
index 069b1a0..eb222fb 100644
--- a/utils.moon
+++ b/utils.moon
@@ -22,9 +22,9 @@ utils = {
elseif not x\find[[']] and not x\find"\n"
"\'"..x.."\'"
else
- for i=1,math.huge
+ for i=0,math.huge
eq = ("=")\rep(i)
- if not x\find"%[#{eq}%[" and not x\find"%]#{eq}%]"
+ if not x\find"%]#{eq}%]" and not x\match(".*]#{eq}$")
-- Stupid bullshit add an extra newline because lua discards first one if it exists
if x\sub(1,1) == "\n"
return "[#{eq}[\n"..x.."]#{eq}]"