diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-09-26 13:58:29 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-09-26 13:59:31 -0700 |
| commit | 8a8940c9bcacfd8bcb6c724a383c75615acd3af8 (patch) | |
| tree | efbbe21e1c520b3c15a46a61ce66392a7b68389e /nomsu_compiler.lua | |
| parent | dcff9ecfcf0c3f81cc22bacd082472ea744c9070 (diff) | |
Fixes for actions with targets colliding with compiler actions, and lua
keywords as dict keys.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 870be9a..ff923ab 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -687,38 +687,36 @@ do local _exp_0 = tree.type if "Action" == _exp_0 then local stub = tree.stub - do - local compile_action = compile_actions[stub] - if compile_action then - local args - do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #tree do - local arg = tree[_index_0] - if type(arg) ~= "string" then - _accum_0[_len_0] = arg - _len_0 = _len_0 + 1 - end + local compile_action = compile_actions[stub] + if compile_action and not tree.target then + local args + do + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #tree do + local arg = tree[_index_0] + if type(arg) ~= "string" then + _accum_0[_len_0] = arg + _len_0 = _len_0 + 1 end - args = _accum_0 end - local ret = compile_action(self, tree, unpack(args)) - if ret == nil then + args = _accum_0 + end + local ret = compile_action(self, tree, unpack(args)) + if ret == nil then + local info = debug.getinfo(compile_action, "S") + local filename = Source:from_string(info.source).filename + self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") failed to return any value.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's returning something.") + end + if AST.is_syntax_tree(ret) then + if ret == tree then local info = debug.getinfo(compile_action, "S") local filename = Source:from_string(info.source).filename - self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") failed to return any value.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's returning something.") - end - if AST.is_syntax_tree(ret) then - if ret == tree then - local info = debug.getinfo(compile_action, "S") - local filename = Source:from_string(info.source).filename - self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") is producing an endless loop.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's not just returning the original tree.") - end - return self:compile(ret, compile_actions) + self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") is producing an endless loop.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's not just returning the original tree.") end - return ret + return self:compile(ret, compile_actions) end + return ret end local lua = LuaCode.Value(tree.source) if tree.target then @@ -929,7 +927,7 @@ do self:compile_error(tree[2], "Can't use this as a dict value, since it's not an expression.") end local key_str = match(tostring(key_lua), [=[^["']([a-zA-Z_][a-zA-Z0-9_]*)['"]$]=]) - if key_str then + if key_str and key_str:is_lua_id() then return LuaCode(tree.source, key_str, "=", value_lua) elseif sub(tostring(key_lua), 1, 1) == "[" then return LuaCode(tree.source, "[ ", key_lua, "]=", value_lua) @@ -952,15 +950,13 @@ do self:compile_error(key, "Can't use this as an index, since it's not an expression.") end local key_lua_str = tostring(key_lua) - do - local lua_id = match(key_lua_str, "^['\"]([a-zA-Z_][a-zA-Z0-9_]*)['\"]$") - if lua_id then - lua:append("." .. tostring(lua_id)) - elseif sub(key_lua_str, 1, 1) == '[' then - lua:append("[ ", key_lua, " ]") - else - lua:append("[", key_lua, "]") - end + local lua_id = match(key_lua_str, "^['\"]([a-zA-Z_][a-zA-Z0-9_]*)['\"]$") + if lua_id and lua_id:is_lua_id() then + lua:append("." .. tostring(lua_id)) + elseif sub(key_lua_str, 1, 1) == '[' then + lua:append("[ ", key_lua, " ]") + else + lua:append("[", key_lua, "]") end end return lua |
