]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/misc.ml
1. helmns and domImpl moved to the misc module ;-(
[helm.git] / helm / gTopLevel / misc.ml
1 (* Copyright (C) 2000-2002, 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 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 06/01/2002                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 exception IllFormedUri of string;;
37
38 let string_of_cic_textual_parser_uri uri =
39  let module C = Cic in
40  let module CTP = CicTextualParser0 in
41   let uri' =
42    match uri with
43       CTP.ConUri uri -> UriManager.string_of_uri uri
44     | CTP.VarUri uri -> UriManager.string_of_uri uri
45     | CTP.IndTyUri (uri,tyno) ->
46        UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
47     | CTP.IndConUri (uri,tyno,consno) ->
48        UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
49         string_of_int consno
50   in
51    (* 4 = String.length "cic:" *)
52    String.sub uri' 4 (String.length uri' - 4)
53 ;;
54
55 let cic_textual_parser_uri_of_string uri' =
56  prerr_endline ("cic_textual_parser_uri_of_string INPUT = " ^ uri');
57  try
58   (* Constant *)
59   if String.sub uri' (String.length uri' - 4) 4 = ".con" then
60    CicTextualParser0.ConUri (UriManager.uri_of_string uri')
61   else
62    if String.sub uri' (String.length uri' - 4) 4 = ".var" then
63     CicTextualParser0.VarUri (UriManager.uri_of_string uri')
64    else
65     (try
66       (* Inductive Type *)
67       let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
68        CicTextualParser0.IndTyUri (uri'',typeno)
69      with
70       _ ->
71        (* Constructor of an Inductive Type *)
72        let uri'',typeno,consno =
73         CicTextualLexer.indconuri_of_uri uri'
74        in
75         CicTextualParser0.IndConUri (uri'',typeno,consno)
76     )
77  with
78   _ -> raise (IllFormedUri uri')
79 ;;
80 let cic_textual_parser_uri_of_string uri' =
81   let res = cic_textual_parser_uri_of_string uri' in
82   prerr_endline ("RESULT: " ^ (string_of_cic_textual_parser_uri res));
83   res
84
85 (* CSC: quick fix: a function from [uri#xpointer(path)] to [uri#path] *)
86 let wrong_xpointer_format_from_wrong_xpointer_format' uri =
87  try
88   let index_sharp =  String.index uri '#' in
89   let index_rest = index_sharp + 10 in
90    let baseuri = String.sub uri 0 index_sharp in
91    let rest =
92     String.sub uri index_rest (String.length uri - index_rest - 1)
93    in
94     baseuri ^ "#" ^ rest
95  with Not_found -> uri
96 ;;
97
98 let domImpl = Gdome.domImplementation ();;
99 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;