Added error truncating.

This commit is contained in:
Bruce Hill 2018-09-14 14:54:55 -07:00
parent 9bba7dd2cd
commit 3e2844ef62
2 changed files with 50 additions and 34 deletions

View File

@ -184,15 +184,14 @@ do
local find_errors
find_errors = function(t)
if t.type == "Error" then
return pretty_error({
return coroutine.yield(pretty_error({
error = t.error,
hint = t.hint,
source = t:get_source_code(),
start = t.source.start,
stop = t.source.stop
})
end
local errs = ""
}))
else
for k, v in pairs(t) do
local _continue_0 = false
repeat
@ -200,24 +199,42 @@ do
_continue_0 = true
break
end
local err = find_errors(v)
if #err > 0 then
if #errs > 0 then
errs = errs .. "\n\n"
end
errs = errs .. err
end
find_errors(v)
_continue_0 = true
until true
if not _continue_0 then
break
end
end
return errs
end
local errs = find_errors(tree)
end
local errs
do
local _accum_0 = { }
local _len_0 = 1
for err in coroutine.wrap(function()
return find_errors(tree)
end) do
_accum_0[_len_0] = err
_len_0 = _len_0 + 1
end
errs = _accum_0
end
if #errs > 4 then
local num_errs = #errs
do
local _accum_0 = { }
local _len_0 = 1
for i = 1, 3 do
_accum_0[_len_0] = errs[i]
_len_0 = _len_0 + 1
end
errs = _accum_0
end
table.insert(errs, "\027[31;1m +" .. tostring(num_errs - #errs) .. " additional errors...\027[0m\n")
end
if #errs > 0 then
error(errs, 0)
error(table.concat(errs, '\n\n'), 0)
end
return tree
end

View File

@ -103,25 +103,24 @@ with NomsuCompiler
parse = Parsers[syntax_version] or Parsers[max_parser_version]
tree = parse(nomsu_code, source.filename)
pretty_error = require("pretty_errors")
-- TODO: truncate
find_errors = (t)->
if t.type == "Error"
return pretty_error{
coroutine.yield pretty_error{
error:t.error, hint:t.hint, source:t\get_source_code!
start:t.source.start, stop:t.source.stop
}
errs = ""
else
for k,v in pairs(t)
continue unless AST.is_syntax_tree(v)
err = find_errors(v)
if #err > 0
if #errs > 0 then errs ..="\n\n"
errs ..= err
return errs
find_errors(v)
errs = find_errors(tree)
errs = [err for err in coroutine.wrap(-> find_errors(tree))]
if #errs > 4
num_errs = #errs
errs = [errs[i] for i=1,3]
table.insert(errs, "\027[31;1m +#{num_errs-#errs} additional errors...\027[0m\n")
if #errs > 0
error(errs, 0)
error(table.concat(errs, '\n\n'), 0)
return tree
.can_optimize = -> false