diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-19 16:57:44 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-19 16:58:47 -0700 |
| commit | ddc7b8e70cb375df4e0d3660056aef9286b2e02f (patch) | |
| tree | a7a01047e8a93bd484a19e000afe6f72ac8e61d3 /nomsu_compiler.lua | |
| parent | bf67a610135c0803187cf6ed896638962f142d14 (diff) | |
Fix for nomsu codegen of blocks, particularly nested mutli-blocks like:
(do: if (yes) (: say "hi"); say "done")
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index b4702ed..16dbd88 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -787,6 +787,7 @@ do recurse = function(t, opts) opts = opts or { } opts.consumed_comments = options.consumed_comments + opts.inside_multiblock = opts.inside_multiblock or options.inside_multiblock return self:tree_to_nomsu(t, opts) end local _exp_0 = tree.type @@ -822,13 +823,23 @@ do if not (arg_nomsu) then return nil end - if not (i == 1 or (bit.type == "Block" and not (#bit > 1 or i < #tree))) then - nomsu:append(" ") - end - if bit.type == "Action" or (bit.type == "Block" and (#bit > 1 or i < #tree)) then - arg_nomsu:parenthesize() + if bit.type == "Block" then + if i == 1 or i < #tree or (options.inside_multiblock and #bit > 1) then + if i > 1 then + nomsu:append(" ") + end + arg_nomsu:parenthesize() + end + nomsu:append(arg_nomsu) + else + if i > 1 then + nomsu:append(" ") + end + if bit.type == "Action" then + arg_nomsu:parenthesize() + end + nomsu:append(arg_nomsu) end - nomsu:append(arg_nomsu) end end return nomsu @@ -911,7 +922,8 @@ do for i, line in ipairs(tree) do nomsu:append(i == 1 and " " or "; ") nomsu:append(assert(recurse(line, { - inline = true + inline = true, + inside_multiblock = true }))) end return nomsu |
