aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-06-06 17:50:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-06-06 17:50:31 -0300
commite31e13f59ef1a4df1698b15ff1fe0198553cc3c2 (patch)
treec16ea4f41bdd378734afd4e475d7d7973a5a2b5d /test.lua
parent44fab2a44d06a956c3121ceba2b39ca7b00dc428 (diff)
downloadlpeg-e31e13f59ef1a4df1698b15ff1fe0198553cc3c2.tar.gz
lpeg-e31e13f59ef1a4df1698b15ff1fe0198553cc3c2.tar.bz2
lpeg-e31e13f59ef1a4df1698b15ff1fe0198553cc3c2.zip
First implementation for the accumulator capture
Diffstat (limited to 'test.lua')
-rwxr-xr-xtest.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/test.lua b/test.lua
index d31a69f..cd85b31 100755
--- a/test.lua
+++ b/test.lua
@@ -493,8 +493,8 @@ local function f_term (v1, op, v2, d)
493end 493end
494 494
495G = m.P{ "Exp", 495G = m.P{ "Exp",
496 Exp = m.Cf(V"Factor" * m.Cg(FactorOp * V"Factor")^0, f_factor); 496 Exp = V"Factor" * (FactorOp * V"Factor" % f_factor)^0;
497 Factor = m.Cf(V"Term" * m.Cg(TermOp * V"Term")^0, f_term); 497 Factor = V"Term" * (TermOp * V"Term" % f_term)^0;
498 Term = Number / tonumber + Open * V"Exp" * Close; 498 Term = Number / tonumber + Open * V"Exp" * Close;
499} 499}
500 500
@@ -866,6 +866,7 @@ print"+"
866-- accumulator capture 866-- accumulator capture
867function f (x) return x + 1 end 867function f (x) return x + 1 end
868assert(m.match(m.Cf(m.Cc(0) * m.C(1)^0, f), "alo alo") == 7) 868assert(m.match(m.Cf(m.Cc(0) * m.C(1)^0, f), "alo alo") == 7)
869assert(m.match(m.Cc(0) * (m.C(1) % f)^0, "alo alo") == 7)
869 870
870t = {m.match(m.Cf(m.Cc(1,2,3), error), "")} 871t = {m.match(m.Cf(m.Cc(1,2,3), error), "")}
871checkeq(t, {1}) 872checkeq(t, {1})
@@ -875,7 +876,7 @@ t = p:match("a=b;c=du;xux=yuy;")
875checkeq(t, {a="b", c="du", xux="yuy"}) 876checkeq(t, {a="b", c="du", xux="yuy"})
876 877
877 878
878-- errors in accumulator capture 879-- errors in fold capture
879 880
880-- no initial capture 881-- no initial capture
881checkerr("no initial value", m.match, m.Cf(m.P(5), print), 'aaaaaa') 882checkerr("no initial value", m.match, m.Cf(m.P(5), print), 'aaaaaa')
@@ -883,8 +884,14 @@ checkerr("no initial value", m.match, m.Cf(m.P(5), print), 'aaaaaa')
883checkerr("no initial value", m.match, m.Cf(m.P(500), print), 884checkerr("no initial value", m.match, m.Cf(m.P(500), print),
884 string.rep('a', 600)) 885 string.rep('a', 600))
885 886
886-- nested capture produces no initial value 887
887checkerr("no initial value", m.match, m.Cf(m.P(1) / {}, print), "alo") 888-- errors in accumulator capture
889
890-- no initial capture
891checkerr("no previous value", m.match, m.P(5) % print, 'aaaaaa')
892-- no initial capture (very long match forces fold to be a pair open-close)
893checkerr("no previous value", m.match, m.P(500) % print,
894 string.rep('a', 600))
888 895
889 896
890-- tests for loop checker 897-- tests for loop checker