1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 exception IllFormedReference of string Lazy.t
31 | Fix of int * int (* fixno, recparamno *)
34 | Con of int * int (* indtyno, constrno *)
36 type reference = Ref of int * string * spec
40 let string_of_reference (Ref (_,s,_)) = s;;
42 module OrderedStrings =
45 let compare (s1 : t) (s2 : t) = compare s1 s2
49 module MapStringsToUri = Map.Make(OrderedStrings);;
51 let set_of_reference = ref MapStringsToUri.empty;;
53 (* '.' not allowed in path and foo
55 * Decl cic:/path/foo.dec
56 * Def cic:/path/foo.def
57 * Fix of int * int cic:/path/foo.fix(i,j)
58 * CoFix of int cic:/path/foo.cfx(i)
59 * Ind of int cic:/path/foo.ind(i)
60 * Con of int * int cic:/path/foo.con(i,j)
63 let reference_of_string =
64 let counter = ref 0 in
65 let c () = incr counter; !counter in
67 let comma = String.rindex s ',' in
68 let i = int_of_string (String.sub s (dot+5) (comma-dot-5)) in
69 let j = int_of_string (String.sub s (comma+1) (String.length s-comma-2)) in
73 let i = int_of_string (String.sub s (dot+5) (String.length s-1)) in
77 try MapStringsToUri.find s !set_of_reference
81 let dot = String.rindex s '.' in
82 let suffix = String.sub s (dot+1) 3 in
84 | "dec" -> Ref (c (), s, Decl)
85 | "def" -> Ref (c (), s, Def)
86 | "fix" -> let i,j = get2 s dot in Ref (c (), s, Fix (i,j))
87 | "cfx" -> let i = get1 s dot in Ref (c (), s, CoFix (i))
88 | "ind" -> let i = get1 s dot in Ref (c (), s, Ind (i))
89 | "con" -> let i,j = get2 s dot in Ref (c (), s, Con (i,j))
90 | _ -> raise Not_found
91 with Not_found -> raise (IllFormedReference (lazy s))
93 set_of_reference := MapStringsToUri.add s new_reference !set_of_reference;
97 let reference_of_ouri u indinfo =
98 let s = UriManager.string_of_uri u in
99 let dot = String.rindex s '.' in
100 let s2 = String.sub s 0 dot in
101 let ns = match indinfo with
102 | Decl -> s2 ^ ".dec"
104 | Fix (i,j) -> s2 ^ ".fix(" ^ string_of_int i ^ "," ^ string_of_int j ^ ")"
105 | CoFix i -> s2 ^ ".cfx(" ^ string_of_int i ^ ")"
106 | Ind i -> s2 ^ ".ind(" ^ string_of_int i ^ ")"
107 | Con (i,j) -> s2 ^ ".con(" ^ string_of_int i ^ "," ^ string_of_int j ^ ")"
108 in reference_of_string ns
111 let ouri_of_reference u =
112 let s = string_of_reference u in
113 let dot = String.rindex s '.' in
114 let prefix = String.sub s 0 dot in
115 let suffix = String.sub s (dot+1) 3 in
119 | "def" -> prefix ^ ".con"
121 | "con" -> prefix ^ ".ind"
124 UriManager.uri_of_string os