aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua_obj.lua11
-rw-r--r--lua_obj.moon10
2 files changed, 13 insertions, 8 deletions
diff --git a/lua_obj.lua b/lua_obj.lua
index c4bbb32..4585d58 100644
--- a/lua_obj.lua
+++ b/lua_obj.lua
@@ -19,9 +19,9 @@ Source = immutable({
end,
__tostring = function(self)
if self.stop then
- return "Source(\"" .. tostring(self.filename) .. "\", " .. tostring(self.start) .. ", " .. tostring(self.stop) .. ")"
+ return "\"" .. tostring(self.filename) .. "[" .. tostring(self.start) .. ":" .. tostring(self.stop) .. "]\""
else
- return "Source(\"" .. tostring(self.filename) .. "\", " .. tostring(self.start) .. ")"
+ return "\"" .. tostring(self.filename) .. "[" .. tostring(self.start) .. "]\""
end
end,
__lt = function(self, other)
@@ -148,11 +148,14 @@ do
...
}
if type(self.source) == 'string' then
- local filename, start, stop = self.source:match("^(.-)[(%d+):(%d+)]$")
+ 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, #self)
+ self.source = Source(self.source, 1, #self + 1)
end
end
end,
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