aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-09-14 14:54:55 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-09-14 14:55:00 -0700
commit3e2844ef62d1b1fd099a790a0927e0768a2a846b (patch)
treeccf8efbd2eae800d016da6f2bf27d7d6a3396f08
parent9bba7dd2cd5860c8b527f10044f7e1c4d1a4a0e2 (diff)
Added error truncating.
-rw-r--r--nomsu_compiler.lua61
-rw-r--r--nomsu_compiler.moon25
2 files changed, 51 insertions, 35 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index bfeca01..b71eab0 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -184,40 +184,57 @@ 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 = ""
- for k, v in pairs(t) do
- local _continue_0 = false
- repeat
- if not (AST.is_syntax_tree(v)) then
+ }))
+ else
+ for k, v in pairs(t) do
+ local _continue_0 = false
+ repeat
+ if not (AST.is_syntax_tree(v)) then
+ _continue_0 = true
+ break
+ end
+ find_errors(v)
_continue_0 = true
+ until true
+ if not _continue_0 then
break
end
- local err = find_errors(v)
- if #err > 0 then
- if #errs > 0 then
- errs = errs .. "\n\n"
- end
- errs = errs .. err
- end
- _continue_0 = true
- until true
- if not _continue_0 then
- break
end
end
- return errs
end
- local errs = find_errors(tree)
+ 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
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index ea79843..9fcf796 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -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 = ""
- 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
-
- errs = find_errors(tree)
+ else
+ for k,v in pairs(t)
+ continue unless AST.is_syntax_tree(v)
+ find_errors(v)
+
+ 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