7 let test_pattern_match =
9 and nm
= fun x y
-> not
(pattern_match x y
) in
11 assert (nm
(Atm Tmp
) (Atm
(Con
42L)));
12 assert (pm (Atm AnyCon
) (Atm
(Con
42L)));
13 assert (nm
(Atm
(Con
42L)) (Atm AnyCon
));
14 assert (nm
(Atm
(Con
42L)) (Atm Tmp
));
19 let p = Bnr
(o, Bnr
(o, Atm Tmp
, Atm Tmp
),
22 let () = assert (List.length
l = 3) in
24 match p with Atm _
-> true | _
-> false in
25 let () = assert (List.for_all
atomic_p l) in
26 let l = List.map
(fun (p, c
) -> fold_cursor c
p) l in
27 let () = assert (List.for_all
((=) p) l) in
31 let l = [1; 2; 3; 4; 5] in
32 let p = fold_pairs
l l [] (fun a b
-> a
:: b
) in
33 let () = assert (List.length
p = 25) in
34 let p = sort_uniq compare
p in
35 let () = assert (List.length
p = 25) in
38 (* test pattern & state *)
41 StateMap.iter
(fun k s'
->
45 List.fold_left
(fun top c
->
47 | Top r
-> top ^
" " ^ r
48 | _
-> top) "" s'
.point
51 " (%s %d %d) -> %d%s\n"
53 sl
.id sr
.id s'
.id
top)
58 let va = Var
("a", Tmp
)
59 and vb
= Var
("b", Tmp
)
60 and vc
= Var
("c", Tmp
)
61 and vs
= Var
("s", Tmp
) in
62 let vars = ["a"; "b"; "c"; "s"] in
63 let rule name pattern
=
65 (fun pattern
-> {name
; vars; pattern
})
69 (* ------------------------------- *)
72 rule "ob" (Bnr
(oa, Atm Tmp
, Atm AnyCon
))
74 rule "bsm" (Bnr
(oa, vb
, Bnr
(om, Var
("m", Con
2L), vs
)))
76 rule "bsm" (Bnr
(oa, vb
, Bnr
(om, Var
("m", Con
4L), vs
)))
78 rule "bsm" (Bnr
(oa, vb
, Bnr
(om, Var
("m", Con
8L), vs
)))
80 rule "bs1" (Bnr
(oa, vb
, vs
))
82 (* rule "osm" (Bnr (oa, Atm AnyCon, Bnr (om, Atm (Con 4L), Atm Tmp))) *) []
84 rule "obs1" (Bnr
(oa, Bnr
(oa, Var
("o", AnyCon
), vb
), vs
))
86 rule "obsm" (Bnr
(oa, Bnr
(oa, Var
("o", AnyCon
), vb
),
87 Bnr
(om, Var
("m", Con
2L), vs
)))
89 rule "obsm" (Bnr
(oa, Bnr
(oa, Var
("o", AnyCon
), vb
),
90 Bnr
(om, Var
("m", Con
4L), vs
)))
92 rule "obsm" (Bnr
(oa, Bnr
(oa, Var
("o", AnyCon
), vb
),
93 Bnr
(om, Var
("m", Con
8L), vs
)))
94 (* ------------------------------- *)
98 ; pattern
= Bnr
(oa, va, Bnr
(oa, vb
, vc
)) } ] @
101 ; pattern
= Bnr
(oa, Bnr
(oa, va, vb
), vc
) } ]
105 let sa, am, sm = generate_table rules
107 Array.iteri (fun i s ->
108 Format.printf "@[state %d: %s@]@."
109 i (show_pattern s.seen))
111 let () = print_sm stdout sm; flush stdout
113 let matcher = lr_matcher sm sa rules "obsm" (* XXX *)
114 let () = Format.printf
"@[<v>%a@]@." Action.pp
matcher
115 let () = Format.printf
"@[matcher size: %d@]@." (Action.size
matcher)
117 let numbr = make_numberer
sa am sm
120 let opts = { pfx
= ""
125 [ ( ["b"; "o"; "s"; "m"]
130 let tp = fuzz_numberer rules numbr
131 let () = test_matchers tp numbr rules