2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
14 exception IllFormedReference of string Lazy.t
18 | Def of int (* height *)
19 | Fix of int * int * int (* fixno, recparamno, height *)
21 | Ind of bool * int * int (* inductive, indtyno, leftno *)
22 | Con of int * int * int (* indtyno, constrno, leftno *)
24 type reference = Ref of NUri.uri * spec
28 let compare (Ref (u1,s1)) (Ref (u2,s2)) =
29 let res = NUri.compare u1 u2 in
30 if res = 0 then compare s1 s2 else res
33 let hash (Ref (uri,spec)) =
34 Hashtbl.hash spec + NUri.hash uri
37 module OrderedStrings =
40 let compare (s1 : t) (s2 : t) = Pervasives.compare s1 s2
44 module MapStringsToReference = Map.Make(OrderedStrings);;
46 let set_of_reference = ref MapStringsToReference.empty;;
48 (* '.' not allowed in path and foo
50 * Decl cic:/path/foo.dec
51 * Def cic:/path/foo.def
52 * Fix of int * int cic:/path/foo.fix(i,j)
53 * CoFix of int cic:/path/foo.cfx(i)
54 * Ind of int cic:/path/foo.ind(i)
55 * Con of int * int cic:/path/foo.con(i,j)
58 let uri_suffix_of_ref_suffix = function
59 | "dec" | "fix" | "cfx" | "def" -> "con"
60 | "ind" | "con" -> "ind"
61 | x -> prerr_endline (x ^ " not a valid suffix"); assert false
64 let reference_of_string =
66 let comma2 = String.rindex s ',' in
67 let comma = String.rindex_from s (comma2-1) ',' in
68 let s_i = String.sub s (dot+5) (comma-dot-5) in
69 let s_j = String.sub s (comma+1) (comma2-comma-1) in
70 let s_h = String.sub s (comma2+1) (String.length s-comma2-2) in
71 let i = int_of_string s_i in
72 let j = int_of_string s_j in
73 let h = int_of_string s_h in
78 let comma = String.rindex s ',' in
79 let i = int_of_string (String.sub s (dot+5) (comma-dot-5)) in
80 let j = int_of_string (String.sub s (comma+1) (String.length s-comma-2)) in
85 let i = int_of_string (String.sub s (dot+5) (String.length s-1-dot-5)) in
89 try MapStringsToReference.find s !set_of_reference
93 let dot = String.rindex s '.' in
94 let prefix = String.sub s 0 (dot+1) in
95 let suffix = String.sub s (dot+1) 3 in
96 let u = NUri.uri_of_string (prefix ^ uri_suffix_of_ref_suffix suffix) in
98 | "dec" -> Ref (u, Decl)
99 | "def" -> let i = get1 s dot in Ref (u, Def i)
100 | "fix" -> let i,j,h = get3 s dot in Ref (u, Fix (i,j,h))
101 | "cfx" -> let i = get1 s dot in Ref (u, CoFix (i))
102 | "ind" -> let b,i,l = get3 s dot in Ref (u, Ind (b=1,i,l))
103 | "con" -> let i,j,l = get3 s dot in Ref (u, Con (i,j,l))
104 | _ -> raise Not_found
105 with Not_found -> raise (IllFormedReference (lazy s))
107 set_of_reference := MapStringsToReference.add s new_reference !set_of_reference;
111 let string_of_reference (Ref (u,indinfo)) =
112 let s = NUri.string_of_uri u in
113 let dot = String.rindex s '.' in
114 let s2 = String.sub s 0 dot in
116 | Decl -> s2 ^ ".dec"
117 | Def h -> s2 ^ ".def(" ^ string_of_int h ^ ")"
119 s2 ^ ".fix(" ^ string_of_int i ^ "," ^
120 string_of_int j ^ "," ^ string_of_int h ^ ")"
121 | CoFix i -> s2 ^ ".cfx(" ^ string_of_int i ^ ")"
122 | Ind (b,i,l)->s2 ^".ind(" ^(if b then "1" else "0")^ "," ^ string_of_int i ^
123 "," ^ string_of_int l ^ ")"
124 | Con (i,j,l) -> s2 ^ ".con(" ^ string_of_int i ^ "," ^ string_of_int j ^
125 "," ^ string_of_int l ^ ")"
128 let mk_constructor j = function
129 | Ref (u, Ind (_,i,l)) ->
130 reference_of_string (string_of_reference (Ref (u, Con (i,j,l))))
132 raise (IllFormedReference (lazy ("NON INDUCTIVE TYPE REFERENCE: " ^
133 string_of_reference r)));
135 let mk_indty b = function
136 | Ref (u, Con (i,_,l)) ->
137 reference_of_string (string_of_reference (Ref (u, Ind (b,i,l))))
139 raise (IllFormedReference (lazy
140 ("NON INDUCTIVE TYPE CONSTRUCTOR REFERENCE: " ^ string_of_reference r)));
143 let mk_fix i j = function
144 | Ref (u, Fix (_,_,h)) ->
145 reference_of_string (string_of_reference (Ref (u, Fix (i,j,h))))
149 let mk_cofix i = function
150 | Ref (u, CoFix _) ->
151 reference_of_string (string_of_reference (Ref (u, CoFix i)))
155 let reference_of_spec u spec =
156 reference_of_string (string_of_reference (Ref (u, spec)))