diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-26 15:58:32 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-26 15:59:03 -0700 |
| commit | 0c7c06beabc5a2ef4f89923cc8cf59331e2c32cf (patch) | |
| tree | dd7cd63e52dc4d2c3bf33b9adf7eda87997f76aa /code_obj.lua | |
| parent | 8cb2788e0dc514e6d6436a7a03e87e414327ec94 (diff) | |
Moving back to capturing tables in LPEG and everything is a Source, not
string.
Diffstat (limited to 'code_obj.lua')
| -rw-r--r-- | code_obj.lua | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/code_obj.lua b/code_obj.lua index d84744e..e8e86fa 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -20,6 +20,13 @@ Source = immutable({ end return filename, start, stop end, + from_string = function(self, str) + local filename, start, stop = str:match("^(.-)%[(%d+):(%d+)%]$") + if not (filename) then + filename, start = str:match("^(.-)%[(%d+)%]$") + end + return Source(filename or str, tonumber(start or 1), tonumber(stop)) + end, __tostring = function(self) if self.stop then return "\"" .. tostring(self.filename) .. "[" .. tostring(self.start) .. ":" .. tostring(self.stop) .. "]\"" @@ -94,11 +101,6 @@ local Code do local _class_0 local _base_0 = { - sub = function(self, start, stop) - local str = tostring(self):sub(start, stop) - local cls = self.__class - return cls(self.source:sub(start, stop), str) - end, append = function(self, ...) local n = select("#", ...) local bits, indents = self.bits, self.indents @@ -156,15 +158,7 @@ do self.bits, self.indents, self.current_indent = { }, { }, 0 self:append(...) if type(self.source) == 'string' then - local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$") - if not (filename) then - filename, start = self.source:match("^(.-)%[(%d+)%]$") - end - if start or stop then - self.source = Source(filename, tonumber(start), tonumber(stop)) - else - self.source = Source(self.source, 1, #tostring(self) + 1) - end + self.source = Source:from_string(self.source) end return assert(self.source) end, |
