diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-09 19:32:13 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-09 19:32:20 -0800 |
| commit | 771007bc4dbcde1698fd86d87374df21651585a5 (patch) | |
| tree | f97a5bcabb00c5736d5621f8b398fb63f61eb188 | |
| parent | b5a5b7f90d576b0a926e9630a3efb1ebfd5539d7 (diff) | |
Fixed word clumping with linebreaks.
| -rw-r--r-- | nomsu_decompiler.lua | 20 | ||||
| -rw-r--r-- | nomsu_decompiler.moon | 11 |
2 files changed, 17 insertions, 14 deletions
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua index b6cb659..17ac7eb 100644 --- a/nomsu_decompiler.lua +++ b/nomsu_decompiler.lua @@ -281,16 +281,18 @@ tree_to_nomsu = function(tree) end for i, bit in ipairs(tree) do if type(bit) == "string" then - local clump_words - if type(tree[i - 1]) == 'string' then - clump_words = is_operator(bit) ~= is_operator(tree[i - 1]) - else - clump_words = bit == "'" - end - if i > 1 and not clump_words then - nomsu:append(" ") + if next_space == " " then + local clump_words + if type(tree[i - 1]) == 'string' then + clump_words = is_operator(bit) ~= is_operator(tree[i - 1]) + else + clump_words = bit == "'" + end + if clump_words then + next_space = "" + end end - nomsu:append(bit) + nomsu:append(next_space, bit) next_space = nomsu:trailing_line_len() > MAX_LINE and " \\\n.." or " " else local bit_nomsu = recurse(bit) diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon index 69d9d76..474d61f 100644 --- a/nomsu_decompiler.moon +++ b/nomsu_decompiler.moon @@ -209,11 +209,12 @@ tree_to_nomsu = (tree)-> for i,bit in ipairs tree if type(bit) == "string" - clump_words = if type(tree[i-1]) == 'string' - is_operator(bit) != is_operator(tree[i-1]) - else bit == "'" - nomsu\append " " if i > 1 and not clump_words - nomsu\append bit + if next_space == " " + clump_words = if type(tree[i-1]) == 'string' + is_operator(bit) != is_operator(tree[i-1]) + else bit == "'" + next_space = "" if clump_words + nomsu\append next_space, bit next_space = nomsu\trailing_line_len! > MAX_LINE and " \\\n.." or " " else bit_nomsu = recurse(bit) |
