diff options
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -493,8 +493,8 @@ local function f_term (v1, op, v2, d) | |||
493 | end | 493 | end |
494 | 494 | ||
495 | G = m.P{ "Exp", | 495 | G = 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 |
867 | function f (x) return x + 1 end | 867 | function f (x) return x + 1 end |
868 | assert(m.match(m.Cf(m.Cc(0) * m.C(1)^0, f), "alo alo") == 7) | 868 | assert(m.match(m.Cf(m.Cc(0) * m.C(1)^0, f), "alo alo") == 7) |
869 | assert(m.match(m.Cc(0) * (m.C(1) % f)^0, "alo alo") == 7) | ||
869 | 870 | ||
870 | t = {m.match(m.Cf(m.Cc(1,2,3), error), "")} | 871 | t = {m.match(m.Cf(m.Cc(1,2,3), error), "")} |
871 | checkeq(t, {1}) | 872 | checkeq(t, {1}) |
@@ -875,7 +876,7 @@ t = p:match("a=b;c=du;xux=yuy;") | |||
875 | checkeq(t, {a="b", c="du", xux="yuy"}) | 876 | checkeq(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 |
881 | checkerr("no initial value", m.match, m.Cf(m.P(5), print), 'aaaaaa') | 882 | checkerr("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') | |||
883 | checkerr("no initial value", m.match, m.Cf(m.P(500), print), | 884 | checkerr("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 | |
887 | checkerr("no initial value", m.match, m.Cf(m.P(1) / {}, print), "alo") | 888 | -- errors in accumulator capture |
889 | |||
890 | -- no initial capture | ||
891 | checkerr("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) | ||
893 | checkerr("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 |