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
52 (* first of all let's initialize the Helm_registry *)
54 let configuration_file = "gTopLevel.conf.xml" in
55 if not (Sys.file_exists configuration_file) then begin
56 eprintf "E: Can't find configuration file '%s'\n" configuration_file;
59 Helm_registry.load_from configuration_file
62 (* GLOBAL CONSTANTS *)
64 let mqi_debug_fun s = debug_print ~level:2 s
65 let mqi_handle = MQIC.init ~log:mqi_debug_fun ()
67 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
69 let restore_environment_on_boot = true ;;
70 let notify_hbugs_on_goal_change = false ;;
72 let auto_disambiguation = ref true ;;
74 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
76 let check_term = ref (fun _ _ _ -> assert false);;
78 exception RenderingWindowsNotInitialized;;
80 let set_rendering_window,rendering_window =
81 let rendering_window_ref = ref None in
82 (function rw -> rendering_window_ref := Some rw),
84 match !rendering_window_ref with
85 None -> raise RenderingWindowsNotInitialized
90 exception SettingsWindowsNotInitialized;;
92 let set_settings_window,settings_window =
93 let settings_window_ref = ref None in
94 (function rw -> settings_window_ref := Some rw),
96 match !settings_window_ref with
97 None -> raise SettingsWindowsNotInitialized
102 exception QedSetSensitiveNotInitialized;;
103 let qed_set_sensitive =
104 ref (function _ -> raise QedSetSensitiveNotInitialized)
107 exception SaveSetSensitiveNotInitialized;;
108 let save_set_sensitive =
109 ref (function _ -> raise SaveSetSensitiveNotInitialized)
112 (* COMMAND LINE OPTIONS *)
118 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
121 Arg.parse argspec ignore ""
125 let term_of_cic_textual_parser_uri uri =
126 let module C = Cic in
127 let module CTP = CicTextualParser0 in
129 CTP.ConUri uri -> C.Const (uri,[])
130 | CTP.VarUri uri -> C.Var (uri,[])
131 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
132 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
135 let string_of_cic_textual_parser_uri uri =
136 let module C = Cic in
137 let module CTP = CicTextualParser0 in
140 CTP.ConUri uri -> UriManager.string_of_uri uri
141 | CTP.VarUri uri -> UriManager.string_of_uri uri
142 | CTP.IndTyUri (uri,tyno) ->
143 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
144 | CTP.IndConUri (uri,tyno,consno) ->
145 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
148 (* 4 = String.length "cic:" *)
149 String.sub uri' 4 (String.length uri' - 4)
152 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
156 let check_window uris =
159 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
161 GPack.notebook ~scrollable:true ~packing:window#add () in
166 let scrolled_window =
167 GBin.scrolled_window ~border_width:10
169 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
174 TermViewer.sequent_viewer
175 ~packing:scrolled_window#add ~width:400 ~height:280 () in
178 term_of_cic_textual_parser_uri
179 (MQueryMisc.cic_textual_parser_uri_of_string uri)
181 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
184 mmlwidget#load_sequent [] (111,[],expr)
187 HelmLogger.log (`Error (`T (Printexc.to_string e)))
192 (notebook#connect#switch_page
194 Lazy.force (List.nth render_terms i)))
200 interactive_user_uri_choice ~(selection_mode:[`MULTIPLE|`SINGLE]) ?(ok="Ok")
201 ?(enable_button_for_non_vars=false) ~title ~msg uris
203 let only_constant_choices =
206 (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
209 if selection_mode <> `SINGLE && !auto_disambiguation then
210 Lazy.force only_constant_choices
212 let choices = ref [] in
213 let chosen = ref false in
214 let use_only_constants = ref false in
216 GWindow.dialog ~modal:true ~title ~width:600 () in
218 GMisc.label ~text:msg
219 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
220 let scrolled_window =
221 GBin.scrolled_window ~border_width:10
222 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
224 let expected_height = 18 * List.length uris in
225 let height = if expected_height > 400 then 400 else expected_height in
226 GList.clist ~columns:1 ~packing:scrolled_window#add
227 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
228 let _ = List.map (function x -> clist#append [x]) uris in
230 GPack.hbox ~border_width:0
231 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
233 GMisc.label ~text:"None of the above. Try this one:"
234 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
236 GEdit.entry ~editable:true
237 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
239 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
241 GButton.button ~label:ok
242 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
243 let _ = okb#misc#set_sensitive false in
248 if enable_button_for_non_vars then
249 hbox#pack ~expand:false ~fill:false ~padding:5 w)
250 ~label:"Try constants only" () in
255 if enable_button_for_non_vars then
256 hbox#pack ~expand:false ~fill:false ~padding:5 w)
259 GButton.button ~label:"Check"
260 ~packing:(hbox#pack ~padding:5) () in
261 let _ = checkb#misc#set_sensitive false in
263 GButton.button ~label:"Abort"
264 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
266 let check_callback () =
267 assert (List.length !choices > 0) ;
268 check_window !choices
270 ignore (window#connect#destroy GMain.Main.quit) ;
271 ignore (cancelb#connect#clicked window#destroy) ;
273 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
275 (nonvarsb#connect#clicked
277 use_only_constants := true ;
281 ignore (autob#connect#clicked (fun () ->
282 auto_disambiguation := true;
283 (rendering_window ())#set_auto_disambiguation true;
284 use_only_constants := true ;
287 ignore (checkb#connect#clicked check_callback) ;
289 (clist#connect#select_row
290 (fun ~row ~column ~event ->
291 checkb#misc#set_sensitive true ;
292 okb#misc#set_sensitive true ;
293 choices := (List.nth uris row)::!choices)) ;
295 (clist#connect#unselect_row
296 (fun ~row ~column ~event ->
298 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
300 (manual_input#connect#changed
302 if manual_input#text = "" then
305 checkb#misc#set_sensitive false ;
306 okb#misc#set_sensitive false ;
307 clist#misc#set_sensitive true
311 choices := [manual_input#text] ;
312 clist#unselect_all () ;
313 checkb#misc#set_sensitive true ;
314 okb#misc#set_sensitive true ;
315 clist#misc#set_sensitive false
317 window#set_position `CENTER ;
321 if !use_only_constants then
322 Lazy.force only_constant_choices
324 if List.length !choices > 0 then !choices else raise NoChoice
330 let interactive_interpretation_choice interpretations =
331 let chosen = ref None in
334 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
335 let vbox = GPack.vbox ~packing:window#add () in
339 ("Ambiguous input since there are many well-typed interpretations." ^
340 " Please, choose one of them.")
341 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
343 GPack.notebook ~scrollable:true
344 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
347 (function interpretation ->
349 let expected_height = 18 * List.length interpretation in
350 let height = if expected_height > 400 then 400 else expected_height in
351 GList.clist ~columns:2 ~packing:notebook#append_page ~height
352 ~titles:["id" ; "URI"] ()
356 (function (id,uri) ->
357 let n = clist#append [id;uri] in
358 clist#set_row ~selectable:false n
361 clist#columns_autosize ()
364 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
366 GButton.button ~label:"Ok"
367 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
369 GButton.button ~label:"Abort"
370 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
372 ignore (window#connect#destroy GMain.Main.quit) ;
373 ignore (cancelb#connect#clicked window#destroy) ;
376 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
377 window#set_position `CENTER ;
381 None -> raise NoChoice
389 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
392 let struri = UriManager.string_of_uri uri in
393 let idx = (String.rindex struri '/') + 1 in
394 String.sub struri idx (String.length struri - idx)
396 let path = pathname ^ "/" ^ name in
398 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
402 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
403 ~ask_dtd_to_the_getter:false
406 let innertypesuri = UriManager.innertypesuri_of_uri uri in
407 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
408 Http_getter.register' innertypesuri
409 (Helm_registry.get "local_library.url" ^
410 Str.replace_first (Str.regexp "^cic:") ""
411 (UriManager.string_of_uri innertypesuri) ^ ".xml"
413 (* constant type / variable / mutual inductive types definition *)
414 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
415 Http_getter.register' uri
416 (Helm_registry.get "local_library.url" ^
417 Str.replace_first (Str.regexp "^cic:") ""
418 (UriManager.string_of_uri uri) ^ ".xml"
425 match UriManager.bodyuri_of_uri uri with
427 | Some bodyuri -> bodyuri
429 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
430 Http_getter.register' bodyuri
431 (Helm_registry.get "local_library.url" ^
432 Str.replace_first (Str.regexp "^cic:") ""
433 (UriManager.string_of_uri bodyuri) ^ ".xml"
440 exception OpenConjecturesStillThere;;
441 exception WrongProof;;
443 let pathname_of_annuri uristring =
444 Helm_registry.get "local_library.dir" ^
445 Str.replace_first (Str.regexp "^cic:") "" uristring
448 let make_dirs dirpath =
449 ignore (Unix.system ("mkdir -p " ^ dirpath))
452 let save_obj uri obj =
454 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
455 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
457 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
459 (* let's save the theorem and register it to the getter *)
460 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
462 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
467 match ProofEngine.get_proof () with
469 | Some (uri,[],bo,ty) ->
471 CicReduction.are_convertible []
472 (CicTypeChecker.type_of_aux' [] [] bo) ty
475 (*CSC: Wrong: [] is just plainly wrong *)
476 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
477 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
478 (rendering_window ())#output#load_proof uri proof
480 !qed_set_sensitive false ;
481 (* let's save the theorem and register it to the getter *)
482 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
484 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
489 | _ -> raise OpenConjecturesStillThere
492 (** save an unfinished proof on the filesystem *)
493 let save_unfinished_proof () =
494 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
495 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
496 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
497 Xml.pp ~quiet:true xml (Some proof_file_type) ;
499 (`Msg (`T ("Current proof type saved to " ^ proof_file_type))) ;
500 Xml.pp ~quiet:true bodyxml (Some proof_file) ;
502 (`Msg (`T ("Current proof body saved to " ^ proof_file)))
505 (* Used to typecheck the loaded proofs *)
506 let typecheck_loaded_proof metasenv bo ty =
507 let module T = CicTypeChecker in
510 (fun metasenv ((_,context,ty) as conj) ->
511 ignore (T.type_of_aux' metasenv context ty) ;
514 ignore (T.type_of_aux' metasenv [] ty) ;
515 ignore (T.type_of_aux' metasenv [] bo)
518 let decompose_uris_choice_callback uris =
519 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
520 let module U = UriManager in
523 match MQueryMisc.cic_textual_parser_uri_of_string uri with
524 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
526 (interactive_user_uri_choice
527 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
528 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
530 (function (uri,typeno,_) ->
531 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
536 let mk_fresh_name_callback metasenv context name ~typ =
538 match FreshNamesGenerator.mk_fresh_name metasenv context name ~typ with
539 Cic.Name fresh_name -> fresh_name
540 | Cic.Anonymous -> assert false
543 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
544 ("Enter a fresh name for the hypothesis " ^
546 (List.map (function None -> None | Some (n,_) -> Some n) context))
548 Some fresh_name' -> Cic.Name fresh_name'
549 | None -> raise NoChoice
552 let refresh_proof (output : TermViewer.proof_viewer) =
554 let uri,currentproof =
555 match ProofEngine.get_proof () with
557 | Some (uri,metasenv,bo,ty) ->
558 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
559 if List.length metasenv = 0 then
561 !qed_set_sensitive true ;
566 (*CSC: Wrong: [] is just plainly wrong *)
568 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
570 ignore (output#load_proof uri currentproof)
573 match ProofEngine.get_proof () with
575 | Some (uri,metasenv,bo,ty) ->
576 debug_print ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[])));
577 raise (InvokeTactics.RefreshProofException e)
579 let set_proof_engine_goal g =
580 ProofEngine.goal := g
583 let refresh_goals ?(empty_notebook=true) notebook =
585 match !ProofEngine.goal with
587 if empty_notebook then
589 notebook#remove_all_pages ~skip_switch_page_event:false ;
590 notebook#set_empty_page
593 notebook#proofw#unload
596 match ProofEngine.get_proof () with
598 | Some (_,metasenv,_,_) -> metasenv
601 List.find (function (m,_,_) -> m=metano) metasenv
603 let regenerate_notebook () =
604 let skip_switch_page_event =
606 (m,_,_)::_ when m = metano -> false
609 notebook#remove_all_pages ~skip_switch_page_event ;
610 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
612 if empty_notebook then
614 regenerate_notebook () ;
615 notebook#set_current_page
616 ~may_skip_switch_page_event:false metano
620 notebook#set_current_page
621 ~may_skip_switch_page_event:true metano ;
622 notebook#proofw#load_sequent metasenv currentsequent
627 match !ProofEngine.goal with
632 match ProofEngine.get_proof () with
634 | Some (_,metasenv,_,_) -> metasenv
637 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
639 ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent);
640 raise (InvokeTactics.RefreshSequentException e)
642 debug_print ("Offending sequent " ^ string_of_int metano ^ " unknown.");
643 raise (InvokeTactics.RefreshSequentException e)
645 module InvokeTacticsCallbacks =
647 let sequent_viewer () = (rendering_window ())#notebook#proofw
648 let term_editor () = (rendering_window ())#inputt
649 let scratch_window () = (rendering_window ())#scratch_window
651 let refresh_proof () =
652 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
655 let refresh_goals () =
656 let notebook = (rendering_window ())#notebook in
657 refresh_goals notebook
659 let decompose_uris_choice_callback = decompose_uris_choice_callback
660 let mk_fresh_name_callback = mk_fresh_name_callback
663 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
665 (* Just to initialize the Hbugs module *)
666 module Ignore = Hbugs.Initialize (InvokeTactics');;
667 Hbugs.set_describe_hint_callback (fun hint ->
669 | Hbugs_types.Use_apply_Luke term -> check_window [term]
673 let dummy_uri = "/dummy.con"
675 (** load an unfinished proof from filesystem *)
676 let load_unfinished_proof () =
677 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
678 let notebook = (rendering_window ())#notebook in
681 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
684 None -> raise NoChoice
686 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
687 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
688 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
689 match CicParser.obj_of_xml proof_file_type (Some proof_file) with
690 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
691 typecheck_loaded_proof metasenv bo ty ;
692 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
693 refresh_proof output ;
694 set_proof_engine_goal
697 | (metano,_,_)::_ -> Some metano
699 refresh_goals notebook ;
701 (`Msg (`T ("Current proof type loaded from " ^ proof_file_type)));
703 (`Msg (`T ("Current proof body loaded from " ^ proof_file))) ;
704 !save_set_sensitive true;
707 InvokeTactics.RefreshSequentException e ->
709 (`Error (`T ("Exception raised during the refresh of the " ^
710 "sequent: " ^ Printexc.to_string e)))
711 | InvokeTactics.RefreshProofException e ->
713 (`Error (`T ("Exception raised during the refresh of the " ^
714 "proof: " ^ Printexc.to_string e)))
717 (`Error (`T (Printexc.to_string e)))
720 let clear_aliases () =
721 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
722 inputt#environment :=
723 DisambiguatingParser.EnvironmentP3.of_string
724 DisambiguatingParser.EnvironmentP3.empty
727 let edit_aliases () =
728 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
729 let disambiguation_env = inputt#environment in
730 let chosen_aliases = ref None in
733 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
735 GPack.vbox ~border_width:0 ~packing:window#add () in
736 let scrolled_window =
737 GBin.scrolled_window ~border_width:10
738 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
739 let input = GText.view ~editable:true ~width:400 ~height:100
740 ~packing:scrolled_window#add () in
742 GPack.hbox ~border_width:0
743 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
745 GButton.button ~label:"Ok"
746 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
748 GButton.button ~label:"Clear"
749 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
751 GButton.button ~label:"Cancel"
752 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
753 ignore (window#connect#destroy GMain.Main.quit) ;
754 ignore (cancelb#connect#clicked window#destroy) ;
755 ignore (clearb#connect#clicked (fun () ->
756 input#buffer#set_text DisambiguatingParser.EnvironmentP3.empty)) ;
757 ignore (okb#connect#clicked (fun () ->
758 chosen_aliases := Some (input#buffer#get_text ());
761 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
762 (DisambiguatingParser.EnvironmentP3.to_string !disambiguation_env ^ "\n"));
765 match !chosen_aliases with
767 | Some raw_aliases ->
768 let new_disambiguation_env =
770 DisambiguatingParser.EnvironmentP3.of_string raw_aliases
774 ("Error while parsing aliases: " ^ Printexc.to_string e)));
777 disambiguation_env := new_disambiguation_env
781 let module L = LogicalOperations in
782 let module G = Gdome in
783 let notebook = (rendering_window ())#notebook in
784 let output = (rendering_window ())#output in
786 output#make_sequent_of_selected_term ;
787 refresh_proof output ;
788 refresh_goals notebook
790 InvokeTactics.RefreshSequentException e ->
792 (`Error (`T ("Exception raised during the refresh of the " ^
793 "sequent: " ^ Printexc.to_string e)))
794 | InvokeTactics.RefreshProofException e ->
796 (`Error (`T ("Exception raised during the refresh of the " ^
797 "proof: " ^ Printexc.to_string e)))
800 (`Error (`T (Printexc.to_string e)))
804 let module L = LogicalOperations in
805 let module G = Gdome in
806 let notebook = (rendering_window ())#notebook in
807 let output = (rendering_window ())#output in
809 output#focus_sequent_of_selected_term ;
810 refresh_goals notebook
812 InvokeTactics.RefreshSequentException e ->
814 (`Error (`T ("Exception raised during the refresh of the " ^
815 "sequent: " ^ Printexc.to_string e)))
816 | InvokeTactics.RefreshProofException e ->
818 (`Error (`T ("Exception raised during the refresh of the " ^
819 "proof: " ^ Printexc.to_string e)))
822 (`Error (`T (Printexc.to_string e)))
825 exception NoPrevGoal;;
826 exception NoNextGoal;;
829 let module L = LogicalOperations in
830 let module G = Gdome in
831 let notebook = (rendering_window ())#notebook in
832 let output = (rendering_window ())#output in
834 match ProofEngine.get_proof () with
836 | Some (_,metasenv,_,_) -> metasenv
839 refresh_goals ~empty_notebook:false notebook
841 InvokeTactics.RefreshSequentException e ->
843 (`Error (`T ("Exception raised during the refresh of the " ^
844 "sequent: " ^ Printexc.to_string e)))
847 (`Error (`T (Printexc.to_string e)))
851 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
854 GWindow.window ~width:800 ~border_width:2 () in
855 let scrolled_window =
856 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
858 GMathViewAux.single_selection_math_view
859 ~packing:scrolled_window#add ~width:600 ~height:400 ()
861 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
862 let href = Gdome.domString "href" in
863 let show_in_show_window_obj uri obj =
866 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
867 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
869 Cic2acic.acic_object_of_cic_object obj
872 ChosenTransformer.mml_of_cic_object
873 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
875 window#set_title (UriManager.string_of_uri uri) ;
876 window#misc#hide () ; window#show () ;
877 mmlwidget#load_doc mml ;
881 (`Error (`T (Printexc.to_string e)))
883 let show_in_show_window_uri uri =
884 let obj = CicEnvironment.get_obj uri in
885 show_in_show_window_obj uri obj
887 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
891 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
893 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
895 show_in_show_window_uri (UriManager.uri_of_string uri)
897 ignore (mmlwidget#action_toggle n')
900 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
902 show_in_show_window_obj, show_in_show_window_uri,
903 show_in_show_window_callback
906 exception NoObjectsLocated;;
908 let user_uri_choice ~title ~msg uris =
911 [] -> raise NoObjectsLocated
915 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
920 String.sub uri 4 (String.length uri - 4)
923 let locate_callback id =
924 let query = MQG.locate id in
925 let result = MQI.execute mqi_handle query in
929 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
931 HelmLogger.log (`Msg (`T "Locate Query:")) ;
932 MQueryUtil.text_of_query (fun m -> HelmLogger.log (`Msg (`T m))) "" query;
933 HelmLogger.log (`Msg (`T "Result:")) ;
934 MQueryUtil.text_of_result (fun m -> HelmLogger.log (`Msg (`T m))) "" result;
935 user_uri_choice ~title:"Ambiguous input."
937 ("Ambiguous input \"" ^ id ^
938 "\". Please, choose one interpetation:")
943 let input_or_locate_uri ~title =
944 let uri = ref None in
947 ~width:400 ~modal:true ~title ~border_width:2 () in
948 let vbox = GPack.vbox ~packing:window#add () in
950 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
952 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
954 GEdit.entry ~editable:true
955 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
957 GButton.button ~label:"Check"
958 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
959 let _ = checkb#misc#set_sensitive false in
961 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
963 GMisc.label ~text:"You can also enter an indentifier to locate:"
964 ~packing:(hbox2#pack ~padding:5) () in
966 GEdit.entry ~editable:true
967 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
969 GButton.button ~label:"Locate"
970 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
971 let _ = locateb#misc#set_sensitive false in
973 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
975 GButton.button ~label:"Ok"
976 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
977 let _ = okb#misc#set_sensitive false in
979 GButton.button ~label:"Cancel"
980 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
982 ignore (window#connect#destroy GMain.Main.quit) ;
984 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
985 let check_callback () =
986 let uri = "cic:" ^ manual_input#text in
988 ignore (Http_getter.resolve' (UriManager.uri_of_string uri)) ;
989 HelmLogger.log (`Msg (`T "OK")) ;
992 Http_getter_types.Unresolvable_URI _ ->
994 (`Error (`T ("URI " ^ uri ^
995 " does not correspond to any object."))) ;
997 | UriManager.IllFormedUri _ ->
999 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
1003 (`Error (`T (Printexc.to_string e))) ;
1007 (okb#connect#clicked
1009 if check_callback () then
1011 uri := Some manual_input#text ;
1015 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1017 (manual_input#connect#changed
1019 if manual_input#text = "" then
1021 checkb#misc#set_sensitive false ;
1022 okb#misc#set_sensitive false
1026 checkb#misc#set_sensitive true ;
1027 okb#misc#set_sensitive true
1030 (locate_input#connect#changed
1031 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1033 (locateb#connect#clicked
1035 let id = locate_input#text in
1036 manual_input#set_text (locate_callback id) ;
1037 locate_input#delete_text 0 (String.length id)
1042 None -> raise NoChoice
1043 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1046 exception AmbiguousInput;;
1048 (* A WIDGET TO ENTER CIC TERMS *)
1050 module DisambiguateCallbacks =
1052 let interactive_user_uri_choice =
1053 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1054 interactive_user_uri_choice ~selection_mode ?ok
1055 ?enable_button_for_non_vars ~title ~msg
1056 let interactive_interpretation_choice = interactive_interpretation_choice
1057 let input_or_locate_uri = input_or_locate_uri
1061 module TermEditor' = ChosenTermEditor.Make (DisambiguateCallbacks);;
1063 (* OTHER FUNCTIONS *)
1066 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1069 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1071 None -> raise NoChoice
1073 let uri = locate_callback input in
1078 (`Error (`T (Printexc.to_string e)))
1082 exception UriAlreadyInUse;;
1083 exception NotAUriToAConstant;;
1085 let new_inductive () =
1086 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1087 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1088 let notebook = (rendering_window ())#notebook in
1090 let chosen = ref false in
1091 let inductive = ref true in
1092 let paramsno = ref 0 in
1093 let get_uri = ref (function _ -> assert false) in
1094 let get_base_uri = ref (function _ -> assert false) in
1095 let get_names = ref (function _ -> assert false) in
1096 let get_types_and_cons = ref (function _ -> assert false) in
1097 let get_context_and_subst = ref (function _ -> assert false) in
1100 ~width:600 ~modal:true ~position:`CENTER
1101 ~title:"New Block of Mutual (Co)Inductive Definitions"
1102 ~border_width:2 () in
1103 let vbox = GPack.vbox ~packing:window#add () in
1105 GPack.hbox ~border_width:0
1106 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1108 GMisc.label ~text:"Enter the URI for the new block:"
1109 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1111 GEdit.entry ~editable:true
1112 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1114 GPack.hbox ~border_width:0
1115 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1119 "Enter the number of left parameters in every arity and constructor type:"
1120 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1121 let paramsno_entry =
1122 GEdit.entry ~editable:true ~text:"0"
1123 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1125 GPack.hbox ~border_width:0
1126 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1128 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1129 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1131 GButton.radio_button ~label:"Inductive"
1132 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1134 GButton.radio_button ~label:"Coinductive"
1135 ~group:inductiveb#group
1136 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1138 GPack.hbox ~border_width:0
1139 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1141 GMisc.label ~text:"Enter the list of the names of the types:"
1142 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1144 GEdit.entry ~editable:true
1145 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1147 GPack.hbox ~border_width:0
1148 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1150 GButton.button ~label:"> Next"
1151 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1152 let _ = okb#misc#set_sensitive true in
1154 GButton.button ~label:"Abort"
1155 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1156 ignore (window#connect#destroy GMain.Main.quit) ;
1157 ignore (cancelb#connect#clicked window#destroy) ;
1161 (okb#connect#clicked
1164 let uristr = "cic:" ^ uri_entry#text in
1165 let namesstr = names_entry#text in
1166 let paramsno' = int_of_string (paramsno_entry#text) in
1167 match Str.split (Str.regexp " +") namesstr with
1169 | (he::tl) as names ->
1170 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1173 ignore (Http_getter.resolve' uri) ;
1174 raise UriAlreadyInUse
1175 with Http_getter_types.Unresolvable_URI _ ->
1176 get_uri := (function () -> uri) ;
1177 get_names := (function () -> names) ;
1178 inductive := inductiveb#active ;
1179 paramsno := paramsno' ;
1185 (`Error (`T (Printexc.to_string e)))
1193 GBin.frame ~label:name
1194 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1195 let vbox = GPack.vbox ~packing:frame#add () in
1196 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1198 GMisc.label ~text:("Enter its type:")
1199 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1200 let scrolled_window =
1201 GBin.scrolled_window ~border_width:5
1202 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1204 TermEditor'.term_editor
1206 ~width:400 ~height:20 ~packing:scrolled_window#add
1207 ~share_environment_with:inputt ()
1208 ~isnotempty_callback:
1210 (*non_empty_type := b ;*)
1211 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1214 GPack.hbox ~border_width:0
1215 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1217 GMisc.label ~text:("Enter the list of its constructors:")
1218 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1219 let cons_names_entry =
1220 GEdit.entry ~editable:true
1221 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1222 (newinputt,cons_names_entry)
1225 vbox#remove hboxn#coerce ;
1227 GPack.hbox ~border_width:0
1228 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1230 GButton.button ~label:"> Next"
1231 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1233 GButton.button ~label:"Abort"
1234 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1235 ignore (cancelb#connect#clicked window#destroy) ;
1237 (okb#connect#clicked
1240 let names = !get_names () in
1241 let types_and_cons =
1243 (fun name (newinputt,cons_names_entry) ->
1244 let consnamesstr = cons_names_entry#text in
1245 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1247 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1250 [] -> expr,cons_names
1251 | _ -> raise AmbiguousInput
1252 ) names type_widgets
1254 let uri = !get_uri () in
1256 (* Let's see if so far the definition is well-typed *)
1259 (* To test if the arities of the inductive types are well *)
1260 (* typed, we check the inductive block definition where *)
1261 (* no constructor is given to each type. *)
1264 (fun name (ty,cons) -> (name, !inductive, ty, []))
1265 names types_and_cons
1267 CicTypeChecker.typecheck_mutual_inductive_defs uri
1268 (tys,params,paramsno)
1270 get_context_and_subst :=
1274 (fun (context,subst) name (ty,_) ->
1276 (Some (Cic.Name name, Cic.Decl ty))::context,
1277 (Cic.MutInd (uri,!i,[]))::subst
1280 ) ([],[]) names types_and_cons) ;
1281 let types_and_cons' =
1283 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1284 names types_and_cons
1286 get_types_and_cons := (function () -> types_and_cons') ;
1292 (`Error (`T (Printexc.to_string e)))
1295 and phase3 name cons =
1296 let get_cons_types = ref (function () -> assert false) in
1299 ~width:600 ~modal:true ~position:`CENTER
1300 ~title:(name ^ " Constructors")
1301 ~border_width:2 () in
1302 let vbox = GPack.vbox ~packing:window2#add () in
1303 let cons_type_widgets =
1305 (function consname ->
1307 GPack.hbox ~border_width:0
1308 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1310 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1311 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1312 let scrolled_window =
1313 GBin.scrolled_window ~border_width:5
1314 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1316 TermEditor'.term_editor
1318 ~width:400 ~height:20 ~packing:scrolled_window#add
1319 ~share_environment_with:inputt ()
1320 ~isnotempty_callback:
1322 (* (*non_empty_type := b ;*)
1323 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1328 GPack.hbox ~border_width:0
1329 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1331 GButton.button ~label:"> Next"
1332 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1333 let _ = okb#misc#set_sensitive true in
1335 GButton.button ~label:"Abort"
1336 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1337 ignore (window2#connect#destroy GMain.Main.quit) ;
1338 ignore (cancelb#connect#clicked window2#destroy) ;
1340 (okb#connect#clicked
1344 let context,subst= !get_context_and_subst () in
1349 inputt#get_metasenv_and_term ~context ~metasenv:[]
1353 let undebrujined_expr =
1355 (fun expr t -> CicSubstitution.subst t expr) expr subst
1357 name, undebrujined_expr
1358 | _ -> raise AmbiguousInput
1359 ) cons cons_type_widgets
1361 get_cons_types := (function () -> cons_types) ;
1366 (`Error (`T (Printexc.to_string e)))
1370 let okb_pressed = !chosen in
1372 if (not okb_pressed) then
1375 assert false (* The control never reaches this point *)
1378 (!get_cons_types ())
1381 (* No more phases left or Abort pressed *)
1387 let uri = !get_uri () in
1390 let tys = !get_types_and_cons () in
1391 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1394 debug_print (CicPp.ppobj obj);
1395 CicTypeChecker.typecheck_mutual_inductive_defs uri
1396 (tys,params,!paramsno) ;
1399 debug_print "Offending mutual (co)inductive type declaration:" ;
1400 debug_print (CicPp.ppobj obj) ;
1402 (* We already know that obj is well-typed. We need to add it to the *)
1403 (* environment in order to compute the inner-types without having to *)
1404 (* debrujin it or having to modify lots of other functions to avoid *)
1405 (* asking the environment for the MUTINDs we are defining now. *)
1406 CicEnvironment.put_inductive_definition uri obj ;
1408 show_in_show_window_obj uri obj
1412 (`Error (`T (Printexc.to_string e)))
1416 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1417 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1418 let notebook = (rendering_window ())#notebook in
1420 let chosen = ref false in
1421 let get_metasenv_and_term = ref (function _ -> assert false) in
1422 let get_uri = ref (function _ -> assert false) in
1423 let non_empty_type = ref false in
1426 ~width:600 ~modal:true ~title:"New Proof or Definition"
1427 ~border_width:2 () in
1428 let vbox = GPack.vbox ~packing:window#add () in
1430 GPack.hbox ~border_width:0
1431 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1433 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1434 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1436 GEdit.entry ~editable:true
1437 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1438 uri_entry#set_text dummy_uri;
1439 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1441 GPack.hbox ~border_width:0
1442 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1444 GMisc.label ~text:"Enter the theorem or definition type:"
1445 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1446 let scrolled_window =
1447 GBin.scrolled_window ~border_width:5
1448 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1449 (* the content of the scrolled_window is moved below (see comment) *)
1451 GPack.hbox ~border_width:0
1452 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1454 GButton.button ~label:"Ok"
1455 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1456 let _ = okb#misc#set_sensitive false in
1458 GButton.button ~label:"Cancel"
1459 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1460 (* moved here to have visibility of the ok button *)
1462 TermEditor'.term_editor
1464 ~width:400 ~height:100 ~packing:scrolled_window#add
1465 ~share_environment_with:inputt ()
1466 ~isnotempty_callback:
1468 non_empty_type := b ;
1469 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1472 newinputt#set_term inputt#get_as_string ;
1475 uri_entry#connect#changed
1477 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1479 ignore (window#connect#destroy GMain.Main.quit) ;
1480 ignore (cancelb#connect#clicked window#destroy) ;
1482 (okb#connect#clicked
1486 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1487 let uristr = "cic:" ^ uri_entry#text in
1488 let uri = UriManager.uri_of_string uristr in
1489 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1490 raise NotAUriToAConstant
1494 ignore (Http_getter.resolve' uri) ;
1495 raise UriAlreadyInUse
1496 with Http_getter_types.Unresolvable_URI _ ->
1497 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1498 get_uri := (function () -> uri) ;
1504 (`Error (`T (Printexc.to_string e)))
1510 let metasenv,expr = !get_metasenv_and_term () in
1511 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1512 ProofEngine.set_proof
1513 (Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr)) ;
1514 set_proof_engine_goal (Some 1) ;
1515 refresh_goals notebook ;
1516 refresh_proof output ;
1517 !save_set_sensitive true ;
1519 ProofEngine.intros ~mk_fresh_name_callback () ;
1520 refresh_goals notebook ;
1521 refresh_proof output
1523 InvokeTactics.RefreshSequentException e ->
1525 (`Error (`T ("Exception raised during the refresh of the " ^
1526 "sequent: " ^ Printexc.to_string e)))
1527 | InvokeTactics.RefreshProofException e ->
1529 (`Error (`T ("Exception raised during the refresh of the " ^
1530 "proof: " ^ Printexc.to_string e)))
1533 (`Error (`T (Printexc.to_string e)))
1536 let check_term_in_scratch scratch_window metasenv context expr =
1538 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1539 let expr = Cic.Cast (expr,ty) in
1540 scratch_window#show () ;
1541 scratch_window#set_term expr ;
1542 scratch_window#set_context context ;
1543 scratch_window#set_metasenv metasenv ;
1544 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1547 print_endline ("? " ^ CicPp.ppterm expr) ;
1551 let check scratch_window () =
1552 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1554 match ProofEngine.get_proof () with
1556 | Some (_,metasenv,_,_) -> metasenv
1559 match !ProofEngine.goal with
1562 let (_,canonical_context,_) =
1563 List.find (function (m,_,_) -> m=metano) metasenv
1568 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1569 check_term_in_scratch scratch_window metasenv' context expr
1573 (`Error (`T (Printexc.to_string e)))
1578 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1582 (`Error (`T (Printexc.to_string e)))
1585 exception NotADefinition;;
1588 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1589 let notebook = (rendering_window ())#notebook in
1591 let uri = input_or_locate_uri ~title:"Open" in
1592 CicTypeChecker.typecheck uri ;
1593 let metasenv,bo,ty =
1594 match CicEnvironment.get_cooked_obj uri with
1595 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1596 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1599 | Cic.InductiveDefinition _ -> raise NotADefinition
1601 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
1602 set_proof_engine_goal None ;
1603 refresh_goals notebook ;
1604 refresh_proof output ;
1605 !save_set_sensitive true
1607 InvokeTactics.RefreshSequentException e ->
1609 (`Error (`T ("Exception raised during the refresh of the " ^
1610 "sequent: " ^ Printexc.to_string e)))
1611 | InvokeTactics.RefreshProofException e ->
1613 (`Error (`T ("Exception raised during the refresh of the " ^
1614 "proof: " ^ Printexc.to_string e)))
1617 (`Error (`T (Printexc.to_string e)))
1620 let show_query_results results =
1623 ~modal:false ~title:"Query results." ~border_width:2 () in
1624 let vbox = GPack.vbox ~packing:window#add () in
1626 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1629 ~text:"Click on a URI to show that object"
1630 ~packing:hbox#add () in
1631 let scrolled_window =
1632 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1633 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1634 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1637 (function (uri,_) ->
1641 clist#set_row ~selectable:false n
1644 clist#columns_autosize () ;
1646 (clist#connect#select_row
1647 (fun ~row ~column ~event ->
1648 let (uristr,_) = List.nth results row in
1650 MQueryMisc.cic_textual_parser_uri_of_string
1651 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1654 CicTextualParser0.ConUri uri
1655 | CicTextualParser0.VarUri uri
1656 | CicTextualParser0.IndTyUri (uri,_)
1657 | CicTextualParser0.IndConUri (uri,_,_) ->
1658 show_in_show_window_uri uri
1664 let refine_constraints (must_obj,must_rel,must_sort) =
1665 let chosen = ref false in
1666 let use_only = ref false in
1669 ~modal:true ~title:"Constraints refinement."
1670 ~width:800 ~border_width:2 () in
1671 let vbox = GPack.vbox ~packing:window#add () in
1673 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1676 ~text: "\"Only\" constraints can be enforced or not."
1677 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1679 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1680 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1683 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1684 (* Notebook for the constraints choice *)
1686 GPack.notebook ~scrollable:true
1687 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1688 (* Rel constraints *)
1691 ~text: "Constraints on Rels" () in
1693 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1696 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1699 ~text: "You can now specify the constraints on Rels."
1700 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1701 let expected_height = 25 * (List.length must_rel + 2) in
1702 let height = if expected_height > 400 then 400 else expected_height in
1703 let scrolled_window =
1704 GBin.scrolled_window ~border_width:10 ~height ~width:600
1705 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1706 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1707 let mk_depth_button (hbox:GPack.box) d =
1708 let mutable_ref = ref (Some d) in
1710 GButton.toggle_button
1711 ~label:("depth = " ^ string_of_int d)
1713 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1716 (depthb#connect#toggled
1718 let sel_depth = if depthb#active then Some d else None in
1719 mutable_ref := sel_depth
1722 let rel_constraints =
1727 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1730 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1731 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1733 | `MainHypothesis None
1734 | `MainConclusion None -> p, ref None
1735 | `MainHypothesis (Some depth')
1736 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1738 (* Sort constraints *)
1741 ~text: "Constraints on Sorts" () in
1743 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1746 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1749 ~text: "You can now specify the constraints on Sorts."
1750 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1751 let expected_height = 25 * (List.length must_sort + 2) in
1752 let height = if expected_height > 400 then 400 else expected_height in
1753 let scrolled_window =
1754 GBin.scrolled_window ~border_width:10 ~height ~width:600
1755 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1756 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1757 let sort_constraints =
1759 (function (p, sort) ->
1762 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1765 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1766 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1768 | `MainHypothesis None
1769 | `MainConclusion None -> p, ref None, sort
1770 | `MainHypothesis (Some depth')
1771 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1773 (* Obj constraints *)
1776 ~text: "Constraints on constants" () in
1778 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1781 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1784 ~text: "You can now specify the constraints on constants."
1785 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1786 let expected_height = 25 * (List.length must_obj + 2) in
1787 let height = if expected_height > 400 then 400 else expected_height in
1788 let scrolled_window =
1789 GBin.scrolled_window ~border_width:10 ~height ~width:600
1790 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1791 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1792 let obj_constraints =
1794 (function (p, uri) ->
1797 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1800 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1801 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1806 | `MainHypothesis None
1807 | `MainConclusion None -> p, ref None, uri
1808 | `MainHypothesis (Some depth')
1809 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1811 (* Confirm/abort buttons *)
1813 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1815 GButton.button ~label:"Ok"
1816 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1818 GButton.button ~label:"Abort"
1819 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1821 ignore (window#connect#destroy GMain.Main.quit) ;
1822 ignore (cancelb#connect#clicked window#destroy) ;
1824 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1825 window#set_position `CENTER ;
1829 let chosen_must_rel =
1831 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1834 let chosen_must_sort =
1836 (function (position, ref_depth, sort) ->
1837 MQGU.set_main_position position !ref_depth,sort)
1840 let chosen_must_obj =
1842 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1845 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1847 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1848 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1856 let completeSearchPattern () =
1857 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1859 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1860 let must = CGSearchPattern.get_constraints expr in
1861 let must',only = refine_constraints must in
1863 MQG.query_of_constraints (Some CGSearchPattern.universe) must' only
1865 let results = MQI.execute mqi_handle query in
1866 show_query_results results
1870 (`Error (`T (Printexc.to_string e)))
1873 let insertQuery () =
1875 let chosen = ref None in
1878 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1879 let vbox = GPack.vbox ~packing:window#add () in
1881 GMisc.label ~text:"Insert Query. For Experts Only."
1882 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1883 let scrolled_window =
1884 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1885 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1886 let input = GText.view ~editable:true
1887 ~packing:scrolled_window#add () in
1889 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1891 GButton.button ~label:"Ok"
1892 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1894 GButton.button ~label:"Load from file..."
1895 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1897 GButton.button ~label:"Abort"
1898 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1899 ignore (window#connect#destroy GMain.Main.quit) ;
1900 ignore (cancelb#connect#clicked window#destroy) ;
1902 (okb#connect#clicked
1904 chosen := Some (input#buffer#get_text ()) ; window#destroy ())) ;
1906 (loadb#connect#clicked
1909 GToolbox.select_file ~title:"Select Query File" ()
1913 let inch = open_in filename in
1914 let rec read_file () =
1916 let line = input_line inch in
1917 line ^ "\n" ^ read_file ()
1921 let text = read_file () in
1922 input#buffer#delete input#buffer#start_iter input#buffer#end_iter ;
1923 ignore (input#buffer#insert text))) ;
1924 window#set_position `CENTER ;
1931 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1933 show_query_results results
1937 (`Error (`T (Printexc.to_string e)))
1940 let choose_must list_of_must only =
1941 let chosen = ref None in
1942 let user_constraints = ref [] in
1945 ~modal:true ~title:"Query refinement." ~border_width:2 () in
1946 let vbox = GPack.vbox ~packing:window#add () in
1948 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1952 ("You can now specify the genericity of the query. " ^
1953 "The more generic the slower.")
1954 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1956 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1960 "Suggestion: start with faster queries before moving to more generic ones."
1961 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1963 GPack.notebook ~scrollable:true
1964 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1967 let last = List.length list_of_must in
1973 (if !page = 1 then "More generic" else
1974 if !page = last then "More precise" else " ") () in
1975 let expected_height = 25 * (List.length must + 2) in
1976 let height = if expected_height > 400 then 400 else expected_height in
1977 let scrolled_window =
1978 GBin.scrolled_window ~border_width:10 ~height ~width:600
1979 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1981 GList.clist ~columns:2 ~packing:scrolled_window#add
1982 ~titles:["URI" ; "Position"] ()
1986 (function (position, uri) ->
1989 [uri; MQGUtil.text_of_position position]
1991 clist#set_row ~selectable:false n
1994 clist#columns_autosize ()
1997 let label = GMisc.label ~text:"User provided" () in
1999 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2001 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2004 ~text:"Select the constraints that must be satisfied and press OK."
2005 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2006 let expected_height = 25 * (List.length only + 2) in
2007 let height = if expected_height > 400 then 400 else expected_height in
2008 let scrolled_window =
2009 GBin.scrolled_window ~border_width:10 ~height ~width:600
2010 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2012 GList.clist ~columns:2 ~packing:scrolled_window#add
2013 ~selection_mode:`MULTIPLE
2014 ~titles:["URI" ; "Position"] ()
2018 (function (position, uri) ->
2021 [uri; MQGUtil.text_of_position position]
2023 clist#set_row ~selectable:true n
2026 clist#columns_autosize () ;
2028 (clist#connect#select_row
2029 (fun ~row ~column ~event ->
2030 user_constraints := (List.nth only row)::!user_constraints)) ;
2032 (clist#connect#unselect_row
2033 (fun ~row ~column ~event ->
2036 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2039 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2041 GButton.button ~label:"Ok"
2042 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2044 GButton.button ~label:"Abort"
2045 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2047 ignore (window#connect#destroy GMain.Main.quit) ;
2048 ignore (cancelb#connect#clicked window#destroy) ;
2050 (okb#connect#clicked
2051 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2052 window#set_position `CENTER ;
2056 None -> raise NoChoice
2058 if n = List.length list_of_must then
2059 (* user provided constraints *)
2062 List.nth list_of_must n
2065 let searchPattern () =
2066 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2069 match ProofEngine.get_proof () with
2070 None -> assert false
2071 | Some proof -> proof
2073 match !ProofEngine.goal with
2077 TacticChaser.matchConclusion mqi_handle
2078 ~choose_must () ~status:(proof, metano)
2081 user_uri_choice ~title:"Ambiguous input."
2082 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2085 inputt#set_term uri' ;
2086 InvokeTactics'.apply ()
2090 (`Error (`T (Printexc.to_string e)))
2093 let choose_selection mmlwidget (element : Gdome.element option) =
2094 let module G = Gdome in
2095 let rec aux element =
2096 if element#hasAttributeNS
2097 ~namespaceURI:Misc.helmns
2098 ~localName:(G.domString "xref")
2100 mmlwidget#set_selection (Some element)
2103 match element#get_parentNode with
2104 None -> assert false
2105 (*CSC: OCAML DIVERGES!
2106 | Some p -> aux (new G.element_of_node p)
2108 | Some p -> aux (new Gdome.element_of_node p)
2110 GdomeInit.DOMCastException _ ->
2112 "******* trying to select above the document root ********"
2116 | None -> mmlwidget#set_selection None
2119 (* STUFF TO BUILD THE GTK INTERFACE *)
2121 (* Stuff for the widget settings *)
2124 let export_to_postscript output =
2125 let lastdir = ref (Unix.getcwd ()) in
2128 GToolbox.select_file ~title:"Export to PostScript"
2129 ~dir:lastdir ~filename:"screenshot.ps" ()
2133 (output :> GMathView.math_view)#export_to_postscript
2134 ~filename:filename ();
2139 let activate_t1 output button_set_anti_aliasing
2140 button_set_transparency export_to_postscript_menu_item
2143 let is_set = button_t1#active in
2144 output#set_font_manager_type
2145 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2148 button_set_anti_aliasing#misc#set_sensitive true ;
2149 button_set_transparency#misc#set_sensitive true ;
2150 export_to_postscript_menu_item#misc#set_sensitive true ;
2154 button_set_anti_aliasing#misc#set_sensitive false ;
2155 button_set_transparency#misc#set_sensitive false ;
2156 export_to_postscript_menu_item#misc#set_sensitive false ;
2160 let set_anti_aliasing output button_set_anti_aliasing () =
2161 output#set_anti_aliasing button_set_anti_aliasing#active
2164 let set_transparency output button_set_transparency () =
2165 output#set_transparency button_set_transparency#active
2169 let changefont output font_size_spinb () =
2170 output#set_font_size font_size_spinb#value_as_int
2173 let set_log_verbosity output log_verbosity_spinb () =
2174 output#set_log_verbosity log_verbosity_spinb#value_as_int
2177 class settings_window output sw
2178 export_to_postscript_menu_item selection_changed_callback
2180 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2182 GPack.vbox ~packing:settings_window#add () in
2185 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2186 ~border_width:5 ~packing:vbox#add () in
2188 GButton.toggle_button ~label:"activate t1 fonts"
2189 ~packing:(table#attach ~left:0 ~top:0) () in
2190 let button_set_anti_aliasing =
2191 GButton.toggle_button ~label:"set_anti_aliasing"
2192 ~packing:(table#attach ~left:0 ~top:1) () in
2193 let button_set_transparency =
2194 GButton.toggle_button ~label:"set_transparency"
2195 ~packing:(table#attach ~left:2 ~top:1) () in
2198 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2199 ~border_width:5 ~packing:vbox#add () in
2200 let font_size_label =
2201 GMisc.label ~text:"font size:"
2202 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2203 let font_size_spinb =
2205 GData.adjustment ~value:(float_of_int output#get_font_size)
2206 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2209 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2210 let log_verbosity_label =
2211 GMisc.label ~text:"log verbosity:"
2212 ~packing:(table#attach ~left:0 ~top:1) () in
2213 let log_verbosity_spinb =
2215 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2218 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2220 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2222 GButton.button ~label:"Close"
2223 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2225 method show = settings_window#show
2227 button_set_anti_aliasing#misc#set_sensitive false ;
2228 button_set_transparency#misc#set_sensitive false ;
2229 (* Signals connection *)
2231 ignore(button_t1#connect#clicked
2232 (activate_t1 output button_set_anti_aliasing
2233 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2235 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2237 ignore(button_set_anti_aliasing#connect#toggled
2238 (set_anti_aliasing output button_set_anti_aliasing));
2239 ignore(button_set_transparency#connect#toggled
2240 (set_transparency output button_set_transparency)) ;
2242 ignore(log_verbosity_spinb#connect#changed
2243 (set_log_verbosity output log_verbosity_spinb)) ;
2244 ignore(closeb#connect#clicked settings_window#misc#hide)
2247 (* Scratch window *)
2249 class scratch_window =
2252 ~title:"MathML viewer"
2253 ~border_width:2 () in
2255 GPack.vbox ~packing:window#add () in
2257 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2259 GButton.button ~label:"Whd"
2260 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2262 GButton.button ~label:"Reduce"
2263 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2265 GButton.button ~label:"Simpl"
2266 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2267 let scrolled_window =
2268 GBin.scrolled_window ~border_width:10
2269 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2270 let sequent_viewer =
2271 TermViewer.sequent_viewer
2272 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2274 val mutable term = Cic.Rel 1 (* dummy value *)
2275 val mutable context = ([] : Cic.context) (* dummy value *)
2276 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2277 method sequent_viewer = sequent_viewer
2278 method show () = window#misc#hide () ; window#show ()
2280 method set_term t = term <- t
2281 method context = context
2282 method set_context t = context <- t
2283 method metasenv = metasenv
2284 method set_metasenv t = metasenv <- t
2287 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2288 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2289 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2290 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2291 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2294 let open_contextual_menu_for_selected_terms mmlwidget infos =
2295 let button = GdkEvent.Button.button infos in
2296 let terms_selected = List.length mmlwidget#get_selections > 0 in
2299 let time = GdkEvent.Button.time infos in
2300 let menu = GMenu.menu () in
2301 let f = new GMenu.factory menu in
2303 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2304 let reduce_menu_item =
2305 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2306 let simpl_menu_item =
2307 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2308 let _ = f#add_separator () in
2309 let generalize_menu_item =
2310 f#add_item "Generalize"
2311 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2312 let _ = f#add_separator () in
2313 let clear_menu_item =
2314 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2315 let clearbody_menu_item =
2316 f#add_item "ClearBody"
2317 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2319 whd_menu_item#misc#set_sensitive terms_selected ;
2320 reduce_menu_item#misc#set_sensitive terms_selected ;
2321 simpl_menu_item#misc#set_sensitive terms_selected ;
2322 generalize_menu_item#misc#set_sensitive terms_selected ;
2323 clear_menu_item#misc#set_sensitive terms_selected ;
2324 clearbody_menu_item#misc#set_sensitive terms_selected ;
2325 menu#popup ~button ~time
2331 let vbox1 = GPack.vbox () in
2333 val mutable proofw_ref = None
2334 val mutable compute_ref = None
2336 Lazy.force self#compute ;
2337 match proofw_ref with
2338 None -> assert false
2339 | Some proofw -> proofw
2340 method content = vbox1
2342 match compute_ref with
2343 None -> assert false
2344 | Some compute -> compute
2348 let scrolled_window1 =
2349 GBin.scrolled_window ~border_width:10
2350 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2352 TermViewer.sequent_viewer ~width:400 ~height:275
2353 ~packing:(scrolled_window1#add) () in
2354 let _ = proofw_ref <- Some proofw in
2356 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2358 GButton.button ~label:"Ring"
2359 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2361 GButton.button ~label:"Fourier"
2362 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2364 GButton.button ~label:"Reflexivity"
2365 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2367 GButton.button ~label:"Symmetry"
2368 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2370 GButton.button ~label:"Assumption"
2371 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2372 let contradictionb =
2373 GButton.button ~label:"Contradiction"
2374 ~packing:(hbox3#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:"Exists"
2379 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2381 GButton.button ~label:"Split"
2382 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2384 GButton.button ~label:"Left"
2385 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2387 GButton.button ~label:"Right"
2388 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2389 let searchpatternb =
2390 GButton.button ~label:"SearchPattern_Apply"
2391 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2393 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2395 GButton.button ~label:"Exact"
2396 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2398 GButton.button ~label:"Intros"
2399 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2401 GButton.button ~label:"Apply"
2402 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2403 let elimintrossimplb =
2404 GButton.button ~label:"ElimIntrosSimpl"
2405 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2407 GButton.button ~label:"ElimType"
2408 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2410 GButton.button ~label:"Fold_whd"
2411 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2413 GButton.button ~label:"Fold_reduce"
2414 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2416 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2418 GButton.button ~label:"Fold_simpl"
2419 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2421 GButton.button ~label:"Cut"
2422 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2424 GButton.button ~label:"Change"
2425 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2427 GButton.button ~label:"Let ... In"
2428 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2430 GButton.button ~label:"RewriteSimpl ->"
2431 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2432 let rewritebacksimplb =
2433 GButton.button ~label:"RewriteSimpl <-"
2434 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2436 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2438 GButton.button ~label:"Absurd"
2439 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2441 GButton.button ~label:"Decompose"
2442 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2444 GButton.button ~label:"Transitivity"
2445 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2447 GButton.button ~label:"Replace"
2448 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2450 GButton.button ~label:"Injection"
2451 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2453 GButton.button ~label:"Discriminate"
2454 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2455 (* Zack: spostare in una toolbar
2457 GButton.button ~label:"Generalize"
2458 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2460 GButton.button ~label:"ClearBody"
2461 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2463 GButton.button ~label:"Clear"
2464 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2466 GButton.button ~label:"Whd"
2467 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2469 GButton.button ~label:"Reduce"
2470 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2472 GButton.button ~label:"Simpl"
2473 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2476 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2477 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2478 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2479 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2480 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2481 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2482 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2483 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2484 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2485 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2486 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2487 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2488 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2489 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2490 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2491 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2492 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2493 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2494 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2495 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2496 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2497 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2498 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2499 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2500 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2501 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2502 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2503 ignore(searchpatternb#connect#clicked searchPattern) ;
2504 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2505 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2506 (* Zack: spostare in una toolbar
2507 ignore(whdb#connect#clicked whd) ;
2508 ignore(reduceb#connect#clicked reduce) ;
2509 ignore(simplb#connect#clicked simpl) ;
2510 ignore(clearbodyb#connect#clicked clearbody) ;
2511 ignore(clearb#connect#clicked clear) ;
2512 ignore(generalizeb#connect#clicked generalize) ;
2514 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2516 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2517 (open_contextual_menu_for_selected_terms proofw)) ;
2523 let vbox1 = GPack.vbox () in
2524 let scrolled_window1 =
2525 GBin.scrolled_window ~border_width:10
2526 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2528 TermViewer.sequent_viewer ~width:400 ~height:275
2529 ~packing:(scrolled_window1#add) () in
2531 method proofw = (assert false : TermViewer.sequent_viewer)
2532 method content = vbox1
2533 method compute = (assert false : unit)
2537 let empty_page = new empty_page;;
2541 val notebook = GPack.notebook ()
2543 val mutable skip_switch_page_event = false
2544 val mutable empty = true
2545 method notebook = notebook
2547 let new_page = new page () in
2549 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2550 notebook#append_page
2551 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2552 new_page#content#coerce
2553 method remove_all_pages ~skip_switch_page_event:skip =
2555 notebook#remove_page 0 (* let's remove the empty page *)
2557 List.iter (function _ -> notebook#remove_page 0) !pages ;
2559 skip_switch_page_event <- skip
2560 method set_current_page ~may_skip_switch_page_event n =
2561 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2562 let new_page = notebook#page_num page#content#coerce in
2563 if may_skip_switch_page_event && new_page <> notebook#current_page then
2564 skip_switch_page_event <- true ;
2565 notebook#goto_page new_page
2566 method set_empty_page =
2569 notebook#append_page
2570 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2571 empty_page#content#coerce
2573 let (_,_,page) = List.nth !pages notebook#current_page in
2577 (notebook#connect#switch_page
2579 let skip = skip_switch_page_event in
2580 skip_switch_page_event <- false ;
2583 let (metano,setgoal,page) = List.nth !pages i in
2584 set_proof_engine_goal (Some metano) ;
2585 Lazy.force (page#compute) ;
2587 if notify_hbugs_on_goal_change then
2594 let dump_environment () =
2596 let oc = open_out (Helm_registry.get "gtoplevel.environment_file") in
2597 HelmLogger.log (`Msg (`T "Dumping environment ..."));
2598 CicEnvironment.dump_to_channel oc;
2599 HelmLogger.log (`Msg (`T "... done!")) ;
2603 (`Error (`T (Printf.sprintf "Dump failure, uncaught exception:%s"
2604 (Printexc.to_string exc))))
2606 let restore_environment () =
2608 let ic = open_in (Helm_registry.get "gtoplevel.environment_file") in
2609 HelmLogger.log (`Msg (`T "Restoring environment ... "));
2610 CicEnvironment.restore_from_channel ic;
2611 HelmLogger.log (`Msg (`T "... done!"));
2615 (`Error (`T (Printf.sprintf "Restore failure, uncaught exception:%s"
2616 (Printexc.to_string exc))))
2621 class rendering_window output (notebook : notebook) =
2622 let scratch_window = new scratch_window in
2625 ~title:"gTopLevel - Helm's Proof Assistant"
2626 ~border_width:0 ~allow_shrink:false () in
2627 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2629 let handle_box = GBin.handle_box ~border_width:2
2630 ~packing:(vbox_for_menu#pack ~padding:0) () in
2631 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2632 let factory0 = new GMenu.factory menubar in
2633 let accel_group = factory0#accel_group in
2635 let file_menu = factory0#add_submenu "File" in
2636 let factory1 = new GMenu.factory file_menu ~accel_group in
2637 (* let export_to_postscript_menu_item = *)
2641 factory1#add_item "New Block of (Co)Inductive Definitions..."
2642 ~key:GdkKeysyms._B ~callback:new_inductive
2645 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2648 let reopen_menu_item =
2649 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2653 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2654 ignore (factory1#add_separator ()) ;
2656 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2657 ~callback:load_unfinished_proof) ;
2658 let save_menu_item =
2659 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2660 ~callback:save_unfinished_proof
2662 ignore (factory1#add_separator ()) ;
2663 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2664 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2666 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2668 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2669 ignore (!save_set_sensitive false);
2670 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2671 ignore (!qed_set_sensitive false);
2672 ignore (factory1#add_separator ()) ;
2674 let export_to_postscript_menu_item =
2675 factory1#add_item "Export to PostScript..."
2676 ~callback:(export_to_postscript output) in
2678 ignore (factory1#add_separator ()) ;
2680 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2681 export_to_postscript_menu_item *)
2684 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2685 let factory2 = new GMenu.factory edit_menu ~accel_group in
2686 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2687 let proveit_menu_item =
2688 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2689 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2691 let focus_menu_item =
2692 factory2#add_item "Focus" ~key:GdkKeysyms._F
2693 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2696 focus_and_proveit_set_sensitive :=
2698 proveit_menu_item#misc#set_sensitive b ;
2699 focus_menu_item#misc#set_sensitive b
2701 let _ = !focus_and_proveit_set_sensitive false in
2702 (* edit term menu *)
2703 let edit_term_menu = factory0#add_submenu "Edit Term" in
2704 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2705 let check_menu_item =
2706 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2707 ~callback:(check scratch_window) in
2708 let _ = check_menu_item#misc#set_sensitive false in
2710 let search_menu = factory0#add_submenu "Search" in
2711 let factory4 = new GMenu.factory search_menu ~accel_group in
2713 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2715 let searchPattern_menu_item =
2716 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2717 ~callback:completeSearchPattern in
2718 let _ = searchPattern_menu_item#misc#set_sensitive false in
2719 let show_menu_item =
2720 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2722 let insert_query_item =
2723 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2724 ~callback:insertQuery in
2726 let hbugs_menu = factory0#add_submenu "HBugs" in
2727 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2729 factory6#add_check_item
2730 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2733 factory6#add_item ~key:GdkKeysyms._Return ~callback:Hbugs.notify
2734 "(Re)Submit status!"
2736 let _ = factory6#add_separator () in
2738 factory6#add_item ~callback:Hbugs.start_web_services "Start Web Services"
2741 factory6#add_item ~callback:Hbugs.stop_web_services "Stop Web Services"
2744 let settings_menu = factory0#add_submenu "Settings" in
2745 let factory3 = new GMenu.factory settings_menu ~accel_group in
2747 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2748 ~callback:edit_aliases in
2750 factory3#add_item "Clear Aliases" ~key:GdkKeysyms._K
2751 ~callback:clear_aliases in
2753 factory3#add_check_item "Auto disambiguation"
2754 ~callback:(fun checked -> auto_disambiguation := checked) in
2755 let _ = factory3#add_separator () in
2757 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2758 ~callback:(function _ -> (settings_window ())#show ()) in
2759 let _ = factory3#add_separator () in
2761 factory3#add_item "Reload Stylesheets"
2764 ChosenTransformer.reload_stylesheets () ;
2765 if ProofEngine.get_proof () <> None then
2767 refresh_goals notebook ;
2768 refresh_proof output
2770 InvokeTactics.RefreshSequentException e ->
2772 (`Error (`T ("An error occurred while refreshing the " ^
2773 "sequent: " ^ Printexc.to_string e))) ;
2774 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2775 notebook#set_empty_page
2776 | InvokeTactics.RefreshProofException e ->
2778 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2782 let _ = window#add_accel_group accel_group in
2786 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2788 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2789 let scrolled_window0 =
2790 GBin.scrolled_window ~border_width:10
2791 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2792 let _ = scrolled_window0#add output#coerce in
2794 GBin.frame ~label:"Insert Term"
2795 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2796 let scrolled_window1 =
2797 GBin.scrolled_window ~border_width:5
2798 ~packing:frame#add () in
2800 TermEditor'.term_editor
2802 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2803 ~isnotempty_callback:
2805 check_menu_item#misc#set_sensitive b ;
2806 searchPattern_menu_item#misc#set_sensitive b) in
2808 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2810 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2812 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2815 new HelmGtkLogger.html_logger
2816 ~width:400 ~height: 100 ~show:true ~packing:frame#add ()
2819 method inputt = inputt
2820 method output = (output : TermViewer.proof_viewer)
2821 method scratch_window = scratch_window
2822 method notebook = notebook
2823 method show = window#show
2824 method set_auto_disambiguation set = autoitem#set_active set
2826 notebook#set_empty_page ;
2827 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2828 check_term := (check_term_in_scratch scratch_window) ;
2830 (* signal handlers here *)
2831 ignore(output#connect#selection_changed
2833 choose_selection output elem ;
2834 !focus_and_proveit_set_sensitive true
2836 ignore (output#connect#click (show_in_show_window_callback output)) ;
2837 let settings_window = new settings_window output scrolled_window0
2838 (*export_to_postscript_menu_item*)() (choose_selection output) in
2839 set_settings_window settings_window ;
2840 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true ))
2845 let initialize_everything () =
2846 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2847 let notebook = new notebook in
2848 let rendering_window' = new rendering_window output notebook in
2849 rendering_window'#set_auto_disambiguation !auto_disambiguation;
2850 set_rendering_window rendering_window';
2851 let print_error_as_html prefix msg =
2852 HelmLogger.log (`Error (`T (prefix ^ msg)))
2854 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2855 Gdome_xslt.setDebugCallback
2856 (Some (print_error_as_html "XSLT Debug Message: "));
2857 rendering_window'#show () ;
2858 if restore_environment_on_boot &&
2859 Sys.file_exists (Helm_registry.get "gtoplevel.environment_file")
2861 restore_environment ();
2866 ignore (GtkMain.Main.init ()) ;
2867 initialize_everything () ;
2868 MQIC.close mqi_handle;
2873 Sys.catch_break true;
2875 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)