diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 19:23:26 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 19:25:03 -0800 |
| commit | 83a40b7493b19e4b55167784e073e92733344b87 (patch) | |
| tree | 758bc8986c6985fad9aabfab5a713318ef180410 /nomsu_compiler.lua | |
| parent | a7adc8cbff9347606fc9c0e8d00d4af2b6b838f5 (diff) | |
Updating to support multiple method calls.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index d51fc1d..a7c4b9d 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -250,29 +250,32 @@ local compile = setmetatable({ lua:add(")") return lua elseif "MethodCall" == _exp_0 then - local stub = tree[2].stub local lua = LuaCode:from(tree.source) local target_lua = compile(tree[1]) local target_text = target_lua:text() - if target_text:match("^%(.*%)$") or target_text:match("^[_a-zA-Z][_a-zA-Z0-9.]*$") or tree[1].type == "IndexChain" then - lua:add(target_lua, ":") - else - lua:add("(", target_lua, "):") + if not (target_text:match("^%(.*%)$") or target_text:match("^[_a-zA-Z][_a-zA-Z0-9.]*$") or tree[1].type == "IndexChain") then + target_lua:parenthesize() end - assert(tree[2].type == "Action") - lua:add((stub):as_lua_id(), "(") - for i, arg in ipairs(tree[2]:get_args()) do - local arg_lua = compile(arg) - if arg.type == "Block" then - arg_lua = LuaCode:from(arg.source, "(function()\n ", arg_lua, "\nend)()") + for i = 2, #tree do + if i > 2 then + lua:add("\n") end - if i > 1 then - lua:add(",") + lua:add(target_lua, ":") + lua:add((tree[i].stub):as_lua_id(), "(") + for argnum, arg in ipairs(tree[i]:get_args()) do + local arg_lua = compile(arg) + if arg.type == "Block" then + arg_lua = LuaCode:from(arg.source, "(function()\n ", arg_lua, "\nend)()") + end + if lua:trailing_line_len() + #arg_lua:text() > MAX_LINE then + lua:add(argnum > 1 and ",\n " or "\n ") + elseif argnum > 1 then + lua:add(", ") + end + lua:add(arg_lua) end - lua:add(lua:trailing_line_len() + #arg_lua:text() > MAX_LINE and "\n " or " ") - lua:add(arg_lua) + lua:add(")") end - lua:add(")") return lua elseif "EscapedNomsu" == _exp_0 then local lua = LuaCode:from(tree.source, "SyntaxTree{") |
