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.lua | |
| 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.lua')
| -rw-r--r-- | code_obj.lua | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/code_obj.lua b/code_obj.lua index 686cc7f..b07c063 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -5,16 +5,16 @@ do end local repr repr = require('utils').repr +local unpack = unpack or table.unpack local LuaCode, NomsuCode, Source do local _class_0 local _base_0 = { __tostring = function(self) - if self.stop then - return "@" .. tostring(self.filename) .. "[" .. tostring(self.start) .. ":" .. tostring(self.stop) .. "]" - else - return "@" .. tostring(self.filename) .. "[" .. tostring(self.start) .. "]" - end + return "@" .. tostring(self.filename) .. "[" .. tostring(self.start) .. tostring(self.stop and ':' .. self.stop or '') .. "]" + end, + __repr = function(self) + return "Source(" .. tostring(repr(self.filename)) .. ", " .. tostring(self.start) .. tostring(self.stop and ', ' .. self.stop or '') .. ")" end, __eq = function(self, other) return getmetatable(self) == getmetatable(other) and self.filename == other.filename and self.start == other.start and self.stop == other.stop @@ -108,9 +108,31 @@ do end return self.__str end, + __repr = function(self) + return tostring(self.__class.__name) .. "(" .. tostring(concat({ + repr(tostring(self.source)), + unpack((function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = self.bits + for _index_0 = 1, #_list_0 do + local b = _list_0[_index_0] + _accum_0[_len_0] = repr(b) + _len_0 = _len_0 + 1 + end + return _accum_0 + end)()) + }, ", ")) .. ")" + end, __len = function(self) return #tostring(self) end, + match = function(self, ...) + return tostring(self):match(...) + end, + gmatch = function(self, ...) + return tostring(self):gmatch(...) + end, dirty = function(self) self.__str = nil self._trailing_line_len = nil @@ -192,8 +214,8 @@ do if b.is_code then b.dirty = error end - local b_str = tostring(b) - local line = match(b_str, "\n([^\n]*)$") + b = tostring(b) + local line = match(b, "\n([^\n]*)$") if line then line_len = #line else @@ -254,6 +276,7 @@ do local _parent_0 = Code local _base_0 = { __tostring = Code.__tostring, + __repr = Code.__repr, __len = Code.__len, add_free_vars = function(self, vars) if not (#vars > 0) then @@ -446,6 +469,7 @@ do local _parent_0 = Code local _base_0 = { __tostring = Code.__tostring, + __repr = Code.__repr, __len = Code.__len } _base_0.__index = _base_0 |
