diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-30 13:07:08 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-30 13:07:15 -0700 |
| commit | f9229c5e91ee505cefd48935c84d82f607110284 (patch) | |
| tree | c771485f471bbe7ff96fed1111473771109c202d /nomsu.lua | |
| parent | e5d9879a7972fa09e8c9e8f88642bbcc27e0c5a1 (diff) | |
Better parse error reporting.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -190,6 +190,10 @@ do if seen_errors[start_pos] then return true end + if utils.size(seen_errors) >= 10 then + seen_errors[start_pos + 1] = colored.bright(colored.yellow(colored.onred("Too many errors, canceling parsing..."))) + return #src + end local err_pos = start_pos local text_loc = userdata.source:sub(err_pos, err_pos) local line_no = text_loc:get_line_number() @@ -197,14 +201,16 @@ do local prev_line = line_no == 1 and "" or src:sub(LINE_STARTS[src][line_no - 1] or 1, LINE_STARTS[src][line_no] - 2) local err_line = src:sub(LINE_STARTS[src][line_no], (LINE_STARTS[src][line_no + 1] or 0) - 2) local next_line = src:sub(LINE_STARTS[src][line_no + 1] or -1, (LINE_STARTS[src][line_no + 2] or 0) - 2) - local pointer = ("-"):rep(err_pos - LINE_STARTS[src][line_no]) .. "^" - err_msg = (err_msg or "Parse error") .. " at " .. tostring(userdata.source.filename) .. ":" .. tostring(line_no) .. ":\n" + local i = err_pos - LINE_STARTS[src][line_no] + local pointer = ("-"):rep(i) .. "^" + err_msg = colored.bright(colored.yellow(colored.onred((err_msg or "Parse error") .. " at " .. tostring(userdata.source.filename) .. ":" .. tostring(line_no) .. ":"))) if #prev_line > 0 then - err_msg = err_msg .. ("\n" .. prev_line) + err_msg = err_msg .. ("\n" .. colored.dim(prev_line)) end - err_msg = err_msg .. "\n" .. tostring(err_line) .. "\n" .. tostring(pointer) + err_line = colored.white(err_line:sub(1, i)) .. colored.bright(colored.red(err_line:sub(i + 1, i + 1))) .. colored.dim(err_line:sub(i + 2, -1)) + err_msg = err_msg .. "\n" .. tostring(err_line) .. "\n" .. tostring(colored.red(pointer)) if #next_line > 0 then - err_msg = err_msg .. ("\n" .. next_line) + err_msg = err_msg .. ("\n" .. colored.dim(next_line)) end seen_errors[start_pos] = err_msg return true @@ -326,7 +332,8 @@ do end errors = _accum_0 end - error(concat(errors, "\n\n"), 0) + io.stderr:write(concat(errors, "\n\n") .. "\n") + os.exit() end return tree end, |
