aboutsummaryrefslogtreecommitdiff
path: root/testlabel.lua
diff options
context:
space:
mode:
authorsergio <sqmedeiros@gmail.com>2016-07-22 15:13:58 -0300
committersergio <sqmedeiros@gmail.com>2016-07-22 15:13:58 -0300
commitabb26cdfd3d44e7b10ec001f2afb980616c71573 (patch)
tree86a5caade53be9dc1d3b5cefb3d212f9096842b4 /testlabel.lua
parent28a44f01cb7a75068b75a99c0badb3abdaf7047a (diff)
downloadlpeglabel-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.lua54
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{
32r, l, serror = g:match(s) 32r, l, serror = g:match(s)
33assert(r == nil and l == 1 and serror == "abc") 33assert(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
36p = m.Lc(m.T(2), m.P"a", 1, 3) 37p = m.Lc(m.T(2), m.P"a", 1, 3)
37r, l, serror = p:match(s) 38r, l, serror = p:match(s)
@@ -188,6 +189,7 @@ assert(p:match("abc") == 2)
188 189
189r, l, serror = p:match("") 190r, l, serror = p:match("")
190assert(r == nil and l == 0 and serror == "") 191assert(r == nil and l == 0 and serror == "")
192]==]
191 193
192-- testing the limit of labels 194-- testing the limit of labels
193p = m.T(0) 195p = m.T(0)
@@ -209,6 +211,7 @@ assert(r == false)
209 211
210print("+") 212print("+")
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
213S -> S0 /{1} ID /{2} ID '=' Exp /{3} 'unsigned'* 'int' ID /{4} 'unsigned'* ID ID / %error 216S -> S0 /{1} ID /{2} ID '=' Exp /{3} 'unsigned'* 'int' ID /{4} 'unsigned'* ID ID / %error
214S0 -> ID S1 / 'unsigned' S2 / 'int' %3 217S0 -> ID S1 / 'unsigned' S2 / 'int' %3
@@ -548,12 +551,12 @@ assert(g:match(s) == terror['undefined'])
548 551
549 552
550print("+") 553print("+")
551 554]==]
552 555
553-- test recovery operator 556-- test recovery operator
554p = m.Rec("a", "b") 557p = m.Rec("a", "b")
555assert(p:match("a") == 2) 558assert(p:match("a") == 2)
556assert(p:match("b") == 2) 559--assert(p:match("b") == 2)
557checkeqlab({nil, 0, "c"}, p:match("c")) 560checkeqlab({nil, 0, "c"}, p:match("c"))
558 561
559p = m.Rec("a", "b", 3) 562p = m.Rec("a", "b", 3)
@@ -583,13 +586,44 @@ g = m.P{
583 586
584assert(g:match("abc") == 4) 587assert(g:match("abc") == 4)
585assert(g:match("aabc") == 5) 588assert(g:match("aabc") == 5)
586assert(g:match("aadc") == 5) 589--assert(g:match("aadc") == 5) --old semantics
587assert(g:match("bc") == 3) 590checkeqlab({nil, 0, "dc"}, g:match("aadc")) --new semantics
591assert(g:match("bc") == 3) -- new semantics
588checkeqlab({nil, 0, "bc"}, g:match("bbc")) 592checkeqlab({nil, 0, "bc"}, g:match("bbc"))
589assert(g:match("xxc") == 4) 593--assert(g:match("xxc") == 4) old semantics
590assert(g:match("c") == 2) 594checkeqlab({nil, 0, "xxc"}, g:match("xxc")) --new semantics
591checkeqlab({nil, 0, ""}, g:match("fail")) 595--assert(g:match("c") == 2) --old semantics
592checkeqlab({nil, 0, ""}, g:match("aaxx")) 596checkeqlab({nil, 0, "c"}, g:match("c")) --new semantics
597--checkeqlab({nil, 0, ""}, g:match("fail")) --old semantics
598checkeqlab({nil, 0, "fail"}, g:match("fail")) --new semantics
599--checkeqlab({nil, 0, ""}, g:match("aaxx")) --old semantics
600checkeqlab({nil, 0, "xx"}, g:match("aaxx")) --new semantics
601
602
603--[[
604S -> (A //{0} (!c .)*) C
605A -> a*b / ^{0}
606C -> c+
607]]
608g = 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
615assert(g:match("abc") == 4)
616assert(g:match("aabc") == 5)
617assert(g:match("aadc") == 5) --updated
618assert(g:match("bc") == 3) -- new semantics
619checkeqlab({nil, 0, "bc"}, g:match("bbc"))
620assert(g:match("xxc") == 4)
621assert(g:match("c") == 2) --old semantics updated
622checkeqlab({nil, 0, ""}, g:match("fail")) --old semantics updated
623checkeqlab({nil, 0, ""}, g:match("aaxx")) --old semantics updated
624
625
626
593 627
594--[[ 628--[[
595S -> (A //{99} (!c .)*) C 629S -> (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
731print("OK") 763print("OK")
732 764