diff options
| author | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-12-16 11:05:04 -0300 |
|---|---|---|
| committer | Sergio Queiroz <sqmedeiros@gmail.com> | 2016-12-16 11:05:04 -0300 |
| commit | 054b33b35f03180732f56f0fdd98f1bf477d2f6a (patch) | |
| tree | 7791e84e771f932d5f4035397bdf0210b04881c3 | |
| parent | 85ec338beacb7d9e25ff27205d7c05723e173edd (diff) | |
| download | lpeglabel-054b33b35f03180732f56f0fdd98f1bf477d2f6a.tar.gz lpeglabel-054b33b35f03180732f56f0fdd98f1bf477d2f6a.tar.bz2 lpeglabel-054b33b35f03180732f56f0fdd98f1bf477d2f6a.zip | |
Updating error message related to / and //{}
| -rw-r--r-- | relabelrec.lua | 18 |
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 |
| 306 | end | 306 | end |
| 307 | 307 | ||
| 308 | local 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 | ||
| 313 | end | ||
| 314 | |||
| 315 | |||
| 308 | local function splitlines(str) | 316 | local 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 |
| 373 | end | 382 | end |
| 374 | 383 | ||
| 375 | local 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 | ||
| 380 | end | ||
| 381 | |||
| 382 | 384 | ||
| 383 | -- exported names | 385 | -- exported names |
| 384 | local re = { | 386 | local re = { |
