4 Helm_registry.load_from "gTopLevel.conf.xml";;
6 let mqi_debug_fun = ignore
8 let mqi_handle = MQIConn.init ~flags:mqi_flags ~log:mqi_debug_fun ()
12 exception Failure of string
13 let fail msg = raise (Failure msg)
15 let uri_predicate = ref (BatchParser.constants_only ~prefix:"")
17 module DisambiguateCallbacks =
19 let interactive_user_uri_choice
20 ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id choices =
21 List.filter !uri_predicate choices
23 let interactive_interpretation_choice =
27 | _::tl -> n::(aux (n+1) tl)
31 let input_or_locate_uri ~title = fail ("Unknown identifier: " ^ title)
34 module Disambiguate' = Disambiguate.Make (DisambiguateCallbacks)
36 let debug_print s = prerr_endline ("^^^^^^ " ^ s)
39 let obj = CicEnvironment.get_obj uri in
40 let (annobj, _, _, ids_to_inner_sorts, _, _, _) =
41 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
43 let ids_to_uris = Hashtbl.create 1023 in
44 let round_trip annterm =
45 debug_print "(1) acic -> ast";
47 Acic2Ast.ast_of_acic ids_to_inner_sorts ids_to_uris annterm
49 let new_pp = BoxPp.pp_term ast in
50 debug_print ("ast:\n" ^ new_pp);
51 let new_ast = CicTextualParser2.parse_term (Stream.of_string new_pp) in
52 debug_print ("new_ast:\n" ^ CicAstPp.pp_term ast);
54 Disambiguate'.disambiguate_term mqi_handle [] [] new_ast
55 DisambiguateTypes.Environment.empty in
57 (fun (domain, _, term) ->
59 ("domain: " ^ CicTextualParser2.EnvironmentP3.to_string domain) ;
60 debug_print ("term: " ^ CicPp.ppterm term)
65 | Cic.AConstant (_, _, _, None, ty, _) ->
66 debug_print "Cic.AConstant (ty)";
68 | Cic.AConstant (_, _, _, Some bo, ty, _) ->
70 debug_print "Cic.AConstant (bo)";
71 let n = round_trip bo in
73 debug_print "Cic.AConstant (ty)";
74 round_trip ty (* + n *)
75 | Cic.AVariable (_, _, None, ty, _) ->
76 debug_print "Cic.AVariable (ty)";
78 | Cic.AVariable (_, _, Some bo, ty, _) ->
80 debug_print "Cic.AVariable (bo)";
81 let n = round_trip bo in
83 debug_print "Cic.AVariable (ty)";
84 round_trip ty (* + n *)
85 | Cic.ACurrentProof (_, _, _, _, _, _, _) ->
87 | Cic.AInductiveDefinition _ ->
88 debug_print "AInductiveDefinition: boh ..." ;
93 if test_uri uri = 1 then `Ok else `Maybe
96 prerr_endline (sprintf "Top Level Uncaught Exception: %s"
97 (Printexc.to_string exn));
100 let report (ok,nok,maybe) =
102 print_endline "TestLibrary report";
103 print_endline "Succeeded URIs:";
104 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !ok);
105 print_endline "Failed URIs:";
106 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !nok);
107 print_endline "Multiple answers URIs:";
108 List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !maybe);
111 let do_uri (ok, nok, maybe) uri =
112 let uri_str = UriManager.string_of_uri uri in
113 printf "Testing URI: %-55s %!" (uri_str ^ " ...");
114 match test_uri uri with
116 print_endline "
\e[01;32m[ OK ]
\e[00m";
119 print_endline "
\e[01;31m[ FAILED ]
\e[00m";
120 nok := uri_str :: !nok
122 print_endline "
\e[01;33m[ MANY ]
\e[00m";
123 maybe := uri_str :: !maybe
125 let do_file status fname =
127 let ic = open_in fname in
130 let line = input_line ic in
132 let uri = UriManager.uri_of_string line in
134 with UriManager.IllFormedUri _ ->
135 printf "Error parsing URI '%s', ignoring it" line
140 printf "Error trying to access '%s' (%s), skipping the file\n%!"
141 fname (Printexc.to_string exn)
144 HelmLogger.register_log_callback
145 (fun ?(append_NL = true) msg ->
146 (if append_NL then prerr_endline else prerr_string)
147 (HelmLogger.string_of_html_msg msg));
148 let names = ref [] in
149 let tryvars = ref false in
150 let prefix = ref "" in
151 let varsprefix = ref "####" in
152 let usage = "testlibrary [OPTION] ... (uri1 | file1) (uri2 | file2) ..." in
154 [ "-vars", Arg.Set tryvars, "try also variables" ;
155 "-novars", Arg.Clear tryvars, "do not try variables (default)" ;
156 "-prefix", Arg.Set_string prefix,
157 "limit object choices to URIs beginning with prefix" ;
158 "-varsprefix", Arg.Set_string varsprefix,
159 "limit variable choices to URIs beginning with prefix; overrides -prefix" ;
162 Arg.parse spec (fun name -> names := name :: !names) usage;
163 let names = List.rev !names in
164 if !varsprefix = "####" then varsprefix := !prefix ;
166 BatchParser.uri_pred_of_conf !tryvars ~prefix:!prefix ~varsprefix:!varsprefix;
167 let status = (ref [], ref [], ref []) in (* <ok, nok, maybe> URIs *)
171 let uri = UriManager.uri_of_string name in
173 with UriManager.IllFormedUri _ ->
174 if Sys.file_exists name then
177 printf "Don't know what to do with '%s', ignoring it\n%!" name)