aboutsummaryrefslogtreecommitdiff
path: root/relabel.lua
diff options
context:
space:
mode:
Diffstat (limited to 'relabel.lua')
-rw-r--r--relabel.lua38
1 files changed, 3 insertions, 35 deletions
diff --git a/relabel.lua b/relabel.lua
index 6a676b9..3188163 100644
--- a/relabel.lua
+++ b/relabel.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 '/' and '//{...}', or the label(s) after '/{' and '//{'"}, 34 {"ExpPatt1", "expected a pattern after '/'"},
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 '!'"},
@@ -52,8 +52,7 @@ local errinfo = {
52 {"ExpName2", "expected the name of a rule after '=' (no space)"}, 52 {"ExpName2", "expected the name of a rule after '=' (no space)"},
53 {"ExpName3", "expected the name of a rule after '<' (no space)"}, 53 {"ExpName3", "expected the name of a rule after '<' (no space)"},
54 54
55 {"ExpLab1", "expected at least one label after '{'"}, 55 {"ExpLab1", "expected a label after '{'"},
56 {"ExpLab2", "expected a label after the comma"},
57 56
58 {"ExpNameOrLab", "expected a name or label after '%' (no space)"}, 57 {"ExpNameOrLab", "expected a name or label after '%' (no space)"},
59 58
@@ -216,41 +215,10 @@ local function NT (n, b)
216 end 215 end
217end 216end
218 217
219local function choicerec (...)
220 local t = { ... }
221 local n = #t
222 local p = t[1]
223 local i = 2
224
225 while i + 2 <= n do
226 -- t[i] is '/' or '//'
227 -- t[i+1] == false when there are no labels
228 -- t[i+2] is a pattern
229 if t[i] == '/' then
230 if not t[i+1] then
231 p = mt.__add(p, t[i+2])
232 else
233 p = mm.Lc(p, t[i+2], unpack(t[i+1]))
234 end
235 else -- t[i] is '//'
236 p = mm.Rec(p, t[i+2], unpack(t[i+1]))
237 end
238 i = i + 3
239 end
240
241 return p
242end
243
244 218
245local exp = m.P{ "Exp", 219local exp = m.P{ "Exp",
246 Exp = S * ( m.V"Grammar" 220 Exp = S * ( m.V"Grammar"
247 + (m.V"Seq" * (S * ((m.C(m.P"//" + "/") * m.Ct(m.V"Labels")) + (m.C"/" * m.Cc(false))) 221 + m.Cf(m.V"Seq" * (S * "/" * expect(S * m.V"Seq", "ExpPatt1"))^0, mt.__add) );
248 * expect(S * m.V"Seq", "ExpPatt1")
249 )^0
250 ) / choicerec);
251 Labels = m.P"{" * expect(S * m.V"Label", "ExpLab1")
252 * (S * "," * expect(S * m.V"Label", "ExpLab2"))^0
253 * expect(S * "}", "MisClose7");
254 Seq = m.Cf(m.Cc(m.P"") * m.V"Prefix" * (S * m.V"Prefix")^0, mt.__mul); 222 Seq = m.Cf(m.Cc(m.P"") * m.V"Prefix" * (S * m.V"Prefix")^0, mt.__mul);
255 Prefix = "&" * expect(S * m.V"Prefix", "ExpPatt2") / mt.__len 223 Prefix = "&" * expect(S * m.V"Prefix", "ExpPatt2") / mt.__len
256 + "!" * expect(S * m.V"Prefix", "ExpPatt3") / mt.__unm 224 + "!" * expect(S * m.V"Prefix", "ExpPatt3") / mt.__unm