| 23 |
] |
] |
| 24 |
|
|
| 25 |
|
|
| 26 |
and pexpr = pexpr' located |
and pexpr = |
| 27 |
and pexpr' = |
| LocatedExpr of loc * pexpr |
| 28 |
|
|
| 29 |
| Forget of pexpr * ppat |
| Forget of pexpr * ppat |
| 30 |
|
|
| 31 |
(* CDuce is a Lambda-calculus ... *) |
(* CDuce is a Lambda-calculus ... *) |
| 32 |
| Var of id |
| Var of id |
| 33 |
| Apply of pexpr * pexpr |
| Apply of pexpr * pexpr |
| 42 |
(* Data destructors *) |
(* Data destructors *) |
| 43 |
| Op of string * pexpr list |
| Op of string * pexpr list |
| 44 |
| Match of pexpr * branches |
| Match of pexpr * branches |
| 45 |
| Map of pexpr * branches |
| Map of bool * pexpr * branches |
| 46 |
| Ttree of pexpr * branches |
| Xtrans of pexpr * branches |
| 47 |
| Dot of pexpr* label |
| Dot of pexpr* label |
| 48 |
| RemoveField of pexpr * label |
| RemoveField of pexpr * label |
| 49 |
|
|
| 50 |
(* Exceptions *) |
(* Exceptions *) |
| 51 |
| Try of pexpr * branches |
| Try of pexpr * branches |
| 52 |
|
|
|
| MatchFail (* internal usage *) |
|
|
|
|
| 53 |
and abstr = { |
and abstr = { |
| 54 |
fun_name : id option; |
fun_name : id option; |
| 55 |
fun_iface : (ppat * ppat) list; |
fun_iface : (ppat * ppat) list; |
| 85 |
| Star of regexp |
| Star of regexp |
| 86 |
| WeakStar of regexp |
| WeakStar of regexp |
| 87 |
| SeqCapture of id * regexp |
| SeqCapture of id * regexp |
|
|
|
|
|
|
|
let rec equal_ppat p1 p2 = |
|
|
let p1 = p1.descr and p2 = p2.descr in |
|
|
(p1 == p2) || |
|
|
match (p1,p2) with |
|
|
| PatVar x1, PatVar x2 -> x1 = x2 |
|
|
| Internal x1, Internal x2 -> Types.equal_descr x1 x2 |
|
|
| Or (x1,y1), Or (x2,y2) |
|
|
| And (x1,y1), And (x2,y2) |
|
|
| Diff (x1,y1), Diff (x2,y2) |
|
|
| Prod (x1,y1), Prod (x2,y2) |
|
|
| XmlT (x1,y1), XmlT (x2,y2) |
|
|
| Arrow (x1,y1), Arrow (x2,y2) |
|
|
-> (equal_ppat x1 x2) && (equal_ppat y1 y2) |
|
|
| Optional x1, Optional x2 -> equal_ppat x1 x2 |
|
|
| Record (o1,r1), Record (o2,r2) -> |
|
|
(o1 == o2) && (LabelMap.equal equal_ppat r1 r2) |
|
|
| Capture x1, Capture x2 -> x1 == x2 |
|
|
| Constant (x1,y1), Constant (x2,y2) -> |
|
|
(x1 == x2) && (Types.equal_const y1 y2) |
|
|
| Regexp (x1,y1), Regexp (x2,y2) -> |
|
|
(equal_regexp x1 x2) && (equal_ppat y1 y2) |
|
|
(* todo: Recurs *) |
|
|
| _ -> false |
|
|
and equal_regexp r1 r2 = |
|
|
(r1 == r2) || |
|
|
match (r1,r2) with |
|
|
| Elem x1, Elem x2 -> equal_ppat x1 x2 |
|
|
| Seq (x1,y1), Seq (x2,y2) |
|
|
| Alt (x1,y1), Alt (x2,y2) -> (equal_regexp x1 x2) && (equal_regexp y1 y2) |
|
|
| Star x1, Star x2 |
|
|
| WeakStar x1, WeakStar x2 -> equal_regexp x1 x2 |
|
|
| SeqCapture (x1,y1), SeqCapture (x2,y2) -> |
|
|
(x1 == x2) && (equal_regexp y1 y2) |
|
|
| _ -> false |
|
|
|
|
|
let rec hash_ppat p = |
|
|
match p.descr with |
|
|
| PatVar x -> 1 + 17 * (Hashtbl.hash x) |
|
|
| Internal x -> 2 + 17 * (Types.hash_descr x) |
|
|
| Or (x,y) -> 3 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| And (x,y) -> 4 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| Diff (x,y) -> 5 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| Prod (x,y) -> 6 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| XmlT (x,y) -> 7 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| Arrow (x,y) -> 8 + 17 * (hash_ppat x) + 257 * (hash_ppat y) |
|
|
| Optional x -> 9 + 17 * (hash_ppat x) |
|
|
| Record (o,r) -> |
|
|
(if o then 10 else 11) + (LabelMap.hash hash_ppat r) |
|
|
| Capture x -> 12 + 17 * (Id.hash x) |
|
|
| Constant (x,y) -> 13 + 17 * (Id.hash x) + 257 * (Types.hash_const y) |
|
|
| Regexp (x,y) -> |
|
|
14 + 17 * (hash_regexp x) + 16637 * (hash_ppat y) |
|
|
| Recurs (x,l) -> |
|
|
15 + 17 * (hash_ppat x) (* todo: hash l *) |
|
|
and hash_regexp = function |
|
|
| Epsilon -> 1 |
|
|
| Elem x -> 2 + 17 * (hash_ppat x) |
|
|
| Seq (x,y) -> 3 + 17 * (hash_regexp x) + 257 * (hash_regexp y) |
|
|
| Alt (x,y) -> 4 + 17 * (hash_regexp x) + 257 * (hash_regexp y) |
|
|
| Star x -> 5 + 17 * (hash_regexp x) |
|
|
| WeakStar x -> 6 + 17 * (hash_regexp x) |
|
|
| SeqCapture (x,y) -> 7 + 17 * (Id.hash x) + 257 * (hash_regexp y) |
|
|
|
|
|
module PpatTable = Hashtbl.Make |
|
|
(struct |
|
|
type t = ppat |
|
|
let equal = equal_ppat |
|
|
let hash = hash_ppat |
|
|
end) |
|