aboutsummaryrefslogtreecommitdiff
path: root/code_obj.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-04 20:41:20 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-04 20:44:58 -0700
commit83183122f180ce0fdbf3b5c1c8ff828d762348a8 (patch)
tree0f536166e9e2169b8aa33a8a8a20ba7e29109950 /code_obj.lua
parent563e415e07ea45df8c80fc9a2afc652e3e6d8c83 (diff)
Optimizations and cleanup. Build script now fails on first error and
uses the precompiled versions it has just compiled.
Diffstat (limited to 'code_obj.lua')
-rw-r--r--code_obj.lua48
1 files changed, 0 insertions, 48 deletions
diff --git a/code_obj.lua b/code_obj.lua
index dcdd95a..fa36234 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -11,16 +11,6 @@ Source = immutable({
"stop"
}, {
name = "Source",
- __new = function(self, filename, start, stop)
- assert(type(filename) == 'string')
- if not start then
- start, stop = 1, #FILE_CACHE[filename]
- end
- if stop and start > stop + 1 then
- error("Invalid range: " .. tostring(start) .. ", " .. tostring(stop))
- end
- return filename, start, stop
- end,
from_string = function(self, str)
local filename, start, stop = str:match("^@(.-)%[(%d+):(%d+)%]$")
if not (filename) then
@@ -60,44 +50,6 @@ Source = immutable({
end
end
return Source(self.filename, self.start + offset, self.stop)
- end,
- sub = function(self, start, stop)
- start = start or 1
- assert(start > 0 and (stop == nil or stop > 0), "Negative subscripts not supported")
- if not self.stop then
- assert(not stop, "cannot subscript non-range with range")
- return Source(self.filename, self.start + start - 1)
- else
- stop = stop or self.stop
- return Source(self.filename, self.start + start - 1, self.start + stop - 1)
- end
- end,
- get_text = function(self)
- return FILE_CACHE[self.filename]:sub(self.start, self.stop)
- end,
- get_line_number = function(self)
- local src = FILE_CACHE[self.filename]
- local line_starts = LINE_STARTS[src]
- local start_line = 1
- while (line_starts[start_line + 1] or math.huge) <= self.start do
- start_line = start_line + 1
- end
- local stop_line = start_line
- while (line_starts[stop_line + 1] or math.huge) <= self.stop do
- stop_line = stop_line + 1
- end
- return start_line, stop_line
- end,
- get_line = function(self)
- return tostring(self.filename) .. ":" .. tostring(self:get_line_number())
- end,
- get_line_range = function(self)
- local start_line, stop_line = self:get_line_number()
- if stop_line == start_line then
- return tostring(self.filename) .. ":" .. tostring(start_line)
- else
- return tostring(self.filename) .. ":" .. tostring(start_line) .. "-" .. tostring(stop_line)
- end
end
})
local Code