diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-19 17:38:31 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-19 17:38:42 -0700 |
| commit | 310712385b5bd3b9f25c1ba15ccdb8ad5606fc6c (patch) | |
| tree | 407900bc61fdad990f47f75e32ec7f6edfc05c8e /lua_obj.moon | |
| parent | ecb4341bdc62dac64b487ac6c67882da51e5205e (diff) | |
Made Source a little more concise.
Diffstat (limited to 'lua_obj.moon')
| -rw-r--r-- | lua_obj.moon | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lua_obj.moon b/lua_obj.moon index 46d5639..b7d3925 100644 --- a/lua_obj.moon +++ b/lua_obj.moon @@ -10,9 +10,9 @@ Source = immutable {"filename","start","stop"}, { return filename, start, stop __tostring: => if @stop - "Source(\"#{@filename}\", #{@start}, #{@stop})" + "\"#{@filename}[#{@start}:#{@stop}]\"" else - "Source(\"#{@filename}\", #{@start})" + "\"#{@filename}[#{@start}]\"" __lt: (other)=> assert(@filename == other.filename, "Cannot compare sources from different files") return if @start == other.start @@ -62,11 +62,13 @@ class Code new: (@source, ...)=> @bits = {...} if type(@source) == 'string' - filename,start,stop = @source\match("^(.-)[(%d+):(%d+)]$") + filename,start,stop = @source\match("^(.-)%[(%d+):(%d+)%]$") + unless filename + filename,start = @source\match("^(.-)%[(%d+)%]$") if start or stop @source = Source(filename, tonumber(start), tonumber(stop)) else - @source = Source(@source, 1, #self) + @source = Source(@source, 1, #self+1) clone: => cls = @__class |
