diff options
Diffstat (limited to 'relabel.lua')
-rw-r--r-- | relabel.lua | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/relabel.lua b/relabel.lua index abb3c7f..6a676b9 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -241,12 +241,6 @@ local function choicerec (...) | |||
241 | return p | 241 | return p |
242 | end | 242 | end |
243 | 243 | ||
244 | local function getlab (f) | ||
245 | if not tlabels[f] then | ||
246 | error("undefined label: " .. f) | ||
247 | end | ||
248 | return tlabels[f] | ||
249 | end | ||
250 | 244 | ||
251 | local exp = m.P{ "Exp", | 245 | local exp = m.P{ "Exp", |
252 | Exp = S * ( m.V"Grammar" | 246 | Exp = S * ( m.V"Grammar" |
@@ -278,7 +272,7 @@ local exp = m.P{ "Exp", | |||
278 | + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), | 272 | + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), |
279 | "ExpName1") | 273 | "ExpName1") |
280 | ) | 274 | ) |
281 | )^0, function (a,b,f) if f == "lab" then return a + mm.T(getlab(b)) else return f(a,b) end end ); | 275 | )^0, function (a,b,f) if f == "lab" then return a + mm.T(b) else return f(a,b) end end ); |
282 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") | 276 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") |
283 | + String / mm.P | 277 | + String / mm.P |
284 | + Class | 278 | + Class |
@@ -301,7 +295,7 @@ local exp = m.P{ "Exp", | |||
301 | + m.P"." * m.Cc(any) | 295 | + m.P"." * m.Cc(any) |
302 | + (name * -arrow + "<" * expect(name, "ExpName3") | 296 | + (name * -arrow + "<" * expect(name, "ExpName3") |
303 | * expect(">", "MisClose6")) * m.Cb("G") / NT; | 297 | * expect(">", "MisClose6")) * m.Cb("G") / NT; |
304 | Label = num + name / function (f) return getlab(f) end; | 298 | Label = num + name; |
305 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); | 299 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); |
306 | Grammar = m.Cg(m.Cc(true), "G") | 300 | Grammar = m.Cg(m.Cc(true), "G") |
307 | * m.Cf(m.V"Definition" / firstdef * (S * m.Cg(m.V"Definition"))^0, | 301 | * m.Cf(m.V"Definition" / firstdef * (S * m.Cg(m.V"Definition"))^0, |
@@ -342,7 +336,7 @@ end | |||
342 | local function compile (p, defs) | 336 | local function compile (p, defs) |
343 | if mm.type(p) == "pattern" then return p end -- already compiled | 337 | if mm.type(p) == "pattern" then return p end -- already compiled |
344 | p = p .. " " -- for better reporting of column numbers in errors when at EOF | 338 | p = p .. " " -- for better reporting of column numbers in errors when at EOF |
345 | local ok, cp, label, suffix = pcall(function() return pattern:match(p, 1, defs) end) | 339 | local ok, cp, label, poserr = pcall(function() return pattern:match(p, 1, defs) end) |
346 | if not ok and cp then | 340 | if not ok and cp then |
347 | if type(cp) == "string" then | 341 | if type(cp) == "string" then |
348 | cp = cp:gsub("^[^:]+:[^:]+: ", "") | 342 | cp = cp:gsub("^[^:]+:[^:]+: ", "") |
@@ -351,8 +345,7 @@ local function compile (p, defs) | |||
351 | end | 345 | end |
352 | if not cp then | 346 | if not cp then |
353 | local lines = splitlines(p) | 347 | local lines = splitlines(p) |
354 | local line, col = lineno(p, #p - #suffix + 1) | 348 | local line, col = lineno(p, poserr) |
355 | --local line, col = calcline(p, #p - #suffix + 1) | ||
356 | local err = {} | 349 | local err = {} |
357 | tinsert(err, "L" .. line .. ":C" .. col .. ": " .. errmsgs[label]) | 350 | tinsert(err, "L" .. line .. ":C" .. col .. ": " .. errmsgs[label]) |
358 | tinsert(err, lines[line]) | 351 | tinsert(err, lines[line]) |