1 (******************************************************************************)
5 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
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) *)
12 (******************************************************************************)
19 print_endline ("WARNING: " ^ w) ;
20 (raise Warnings : unit)
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
34 | he::tl -> he::(chop_list tl)
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
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 *)
44 let term_of_xml filename uri process_annotations =
45 let module Y = Pxp_yacc in
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)
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 *)
67 print_endline ("Filename: " ^ filename ^ "\nException: ") ;
68 print_endline (Pxp_types.string_of_exn e) ;