aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--relabelrec.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/relabelrec.lua b/relabelrec.lua
index 16ca7f0..af1a440 100644
--- a/relabelrec.lua
+++ b/relabelrec.lua
@@ -31,7 +31,7 @@ local errinfo = {
31 {"NoPatt", "no pattern found"}, 31 {"NoPatt", "no pattern found"},
32 {"ExtraChars", "unexpected characters after the pattern"}, 32 {"ExtraChars", "unexpected characters after the pattern"},
33 33
34 {"ExpPatt1", "expected a pattern after '/' or the label(s)"}, 34 {"ExpPatt1", "expected a pattern after '/' or '//{...}'"},
35 35
36 {"ExpPatt2", "expected a pattern after '&'"}, 36 {"ExpPatt2", "expected a pattern after '&'"},
37 {"ExpPatt3", "expected a pattern after '!'"}, 37 {"ExpPatt3", "expected a pattern after '!'"},
@@ -305,6 +305,14 @@ local function lineno (s, i)
305 return 1 + num, (r ~= 0 and r or 1) + adjustment 305 return 1 + num, (r ~= 0 and r or 1) + adjustment
306end 306end
307 307
308local function calcline (s, i)
309 if i == 1 then return 1, 1 end
310 local rest, line = s:sub(1,i):gsub("[^\n]*\n", "")
311 local col = #rest
312 return 1 + line, col ~= 0 and col or 1
313end
314
315
308local function splitlines(str) 316local function splitlines(str)
309 local t = {} 317 local t = {}
310 local function helper(line) tinsert(t, line) return "" end 318 local function helper(line) tinsert(t, line) return "" end
@@ -325,6 +333,7 @@ local function compile (p, defs)
325 if not cp then 333 if not cp then
326 local lines = splitlines(p) 334 local lines = splitlines(p)
327 local line, col = lineno(p, #p - #suffix + 1) 335 local line, col = lineno(p, #p - #suffix + 1)
336 --local line, col = calcline(p, #p - #suffix + 1)
328 local err = {} 337 local err = {}
329 tinsert(err, "L" .. line .. ":C" .. col .. ": " .. errmsgs[label]) 338 tinsert(err, "L" .. line .. ":C" .. col .. ": " .. errmsgs[label])
330 tinsert(err, lines[line]) 339 tinsert(err, lines[line])
@@ -372,13 +381,6 @@ local function setlabels (t)
372 tlabels = t 381 tlabels = t
373end 382end
374 383
375local function calcline (s, i)
376 if i == 1 then return 1, 1 end
377 local rest, line = s:sub(1,i):gsub("[^\n]*\n", "")
378 local col = #rest
379 return 1 + line, col ~= 0 and col or 1
380end
381
382 384
383-- exported names 385-- exported names
384local re = { 386local re = {