diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-04 20:41:20 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-04 20:44:58 -0700 |
| commit | 83183122f180ce0fdbf3b5c1c8ff828d762348a8 (patch) | |
| tree | 0f536166e9e2169b8aa33a8a8a20ba7e29109950 /code_obj.moon | |
| parent | 563e415e07ea45df8c80fc9a2afc652e3e6d8c83 (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.moon')
| -rw-r--r-- | code_obj.moon | 34 |
1 files changed, 0 insertions, 34 deletions
diff --git a/code_obj.moon b/code_obj.moon index 8dfc0a1..5fe6c98 100644 --- a/code_obj.moon +++ b/code_obj.moon @@ -5,12 +5,6 @@ export LINE_STARTS Source = immutable {"filename","start","stop"}, { name:"Source" - __new: (filename, start, stop)=> - assert(type(filename) == 'string') - if not start - start, stop = 1, #FILE_CACHE[filename] - if stop and start > stop+1 then error("Invalid range: #{start}, #{stop}") - return filename, start, stop from_string: (str)=> filename,start,stop = str\match("^@(.-)%[(%d+):(%d+)%]$") unless filename @@ -36,34 +30,6 @@ Source = immutable {"filename","start","stop"}, { offset, self = self, offset else if type(offset) != 'number' then error("Cannot add Source and #{type(offset)}") return Source(@filename, @start+offset, @stop) - sub: (start, stop)=> - start or= 1 - assert(start > 0 and (stop == nil or stop > 0), "Negative subscripts not supported") - if not @stop - assert(not stop, "cannot subscript non-range with range") - return Source(@filename, @start + start - 1) - else - stop or= @stop - return Source(@filename, @start + start - 1, @start + stop - 1) - get_text: => - FILE_CACHE[@filename]\sub(@start,@stop) - get_line_number: => - -- TODO: do a binary search if this is actually slow, which I doubt - src = FILE_CACHE[@filename] - line_starts = LINE_STARTS[src] - start_line = 1 - while (line_starts[start_line+1] or math.huge) <= @start - start_line += 1 - stop_line = start_line - while (line_starts[stop_line+1] or math.huge) <= @stop - stop_line += 1 - return start_line, stop_line - get_line: => "#{@filename}:#{@get_line_number!}" - get_line_range: => - start_line, stop_line = @get_line_number! - return if stop_line == start_line - "#{@filename}:#{start_line}" - else "#{@filename}:#{start_line}-#{stop_line}" } class Code |
