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 * NUri.uri * spec
40 module OrderedStrings =
43 let compare (s1 : t) (s2 : t) = compare s1 s2
47 module MapStringsToReference = Map.Make(OrderedStrings);;
49 let set_of_reference = ref MapStringsToReference.empty;;
51 (* '.' not allowed in path and foo
53 * Decl cic:/path/foo.dec
54 * Def cic:/path/foo.def
55 * Fix of int * int cic:/path/foo.fix(i,j)
56 * CoFix of int cic:/path/foo.cfx(i)
57 * Ind of int cic:/path/foo.ind(i)
58 * Con of int * int cic:/path/foo.con(i,j)
61 let uri_suffix_of_ref_suffix = function
62 | "dec" | "fix" | "cfx" | "def" -> "con"
63 | "ind" | "con" -> "ind"
64 | x -> prerr_endline (x ^ " not a valid suffix"); assert false
67 let reference_of_string =
68 let counter = ref 0 in
69 let c () = incr counter; !counter in
71 let comma = String.rindex s ',' in
72 let i = int_of_string (String.sub s (dot+5) (comma-dot-5)) in
73 let j = int_of_string (String.sub s (comma+1) (String.length s-comma-2)) in
77 let i = int_of_string (String.sub s (dot+5) (String.length s-1-dot-5)) in
81 try MapStringsToReference.find s !set_of_reference
85 let dot = String.rindex s '.' in
86 let prefix = String.sub s 0 (dot+1) in
87 let suffix = String.sub s (dot+1) 3 in
88 let u = NUri.uri_of_string (prefix ^ uri_suffix_of_ref_suffix suffix) in
90 | "dec" -> Ref (c (), u, Decl)
91 | "def" -> Ref (c (), u, Def)
92 | "fix" -> let i,j = get2 s dot in Ref (c (), u, Fix (i,j))
93 | "cfx" -> let i = get1 s dot in Ref (c (), u, CoFix (i))
94 | "ind" -> let i = get1 s dot in Ref (c (), u, Ind (i))
95 | "con" -> let i,j = get2 s dot in Ref (c (), u, Con (i,j))
96 | _ -> raise Not_found
97 with Not_found -> raise (IllFormedReference (lazy s))
99 set_of_reference := MapStringsToReference.add s new_reference !set_of_reference;
103 let string_of_reference (Ref (_,u,indinfo)) =
104 let s = NUri.string_of_uri u in
105 let dot = String.rindex s '.' in
106 let s2 = String.sub s 0 dot in
108 | Decl -> s2 ^ ".dec"
110 | Fix (i,j) -> s2 ^ ".fix(" ^ string_of_int i ^ "," ^ string_of_int j ^ ")"
111 | CoFix i -> s2 ^ ".cfx(" ^ string_of_int i ^ ")"
112 | Ind i -> s2 ^ ".ind(" ^ string_of_int i ^ ")"
113 | Con (i,j) -> s2 ^ ".con(" ^ string_of_int i ^ "," ^ string_of_int j ^ ")"
116 let mk_constructor j = function
117 | Ref (d, u, Ind i) ->
118 reference_of_string (string_of_reference (Ref (d, u, Con (i,j))))
122 let mk_fix i j = function
123 | Ref (d, u, Fix _) ->
124 reference_of_string (string_of_reference (Ref (d, u, Fix (i,j))))
128 let reference_of_ouri u indinfo =
129 let u = NUri.nuri_of_ouri u in
130 reference_of_string (string_of_reference (Ref (max_int,u,indinfo)))
133 let ouri_of_reference (Ref (_,u,_)) = NUri.ouri_of_nuri u;;