From 310712385b5bd3b9f25c1ba15ccdb8ad5606fc6c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 19 Apr 2018 17:38:31 -0700 Subject: Made Source a little more concise. --- lua_obj.moon | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lua_obj.moon') 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 -- cgit v1.2.3