Made repr fix more flexible/correct.
This commit is contained in:
parent
ed0b5a3373
commit
13490a34c8
50
nomsu.lua
50
nomsu.lua
@ -360,19 +360,13 @@ do
|
|||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
local statement = _list_0[_index_0]
|
local statement = _list_0[_index_0]
|
||||||
local code = to_lua(statement, "Statement")
|
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
|
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)))
|
error("Failed to compile generated code:\n" .. tostring(code) .. "\n\n" .. tostring(err) .. "\n\nProduced by statement:\n" .. tostring(utils.repr(statement)))
|
||||||
end
|
end
|
||||||
local ok, value = pcall(lua_thunk)
|
local value = lua_thunk()
|
||||||
if not ok then
|
return_value = value(self, vars)
|
||||||
error(value)
|
|
||||||
end
|
|
||||||
ok, value = pcall(value, self, vars)
|
|
||||||
if not ok then
|
|
||||||
error()
|
|
||||||
end
|
|
||||||
return_value = value
|
|
||||||
add(code)
|
add(code)
|
||||||
end
|
end
|
||||||
add([[ return ret
|
add([[ return ret
|
||||||
@ -672,6 +666,7 @@ do
|
|||||||
return code, retval
|
return code, retval
|
||||||
end,
|
end,
|
||||||
error = function(self, ...)
|
error = function(self, ...)
|
||||||
|
print("ERROR!")
|
||||||
print(...)
|
print(...)
|
||||||
print("Callstack:")
|
print("Callstack:")
|
||||||
for i = #self.callstack, 1, -1 do
|
for i = #self.callstack, 1, -1 do
|
||||||
@ -717,42 +712,11 @@ do
|
|||||||
if kind == "Expression" then
|
if kind == "Expression" then
|
||||||
error("Expected to be in statement.")
|
error("Expected to be in statement.")
|
||||||
end
|
end
|
||||||
local lua_code = vars.lua_code.value
|
return self:tree_to_value(vars.lua_code, vars), true
|
||||||
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
|
|
||||||
end)
|
end)
|
||||||
self:defmacro([[lua expr %lua_code]], function(self, vars, kind)
|
self:defmacro([[lua expr %lua_code]], function(self, vars, kind)
|
||||||
local lua_code = vars.lua_code.value
|
local lua_code = vars.lua_code.value
|
||||||
local _exp_0 = lua_code.type
|
return self:tree_to_value(vars.lua_code, vars)
|
||||||
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
|
|
||||||
end)
|
end)
|
||||||
self:def("rule %spec %body", function(self, vars)
|
self:def("rule %spec %body", function(self, vars)
|
||||||
return self:def(vars.spec, vars.body)
|
return self:def(vars.spec, vars.body)
|
||||||
|
@ -48,7 +48,7 @@ utils = {
|
|||||||
else
|
else
|
||||||
for i = 0, math.huge do
|
for i = 0, math.huge do
|
||||||
local eq = ("="):rep(i)
|
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
|
if x:sub(1, 1) == "\n" then
|
||||||
return "[" .. tostring(eq) .. "[\n" .. x .. "]" .. tostring(eq) .. "]"
|
return "[" .. tostring(eq) .. "[\n" .. x .. "]" .. tostring(eq) .. "]"
|
||||||
else
|
else
|
||||||
|
@ -22,9 +22,9 @@ utils = {
|
|||||||
elseif not x\find[[']] and not x\find"\n"
|
elseif not x\find[[']] and not x\find"\n"
|
||||||
"\'"..x.."\'"
|
"\'"..x.."\'"
|
||||||
else
|
else
|
||||||
for i=1,math.huge
|
for i=0,math.huge
|
||||||
eq = ("=")\rep(i)
|
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
|
-- Stupid bullshit add an extra newline because lua discards first one if it exists
|
||||||
if x\sub(1,1) == "\n"
|
if x\sub(1,1) == "\n"
|
||||||
return "[#{eq}[\n"..x.."]#{eq}]"
|
return "[#{eq}[\n"..x.."]#{eq}]"
|
||||||
|
Loading…
Reference in New Issue
Block a user