aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSérgio Medeiros <sqmedeiros@gmail.com>2016-08-19 08:54:21 -0300
committerGitHub <noreply@github.com>2016-08-19 08:54:21 -0300
commitbfc1b51c5f86a253f0177bbc2163b97767921d83 (patch)
treed1bfb15252648b394397988f81cb69baf45c8481
parent28a44f01cb7a75068b75a99c0badb3abdaf7047a (diff)
parentbee5ae4f5e511bc29918aebc95cfc04214af244d (diff)
downloadlpeglabel-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.lua16
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
83end 83end
84 84
85local syntaxerrs = {}
86
87local function expect (pattern, labelname) 85local 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)
94end 92end
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
250local ignore = m.Cmt(any, function (input, pos) 248local ignore = m.Cmt(m.Carg(2), function (input, pos, syntaxerrs)
251 return syntaxerrs[#syntaxerrs].pos, dummy 249 return syntaxerrs[#syntaxerrs].pos, dummy
252end) 250end)
253 251
254local pointAtStart = m.Cmt(any, function (input, pos) 252local 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
259end) 257end)
260 258
@@ -373,7 +371,8 @@ end
373local function compile (p, defs) 371local 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