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_flags = [MQIC.Postgres ; MQIC.Stat ; MQIC.Warn ; MQIC.Log]
66 let mqi_handle = MQIC.init mqi_flags mqi_debug_fun
68 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
70 let restore_environment_on_boot = true ;;
71 let notify_hbugs_on_goal_change = false ;;
73 let auto_disambiguation = ref true ;;
75 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
77 let check_term = ref (fun _ _ _ -> assert false);;
79 exception RenderingWindowsNotInitialized;;
81 let set_rendering_window,rendering_window =
82 let rendering_window_ref = ref None in
83 (function rw -> rendering_window_ref := Some rw),
85 match !rendering_window_ref with
86 None -> raise RenderingWindowsNotInitialized
91 exception SettingsWindowsNotInitialized;;
93 let set_settings_window,settings_window =
94 let settings_window_ref = ref None in
95 (function rw -> settings_window_ref := Some rw),
97 match !settings_window_ref with
98 None -> raise SettingsWindowsNotInitialized
103 exception QedSetSensitiveNotInitialized;;
104 let qed_set_sensitive =
105 ref (function _ -> raise QedSetSensitiveNotInitialized)
108 exception SaveSetSensitiveNotInitialized;;
109 let save_set_sensitive =
110 ref (function _ -> raise SaveSetSensitiveNotInitialized)
113 (* COMMAND LINE OPTIONS *)
119 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
122 Arg.parse argspec ignore ""
126 let term_of_cic_textual_parser_uri uri =
127 let module C = Cic in
128 let module CTP = CicTextualParser0 in
130 CTP.ConUri uri -> C.Const (uri,[])
131 | CTP.VarUri uri -> C.Var (uri,[])
132 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
133 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
136 let string_of_cic_textual_parser_uri uri =
137 let module C = Cic in
138 let module CTP = CicTextualParser0 in
141 CTP.ConUri uri -> UriManager.string_of_uri uri
142 | CTP.VarUri uri -> UriManager.string_of_uri uri
143 | CTP.IndTyUri (uri,tyno) ->
144 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
145 | CTP.IndConUri (uri,tyno,consno) ->
146 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
149 (* 4 = String.length "cic:" *)
150 String.sub uri' 4 (String.length uri' - 4)
153 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
157 let check_window uris =
160 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
162 GPack.notebook ~scrollable:true ~packing:window#add () in
167 let scrolled_window =
168 GBin.scrolled_window ~border_width:10
170 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
175 TermViewer.sequent_viewer
176 ~packing:scrolled_window#add ~width:400 ~height:280 () in
179 term_of_cic_textual_parser_uri
180 (MQueryMisc.cic_textual_parser_uri_of_string uri)
182 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
185 mmlwidget#load_sequent [] (111,[],expr)
188 HelmLogger.log (`Error (`T (Printexc.to_string e)))
193 (notebook#connect#switch_page
195 Lazy.force (List.nth render_terms i)))
201 interactive_user_uri_choice ~(selection_mode:[`MULTIPLE|`SINGLE]) ?(ok="Ok")
202 ?(enable_button_for_non_vars=false) ~title ~msg uris
204 let only_constant_choices =
207 (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
210 if selection_mode <> `SINGLE && !auto_disambiguation then
211 Lazy.force only_constant_choices
213 let choices = ref [] in
214 let chosen = ref false in
215 let use_only_constants = ref false in
217 GWindow.dialog ~modal:true ~title ~width:600 () in
219 GMisc.label ~text:msg
220 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
221 let scrolled_window =
222 GBin.scrolled_window ~border_width:10
223 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
225 let expected_height = 18 * List.length uris in
226 let height = if expected_height > 400 then 400 else expected_height in
227 GList.clist ~columns:1 ~packing:scrolled_window#add
228 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
229 let _ = List.map (function x -> clist#append [x]) uris in
231 GPack.hbox ~border_width:0
232 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
234 GMisc.label ~text:"None of the above. Try this one:"
235 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
237 GEdit.entry ~editable:true
238 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
240 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
242 GButton.button ~label:ok
243 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
244 let _ = okb#misc#set_sensitive false in
249 if enable_button_for_non_vars then
250 hbox#pack ~expand:false ~fill:false ~padding:5 w)
251 ~label:"Try constants only" () in
256 if enable_button_for_non_vars then
257 hbox#pack ~expand:false ~fill:false ~padding:5 w)
260 GButton.button ~label:"Check"
261 ~packing:(hbox#pack ~padding:5) () in
262 let _ = checkb#misc#set_sensitive false in
264 GButton.button ~label:"Abort"
265 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
267 let check_callback () =
268 assert (List.length !choices > 0) ;
269 check_window !choices
271 ignore (window#connect#destroy GMain.Main.quit) ;
272 ignore (cancelb#connect#clicked window#destroy) ;
274 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
276 (nonvarsb#connect#clicked
278 use_only_constants := true ;
282 ignore (autob#connect#clicked (fun () ->
283 auto_disambiguation := true;
284 (rendering_window ())#set_auto_disambiguation true;
285 use_only_constants := true ;
288 ignore (checkb#connect#clicked check_callback) ;
290 (clist#connect#select_row
291 (fun ~row ~column ~event ->
292 checkb#misc#set_sensitive true ;
293 okb#misc#set_sensitive true ;
294 choices := (List.nth uris row)::!choices)) ;
296 (clist#connect#unselect_row
297 (fun ~row ~column ~event ->
299 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
301 (manual_input#connect#changed
303 if manual_input#text = "" then
306 checkb#misc#set_sensitive false ;
307 okb#misc#set_sensitive false ;
308 clist#misc#set_sensitive true
312 choices := [manual_input#text] ;
313 clist#unselect_all () ;
314 checkb#misc#set_sensitive true ;
315 okb#misc#set_sensitive true ;
316 clist#misc#set_sensitive false
318 window#set_position `CENTER ;
322 if !use_only_constants then
323 Lazy.force only_constant_choices
325 if List.length !choices > 0 then !choices else raise NoChoice
331 let interactive_interpretation_choice interpretations =
332 let chosen = ref None in
335 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
336 let vbox = GPack.vbox ~packing:window#add () in
340 ("Ambiguous input since there are many well-typed interpretations." ^
341 " Please, choose one of them.")
342 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
344 GPack.notebook ~scrollable:true
345 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
348 (function interpretation ->
350 let expected_height = 18 * List.length interpretation in
351 let height = if expected_height > 400 then 400 else expected_height in
352 GList.clist ~columns:2 ~packing:notebook#append_page ~height
353 ~titles:["id" ; "URI"] ()
357 (function (id,uri) ->
358 let n = clist#append [id;uri] in
359 clist#set_row ~selectable:false n
362 clist#columns_autosize ()
365 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
367 GButton.button ~label:"Ok"
368 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
370 GButton.button ~label:"Abort"
371 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
373 ignore (window#connect#destroy GMain.Main.quit) ;
374 ignore (cancelb#connect#clicked window#destroy) ;
377 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
378 window#set_position `CENTER ;
382 None -> raise NoChoice
390 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
393 let struri = UriManager.string_of_uri uri in
394 let idx = (String.rindex struri '/') + 1 in
395 String.sub struri idx (String.length struri - idx)
397 let path = pathname ^ "/" ^ name in
399 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
403 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
404 ~ask_dtd_to_the_getter:false
407 let innertypesuri = UriManager.innertypesuri_of_uri uri in
408 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
409 Http_getter.register' innertypesuri
410 (Helm_registry.get "local_library.url" ^
411 Str.replace_first (Str.regexp "^cic:") ""
412 (UriManager.string_of_uri innertypesuri) ^ ".xml"
414 (* constant type / variable / mutual inductive types definition *)
415 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
416 Http_getter.register' uri
417 (Helm_registry.get "local_library.url" ^
418 Str.replace_first (Str.regexp "^cic:") ""
419 (UriManager.string_of_uri uri) ^ ".xml"
426 match UriManager.bodyuri_of_uri uri with
428 | Some bodyuri -> bodyuri
430 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
431 Http_getter.register' bodyuri
432 (Helm_registry.get "local_library.url" ^
433 Str.replace_first (Str.regexp "^cic:") ""
434 (UriManager.string_of_uri bodyuri) ^ ".xml"
441 exception OpenConjecturesStillThere;;
442 exception WrongProof;;
444 let pathname_of_annuri uristring =
445 Helm_registry.get "local_library.dir" ^
446 Str.replace_first (Str.regexp "^cic:") "" uristring
449 let make_dirs dirpath =
450 ignore (Unix.system ("mkdir -p " ^ dirpath))
453 let save_obj uri obj =
455 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
456 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
458 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
460 (* let's save the theorem and register it to the getter *)
461 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
463 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
468 match ProofEngine.get_proof () with
470 | Some (uri,[],bo,ty) ->
472 CicReduction.are_convertible []
473 (CicTypeChecker.type_of_aux' [] [] bo) ty
476 (*CSC: Wrong: [] is just plainly wrong *)
477 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
478 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
479 (rendering_window ())#output#load_proof uri proof
481 !qed_set_sensitive false ;
482 (* let's save the theorem and register it to the getter *)
483 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
485 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
490 | _ -> raise OpenConjecturesStillThere
493 (** save an unfinished proof on the filesystem *)
494 let save_unfinished_proof () =
495 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
496 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
497 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
498 Xml.pp ~quiet:true xml (Some proof_file_type) ;
500 (`Msg (`T ("Current proof type saved to " ^ proof_file_type))) ;
501 Xml.pp ~quiet:true bodyxml (Some proof_file) ;
503 (`Msg (`T ("Current proof body saved to " ^ proof_file)))
506 (* Used to typecheck the loaded proofs *)
507 let typecheck_loaded_proof metasenv bo ty =
508 let module T = CicTypeChecker in
511 (fun metasenv ((_,context,ty) as conj) ->
512 ignore (T.type_of_aux' metasenv context ty) ;
515 ignore (T.type_of_aux' metasenv [] ty) ;
516 ignore (T.type_of_aux' metasenv [] bo)
519 let decompose_uris_choice_callback uris =
520 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
521 let module U = UriManager in
524 match MQueryMisc.cic_textual_parser_uri_of_string uri with
525 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
527 (interactive_user_uri_choice
528 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
529 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
531 (function (uri,typeno,_) ->
532 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
537 let mk_fresh_name_callback metasenv context name ~typ =
539 match FreshNamesGenerator.mk_fresh_name metasenv context name ~typ with
540 Cic.Name fresh_name -> fresh_name
541 | Cic.Anonymous -> assert false
544 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
545 ("Enter a fresh name for the hypothesis " ^
547 (List.map (function None -> None | Some (n,_) -> Some n) context))
549 Some fresh_name' -> Cic.Name fresh_name'
550 | None -> raise NoChoice
553 let refresh_proof (output : TermViewer.proof_viewer) =
555 let uri,currentproof =
556 match ProofEngine.get_proof () with
558 | Some (uri,metasenv,bo,ty) ->
559 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
560 if List.length metasenv = 0 then
562 !qed_set_sensitive true ;
567 (*CSC: Wrong: [] is just plainly wrong *)
569 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
571 ignore (output#load_proof uri currentproof)
574 match ProofEngine.get_proof () with
576 | Some (uri,metasenv,bo,ty) ->
577 debug_print ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[])));
578 raise (InvokeTactics.RefreshProofException e)
580 let set_proof_engine_goal g =
581 ProofEngine.goal := g
584 let refresh_goals ?(empty_notebook=true) notebook =
586 match !ProofEngine.goal with
588 if empty_notebook then
590 notebook#remove_all_pages ~skip_switch_page_event:false ;
591 notebook#set_empty_page
594 notebook#proofw#unload
597 match ProofEngine.get_proof () with
599 | Some (_,metasenv,_,_) -> metasenv
602 List.find (function (m,_,_) -> m=metano) metasenv
604 let regenerate_notebook () =
605 let skip_switch_page_event =
607 (m,_,_)::_ when m = metano -> false
610 notebook#remove_all_pages ~skip_switch_page_event ;
611 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
613 if empty_notebook then
615 regenerate_notebook () ;
616 notebook#set_current_page
617 ~may_skip_switch_page_event:false metano
621 notebook#set_current_page
622 ~may_skip_switch_page_event:true metano ;
623 notebook#proofw#load_sequent metasenv currentsequent
628 match !ProofEngine.goal with
633 match ProofEngine.get_proof () with
635 | Some (_,metasenv,_,_) -> metasenv
638 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
640 ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent);
641 raise (InvokeTactics.RefreshSequentException e)
643 debug_print ("Offending sequent " ^ string_of_int metano ^ " unknown.");
644 raise (InvokeTactics.RefreshSequentException e)
646 module InvokeTacticsCallbacks =
648 let sequent_viewer () = (rendering_window ())#notebook#proofw
649 let term_editor () = (rendering_window ())#inputt
650 let scratch_window () = (rendering_window ())#scratch_window
652 let refresh_proof () =
653 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
656 let refresh_goals () =
657 let notebook = (rendering_window ())#notebook in
658 refresh_goals notebook
660 let decompose_uris_choice_callback = decompose_uris_choice_callback
661 let mk_fresh_name_callback = mk_fresh_name_callback
664 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
666 (* Just to initialize the Hbugs module *)
667 module Ignore = Hbugs.Initialize (InvokeTactics');;
668 Hbugs.set_describe_hint_callback (fun hint ->
670 | Hbugs_types.Use_apply_Luke term -> check_window [term]
674 let dummy_uri = "/dummy.con"
676 (** load an unfinished proof from filesystem *)
677 let load_unfinished_proof () =
678 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
679 let notebook = (rendering_window ())#notebook in
682 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
685 None -> raise NoChoice
687 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
688 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
689 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
690 match CicParser.obj_of_xml proof_file_type (Some proof_file) with
691 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
692 typecheck_loaded_proof metasenv bo ty ;
693 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
694 refresh_proof output ;
695 set_proof_engine_goal
698 | (metano,_,_)::_ -> Some metano
700 refresh_goals notebook ;
702 (`Msg (`T ("Current proof type loaded from " ^ proof_file_type)));
704 (`Msg (`T ("Current proof body loaded from " ^ proof_file))) ;
705 !save_set_sensitive true;
708 InvokeTactics.RefreshSequentException e ->
710 (`Error (`T ("Exception raised during the refresh of the " ^
711 "sequent: " ^ Printexc.to_string e)))
712 | InvokeTactics.RefreshProofException e ->
714 (`Error (`T ("Exception raised during the refresh of the " ^
715 "proof: " ^ Printexc.to_string e)))
718 (`Error (`T (Printexc.to_string e)))
721 let clear_aliases () =
722 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
723 inputt#environment :=
724 DisambiguatingParser.EnvironmentP3.of_string
725 DisambiguatingParser.EnvironmentP3.empty
728 let edit_aliases () =
729 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
730 let disambiguation_env = inputt#environment in
731 let chosen_aliases = ref None in
734 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
736 GPack.vbox ~border_width:0 ~packing:window#add () in
737 let scrolled_window =
738 GBin.scrolled_window ~border_width:10
739 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
740 let input = GText.view ~editable:true ~width:400 ~height:100
741 ~packing:scrolled_window#add () in
743 GPack.hbox ~border_width:0
744 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
746 GButton.button ~label:"Ok"
747 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
749 GButton.button ~label:"Clear"
750 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
752 GButton.button ~label:"Cancel"
753 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
754 ignore (window#connect#destroy GMain.Main.quit) ;
755 ignore (cancelb#connect#clicked window#destroy) ;
756 ignore (clearb#connect#clicked (fun () ->
757 input#buffer#set_text DisambiguatingParser.EnvironmentP3.empty)) ;
758 ignore (okb#connect#clicked (fun () ->
759 chosen_aliases := Some (input#buffer#get_text ());
762 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
763 (DisambiguatingParser.EnvironmentP3.to_string !disambiguation_env ^ "\n"));
766 match !chosen_aliases with
768 | Some raw_aliases ->
769 let new_disambiguation_env =
771 DisambiguatingParser.EnvironmentP3.of_string raw_aliases
775 ("Error while parsing aliases: " ^ Printexc.to_string e)));
778 disambiguation_env := new_disambiguation_env
782 let module L = LogicalOperations in
783 let module G = Gdome in
784 let notebook = (rendering_window ())#notebook in
785 let output = (rendering_window ())#output in
787 output#make_sequent_of_selected_term ;
788 refresh_proof output ;
789 refresh_goals notebook
791 InvokeTactics.RefreshSequentException e ->
793 (`Error (`T ("Exception raised during the refresh of the " ^
794 "sequent: " ^ Printexc.to_string e)))
795 | InvokeTactics.RefreshProofException e ->
797 (`Error (`T ("Exception raised during the refresh of the " ^
798 "proof: " ^ Printexc.to_string e)))
801 (`Error (`T (Printexc.to_string e)))
805 let module L = LogicalOperations in
806 let module G = Gdome in
807 let notebook = (rendering_window ())#notebook in
808 let output = (rendering_window ())#output in
810 output#focus_sequent_of_selected_term ;
811 refresh_goals notebook
813 InvokeTactics.RefreshSequentException e ->
815 (`Error (`T ("Exception raised during the refresh of the " ^
816 "sequent: " ^ Printexc.to_string e)))
817 | InvokeTactics.RefreshProofException e ->
819 (`Error (`T ("Exception raised during the refresh of the " ^
820 "proof: " ^ Printexc.to_string e)))
823 (`Error (`T (Printexc.to_string e)))
826 exception NoPrevGoal;;
827 exception NoNextGoal;;
830 let module L = LogicalOperations in
831 let module G = Gdome in
832 let notebook = (rendering_window ())#notebook in
833 let output = (rendering_window ())#output in
835 match ProofEngine.get_proof () with
837 | Some (_,metasenv,_,_) -> metasenv
840 refresh_goals ~empty_notebook:false notebook
842 InvokeTactics.RefreshSequentException e ->
844 (`Error (`T ("Exception raised during the refresh of the " ^
845 "sequent: " ^ Printexc.to_string e)))
848 (`Error (`T (Printexc.to_string e)))
852 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
855 GWindow.window ~width:800 ~border_width:2 () in
856 let scrolled_window =
857 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
859 GMathViewAux.single_selection_math_view
860 ~packing:scrolled_window#add ~width:600 ~height:400 ()
862 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
863 let href = Gdome.domString "href" in
864 let show_in_show_window_obj uri obj =
867 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
868 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
870 Cic2acic.acic_object_of_cic_object obj
873 ChosenTransformer.mml_of_cic_object
874 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
876 window#set_title (UriManager.string_of_uri uri) ;
877 window#misc#hide () ; window#show () ;
878 mmlwidget#load_doc mml ;
882 (`Error (`T (Printexc.to_string e)))
884 let show_in_show_window_uri uri =
885 let obj = CicEnvironment.get_obj uri in
886 show_in_show_window_obj uri obj
888 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
892 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
894 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
896 show_in_show_window_uri (UriManager.uri_of_string uri)
898 ignore (mmlwidget#action_toggle n')
901 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
903 show_in_show_window_obj, show_in_show_window_uri,
904 show_in_show_window_callback
907 exception NoObjectsLocated;;
909 let user_uri_choice ~title ~msg uris =
912 [] -> raise NoObjectsLocated
916 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
921 String.sub uri 4 (String.length uri - 4)
924 let locate_callback id =
925 let query = MQG.locate id in
926 let result = MQI.execute mqi_handle query in
930 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
932 HelmLogger.log (`Msg (`T "Locate Query:")) ;
933 MQueryUtil.text_of_query (fun m -> HelmLogger.log (`Msg (`T m))) "" query;
934 HelmLogger.log (`Msg (`T "Result:")) ;
935 MQueryUtil.text_of_result (fun m -> HelmLogger.log (`Msg (`T m))) "" result;
936 user_uri_choice ~title:"Ambiguous input."
938 ("Ambiguous input \"" ^ id ^
939 "\". Please, choose one interpetation:")
944 let input_or_locate_uri ~title =
945 let uri = ref None in
948 ~width:400 ~modal:true ~title ~border_width:2 () in
949 let vbox = GPack.vbox ~packing:window#add () in
951 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
953 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
955 GEdit.entry ~editable:true
956 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
958 GButton.button ~label:"Check"
959 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
960 let _ = checkb#misc#set_sensitive false in
962 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
964 GMisc.label ~text:"You can also enter an indentifier to locate:"
965 ~packing:(hbox2#pack ~padding:5) () in
967 GEdit.entry ~editable:true
968 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
970 GButton.button ~label:"Locate"
971 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
972 let _ = locateb#misc#set_sensitive false in
974 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
976 GButton.button ~label:"Ok"
977 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
978 let _ = okb#misc#set_sensitive false in
980 GButton.button ~label:"Cancel"
981 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
983 ignore (window#connect#destroy GMain.Main.quit) ;
985 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
986 let check_callback () =
987 let uri = "cic:" ^ manual_input#text in
989 ignore (Http_getter.resolve' (UriManager.uri_of_string uri)) ;
990 HelmLogger.log (`Msg (`T "OK")) ;
993 Http_getter_types.Unresolvable_URI _ ->
995 (`Error (`T ("URI " ^ uri ^
996 " does not correspond to any object."))) ;
998 | UriManager.IllFormedUri _ ->
1000 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
1004 (`Error (`T (Printexc.to_string e))) ;
1008 (okb#connect#clicked
1010 if check_callback () then
1012 uri := Some manual_input#text ;
1016 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1018 (manual_input#connect#changed
1020 if manual_input#text = "" then
1022 checkb#misc#set_sensitive false ;
1023 okb#misc#set_sensitive false
1027 checkb#misc#set_sensitive true ;
1028 okb#misc#set_sensitive true
1031 (locate_input#connect#changed
1032 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1034 (locateb#connect#clicked
1036 let id = locate_input#text in
1037 manual_input#set_text (locate_callback id) ;
1038 locate_input#delete_text 0 (String.length id)
1043 None -> raise NoChoice
1044 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1047 exception AmbiguousInput;;
1049 (* A WIDGET TO ENTER CIC TERMS *)
1051 module DisambiguateCallbacks =
1053 let interactive_user_uri_choice =
1054 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1055 interactive_user_uri_choice ~selection_mode ?ok
1056 ?enable_button_for_non_vars ~title ~msg
1057 let interactive_interpretation_choice = interactive_interpretation_choice
1058 let input_or_locate_uri = input_or_locate_uri
1062 module TermEditor' = ChosenTermEditor.Make (DisambiguateCallbacks);;
1064 (* OTHER FUNCTIONS *)
1067 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1070 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1072 None -> raise NoChoice
1074 let uri = locate_callback input in
1079 (`Error (`T (Printexc.to_string e)))
1083 exception UriAlreadyInUse;;
1084 exception NotAUriToAConstant;;
1086 let new_inductive () =
1087 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1088 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1089 let notebook = (rendering_window ())#notebook in
1091 let chosen = ref false in
1092 let inductive = ref true in
1093 let paramsno = ref 0 in
1094 let get_uri = ref (function _ -> assert false) in
1095 let get_base_uri = ref (function _ -> assert false) in
1096 let get_names = ref (function _ -> assert false) in
1097 let get_types_and_cons = ref (function _ -> assert false) in
1098 let get_context_and_subst = ref (function _ -> assert false) in
1101 ~width:600 ~modal:true ~position:`CENTER
1102 ~title:"New Block of Mutual (Co)Inductive Definitions"
1103 ~border_width:2 () in
1104 let vbox = GPack.vbox ~packing:window#add () in
1106 GPack.hbox ~border_width:0
1107 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1109 GMisc.label ~text:"Enter the URI for the new block:"
1110 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1112 GEdit.entry ~editable:true
1113 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1115 GPack.hbox ~border_width:0
1116 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1120 "Enter the number of left parameters in every arity and constructor type:"
1121 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1122 let paramsno_entry =
1123 GEdit.entry ~editable:true ~text:"0"
1124 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1126 GPack.hbox ~border_width:0
1127 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1129 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1130 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1132 GButton.radio_button ~label:"Inductive"
1133 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1135 GButton.radio_button ~label:"Coinductive"
1136 ~group:inductiveb#group
1137 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1139 GPack.hbox ~border_width:0
1140 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1142 GMisc.label ~text:"Enter the list of the names of the types:"
1143 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1145 GEdit.entry ~editable:true
1146 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1148 GPack.hbox ~border_width:0
1149 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1151 GButton.button ~label:"> Next"
1152 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1153 let _ = okb#misc#set_sensitive true in
1155 GButton.button ~label:"Abort"
1156 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1157 ignore (window#connect#destroy GMain.Main.quit) ;
1158 ignore (cancelb#connect#clicked window#destroy) ;
1162 (okb#connect#clicked
1165 let uristr = "cic:" ^ uri_entry#text in
1166 let namesstr = names_entry#text in
1167 let paramsno' = int_of_string (paramsno_entry#text) in
1168 match Str.split (Str.regexp " +") namesstr with
1170 | (he::tl) as names ->
1171 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1174 ignore (Http_getter.resolve' uri) ;
1175 raise UriAlreadyInUse
1176 with Http_getter_types.Unresolvable_URI _ ->
1177 get_uri := (function () -> uri) ;
1178 get_names := (function () -> names) ;
1179 inductive := inductiveb#active ;
1180 paramsno := paramsno' ;
1186 (`Error (`T (Printexc.to_string e)))
1194 GBin.frame ~label:name
1195 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1196 let vbox = GPack.vbox ~packing:frame#add () in
1197 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1199 GMisc.label ~text:("Enter its type:")
1200 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1201 let scrolled_window =
1202 GBin.scrolled_window ~border_width:5
1203 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1205 TermEditor'.term_editor
1207 ~width:400 ~height:20 ~packing:scrolled_window#add
1208 ~share_environment_with:inputt ()
1209 ~isnotempty_callback:
1211 (*non_empty_type := b ;*)
1212 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1215 GPack.hbox ~border_width:0
1216 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1218 GMisc.label ~text:("Enter the list of its constructors:")
1219 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1220 let cons_names_entry =
1221 GEdit.entry ~editable:true
1222 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1223 (newinputt,cons_names_entry)
1226 vbox#remove hboxn#coerce ;
1228 GPack.hbox ~border_width:0
1229 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1231 GButton.button ~label:"> Next"
1232 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1234 GButton.button ~label:"Abort"
1235 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1236 ignore (cancelb#connect#clicked window#destroy) ;
1238 (okb#connect#clicked
1241 let names = !get_names () in
1242 let types_and_cons =
1244 (fun name (newinputt,cons_names_entry) ->
1245 let consnamesstr = cons_names_entry#text in
1246 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1248 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1251 [] -> expr,cons_names
1252 | _ -> raise AmbiguousInput
1253 ) names type_widgets
1255 let uri = !get_uri () in
1257 (* Let's see if so far the definition is well-typed *)
1260 (* To test if the arities of the inductive types are well *)
1261 (* typed, we check the inductive block definition where *)
1262 (* no constructor is given to each type. *)
1265 (fun name (ty,cons) -> (name, !inductive, ty, []))
1266 names types_and_cons
1268 CicTypeChecker.typecheck_mutual_inductive_defs uri
1269 (tys,params,paramsno)
1271 get_context_and_subst :=
1275 (fun (context,subst) name (ty,_) ->
1277 (Some (Cic.Name name, Cic.Decl ty))::context,
1278 (Cic.MutInd (uri,!i,[]))::subst
1281 ) ([],[]) names types_and_cons) ;
1282 let types_and_cons' =
1284 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1285 names types_and_cons
1287 get_types_and_cons := (function () -> types_and_cons') ;
1293 (`Error (`T (Printexc.to_string e)))
1296 and phase3 name cons =
1297 let get_cons_types = ref (function () -> assert false) in
1300 ~width:600 ~modal:true ~position:`CENTER
1301 ~title:(name ^ " Constructors")
1302 ~border_width:2 () in
1303 let vbox = GPack.vbox ~packing:window2#add () in
1304 let cons_type_widgets =
1306 (function consname ->
1308 GPack.hbox ~border_width:0
1309 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1311 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1312 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1313 let scrolled_window =
1314 GBin.scrolled_window ~border_width:5
1315 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1317 TermEditor'.term_editor
1319 ~width:400 ~height:20 ~packing:scrolled_window#add
1320 ~share_environment_with:inputt ()
1321 ~isnotempty_callback:
1323 (* (*non_empty_type := b ;*)
1324 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1329 GPack.hbox ~border_width:0
1330 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1332 GButton.button ~label:"> Next"
1333 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1334 let _ = okb#misc#set_sensitive true in
1336 GButton.button ~label:"Abort"
1337 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1338 ignore (window2#connect#destroy GMain.Main.quit) ;
1339 ignore (cancelb#connect#clicked window2#destroy) ;
1341 (okb#connect#clicked
1345 let context,subst= !get_context_and_subst () in
1350 inputt#get_metasenv_and_term ~context ~metasenv:[]
1354 let undebrujined_expr =
1356 (fun expr t -> CicSubstitution.subst t expr) expr subst
1358 name, undebrujined_expr
1359 | _ -> raise AmbiguousInput
1360 ) cons cons_type_widgets
1362 get_cons_types := (function () -> cons_types) ;
1367 (`Error (`T (Printexc.to_string e)))
1371 let okb_pressed = !chosen in
1373 if (not okb_pressed) then
1376 assert false (* The control never reaches this point *)
1379 (!get_cons_types ())
1382 (* No more phases left or Abort pressed *)
1388 let uri = !get_uri () in
1391 let tys = !get_types_and_cons () in
1392 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1395 debug_print (CicPp.ppobj obj);
1396 CicTypeChecker.typecheck_mutual_inductive_defs uri
1397 (tys,params,!paramsno) ;
1400 debug_print "Offending mutual (co)inductive type declaration:" ;
1401 debug_print (CicPp.ppobj obj) ;
1403 (* We already know that obj is well-typed. We need to add it to the *)
1404 (* environment in order to compute the inner-types without having to *)
1405 (* debrujin it or having to modify lots of other functions to avoid *)
1406 (* asking the environment for the MUTINDs we are defining now. *)
1407 CicEnvironment.put_inductive_definition uri obj ;
1409 show_in_show_window_obj uri obj
1413 (`Error (`T (Printexc.to_string e)))
1417 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1418 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1419 let notebook = (rendering_window ())#notebook in
1421 let chosen = ref false in
1422 let get_metasenv_and_term = ref (function _ -> assert false) in
1423 let get_uri = ref (function _ -> assert false) in
1424 let non_empty_type = ref false in
1427 ~width:600 ~modal:true ~title:"New Proof or Definition"
1428 ~border_width:2 () in
1429 let vbox = GPack.vbox ~packing:window#add () in
1431 GPack.hbox ~border_width:0
1432 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1434 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1435 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1437 GEdit.entry ~editable:true
1438 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1439 uri_entry#set_text dummy_uri;
1440 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1442 GPack.hbox ~border_width:0
1443 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1445 GMisc.label ~text:"Enter the theorem or definition type:"
1446 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1447 let scrolled_window =
1448 GBin.scrolled_window ~border_width:5
1449 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1450 (* the content of the scrolled_window is moved below (see comment) *)
1452 GPack.hbox ~border_width:0
1453 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1455 GButton.button ~label:"Ok"
1456 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1457 let _ = okb#misc#set_sensitive false in
1459 GButton.button ~label:"Cancel"
1460 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1461 (* moved here to have visibility of the ok button *)
1463 TermEditor'.term_editor
1465 ~width:400 ~height:100 ~packing:scrolled_window#add
1466 ~share_environment_with:inputt ()
1467 ~isnotempty_callback:
1469 non_empty_type := b ;
1470 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1473 newinputt#set_term inputt#get_as_string ;
1476 uri_entry#connect#changed
1478 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1480 ignore (window#connect#destroy GMain.Main.quit) ;
1481 ignore (cancelb#connect#clicked window#destroy) ;
1483 (okb#connect#clicked
1487 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1488 let uristr = "cic:" ^ uri_entry#text in
1489 let uri = UriManager.uri_of_string uristr in
1490 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1491 raise NotAUriToAConstant
1495 ignore (Http_getter.resolve' uri) ;
1496 raise UriAlreadyInUse
1497 with Http_getter_types.Unresolvable_URI _ ->
1498 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1499 get_uri := (function () -> uri) ;
1505 (`Error (`T (Printexc.to_string e)))
1511 let metasenv,expr = !get_metasenv_and_term () in
1512 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1513 ProofEngine.set_proof
1514 (Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr)) ;
1515 set_proof_engine_goal (Some 1) ;
1516 refresh_goals notebook ;
1517 refresh_proof output ;
1518 !save_set_sensitive true ;
1520 ProofEngine.intros ~mk_fresh_name_callback () ;
1521 refresh_goals notebook ;
1522 refresh_proof output
1524 InvokeTactics.RefreshSequentException e ->
1526 (`Error (`T ("Exception raised during the refresh of the " ^
1527 "sequent: " ^ Printexc.to_string e)))
1528 | InvokeTactics.RefreshProofException e ->
1530 (`Error (`T ("Exception raised during the refresh of the " ^
1531 "proof: " ^ Printexc.to_string e)))
1534 (`Error (`T (Printexc.to_string e)))
1537 let check_term_in_scratch scratch_window metasenv context expr =
1539 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1540 let expr = Cic.Cast (expr,ty) in
1541 scratch_window#show () ;
1542 scratch_window#set_term expr ;
1543 scratch_window#set_context context ;
1544 scratch_window#set_metasenv metasenv ;
1545 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1548 print_endline ("? " ^ CicPp.ppterm expr) ;
1552 let check scratch_window () =
1553 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1555 match ProofEngine.get_proof () with
1557 | Some (_,metasenv,_,_) -> metasenv
1560 match !ProofEngine.goal with
1563 let (_,canonical_context,_) =
1564 List.find (function (m,_,_) -> m=metano) metasenv
1569 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1570 check_term_in_scratch scratch_window metasenv' context expr
1574 (`Error (`T (Printexc.to_string e)))
1579 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1583 (`Error (`T (Printexc.to_string e)))
1586 exception NotADefinition;;
1589 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1590 let notebook = (rendering_window ())#notebook in
1592 let uri = input_or_locate_uri ~title:"Open" in
1593 CicTypeChecker.typecheck uri ;
1594 let metasenv,bo,ty =
1595 match CicEnvironment.get_cooked_obj uri with
1596 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1597 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1600 | Cic.InductiveDefinition _ -> raise NotADefinition
1602 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
1603 set_proof_engine_goal None ;
1604 refresh_goals notebook ;
1605 refresh_proof output ;
1606 !save_set_sensitive true
1608 InvokeTactics.RefreshSequentException e ->
1610 (`Error (`T ("Exception raised during the refresh of the " ^
1611 "sequent: " ^ Printexc.to_string e)))
1612 | InvokeTactics.RefreshProofException e ->
1614 (`Error (`T ("Exception raised during the refresh of the " ^
1615 "proof: " ^ Printexc.to_string e)))
1618 (`Error (`T (Printexc.to_string e)))
1621 let show_query_results results =
1624 ~modal:false ~title:"Query results." ~border_width:2 () in
1625 let vbox = GPack.vbox ~packing:window#add () in
1627 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1630 ~text:"Click on a URI to show that object"
1631 ~packing:hbox#add () in
1632 let scrolled_window =
1633 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1634 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1635 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1638 (function (uri,_) ->
1642 clist#set_row ~selectable:false n
1645 clist#columns_autosize () ;
1647 (clist#connect#select_row
1648 (fun ~row ~column ~event ->
1649 let (uristr,_) = List.nth results row in
1651 MQueryMisc.cic_textual_parser_uri_of_string
1652 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1655 CicTextualParser0.ConUri uri
1656 | CicTextualParser0.VarUri uri
1657 | CicTextualParser0.IndTyUri (uri,_)
1658 | CicTextualParser0.IndConUri (uri,_,_) ->
1659 show_in_show_window_uri uri
1665 let refine_constraints (must_obj,must_rel,must_sort) =
1666 let chosen = ref false in
1667 let use_only = ref false in
1670 ~modal:true ~title:"Constraints refinement."
1671 ~width:800 ~border_width:2 () in
1672 let vbox = GPack.vbox ~packing:window#add () in
1674 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1677 ~text: "\"Only\" constraints can be enforced or not."
1678 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1680 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1681 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1684 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1685 (* Notebook for the constraints choice *)
1687 GPack.notebook ~scrollable:true
1688 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1689 (* Rel constraints *)
1692 ~text: "Constraints on Rels" () in
1694 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1697 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1700 ~text: "You can now specify the constraints on Rels."
1701 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1702 let expected_height = 25 * (List.length must_rel + 2) in
1703 let height = if expected_height > 400 then 400 else expected_height in
1704 let scrolled_window =
1705 GBin.scrolled_window ~border_width:10 ~height ~width:600
1706 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1707 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1708 let mk_depth_button (hbox:GPack.box) d =
1709 let mutable_ref = ref (Some d) in
1711 GButton.toggle_button
1712 ~label:("depth = " ^ string_of_int d)
1714 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1717 (depthb#connect#toggled
1719 let sel_depth = if depthb#active then Some d else None in
1720 mutable_ref := sel_depth
1723 let rel_constraints =
1728 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1731 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1732 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1734 | `MainHypothesis None
1735 | `MainConclusion None -> p, ref None
1736 | `MainHypothesis (Some depth')
1737 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1739 (* Sort constraints *)
1742 ~text: "Constraints on Sorts" () in
1744 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1747 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1750 ~text: "You can now specify the constraints on Sorts."
1751 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1752 let expected_height = 25 * (List.length must_sort + 2) in
1753 let height = if expected_height > 400 then 400 else expected_height in
1754 let scrolled_window =
1755 GBin.scrolled_window ~border_width:10 ~height ~width:600
1756 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1757 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1758 let sort_constraints =
1760 (function (p, sort) ->
1763 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1766 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1767 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1769 | `MainHypothesis None
1770 | `MainConclusion None -> p, ref None, sort
1771 | `MainHypothesis (Some depth')
1772 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1774 (* Obj constraints *)
1777 ~text: "Constraints on constants" () in
1779 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1782 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1785 ~text: "You can now specify the constraints on constants."
1786 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1787 let expected_height = 25 * (List.length must_obj + 2) in
1788 let height = if expected_height > 400 then 400 else expected_height in
1789 let scrolled_window =
1790 GBin.scrolled_window ~border_width:10 ~height ~width:600
1791 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1792 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1793 let obj_constraints =
1795 (function (p, uri) ->
1798 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1801 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1802 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1807 | `MainHypothesis None
1808 | `MainConclusion None -> p, ref None, uri
1809 | `MainHypothesis (Some depth')
1810 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1812 (* Confirm/abort buttons *)
1814 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1816 GButton.button ~label:"Ok"
1817 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1819 GButton.button ~label:"Abort"
1820 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1822 ignore (window#connect#destroy GMain.Main.quit) ;
1823 ignore (cancelb#connect#clicked window#destroy) ;
1825 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1826 window#set_position `CENTER ;
1830 let chosen_must_rel =
1832 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1835 let chosen_must_sort =
1837 (function (position, ref_depth, sort) ->
1838 MQGU.set_main_position position !ref_depth,sort)
1841 let chosen_must_obj =
1843 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1846 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1848 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1849 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1857 let completeSearchPattern () =
1858 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1860 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1861 let must = CGSearchPattern.get_constraints expr in
1862 let must',only = refine_constraints must in
1864 MQG.query_of_constraints (Some CGSearchPattern.universe) must' only
1866 let results = MQI.execute mqi_handle query in
1867 show_query_results results
1871 (`Error (`T (Printexc.to_string e)))
1874 let insertQuery () =
1876 let chosen = ref None in
1879 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1880 let vbox = GPack.vbox ~packing:window#add () in
1882 GMisc.label ~text:"Insert Query. For Experts Only."
1883 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1884 let scrolled_window =
1885 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1886 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1887 let input = GText.view ~editable:true
1888 ~packing:scrolled_window#add () in
1890 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1892 GButton.button ~label:"Ok"
1893 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1895 GButton.button ~label:"Load from file..."
1896 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1898 GButton.button ~label:"Abort"
1899 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1900 ignore (window#connect#destroy GMain.Main.quit) ;
1901 ignore (cancelb#connect#clicked window#destroy) ;
1903 (okb#connect#clicked
1905 chosen := Some (input#buffer#get_text ()) ; window#destroy ())) ;
1907 (loadb#connect#clicked
1910 GToolbox.select_file ~title:"Select Query File" ()
1914 let inch = open_in filename in
1915 let rec read_file () =
1917 let line = input_line inch in
1918 line ^ "\n" ^ read_file ()
1922 let text = read_file () in
1923 input#buffer#delete input#buffer#start_iter input#buffer#end_iter ;
1924 ignore (input#buffer#insert text))) ;
1925 window#set_position `CENTER ;
1932 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1934 show_query_results results
1938 (`Error (`T (Printexc.to_string e)))
1941 let choose_must list_of_must only =
1942 let chosen = ref None in
1943 let user_constraints = ref [] in
1946 ~modal:true ~title:"Query refinement." ~border_width:2 () in
1947 let vbox = GPack.vbox ~packing:window#add () in
1949 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1953 ("You can now specify the genericity of the query. " ^
1954 "The more generic the slower.")
1955 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1957 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1961 "Suggestion: start with faster queries before moving to more generic ones."
1962 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1964 GPack.notebook ~scrollable:true
1965 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1968 let last = List.length list_of_must in
1974 (if !page = 1 then "More generic" else
1975 if !page = last then "More precise" else " ") () in
1976 let expected_height = 25 * (List.length must + 2) in
1977 let height = if expected_height > 400 then 400 else expected_height in
1978 let scrolled_window =
1979 GBin.scrolled_window ~border_width:10 ~height ~width:600
1980 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1982 GList.clist ~columns:2 ~packing:scrolled_window#add
1983 ~titles:["URI" ; "Position"] ()
1987 (function (position, uri) ->
1990 [uri; MQGUtil.text_of_position position]
1992 clist#set_row ~selectable:false n
1995 clist#columns_autosize ()
1998 let label = GMisc.label ~text:"User provided" () in
2000 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2002 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2005 ~text:"Select the constraints that must be satisfied and press OK."
2006 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2007 let expected_height = 25 * (List.length only + 2) in
2008 let height = if expected_height > 400 then 400 else expected_height in
2009 let scrolled_window =
2010 GBin.scrolled_window ~border_width:10 ~height ~width:600
2011 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2013 GList.clist ~columns:2 ~packing:scrolled_window#add
2014 ~selection_mode:`MULTIPLE
2015 ~titles:["URI" ; "Position"] ()
2019 (function (position, uri) ->
2022 [uri; MQGUtil.text_of_position position]
2024 clist#set_row ~selectable:true n
2027 clist#columns_autosize () ;
2029 (clist#connect#select_row
2030 (fun ~row ~column ~event ->
2031 user_constraints := (List.nth only row)::!user_constraints)) ;
2033 (clist#connect#unselect_row
2034 (fun ~row ~column ~event ->
2037 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2040 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2042 GButton.button ~label:"Ok"
2043 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2045 GButton.button ~label:"Abort"
2046 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2048 ignore (window#connect#destroy GMain.Main.quit) ;
2049 ignore (cancelb#connect#clicked window#destroy) ;
2051 (okb#connect#clicked
2052 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2053 window#set_position `CENTER ;
2057 None -> raise NoChoice
2059 if n = List.length list_of_must then
2060 (* user provided constraints *)
2063 List.nth list_of_must n
2066 let searchPattern () =
2067 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2070 match ProofEngine.get_proof () with
2071 None -> assert false
2072 | Some proof -> proof
2074 match !ProofEngine.goal with
2078 TacticChaser.matchConclusion mqi_handle
2079 ~choose_must () ~status:(proof, metano)
2082 user_uri_choice ~title:"Ambiguous input."
2083 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2086 inputt#set_term uri' ;
2087 InvokeTactics'.apply ()
2091 (`Error (`T (Printexc.to_string e)))
2094 let choose_selection mmlwidget (element : Gdome.element option) =
2095 let module G = Gdome in
2096 let rec aux element =
2097 if element#hasAttributeNS
2098 ~namespaceURI:Misc.helmns
2099 ~localName:(G.domString "xref")
2101 mmlwidget#set_selection (Some element)
2104 match element#get_parentNode with
2105 None -> assert false
2106 (*CSC: OCAML DIVERGES!
2107 | Some p -> aux (new G.element_of_node p)
2109 | Some p -> aux (new Gdome.element_of_node p)
2111 GdomeInit.DOMCastException _ ->
2113 "******* trying to select above the document root ********"
2117 | None -> mmlwidget#set_selection None
2120 (* STUFF TO BUILD THE GTK INTERFACE *)
2122 (* Stuff for the widget settings *)
2125 let export_to_postscript output =
2126 let lastdir = ref (Unix.getcwd ()) in
2129 GToolbox.select_file ~title:"Export to PostScript"
2130 ~dir:lastdir ~filename:"screenshot.ps" ()
2134 (output :> GMathView.math_view)#export_to_postscript
2135 ~filename:filename ();
2140 let activate_t1 output button_set_anti_aliasing
2141 button_set_transparency export_to_postscript_menu_item
2144 let is_set = button_t1#active in
2145 output#set_font_manager_type
2146 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2149 button_set_anti_aliasing#misc#set_sensitive true ;
2150 button_set_transparency#misc#set_sensitive true ;
2151 export_to_postscript_menu_item#misc#set_sensitive true ;
2155 button_set_anti_aliasing#misc#set_sensitive false ;
2156 button_set_transparency#misc#set_sensitive false ;
2157 export_to_postscript_menu_item#misc#set_sensitive false ;
2161 let set_anti_aliasing output button_set_anti_aliasing () =
2162 output#set_anti_aliasing button_set_anti_aliasing#active
2165 let set_transparency output button_set_transparency () =
2166 output#set_transparency button_set_transparency#active
2170 let changefont output font_size_spinb () =
2171 output#set_font_size font_size_spinb#value_as_int
2174 let set_log_verbosity output log_verbosity_spinb () =
2175 output#set_log_verbosity log_verbosity_spinb#value_as_int
2178 class settings_window output sw
2179 export_to_postscript_menu_item selection_changed_callback
2181 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2183 GPack.vbox ~packing:settings_window#add () in
2186 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2187 ~border_width:5 ~packing:vbox#add () in
2189 GButton.toggle_button ~label:"activate t1 fonts"
2190 ~packing:(table#attach ~left:0 ~top:0) () in
2191 let button_set_anti_aliasing =
2192 GButton.toggle_button ~label:"set_anti_aliasing"
2193 ~packing:(table#attach ~left:0 ~top:1) () in
2194 let button_set_transparency =
2195 GButton.toggle_button ~label:"set_transparency"
2196 ~packing:(table#attach ~left:2 ~top:1) () in
2199 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2200 ~border_width:5 ~packing:vbox#add () in
2201 let font_size_label =
2202 GMisc.label ~text:"font size:"
2203 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2204 let font_size_spinb =
2206 GData.adjustment ~value:(float_of_int output#get_font_size)
2207 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2210 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2211 let log_verbosity_label =
2212 GMisc.label ~text:"log verbosity:"
2213 ~packing:(table#attach ~left:0 ~top:1) () in
2214 let log_verbosity_spinb =
2216 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2219 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2221 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2223 GButton.button ~label:"Close"
2224 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2226 method show = settings_window#show
2228 button_set_anti_aliasing#misc#set_sensitive false ;
2229 button_set_transparency#misc#set_sensitive false ;
2230 (* Signals connection *)
2232 ignore(button_t1#connect#clicked
2233 (activate_t1 output button_set_anti_aliasing
2234 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2236 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2238 ignore(button_set_anti_aliasing#connect#toggled
2239 (set_anti_aliasing output button_set_anti_aliasing));
2240 ignore(button_set_transparency#connect#toggled
2241 (set_transparency output button_set_transparency)) ;
2243 ignore(log_verbosity_spinb#connect#changed
2244 (set_log_verbosity output log_verbosity_spinb)) ;
2245 ignore(closeb#connect#clicked settings_window#misc#hide)
2248 (* Scratch window *)
2250 class scratch_window =
2253 ~title:"MathML viewer"
2254 ~border_width:2 () in
2256 GPack.vbox ~packing:window#add () in
2258 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2260 GButton.button ~label:"Whd"
2261 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2263 GButton.button ~label:"Reduce"
2264 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2266 GButton.button ~label:"Simpl"
2267 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2268 let scrolled_window =
2269 GBin.scrolled_window ~border_width:10
2270 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2271 let sequent_viewer =
2272 TermViewer.sequent_viewer
2273 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2275 val mutable term = Cic.Rel 1 (* dummy value *)
2276 val mutable context = ([] : Cic.context) (* dummy value *)
2277 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2278 method sequent_viewer = sequent_viewer
2279 method show () = window#misc#hide () ; window#show ()
2281 method set_term t = term <- t
2282 method context = context
2283 method set_context t = context <- t
2284 method metasenv = metasenv
2285 method set_metasenv t = metasenv <- t
2288 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2289 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2290 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2291 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2292 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2295 let open_contextual_menu_for_selected_terms mmlwidget infos =
2296 let button = GdkEvent.Button.button infos in
2297 let terms_selected = List.length mmlwidget#get_selections > 0 in
2300 let time = GdkEvent.Button.time infos in
2301 let menu = GMenu.menu () in
2302 let f = new GMenu.factory menu in
2304 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2305 let reduce_menu_item =
2306 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2307 let simpl_menu_item =
2308 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2309 let _ = f#add_separator () in
2310 let generalize_menu_item =
2311 f#add_item "Generalize"
2312 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2313 let _ = f#add_separator () in
2314 let clear_menu_item =
2315 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2316 let clearbody_menu_item =
2317 f#add_item "ClearBody"
2318 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2320 whd_menu_item#misc#set_sensitive terms_selected ;
2321 reduce_menu_item#misc#set_sensitive terms_selected ;
2322 simpl_menu_item#misc#set_sensitive terms_selected ;
2323 generalize_menu_item#misc#set_sensitive terms_selected ;
2324 clear_menu_item#misc#set_sensitive terms_selected ;
2325 clearbody_menu_item#misc#set_sensitive terms_selected ;
2326 menu#popup ~button ~time
2332 let vbox1 = GPack.vbox () in
2334 val mutable proofw_ref = None
2335 val mutable compute_ref = None
2337 Lazy.force self#compute ;
2338 match proofw_ref with
2339 None -> assert false
2340 | Some proofw -> proofw
2341 method content = vbox1
2343 match compute_ref with
2344 None -> assert false
2345 | Some compute -> compute
2349 let scrolled_window1 =
2350 GBin.scrolled_window ~border_width:10
2351 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2353 TermViewer.sequent_viewer ~width:400 ~height:275
2354 ~packing:(scrolled_window1#add) () in
2355 let _ = proofw_ref <- Some proofw in
2357 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2359 GButton.button ~label:"Ring"
2360 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2362 GButton.button ~label:"Fourier"
2363 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2365 GButton.button ~label:"Reflexivity"
2366 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2368 GButton.button ~label:"Symmetry"
2369 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2371 GButton.button ~label:"Assumption"
2372 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2373 let contradictionb =
2374 GButton.button ~label:"Contradiction"
2375 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2377 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2379 GButton.button ~label:"Exists"
2380 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2382 GButton.button ~label:"Split"
2383 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2385 GButton.button ~label:"Left"
2386 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2388 GButton.button ~label:"Right"
2389 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2390 let searchpatternb =
2391 GButton.button ~label:"SearchPattern_Apply"
2392 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2394 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2396 GButton.button ~label:"Exact"
2397 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2399 GButton.button ~label:"Intros"
2400 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2402 GButton.button ~label:"Apply"
2403 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2404 let elimintrossimplb =
2405 GButton.button ~label:"ElimIntrosSimpl"
2406 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2408 GButton.button ~label:"ElimType"
2409 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2411 GButton.button ~label:"Fold_whd"
2412 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2414 GButton.button ~label:"Fold_reduce"
2415 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2417 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2419 GButton.button ~label:"Fold_simpl"
2420 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2422 GButton.button ~label:"Cut"
2423 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2425 GButton.button ~label:"Change"
2426 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2428 GButton.button ~label:"Let ... In"
2429 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2431 GButton.button ~label:"RewriteSimpl ->"
2432 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2433 let rewritebacksimplb =
2434 GButton.button ~label:"RewriteSimpl <-"
2435 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2437 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2439 GButton.button ~label:"Absurd"
2440 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2442 GButton.button ~label:"Decompose"
2443 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2445 GButton.button ~label:"Transitivity"
2446 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2448 GButton.button ~label:"Replace"
2449 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2451 GButton.button ~label:"Injection"
2452 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2454 GButton.button ~label:"Discriminate"
2455 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2456 (* Zack: spostare in una toolbar
2458 GButton.button ~label:"Generalize"
2459 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2461 GButton.button ~label:"ClearBody"
2462 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2464 GButton.button ~label:"Clear"
2465 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2467 GButton.button ~label:"Whd"
2468 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2470 GButton.button ~label:"Reduce"
2471 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2473 GButton.button ~label:"Simpl"
2474 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2477 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2478 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2479 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2480 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2481 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2482 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2483 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2484 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2485 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2486 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2487 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2488 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2489 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2490 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2491 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2492 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2493 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2494 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2495 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2496 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2497 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2498 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2499 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2500 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2501 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2502 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2503 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2504 ignore(searchpatternb#connect#clicked searchPattern) ;
2505 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2506 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2507 (* Zack: spostare in una toolbar
2508 ignore(whdb#connect#clicked whd) ;
2509 ignore(reduceb#connect#clicked reduce) ;
2510 ignore(simplb#connect#clicked simpl) ;
2511 ignore(clearbodyb#connect#clicked clearbody) ;
2512 ignore(clearb#connect#clicked clear) ;
2513 ignore(generalizeb#connect#clicked generalize) ;
2515 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2517 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2518 (open_contextual_menu_for_selected_terms proofw)) ;
2524 let vbox1 = GPack.vbox () in
2525 let scrolled_window1 =
2526 GBin.scrolled_window ~border_width:10
2527 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2529 TermViewer.sequent_viewer ~width:400 ~height:275
2530 ~packing:(scrolled_window1#add) () in
2532 method proofw = (assert false : TermViewer.sequent_viewer)
2533 method content = vbox1
2534 method compute = (assert false : unit)
2538 let empty_page = new empty_page;;
2542 val notebook = GPack.notebook ()
2544 val mutable skip_switch_page_event = false
2545 val mutable empty = true
2546 method notebook = notebook
2548 let new_page = new page () in
2550 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2551 notebook#append_page
2552 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2553 new_page#content#coerce
2554 method remove_all_pages ~skip_switch_page_event:skip =
2556 notebook#remove_page 0 (* let's remove the empty page *)
2558 List.iter (function _ -> notebook#remove_page 0) !pages ;
2560 skip_switch_page_event <- skip
2561 method set_current_page ~may_skip_switch_page_event n =
2562 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2563 let new_page = notebook#page_num page#content#coerce in
2564 if may_skip_switch_page_event && new_page <> notebook#current_page then
2565 skip_switch_page_event <- true ;
2566 notebook#goto_page new_page
2567 method set_empty_page =
2570 notebook#append_page
2571 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2572 empty_page#content#coerce
2574 let (_,_,page) = List.nth !pages notebook#current_page in
2578 (notebook#connect#switch_page
2580 let skip = skip_switch_page_event in
2581 skip_switch_page_event <- false ;
2584 let (metano,setgoal,page) = List.nth !pages i in
2585 set_proof_engine_goal (Some metano) ;
2586 Lazy.force (page#compute) ;
2588 if notify_hbugs_on_goal_change then
2595 let dump_environment () =
2597 let oc = open_out (Helm_registry.get "gtoplevel.environment_file") in
2598 HelmLogger.log (`Msg (`T "Dumping environment ..."));
2599 CicEnvironment.dump_to_channel oc;
2600 HelmLogger.log (`Msg (`T "... done!")) ;
2604 (`Error (`T (Printf.sprintf "Dump failure, uncaught exception:%s"
2605 (Printexc.to_string exc))))
2607 let restore_environment () =
2609 let ic = open_in (Helm_registry.get "gtoplevel.environment_file") in
2610 HelmLogger.log (`Msg (`T "Restoring environment ... "));
2611 CicEnvironment.restore_from_channel ic;
2612 HelmLogger.log (`Msg (`T "... done!"));
2616 (`Error (`T (Printf.sprintf "Restore failure, uncaught exception:%s"
2617 (Printexc.to_string exc))))
2622 class rendering_window output (notebook : notebook) =
2623 let scratch_window = new scratch_window in
2626 ~title:"gTopLevel - Helm's Proof Assistant"
2627 ~border_width:0 ~allow_shrink:false () in
2628 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2630 let handle_box = GBin.handle_box ~border_width:2
2631 ~packing:(vbox_for_menu#pack ~padding:0) () in
2632 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2633 let factory0 = new GMenu.factory menubar in
2634 let accel_group = factory0#accel_group in
2636 let file_menu = factory0#add_submenu "File" in
2637 let factory1 = new GMenu.factory file_menu ~accel_group in
2638 (* let export_to_postscript_menu_item = *)
2642 factory1#add_item "New Block of (Co)Inductive Definitions..."
2643 ~key:GdkKeysyms._B ~callback:new_inductive
2646 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2649 let reopen_menu_item =
2650 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2654 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2655 ignore (factory1#add_separator ()) ;
2657 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2658 ~callback:load_unfinished_proof) ;
2659 let save_menu_item =
2660 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2661 ~callback:save_unfinished_proof
2663 ignore (factory1#add_separator ()) ;
2664 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2665 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2667 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2669 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2670 ignore (!save_set_sensitive false);
2671 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2672 ignore (!qed_set_sensitive false);
2673 ignore (factory1#add_separator ()) ;
2675 let export_to_postscript_menu_item =
2676 factory1#add_item "Export to PostScript..."
2677 ~callback:(export_to_postscript output) in
2679 ignore (factory1#add_separator ()) ;
2681 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2682 export_to_postscript_menu_item *)
2685 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2686 let factory2 = new GMenu.factory edit_menu ~accel_group in
2687 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2688 let proveit_menu_item =
2689 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2690 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2692 let focus_menu_item =
2693 factory2#add_item "Focus" ~key:GdkKeysyms._F
2694 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2697 focus_and_proveit_set_sensitive :=
2699 proveit_menu_item#misc#set_sensitive b ;
2700 focus_menu_item#misc#set_sensitive b
2702 let _ = !focus_and_proveit_set_sensitive false in
2703 (* edit term menu *)
2704 let edit_term_menu = factory0#add_submenu "Edit Term" in
2705 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2706 let check_menu_item =
2707 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2708 ~callback:(check scratch_window) in
2709 let _ = check_menu_item#misc#set_sensitive false in
2711 let search_menu = factory0#add_submenu "Search" in
2712 let factory4 = new GMenu.factory search_menu ~accel_group in
2714 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2716 let searchPattern_menu_item =
2717 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2718 ~callback:completeSearchPattern in
2719 let _ = searchPattern_menu_item#misc#set_sensitive false in
2720 let show_menu_item =
2721 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2723 let insert_query_item =
2724 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2725 ~callback:insertQuery in
2727 let hbugs_menu = factory0#add_submenu "HBugs" in
2728 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2730 factory6#add_check_item
2731 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2734 factory6#add_item ~key:GdkKeysyms._Return ~callback:Hbugs.notify
2735 "(Re)Submit status!"
2737 let _ = factory6#add_separator () in
2739 factory6#add_item ~callback:Hbugs.start_web_services "Start Web Services"
2742 factory6#add_item ~callback:Hbugs.stop_web_services "Stop Web Services"
2745 let settings_menu = factory0#add_submenu "Settings" in
2746 let factory3 = new GMenu.factory settings_menu ~accel_group in
2748 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2749 ~callback:edit_aliases in
2751 factory3#add_item "Clear Aliases" ~key:GdkKeysyms._K
2752 ~callback:clear_aliases in
2754 factory3#add_check_item "Auto disambiguation"
2755 ~callback:(fun checked -> auto_disambiguation := checked) in
2756 let _ = factory3#add_separator () in
2758 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2759 ~callback:(function _ -> (settings_window ())#show ()) in
2760 let _ = factory3#add_separator () in
2762 factory3#add_item "Reload Stylesheets"
2765 ChosenTransformer.reload_stylesheets () ;
2766 if ProofEngine.get_proof () <> None then
2768 refresh_goals notebook ;
2769 refresh_proof output
2771 InvokeTactics.RefreshSequentException e ->
2773 (`Error (`T ("An error occurred while refreshing the " ^
2774 "sequent: " ^ Printexc.to_string e))) ;
2775 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2776 notebook#set_empty_page
2777 | InvokeTactics.RefreshProofException e ->
2779 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2783 let _ = window#add_accel_group accel_group in
2787 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2789 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2790 let scrolled_window0 =
2791 GBin.scrolled_window ~border_width:10
2792 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2793 let _ = scrolled_window0#add output#coerce in
2795 GBin.frame ~label:"Insert Term"
2796 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2797 let scrolled_window1 =
2798 GBin.scrolled_window ~border_width:5
2799 ~packing:frame#add () in
2801 TermEditor'.term_editor
2803 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2804 ~isnotempty_callback:
2806 check_menu_item#misc#set_sensitive b ;
2807 searchPattern_menu_item#misc#set_sensitive b) in
2809 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2811 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2813 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2816 new HelmGtkLogger.html_logger
2817 ~width:400 ~height: 100 ~show:true ~packing:frame#add ()
2820 method inputt = inputt
2821 method output = (output : TermViewer.proof_viewer)
2822 method scratch_window = scratch_window
2823 method notebook = notebook
2824 method show = window#show
2825 method set_auto_disambiguation set = autoitem#set_active set
2827 notebook#set_empty_page ;
2828 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2829 check_term := (check_term_in_scratch scratch_window) ;
2831 (* signal handlers here *)
2832 ignore(output#connect#selection_changed
2834 choose_selection output elem ;
2835 !focus_and_proveit_set_sensitive true
2837 ignore (output#connect#click (show_in_show_window_callback output)) ;
2838 let settings_window = new settings_window output scrolled_window0
2839 (*export_to_postscript_menu_item*)() (choose_selection output) in
2840 set_settings_window settings_window ;
2841 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true ))
2846 let initialize_everything () =
2847 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2848 let notebook = new notebook in
2849 let rendering_window' = new rendering_window output notebook in
2850 rendering_window'#set_auto_disambiguation !auto_disambiguation;
2851 set_rendering_window rendering_window';
2852 let print_error_as_html prefix msg =
2853 HelmLogger.log (`Error (`T (prefix ^ msg)))
2855 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2856 Gdome_xslt.setDebugCallback
2857 (Some (print_error_as_html "XSLT Debug Message: "));
2858 rendering_window'#show () ;
2859 if restore_environment_on_boot &&
2860 Sys.file_exists (Helm_registry.get "gtoplevel.environment_file")
2862 restore_environment ();
2867 ignore (GtkMain.Main.init ()) ;
2868 initialize_everything () ;
2869 MQIC.close mqi_handle;
2874 Sys.catch_break true;
2876 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)