diff options
author | Sérgio Medeiros <sqmedeiros@gmail.com> | 2016-08-19 08:54:21 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-19 08:54:21 -0300 |
commit | bfc1b51c5f86a253f0177bbc2163b97767921d83 (patch) | |
tree | d1bfb15252648b394397988f81cb69baf45c8481 | |
parent | 28a44f01cb7a75068b75a99c0badb3abdaf7047a (diff) | |
parent | bee5ae4f5e511bc29918aebc95cfc04214af244d (diff) | |
download | lpeglabel-bfc1b51c5f86a253f0177bbc2163b97767921d83.tar.gz lpeglabel-bfc1b51c5f86a253f0177bbc2163b97767921d83.tar.bz2 lpeglabel-bfc1b51c5f86a253f0177bbc2163b97767921d83.zip |
Merge pull request #12 from undecidabot/relabel-recovery
Moving recovery to a separate branch
-rw-r--r-- | relabel.lua | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/relabel.lua b/relabel.lua index ff2e486..9fc4b01 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -82,15 +82,13 @@ for i, err in ipairs(errinfo) do | |||
82 | labels[err[1]] = i | 82 | labels[err[1]] = i |
83 | end | 83 | end |
84 | 84 | ||
85 | local syntaxerrs = {} | ||
86 | |||
87 | local function expect (pattern, labelname) | 85 | local function expect (pattern, labelname) |
88 | local label = labels[labelname] | 86 | local label = labels[labelname] |
89 | local record = function (input, pos) | 87 | local record = function (input, pos, syntaxerrs) |
90 | tinsert(syntaxerrs, { label = label, pos = pos }) | 88 | tinsert(syntaxerrs, { label = label, pos = pos }) |
91 | return true | 89 | return true |
92 | end | 90 | end |
93 | return pattern + m.Cmt("", record) * m.T(label) | 91 | return pattern + m.Cmt(m.Carg(2), record) * m.T(label) |
94 | end | 92 | end |
95 | 93 | ||
96 | 94 | ||
@@ -247,14 +245,14 @@ local skip = m.P { "Skip", | |||
247 | + '"' * (-m.P'"' * m.V"Ignored")^0 * '"'; | 245 | + '"' * (-m.P'"' * m.V"Ignored")^0 * '"'; |
248 | } | 246 | } |
249 | 247 | ||
250 | local ignore = m.Cmt(any, function (input, pos) | 248 | local ignore = m.Cmt(m.Carg(2), function (input, pos, syntaxerrs) |
251 | return syntaxerrs[#syntaxerrs].pos, dummy | 249 | return syntaxerrs[#syntaxerrs].pos, dummy |
252 | end) | 250 | end) |
253 | 251 | ||
254 | local pointAtStart = m.Cmt(any, function (input, pos) | 252 | local pointAtStart = m.Cmt(m.Carg(2), function (input, pos, syntaxerrs) |
255 | -- like ignore but makes the last syntax error point at the start | 253 | -- like ignore but makes the last syntax error point at the start |
256 | local ret = syntaxerrs[#syntaxerrs].pos | 254 | local ret = syntaxerrs[#syntaxerrs].pos |
257 | syntaxerrs[#syntaxerrs].pos = pos-1 | 255 | syntaxerrs[#syntaxerrs].pos = pos |
258 | return ret, dummy | 256 | return ret, dummy |
259 | end) | 257 | end) |
260 | 258 | ||
@@ -373,7 +371,8 @@ end | |||
373 | local function compile (p, defs) | 371 | local function compile (p, defs) |
374 | if mm.type(p) == "pattern" then return p end -- already compiled | 372 | if mm.type(p) == "pattern" then return p end -- already compiled |
375 | p = p .. " " -- for better reporting of column numbers in errors when at EOF | 373 | p = p .. " " -- for better reporting of column numbers in errors when at EOF |
376 | local ok, cp, label, suffix = pcall(function() return pattern:match(p, 1, defs) end) | 374 | local syntaxerrs = {} |
375 | local ok, cp, label, suffix = pcall(function() return pattern:match(p, 1, defs, syntaxerrs) end) | ||
377 | if not ok and #syntaxerrs == 0 then | 376 | if not ok and #syntaxerrs == 0 then |
378 | if type(cp) == "string" then | 377 | if type(cp) == "string" then |
379 | cp = cp:gsub("^[^:]+:[^:]+: ", "") | 378 | cp = cp:gsub("^[^:]+:[^:]+: ", "") |
@@ -389,7 +388,6 @@ local function compile (p, defs) | |||
389 | tinsert(errors, lines[line]) | 388 | tinsert(errors, lines[line]) |
390 | tinsert(errors, rep(" ", col-1) .. "^") | 389 | tinsert(errors, rep(" ", col-1) .. "^") |
391 | end | 390 | end |
392 | syntaxerrs = {} | ||
393 | error("syntax error(s) in pattern\n" .. concat(errors, "\n"), 3) | 391 | error("syntax error(s) in pattern\n" .. concat(errors, "\n"), 3) |
394 | end | 392 | end |
395 | return cp | 393 | return cp |