4 let mqi_debug_fun = ignore
6 let mqi_handle = MQIConn.init mqi_flags mqi_debug_fun
10 exception Failure of string
11 exception Multiple_interpretations
12 let fail msg = raise (Failure msg)
14 let uri_predicate = ref BatchParser.constants_only
16 module DisambiguateCallbacks =
18 let interactive_user_uri_choice
19 ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id choices =
20 List.filter !uri_predicate choices
22 let interactive_interpretation_choice _ = raise Multiple_interpretations
23 let input_or_locate_uri ~title = fail ("Unknown identifier: " ^ title)
26 module Disambiguate' = Disambiguate.Make (DisambiguateCallbacks)
28 let debug_print s = prerr_endline ("^^^^^^ " ^ s)
31 let obj = CicEnvironment.get_obj uri in
32 let (annobj, _, _, ids_to_inner_sorts, _, _, _) =
33 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
35 let ids_to_uris = Hashtbl.create 1023 in
36 let round_trip annterm =
37 debug_print "(1) acic -> ast";
39 Acic2Ast.ast_of_acic ids_to_inner_sorts ids_to_uris annterm
41 let new_pp = BoxPp.pp_term ast in
42 debug_print ("ast:\n" ^ new_pp);
43 let new_ast = CicTextualParser2.parse_term (Stream.of_string new_pp) in
44 debug_print ("new_ast:\n" ^ CicAstPp.pp_term ast);
46 Disambiguate'.disambiguate_term mqi_handle [] [] new_ast
47 DisambiguateTypes.Environment.empty
49 debug_print ("term: " ^ CicPp.ppterm term)
52 | Cic.AConstant (_, _, _, None, ty, _) ->
53 debug_print "Cic.AConstant (ty)";
55 | Cic.AConstant (_, _, _, Some bo, ty, _) ->
57 debug_print "Cic.AConstant (bo)";
60 debug_print "Cic.AConstant (ty)";
62 | Cic.AVariable (_, _, None, ty, _) ->
63 debug_print "Cic.AVariable (ty)";
65 | Cic.AVariable (_, _, Some bo, ty, _) ->
66 debug_print "Cic.AVariable (bo)";
68 debug_print "Cic.AVariable (ty)";
70 | Cic.ACurrentProof (_, _, _, _, proof, ty, _) ->
71 debug_print "Cic.ACurrentProof (proof)";
73 debug_print "Cic.ACurrentProof (ty)";
75 | Cic.AInductiveDefinition _ ->
76 debug_print "AInductiveDefinition: boh ..."
83 | Multiple_interpretations -> `Maybe
85 prerr_endline (sprintf "Top Level Uncaught Exception: %s"
86 (Printexc.to_string exn));
89 let report (ok,nok,maybe) =
91 print_endline "TestLibrary report";
92 print_endline "Succeeded URIs:";
93 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !ok);
94 print_endline "Failed URIs:";
95 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !nok);
96 print_endline "Multiple answers URIs:";
97 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !maybe);
100 let do_uri (ok, nok, maybe) uri =
101 let uri_str = UriManager.string_of_uri uri in
102 printf "Testing URI: %-55s %!" (uri_str ^ " ...");
103 match test_uri uri with
105 print_endline "
\e[01;32m[ OK ]
\e[00m";
108 print_endline "
\e[01;31m[ FAILED ]
\e[00m";
109 nok := uri_str :: !nok
111 print_endline "
\e[01;33m[ MANY ]
\e[00m";
112 maybe := uri_str :: !maybe
114 let do_file status fname =
116 let ic = open_in fname in
119 let line = input_line ic in
121 let uri = UriManager.uri_of_string line in
123 with UriManager.IllFormedUri _ ->
124 printf "Error parsing URI '%s', ignoring it" line
129 printf "Error trying to access '%s' (%s), skipping the file\n%!"
130 fname (Printexc.to_string exn)
133 Helm_registry.load_from "triciclo.conf.xml";
134 HelmLogger.register_log_callback
135 (fun ?(append_NL = true) msg ->
136 (if append_NL then prerr_endline else prerr_string)
137 (HelmLogger.string_of_html_msg msg));
138 let names = ref [] in
139 let tryvars = ref false in
140 let varsprefix = ref "" in
141 let usage = "testlibrary [OPTION] ... (uri1 | file1) (uri2 | file2) ..." in
143 [ "-vars", Arg.Set tryvars, "try also variables" ;
144 "-novars", Arg.Clear tryvars, "do not try variables (default)" ;
145 "-varsprefix", Arg.Set_string varsprefix,
146 "limit variable choices to URIs beginning with prefix" ;
149 Arg.parse spec (fun name -> names := name :: !names) usage;
150 let names = List.rev !names in
151 uri_predicate := BatchParser.uri_pred_of_conf !tryvars !varsprefix;
152 let status = (ref [], ref [], ref []) in (* <ok, nok, maybe> URIs *)
156 let uri = UriManager.uri_of_string name in
158 with UriManager.IllFormedUri _ ->
159 if Sys.file_exists name then
162 printf "Don't know what to do with '%s', ignoring it\n%!" name)