1 (* Copyright (C) 2000-2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 let debug_level = ref 1
37 let debug_print ?(level = 1) s = if !debug_level >= level then prerr_endline s
38 let error s = prerr_endline ("E: " ^ s)
39 let warning s = prerr_endline ("W: " ^ s)
45 module MQI = MQueryInterpreter
47 module MQGT = MQGTypes
49 module MQG = MQueryGenerator
53 (* first of all let's initialize the Helm_registry *)
55 let configuration_file = "gTopLevel.conf.xml" in
56 if not (Sys.file_exists configuration_file) then begin
57 eprintf "E: Can't find configuration file '%s'\n" configuration_file;
60 Helm_registry.load_from configuration_file
63 (* GLOBAL CONSTANTS *)
65 let mqi_debug_fun s = debug_print ~level:2 s
66 let mqi_handle = MQIC.init_if_connected ~log:mqi_debug_fun ()
67 let dbh = new DB.connection ~host:"mowgli.cs.unibo.it" ~user:"helm" "mowgli"
69 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
71 let restore_environment_on_boot = true ;;
72 let notify_hbugs_on_goal_change = false ;;
74 let auto_disambiguation = ref true ;;
76 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
78 let check_term = ref (fun _ _ _ -> assert false);;
80 exception RenderingWindowsNotInitialized;;
82 let set_rendering_window,rendering_window =
83 let rendering_window_ref = ref None in
84 (function rw -> rendering_window_ref := Some rw),
86 match !rendering_window_ref with
87 None -> raise RenderingWindowsNotInitialized
92 exception SettingsWindowsNotInitialized;;
94 let set_settings_window,settings_window =
95 let settings_window_ref = ref None in
96 (function rw -> settings_window_ref := Some rw),
98 match !settings_window_ref with
99 None -> raise SettingsWindowsNotInitialized
104 exception QedSetSensitiveNotInitialized;;
105 let qed_set_sensitive =
106 ref (function _ -> raise QedSetSensitiveNotInitialized)
109 exception SaveSetSensitiveNotInitialized;;
110 let save_set_sensitive =
111 ref (function _ -> raise SaveSetSensitiveNotInitialized)
114 (* COMMAND LINE OPTIONS *)
120 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
123 Arg.parse argspec ignore ""
125 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
129 let check_window uris =
132 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
134 GPack.notebook ~scrollable:true ~packing:window#add () in
139 let scrolled_window =
140 GBin.scrolled_window ~border_width:10
142 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
147 TermViewer.sequent_viewer
148 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
149 ~packing:scrolled_window#add ~width:400 ~height:280 () in
151 let term = CicUtil.term_of_uri uri in
152 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
155 mmlwidget#load_sequent [] (111,[],expr)
158 HelmLogger.log (`Error (`T (Printexc.to_string e)))
163 (notebook#connect#switch_page
165 Lazy.force (List.nth render_terms i)))
170 let interactive_user_uri_choice
171 ~(selection_mode:[ `SINGLE | `MULTIPLE ])
172 ?(ok="Ok") ?(enable_button_for_non_vars=false) ~title ~msg uris
174 let only_constant_choices =
177 (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
180 if selection_mode <> `SINGLE && !auto_disambiguation then
181 Lazy.force only_constant_choices
183 let choices = ref [] in
184 let chosen = ref false in
185 let use_only_constants = ref false in
187 GWindow.dialog ~modal:true ~title ~width:600 () in
189 GMisc.label ~text:msg
190 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
191 let scrolled_window =
192 GBin.scrolled_window ~border_width:10
193 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
195 let expected_height = 18 * List.length uris in
196 let height = if expected_height > 400 then 400 else expected_height in
197 GList.clist ~columns:1 ~packing:scrolled_window#add
198 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
199 let _ = List.map (function x -> clist#append [x]) uris in
201 GPack.hbox ~border_width:0
202 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
204 GMisc.label ~text:"None of the above. Try this one:"
205 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
207 GEdit.entry ~editable:true
208 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
210 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
212 GButton.button ~label:ok
213 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
214 let _ = okb#misc#set_sensitive false in
219 if enable_button_for_non_vars then
220 hbox#pack ~expand:false ~fill:false ~padding:5 w)
221 ~label:"Try constants only" () in
226 if enable_button_for_non_vars then
227 hbox#pack ~expand:false ~fill:false ~padding:5 w)
230 GButton.button ~label:"Check"
231 ~packing:(hbox#pack ~padding:5) () in
232 let _ = checkb#misc#set_sensitive false in
234 GButton.button ~label:"Abort"
235 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
237 let check_callback () =
238 assert (List.length !choices > 0) ;
239 check_window !choices
241 ignore (window#connect#destroy GMain.Main.quit) ;
242 ignore (cancelb#connect#clicked window#destroy) ;
244 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
246 (nonvarsb#connect#clicked
248 use_only_constants := true ;
252 ignore (autob#connect#clicked (fun () ->
253 auto_disambiguation := true;
254 (rendering_window ())#set_auto_disambiguation true;
255 use_only_constants := true ;
258 ignore (checkb#connect#clicked check_callback) ;
260 (clist#connect#select_row
261 (fun ~row ~column ~event ->
262 checkb#misc#set_sensitive true ;
263 okb#misc#set_sensitive true ;
264 choices := (List.nth uris row)::!choices)) ;
266 (clist#connect#unselect_row
267 (fun ~row ~column ~event ->
269 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
271 (manual_input#connect#changed
273 if manual_input#text = "" then
276 checkb#misc#set_sensitive false ;
277 okb#misc#set_sensitive false ;
278 clist#misc#set_sensitive true
282 choices := [manual_input#text] ;
283 clist#unselect_all () ;
284 checkb#misc#set_sensitive true ;
285 okb#misc#set_sensitive true ;
286 clist#misc#set_sensitive false
288 window#set_position `CENTER ;
292 if !use_only_constants then
293 Lazy.force only_constant_choices
295 if List.length !choices > 0 then !choices else raise NoChoice
301 let interactive_interpretation_choice interpretations =
302 let chosen = ref None in
305 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
306 let vbox = GPack.vbox ~packing:window#add () in
310 ("Ambiguous input since there are many well-typed interpretations." ^
311 " Please, choose one of them.")
312 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
314 GPack.notebook ~scrollable:true
315 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
318 (function interpretation ->
320 let expected_height = 18 * List.length interpretation in
321 let height = if expected_height > 400 then 400 else expected_height in
322 GList.clist ~columns:2 ~packing:notebook#append_page ~height
323 ~titles:["id" ; "URI"] ()
327 (function (id,uri) ->
328 let n = clist#append [id;uri] in
329 clist#set_row ~selectable:false n
332 clist#columns_autosize ()
335 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
337 GButton.button ~label:"Ok"
338 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
340 GButton.button ~label:"Abort"
341 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
343 ignore (window#connect#destroy GMain.Main.quit) ;
344 ignore (cancelb#connect#clicked window#destroy) ;
347 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
348 window#set_position `CENTER ;
352 None -> raise NoChoice
360 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
363 let struri = UriManager.string_of_uri uri in
364 let idx = (String.rindex struri '/') + 1 in
365 String.sub struri idx (String.length struri - idx)
367 let path = pathname ^ "/" ^ name in
369 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
373 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
374 ~ask_dtd_to_the_getter:false
377 let innertypesuri = UriManager.innertypesuri_of_uri uri in
378 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
379 Http_getter.register' innertypesuri
380 (Helm_registry.get "local_library.url" ^
381 Str.replace_first (Str.regexp "^cic:") ""
382 (UriManager.string_of_uri innertypesuri) ^ ".xml"
384 (* constant type / variable / mutual inductive types definition *)
385 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
386 Http_getter.register' uri
387 (Helm_registry.get "local_library.url" ^
388 Str.replace_first (Str.regexp "^cic:") ""
389 (UriManager.string_of_uri uri) ^ ".xml"
396 match UriManager.bodyuri_of_uri uri with
398 | Some bodyuri -> bodyuri
400 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
401 Http_getter.register' bodyuri
402 (Helm_registry.get "local_library.url" ^
403 Str.replace_first (Str.regexp "^cic:") ""
404 (UriManager.string_of_uri bodyuri) ^ ".xml"
411 exception OpenConjecturesStillThere;;
412 exception WrongProof;;
414 let pathname_of_annuri uristring =
415 Helm_registry.get "local_library.dir" ^
416 Str.replace_first (Str.regexp "^cic:") "" uristring
419 let make_dirs dirpath =
420 ignore (Unix.system ("mkdir -p " ^ dirpath))
423 let save_obj uri obj =
425 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
426 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
428 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
430 (* let's save the theorem and register it to the getter *)
431 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
433 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
438 match ProofEngine.get_proof () with
440 | Some (uri,[],bo,ty) ->
441 let uri = match uri with Some uri -> uri | _ -> assert false in
442 (* we want to typecheck in the ENV *)
443 (*let old_working = CicUniv.get_working () in
444 CicUniv.set_working (CicUniv.get_global ());*)
445 CicUniv.directly_to_env_begin () ;
446 prerr_endline "-------------> QED";
448 CicReduction.are_convertible []
449 (CicTypeChecker.type_of_aux' [] [] bo) ty
452 (*CSC: Wrong: [] is just plainly wrong *)
453 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
454 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
455 (rendering_window ())#output#load_proof uri proof
457 !qed_set_sensitive false ;
458 (* let's save the theorem and register it to the getter *)
459 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
461 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
463 (* add the object to the env *)
464 CicEnvironment.add_type_checked_term uri (
465 Cic.Constant ((UriManager.name_of_uri uri),(Some bo),ty,[]));
466 (* FIXME: the variable list!! *)
468 CicUniv.qed (); (* now the env has the right constraints *)*)
469 CicUniv.directly_to_env_end();
470 CicUniv.reset_working ();
471 prerr_endline "-------------> FINE";
475 | _ -> raise OpenConjecturesStillThere
478 (** save an unfinished proof on the filesystem *)
479 let save_unfinished_proof () =
480 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
481 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
482 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
483 Xml.pp ~quiet:true xml (Some proof_file_type) ;
485 (`Msg (`T ("Current proof type saved to " ^ proof_file_type))) ;
486 Xml.pp ~quiet:true bodyxml (Some proof_file) ;
488 (`Msg (`T ("Current proof body saved to " ^ proof_file)))
491 (* Used to typecheck the loaded proofs *)
492 let typecheck_loaded_proof metasenv bo ty =
493 let module T = CicTypeChecker in
496 (fun metasenv ((_,context,ty) as conj) ->
497 ignore (T.type_of_aux' metasenv context ty) ;
500 ignore (T.type_of_aux' metasenv [] ty) ;
501 ignore (T.type_of_aux' metasenv [] bo)
504 let decompose_uris_choice_callback uris =
505 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
506 let module U = UriManager in
509 match CicUtil.term_of_uri uri with
510 | Cic.MutInd (uri, typeno, _) -> (uri, typeno, [])
512 (interactive_user_uri_choice
513 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
514 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
516 (function (uri,typeno,_) ->
517 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
522 let mk_fresh_name_callback metasenv context name ~typ =
524 match FreshNamesGenerator.mk_fresh_name metasenv context name ~typ with
525 Cic.Name fresh_name -> fresh_name
526 | Cic.Anonymous -> assert false
529 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
530 ("Enter a fresh name for the hypothesis " ^
532 (List.map (function None -> None | Some (n,_) -> Some n) context))
534 Some fresh_name' -> Cic.Name fresh_name'
535 | None -> raise NoChoice
538 let refresh_proof (output : TermViewer.proof_viewer) =
540 let uri,currentproof =
541 match ProofEngine.get_proof () with
543 | Some (uri,metasenv,bo,ty) ->
544 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
545 if List.length metasenv = 0 then
547 !qed_set_sensitive true ;
552 (*CSC: Wrong: [] is just plainly wrong *)
553 let uri = match uri with Some uri -> uri | _ -> assert false in
555 Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
557 ignore (output#load_proof uri currentproof)
560 match ProofEngine.get_proof () with
562 | Some (uri,metasenv,bo,ty) ->
563 debug_print ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[])));
564 raise (InvokeTactics.RefreshProofException e)
566 let set_proof_engine_goal g =
567 ProofEngine.goal := g
570 let refresh_goals ?(empty_notebook=true) notebook =
572 match !ProofEngine.goal with
574 if empty_notebook then
576 notebook#remove_all_pages ~skip_switch_page_event:false ;
577 notebook#set_empty_page
580 notebook#proofw#unload
583 match ProofEngine.get_proof () with
585 | Some (_,metasenv,_,_) -> metasenv
588 List.find (function (m,_,_) -> m=metano) metasenv
590 let regenerate_notebook () =
591 let skip_switch_page_event =
593 (m,_,_)::_ when m = metano -> false
596 notebook#remove_all_pages ~skip_switch_page_event ;
597 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
599 if empty_notebook then
601 regenerate_notebook () ;
602 notebook#set_current_page
603 ~may_skip_switch_page_event:false metano
607 notebook#set_current_page
608 ~may_skip_switch_page_event:true metano ;
609 prerr_endline "CIAO CIAO" ;
610 prerr_endline ("SEQUENTE CORRENTE: " ^ SequentPp.TextualPp.print_sequent currentsequent) ;
611 notebook#proofw#load_sequent metasenv currentsequent ;
612 prerr_endline "pASSO CIAO CIAO"
617 match !ProofEngine.goal with
622 match ProofEngine.get_proof () with
624 | Some (_,metasenv,_,_) -> metasenv
627 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
629 ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent);
630 raise (InvokeTactics.RefreshSequentException e)
632 debug_print ("Offending sequent " ^ string_of_int metano ^ " unknown.");
633 raise (InvokeTactics.RefreshSequentException e)
635 module InvokeTacticsCallbacks =
637 let sequent_viewer () = (rendering_window ())#notebook#proofw
638 let term_editor () = (rendering_window ())#inputt
639 let scratch_window () = (rendering_window ())#scratch_window
641 let refresh_proof () =
642 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
645 let refresh_goals () =
646 let notebook = (rendering_window ())#notebook in
647 refresh_goals notebook
649 let decompose_uris_choice_callback = decompose_uris_choice_callback
650 let mk_fresh_name_callback = mk_fresh_name_callback
651 let mqi_handle = mqi_handle
655 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
657 (* Just to initialize the Hbugs module *)
658 module Ignore = Hbugs.Initialize (InvokeTactics');;
659 Hbugs.set_describe_hint_callback (fun hint ->
661 | Hbugs_types.Use_apply_Luke term -> check_window [term]
665 let dummy_uri = "/dummy.con"
667 (** load an unfinished proof from filesystem *)
668 let load_unfinished_proof () =
669 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
670 let notebook = (rendering_window ())#notebook in
673 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
676 None -> raise NoChoice
678 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
679 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
680 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
681 match CicParser.obj_of_xml proof_file_type (Some proof_file) with
682 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
683 typecheck_loaded_proof metasenv bo ty ;
684 ProofEngine.set_proof (Some (Some uri, metasenv, bo, ty));
685 refresh_proof output ;
686 set_proof_engine_goal
689 | (metano,_,_)::_ -> Some metano
691 refresh_goals notebook ;
693 (`Msg (`T ("Current proof type loaded from " ^ proof_file_type)));
695 (`Msg (`T ("Current proof body loaded from " ^ proof_file))) ;
696 !save_set_sensitive true;
699 InvokeTactics.RefreshSequentException e ->
701 (`Error (`T ("Exception raised during the refresh of the " ^
702 "sequent: " ^ Printexc.to_string e)))
703 | InvokeTactics.RefreshProofException e ->
705 (`Error (`T ("Exception raised during the refresh of the " ^
706 "proof: " ^ Printexc.to_string e)))
709 (`Error (`T (Printexc.to_string e)))
712 let clear_aliases () =
713 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
714 inputt#environment :=
715 DisambiguatingParser.EnvironmentP3.of_string
716 DisambiguatingParser.EnvironmentP3.empty
719 let edit_aliases () =
720 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
721 let disambiguation_env = inputt#environment in
722 let chosen_aliases = ref None in
725 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
727 GPack.vbox ~border_width:0 ~packing:window#add () in
728 let scrolled_window =
729 GBin.scrolled_window ~border_width:10
730 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
731 let input = GText.view ~editable:true ~width:400 ~height:100
732 ~packing:scrolled_window#add () in
734 GPack.hbox ~border_width:0
735 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
737 GButton.button ~label:"Ok"
738 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
740 GButton.button ~label:"Clear"
741 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
743 GButton.button ~label:"Cancel"
744 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
745 ignore (window#connect#destroy GMain.Main.quit) ;
746 ignore (cancelb#connect#clicked window#destroy) ;
747 ignore (clearb#connect#clicked (fun () ->
748 input#buffer#set_text DisambiguatingParser.EnvironmentP3.empty)) ;
749 ignore (okb#connect#clicked (fun () ->
750 chosen_aliases := Some (input#buffer#get_text ());
753 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
754 (DisambiguatingParser.EnvironmentP3.to_string !disambiguation_env ^ "\n"));
757 match !chosen_aliases with
759 | Some raw_aliases ->
760 let new_disambiguation_env =
762 DisambiguatingParser.EnvironmentP3.of_string raw_aliases
766 ("Error while parsing aliases: " ^ Printexc.to_string e)));
769 disambiguation_env := new_disambiguation_env
773 let module L = LogicalOperations in
774 let module G = Gdome in
775 let notebook = (rendering_window ())#notebook in
776 let output = (rendering_window ())#output in
778 output#make_sequent_of_selected_term ;
779 refresh_proof output ;
780 refresh_goals notebook
782 InvokeTactics.RefreshSequentException e ->
784 (`Error (`T ("Exception raised during the refresh of the " ^
785 "sequent: " ^ Printexc.to_string e)))
786 | InvokeTactics.RefreshProofException e ->
788 (`Error (`T ("Exception raised during the refresh of the " ^
789 "proof: " ^ Printexc.to_string e)))
792 (`Error (`T (Printexc.to_string e)))
796 let module L = LogicalOperations in
797 let module G = Gdome in
798 let notebook = (rendering_window ())#notebook in
799 let output = (rendering_window ())#output in
801 output#focus_sequent_of_selected_term ;
802 refresh_goals notebook
804 InvokeTactics.RefreshSequentException e ->
806 (`Error (`T ("Exception raised during the refresh of the " ^
807 "sequent: " ^ Printexc.to_string e)))
808 | InvokeTactics.RefreshProofException e ->
810 (`Error (`T ("Exception raised during the refresh of the " ^
811 "proof: " ^ Printexc.to_string e)))
814 (`Error (`T (Printexc.to_string e)))
817 exception NoPrevGoal;;
818 exception NoNextGoal;;
821 let module L = LogicalOperations in
822 let module G = Gdome in
823 let notebook = (rendering_window ())#notebook in
824 let output = (rendering_window ())#output in
826 match ProofEngine.get_proof () with
828 | Some (_,metasenv,_,_) -> metasenv
831 refresh_goals ~empty_notebook:false notebook
833 InvokeTactics.RefreshSequentException e ->
835 (`Error (`T ("Exception raised during the refresh of the " ^
836 "sequent: " ^ Printexc.to_string e)))
839 (`Error (`T (Printexc.to_string e)))
843 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
846 GWindow.window ~width:800 ~border_width:2 () in
847 let scrolled_window =
848 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
850 GMathViewAux.single_selection_math_view
851 ~packing:scrolled_window#add ~width:600 ~height:400 ()
853 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
854 let href = Gdome.domString "href" in
855 let show_in_show_window_obj uri obj =
858 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
859 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
861 Cic2acic.acic_object_of_cic_object obj
864 ChosenTransformer.mml_of_cic_object
865 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
867 window#set_title (UriManager.string_of_uri uri) ;
868 window#misc#hide () ; window#show () ;
869 mmlwidget#load_root mml#get_documentElement ;
873 (`Error (`T (Printexc.to_string e)))
875 let show_in_show_window_uri uri =
876 let obj = CicEnvironment.get_obj uri in
877 show_in_show_window_obj uri obj
879 let show_in_show_window_callback mmlwidget ((n : Gdome.element option),_,_,_) =
883 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
885 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
887 show_in_show_window_uri (UriManager.uri_of_string uri)
889 ignore (mmlwidget#action_toggle n')
892 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
894 show_in_show_window_obj, show_in_show_window_uri,
895 show_in_show_window_callback
898 exception NoObjectsLocated;;
900 let user_uri_choice ~title ~msg uris =
903 [] -> raise NoObjectsLocated
907 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
912 String.sub uri 4 (String.length uri - 4)
915 let locate_callback id =
916 let uris = MetadataQuery.locate ~dbh id in
917 HelmLogger.log (`Msg (`T ("Locate Query: " ^ id))) ;
918 HelmLogger.log (`Msg (`T "Result:")) ;
919 List.iter (fun uri -> HelmLogger.log (`Msg (`T uri))) uris;
920 user_uri_choice ~title:"Ambiguous input."
921 ~msg:(sprintf "Ambiguous input \"%s\". Please, choose one interpetation:" id)
926 let input_or_locate_uri ~title =
927 let uri = ref None in
930 ~width:400 ~modal:true ~title ~border_width:2 () in
931 let vbox = GPack.vbox ~packing:window#add () in
933 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
935 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
937 GEdit.entry ~editable:true
938 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
940 GButton.button ~label:"Check"
941 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
942 let _ = checkb#misc#set_sensitive false in
944 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
946 GMisc.label ~text:"You can also enter an indentifier to locate:"
947 ~packing:(hbox2#pack ~padding:5) () in
949 GEdit.entry ~editable:true
950 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
952 GButton.button ~label:"Locate"
953 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
954 let _ = locateb#misc#set_sensitive false in
956 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
958 GButton.button ~label:"Ok"
959 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
960 let _ = okb#misc#set_sensitive false in
962 GButton.button ~label:"Cancel"
963 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
965 ignore (window#connect#destroy GMain.Main.quit) ;
967 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
968 let check_callback () =
969 let uri = "cic:" ^ manual_input#text in
971 ignore (Http_getter.resolve' (UriManager.uri_of_string uri)) ;
972 HelmLogger.log (`Msg (`T "OK")) ;
975 Http_getter_types.Key_not_found _ ->
977 (`Error (`T ("URI " ^ uri ^
978 " does not correspond to any object."))) ;
980 | UriManager.IllFormedUri _ ->
982 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
986 (`Error (`T (Printexc.to_string e))) ;
992 if check_callback () then
994 uri := Some manual_input#text ;
998 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1000 (manual_input#connect#changed
1002 if manual_input#text = "" then
1004 checkb#misc#set_sensitive false ;
1005 okb#misc#set_sensitive false
1009 checkb#misc#set_sensitive true ;
1010 okb#misc#set_sensitive true
1013 (locate_input#connect#changed
1014 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1016 (locateb#connect#clicked
1018 let id = locate_input#text in
1019 manual_input#set_text (locate_callback id) ;
1020 locate_input#delete_text 0 (String.length id)
1025 None -> raise NoChoice
1026 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1029 exception AmbiguousInput;;
1031 (* A WIDGET TO ENTER CIC TERMS *)
1033 module DisambiguateCallbacks =
1035 let interactive_user_uri_choice =
1036 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1037 interactive_user_uri_choice ~selection_mode ?ok
1038 ?enable_button_for_non_vars ~title ~msg
1039 let interactive_interpretation_choice = interactive_interpretation_choice
1040 let input_or_locate_uri ~title ?id () = input_or_locate_uri ~title
1044 module TermEditor' = ChosenTermEditor.Make (DisambiguateCallbacks);;
1046 (* OTHER FUNCTIONS *)
1049 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1052 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1054 None -> raise NoChoice
1056 let uri = locate_callback input in
1061 (`Error (`T (Printexc.to_string e)))
1065 exception UriAlreadyInUse;;
1066 exception NotAUriToAConstant;;
1068 let new_inductive () =
1069 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1070 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1071 let notebook = (rendering_window ())#notebook in
1073 let chosen = ref false in
1074 let inductive = ref true in
1075 let paramsno = ref 0 in
1076 let get_uri = ref (function _ -> assert false) in
1077 let get_base_uri = ref (function _ -> assert false) in
1078 let get_names = ref (function _ -> assert false) in
1079 let get_types_and_cons = ref (function _ -> assert false) in
1080 let get_context_and_subst = ref (function _ -> assert false) in
1083 ~width:600 ~modal:true ~position:`CENTER
1084 ~title:"New Block of Mutual (Co)Inductive Definitions"
1085 ~border_width:2 () in
1086 let vbox = GPack.vbox ~packing:window#add () in
1088 GPack.hbox ~border_width:0
1089 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1091 GMisc.label ~text:"Enter the URI for the new block:"
1092 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1094 GEdit.entry ~editable:true
1095 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1097 GPack.hbox ~border_width:0
1098 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1102 "Enter the number of left parameters in every arity and constructor type:"
1103 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1104 let paramsno_entry =
1105 GEdit.entry ~editable:true ~text:"0"
1106 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1108 GPack.hbox ~border_width:0
1109 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1111 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1112 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1114 GButton.radio_button ~label:"Inductive"
1115 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1117 GButton.radio_button ~label:"Coinductive"
1118 ~group:inductiveb#group
1119 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1121 GPack.hbox ~border_width:0
1122 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1124 GMisc.label ~text:"Enter the list of the names of the types:"
1125 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1127 GEdit.entry ~editable:true
1128 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1130 GPack.hbox ~border_width:0
1131 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1133 GButton.button ~label:"> Next"
1134 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1135 let _ = okb#misc#set_sensitive true in
1137 GButton.button ~label:"Abort"
1138 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1139 ignore (window#connect#destroy GMain.Main.quit) ;
1140 ignore (cancelb#connect#clicked window#destroy) ;
1144 (okb#connect#clicked
1147 let uristr = "cic:" ^ uri_entry#text in
1148 let namesstr = names_entry#text in
1149 let paramsno' = int_of_string (paramsno_entry#text) in
1150 match Str.split (Str.regexp " +") namesstr with
1152 | (he::tl) as names ->
1153 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1156 ignore (Http_getter.resolve' uri) ;
1157 raise UriAlreadyInUse
1158 with Http_getter_types.Key_not_found _ ->
1159 get_uri := (function () -> uri) ;
1160 get_names := (function () -> names) ;
1161 inductive := inductiveb#active ;
1162 paramsno := paramsno' ;
1168 (`Error (`T (Printexc.to_string e)))
1176 GBin.frame ~label:name
1177 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1178 let vbox = GPack.vbox ~packing:frame#add () in
1179 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1181 GMisc.label ~text:("Enter its type:")
1182 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1183 let scrolled_window =
1184 GBin.scrolled_window ~border_width:5
1185 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1187 TermEditor'.term_editor
1189 ~width:400 ~height:20 ~packing:scrolled_window#add
1190 ~share_environment_with:inputt ()
1191 ~isnotempty_callback:
1193 (*non_empty_type := b ;*)
1194 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1197 GPack.hbox ~border_width:0
1198 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1200 GMisc.label ~text:("Enter the list of its constructors:")
1201 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1202 let cons_names_entry =
1203 GEdit.entry ~editable:true
1204 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1205 (newinputt,cons_names_entry)
1208 vbox#remove hboxn#coerce ;
1210 GPack.hbox ~border_width:0
1211 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1213 GButton.button ~label:"> Next"
1214 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1216 GButton.button ~label:"Abort"
1217 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1218 ignore (cancelb#connect#clicked window#destroy) ;
1220 (okb#connect#clicked
1223 let names = !get_names () in
1224 let types_and_cons =
1226 (fun name (newinputt,cons_names_entry) ->
1227 let consnamesstr = cons_names_entry#text in
1228 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1230 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1233 [] -> expr,cons_names
1234 | _ -> raise AmbiguousInput
1235 ) names type_widgets
1237 let uri = !get_uri () in
1239 (* Let's see if so far the definition is well-typed *)
1242 (* To test if the arities of the inductive types are well *)
1243 (* typed, we check the inductive block definition where *)
1244 (* no constructor is given to each type. *)
1247 (fun name (ty,cons) -> (name, !inductive, ty, []))
1248 names types_and_cons
1250 CicTypeChecker.typecheck_mutual_inductive_defs uri
1251 (tys,params,paramsno)
1253 get_context_and_subst :=
1257 (fun (context,subst) name (ty,_) ->
1259 (Some (Cic.Name name, Cic.Decl ty))::context,
1260 (Cic.MutInd (uri,!i,[]))::subst
1263 ) ([],[]) names types_and_cons) ;
1264 let types_and_cons' =
1266 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1267 names types_and_cons
1269 get_types_and_cons := (function () -> types_and_cons') ;
1275 (`Error (`T (Printexc.to_string e)))
1278 and phase3 name cons =
1279 let get_cons_types = ref (function () -> assert false) in
1282 ~width:600 ~modal:true ~position:`CENTER
1283 ~title:(name ^ " Constructors")
1284 ~border_width:2 () in
1285 let vbox = GPack.vbox ~packing:window2#add () in
1286 let cons_type_widgets =
1288 (function consname ->
1290 GPack.hbox ~border_width:0
1291 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1293 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1294 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1295 let scrolled_window =
1296 GBin.scrolled_window ~border_width:5
1297 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1299 TermEditor'.term_editor
1301 ~width:400 ~height:20 ~packing:scrolled_window#add
1302 ~share_environment_with:inputt ()
1303 ~isnotempty_callback:
1305 (* (*non_empty_type := b ;*)
1306 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1311 GPack.hbox ~border_width:0
1312 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1314 GButton.button ~label:"> Next"
1315 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1316 let _ = okb#misc#set_sensitive true in
1318 GButton.button ~label:"Abort"
1319 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1320 ignore (window2#connect#destroy GMain.Main.quit) ;
1321 ignore (cancelb#connect#clicked window2#destroy) ;
1323 (okb#connect#clicked
1327 let context,subst= !get_context_and_subst () in
1332 inputt#get_metasenv_and_term ~context ~metasenv:[]
1336 let undebrujined_expr =
1338 (fun expr t -> CicSubstitution.subst t expr) expr subst
1340 name, undebrujined_expr
1341 | _ -> raise AmbiguousInput
1342 ) cons cons_type_widgets
1344 get_cons_types := (function () -> cons_types) ;
1349 (`Error (`T (Printexc.to_string e)))
1353 let okb_pressed = !chosen in
1355 if (not okb_pressed) then
1358 assert false (* The control never reaches this point *)
1361 (!get_cons_types ())
1364 (* No more phases left or Abort pressed *)
1370 let uri = !get_uri () in
1373 let tys = !get_types_and_cons () in
1374 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1377 debug_print (CicPp.ppobj obj);
1378 CicTypeChecker.typecheck_mutual_inductive_defs uri
1379 (tys,params,!paramsno) ;
1382 debug_print "Offending mutual (co)inductive type declaration:" ;
1383 debug_print (CicPp.ppobj obj) ;
1385 (* We already know that obj is well-typed. We need to add it to the *)
1386 (* environment in order to compute the inner-types without having to *)
1387 (* debrujin it or having to modify lots of other functions to avoid *)
1388 (* asking the environment for the MUTINDs we are defining now. *)
1389 CicEnvironment.put_inductive_definition uri obj ;
1391 show_in_show_window_obj uri obj
1395 (`Error (`T (Printexc.to_string e)))
1399 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1400 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1401 let notebook = (rendering_window ())#notebook in
1403 let chosen = ref false in
1404 let get_metasenv_and_term = ref (function _ -> assert false) in
1405 let get_uri = ref (function _ -> assert false) in
1406 let non_empty_type = ref false in
1409 ~width:600 ~modal:true ~title:"New Proof or Definition"
1410 ~border_width:2 () in
1411 let vbox = GPack.vbox ~packing:window#add () in
1413 GPack.hbox ~border_width:0
1414 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1416 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1417 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1419 GEdit.entry ~editable:true
1420 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1421 uri_entry#set_text dummy_uri;
1422 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1424 GPack.hbox ~border_width:0
1425 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1427 GMisc.label ~text:"Enter the theorem or definition type:"
1428 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1429 let scrolled_window =
1430 GBin.scrolled_window ~border_width:5
1431 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1432 (* the content of the scrolled_window is moved below (see comment) *)
1434 GPack.hbox ~border_width:0
1435 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1437 GButton.button ~label:"Ok"
1438 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1439 let _ = okb#misc#set_sensitive false in
1441 GButton.button ~label:"Cancel"
1442 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1443 (* moved here to have visibility of the ok button *)
1445 TermEditor'.term_editor
1447 ~width:400 ~height:100 ~packing:scrolled_window#add
1448 ~share_environment_with:inputt ()
1449 ~isnotempty_callback:
1451 non_empty_type := b ;
1452 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1455 newinputt#set_term inputt#get_as_string ;
1458 uri_entry#connect#changed
1460 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1462 ignore (window#connect#destroy GMain.Main.quit) ;
1463 ignore (cancelb#connect#clicked window#destroy) ;
1465 (okb#connect#clicked
1469 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1470 let uristr = "cic:" ^ uri_entry#text in
1471 let uri = UriManager.uri_of_string uristr in
1472 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1473 raise NotAUriToAConstant
1477 ignore (Http_getter.resolve' uri) ;
1478 raise UriAlreadyInUse
1479 with Http_getter_types.Key_not_found _ ->
1480 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1481 get_uri := (function () -> uri) ;
1487 (`Error (`T (Printexc.to_string e)))
1493 let metasenv,expr = !get_metasenv_and_term () in
1494 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1495 ProofEngine.set_proof
1496 (Some (Some (!get_uri ()), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr));
1497 set_proof_engine_goal (Some 1) ;
1498 refresh_goals notebook ;
1499 refresh_proof output ;
1500 !save_set_sensitive true ;
1502 ProofEngine.intros ~mk_fresh_name_callback () ;
1503 refresh_goals notebook ;
1504 refresh_proof output
1506 InvokeTactics.RefreshSequentException e ->
1508 (`Error (`T ("Exception raised during the refresh of the " ^
1509 "sequent: " ^ Printexc.to_string e)))
1510 | InvokeTactics.RefreshProofException e ->
1512 (`Error (`T ("Exception raised during the refresh of the " ^
1513 "proof: " ^ Printexc.to_string e)))
1516 (`Error (`T (Printexc.to_string e)))
1519 let check_term_in_scratch scratch_window metasenv context expr =
1521 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1522 let expr = Cic.Cast (expr,ty) in
1523 scratch_window#show () ;
1524 scratch_window#set_term expr ;
1525 scratch_window#set_context context ;
1526 scratch_window#set_metasenv metasenv ;
1527 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1530 print_endline ("? " ^ CicPp.ppterm expr) ;
1534 let check scratch_window () =
1535 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1537 match ProofEngine.get_proof () with
1539 | Some (_,metasenv,_,_) -> metasenv
1542 match !ProofEngine.goal with
1545 let (_,canonical_context,_) =
1546 List.find (function (m,_,_) -> m=metano) metasenv
1551 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1552 check_term_in_scratch scratch_window metasenv' context expr
1556 (`Error (`T (Printexc.to_string e)))
1561 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1565 (`Error (`T (Printexc.to_string e)))
1568 exception NotADefinition;;
1571 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1572 let notebook = (rendering_window ())#notebook in
1574 let uri = input_or_locate_uri ~title:"Open" in
1575 ignore(CicTypeChecker.typecheck uri);
1576 (* TASSI: typecheck mette la uri nell'env... cosa fa la open_ ?*)
1577 let metasenv,bo,ty =
1578 match CicEnvironment.get_cooked_obj uri with
1579 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1580 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1583 | Cic.InductiveDefinition _ -> raise NotADefinition
1585 ProofEngine.set_proof (Some (Some uri, metasenv, bo, ty)) ;
1586 set_proof_engine_goal None ;
1587 refresh_goals notebook ;
1588 refresh_proof output ;
1589 !save_set_sensitive true
1591 InvokeTactics.RefreshSequentException e ->
1593 (`Error (`T ("Exception raised during the refresh of the " ^
1594 "sequent: " ^ Printexc.to_string e)))
1595 | InvokeTactics.RefreshProofException e ->
1597 (`Error (`T ("Exception raised during the refresh of the " ^
1598 "proof: " ^ Printexc.to_string e)))
1601 (`Error (`T (Printexc.to_string e)))
1604 let show_query_results results =
1607 ~modal:false ~title:"Query results." ~border_width:2 () in
1608 let vbox = GPack.vbox ~packing:window#add () in
1610 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1613 ~text:"Click on a URI to show that object"
1614 ~packing:hbox#add () in
1615 let scrolled_window =
1616 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1617 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1618 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1621 (function (uri,_) ->
1625 clist#set_row ~selectable:false n
1628 clist#columns_autosize () ;
1630 (clist#connect#select_row
1631 (fun ~row ~column ~event ->
1632 let (uristr,_) = List.nth results row in
1633 match CicUtil.term_of_uri uristr with
1634 | Cic.Const (uri, _)
1636 | Cic.MutInd (uri, _, _)
1637 | Cic.MutConstruct (uri, _, _, _) ->
1638 show_in_show_window_uri uri
1645 let refine_constraints (must_obj,must_rel,must_sort) =
1646 let chosen = ref false in
1647 let use_only = ref false in
1650 ~modal:true ~title:"Constraints refinement."
1651 ~width:800 ~border_width:2 () in
1652 let vbox = GPack.vbox ~packing:window#add () in
1654 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1657 ~text: "\"Only\" constraints can be enforced or not."
1658 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1660 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1661 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1664 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1665 (* Notebook for the constraints choice *)
1667 GPack.notebook ~scrollable:true
1668 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1669 (* Rel constraints *)
1672 ~text: "Constraints on Rels" () in
1674 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1677 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1680 ~text: "You can now specify the constraints on Rels."
1681 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1682 let expected_height = 25 * (List.length must_rel + 2) in
1683 let height = if expected_height > 400 then 400 else expected_height in
1684 let scrolled_window =
1685 GBin.scrolled_window ~border_width:10 ~height ~width:600
1686 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1687 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1688 let mk_depth_button (hbox:GPack.box) d =
1689 let mutable_ref = ref (Some d) in
1691 GButton.toggle_button
1692 ~label:("depth = " ^ string_of_int d)
1694 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1697 (depthb#connect#toggled
1699 let sel_depth = if depthb#active then Some d else None in
1700 mutable_ref := sel_depth
1703 let rel_constraints =
1708 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1711 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1712 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1714 | `MainHypothesis None
1715 | `MainConclusion None -> p, ref None
1716 | `MainHypothesis (Some depth')
1717 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1719 (* Sort constraints *)
1722 ~text: "Constraints on Sorts" () in
1724 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1727 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1730 ~text: "You can now specify the constraints on Sorts."
1731 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1732 let expected_height = 25 * (List.length must_sort + 2) in
1733 let height = if expected_height > 400 then 400 else expected_height in
1734 let scrolled_window =
1735 GBin.scrolled_window ~border_width:10 ~height ~width:600
1736 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1737 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1738 let sort_constraints =
1740 (function (p, sort) ->
1743 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1746 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1747 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1749 | `MainHypothesis None
1750 | `MainConclusion None -> p, ref None, sort
1751 | `MainHypothesis (Some depth')
1752 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1754 (* Obj constraints *)
1757 ~text: "Constraints on constants" () in
1759 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1762 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1765 ~text: "You can now specify the constraints on constants."
1766 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1767 let expected_height = 25 * (List.length must_obj + 2) in
1768 let height = if expected_height > 400 then 400 else expected_height in
1769 let scrolled_window =
1770 GBin.scrolled_window ~border_width:10 ~height ~width:600
1771 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1772 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1773 let obj_constraints =
1775 (function (p, uri) ->
1778 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1781 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1782 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1787 | `MainHypothesis None
1788 | `MainConclusion None -> p, ref None, uri
1789 | `MainHypothesis (Some depth')
1790 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1792 (* Confirm/abort buttons *)
1794 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1796 GButton.button ~label:"Ok"
1797 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1799 GButton.button ~label:"Abort"
1800 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1802 ignore (window#connect#destroy GMain.Main.quit) ;
1803 ignore (cancelb#connect#clicked window#destroy) ;
1805 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1806 window#set_position `CENTER ;
1810 let chosen_must_rel =
1812 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1815 let chosen_must_sort =
1817 (function (position, ref_depth, sort) ->
1818 MQGU.set_main_position position !ref_depth,sort)
1821 let chosen_must_obj =
1823 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1826 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1828 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1829 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1837 let completeSearchPattern () =
1838 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1840 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1841 let must = CGSearchPattern.get_constraints expr in
1842 let must',only = refine_constraints must in
1844 MQG.query_of_constraints (Some CGSearchPattern.universe) must' only
1846 let results = MQI.execute mqi_handle query in
1847 show_query_results results
1851 (`Error (`T (Printexc.to_string e)))
1854 let insertQuery () =
1856 let chosen = ref None in
1859 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1860 let vbox = GPack.vbox ~packing:window#add () in
1862 GMisc.label ~text:"Insert Query. For Experts Only."
1863 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1864 let scrolled_window =
1865 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1866 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1867 let input = GText.view ~editable:true
1868 ~packing:scrolled_window#add () in
1870 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1872 GButton.button ~label:"Ok"
1873 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1875 GButton.button ~label:"Load from file..."
1876 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1878 GButton.button ~label:"Abort"
1879 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1880 ignore (window#connect#destroy GMain.Main.quit) ;
1881 ignore (cancelb#connect#clicked window#destroy) ;
1883 (okb#connect#clicked
1885 chosen := Some (input#buffer#get_text ()) ; window#destroy ())) ;
1887 (loadb#connect#clicked
1890 GToolbox.select_file ~title:"Select Query File" ()
1894 let inch = open_in filename in
1895 let rec read_file () =
1897 let line = input_line inch in
1898 line ^ "\n" ^ read_file ()
1902 let text = read_file () in
1903 input#buffer#delete input#buffer#start_iter input#buffer#end_iter ;
1904 ignore (input#buffer#insert text))) ;
1905 window#set_position `CENTER ;
1912 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1914 show_query_results results
1918 (`Error (`T (Printexc.to_string e)))
1921 let choose_must list_of_must only =
1922 let chosen = ref None in
1923 let user_constraints = ref [] in
1926 ~modal:true ~title:"Query refinement." ~border_width:2 () in
1927 let vbox = GPack.vbox ~packing:window#add () in
1929 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1933 ("You can now specify the genericity of the query. " ^
1934 "The more generic the slower.")
1935 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1937 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1941 "Suggestion: start with faster queries before moving to more generic ones."
1942 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1944 GPack.notebook ~scrollable:true
1945 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1948 let last = List.length list_of_must in
1954 (if !page = 1 then "More generic" else
1955 if !page = last then "More precise" else " ") () in
1956 let expected_height = 25 * (List.length must + 2) in
1957 let height = if expected_height > 400 then 400 else expected_height in
1958 let scrolled_window =
1959 GBin.scrolled_window ~border_width:10 ~height ~width:600
1960 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1962 GList.clist ~columns:2 ~packing:scrolled_window#add
1963 ~titles:["URI" ; "Position"] ()
1967 (function (position, uri) ->
1970 [uri; MQGUtil.text_of_position position]
1972 clist#set_row ~selectable:false n
1975 clist#columns_autosize ()
1978 let label = GMisc.label ~text:"User provided" () in
1980 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1982 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1985 ~text:"Select the constraints that must be satisfied and press OK."
1986 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1987 let expected_height = 25 * (List.length only + 2) in
1988 let height = if expected_height > 400 then 400 else expected_height in
1989 let scrolled_window =
1990 GBin.scrolled_window ~border_width:10 ~height ~width:600
1991 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1993 GList.clist ~columns:2 ~packing:scrolled_window#add
1994 ~selection_mode:`MULTIPLE
1995 ~titles:["URI" ; "Position"] ()
1999 (function (position, uri) ->
2002 [uri; MQGUtil.text_of_position position]
2004 clist#set_row ~selectable:true n
2007 clist#columns_autosize () ;
2009 (clist#connect#select_row
2010 (fun ~row ~column ~event ->
2011 user_constraints := (List.nth only row)::!user_constraints)) ;
2013 (clist#connect#unselect_row
2014 (fun ~row ~column ~event ->
2017 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2020 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2022 GButton.button ~label:"Ok"
2023 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2025 GButton.button ~label:"Abort"
2026 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2028 ignore (window#connect#destroy GMain.Main.quit) ;
2029 ignore (cancelb#connect#clicked window#destroy) ;
2031 (okb#connect#clicked
2032 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2033 window#set_position `CENTER ;
2037 None -> raise NoChoice
2039 if n = List.length list_of_must then
2040 (* user provided constraints *)
2043 List.nth list_of_must n
2046 let searchPattern () =
2047 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2050 match ProofEngine.get_proof () with
2051 None -> assert false
2052 | Some proof -> proof
2054 match !ProofEngine.goal with
2057 let uris' = List.map fst (MetadataQuery.hint ~dbh (proof, metano)) in
2059 user_uri_choice ~title:"Ambiguous input."
2060 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2063 inputt#set_term uri' ;
2064 InvokeTactics'.apply ()
2068 (`Error (`T (Printexc.to_string e)))
2071 let choose_selection mmlwidget (element : Gdome.element option) =
2072 let module G = Gdome in
2073 let rec aux element =
2074 if element#hasAttributeNS
2075 ~namespaceURI:Misc.helmns
2076 ~localName:(G.domString "xref")
2078 mmlwidget#set_selection (Some element)
2081 match element#get_parentNode with
2082 None -> assert false
2083 (*CSC: OCAML DIVERGES!
2084 | Some p -> aux (new G.element_of_node p)
2086 | Some p -> aux (new Gdome.element_of_node p)
2088 GdomeInit.DOMCastException _ ->
2090 "******* trying to select above the document root ********"
2094 | None -> mmlwidget#set_selection None
2097 (* STUFF TO BUILD THE GTK INTERFACE *)
2099 (* Stuff for the widget settings *)
2102 let export_to_postscript output =
2103 let lastdir = ref (Unix.getcwd ()) in
2106 GToolbox.select_file ~title:"Export to PostScript"
2107 ~dir:lastdir ~filename:"screenshot.ps" ()
2111 (output :> GMathView.math_view)#export_to_postscript
2112 ~filename:filename ();
2117 let activate_t1 output button_set_anti_aliasing
2118 button_set_transparency export_to_postscript_menu_item
2121 let is_set = button_t1#active in
2122 output#set_font_manager_type
2123 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2126 button_set_anti_aliasing#misc#set_sensitive true ;
2127 button_set_transparency#misc#set_sensitive true ;
2128 export_to_postscript_menu_item#misc#set_sensitive true ;
2132 button_set_anti_aliasing#misc#set_sensitive false ;
2133 button_set_transparency#misc#set_sensitive false ;
2134 export_to_postscript_menu_item#misc#set_sensitive false ;
2138 let set_anti_aliasing output button_set_anti_aliasing () =
2139 output#set_anti_aliasing button_set_anti_aliasing#active
2142 let set_transparency output button_set_transparency () =
2143 output#set_transparency button_set_transparency#active
2147 let changefont output font_size_spinb () =
2148 output#set_font_size font_size_spinb#value_as_int
2151 let set_log_verbosity output log_verbosity_spinb () =
2152 output#set_log_verbosity log_verbosity_spinb#value_as_int
2155 class settings_window output sw
2156 export_to_postscript_menu_item selection_changed_callback
2158 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2160 GPack.vbox ~packing:settings_window#add () in
2163 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2164 ~border_width:5 ~packing:vbox#add () in
2166 GButton.toggle_button ~label:"activate t1 fonts"
2167 ~packing:(table#attach ~left:0 ~top:0) () in
2168 let button_set_anti_aliasing =
2169 GButton.toggle_button ~label:"set_anti_aliasing"
2170 ~packing:(table#attach ~left:0 ~top:1) () in
2171 let button_set_transparency =
2172 GButton.toggle_button ~label:"set_transparency"
2173 ~packing:(table#attach ~left:2 ~top:1) () in
2176 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2177 ~border_width:5 ~packing:vbox#add () in
2178 let font_size_label =
2179 GMisc.label ~text:"font size:"
2180 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2181 let font_size_spinb =
2183 GData.adjustment ~value:(float_of_int output#get_font_size)
2184 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2187 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2188 let log_verbosity_label =
2189 GMisc.label ~text:"log verbosity:"
2190 ~packing:(table#attach ~left:0 ~top:1) () in
2191 let log_verbosity_spinb =
2193 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2196 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2198 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2200 GButton.button ~label:"Close"
2201 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2203 method show = settings_window#show
2205 button_set_anti_aliasing#misc#set_sensitive false ;
2206 button_set_transparency#misc#set_sensitive false ;
2207 (* Signals connection *)
2209 ignore(button_t1#connect#clicked
2210 (activate_t1 output button_set_anti_aliasing
2211 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2213 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2215 ignore(button_set_anti_aliasing#connect#toggled
2216 (set_anti_aliasing output button_set_anti_aliasing));
2217 ignore(button_set_transparency#connect#toggled
2218 (set_transparency output button_set_transparency)) ;
2220 ignore(log_verbosity_spinb#connect#changed
2221 (set_log_verbosity output log_verbosity_spinb)) ;
2222 ignore(closeb#connect#clicked settings_window#misc#hide)
2225 (* Scratch window *)
2227 class scratch_window =
2230 ~title:"MathML viewer"
2231 ~border_width:2 () in
2233 GPack.vbox ~packing:window#add () in
2235 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2237 GButton.button ~label:"Whd"
2238 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2240 GButton.button ~label:"Reduce"
2241 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2243 GButton.button ~label:"Simpl"
2244 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2245 let scrolled_window =
2246 GBin.scrolled_window ~border_width:10
2247 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2248 let sequent_viewer =
2249 TermViewer.sequent_viewer
2250 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2251 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2253 val mutable term = Cic.Rel 1 (* dummy value *)
2254 val mutable context = ([] : Cic.context) (* dummy value *)
2255 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2256 method sequent_viewer = sequent_viewer
2257 method show () = window#misc#hide () ; window#show ()
2259 method set_term t = term <- t
2260 method context = context
2261 method set_context t = context <- t
2262 method metasenv = metasenv
2263 method set_metasenv t = metasenv <- t
2266 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2267 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2268 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2269 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2270 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2273 let open_contextual_menu_for_selected_terms mmlwidget infos =
2274 let button = GdkEvent.Button.button infos in
2275 let terms_selected = List.length mmlwidget#get_selections > 0 in
2278 let time = GdkEvent.Button.time infos in
2279 let menu = GMenu.menu () in
2280 let f = new GMenu.factory menu in
2282 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2283 let reduce_menu_item =
2284 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2285 let simpl_menu_item =
2286 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2287 let _ = f#add_separator () in
2288 let generalize_menu_item =
2289 f#add_item "Generalize"
2290 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2291 let _ = f#add_separator () in
2292 let clear_menu_item =
2293 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2294 let clearbody_menu_item =
2295 f#add_item "ClearBody"
2296 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2298 whd_menu_item#misc#set_sensitive terms_selected ;
2299 reduce_menu_item#misc#set_sensitive terms_selected ;
2300 simpl_menu_item#misc#set_sensitive terms_selected ;
2301 generalize_menu_item#misc#set_sensitive terms_selected ;
2302 clear_menu_item#misc#set_sensitive terms_selected ;
2303 clearbody_menu_item#misc#set_sensitive terms_selected ;
2304 menu#popup ~button ~time
2310 let vbox1 = GPack.vbox () in
2312 val mutable proofw_ref = None
2313 val mutable compute_ref = None
2315 Lazy.force self#compute ;
2316 match proofw_ref with
2317 None -> assert false
2318 | Some proofw -> proofw
2319 method content = vbox1
2321 match compute_ref with
2322 None -> assert false
2323 | Some compute -> compute
2327 let scrolled_window1 =
2328 GBin.scrolled_window ~border_width:10
2329 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2331 TermViewer.sequent_viewer
2332 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2333 ~width:400 ~height:275 ~packing:(scrolled_window1#add) () in
2334 let _ = proofw_ref <- Some proofw in
2336 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2338 GButton.button ~label:"Ring"
2339 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2341 GButton.button ~label:"Fourier"
2342 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2344 GButton.button ~label:"Reflexivity"
2345 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2347 GButton.button ~label:"Symmetry"
2348 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2350 GButton.button ~label:"Assumption"
2351 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2352 let contradictionb =
2353 GButton.button ~label:"Contradiction"
2354 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2356 GButton.button ~label:"Auto"
2357 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2359 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2361 GButton.button ~label:"Exists"
2362 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2364 GButton.button ~label:"Split"
2365 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2367 GButton.button ~label:"Left"
2368 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2370 GButton.button ~label:"Right"
2371 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2372 let searchpatternb =
2373 GButton.button ~label:"SearchPattern_Apply"
2374 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2376 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2378 GButton.button ~label:"Exact"
2379 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2381 GButton.button ~label:"Intros"
2382 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2384 GButton.button ~label:"Apply"
2385 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2386 let elimintrossimplb =
2387 GButton.button ~label:"ElimIntrosSimpl"
2388 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2390 GButton.button ~label:"ElimType"
2391 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2393 GButton.button ~label:"Fold_whd"
2394 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2396 GButton.button ~label:"Fold_reduce"
2397 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2399 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2401 GButton.button ~label:"Fold_simpl"
2402 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2404 GButton.button ~label:"Cut"
2405 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2407 GButton.button ~label:"Change"
2408 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2410 GButton.button ~label:"Let ... In"
2411 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2413 GButton.button ~label:"RewriteSimpl ->"
2414 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2415 let rewritebacksimplb =
2416 GButton.button ~label:"RewriteSimpl <-"
2417 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2419 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2421 GButton.button ~label:"Absurd"
2422 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2424 GButton.button ~label:"Decompose"
2425 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2427 GButton.button ~label:"Transitivity"
2428 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2430 GButton.button ~label:"Replace"
2431 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2433 GButton.button ~label:"Injection"
2434 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2436 GButton.button ~label:"Discriminate"
2437 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2438 (* Zack: spostare in una toolbar
2440 GButton.button ~label:"Generalize"
2441 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2443 GButton.button ~label:"ClearBody"
2444 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2446 GButton.button ~label:"Clear"
2447 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2449 GButton.button ~label:"Whd"
2450 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2452 GButton.button ~label:"Reduce"
2453 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2455 GButton.button ~label:"Simpl"
2456 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2459 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2460 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2461 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2462 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2463 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2464 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2465 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2466 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2467 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2468 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2469 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2470 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2471 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2472 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2473 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2474 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2475 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2476 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2477 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2478 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2479 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2480 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2481 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2482 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2483 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2484 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2485 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2486 ignore(searchpatternb#connect#clicked searchPattern) ;
2487 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2488 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2489 ignore(autob#connect#clicked InvokeTactics'.auto) ;
2490 (* Zack: spostare in una toolbar
2491 ignore(whdb#connect#clicked whd) ;
2492 ignore(reduceb#connect#clicked reduce) ;
2493 ignore(simplb#connect#clicked simpl) ;
2494 ignore(clearbodyb#connect#clicked clearbody) ;
2495 ignore(clearb#connect#clicked clear) ;
2496 ignore(generalizeb#connect#clicked generalize) ;
2498 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2500 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2501 (open_contextual_menu_for_selected_terms proofw)) ;
2507 let vbox1 = GPack.vbox () in
2508 let scrolled_window1 =
2509 GBin.scrolled_window ~border_width:10
2510 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2512 TermViewer.sequent_viewer
2513 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2514 ~width:400 ~height:275 ~packing:(scrolled_window1#add) () in
2516 method proofw = (assert false : TermViewer.sequent_viewer)
2517 method content = vbox1
2518 method compute = (assert false : unit)
2522 let empty_page = new empty_page;;
2526 val notebook = GPack.notebook ()
2528 val mutable skip_switch_page_event = false
2529 val mutable empty = true
2530 method notebook = notebook
2532 let new_page = new page () in
2534 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2535 notebook#append_page
2536 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2537 new_page#content#coerce
2538 method remove_all_pages ~skip_switch_page_event:skip =
2540 notebook#remove_page 0 (* let's remove the empty page *)
2542 List.iter (function _ -> notebook#remove_page 0) !pages ;
2544 skip_switch_page_event <- skip
2545 method set_current_page ~may_skip_switch_page_event n =
2546 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2547 let new_page = notebook#page_num page#content#coerce in
2548 if may_skip_switch_page_event && new_page <> notebook#current_page then
2549 skip_switch_page_event <- true ;
2550 notebook#goto_page new_page
2551 method set_empty_page =
2554 notebook#append_page
2555 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2556 empty_page#content#coerce
2558 let (_,_,page) = List.nth !pages notebook#current_page in
2562 (notebook#connect#switch_page
2564 let skip = skip_switch_page_event in
2565 skip_switch_page_event <- false ;
2568 let (metano,setgoal,page) = List.nth !pages i in
2569 set_proof_engine_goal (Some metano) ;
2570 Lazy.force (page#compute) ;
2572 if notify_hbugs_on_goal_change then
2579 let dump_environment () =
2581 let oc = open_out (Helm_registry.get "gtoplevel.environment_file") in
2582 HelmLogger.log (`Msg (`T "Dumping environment ..."));
2583 CicEnvironment.dump_to_channel oc;
2584 HelmLogger.log (`Msg (`T "... done!")) ;
2588 (`Error (`T (Printf.sprintf "Dump failure, uncaught exception:%s"
2589 (Printexc.to_string exc))))
2591 let restore_environment () =
2593 let ic = open_in (Helm_registry.get "gtoplevel.environment_file") in
2594 HelmLogger.log (`Msg (`T "Restoring environment ... "));
2595 CicEnvironment.restore_from_channel ic;
2596 HelmLogger.log (`Msg (`T "... done!"));
2600 (`Error (`T (Printf.sprintf "Restore failure, uncaught exception:%s"
2601 (Printexc.to_string exc))))
2606 class rendering_window output (notebook : notebook) =
2607 let scratch_window = new scratch_window in
2610 ~title:"gTopLevel - Helm's Proof Assistant"
2611 ~border_width:0 ~allow_shrink:false () in
2612 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2614 let handle_box = GBin.handle_box ~border_width:2
2615 ~packing:(vbox_for_menu#pack ~padding:0) () in
2616 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2617 let factory0 = new GMenu.factory menubar in
2618 let accel_group = factory0#accel_group in
2620 let file_menu = factory0#add_submenu "File" in
2621 let factory1 = new GMenu.factory file_menu ~accel_group in
2622 (* let export_to_postscript_menu_item = *)
2626 factory1#add_item "New Block of (Co)Inductive Definitions..."
2627 ~key:GdkKeysyms._B ~callback:new_inductive
2630 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2633 let reopen_menu_item =
2634 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2638 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2639 ignore (factory1#add_separator ()) ;
2641 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2642 ~callback:load_unfinished_proof) ;
2643 let save_menu_item =
2644 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2645 ~callback:save_unfinished_proof
2647 ignore (factory1#add_separator ()) ;
2648 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2649 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2651 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2653 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2654 ignore (!save_set_sensitive false);
2655 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2656 ignore (!qed_set_sensitive false);
2657 ignore (factory1#add_separator ()) ;
2659 let export_to_postscript_menu_item =
2660 factory1#add_item "Export to PostScript..."
2661 ~callback:(export_to_postscript output) in
2663 ignore (factory1#add_separator ()) ;
2665 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2666 export_to_postscript_menu_item *)
2669 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2670 let factory2 = new GMenu.factory edit_menu ~accel_group in
2671 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2672 let proveit_menu_item =
2673 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2674 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2676 let focus_menu_item =
2677 factory2#add_item "Focus" ~key:GdkKeysyms._F
2678 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2681 focus_and_proveit_set_sensitive :=
2683 proveit_menu_item#misc#set_sensitive b ;
2684 focus_menu_item#misc#set_sensitive b
2686 let _ = !focus_and_proveit_set_sensitive false in
2687 (* edit term menu *)
2688 let edit_term_menu = factory0#add_submenu "Edit Term" in
2689 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2690 let check_menu_item =
2691 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2692 ~callback:(check scratch_window) in
2693 let _ = check_menu_item#misc#set_sensitive false in
2695 let search_menu = factory0#add_submenu "Search" in
2696 let factory4 = new GMenu.factory search_menu ~accel_group in
2698 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2700 let searchPattern_menu_item =
2701 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2702 ~callback:completeSearchPattern in
2703 let _ = searchPattern_menu_item#misc#set_sensitive false in
2704 let show_menu_item =
2705 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2707 let insert_query_item =
2708 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2709 ~callback:insertQuery in
2711 let hbugs_menu = factory0#add_submenu "HBugs" in
2712 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2714 factory6#add_check_item
2715 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2718 factory6#add_item ~key:GdkKeysyms._Return ~callback:Hbugs.notify
2719 "(Re)Submit status!"
2721 let _ = factory6#add_separator () in
2723 factory6#add_item ~callback:Hbugs.start_web_services "Start Web Services"
2726 factory6#add_item ~callback:Hbugs.stop_web_services "Stop Web Services"
2729 let settings_menu = factory0#add_submenu "Settings" in
2730 let factory3 = new GMenu.factory settings_menu ~accel_group in
2732 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2733 ~callback:edit_aliases in
2735 factory3#add_item "Clear Aliases" ~key:GdkKeysyms._K
2736 ~callback:clear_aliases in
2738 factory3#add_check_item "Auto disambiguation"
2739 ~callback:(fun checked -> auto_disambiguation := checked) in
2740 let _ = factory3#add_separator () in
2742 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2743 ~callback:(function _ -> (settings_window ())#show ()) in
2744 let _ = factory3#add_separator () in
2746 factory3#add_item "Reload Stylesheets"
2749 ChosenTransformer.reload_stylesheets () ;
2750 if ProofEngine.get_proof () <> None then
2752 refresh_goals notebook ;
2753 refresh_proof output
2755 InvokeTactics.RefreshSequentException e ->
2757 (`Error (`T ("An error occurred while refreshing the " ^
2758 "sequent: " ^ Printexc.to_string e))) ;
2759 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2760 notebook#set_empty_page
2761 | InvokeTactics.RefreshProofException e ->
2763 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2767 let _ = window#add_accel_group accel_group in
2771 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2773 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2774 let scrolled_window0 =
2775 GBin.scrolled_window ~border_width:10
2776 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2777 let _ = scrolled_window0#add output#coerce in
2779 GBin.frame ~label:"Insert Term"
2780 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2781 let scrolled_window1 =
2782 GBin.scrolled_window ~border_width:5
2783 ~packing:frame#add () in
2785 TermEditor'.term_editor
2787 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2788 ~isnotempty_callback:
2790 check_menu_item#misc#set_sensitive b ;
2791 searchPattern_menu_item#misc#set_sensitive b) in
2793 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2795 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2797 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2800 new HelmGtkLogger.html_logger
2801 ~width:400 ~height: 100 ~show:true ~packing:frame#add ()
2804 method inputt = inputt
2805 method output = (output : TermViewer.proof_viewer)
2806 method scratch_window = scratch_window
2807 method notebook = notebook
2808 method show = window#show
2809 method set_auto_disambiguation set = autoitem#set_active set
2811 notebook#set_empty_page ;
2812 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2813 check_term := (check_term_in_scratch scratch_window) ;
2815 (* signal handlers here *)
2816 ignore(output#connect#selection_changed
2818 choose_selection output elem ;
2819 !focus_and_proveit_set_sensitive true
2821 ignore (output#connect#click (show_in_show_window_callback output)) ;
2822 let settings_window = new settings_window output scrolled_window0
2823 (*export_to_postscript_menu_item*)() (choose_selection output) in
2824 set_settings_window settings_window ;
2825 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true ))
2830 let initialize_everything () =
2831 prerr_endline "STO PER CREARE LA PROOF WINDOW" ;
2833 TermViewer.proof_viewer
2834 ~mml_of_cic_object:ChosenTransformer.mml_of_cic_object
2835 ~width:350 ~height:280 ()
2837 prerr_endline "CREATA" ;
2838 let notebook = new notebook in
2839 let rendering_window' = new rendering_window output notebook in
2840 prerr_endline "OK" ;
2841 rendering_window'#set_auto_disambiguation !auto_disambiguation;
2842 set_rendering_window rendering_window';
2843 let print_error_as_html prefix msg =
2844 HelmLogger.log (`Error (`T (prefix ^ msg)))
2846 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2847 Gdome_xslt.setDebugCallback
2848 (Some (print_error_as_html "XSLT Debug Message: "));
2849 rendering_window'#show () ;
2850 if restore_environment_on_boot &&
2851 Sys.file_exists (Helm_registry.get "gtoplevel.environment_file")
2853 restore_environment ();
2858 prerr_endline "CIAO" ;
2859 ignore (GtkMain.Main.init ()) ;
2860 initialize_everything () ;
2861 MQIC.close mqi_handle;
2866 Sys.catch_break true;
2868 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)