diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-10 17:34:39 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-10 17:34:50 -0700 |
| commit | 194146d36591e6c3a964667ead9109bbc6e00524 (patch) | |
| tree | fa2801b488f55f48bbd9a41f49585d125a54b180 /code_obj.moon | |
| parent | 26a6174f28191fe3364e30c76c1c7a5814e7c5ab (diff) | |
Improving codegen line wrapping.
Diffstat (limited to 'code_obj.moon')
| -rw-r--r-- | code_obj.moon | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/code_obj.moon b/code_obj.moon index 8ac7146..1586d15 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -45,7 +45,9 @@ class Source class Code new: (@source, ...)=> - @bits, @indents, @current_indent = {}, {}, 0 + @bits = {} + @indents, @current_indent = {}, 0 + @trailing_line_len = 0 if type(@source) == 'string' @source = Source\from_string(@source) assert(@source and Source\is_instance(@source), "Source has the wrong type") @@ -57,14 +59,21 @@ class Code match = string.match for i=1,n b = select(i, ...) - assert(b, "bit is nil") + assert(b, "code bit is nil") if b == '' then continue bits[#bits+1] = b if type(b) == 'string' - if spaces = match(b, "\n([ ]*)[^\n]*$") + trailing_text, spaces = match(b, "\n(([ ]*)[^\n]*)$") + if trailing_text @current_indent = #spaces - elseif @current_indent != 0 - indents[#bits] = @current_indent + @trailing_line_len = #trailing_text + else + if #b.indents > 1 + @trailing_line_len = b.trailing_line_len + else + @trailing_line_len += #tostring(b) + if @current_indent != 0 + indents[#bits] = @current_indent @__str = nil concat_append: (values, joiner, wrapping_joiner)=> |
