]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nUriManager.ml
new uri defined
[helm.git] / helm / software / components / ng_kernel / nUriManager.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 type spec = 
27  | Decl 
28  | Def
29  | Fix of int * int (* fixno, recparamno *)
30  | CoFix of int
31  | Ind of int
32  | IConstr of int * int (* indtyno, constrno *)
33
34 type uri = Uri of int *  string * spec
35
36 let eq = (==);;
37
38 let string_of_uri (Uri (_,s,_)) = s ;;
39
40 module OrderedStrings =
41  struct
42   type t = string
43   let compare (s1 : t) (s2 : t) = compare s1 s2
44  end
45 ;;
46
47 module MapStringsToUri = Map.Make(OrderedStrings);;
48
49 let set_of_uri = ref MapStringsToUri.empty;;
50
51 (* '.' not allowed in path and foo
52  *
53  * Decl                   cic:/path/foo.decl
54  * Def                    cic:/path/foo.def
55  * Fix of int * int       cic:/path/foo.fix(i,j)
56  * CoFix of int           cic:/path/foo.cofix(i)
57  * Ind of int             cic:/path/foo.ind(i)
58  * Constr of int * int    cic:/path/foo.constr(i,j)
59  *)
60
61 let uri_of_string_aux =
62   let counter = ref 0 in fun s ->
63   incr counter;
64   try
65     let sharp = String.rindex s '#' in
66     let pre = String.sub s 0 sharp in
67     let ind = String.sub s (sharp+12) (String.length s - (sharp+13)) in
68     try
69       let slash = String.rindex ind '/' in
70       let indno = String.sub ind 0 slash in   
71       let constr = String.sub ind (slash+1) (String.length ind - (slash+1)) in
72       Uri(!counter,pre,Some(int_of_string indno-1,Some(int_of_string constr-1)))
73     with Not_found -> Uri (!counter,pre,Some (int_of_string ind-1, None))
74   with Not_found -> Uri (!counter,s,None)
75 ;;
76
77 let uri_of_string s =
78   try
79     MapStringsToUri.find s !set_of_uri
80   with Not_found ->
81     let new_uri = uri_of_string_aux s in
82     set_of_uri := MapStringsToUri.add s new_uri !set_of_uri;
83     new_uri
84 ;;
85
86 let nuri_of_ouri u indinfo =
87   uri_of_string (string_of_uri (Uri(0,UriManager.string_of_uri u,indinfo)))
88 ;;
89
90 let ouri_of_nuri u =
91   UriManager.uri_of_string (string_of_uri u)
92 ;;