aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu_decompiler.lua12
-rw-r--r--nomsu_decompiler.moon11
2 files changed, 13 insertions, 10 deletions
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index 77905e5..b1e02f7 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -265,7 +265,7 @@ tree_to_nomsu = function(tree)
local next_space = ""
if tree.target then
local target_nomsu = recurse(tree.target)
- if (tree.target.type == "Block" or tree.target.type == "EscapedNomsu") and not target_nomsu:is_multiline() then
+ if tree.target.type == "Block" and not target_nomsu:is_multiline() then
target_nomsu:parenthesize()
end
nomsu:append(target_nomsu)
@@ -280,7 +280,7 @@ tree_to_nomsu = function(tree)
next_space = nomsu:trailing_line_len() > MAX_LINE and " \\\n.." or " "
else
local bit_nomsu = recurse(bit)
- if i < #tree and (bit.type == "Block" or bit.type == "EscapedNomsu") and not bit_nomsu:is_multiline() then
+ if i < #tree and bit.type == "Block" and not bit_nomsu:is_multiline() then
bit_nomsu:parenthesize()
end
if next_space == " " and not bit_nomsu:is_multiline() and nomsu:trailing_line_len() + #bit_nomsu:text() > MAX_LINE then
@@ -295,7 +295,11 @@ tree_to_nomsu = function(tree)
end
return nomsu
elseif "EscapedNomsu" == _exp_0 then
- return NomsuCode(tree.source, "\\", recurse(tree[1]))
+ nomsu = recurse(tree[1])
+ if tree[1].type == 'Block' and not nomsu:is_multiline() then
+ nomsu:parenthesize()
+ end
+ return NomsuCode(tree.source, "\\", nomsu)
elseif "Block" == _exp_0 then
for i, line in ipairs(tree) do
local line_nomsu = tree_to_nomsu(line)
@@ -367,8 +371,6 @@ tree_to_nomsu = function(tree)
local item_nomsu = tree_to_inline_nomsu(item)
if #item_nomsu:text() > MAX_LINE then
item_nomsu = recurse(item)
- elseif item.type == "Block" or item.type == "EscapedNomsu" then
- item_nomsu:parenthesize()
end
nomsu:append(item_nomsu)
if i < #tree then
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index 1de60ca..75eae6d 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -198,7 +198,7 @@ tree_to_nomsu = (tree)->
next_space = ""
if tree.target
target_nomsu = recurse(tree.target)
- if (tree.target.type == "Block" or tree.target.type == "EscapedNomsu") and not target_nomsu\is_multiline!
+ if tree.target.type == "Block" and not target_nomsu\is_multiline!
target_nomsu\parenthesize!
nomsu\append target_nomsu
nomsu\append(target_nomsu\is_multiline! and "\n..::" or "::")
@@ -211,7 +211,7 @@ tree_to_nomsu = (tree)->
next_space = nomsu\trailing_line_len! > MAX_LINE and " \\\n.." or " "
else
bit_nomsu = recurse(bit)
- if i < #tree and (bit.type == "Block" or bit.type == "EscapedNomsu") and not bit_nomsu\is_multiline!
+ if i < #tree and bit.type == "Block" and not bit_nomsu\is_multiline!
bit_nomsu\parenthesize!
if next_space == " " and not bit_nomsu\is_multiline! and nomsu\trailing_line_len! + #bit_nomsu\text! > MAX_LINE
@@ -225,7 +225,10 @@ tree_to_nomsu = (tree)->
return nomsu
when "EscapedNomsu"
- return NomsuCode tree.source, "\\", recurse(tree[1])
+ nomsu = recurse(tree[1])
+ if tree[1].type == 'Block' and not nomsu\is_multiline!
+ nomsu\parenthesize!
+ return NomsuCode tree.source, "\\", nomsu
when "Block"
for i, line in ipairs tree
@@ -284,8 +287,6 @@ tree_to_nomsu = (tree)->
item_nomsu = tree_to_inline_nomsu(item)
if #item_nomsu\text! > MAX_LINE
item_nomsu = recurse(item)
- elseif item.type == "Block" or item.type == "EscapedNomsu"
- item_nomsu\parenthesize!
nomsu\append item_nomsu
if i < #tree
nomsu\append((item_nomsu\is_multiline! or nomsu\trailing_line_len! + #tostring(item_nomsu) >= MAX_LINE) and '\n' or ', ')