1 module Pass_simple_recursion =
4 let lbr = del "<" "<" in
5 let rbr = del ">" ">" in
6 let k = [ key /[a-z]+/ ] in
7 let node = [ label "S" . lbr . lns . rbr ] in
11 (* let rec lns = [ key "a" . lns ] | [ key "a" ] *)
12 test lns get "<x>" = { "S" { "x" } }
14 test lns put "<x>" after rm "nothing" = "<x>"
16 test lns put "<<x>>" after rm "nothing" = "<<x>>"
18 test lns put "<x><x>" after rm "/S[2]" = "<x>"
20 test lns put "<x>" after clear "/S/S/S/x" = "<x<<x>>>"
23 (* Start with { "S" { "x" } } and modify to { "S" { "S" { "x" } } } *)
24 test lns put "<x>" after
29 test lns get "<<<x><x>><x>><x>" =
37 test lns put "<<<x><x>><x>><x>" after rm "/S[1]/S[1]/S[1]" =
41 test lns get "<<yo>><zulu>" =
42 { "S" { "S" { "yo" } } }
45 (* Some pathological tests for nullable lenses *)
47 let rec prim_nullable = [ prim_nullable . key /x/ ] | del /s*/ ""
48 test prim_nullable get "sx" = { "x" }
49 test prim_nullable get "x" = { "x" }
51 let rec ambig = [ ambig . label "x" ] | del /s+/ "s"
53 test ambig get "s" = *
55 (* Test link filtering. These tests cause seemingly ambiguous parses, which
56 * need to be disambiguated by filtering links in the Earley graph. See
57 * section 5.3 in the paper *)
58 let rec unamb1 = [ label "x" . unamb1 . store /y/ ] | [ key "z" ]
59 test unamb1 get "zyy" = { "x" = "y" { "x" = "y" { "z" } } }
62 let rec unamb2 = del /u*/ "" . [ unamb2 . key /x/ ] | del /s*/ ""
63 test unamb2 get "sx" = { "x" }
64 test unamb2 get "x" = { "x" }
66 (* Test proper handling of '?'; bug #119 *)
67 let rec maybe = [ del "a" "a" . maybe . del "b" "b" ]?
68 test maybe get "aabb" = { { } }
70 (* Test proper handling of '?'; bug #180 *)
71 let rec maybe2 = [ del "a" "a" . maybe2 ]?
72 test maybe2 get "aa" = { { } }
74 let rec maybe3 = [ maybe3 . del "a" "a" ]?
75 test maybe3 get "aa" = { { } }
77 let rec maybe4 = [ del "a" "a" ] . maybe4?
78 test maybe4 get "aa" = { } { }
80 let rec maybe5 = maybe5? . [ del "a" "a" ]
81 test maybe5 get "aa" = { } { }
83 (* Test that parses ending with a SCAN are accepted; bug #126 *)
84 let dels (s:string) = del s s
86 let sec (body:lens) = [ key /a*/ . dels "{" . body . dels "}"]*
87 let rec sec_complete = sec sec_complete
88 let lns2 = sec_complete . d2
89 test lns2 get "a{}b" = { "a" }
91 (* Test stack handling with both parsing direction; bug #136 *)
92 let idr = [ key /[0-9]+/ . del /z+/ "z" . store /[0-9]+/ . del /a+/ "a" ]
93 let rec idr_left = idr_left? . idr
94 let rec idr_right = idr . idr_right?
95 let input = "1zz2aa33zzz44aaa555zzzz666aaaa"
96 test idr_left get input = { "1" = "2" }{ "33" = "44" }{ "555" = "666" }
97 test idr_right get input = { "1" = "2" }{ "33" = "44" }{ "555" = "666" }