Skip to content

Commit

Permalink
Merge pull request #17 from logiceditor-com/avr/8279/detailed-errors
Browse files Browse the repository at this point in the history
lua-parser/parser.lua: add feature for returning the detailed error
  • Loading branch information
andremm committed Feb 3, 2023
2 parents cf573f0 + 20e9078 commit 818b79f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lua-parser/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ local G = { V"Lua",
PowOp = sym("^") / "pow";
}

local parser = {}
local parser = { detailed_errors = false }

local validator = require("lua-parser.validator")
local validate = validator.validate
Expand All @@ -467,8 +467,20 @@ function parser.parse (subject, filename)
lpeg.setmaxstack(1000)
local ast, label, errorpos = lpeg.match(G, subject, nil, errorinfo)
if not ast then
local errmsg = labels[label][2]
return ast, syntaxerror(errorinfo, errorpos, errmsg)
if parser.detailed_errors then
local re = require "relabel"
local line, col = re.calcline(subject, errorpos)
return ast, {
line = line;
column = col;
id = labels[label][1];
message = labels[label][2];
position = errorpos;
}
else
local errmsg = labels[label][2]
return ast, syntaxerror(errorinfo, errorpos, errmsg)
end
end
return validate(ast, errorinfo)
end
Expand Down

0 comments on commit 818b79f

Please sign in to comment.