diff --git a/moonscript/compile.lua b/moonscript/compile.lua index 379c9c9..e5515a5 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -150,38 +150,30 @@ end do local _base_0 = { pos = nil, - _append_single = function(self, item) - if Line == mtype(item) then - if not (self.pos) then - self.pos = item.pos - end - for _index_0 = 1, #item do - local value = item[_index_0] - self:_append_single(value) - end - else - insert(self, item) - end - return nil - end, append_list = function(self, items, delim) for i = 1, #items do - self:_append_single(items[i]) + self:append(items[i]) if i < #items then insert(self, delim) end end return nil end, - append = function(self, ...) - local _list_0 = { - ... - } - for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - self:_append_single(item) + append = function(self, first, ...) + if Line == mtype(first) then + if not (self.pos) then + self.pos = first.pos + end + for _index_0 = 1, #first do + local value = first[_index_0] + self:append(value) + end + else + insert(self, first) + end + if ... then + return self:append(...) end - return nil end, render = function(self, buffer) local current = { } @@ -209,7 +201,7 @@ do insert(current, chunk) end end - if #current > 0 then + if current[1] then add_current() end return buffer diff --git a/moonscript/compile.moon b/moonscript/compile.moon index af7242e..c8b3a54 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -97,24 +97,22 @@ class Lines class Line pos: nil - _append_single: (item) => - if Line == mtype item - -- print "appending line to line", item.pos, item - @pos = item.pos unless @pos -- bubble pos if there isn't one - @_append_single value for value in *item - else - insert self, item - nil - append_list: (items, delim) => for i = 1,#items - @_append_single items[i] + @append items[i] if i < #items then insert self, delim nil - append: (...) => - @_append_single item for item in *{...} - nil + append: (first, ...) => + if Line == mtype first + -- print "appending line to line", first.pos, first + @pos = first.pos unless @pos -- bubble pos if there isn't one + @append value for value in *first + else + insert self, first + + if ... + @append ... -- todo: try to remove concats from here render: (buffer) => @@ -137,7 +135,7 @@ class Line else insert current, chunk - if #current > 0 + if current[1] add_current! buffer