diff options
author | Undecidable Robot <undecidabot@gmail.com> | 2016-05-07 21:54:31 +0800 |
---|---|---|
committer | Undecidable Robot <undecidabot@gmail.com> | 2016-05-07 21:54:31 +0800 |
commit | a3e8fbe233e7b3ca7a4e72ec03a495da79450b17 (patch) | |
tree | e47e898230675263e97cb07946ea25c127d8dfac /relabel.lua | |
parent | 0233268dd31b7d708d6123167c0d97dc1c836dd4 (diff) | |
download | lpeglabel-a3e8fbe233e7b3ca7a4e72ec03a495da79450b17.tar.gz lpeglabel-a3e8fbe233e7b3ca7a4e72ec03a495da79450b17.tar.bz2 lpeglabel-a3e8fbe233e7b3ca7a4e72ec03a495da79450b17.zip |
Adding line and column number to error messages
Diffstat (limited to '')
-rw-r--r-- | relabel.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/relabel.lua b/relabel.lua index 12de21e..3748da6 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -223,11 +223,20 @@ local exp = m.P{ "Exp", | |||
223 | 223 | ||
224 | local pattern = S * m.Cg(m.Cc(false), "G") * (exp + m.T(1)) / mm.P * (-any + m.T(2)) | 224 | local pattern = S * m.Cg(m.Cc(false), "G") * (exp + m.T(1)) / mm.P * (-any + m.T(2)) |
225 | 225 | ||
226 | local function lineno (s, i) | ||
227 | if i == 1 then return 1, 1 end | ||
228 | local rest, num = s:sub(1,i):gsub("[^\n]*\n", "") | ||
229 | local r = #rest | ||
230 | return 1 + num, r ~= 0 and r or 1 | ||
231 | end | ||
226 | 232 | ||
227 | local function compile (p, defs) | 233 | local function compile (p, defs) |
228 | if mm.type(p) == "pattern" then return p end -- already compiled | 234 | if mm.type(p) == "pattern" then return p end -- already compiled |
229 | local cp, label = pattern:match(p, 1, defs) | 235 | local cp, label, suffix = pattern:match(p, 1, defs) |
230 | if not cp then error("incorrect pattern " .. label, 3) end | 236 | if not cp then |
237 | local line, col = lineno(p, p:len() - suffix:len()) | ||
238 | error("incorrect pattern on line " .. line .. " col " .. col .. ": " .. label, 3) | ||
239 | end | ||
231 | return cp | 240 | return cp |
232 | end | 241 | end |
233 | 242 | ||