diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-19 20:41:31 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-19 20:42:09 -0700 |
| commit | 47db74229deaf281ad02c8305c4e4d4c8dbd3d7d (patch) | |
| tree | fac39ef65240c3de58b68a4f59bb93f2d4e622c6 /code_obj.moon | |
| parent | 0eff1c77f250e6839086f41af0c79bb3e2e8ea39 (diff) | |
Fixed some bugs in trailing_line_len() and refactored tree_to_nomsu into
separate inline/not-inline functions.
Diffstat (limited to 'code_obj.moon')
| -rw-r--r-- | code_obj.moon | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/code_obj.moon b/code_obj.moon index 9bfa9a5..35d1027 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -51,6 +51,11 @@ class Code @source = Source\from_string(@source) assert(@source and Source\is_instance(@source), "Source has the wrong type") @append(...) + + dirty: => + @__str = nil + @_trailing_line_len = nil + @_is_multiline = nil append: (...)=> n = select("#",...) @@ -64,8 +69,7 @@ class Code bits[#bits+1] = b if type(b) != 'string' and not (type(b) == 'table' and b.is_code) b = repr(b) - @__str = nil - @_trailing_line_len = nil + @dirty! trailing_line_len: => if @_trailing_line_len == nil @@ -75,13 +79,25 @@ class Code b = bits[i] if type(b) == 'string' if line = match(b, "\n([^\n]*)$") - return len + #line + len += #line + break else len += #b else len += b\trailing_line_len! + break if b\is_multiline! @_trailing_line_len = len return @_trailing_line_len - + + is_multiline: => + if @_is_multiline == nil + match = string.match + @_is_multiline = false + for b in *@bits + if type(b) != 'string' or match(b, "\n") + @_is_multiline = true + break + return @_is_multiline + concat_append: (values, joiner, wrapping_joiner)=> wrapping_joiner or= joiner match = string.match @@ -102,8 +118,7 @@ class Code line_len = #line else line_len += #b - @__str = nil - @_trailing_line_len = nil + @dirty! prepend: (...)=> n = select("#",...) @@ -112,8 +127,7 @@ class Code bits[i] = bits[i-n] for i=1,n bits[i] = select(i, ...) - @__str = nil - @_trailing_line_len = nil + @dirty! class LuaCode extends Code new: (...)=> @@ -134,8 +148,7 @@ class LuaCode extends Code unless seen[var] @free_vars[#@free_vars+1] = var seen[var] = true - @__str = nil - @_trailing_line_len = nil + @dirty! remove_free_vars: (vars)=> return unless #vars > 0 @@ -154,8 +167,7 @@ class LuaCode extends Code for b in *lua.bits if type(b) != 'string' stack[#stack+1] = b - @__str = nil - @_trailing_line_len = nil + @dirty! declare_locals: (to_declare=nil)=> if to_declare == nil |
