aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-31 01:36:48 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-31 01:37:21 -0800
commit7762c8c45b6f0349d769682b26349fb25a7a8657 (patch)
treefdcac310b37753312bb9cc010db67d92c854810d
parentd8f9b15fd9da8c9ae29ee0b63c4302e5efbde387 (diff)
Added the ": for $ in $: ..." shorthand for indented comprehensions.
-rw-r--r--nomsu_decompiler.lua8
-rw-r--r--nomsu_decompiler.moon8
2 files changed, 14 insertions, 2 deletions
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index e17f25e..1918ac2 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -562,6 +562,12 @@ tree_to_nomsu = function(tree)
if i > 1 then
sep = '\n'
end
+ elseif item.type == 'Block' and #item == 1 then
+ item_nomsu = tree_to_nomsu(item[1])
+ item_nomsu:prepend(": ")
+ if i > 1 then
+ sep = '\n'
+ end
else
item_nomsu = tree_to_inline_nomsu(item)
if #item_nomsu:text() > MAX_LINE then
@@ -573,7 +579,7 @@ tree_to_nomsu = function(tree)
end
nomsu:add(sep)
nomsu:add(item_nomsu)
- if item_nomsu:is_multiline() or item.type == 'Comment' or nomsu:trailing_line_len() + #tostring(item_nomsu) >= MAX_LINE then
+ if item_nomsu:is_multiline() or item.type == 'Comment' or item.type == "Block" or nomsu:trailing_line_len() + #tostring(item_nomsu) >= MAX_LINE then
sep = '\n'
else
sep = ', '
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index 3c20f76..3deaabc 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -427,6 +427,11 @@ tree_to_nomsu = (tree)->
elseif item.type == 'Comment'
item_nomsu = tree_to_nomsu(item)
sep = '\n' if i > 1
+ elseif item.type == 'Block' and #item == 1
+ -- Comprehensions use the more concise ": for $ in $: ..." form
+ item_nomsu = tree_to_nomsu(item[1])
+ item_nomsu\prepend ": "
+ sep = '\n' if i > 1
else
item_nomsu = tree_to_inline_nomsu(item)
if #item_nomsu\text! > MAX_LINE
@@ -434,7 +439,8 @@ tree_to_nomsu = (tree)->
item_nomsu = tree_to_nomsu(item)
nomsu\add sep
nomsu\add item_nomsu
- if item_nomsu\is_multiline! or item.type == 'Comment' or nomsu\trailing_line_len! + #tostring(item_nomsu) >= MAX_LINE
+ if item_nomsu\is_multiline! or item.type == 'Comment' or item.type == "Block" or
+ nomsu\trailing_line_len! + #tostring(item_nomsu) >= MAX_LINE
sep = '\n'
else
sep = ', '