diff options
Diffstat (limited to 'relabel.lua')
-rw-r--r-- | relabel.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/relabel.lua b/relabel.lua index 87269be..642b0fe 100644 --- a/relabel.lua +++ b/relabel.lua | |||
@@ -241,6 +241,13 @@ 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 mm.T(tlabels[f]) | ||
249 | end | ||
250 | |||
244 | local exp = m.P{ "Exp", | 251 | local exp = m.P{ "Exp", |
245 | Exp = S * ( m.V"Grammar" | 252 | Exp = S * ( m.V"Grammar" |
246 | + (m.V"Seq" * (S * ((m.C(m.P"//" + "/") * m.Ct(m.V"Labels")) + (m.C"/" * m.Cc(false))) | 253 | + (m.V"Seq" * (S * ((m.C(m.P"//" + "/") * m.Ct(m.V"Labels")) + (m.C"/" * m.Cc(false))) |
@@ -260,6 +267,7 @@ local exp = m.P{ "Exp", | |||
260 | + m.P"?" * m.Cc(-1, mt.__pow) | 267 | + m.P"?" * m.Cc(-1, mt.__pow) |
261 | + "^" * expect( m.Cg(num * m.Cc(mult)) | 268 | + "^" * expect( m.Cg(num * m.Cc(mult)) |
262 | + m.Cg(m.C(m.S"+-" * m.R"09"^1) * m.Cc(mt.__pow) | 269 | + m.Cg(m.C(m.S"+-" * m.R"09"^1) * m.Cc(mt.__pow) |
270 | + name * m.Cc"lab" | ||
263 | ), | 271 | ), |
264 | "ExpNum") | 272 | "ExpNum") |
265 | + "->" * expect(S * ( m.Cg((String + num) * m.Cc(mt.__div)) | 273 | + "->" * expect(S * ( m.Cg((String + num) * m.Cc(mt.__div)) |
@@ -270,7 +278,7 @@ local exp = m.P{ "Exp", | |||
270 | + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), | 278 | + "=>" * expect(S * m.Cg(Def / getdef * m.Cc(m.Cmt)), |
271 | "ExpName1") | 279 | "ExpName1") |
272 | ) | 280 | ) |
273 | )^0, function (a,b,f) return f(a,b) end ); | 281 | )^0, function (a,b,f) if f == "lab" then return a + getlab(b) else return f(a,b) end end ); |
274 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") | 282 | Primary = "(" * expect(m.V"Exp", "ExpPatt4") * expect(S * ")", "MisClose1") |
275 | + String / mm.P | 283 | + String / mm.P |
276 | + Class | 284 | + Class |
@@ -293,7 +301,7 @@ local exp = m.P{ "Exp", | |||
293 | + m.P"." * m.Cc(any) | 301 | + m.P"." * m.Cc(any) |
294 | + (name * -arrow + "<" * expect(name, "ExpName3") | 302 | + (name * -arrow + "<" * expect(name, "ExpName3") |
295 | * expect(">", "MisClose6")) * m.Cb("G") / NT; | 303 | * expect(">", "MisClose6")) * m.Cb("G") / NT; |
296 | Label = num + name / function (f) return tlabels[f] end; | 304 | Label = num + name / function (f) return getlab(f) end; |
297 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); | 305 | Definition = name * arrow * expect(m.V"Exp", "ExpPatt8"); |
298 | Grammar = m.Cg(m.Cc(true), "G") | 306 | Grammar = m.Cg(m.Cc(true), "G") |
299 | * m.Cf(m.V"Definition" / firstdef * (S * m.Cg(m.V"Definition"))^0, | 307 | * m.Cf(m.V"Definition" / firstdef * (S * m.Cg(m.V"Definition"))^0, |