diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-26 16:21:42 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-26 16:22:04 -0800 |
| commit | 8e5f1b9e1e912f781738a564843e024b0e0b2e96 (patch) | |
| tree | d0ff38fc1f791d784ef2c968940365f04d3b6eee /nomsu_compiler.moon | |
| parent | cbbe6b1c14faf85c20dee4c481723cf0e468e0e8 (diff) | |
Simplifying the control flow API and deduplicating the code.
Diffstat (limited to 'nomsu_compiler.moon')
| -rw-r--r-- | nomsu_compiler.moon | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index 3600e60..a818c99 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -213,24 +213,36 @@ compile = setmetatable({ when "Text" lua = LuaCode\from(tree.source) + added = 0 string_buffer = "" for i, bit in ipairs tree if type(bit) == "string" string_buffer ..= bit continue if string_buffer != "" - if #lua.bits > 0 then lua\append ".." - lua\append string_buffer\as_lua! + string_buffer = string_buffer\as_lua! + if lua\trailing_line_len! + #string_buffer > MAX_LINE + lua\append "\n " + if added > 0 then lua\append ".." + lua\append string_buffer + added += 1 string_buffer = "" bit_lua = compile(bit) - if #lua.bits > 0 then lua\append ".." + if lua\trailing_line_len! + #bit_lua\text! > MAX_LINE + lua\append "\n " + if added > 0 then lua\append ".." if bit.type != "Text" bit_lua = LuaCode\from(bit.source, "tostring(",bit_lua,")") lua\append bit_lua + added += 1 if string_buffer ~= "" or #lua.bits == 0 - if #lua.bits > 0 then lua\append ".." - lua\append string_buffer\as_lua! + string_buffer = string_buffer\as_lua! + if lua\trailing_line_len! + #string_buffer > MAX_LINE + lua\append "\n " + if added > 0 then lua\append ".." + lua\append string_buffer + added += 1 if #lua.bits > 1 lua\parenthesize! |
