]> matita.cs.unibo.it Git - helm.git/blob - helm/interface/cicParser.ml
ec8c5efb8baad0f92b8db716cd18ad49191e0083
[helm.git] / helm / interface / cicParser.ml
1 (******************************************************************************)
2 (*                                                                            *)
3 (*                               PROJECT HELM                                 *)
4 (*                                                                            *)
5 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
6 (*                                 24/01/2000                                 *)
7 (*                                                                            *)
8 (* This is the main (top level) module of a parser for cic objects from xml   *)
9 (* files to the internal representation. It uses the modules cicParser2       *)
10 (* (objects level) and cicParser3 (terms level)                               *)
11 (*                                                                            *)
12 (******************************************************************************)
13
14 exception Warnings;;
15
16 class warner =
17   object 
18     method warn w =
19       print_endline ("WARNING: " ^ w) ;
20       (raise Warnings : unit)
21   end
22 ;;
23
24 exception EmptyUri;;
25
26 (* given an uri u it returns the list of tokens of the base uri of u *)
27 (* e.g.: token_of_uri "cic:/a/b/c/d.xml" returns ["a" ; "b" ; "c"]   *)
28 let tokens_of_uri uri =
29  let uri' = UriManager.string_of_uri uri in
30  let rec chop_list =
31   function
32      [] -> raise EmptyUri
33    | he::[fn] -> [he]
34    | he::tl -> he::(chop_list tl)
35  in
36   let trimmed_uri = Str.replace_first (Str.regexp "cic:") "" uri' in
37    let list_of_tokens = Str.split (Str.regexp "/") trimmed_uri in
38     chop_list list_of_tokens
39 ;;
40
41 (* given the filename of an xml file of a cic object it returns its internal *)
42 (* representation. process_annotations is true if the annotations do really  *)
43 (* matter                                                                    *)
44 let term_of_xml filename uri process_annotations =
45  let module Y = Pxp_yacc in
46   try 
47     let d =
48       (* sets the current base uri to resolve relative URIs *)
49       CicParser3.current_sp := tokens_of_uri uri ;
50       CicParser3.current_uri := uri ;
51       CicParser3.process_annotations := process_annotations ;
52       CicParser3.ids_to_targets :=
53        if process_annotations then Some (Hashtbl.create 500) else None ;
54       let config = {Y.default_config with Y.warner = new warner} in
55       Y.parse_document_entity config
56 (*PXP       (Y.ExtID (Pxp_types.System filename,
57          new Pxp_reader.resolve_as_file ~url_of_id ()))
58 *)     (PxpUriResolver.from_file filename)
59        CicParser3.domspec
60     in
61      let ids_to_targets = !CicParser3.ids_to_targets in
62       let res = (CicParser2.get_term d#root, ids_to_targets) in
63        CicParser3.ids_to_targets := None ; (* let's help the GC *)
64        res
65   with
66    e ->
67      print_endline (Pxp_types.string_of_exn e) ;
68      raise e
69 ;;