X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_kernel%2FnUriManager.ml;h=86cae6b6ba4984d59c18f725c9de170a02b78ae9;hb=d9373d1ab9c84de43f212e11912178cabd5562ac;hp=de7116cb1a7dbcfa3ec329441106fa082a545c38;hpb=a3ba13b9503a2c0dd89b89b489899362d17b3f3a;p=helm.git diff --git a/helm/software/components/ng_kernel/nUriManager.ml b/helm/software/components/ng_kernel/nUriManager.ml index de7116cb1..86cae6b6b 100644 --- a/helm/software/components/ng_kernel/nUriManager.ml +++ b/helm/software/components/ng_kernel/nUriManager.ml @@ -23,18 +23,70 @@ * http://cs.unibo.it/helm/. *) -exception IllFormedUri of string Lazy.t;; +type spec = + | Decl + | Def + | Fix of int * int (* fixno, recparamno *) + | CoFix of int + | Ind of int + | IConstr of int * int (* indtyno, constrno *) -(* order, uri, (type, constructor) *) -type uri = private Uri of int * string * (int * int option ) option +type uri = Uri of int * string * spec -let eq (Uri(_,x1,x2)) (Uri(_,y1,y2)) = x1 = y1 && x2 = y2;; +let eq = (==);; -let string_of_uri = function - | Uri (_,s,None) -> s - | Uri (_,s,Some (i,None)) -> - s ^ "#xpointer(1/" ^ string_of_int (i+1) ^ ")" - | Uri (_,s,Some (i, Some k)) -> - s ^ "#xpointer(1/" ^ string_of_int (i+1) ^ "/" ^ string_of_int k ^ ")" +let string_of_uri (Uri (_,s,_)) = s ;; + +module OrderedStrings = + struct + type t = string + let compare (s1 : t) (s2 : t) = compare s1 s2 + end ;; +module MapStringsToUri = Map.Make(OrderedStrings);; + +let set_of_uri = ref MapStringsToUri.empty;; + +(* '.' not allowed in path and foo + * + * Decl cic:/path/foo.decl + * Def cic:/path/foo.def + * Fix of int * int cic:/path/foo.fix(i,j) + * CoFix of int cic:/path/foo.cofix(i) + * Ind of int cic:/path/foo.ind(i) + * Constr of int * int cic:/path/foo.constr(i,j) + *) + +let uri_of_string_aux = + let counter = ref 0 in fun s -> + incr counter; + try + let sharp = String.rindex s '#' in + let pre = String.sub s 0 sharp in + let ind = String.sub s (sharp+12) (String.length s - (sharp+13)) in + try + let slash = String.rindex ind '/' in + let indno = String.sub ind 0 slash in + let constr = String.sub ind (slash+1) (String.length ind - (slash+1)) in + Uri(!counter,pre,Some(int_of_string indno-1,Some(int_of_string constr-1))) + with Not_found -> Uri (!counter,pre,Some (int_of_string ind-1, None)) + with Not_found -> Uri (!counter,s,None) +;; + +let uri_of_string s = + try + MapStringsToUri.find s !set_of_uri + with Not_found -> + let new_uri = uri_of_string_aux s in + set_of_uri := MapStringsToUri.add s new_uri !set_of_uri; + new_uri +;; + +let nuri_of_ouri u indinfo = + uri_of_string (string_of_uri (Uri(0,UriManager.string_of_uri u,indinfo))) +;; + +let ouri_of_nuri u = + UriManager.uri_of_string (string_of_uri u) +;;