aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-26 16:21:42 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-26 16:22:04 -0800
commit8e5f1b9e1e912f781738a564843e024b0e0b2e96 (patch)
treed0ff38fc1f791d784ef2c968940365f04d3b6eee /nomsu_compiler.lua
parentcbbe6b1c14faf85c20dee4c481723cf0e468e0e8 (diff)
Simplifying the control flow API and deduplicating the code.
Diffstat (limited to 'nomsu_compiler.lua')
-rw-r--r--nomsu_compiler.lua25
1 files changed, 20 insertions, 5 deletions
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()