aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nomsu_decompiler.lua6
-rw-r--r--nomsu_decompiler.moon8
2 files changed, 8 insertions, 6 deletions
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index c82bd39..cd35019 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -515,7 +515,7 @@ tree_to_nomsu = function(tree)
nomsu:add("\n")
if tree[i - 1].type ~= "Comment" then
needs_space[i] = (line_nomsu:is_multiline() and prev_line:is_multiline())
- if tree[i].type == "Comment" or needs_space[i] or needs_space[i - 1] then
+ if (tree[i].type == "Comment" or needs_space[i] or needs_space[i - 1] or prev_line:text():match("\n [^\n]*$")) then
nomsu:add("\n")
end
end
@@ -654,9 +654,9 @@ tree_to_nomsu = function(tree)
end
nomsu:add(sep)
if sep == '\n' then
- if tree[i - 1].type ~= "Comment" then
+ if i > 1 and tree[i - 1].type ~= "Comment" then
needs_space[i] = (item_nomsu:is_multiline() and prev_item:is_multiline())
- if tree[i].type == "Comment" or needs_space[i] or needs_space[i - 1] then
+ if (tree[i].type == "Comment" or needs_space[i] or needs_space[i - 1] or prev_item:text():match("\n [^\n]*$")) then
nomsu:add("\n")
end
end
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index e28c403..aff9433 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -393,7 +393,8 @@ tree_to_nomsu = (tree)->
-- or if the last line starts with ".."
if tree[i-1].type != "Comment"
needs_space[i] = (line_nomsu\is_multiline! and prev_line\is_multiline!)
- if tree[i].type == "Comment" or needs_space[i] or needs_space[i-1]
+ if (tree[i].type == "Comment" or needs_space[i] or needs_space[i-1] or
+ prev_line\text!\match("\n [^\n]*$"))
nomsu\add "\n"
nomsu\add line_nomsu
prev_line = line_nomsu
@@ -503,9 +504,10 @@ tree_to_nomsu = (tree)->
-- Rule of thumb: add a blank line between two lines if both are
-- multi-line non-comments, or if a comment comes after a non-comment,
-- or if the last line starts with ".."
- if tree[i-1].type != "Comment"
+ if i > 1 and tree[i-1].type != "Comment"
needs_space[i] = (item_nomsu\is_multiline! and prev_item\is_multiline!)
- if tree[i].type == "Comment" or needs_space[i] or needs_space[i-1]
+ if (tree[i].type == "Comment" or needs_space[i] or needs_space[i-1] or
+ prev_item\text!\match("\n [^\n]*$"))
nomsu\add "\n"
nomsu\add item_nomsu
prev_item = item_nomsu