diff --git a/lua-parser/parser.lua b/lua-parser/parser.lua index fcd880a..cb0cdb8 100644 --- a/lua-parser/parser.lua +++ b/lua-parser/parser.lua @@ -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 @@ -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