1 let connection_param = "host=mowgli.cs.unibo.it dbname=helm user=helm"
3 let show_queries = ref false
13 if ! use_db then begin Mqint.init connection_param; db_down := false; true end
14 else begin print_endline "Not issuing in restricted mode"; false end
17 let default_confirm q =
18 let module Util = MQueryUtil in
19 if ! show_queries then print_string (Util.text_of_query q ^ nl);
20 let b = check_db () in
21 if ! db_down then print_endline "db_down"; b
25 let lexbuf = Lexing.from_channel stdin in
28 match CicTextualParserContext.main
29 (UriManager.uri_of_string "cic:/dummy") [] []
30 CicTextualLexer.token lexbuf
33 | Some (_, expr) -> terms := expr :: ! terms
37 CicTextualParser0.Eof -> ! terms
40 let u = UriManager.uri_of_string uri in
41 let s = match (CicEnvironment.get_obj u) with
42 | Cic.Definition (_, _, ty, _) -> CicPp.ppterm ty
43 | Cic.Axiom (_, ty, _) -> CicPp.ppterm ty
44 | Cic.Variable (_, _, ty) -> CicPp.ppterm ty
45 | _ -> "Current proof or inductive definition."
47 | Cic.CurrentProof (_,conjs,te,ty) ->
48 | C.InductiveDefinition _ ->
50 in print_endline s; flush stdout
53 let on = check_db () in
54 if on then ignore (Mqint.check ())
56 let rec display = function
60 print_string ("? " ^ CicPp.ppterm term ^ nl);
64 let module Gen = MQueryGenerator in
65 let rec levels_aux = function
69 print_string ("? " ^ CicPp.ppterm term ^ nl);
70 print_string (Gen.string_of_levels (Gen.levels_of_term [] [] term) nl);
76 let module Util = MQueryUtil in
77 let module Gen = MQueryGenerator in
78 Gen.set_confirm_query default_confirm;
80 let q = Util.query_of_text (Lexing.from_channel ich) in
81 print_endline (Util.text_of_result (Gen.execute_query q) nl);
83 with Gen.Discard -> ()
86 let module Util = MQueryUtil in
87 let module Gen = MQueryGenerator in
88 Gen.set_confirm_query default_confirm;
90 print_endline (Util.text_of_result (Gen.locate name) nl);
92 with Gen.Discard -> ()
95 let module Util = MQueryUtil in
96 let module Gen = MQueryGenerator in
97 let queries = ref [] in
99 if List.mem query ! queries then false
100 else begin queries := query :: ! queries; default_confirm query end
102 let rec backward level = function
106 print_string ("? " ^ CicPp.ppterm term ^ nl);
108 let t0 = Sys.time () in
109 let r = Gen.backward [] [] term level in
110 let t1 = Sys.time () -. t0 in
111 let info = List.nth (Gen.get_query_info ()) 0 in
112 print_string ("GEN = " ^ info ^ ":" ^ string_of_float t1 ^ "s" ^ nl);
113 print_string (Util.text_of_result r nl);
115 with Gen.Discard -> ()
117 Gen.set_confirm_query confirm;
118 for level = max m n downto min m n do
119 prerr_endline ("toplevel: backward: trying level " ^
120 string_of_int level);
123 prerr_endline ("toplevel: backward: " ^
124 string_of_int (List.length ! queries) ^
128 prerr_endline "\nUSAGE: toplevel.opt OPTIONS < INPUTFILE\n";
129 prerr_endline "The tool provides a textual interface to the HELM Query Generator, used for";
130 prerr_endline "testing purposes. Toplevel reads its input from stdin and produces ith output";
131 prerr_endline "in HTML on stdout. The options can be one ore more of the following.\n";
132 prerr_endline "OPTIONS:\n";
133 prerr_endline "-h -help shows this help message";
134 prerr_endline "-q -show-queries outputs the generated queries";
135 prerr_endline "-c -db-check checks the database connection";
136 prerr_endline "-r -restricted -nodb enables restricted mode: queries are not issued";
137 prerr_endline "-t -typeof URI outputs the CIC type of the given HELM object";
138 prerr_endline "-x -execute issues a query given in the input file";
139 prerr_endline "-d -disply outputs the CIC terms given in the input file";
140 prerr_endline "-l -levels outputs the cut levels of the CIC terms given in the input file";
141 prerr_endline "-L -locate ALIAS issues the \"Locate\" query for the given alias";
142 prerr_endline "-B -backward LEVEL issues the \"Backward\" query for the given level on all CIC terms";
143 prerr_endline " in the input file";
144 prerr_endline "-MB -multi-backward MAX issues the \"Backward\" query for each level from max to 0 on all";
145 prerr_endline " CIC terms in the input file\n";
146 prerr_endline "NOTES: CIC terms are read with the HELM CIC Textual Parser";
147 prerr_endline " -typeof does not work with inductive types and proofs in progress\n"
150 let rec parse = function
152 | ("-h"|"-help") :: rem -> prerr_help ()
153 | ("-d"|"-display") :: rem -> display (get_terms ())
154 | ("-t"|"-typeof") :: arg :: rem -> pp_type_of arg; parse rem
155 | ("-l"|"-levels") :: rem -> levels (get_terms ())
156 | ("-x"|"-execute") :: rem -> execute stdin; parse rem
157 | ("-q"|"-show-queries") :: rem -> show_queries := true; parse rem
158 | ("-r"|"-restricted"|"-nodb") :: rem -> use_db := false; parse rem
159 | ("-c"|"-db-check") :: rem -> dbc (); parse rem
160 | ("-L"|"-locate") :: arg :: rem -> locate arg; parse rem
161 | ("-B"|"-backward") :: arg :: rem ->
162 let m = (int_of_string arg) in
163 mbackward m m (get_terms ())
164 | ("-MB"|"-multi-backward") :: arg :: rem ->
165 let m = (int_of_string arg) in
166 mbackward m 0 (get_terms ())
167 | _ :: rem -> parse rem
169 parse (List.tl (Array.to_list Sys.argv))
172 let module Gen = MQueryGenerator in
174 Logger.log_callback :=
176 ~print_and_flush:(function s -> print_string s ; flush stdout)) ;
177 Gen.set_log_file "MQGenLog.htm";
179 if not ! db_down then Mqint.close ();
180 Gen.set_confirm_query (fun _ -> true);
181 prerr_endline ("toplevel: done in " ^ string_of_float (Sys.time ()) ^