diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-07 21:39:23 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-07 21:40:01 -0800 |
| commit | 80167c9df2d48fff0860034cc05cc9125be190f8 (patch) | |
| tree | da3d4d516f017a27ed52b97e1615997f98bfce44 /nomsu_decompiler.lua | |
| parent | 5f961d32c4fa9ca4f73da24ea3b73bba8c872c85 (diff) | |
Fix for no-arg functioncalls of expressions (e.g. $fn()), and line
wrapping of list/dicts.
Diffstat (limited to 'nomsu_decompiler.lua')
| -rw-r--r-- | nomsu_decompiler.lua | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua index 02f2426..472be27 100644 --- a/nomsu_decompiler.lua +++ b/nomsu_decompiler.lua @@ -49,9 +49,10 @@ tree_to_inline_nomsu = function(tree) local _exp_0 = tree.type if "Action" == _exp_0 then local nomsu = NomsuCode:from(tree.source) - local num_args = 0 + local num_args, num_words = 0, 0 for i, bit in ipairs(tree) do if type(bit) == "string" then + num_words = num_words + 1 local clump_words if type(tree[i - 1]) == 'string' then clump_words = is_operator(bit) ~= is_operator(tree[i - 1]) @@ -83,6 +84,9 @@ tree_to_inline_nomsu = function(tree) nomsu:add(arg_nomsu) end end + if num_args == 1 and num_words == 0 then + nomsu:append("()") + end return nomsu elseif "MethodCall" == _exp_0 then local target_nomsu = tree_to_inline_nomsu(tree[1]) @@ -355,11 +359,12 @@ tree_to_nomsu = function(tree) elseif "Action" == _exp_0 then local next_space = "" local word_buffer = { } - local num_args = 0 + local num_args, num_words = 0, 0 for i, bit in ipairs(tree) do local _continue_0 = false repeat if type(bit) == "string" then + num_words = num_words + 1 if #word_buffer > 0 and is_operator(bit) == is_operator(word_buffer[#word_buffer]) then table.insert(word_buffer, " ") end @@ -425,6 +430,12 @@ tree_to_nomsu = function(tree) nomsu:add(next_space, words) next_space = " " end + if num_args == 1 and num_words == 0 then + if next_space ~= " " then + nomsu:append(next_space) + end + nomsu:append("()") + end return nomsu elseif "MethodCall" == _exp_0 then local target_nomsu = recurse(tree[1]) @@ -575,7 +586,7 @@ tree_to_nomsu = function(tree) end else item_nomsu = tree_to_inline_nomsu(item) - if #item_nomsu:text() > MAX_LINE then + if nomsu:trailing_line_len() + #item_nomsu:text() > MAX_LINE then if i > 1 then sep = '\n' end |
