aboutsummaryrefslogtreecommitdiff
path: root/relabel.lua
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 16:01:44 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2017-07-06 16:01:44 -0300
commite2a8e1c789a7a769c83a66d6fd2f191b0e465cba (patch)
treee2aecc3d439e44db98439c26cf23625da1bedb3f /relabel.lua
parenta36fe71ac0271d9013f76d9342f9a2fca40f64fc (diff)
downloadlpeglabel-e2a8e1c789a7a769c83a66d6fd2f191b0e465cba.tar.gz
lpeglabel-e2a8e1c789a7a769c83a66d6fd2f191b0e465cba.tar.bz2
lpeglabel-e2a8e1c789a7a769c83a66d6fd2f191b0e465cba.zip
Reintroducing the labeled ordered choice (tests without it passed)
Diffstat (limited to 'relabel.lua')
-rw-r--r--relabel.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/relabel.lua b/relabel.lua
index b02c95d..cfe5f2e 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 '/' or '//{...}'"}, 34 {"ExpPatt1", "expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{'"},
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 '!'"},
@@ -221,10 +221,28 @@ local function choicerec (...)
221 local n = #t 221 local n = #t
222 local p = t[1] 222 local p = t[1]
223 local i = 2 223 local i = 2
224 while i + 1 <= n do 224 --print("eu")
225 -- t[i] == false when there are no labels 225 --for i, v in ipairs(t) do
226 p = t[i] and mm.Rec(p, t[i+1], unpack(t[i])) or mt.__add(p, t[i+1]) 226 -- print(i, v)
227 i = i + 2 227 --end
228 --print"fim"
229
230 while i + 2 <= n do
231 -- t[i] is '/' or '//'
232 -- t[i+1] == false when there are no labels
233 -- t[i+2] is a pattern
234 if t[i] == '/' then
235 if not t[i+1] then
236 p = mt.__add(p, t[i+2])
237 --print("foi aqui", t[i], t[i+1], t[i+2])
238 --p:pcode()
239 else
240 p = mm.Lc(p, t[i+2], unpack(t[i+1]))
241 end
242 else -- t[i] is '//'
243 p = mm.Rec(p, t[i+2], unpack(t[i+1]))
244 end
245 i = i + 3
228 end 246 end
229 247
230 return p 248 return p
@@ -232,7 +250,7 @@ end
232 250
233local exp = m.P{ "Exp", 251local exp = m.P{ "Exp",
234 Exp = S * ( m.V"Grammar" 252 Exp = S * ( m.V"Grammar"
235 + (m.V"Seq" * (S * (("//" * m.Ct(m.V"Labels")) + ("/" * m.Cc(false))) 253 + (m.V"Seq" * (S * ((m.C(m.P"//" + "/") * m.Ct(m.V"Labels")) + (m.C"/" * m.Cc(false)))
236 * expect(S * m.V"Seq", "ExpPatt1") 254 * expect(S * m.V"Seq", "ExpPatt1")
237 )^0 255 )^0
238 ) / choicerec); 256 ) / choicerec);