diff options
author | sergio <sqmedeiros@gmail.com> | 2016-07-22 15:13:58 -0300 |
---|---|---|
committer | sergio <sqmedeiros@gmail.com> | 2016-07-22 15:13:58 -0300 |
commit | abb26cdfd3d44e7b10ec001f2afb980616c71573 (patch) | |
tree | 86a5caade53be9dc1d3b5cefb3d212f9096842b4 /testlabel.lua | |
parent | 28a44f01cb7a75068b75a99c0badb3abdaf7047a (diff) | |
download | lpeglabel-abb26cdfd3d44e7b10ec001f2afb980616c71573.tar.gz lpeglabel-abb26cdfd3d44e7b10ec001f2afb980616c71573.tar.bz2 lpeglabel-abb26cdfd3d44e7b10ec001f2afb980616c71573.zip |
Changing the semantics of labels to recovery/resume (ILabChoice does not work)
Diffstat (limited to 'testlabel.lua')
-rw-r--r-- | testlabel.lua | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/testlabel.lua b/testlabel.lua index db16354..cbe623c 100644 --- a/testlabel.lua +++ b/testlabel.lua | |||
@@ -32,6 +32,7 @@ local g = m.P{ | |||
32 | r, l, serror = g:match(s) | 32 | r, l, serror = g:match(s) |
33 | assert(r == nil and l == 1 and serror == "abc") | 33 | assert(r == nil and l == 1 and serror == "abc") |
34 | 34 | ||
35 | --[==[ TODO: labeled choice does not work anymore | ||
35 | -- throws a label that is not caught by labeled choice | 36 | -- throws a label that is not caught by labeled choice |
36 | p = m.Lc(m.T(2), m.P"a", 1, 3) | 37 | p = m.Lc(m.T(2), m.P"a", 1, 3) |
37 | r, l, serror = p:match(s) | 38 | r, l, serror = p:match(s) |
@@ -188,6 +189,7 @@ assert(p:match("abc") == 2) | |||
188 | 189 | ||
189 | r, l, serror = p:match("") | 190 | r, l, serror = p:match("") |
190 | assert(r == nil and l == 0 and serror == "") | 191 | assert(r == nil and l == 0 and serror == "") |
192 | ]==] | ||
191 | 193 | ||
192 | -- testing the limit of labels | 194 | -- testing the limit of labels |
193 | p = m.T(0) | 195 | p = m.T(0) |
@@ -209,6 +211,7 @@ assert(r == false) | |||
209 | 211 | ||
210 | print("+") | 212 | print("+") |
211 | 213 | ||
214 | --[==[ TODO: labeled choice does not work anymore | ||
212 | --[[ grammar based on Figure 8 of paper submitted to SCP | 215 | --[[ grammar based on Figure 8 of paper submitted to SCP |
213 | S -> S0 /{1} ID /{2} ID '=' Exp /{3} 'unsigned'* 'int' ID /{4} 'unsigned'* ID ID / %error | 216 | S -> S0 /{1} ID /{2} ID '=' Exp /{3} 'unsigned'* 'int' ID /{4} 'unsigned'* ID ID / %error |
214 | S0 -> ID S1 / 'unsigned' S2 / 'int' %3 | 217 | S0 -> ID S1 / 'unsigned' S2 / 'int' %3 |
@@ -548,12 +551,12 @@ assert(g:match(s) == terror['undefined']) | |||
548 | 551 | ||
549 | 552 | ||
550 | print("+") | 553 | print("+") |
551 | 554 | ]==] | |
552 | 555 | ||
553 | -- test recovery operator | 556 | -- test recovery operator |
554 | p = m.Rec("a", "b") | 557 | p = m.Rec("a", "b") |
555 | assert(p:match("a") == 2) | 558 | assert(p:match("a") == 2) |
556 | assert(p:match("b") == 2) | 559 | --assert(p:match("b") == 2) |
557 | checkeqlab({nil, 0, "c"}, p:match("c")) | 560 | checkeqlab({nil, 0, "c"}, p:match("c")) |
558 | 561 | ||
559 | p = m.Rec("a", "b", 3) | 562 | p = m.Rec("a", "b", 3) |
@@ -583,13 +586,44 @@ g = m.P{ | |||
583 | 586 | ||
584 | assert(g:match("abc") == 4) | 587 | assert(g:match("abc") == 4) |
585 | assert(g:match("aabc") == 5) | 588 | assert(g:match("aabc") == 5) |
586 | assert(g:match("aadc") == 5) | 589 | --assert(g:match("aadc") == 5) --old semantics |
587 | assert(g:match("bc") == 3) | 590 | checkeqlab({nil, 0, "dc"}, g:match("aadc")) --new semantics |
591 | assert(g:match("bc") == 3) -- new semantics | ||
588 | checkeqlab({nil, 0, "bc"}, g:match("bbc")) | 592 | checkeqlab({nil, 0, "bc"}, g:match("bbc")) |
589 | assert(g:match("xxc") == 4) | 593 | --assert(g:match("xxc") == 4) old semantics |
590 | assert(g:match("c") == 2) | 594 | checkeqlab({nil, 0, "xxc"}, g:match("xxc")) --new semantics |
591 | checkeqlab({nil, 0, ""}, g:match("fail")) | 595 | --assert(g:match("c") == 2) --old semantics |
592 | checkeqlab({nil, 0, ""}, g:match("aaxx")) | 596 | checkeqlab({nil, 0, "c"}, g:match("c")) --new semantics |
597 | --checkeqlab({nil, 0, ""}, g:match("fail")) --old semantics | ||
598 | checkeqlab({nil, 0, "fail"}, g:match("fail")) --new semantics | ||
599 | --checkeqlab({nil, 0, ""}, g:match("aaxx")) --old semantics | ||
600 | checkeqlab({nil, 0, "xx"}, g:match("aaxx")) --new semantics | ||
601 | |||
602 | |||
603 | --[[ | ||
604 | S -> (A //{0} (!c .)*) C | ||
605 | A -> a*b / ^{0} | ||
606 | C -> c+ | ||
607 | ]] | ||
608 | g = m.P{ | ||
609 | "S", | ||
610 | S = m.Rec(m.V"A", (-m.P"c" * m.P(1))^0) * m.V"C", | ||
611 | A = m.P"a"^0 * m.P"b" + m.T(0), | ||
612 | C = m.P"c"^1, | ||
613 | } | ||
614 | |||
615 | assert(g:match("abc") == 4) | ||
616 | assert(g:match("aabc") == 5) | ||
617 | assert(g:match("aadc") == 5) --updated | ||
618 | assert(g:match("bc") == 3) -- new semantics | ||
619 | checkeqlab({nil, 0, "bc"}, g:match("bbc")) | ||
620 | assert(g:match("xxc") == 4) | ||
621 | assert(g:match("c") == 2) --old semantics updated | ||
622 | checkeqlab({nil, 0, ""}, g:match("fail")) --old semantics updated | ||
623 | checkeqlab({nil, 0, ""}, g:match("aaxx")) --old semantics updated | ||
624 | |||
625 | |||
626 | |||
593 | 627 | ||
594 | --[[ | 628 | --[[ |
595 | S -> (A //{99} (!c .)*) C | 629 | S -> (A //{99} (!c .)*) C |
@@ -726,7 +760,5 @@ print(eval "(1+1-1*(2/2+)-():") | |||
726 | --> syntax error: extra characters found after the expression (at index | 760 | --> syntax error: extra characters found after the expression (at index |
727 | 761 | ||
728 | 762 | ||
729 | |||
730 | |||
731 | print("OK") | 763 | print("OK") |
732 | 764 | ||