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)
43 module MQI = MQueryInterpreter
45 module MQGT = MQGTypes
47 module MQG = MQueryGenerator
49 (* first of all let's initialize the Helm_registry *)
51 let configuration_file = "gTopLevel.conf.xml" in
52 if not (Sys.file_exists configuration_file) then begin
53 eprintf "E: Can't find configuration file '%s'\n" configuration_file;
56 Helm_registry.load_from configuration_file
59 (* GLOBAL CONSTANTS *)
61 let mqi_handle = MQIC.init_if_connected ()
65 ~host:(Helm_registry.get "db.host")
66 ~user:(Helm_registry.get "db.user")
67 ~database:(Helm_registry.get "db.database")
70 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
72 let restore_environment_on_boot = true ;;
73 let notify_hbugs_on_goal_change = false ;;
75 let auto_disambiguation = ref true ;;
77 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
79 let check_term = ref (fun _ _ _ -> assert false);;
81 exception RenderingWindowsNotInitialized;;
83 let set_rendering_window,rendering_window =
84 let rendering_window_ref = ref None in
85 (function rw -> rendering_window_ref := Some rw),
87 match !rendering_window_ref with
88 None -> raise RenderingWindowsNotInitialized
93 exception SettingsWindowsNotInitialized;;
95 let set_settings_window,settings_window =
96 let settings_window_ref = ref None in
97 (function rw -> settings_window_ref := Some rw),
99 match !settings_window_ref with
100 None -> raise SettingsWindowsNotInitialized
105 exception QedSetSensitiveNotInitialized;;
106 let qed_set_sensitive =
107 ref (function _ -> raise QedSetSensitiveNotInitialized)
110 exception SaveSetSensitiveNotInitialized;;
111 let save_set_sensitive =
112 ref (function _ -> raise SaveSetSensitiveNotInitialized)
115 (* COMMAND LINE OPTIONS *)
121 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
124 Arg.parse argspec ignore ""
126 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
130 let check_window uris =
133 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
135 GPack.notebook ~scrollable:true ~packing:window#add () in
140 let scrolled_window =
141 GBin.scrolled_window ~border_width:10
143 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
148 TermViewer.sequent_viewer
149 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
150 ~packing:scrolled_window#add ~width:400 ~height:280 () in
152 let term = CicUtil.term_of_uri uri in
153 (Cic.Cast (term, fst(CicTypeChecker.type_of_aux' [] [] term
154 CicUniv.empty_ugraph )))
157 mmlwidget#load_sequent [] (111,[],expr)
160 HelmLogger.log (`Error (`T (Printexc.to_string e)))
165 (notebook#connect#switch_page
167 Lazy.force (List.nth render_terms i)))
172 let interactive_user_uri_choice
173 ~(selection_mode:[ `SINGLE | `MULTIPLE ])
174 ?(ok="Ok") ?(enable_button_for_non_vars=false) ~title ~msg uris
176 let only_constant_choices =
179 (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
182 if selection_mode <> `SINGLE && !auto_disambiguation then
183 Lazy.force only_constant_choices
185 let choices = ref [] in
186 let chosen = ref false in
187 let use_only_constants = ref false in
189 GWindow.dialog ~modal:true ~title ~width:600 () in
191 GMisc.label ~text:msg
192 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
193 let scrolled_window =
194 GBin.scrolled_window ~border_width:10
195 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
197 let expected_height = 18 * List.length uris in
198 let height = if expected_height > 400 then 400 else expected_height in
199 GList.clist ~columns:1 ~packing:scrolled_window#add
200 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
201 let _ = List.map (function x -> clist#append [x]) uris in
203 GPack.hbox ~border_width:0
204 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
206 GMisc.label ~text:"None of the above. Try this one:"
207 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
209 GEdit.entry ~editable:true
210 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
212 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
214 GButton.button ~label:ok
215 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
216 let _ = okb#misc#set_sensitive false in
221 if enable_button_for_non_vars then
222 hbox#pack ~expand:false ~fill:false ~padding:5 w)
223 ~label:"Try constants only" () in
228 if enable_button_for_non_vars then
229 hbox#pack ~expand:false ~fill:false ~padding:5 w)
232 GButton.button ~label:"Check"
233 ~packing:(hbox#pack ~padding:5) () in
234 let _ = checkb#misc#set_sensitive false in
236 GButton.button ~label:"Abort"
237 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
239 let check_callback () =
240 assert (List.length !choices > 0) ;
241 check_window !choices
243 ignore (window#connect#destroy GMain.Main.quit) ;
244 ignore (cancelb#connect#clicked window#destroy) ;
246 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
248 (nonvarsb#connect#clicked
250 use_only_constants := true ;
254 ignore (autob#connect#clicked (fun () ->
255 auto_disambiguation := true;
256 (rendering_window ())#set_auto_disambiguation true;
257 use_only_constants := true ;
260 ignore (checkb#connect#clicked check_callback) ;
262 (clist#connect#select_row
263 (fun ~row ~column ~event ->
264 checkb#misc#set_sensitive true ;
265 okb#misc#set_sensitive true ;
266 choices := (List.nth uris row)::!choices)) ;
268 (clist#connect#unselect_row
269 (fun ~row ~column ~event ->
271 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
273 (manual_input#connect#changed
275 if manual_input#text = "" then
278 checkb#misc#set_sensitive false ;
279 okb#misc#set_sensitive false ;
280 clist#misc#set_sensitive true
284 choices := [manual_input#text] ;
285 clist#unselect_all () ;
286 checkb#misc#set_sensitive true ;
287 okb#misc#set_sensitive true ;
288 clist#misc#set_sensitive false
290 window#set_position `CENTER ;
294 if !use_only_constants then
295 Lazy.force only_constant_choices
297 if List.length !choices > 0 then !choices else raise NoChoice
303 let interactive_interpretation_choice interpretations =
304 let chosen = ref None in
307 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
308 let vbox = GPack.vbox ~packing:window#add () in
312 ("Ambiguous input since there are many well-typed interpretations." ^
313 " Please, choose one of them.")
314 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
316 GPack.notebook ~scrollable:true
317 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
320 (function interpretation ->
322 let expected_height = 18 * List.length interpretation in
323 let height = if expected_height > 400 then 400 else expected_height in
324 GList.clist ~columns:2 ~packing:notebook#append_page ~height
325 ~titles:["id" ; "URI"] ()
329 (function (id,uri) ->
330 let n = clist#append [id;uri] in
331 clist#set_row ~selectable:false n
334 clist#columns_autosize ()
337 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
339 GButton.button ~label:"Ok"
340 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
342 GButton.button ~label:"Abort"
343 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
345 ignore (window#connect#destroy GMain.Main.quit) ;
346 ignore (cancelb#connect#clicked window#destroy) ;
349 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
350 window#set_position `CENTER ;
354 None -> raise NoChoice
362 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
365 let struri = UriManager.string_of_uri uri in
366 let idx = (String.rindex struri '/') + 1 in
367 String.sub struri idx (String.length struri - idx)
369 let path = pathname ^ "/" ^ name in
371 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
375 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
376 ~ask_dtd_to_the_getter:false
379 let innertypesuri = UriManager.innertypesuri_of_uri uri in
380 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
381 Http_getter.register' innertypesuri
382 (Helm_registry.get "local_library.url" ^
383 Str.replace_first (Str.regexp "^cic:") ""
384 (UriManager.string_of_uri innertypesuri) ^ ".xml"
386 (* constant type / variable / mutual inductive types definition *)
387 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
388 Http_getter.register' uri
389 (Helm_registry.get "local_library.url" ^
390 Str.replace_first (Str.regexp "^cic:") ""
391 (UriManager.string_of_uri uri) ^ ".xml"
398 match UriManager.bodyuri_of_uri uri with
400 | Some bodyuri -> bodyuri
402 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
403 Http_getter.register' bodyuri
404 (Helm_registry.get "local_library.url" ^
405 Str.replace_first (Str.regexp "^cic:") ""
406 (UriManager.string_of_uri bodyuri) ^ ".xml"
413 exception OpenConjecturesStillThere;;
414 exception WrongProof;;
416 let pathname_of_annuri uristring =
417 Helm_registry.get "local_library.dir" ^
418 Str.replace_first (Str.regexp "^cic:") "" uristring
421 let make_dirs dirpath =
422 ignore (Unix.system ("mkdir -p " ^ dirpath))
425 let save_obj uri obj =
427 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
428 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
430 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
432 (* let's save the theorem and register it to the getter *)
433 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
435 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
440 match ProofEngine.get_proof () with
442 | Some (uri,[],bo,ty) ->
443 let uri = match uri with Some uri -> uri | _ -> assert false in
444 (* we want to typecheck in the ENV *)
445 prerr_endline "-------------> QED";
447 CicTypeChecker.type_of_aux' [] [] bo CicUniv.empty_ugraph in
448 let b,u1 = CicReduction.are_convertible [] ty_bo ty u in
451 (*CSC: Wrong: [] is just plainly wrong *)
453 Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
454 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
455 (rendering_window ())#output#load_proof uri proof
457 !qed_set_sensitive false ;
458 (* let's save the theorem and register it to the getter *)
460 pathname_of_annuri (UriManager.buri_of_uri uri)
462 let list_of_universes =
463 CicUnivUtils.universes_of_obj uri (Cic.Constant ("",None,ty,[]))
465 let u1_clean = CicUniv.clean_ugraph u1 list_of_universes in
466 let u2 = CicUniv.fill_empty_nodes_with_uri u1_clean uri in
467 (**********************************************
468 TASSI: to uncomment whe universes will be ON
469 ***********************************************)
472 save_object_to_disk uri acic ids_to_inner_sorts
473 ids_to_inner_types pathname;
475 (* save the universe graph u2 *)
476 (* add the object to the env *)
477 CicEnvironment.add_type_checked_term uri ((
478 Cic.Constant ((UriManager.name_of_uri uri),
479 (Some bo),ty,[])),u2);
480 (* FIXME: the variable list!! *)
481 prerr_endline "-------------> FINE";
485 | _ -> raise OpenConjecturesStillThere
488 (** save an unfinished proof on the filesystem *)
489 let save_unfinished_proof () =
490 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
491 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
492 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
493 Xml.pp ~quiet:true xml (Some proof_file_type) ;
495 (`Msg (`T ("Current proof type saved to " ^ proof_file_type))) ;
496 Xml.pp ~quiet:true bodyxml (Some proof_file) ;
498 (`Msg (`T ("Current proof body saved to " ^ proof_file)))
501 (* Used to typecheck the loaded proofs *)
502 let typecheck_loaded_proof metasenv bo ty =
503 let module T = CicTypeChecker in
506 (fun metasenv ((_,context,ty) as conj) ->
507 ignore (T.type_of_aux' metasenv context ty CicUniv.empty_ugraph) ;
510 ignore (T.type_of_aux' metasenv [] ty CicUniv.empty_ugraph) ;
511 ignore (T.type_of_aux' metasenv [] bo CicUniv.empty_ugraph)
514 let decompose_uris_choice_callback uris =
515 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
516 let module U = UriManager in
519 match CicUtil.term_of_uri uri with
520 | Cic.MutInd (uri, typeno, _) -> (uri, typeno, [])
522 (interactive_user_uri_choice
523 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
524 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
526 (function (uri,typeno,_) ->
527 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
532 let mk_fresh_name_callback metasenv context name ~typ =
534 match FreshNamesGenerator.mk_fresh_name ~subst:[] metasenv context name ~typ with
535 Cic.Name fresh_name -> fresh_name
536 | Cic.Anonymous -> assert false
539 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
540 ("Enter a fresh name for the hypothesis " ^
542 (List.map (function None -> None | Some (n,_) -> Some n) context))
544 Some fresh_name' -> Cic.Name fresh_name'
545 | None -> raise NoChoice
548 let refresh_proof (output : TermViewer.proof_viewer) =
550 let uri,currentproof =
551 match ProofEngine.get_proof () with
553 | Some (uri,metasenv,bo,ty) ->
554 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
555 if List.length metasenv = 0 then
557 !qed_set_sensitive true ;
562 (*CSC: Wrong: [] is just plainly wrong *)
563 let uri = match uri with Some uri -> uri | _ -> assert false in
565 Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
567 ignore (output#load_proof uri currentproof)
570 match ProofEngine.get_proof () with
572 | Some (uri,metasenv,bo,ty) ->
573 debug_print ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[])));
574 raise (InvokeTactics.RefreshProofException e)
576 let set_proof_engine_goal g =
577 ProofEngine.goal := g
580 let refresh_goals ?(empty_notebook=true) notebook =
582 match !ProofEngine.goal with
584 if empty_notebook then
586 notebook#remove_all_pages ~skip_switch_page_event:false ;
587 notebook#set_empty_page
590 notebook#proofw#unload
593 match ProofEngine.get_proof () with
595 | Some (_,metasenv,_,_) -> metasenv
598 List.find (function (m,_,_) -> m=metano) metasenv
600 let regenerate_notebook () =
601 let skip_switch_page_event =
603 (m,_,_)::_ when m = metano -> false
606 notebook#remove_all_pages ~skip_switch_page_event ;
607 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
609 if empty_notebook then
611 regenerate_notebook () ;
612 notebook#set_current_page
613 ~may_skip_switch_page_event:false metano
617 notebook#set_current_page
618 ~may_skip_switch_page_event:true metano ;
619 notebook#proofw#load_sequent metasenv currentsequent ;
624 match !ProofEngine.goal with
629 match ProofEngine.get_proof () with
631 | Some (_,metasenv,_,_) -> metasenv
634 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
636 ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent);
637 raise (InvokeTactics.RefreshSequentException e)
639 debug_print ("Offending sequent " ^ string_of_int metano ^ " unknown.");
640 raise (InvokeTactics.RefreshSequentException e)
642 module InvokeTacticsCallbacks =
644 let sequent_viewer () = (rendering_window ())#notebook#proofw
645 let term_editor () = (rendering_window ())#inputt
646 let scratch_window () = (rendering_window ())#scratch_window
648 let refresh_proof () =
649 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
652 let refresh_goals () =
653 let notebook = (rendering_window ())#notebook in
654 refresh_goals notebook
656 let decompose_uris_choice_callback = decompose_uris_choice_callback
657 let mk_fresh_name_callback = mk_fresh_name_callback
658 let mqi_handle = mqi_handle
662 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
664 (* Just to initialize the Hbugs module *)
665 module Ignore = Hbugs.Initialize (InvokeTactics');;
666 Hbugs.set_describe_hint_callback (fun hint ->
668 | Hbugs_types.Use_apply_Luke term -> check_window [term]
672 let dummy_uri = "/dummy.con"
674 (** load an unfinished proof from filesystem *)
675 let load_unfinished_proof () =
676 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
677 let notebook = (rendering_window ())#notebook in
680 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
683 None -> raise NoChoice
685 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
686 let proof_file_type = Helm_registry.get "gtoplevel.proof_file_type" in
687 let proof_file = Helm_registry.get "gtoplevel.proof_file" in
688 match CicParser.obj_of_xml proof_file_type (Some proof_file) with
689 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
690 typecheck_loaded_proof metasenv bo ty ;
691 ProofEngine.set_proof (Some (Some uri, metasenv, bo, ty));
692 refresh_proof output ;
693 set_proof_engine_goal
696 | (metano,_,_)::_ -> Some metano
698 refresh_goals notebook ;
700 (`Msg (`T ("Current proof type loaded from " ^ proof_file_type)));
702 (`Msg (`T ("Current proof body loaded from " ^ proof_file))) ;
703 !save_set_sensitive true;
706 InvokeTactics.RefreshSequentException e ->
708 (`Error (`T ("Exception raised during the refresh of the " ^
709 "sequent: " ^ Printexc.to_string e)))
710 | InvokeTactics.RefreshProofException e ->
712 (`Error (`T ("Exception raised during the refresh of the " ^
713 "proof: " ^ Printexc.to_string e)))
716 (`Error (`T (Printexc.to_string e)))
719 let clear_aliases () =
720 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
721 inputt#environment :=
722 DisambiguatingParser.EnvironmentP3.of_string
723 DisambiguatingParser.EnvironmentP3.empty
726 let edit_aliases () =
727 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
728 let disambiguation_env = inputt#environment in
729 let chosen_aliases = ref None in
732 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
734 GPack.vbox ~border_width:0 ~packing:window#add () in
735 let scrolled_window =
736 GBin.scrolled_window ~border_width:10
737 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
738 let input = GText.view ~editable:true ~width:400 ~height:100
739 ~packing:scrolled_window#add () in
741 GPack.hbox ~border_width:0
742 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
744 GButton.button ~label:"Ok"
745 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
747 GButton.button ~label:"Clear"
748 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
750 GButton.button ~label:"Cancel"
751 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
752 ignore (window#connect#destroy GMain.Main.quit) ;
753 ignore (cancelb#connect#clicked window#destroy) ;
754 ignore (clearb#connect#clicked (fun () ->
755 input#buffer#set_text DisambiguatingParser.EnvironmentP3.empty)) ;
756 ignore (okb#connect#clicked (fun () ->
757 chosen_aliases := Some (input#buffer#get_text ());
760 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
761 (DisambiguatingParser.EnvironmentP3.to_string !disambiguation_env ^ "\n"));
764 match !chosen_aliases with
766 | Some raw_aliases ->
767 let new_disambiguation_env =
769 DisambiguatingParser.EnvironmentP3.of_string raw_aliases
773 ("Error while parsing aliases: " ^ Printexc.to_string e)));
776 disambiguation_env := new_disambiguation_env
780 let module L = LogicalOperations in
781 let module G = Gdome in
782 let notebook = (rendering_window ())#notebook in
783 let output = (rendering_window ())#output in
785 output#make_sequent_of_selected_term ;
786 refresh_proof output ;
787 refresh_goals notebook
789 InvokeTactics.RefreshSequentException e ->
791 (`Error (`T ("Exception raised during the refresh of the " ^
792 "sequent: " ^ Printexc.to_string e)))
793 | InvokeTactics.RefreshProofException e ->
795 (`Error (`T ("Exception raised during the refresh of the " ^
796 "proof: " ^ Printexc.to_string e)))
799 (`Error (`T (Printexc.to_string e)))
803 let module L = LogicalOperations in
804 let module G = Gdome in
805 let notebook = (rendering_window ())#notebook in
806 let output = (rendering_window ())#output in
808 output#focus_sequent_of_selected_term ;
809 refresh_goals notebook
811 InvokeTactics.RefreshSequentException e ->
813 (`Error (`T ("Exception raised during the refresh of the " ^
814 "sequent: " ^ Printexc.to_string e)))
815 | InvokeTactics.RefreshProofException e ->
817 (`Error (`T ("Exception raised during the refresh of the " ^
818 "proof: " ^ Printexc.to_string e)))
821 (`Error (`T (Printexc.to_string e)))
824 exception NoPrevGoal;;
825 exception NoNextGoal;;
828 let module L = LogicalOperations in
829 let module G = Gdome in
830 let notebook = (rendering_window ())#notebook in
831 let output = (rendering_window ())#output in
833 match ProofEngine.get_proof () with
835 | Some (_,metasenv,_,_) -> metasenv
838 refresh_goals ~empty_notebook:false notebook
840 InvokeTactics.RefreshSequentException e ->
842 (`Error (`T ("Exception raised during the refresh of the " ^
843 "sequent: " ^ Printexc.to_string e)))
846 (`Error (`T (Printexc.to_string e)))
850 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
853 GWindow.window ~width:800 ~border_width:2 () in
854 let scrolled_window =
855 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
857 GMathViewAux.single_selection_math_view
858 ~packing:scrolled_window#add ~width:600 ~height:400 ()
860 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
861 let href = Gdome.domString "href" in
862 let show_in_show_window_obj uri obj =
865 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
866 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
868 Cic2acic.acic_object_of_cic_object obj
871 ChosenTransformer.mml_of_cic_object
872 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
874 window#set_title (UriManager.string_of_uri uri) ;
875 window#misc#hide () ; window#show () ;
876 mmlwidget#load_root mml#get_documentElement ;
880 (`Error (`T (Printexc.to_string e)))
882 let show_in_show_window_uri uri =
883 let obj,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
884 show_in_show_window_obj uri obj
886 let show_in_show_window_callback mmlwidget ((n : Gdome.element option),_,_,_) =
890 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
892 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
894 show_in_show_window_uri (UriManager.uri_of_string uri)
896 ignore (mmlwidget#action_toggle n')
899 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
901 show_in_show_window_obj, show_in_show_window_uri,
902 show_in_show_window_callback
905 exception NoObjectsLocated;;
907 let user_uri_choice ~title ~msg uris =
910 [] -> raise NoObjectsLocated
914 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
919 String.sub uri 4 (String.length uri - 4)
922 let locate_callback id =
923 let uris = MetadataQuery.locate ~dbd id in
924 HelmLogger.log (`Msg (`T ("Locate Query: " ^ id))) ;
925 HelmLogger.log (`Msg (`T "Result:")) ;
926 List.iter (fun uri -> HelmLogger.log (`Msg (`T uri))) uris;
927 user_uri_choice ~title:"Ambiguous input."
928 ~msg:(sprintf "Ambiguous input \"%s\". Please, choose one interpetation:" id)
933 let input_or_locate_uri ~title =
934 let uri = ref None in
937 ~width:400 ~modal:true ~title ~border_width:2 () in
938 let vbox = GPack.vbox ~packing:window#add () in
940 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
942 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
944 GEdit.entry ~editable:true
945 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
947 GButton.button ~label:"Check"
948 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
949 let _ = checkb#misc#set_sensitive false in
951 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
953 GMisc.label ~text:"You can also enter an indentifier to locate:"
954 ~packing:(hbox2#pack ~padding:5) () in
956 GEdit.entry ~editable:true
957 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
959 GButton.button ~label:"Locate"
960 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
961 let _ = locateb#misc#set_sensitive false in
963 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
965 GButton.button ~label:"Ok"
966 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
967 let _ = okb#misc#set_sensitive false in
969 GButton.button ~label:"Cancel"
970 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
972 ignore (window#connect#destroy GMain.Main.quit) ;
974 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
975 let check_callback () =
976 let uri = "cic:" ^ manual_input#text in
978 ignore (Http_getter.resolve' (UriManager.uri_of_string uri)) ;
979 HelmLogger.log (`Msg (`T "OK")) ;
982 Http_getter_types.Key_not_found _ ->
984 (`Error (`T ("URI " ^ uri ^
985 " does not correspond to any object."))) ;
987 | UriManager.IllFormedUri _ ->
989 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
993 (`Error (`T (Printexc.to_string e))) ;
999 if check_callback () then
1001 uri := Some manual_input#text ;
1005 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1007 (manual_input#connect#changed
1009 if manual_input#text = "" then
1011 checkb#misc#set_sensitive false ;
1012 okb#misc#set_sensitive false
1016 checkb#misc#set_sensitive true ;
1017 okb#misc#set_sensitive true
1020 (locate_input#connect#changed
1021 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1023 (locateb#connect#clicked
1025 let id = locate_input#text in
1026 manual_input#set_text (locate_callback id) ;
1027 locate_input#delete_text 0 (String.length id)
1032 None -> raise NoChoice
1033 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1036 exception AmbiguousInput;;
1038 (* A WIDGET TO ENTER CIC TERMS *)
1040 module DisambiguateCallbacks =
1042 let interactive_user_uri_choice =
1043 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1044 interactive_user_uri_choice ~selection_mode ?ok
1045 ?enable_button_for_non_vars ~title ~msg
1046 let interactive_interpretation_choice = interactive_interpretation_choice
1047 let input_or_locate_uri ~title ?id () = input_or_locate_uri ~title
1051 module TermEditor' = ChosenTermEditor.Make (DisambiguateCallbacks);;
1053 (* OTHER FUNCTIONS *)
1056 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1059 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1061 None -> raise NoChoice
1063 let uri = locate_callback input in
1068 (`Error (`T (Printexc.to_string e)))
1072 exception UriAlreadyInUse;;
1073 exception NotAUriToAConstant;;
1075 let new_inductive () =
1076 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1077 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1078 let notebook = (rendering_window ())#notebook in
1080 let chosen = ref false in
1081 let inductive = ref true in
1082 let paramsno = ref 0 in
1083 let get_uri = ref (function _ -> assert false) in
1084 let get_base_uri = ref (function _ -> assert false) in
1085 let get_names = ref (function _ -> assert false) in
1086 let get_types_and_cons = ref (function _ -> assert false) in
1087 let get_context_and_subst = ref (function _ -> assert false) in
1090 ~width:600 ~modal:true ~position:`CENTER
1091 ~title:"New Block of Mutual (Co)Inductive Definitions"
1092 ~border_width:2 () in
1093 let vbox = GPack.vbox ~packing:window#add () in
1095 GPack.hbox ~border_width:0
1096 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1098 GMisc.label ~text:"Enter the URI for the new block:"
1099 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1101 GEdit.entry ~editable:true
1102 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1104 GPack.hbox ~border_width:0
1105 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1109 "Enter the number of left parameters in every arity and constructor type:"
1110 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1111 let paramsno_entry =
1112 GEdit.entry ~editable:true ~text:"0"
1113 ~packing:(hbox0#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
1118 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1119 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1121 GButton.radio_button ~label:"Inductive"
1122 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1124 GButton.radio_button ~label:"Coinductive"
1125 ~group:inductiveb#group
1126 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1128 GPack.hbox ~border_width:0
1129 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1131 GMisc.label ~text:"Enter the list of the names of the types:"
1132 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1134 GEdit.entry ~editable:true
1135 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1137 GPack.hbox ~border_width:0
1138 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1140 GButton.button ~label:"> Next"
1141 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1142 let _ = okb#misc#set_sensitive true in
1144 GButton.button ~label:"Abort"
1145 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1146 ignore (window#connect#destroy GMain.Main.quit) ;
1147 ignore (cancelb#connect#clicked window#destroy) ;
1151 (okb#connect#clicked
1154 let uristr = "cic:" ^ uri_entry#text in
1155 let namesstr = names_entry#text in
1156 let paramsno' = int_of_string (paramsno_entry#text) in
1157 match Str.split (Str.regexp " +") namesstr with
1159 | (he::tl) as names ->
1160 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1163 ignore (Http_getter.resolve' uri) ;
1164 raise UriAlreadyInUse
1165 with Http_getter_types.Key_not_found _ ->
1166 get_uri := (function () -> uri) ;
1167 get_names := (function () -> names) ;
1168 inductive := inductiveb#active ;
1169 paramsno := paramsno' ;
1175 (`Error (`T (Printexc.to_string e)))
1183 GBin.frame ~label:name
1184 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1185 let vbox = GPack.vbox ~packing:frame#add () in
1186 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1188 GMisc.label ~text:("Enter its type:")
1189 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1190 let scrolled_window =
1191 GBin.scrolled_window ~border_width:5
1192 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1194 TermEditor'.term_editor
1196 ~width:400 ~height:20 ~packing:scrolled_window#add
1197 ~share_environment_with:inputt ()
1198 ~isnotempty_callback:
1200 (*non_empty_type := b ;*)
1201 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1204 GPack.hbox ~border_width:0
1205 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1207 GMisc.label ~text:("Enter the list of its constructors:")
1208 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1209 let cons_names_entry =
1210 GEdit.entry ~editable:true
1211 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1212 (newinputt,cons_names_entry)
1215 vbox#remove hboxn#coerce ;
1217 GPack.hbox ~border_width:0
1218 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1220 GButton.button ~label:"> Next"
1221 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1223 GButton.button ~label:"Abort"
1224 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1225 ignore (cancelb#connect#clicked window#destroy) ;
1227 (okb#connect#clicked
1230 let names = !get_names () in
1231 let types_and_cons =
1233 (fun name (newinputt,cons_names_entry) ->
1234 let consnamesstr = cons_names_entry#text in
1235 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1236 let metasenv,expr,ugraph =
1237 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1240 [] -> expr,cons_names
1241 | _ -> raise AmbiguousInput
1242 ) names type_widgets
1244 let uri = !get_uri () in
1246 (* Let's see if so far the definition is well-typed *)
1249 (* To test if the arities of the inductive types are well *)
1250 (* typed, we check the inductive block definition where *)
1251 (* no constructor is given to each type. *)
1254 (fun name (ty,cons) -> (name, !inductive, ty, []))
1255 names types_and_cons
1257 CicTypeChecker.typecheck_mutual_inductive_defs uri
1258 (tys,params,paramsno)
1260 get_context_and_subst :=
1264 (fun (context,subst) name (ty,_) ->
1266 (Some (Cic.Name name, Cic.Decl ty))::context,
1267 (Cic.MutInd (uri,!i,[]))::subst
1270 ) ([],[]) names types_and_cons) ;
1271 let types_and_cons' =
1273 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1274 names types_and_cons
1276 get_types_and_cons := (function () -> types_and_cons') ;
1282 (`Error (`T (Printexc.to_string e)))
1285 and phase3 name cons =
1286 let get_cons_types = ref (function () -> assert false) in
1289 ~width:600 ~modal:true ~position:`CENTER
1290 ~title:(name ^ " Constructors")
1291 ~border_width:2 () in
1292 let vbox = GPack.vbox ~packing:window2#add () in
1293 let cons_type_widgets =
1295 (function consname ->
1297 GPack.hbox ~border_width:0
1298 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1300 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1301 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1302 let scrolled_window =
1303 GBin.scrolled_window ~border_width:5
1304 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1306 TermEditor'.term_editor
1308 ~width:400 ~height:20 ~packing:scrolled_window#add
1309 ~share_environment_with:inputt ()
1310 ~isnotempty_callback:
1312 (* (*non_empty_type := b ;*)
1313 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1318 GPack.hbox ~border_width:0
1319 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1321 GButton.button ~label:"> Next"
1322 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1323 let _ = okb#misc#set_sensitive true in
1325 GButton.button ~label:"Abort"
1326 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1327 ignore (window2#connect#destroy GMain.Main.quit) ;
1328 ignore (cancelb#connect#clicked window2#destroy) ;
1330 (okb#connect#clicked
1334 let context,subst= !get_context_and_subst () in
1338 let metasenv,expr,ugraph =
1339 inputt#get_metasenv_and_term ~context ~metasenv:[]
1343 let undebrujined_expr =
1345 (fun expr t -> CicSubstitution.subst t expr) expr subst
1347 name, undebrujined_expr
1348 | _ -> raise AmbiguousInput
1349 ) cons cons_type_widgets
1351 get_cons_types := (function () -> cons_types) ;
1356 (`Error (`T (Printexc.to_string e)))
1360 let okb_pressed = !chosen in
1362 if (not okb_pressed) then
1365 assert false (* The control never reaches this point *)
1368 (!get_cons_types ())
1371 (* No more phases left or Abort pressed *)
1377 let uri = !get_uri () in
1380 let tys = !get_types_and_cons () in
1381 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1385 debug_print (CicPp.ppobj obj);
1386 CicTypeChecker.typecheck_mutual_inductive_defs uri
1387 (tys,params,!paramsno) CicUniv.empty_ugraph
1390 debug_print "Offending mutual (co)inductive type declaration:" ;
1391 debug_print (CicPp.ppobj obj) ;
1392 (* I think we should fail here! *)
1393 CicUniv.empty_ugraph
1396 (* We already know that obj is well-typed. We need to add it to the *)
1397 (* environment in order to compute the inner-types without having to *)
1398 (* debrujin it or having to modify lots of other functions to avoid *)
1399 (* asking the environment for the MUTINDs we are defining now. *)
1401 (* u should be cleaned before adding it to the env *)
1402 CicEnvironment.put_inductive_definition uri (obj,u) ;
1404 (* TASSI: FIXME we should save the cleaned u here *)
1405 show_in_show_window_obj uri obj
1409 (`Error (`T (Printexc.to_string e)))
1413 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1414 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1415 let notebook = (rendering_window ())#notebook in
1417 let chosen = ref false in
1418 let get_metasenv_and_term = ref (function _ -> assert false) in
1419 let get_uri = ref (function _ -> assert false) in
1420 let non_empty_type = ref false in
1423 ~width:600 ~modal:true ~title:"New Proof or Definition"
1424 ~border_width:2 () in
1425 let vbox = GPack.vbox ~packing:window#add () in
1427 GPack.hbox ~border_width:0
1428 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1430 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1431 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1433 GEdit.entry ~editable:true
1434 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1435 uri_entry#set_text dummy_uri;
1436 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1438 GPack.hbox ~border_width:0
1439 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1441 GMisc.label ~text:"Enter the theorem or definition type:"
1442 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1443 let scrolled_window =
1444 GBin.scrolled_window ~border_width:5
1445 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1446 (* the content of the scrolled_window is moved below (see comment) *)
1448 GPack.hbox ~border_width:0
1449 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1451 GButton.button ~label:"Ok"
1452 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1453 let _ = okb#misc#set_sensitive false in
1455 GButton.button ~label:"Cancel"
1456 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1457 (* moved here to have visibility of the ok button *)
1459 TermEditor'.term_editor
1461 ~width:400 ~height:100 ~packing:scrolled_window#add
1462 ~share_environment_with:inputt ()
1463 ~isnotempty_callback:
1465 non_empty_type := b ;
1466 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1469 newinputt#set_term inputt#get_as_string ;
1472 uri_entry#connect#changed
1474 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1476 ignore (window#connect#destroy GMain.Main.quit) ;
1477 ignore (cancelb#connect#clicked window#destroy) ;
1479 (okb#connect#clicked
1483 let metasenv,parsed,ugraph = newinputt#get_metasenv_and_term [] [] in
1484 let uristr = "cic:" ^ uri_entry#text in
1485 let uri = UriManager.uri_of_string uristr in
1486 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1487 raise NotAUriToAConstant
1491 ignore (Http_getter.resolve' uri) ;
1492 raise UriAlreadyInUse
1493 with Http_getter_types.Key_not_found _ ->
1494 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1495 get_uri := (function () -> uri) ;
1501 (`Error (`T (Printexc.to_string e)))
1507 let metasenv,expr = !get_metasenv_and_term () in
1508 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1509 ProofEngine.set_proof
1510 (Some (Some (!get_uri ()), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr));
1511 set_proof_engine_goal (Some 1) ;
1512 refresh_goals notebook ;
1513 refresh_proof output ;
1514 !save_set_sensitive true ;
1516 ProofEngine.intros ~mk_fresh_name_callback () ;
1517 refresh_goals notebook ;
1518 refresh_proof output
1520 InvokeTactics.RefreshSequentException e ->
1522 (`Error (`T ("Exception raised during the refresh of the " ^
1523 "sequent: " ^ Printexc.to_string e)))
1524 | InvokeTactics.RefreshProofException e ->
1526 (`Error (`T ("Exception raised during the refresh of the " ^
1527 "proof: " ^ Printexc.to_string e)))
1530 (`Error (`T (Printexc.to_string e)))
1533 let check_term_in_scratch scratch_window metasenv context expr =
1536 CicTypeChecker.type_of_aux' metasenv context expr CicUniv.empty_ugraph
1538 let expr = Cic.Cast (expr,ty) in
1539 scratch_window#show () ;
1540 scratch_window#set_term expr ;
1541 scratch_window#set_context context ;
1542 scratch_window#set_metasenv metasenv ;
1543 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1546 print_endline ("? " ^ CicPp.ppterm expr) ;
1550 let check scratch_window () =
1551 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1553 match ProofEngine.get_proof () with
1555 | Some (_,metasenv,_,_) -> metasenv
1558 match !ProofEngine.goal with
1561 let (_,canonical_context,_) =
1562 List.find (function (m,_,_) -> m=metano) metasenv
1567 let metasenv',expr,ugraph =
1568 inputt#get_metasenv_and_term context metasenv
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 ignore(CicTypeChecker.typecheck uri CicUniv.empty_ugraph);
1594 (* TASSI: typecheck mette la uri nell'env... cosa fa la open_ ?*)
1595 let metasenv,bo,ty =
1596 match fst(CicEnvironment.get_cooked_obj CicUniv.empty_ugraph uri ) with
1597 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1598 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1601 | Cic.InductiveDefinition _ -> raise NotADefinition
1603 ProofEngine.set_proof (Some (Some uri, metasenv, bo, ty)) ;
1604 set_proof_engine_goal None ;
1605 refresh_goals notebook ;
1606 refresh_proof output ;
1607 !save_set_sensitive true
1609 InvokeTactics.RefreshSequentException e ->
1611 (`Error (`T ("Exception raised during the refresh of the " ^
1612 "sequent: " ^ Printexc.to_string e)))
1613 | InvokeTactics.RefreshProofException e ->
1615 (`Error (`T ("Exception raised during the refresh of the " ^
1616 "proof: " ^ Printexc.to_string e)))
1619 (`Error (`T (Printexc.to_string e)))
1622 let show_query_results results =
1625 ~modal:false ~title:"Query results." ~border_width:2 () in
1626 let vbox = GPack.vbox ~packing:window#add () in
1628 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1631 ~text:"Click on a URI to show that object"
1632 ~packing:hbox#add () in
1633 let scrolled_window =
1634 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1635 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1636 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1639 (function (uri,_) ->
1643 clist#set_row ~selectable:false n
1646 clist#columns_autosize () ;
1648 (clist#connect#select_row
1649 (fun ~row ~column ~event ->
1650 let (uristr,_) = List.nth results row in
1651 match CicUtil.term_of_uri uristr with
1652 | Cic.Const (uri, _)
1654 | Cic.MutInd (uri, _, _)
1655 | Cic.MutConstruct (uri, _, _, _) ->
1656 show_in_show_window_uri uri
1663 let refine_constraints (must_obj,must_rel,must_sort) =
1664 let chosen = ref false in
1665 let use_only = ref false in
1668 ~modal:true ~title:"Constraints refinement."
1669 ~width:800 ~border_width:2 () in
1670 let vbox = GPack.vbox ~packing:window#add () in
1672 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1675 ~text: "\"Only\" constraints can be enforced or not."
1676 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1678 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1679 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1682 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1683 (* Notebook for the constraints choice *)
1685 GPack.notebook ~scrollable:true
1686 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1687 (* Rel constraints *)
1690 ~text: "Constraints on Rels" () in
1692 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1695 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1698 ~text: "You can now specify the constraints on Rels."
1699 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1700 let expected_height = 25 * (List.length must_rel + 2) in
1701 let height = if expected_height > 400 then 400 else expected_height in
1702 let scrolled_window =
1703 GBin.scrolled_window ~border_width:10 ~height ~width:600
1704 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1705 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1706 let mk_depth_button (hbox:GPack.box) d =
1707 let mutable_ref = ref (Some d) in
1709 GButton.toggle_button
1710 ~label:("depth = " ^ string_of_int d)
1712 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1715 (depthb#connect#toggled
1717 let sel_depth = if depthb#active then Some d else None in
1718 mutable_ref := sel_depth
1721 let rel_constraints =
1726 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1729 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1730 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1732 | `MainHypothesis None
1733 | `MainConclusion None -> p, ref None
1734 | `MainHypothesis (Some depth')
1735 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1737 (* Sort constraints *)
1740 ~text: "Constraints on Sorts" () in
1742 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1745 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1748 ~text: "You can now specify the constraints on Sorts."
1749 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1750 let expected_height = 25 * (List.length must_sort + 2) in
1751 let height = if expected_height > 400 then 400 else expected_height in
1752 let scrolled_window =
1753 GBin.scrolled_window ~border_width:10 ~height ~width:600
1754 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1755 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1756 let sort_constraints =
1758 (function (p, sort) ->
1761 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1764 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1765 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1767 | `MainHypothesis None
1768 | `MainConclusion None -> p, ref None, sort
1769 | `MainHypothesis (Some depth')
1770 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1772 (* Obj constraints *)
1775 ~text: "Constraints on constants" () in
1777 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1780 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1783 ~text: "You can now specify the constraints on constants."
1784 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1785 let expected_height = 25 * (List.length must_obj + 2) in
1786 let height = if expected_height > 400 then 400 else expected_height in
1787 let scrolled_window =
1788 GBin.scrolled_window ~border_width:10 ~height ~width:600
1789 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1790 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1791 let obj_constraints =
1793 (function (p, uri) ->
1796 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1799 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1800 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1805 | `MainHypothesis None
1806 | `MainConclusion None -> p, ref None, uri
1807 | `MainHypothesis (Some depth')
1808 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1810 (* Confirm/abort buttons *)
1812 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1814 GButton.button ~label:"Ok"
1815 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1817 GButton.button ~label:"Abort"
1818 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1820 ignore (window#connect#destroy GMain.Main.quit) ;
1821 ignore (cancelb#connect#clicked window#destroy) ;
1823 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1824 window#set_position `CENTER ;
1828 let chosen_must_rel =
1830 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1833 let chosen_must_sort =
1835 (function (position, ref_depth, sort) ->
1836 MQGU.set_main_position position !ref_depth,sort)
1839 let chosen_must_obj =
1841 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1844 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1846 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1847 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1855 let completeSearchPattern () =
1856 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1858 let metasenv,expr,ugraph =
1859 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
2076 let uris' = List.map fst (MetadataQuery.hint ~dbd (proof, metano)) in
2078 user_uri_choice ~title:"Ambiguous input."
2079 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2082 inputt#set_term uri' ;
2083 InvokeTactics'.apply ()
2087 (`Error (`T (Printexc.to_string e)))
2090 let choose_selection mmlwidget (element : Gdome.element option) =
2091 let module G = Gdome in
2092 let rec aux element =
2093 if element#hasAttributeNS
2094 ~namespaceURI:Misc.helmns
2095 ~localName:(G.domString "xref")
2097 mmlwidget#set_selection (Some element)
2100 match element#get_parentNode with
2101 None -> assert false
2102 (*CSC: OCAML DIVERGES!
2103 | Some p -> aux (new G.element_of_node p)
2105 | Some p -> aux (new Gdome.element_of_node p)
2107 GdomeInit.DOMCastException _ ->
2109 "******* trying to select above the document root ********"
2113 | None -> mmlwidget#set_selection None
2116 (* STUFF TO BUILD THE GTK INTERFACE *)
2118 (* Stuff for the widget settings *)
2121 let export_to_postscript output =
2122 let lastdir = ref (Unix.getcwd ()) in
2125 GToolbox.select_file ~title:"Export to PostScript"
2126 ~dir:lastdir ~filename:"screenshot.ps" ()
2130 (output :> GMathView.math_view)#export_to_postscript
2131 ~filename:filename ();
2136 let activate_t1 output button_set_anti_aliasing
2137 button_set_transparency export_to_postscript_menu_item
2140 let is_set = button_t1#active in
2141 output#set_font_manager_type
2142 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2145 button_set_anti_aliasing#misc#set_sensitive true ;
2146 button_set_transparency#misc#set_sensitive true ;
2147 export_to_postscript_menu_item#misc#set_sensitive true ;
2151 button_set_anti_aliasing#misc#set_sensitive false ;
2152 button_set_transparency#misc#set_sensitive false ;
2153 export_to_postscript_menu_item#misc#set_sensitive false ;
2157 let set_anti_aliasing output button_set_anti_aliasing () =
2158 output#set_anti_aliasing button_set_anti_aliasing#active
2161 let set_transparency output button_set_transparency () =
2162 output#set_transparency button_set_transparency#active
2166 let changefont output font_size_spinb () =
2167 output#set_font_size font_size_spinb#value_as_int
2170 let set_log_verbosity output log_verbosity_spinb () =
2171 output#set_log_verbosity log_verbosity_spinb#value_as_int
2174 class settings_window output sw
2175 export_to_postscript_menu_item selection_changed_callback
2177 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2179 GPack.vbox ~packing:settings_window#add () in
2182 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2183 ~border_width:5 ~packing:vbox#add () in
2185 GButton.toggle_button ~label:"activate t1 fonts"
2186 ~packing:(table#attach ~left:0 ~top:0) () in
2187 let button_set_anti_aliasing =
2188 GButton.toggle_button ~label:"set_anti_aliasing"
2189 ~packing:(table#attach ~left:0 ~top:1) () in
2190 let button_set_transparency =
2191 GButton.toggle_button ~label:"set_transparency"
2192 ~packing:(table#attach ~left:2 ~top:1) () in
2195 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2196 ~border_width:5 ~packing:vbox#add () in
2197 let font_size_label =
2198 GMisc.label ~text:"font size:"
2199 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2200 let font_size_spinb =
2202 GData.adjustment ~value:(float_of_int output#get_font_size)
2203 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2206 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2207 let log_verbosity_label =
2208 GMisc.label ~text:"log verbosity:"
2209 ~packing:(table#attach ~left:0 ~top:1) () in
2210 let log_verbosity_spinb =
2212 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2215 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2217 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2219 GButton.button ~label:"Close"
2220 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2222 method show = settings_window#show
2224 button_set_anti_aliasing#misc#set_sensitive false ;
2225 button_set_transparency#misc#set_sensitive false ;
2226 (* Signals connection *)
2228 ignore(button_t1#connect#clicked
2229 (activate_t1 output button_set_anti_aliasing
2230 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2232 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2234 ignore(button_set_anti_aliasing#connect#toggled
2235 (set_anti_aliasing output button_set_anti_aliasing));
2236 ignore(button_set_transparency#connect#toggled
2237 (set_transparency output button_set_transparency)) ;
2239 ignore(log_verbosity_spinb#connect#changed
2240 (set_log_verbosity output log_verbosity_spinb)) ;
2241 ignore(closeb#connect#clicked settings_window#misc#hide)
2244 (* Scratch window *)
2246 class scratch_window =
2249 ~title:"MathML viewer"
2250 ~border_width:2 () in
2252 GPack.vbox ~packing:window#add () in
2254 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2256 GButton.button ~label:"Whd"
2257 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2259 GButton.button ~label:"Reduce"
2260 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2262 GButton.button ~label:"Simpl"
2263 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2264 let scrolled_window =
2265 GBin.scrolled_window ~border_width:10
2266 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2267 let sequent_viewer =
2268 TermViewer.sequent_viewer
2269 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2270 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2272 val mutable term = Cic.Rel 1 (* dummy value *)
2273 val mutable context = ([] : Cic.context) (* dummy value *)
2274 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2275 method sequent_viewer = sequent_viewer
2276 method show () = window#misc#hide () ; window#show ()
2278 method set_term t = term <- t
2279 method context = context
2280 method set_context t = context <- t
2281 method metasenv = metasenv
2282 method set_metasenv t = metasenv <- t
2285 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2286 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2287 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2288 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2289 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2292 let open_contextual_menu_for_selected_terms mmlwidget infos =
2293 let button = GdkEvent.Button.button infos in
2294 let terms_selected = List.length mmlwidget#get_selections > 0 in
2297 let time = GdkEvent.Button.time infos in
2298 let menu = GMenu.menu () in
2299 let f = new GMenu.factory menu in
2301 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2302 let reduce_menu_item =
2303 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2304 let simpl_menu_item =
2305 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2306 let _ = f#add_separator () in
2307 let generalize_menu_item =
2308 f#add_item "Generalize"
2309 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2310 let _ = f#add_separator () in
2311 let clear_menu_item =
2312 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2313 let clearbody_menu_item =
2314 f#add_item "ClearBody"
2315 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2317 whd_menu_item#misc#set_sensitive terms_selected ;
2318 reduce_menu_item#misc#set_sensitive terms_selected ;
2319 simpl_menu_item#misc#set_sensitive terms_selected ;
2320 generalize_menu_item#misc#set_sensitive terms_selected ;
2321 clear_menu_item#misc#set_sensitive terms_selected ;
2322 clearbody_menu_item#misc#set_sensitive terms_selected ;
2323 menu#popup ~button ~time
2329 let vbox1 = GPack.vbox () in
2331 val mutable proofw_ref = None
2332 val mutable compute_ref = None
2334 Lazy.force self#compute ;
2335 match proofw_ref with
2336 None -> assert false
2337 | Some proofw -> proofw
2338 method content = vbox1
2340 match compute_ref with
2341 None -> assert false
2342 | Some compute -> compute
2346 let scrolled_window1 =
2347 GBin.scrolled_window ~border_width:10
2348 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2350 TermViewer.sequent_viewer
2351 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2352 ~width:400 ~height:275 ~packing:(scrolled_window1#add) () in
2353 let _ = proofw_ref <- Some proofw in
2355 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2357 GButton.button ~label:"Ring"
2358 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2360 GButton.button ~label:"Fourier"
2361 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2363 GButton.button ~label:"Reflexivity"
2364 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2366 GButton.button ~label:"Symmetry"
2367 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2369 GButton.button ~label:"Assumption"
2370 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2371 let contradictionb =
2372 GButton.button ~label:"Contradiction"
2373 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2375 GButton.button ~label:"Auto"
2376 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2378 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2380 GButton.button ~label:"Exists"
2381 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2383 GButton.button ~label:"Split"
2384 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2386 GButton.button ~label:"Left"
2387 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2389 GButton.button ~label:"Right"
2390 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2391 let searchpatternb =
2392 GButton.button ~label:"SearchPattern_Apply"
2393 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2395 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2397 GButton.button ~label:"Exact"
2398 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2400 GButton.button ~label:"Intros"
2401 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2403 GButton.button ~label:"Apply"
2404 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2405 let elimintrossimplb =
2406 GButton.button ~label:"ElimIntrosSimpl"
2407 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2409 GButton.button ~label:"ElimType"
2410 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2412 GButton.button ~label:"Fold_whd"
2413 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2415 GButton.button ~label:"Fold_reduce"
2416 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2418 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2420 GButton.button ~label:"Fold_simpl"
2421 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2423 GButton.button ~label:"Cut"
2424 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2426 GButton.button ~label:"Change"
2427 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2429 GButton.button ~label:"Let ... In"
2430 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2432 GButton.button ~label:"RewriteSimpl ->"
2433 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2434 let rewritebacksimplb =
2435 GButton.button ~label:"RewriteSimpl <-"
2436 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2438 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2440 GButton.button ~label:"Absurd"
2441 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2443 GButton.button ~label:"Decompose"
2444 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2446 GButton.button ~label:"Transitivity"
2447 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2449 GButton.button ~label:"Replace"
2450 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2452 GButton.button ~label:"Injection"
2453 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2455 GButton.button ~label:"Discriminate"
2456 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2457 (* Zack: spostare in una toolbar
2459 GButton.button ~label:"Generalize"
2460 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2462 GButton.button ~label:"ClearBody"
2463 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2465 GButton.button ~label:"Clear"
2466 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2468 GButton.button ~label:"Whd"
2469 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2471 GButton.button ~label:"Reduce"
2472 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2474 GButton.button ~label:"Simpl"
2475 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2478 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2479 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2480 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2481 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2482 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2483 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2484 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2485 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2486 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2487 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2488 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2489 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2490 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2491 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2492 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2493 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2494 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2495 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2496 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2497 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2498 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2499 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2500 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2501 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2502 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2503 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2504 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2505 ignore(searchpatternb#connect#clicked searchPattern) ;
2506 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2507 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2508 ignore(autob#connect#clicked InvokeTactics'.auto) ;
2509 (* Zack: spostare in una toolbar
2510 ignore(whdb#connect#clicked whd) ;
2511 ignore(reduceb#connect#clicked reduce) ;
2512 ignore(simplb#connect#clicked simpl) ;
2513 ignore(clearbodyb#connect#clicked clearbody) ;
2514 ignore(clearb#connect#clicked clear) ;
2515 ignore(generalizeb#connect#clicked generalize) ;
2517 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2519 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2520 (open_contextual_menu_for_selected_terms proofw)) ;
2526 let vbox1 = GPack.vbox () in
2527 let scrolled_window1 =
2528 GBin.scrolled_window ~border_width:10
2529 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2531 TermViewer.sequent_viewer
2532 ~mml_of_cic_sequent:ChosenTransformer.mml_of_cic_sequent
2533 ~width:400 ~height:275 ~packing:(scrolled_window1#add) () in
2535 method proofw = (assert false : TermViewer.sequent_viewer)
2536 method content = vbox1
2537 method compute = (assert false : unit)
2541 let empty_page = new empty_page;;
2545 val notebook = GPack.notebook ()
2547 val mutable skip_switch_page_event = false
2548 val mutable empty = true
2549 method notebook = notebook
2551 let new_page = new page () in
2553 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2554 notebook#append_page
2555 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2556 new_page#content#coerce
2557 method remove_all_pages ~skip_switch_page_event:skip =
2559 notebook#remove_page 0 (* let's remove the empty page *)
2561 List.iter (function _ -> notebook#remove_page 0) !pages ;
2563 skip_switch_page_event <- skip
2564 method set_current_page ~may_skip_switch_page_event n =
2565 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2566 let new_page = notebook#page_num page#content#coerce in
2567 if may_skip_switch_page_event && new_page <> notebook#current_page then
2568 skip_switch_page_event <- true ;
2569 notebook#goto_page new_page
2570 method set_empty_page =
2573 notebook#append_page
2574 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2575 empty_page#content#coerce
2577 let (_,_,page) = List.nth !pages notebook#current_page in
2581 (notebook#connect#switch_page
2583 let skip = skip_switch_page_event in
2584 skip_switch_page_event <- false ;
2587 let (metano,setgoal,page) = List.nth !pages i in
2588 set_proof_engine_goal (Some metano) ;
2589 Lazy.force (page#compute) ;
2591 if notify_hbugs_on_goal_change then
2598 let dump_environment () =
2600 let oc = open_out (Helm_registry.get "gtoplevel.environment_file") in
2601 HelmLogger.log (`Msg (`T "Dumping environment ..."));
2602 CicEnvironment.dump_to_channel oc;
2603 HelmLogger.log (`Msg (`T "... done!")) ;
2607 (`Error (`T (Printf.sprintf "Dump failure, uncaught exception:%s"
2608 (Printexc.to_string exc))))
2610 let restore_environment () =
2612 let ic = open_in (Helm_registry.get "gtoplevel.environment_file") in
2613 HelmLogger.log (`Msg (`T "Restoring environment ... "));
2614 CicEnvironment.restore_from_channel ic;
2615 HelmLogger.log (`Msg (`T "... done!"));
2619 (`Error (`T (Printf.sprintf "Restore failure, uncaught exception:%s"
2620 (Printexc.to_string exc))))
2625 class rendering_window output (notebook : notebook) =
2626 let scratch_window = new scratch_window in
2629 ~title:"gTopLevel - Helm's Proof Assistant"
2630 ~border_width:0 ~allow_shrink:false () in
2631 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2633 let handle_box = GBin.handle_box ~border_width:2
2634 ~packing:(vbox_for_menu#pack ~padding:0) () in
2635 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2636 let factory0 = new GMenu.factory menubar in
2637 let accel_group = factory0#accel_group in
2639 let file_menu = factory0#add_submenu "File" in
2640 let factory1 = new GMenu.factory file_menu ~accel_group in
2641 (* let export_to_postscript_menu_item = *)
2645 factory1#add_item "New Block of (Co)Inductive Definitions..."
2646 ~key:GdkKeysyms._B ~callback:new_inductive
2649 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2652 let reopen_menu_item =
2653 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2657 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2658 ignore (factory1#add_separator ()) ;
2660 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2661 ~callback:load_unfinished_proof) ;
2662 let save_menu_item =
2663 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2664 ~callback:save_unfinished_proof
2666 ignore (factory1#add_separator ()) ;
2667 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2668 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2670 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2672 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2673 ignore (!save_set_sensitive false);
2674 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2675 ignore (!qed_set_sensitive false);
2676 ignore (factory1#add_separator ()) ;
2678 let export_to_postscript_menu_item =
2679 factory1#add_item "Export to PostScript..."
2680 ~callback:(export_to_postscript output) in
2682 ignore (factory1#add_separator ()) ;
2684 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2685 export_to_postscript_menu_item *)
2688 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2689 let factory2 = new GMenu.factory edit_menu ~accel_group in
2690 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2691 let proveit_menu_item =
2692 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2693 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2695 let focus_menu_item =
2696 factory2#add_item "Focus" ~key:GdkKeysyms._F
2697 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2700 focus_and_proveit_set_sensitive :=
2702 proveit_menu_item#misc#set_sensitive b ;
2703 focus_menu_item#misc#set_sensitive b
2705 let _ = !focus_and_proveit_set_sensitive false in
2706 (* edit term menu *)
2707 let edit_term_menu = factory0#add_submenu "Edit Term" in
2708 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2709 let check_menu_item =
2710 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2711 ~callback:(check scratch_window) in
2712 let _ = check_menu_item#misc#set_sensitive false in
2714 let search_menu = factory0#add_submenu "Search" in
2715 let factory4 = new GMenu.factory search_menu ~accel_group in
2717 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2719 let searchPattern_menu_item =
2720 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2721 ~callback:completeSearchPattern in
2722 let _ = searchPattern_menu_item#misc#set_sensitive false in
2723 let show_menu_item =
2724 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2726 let insert_query_item =
2727 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2728 ~callback:insertQuery in
2730 let hbugs_menu = factory0#add_submenu "HBugs" in
2731 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2733 factory6#add_check_item
2734 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2737 factory6#add_item ~key:GdkKeysyms._Return ~callback:Hbugs.notify
2738 "(Re)Submit status!"
2740 let _ = factory6#add_separator () in
2742 factory6#add_item ~callback:Hbugs.start_web_services "Start Web Services"
2745 factory6#add_item ~callback:Hbugs.stop_web_services "Stop Web Services"
2748 let settings_menu = factory0#add_submenu "Settings" in
2749 let factory3 = new GMenu.factory settings_menu ~accel_group in
2751 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2752 ~callback:edit_aliases in
2754 factory3#add_item "Clear Aliases" ~key:GdkKeysyms._K
2755 ~callback:clear_aliases in
2757 factory3#add_check_item "Auto disambiguation"
2758 ~callback:(fun checked -> auto_disambiguation := checked) in
2759 let _ = factory3#add_separator () in
2761 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2762 ~callback:(function _ -> (settings_window ())#show ()) in
2763 let _ = factory3#add_separator () in
2765 factory3#add_item "Reload Stylesheets"
2768 ChosenTransformer.reload_stylesheets () ;
2769 if ProofEngine.get_proof () <> None then
2771 refresh_goals notebook ;
2772 refresh_proof output
2774 InvokeTactics.RefreshSequentException e ->
2776 (`Error (`T ("An error occurred while refreshing the " ^
2777 "sequent: " ^ Printexc.to_string e))) ;
2778 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2779 notebook#set_empty_page
2780 | InvokeTactics.RefreshProofException e ->
2782 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2786 let _ = window#add_accel_group accel_group in
2790 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2792 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2793 let scrolled_window0 =
2794 GBin.scrolled_window ~border_width:10
2795 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2796 let _ = scrolled_window0#add output#coerce in
2798 GBin.frame ~label:"Insert Term"
2799 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2800 let scrolled_window1 =
2801 GBin.scrolled_window ~border_width:5
2802 ~packing:frame#add () in
2804 TermEditor'.term_editor
2806 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2807 ~isnotempty_callback:
2809 check_menu_item#misc#set_sensitive b ;
2810 searchPattern_menu_item#misc#set_sensitive b) in
2812 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2814 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2816 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2819 new HelmGtkLogger.html_logger
2820 ~width:400 ~height: 100 ~show:true ~packing:frame#add ()
2823 method inputt = inputt
2824 method output = (output : TermViewer.proof_viewer)
2825 method scratch_window = scratch_window
2826 method notebook = notebook
2827 method show = window#show
2828 method set_auto_disambiguation set = autoitem#set_active set
2830 notebook#set_empty_page ;
2831 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2832 check_term := (check_term_in_scratch scratch_window) ;
2834 (* signal handlers here *)
2835 ignore(output#connect#selection_changed
2837 choose_selection output elem ;
2838 !focus_and_proveit_set_sensitive true
2840 ignore (output#connect#click (show_in_show_window_callback output)) ;
2841 let settings_window = new settings_window output scrolled_window0
2842 (*export_to_postscript_menu_item*)() (choose_selection output) in
2843 set_settings_window settings_window ;
2844 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true ))
2849 let initialize_everything () =
2851 TermViewer.proof_viewer
2852 ~mml_of_cic_object:ChosenTransformer.mml_of_cic_object
2853 ~width:350 ~height:280 ()
2855 let notebook = new notebook in
2856 let rendering_window' = new rendering_window output notebook in
2857 rendering_window'#set_auto_disambiguation !auto_disambiguation;
2858 set_rendering_window rendering_window';
2859 let print_error_as_html prefix msg =
2860 HelmLogger.log (`Error (`T (prefix ^ msg)))
2862 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2863 Gdome_xslt.setDebugCallback
2864 (Some (print_error_as_html "XSLT Debug Message: "));
2865 rendering_window'#show () ;
2866 if restore_environment_on_boot &&
2867 Sys.file_exists (Helm_registry.get "gtoplevel.environment_file")
2869 restore_environment ();
2874 ignore (GtkMain.Main.init ()) ;
2875 initialize_everything () ;
2876 MQIC.close mqi_handle;
2881 (* CicEnvironment.set_trust (fun _ -> false); *)
2882 Sys.catch_break true;
2884 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)