aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-19 16:57:44 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-19 16:58:47 -0700
commitddc7b8e70cb375df4e0d3660056aef9286b2e02f (patch)
treea7a01047e8a93bd484a19e000afe6f72ac8e61d3 /nomsu_compiler.moon
parentbf67a610135c0803187cf6ed896638962f142d14 (diff)
Fix for nomsu codegen of blocks, particularly nested mutli-blocks like:
(do: if (yes) (: say "hi"); say "done")
Diffstat (limited to 'nomsu_compiler.moon')
-rw-r--r--nomsu_compiler.moon17
1 files changed, 11 insertions, 6 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 5b9b3f6..e4521f2 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -509,6 +509,7 @@ with NomsuCompiler
recurse = (t, opts)->
opts or= {}
opts.consumed_comments = options.consumed_comments
+ opts.inside_multiblock or= options.inside_multiblock
return @tree_to_nomsu(t, opts)
switch tree.type
@@ -532,11 +533,15 @@ with NomsuCompiler
else
arg_nomsu = recurse(bit,inline:true)
return nil unless arg_nomsu
- unless i == 1 or (bit.type == "Block" and not (#bit > 1 or i < #tree))
- nomsu\append " "
- if bit.type == "Action" or (bit.type == "Block" and (#bit > 1 or i < #tree))
- arg_nomsu\parenthesize!
- nomsu\append arg_nomsu
+ if bit.type == "Block"
+ if i == 1 or i < #tree or (options.inside_multiblock and #bit > 1)
+ nomsu\append " " if i > 1
+ arg_nomsu\parenthesize!
+ nomsu\append arg_nomsu
+ else
+ nomsu\append " " if i > 1
+ arg_nomsu\parenthesize! if bit.type == "Action"
+ nomsu\append arg_nomsu
return nomsu
else
pos = tree.source.start
@@ -596,7 +601,7 @@ with NomsuCompiler
nomsu = NomsuCode(tree.source, ":")
for i,line in ipairs tree
nomsu\append(i == 1 and " " or "; ")
- nomsu\append assert(recurse(line, inline:true))
+ nomsu\append assert(recurse(line, inline:true, inside_multiblock:true))
return nomsu
nomsu = NomsuCode(tree.source, pop_comments(tree.source.start))
for i, line in ipairs tree