aboutsummaryrefslogtreecommitdiff
path: root/nomsu_decompiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-07 21:39:23 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-07 21:40:01 -0800
commit80167c9df2d48fff0860034cc05cc9125be190f8 (patch)
treeda3d4d516f017a27ed52b97e1615997f98bfce44 /nomsu_decompiler.moon
parent5f961d32c4fa9ca4f73da24ea3b73bba8c872c85 (diff)
Fix for no-arg functioncalls of expressions (e.g. $fn()), and line
wrapping of list/dicts.
Diffstat (limited to 'nomsu_decompiler.moon')
-rw-r--r--nomsu_decompiler.moon14
1 files changed, 11 insertions, 3 deletions
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index bc5c986..03e9956 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -33,9 +33,10 @@ tree_to_inline_nomsu = (tree)->
switch tree.type
when "Action"
nomsu = NomsuCode\from(tree.source)
- num_args = 0
+ num_args, num_words = 0, 0
for i,bit in ipairs tree
if type(bit) == "string"
+ num_words += 1
clump_words = if type(tree[i-1]) == 'string'
is_operator(bit) != is_operator(tree[i-1])
else bit == "'"
@@ -54,6 +55,8 @@ tree_to_inline_nomsu = (tree)->
if bit.type == "Action" or bit.type == "MethodCall"
arg_nomsu\parenthesize!
nomsu\add arg_nomsu
+ if num_args == 1 and num_words == 0
+ nomsu\append "()"
return nomsu
when "MethodCall"
@@ -253,10 +256,11 @@ tree_to_nomsu = (tree)->
when "Action"
next_space = ""
word_buffer = {}
- num_args = 0
+ num_args, num_words = 0, 0
for i,bit in ipairs tree
-- TODO: properly wrap super long chains of words
if type(bit) == "string"
+ num_words += 1
if #word_buffer > 0 and is_operator(bit) == is_operator(word_buffer[#word_buffer])
table.insert word_buffer, " "
table.insert word_buffer, bit
@@ -314,6 +318,10 @@ tree_to_nomsu = (tree)->
nomsu\add next_space, words
next_space = " "
+ if num_args == 1 and num_words == 0
+ if next_space != " "
+ nomsu\append next_space
+ nomsu\append "()"
return nomsu
when "MethodCall"
@@ -439,7 +447,7 @@ tree_to_nomsu = (tree)->
sep = '\n' if i > 1
else
item_nomsu = tree_to_inline_nomsu(item)
- if #item_nomsu\text! > MAX_LINE
+ if nomsu\trailing_line_len! + #item_nomsu\text! > MAX_LINE
sep = '\n' if i > 1
item_nomsu = tree_to_nomsu(item)
nomsu\add sep