From 8e5f1b9e1e912f781738a564843e024b0e0b2e96 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 26 Nov 2018 16:21:42 -0800 Subject: Simplifying the control flow API and deduplicating the code. --- nomsu_compiler.lua | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'nomsu_compiler.lua') diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 5a840ea..b08b5e1 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -307,6 +307,7 @@ local compile = setmetatable({ return lua elseif "Text" == _exp_0 then local lua = LuaCode:from(tree.source) + local added = 0 local string_buffer = "" for i, bit in ipairs(tree) do local _continue_0 = false @@ -317,20 +318,29 @@ local compile = setmetatable({ break end if string_buffer ~= "" then - if #lua.bits > 0 then + string_buffer = string_buffer:as_lua() + if lua:trailing_line_len() + #string_buffer > MAX_LINE then + lua:append("\n ") + end + if added > 0 then lua:append("..") end - lua:append(string_buffer:as_lua()) + lua:append(string_buffer) + added = added + 1 string_buffer = "" end local bit_lua = compile(bit) - if #lua.bits > 0 then + if lua:trailing_line_len() + #bit_lua:text() > MAX_LINE then + lua:append("\n ") + end + if added > 0 then lua:append("..") end if bit.type ~= "Text" then bit_lua = LuaCode:from(bit.source, "tostring(", bit_lua, ")") end lua:append(bit_lua) + added = added + 1 _continue_0 = true until true if not _continue_0 then @@ -338,10 +348,15 @@ local compile = setmetatable({ end end if string_buffer ~= "" or #lua.bits == 0 then - if #lua.bits > 0 then + string_buffer = string_buffer:as_lua() + if lua:trailing_line_len() + #string_buffer > MAX_LINE then + lua:append("\n ") + end + if added > 0 then lua:append("..") end - lua:append(string_buffer:as_lua()) + lua:append(string_buffer) + added = added + 1 end if #lua.bits > 1 then lua:parenthesize() -- cgit v1.2.3