aboutsummaryrefslogtreecommitdiff
path: root/code_obj.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-10 17:34:39 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-10 17:34:50 -0700
commit194146d36591e6c3a964667ead9109bbc6e00524 (patch)
treefa2801b488f55f48bbd9a41f49585d125a54b180 /code_obj.lua
parent26a6174f28191fe3364e30c76c1c7a5814e7c5ab (diff)
Improving codegen line wrapping.
Diffstat (limited to 'code_obj.lua')
-rw-r--r--code_obj.lua26
1 files changed, 17 insertions, 9 deletions
diff --git a/code_obj.lua b/code_obj.lua
index cc2fb69..a822499 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -85,21 +85,27 @@ do
local _continue_0 = false
repeat
local b = select(i, ...)
- assert(b, "bit is nil")
+ assert(b, "code bit is nil")
if b == '' then
_continue_0 = true
break
end
bits[#bits + 1] = b
if type(b) == 'string' then
- do
- local spaces = match(b, "\n([ ]*)[^\n]*$")
- if spaces then
- self.current_indent = #spaces
- end
+ local trailing_text, spaces = match(b, "\n(([ ]*)[^\n]*)$")
+ if trailing_text then
+ self.current_indent = #spaces
+ self.trailing_line_len = #trailing_text
+ end
+ else
+ if #b.indents > 1 then
+ self.trailing_line_len = b.trailing_line_len
+ else
+ self.trailing_line_len = self.trailing_line_len + #tostring(b)
+ end
+ if self.current_indent ~= 0 then
+ indents[#bits] = self.current_indent
end
- elseif self.current_indent ~= 0 then
- indents[#bits] = self.current_indent
end
_continue_0 = true
until true
@@ -172,7 +178,9 @@ do
_class_0 = setmetatable({
__init = function(self, source, ...)
self.source = source
- self.bits, self.indents, self.current_indent = { }, { }, 0
+ self.bits = { }
+ self.indents, self.current_indent = { }, 0
+ self.trailing_line_len = 0
if type(self.source) == 'string' then
self.source = Source:from_string(self.source)
end