aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-29 17:10:44 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-29 17:10:54 -0700
commite697689ddd2e62719927fcc084547b3faed6fc6d (patch)
tree3dd1b5a5a9e727a3cdc4647d36ef928726b4196d
parent3573dfe9950d7037dfc3c48c6486d432100e6866 (diff)
Fixed up the edge cases and simplified the code a bit.
-rw-r--r--nomsu.lua54
-rwxr-xr-xnomsu.moon40
2 files changed, 12 insertions, 82 deletions
diff --git a/nomsu.lua b/nomsu.lua
index ddad7dd..1e673bb 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -313,24 +313,6 @@ do
define_compile_action = function(self, signature, fn)
return self:define_action(signature, fn, true)
end,
- lua_line_to_nomsu = function(self, source, line_no)
- local pos = 0
- local line = 0
- local filename = source:match('"([^[]*)')
- for line in FILE_CACHE[filename]:gmatch("[^\n]*\n") do
- line = line + 1
- pos = pos + #line
- if line == line_no then
- break
- end
- end
- for i, entry in ipairs(self.source_map[source]) do
- if entry[1] > pos then
- return self.source_map[source][i - 1][2]
- end
- end
- return self.source_map[source][#self.source_map[source]][2]
- end,
parse = function(self, nomsu_code)
if type(nomsu_code) == 'string' then
_nomsu_chunk_counter = _nomsu_chunk_counter + 1
@@ -502,22 +484,14 @@ do
local fn
fn = function(s)
if type(s) == 'string' then
- map[lua_line] = map[lua_line] or {
- nomsu_line
- }
for nl in s:gmatch("\n") do
+ map[lua_line] = map[lua_line] or nomsu_line
lua_line = lua_line + 1
- map[lua_line] = map[lua_line] or {
- nomsu_line
- }
end
else
local old_line = nomsu_line
if s.source then
nomsu_line = pos_to_line(nomsu_line_to_pos, s.source.start)
- if nomsu_line ~= old_line then
- insert(map[lua_line], nomsu_line)
- end
end
local _list_0 = s.bits
for _index_0 = 1, #_list_0 do
@@ -527,6 +501,8 @@ do
end
end
fn(lua)
+ map[lua_line] = map[lua_line] or nomsu_line
+ map[0] = 0
self.source_map[tostring(lua.source)] = map
end
return run_lua_fn()
@@ -1493,35 +1469,17 @@ OPTIONS
local map = nomsu.source_map[info.source]
if map then
if info.currentline then
- info.currentline = (map[info.currentline] or {
- info.currentline
- })[1]
+ info.currentline = assert(map[info.currentline])
end
if info.linedefined then
- info.linedefined = (map[info.linedefined] or {
- info.linedefined
- })[1]
+ info.linedefined = assert(map[info.linedefined])
end
if info.lastlinedefined then
- info.lastlinedefined = (map[info.lastlinedefined] or {
- info.lastlinedefined
- })[1]
+ info.lastlinedefined = assert(map[info.lastlinedefined])
end
info.short_src = info.source:match('"([^[]*)')
end
end
- local _ = [=[ if metadata = nomsu.action_metadata[info.func]
- info.name = metadata.aliases[1]
- filename = if type(metadata.source) == 'string'
- metadata.source\match("^[^[:]*")
- else metadata.source.filename
- info.short_src = filename
- info.source = FILE_CACHE[filename]
- ok, linedefined = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
- if ok then info.linedefined = linedefined
- ok, currentline = pcall(lua_line_to_nomsu_line, info.short_src, info.currentline)
- --if ok then info.currentline = currentline
- ]=]
end
return info
end
diff --git a/nomsu.moon b/nomsu.moon
index 36911bd..a464827 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -325,20 +325,6 @@ class NomsuCompiler
define_compile_action: (signature, fn)=>
return @define_action(signature, fn, true)
- lua_line_to_nomsu: (source, line_no)=>
- pos = 0
- line = 0
- filename = source\match('"([^[]*)')
- for line in FILE_CACHE[filename]\gmatch("[^\n]*\n")
- line += 1
- pos += #line
- if line == line_no
- break
- for i, entry in ipairs @source_map[source]
- if entry[1] > pos
- return @source_map[source][i-1][2]
- return @source_map[source][#@source_map[source]][2]
-
_nomsu_chunk_counter = 0
parse: (nomsu_code)=>
if type(nomsu_code) == 'string'
@@ -460,18 +446,17 @@ class NomsuCompiler
nomsu_line = pos_to_line(nomsu_line_to_pos, lua.source.start)
fn = (s)->
if type(s) == 'string'
- map[lua_line] or= {nomsu_line}
for nl in s\gmatch("\n")
+ map[lua_line] or= nomsu_line
lua_line += 1
- map[lua_line] or= {nomsu_line}
else
old_line = nomsu_line
if s.source
nomsu_line = pos_to_line(nomsu_line_to_pos, s.source.start)
- if nomsu_line != old_line
- insert map[lua_line], nomsu_line
for b in *s.bits do fn(b)
fn(lua)
+ map[lua_line] or= nomsu_line
+ map[0] = 0
-- Mapping from lua line number to nomsu line numbers
@source_map[tostring(lua.source)] = map
@@ -1058,25 +1043,12 @@ OPTIONS
if map = nomsu.source_map[info.source]
if info.currentline
- info.currentline = (map[info.currentline] or {info.currentline})[1]
+ info.currentline = assert(map[info.currentline])
if info.linedefined
- info.linedefined = (map[info.linedefined] or {info.linedefined})[1]
+ info.linedefined = assert(map[info.linedefined])
if info.lastlinedefined
- info.lastlinedefined = (map[info.lastlinedefined] or {info.lastlinedefined})[1]
+ info.lastlinedefined = assert(map[info.lastlinedefined])
info.short_src = info.source\match('"([^[]*)')
- [=[
- if metadata = nomsu.action_metadata[info.func]
- info.name = metadata.aliases[1]
- filename = if type(metadata.source) == 'string'
- metadata.source\match("^[^[:]*")
- else metadata.source.filename
- info.short_src = filename
- info.source = FILE_CACHE[filename]
- ok, linedefined = pcall(lua_line_to_nomsu_line, info.short_src, info.linedefined)
- if ok then info.linedefined = linedefined
- ok, currentline = pcall(lua_line_to_nomsu_line, info.short_src, info.currentline)
- --if ok then info.currentline = currentline
- ]=]
return info
print_err_msg = (error_message, stack_offset=2)->