diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-08-28 15:08:00 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-08-28 15:08:07 -0700 |
| commit | e44acbf338e17fb86a47eebf448c27a04d446048 (patch) | |
| tree | dce45fa28ffd070c70ae2c0b27ad9794489cec6a /code_obj.moon | |
| parent | 930d522fbc3ab57faa926ed85f0d35d661722402 (diff) | |
Lots of overhaul, supporting a new Object Oriented approach (e.g.
%obj::action 1 2) and syntax.
Diffstat (limited to 'code_obj.moon')
| -rw-r--r-- | code_obj.moon | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/code_obj.moon b/code_obj.moon index 7752de6..5ed10f3 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -3,6 +3,7 @@ -- indentation levels. {:insert, :remove, :concat} = table {:repr} = require 'utils' +unpack or= table.unpack local LuaCode, NomsuCode, Source class Source @@ -16,11 +17,9 @@ class Source @is_instance: (x)=> type(x) == 'table' and x.__class == @ - __tostring: => - if @stop - "@#{@filename}[#{@start}:#{@stop}]" - else - "@#{@filename}[#{@start}]" + __tostring: => "@#{@filename}[#{@start}#{@stop and ':'..@stop or ''}]" + + __repr: => "Source(#{repr @filename}, #{@start}#{@stop and ', '..@stop or ''})" __eq: (other)=> getmetatable(@) == getmetatable(other) and @filename == other.filename and @start == other.start and @stop == other.stop @@ -68,8 +67,14 @@ class Code @__str = concat(buff, "") return @__str - __len: => - #tostring(self) + __repr: => + "#{@__class.__name}(#{concat {repr(tostring(@source)), unpack([repr(b) for b in *@bits])}, ", "})" + + __len: => #tostring(@) + + match: (...)=> tostring(@)\match(...) + + gmatch: (...)=> tostring(@)\gmatch(...) dirty: => @__str = nil @@ -126,8 +131,8 @@ class Code bits[#bits+1] = joiner bits[#bits+1] = b b.dirty = error if b.is_code - b_str = tostring(b) - line = match(b_str, "\n([^\n]*)$") + b = tostring(b) + line = match(b, "\n([^\n]*)$") if line line_len = #line else @@ -153,6 +158,7 @@ class Code class LuaCode extends Code __tostring: Code.__tostring + __repr: Code.__repr __len: Code.__len new: (...)=> super ... @@ -247,6 +253,7 @@ class LuaCode extends Code class NomsuCode extends Code __tostring: Code.__tostring + __repr: Code.__repr __len: Code.__len return {:Code, :NomsuCode, :LuaCode, :Source} |
