diff options
Diffstat (limited to 'relabel.lua')
-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 | ||