diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 15:05:41 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 15:06:03 -0700 |
| commit | ab4ebdf1751158391100efb0002f40b1d7f6314c (patch) | |
| tree | be675ed7b35164a24bdae5e8f1d3dd73af98490f /nomsu_compiler.moon | |
| parent | 7c488dd266466f80e55a3f02050f4e4a019d64b5 (diff) | |
Changed autoformatting rules to ensure tests get clumped together with
the thing below them.
Diffstat (limited to 'nomsu_compiler.moon')
| -rw-r--r-- | nomsu_compiler.moon | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index a8eba0c..b48a8f7 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -648,26 +648,28 @@ with NomsuCompiler switch tree.type when "FileChunks" - setup = nil nomsu = NomsuCode(tree.source, pop_comments(tree.source.start)) + should_clump = (prev_line, line)-> + if prev_line and prev_line.type == "Action" and line.type == "Action" + if prev_line.stub == "use %" then return line.stub == "use %" + if prev_line.stub == "test %" then return true + if line.stub == "test %" then return false + return false if recurse(prev_line)\is_multiline! + return true for chunk_no, chunk in ipairs tree nomsu\append "\n\n#{("~")\rep(80)}\n\n" if chunk_no > 1 nomsu\append pop_comments(chunk.source.start) if chunk.type == "Block" for line_no, line in ipairs chunk - if setup == nil - setup = line.type == "Action" and line.stub == "use %" - elseif setup and not (line.type == "Action" and line.stub == "use %") - nomsu\append "\n", pop_comments(line.source.start) - setup = false - nomsu\append pop_comments(line.source.start, tostring(nomsu)\match("\n\n$") and "" or "\n") - line_nomsu = @tree_to_nomsu(line, pop_comments) - nomsu\append line_nomsu - nomsu\append(line_nomsu\is_multiline! and "\n\n" or "\n") if line_no < #chunk + if line_no > 1 + if should_clump(chunk[line_no-1], line) + nomsu\append "\n", pop_comments(line.source.start, '\n') + else + nomsu\append "\n\n", pop_comments(line.source.start) + nomsu\append @tree_to_nomsu(line, pop_comments) nomsu\append pop_comments(chunk.source.stop, '\n') else nomsu\append recurse(chunk) - setup = false nomsu\append pop_comments(tree.source.stop, '\n') nomsu\append('\n') unless tostring(nomsu)\match("\n$") return nomsu |
