1 (* Copyright (C) 2000-2003, 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://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
40 module MQI = MQueryInterpreter
42 module MQGT = MQGTypes
44 module MQG = MQueryGenerator
46 (* GLOBAL CONSTANTS *)
48 let mqi_flags = [MQIC.Postgres ; MQIC.Stat ; MQIC.Warn ; MQIC.Log] (* default MathQL interpreter options *)
50 let mqi_flags = [] (* default MathQL interpreter options *)
52 let mqi_handle = MQIC.init mqi_flags prerr_string
54 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
58 " <body bgColor=\"white\">"
68 Sys.getenv "GTOPLEVEL_PROOFFILE"
70 Not_found -> "/public/currentproof"
75 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
77 Not_found -> "/public/currentprooftype"
82 Sys.getenv "GTOPLEVEL_ENVIRONMENTFILE"
84 Not_found -> "/public/environment"
87 let restore_environment_on_boot = true ;;
88 let notify_hbugs_on_goal_change = false ;;
90 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
92 let htmlheader_and_content = ref htmlheader;;
94 let check_term = ref (fun _ _ _ -> assert false);;
96 exception RenderingWindowsNotInitialized;;
98 let set_rendering_window,rendering_window =
99 let rendering_window_ref = ref None in
100 (function rw -> rendering_window_ref := Some rw),
102 match !rendering_window_ref with
103 None -> raise RenderingWindowsNotInitialized
108 exception SettingsWindowsNotInitialized;;
110 let set_settings_window,settings_window =
111 let settings_window_ref = ref None in
112 (function rw -> settings_window_ref := Some rw),
114 match !settings_window_ref with
115 None -> raise SettingsWindowsNotInitialized
120 exception OutputHtmlNotInitialized;;
122 let set_outputhtml,outputhtml =
123 let outputhtml_ref = ref None in
124 (function rw -> outputhtml_ref := Some rw),
126 match !outputhtml_ref with
127 None -> raise OutputHtmlNotInitialized
128 | Some outputhtml -> outputhtml
132 exception QedSetSensitiveNotInitialized;;
133 let qed_set_sensitive =
134 ref (function _ -> raise QedSetSensitiveNotInitialized)
137 exception SaveSetSensitiveNotInitialized;;
138 let save_set_sensitive =
139 ref (function _ -> raise SaveSetSensitiveNotInitialized)
142 (* COMMAND LINE OPTIONS *)
148 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
151 Arg.parse argspec ignore ""
155 let term_of_cic_textual_parser_uri uri =
156 let module C = Cic in
157 let module CTP = CicTextualParser0 in
159 CTP.ConUri uri -> C.Const (uri,[])
160 | CTP.VarUri uri -> C.Var (uri,[])
161 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
162 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
165 let string_of_cic_textual_parser_uri uri =
166 let module C = Cic in
167 let module CTP = CicTextualParser0 in
170 CTP.ConUri uri -> UriManager.string_of_uri uri
171 | CTP.VarUri uri -> UriManager.string_of_uri uri
172 | CTP.IndTyUri (uri,tyno) ->
173 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
174 | CTP.IndConUri (uri,tyno,consno) ->
175 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
178 (* 4 = String.length "cic:" *)
179 String.sub uri' 4 (String.length uri' - 4)
182 let output_html outputhtml msg =
186 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
190 let check_window outputhtml uris =
193 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
195 GPack.notebook ~scrollable:true ~packing:window#add () in
200 let scrolled_window =
201 GBin.scrolled_window ~border_width:10
203 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
208 TermViewer.sequent_viewer
209 ~packing:scrolled_window#add ~width:400 ~height:280 () in
212 term_of_cic_textual_parser_uri
213 (MQueryMisc.cic_textual_parser_uri_of_string uri)
215 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
218 mmlwidget#load_sequent [] (111,[],expr)
221 output_html outputhtml
222 (`Error (`T (Printexc.to_string e)))
227 (notebook#connect#switch_page
229 Lazy.force (List.nth render_terms i)))
235 interactive_user_uri_choice ~(selection_mode:[`MULTIPLE|`SINGLE]) ?(ok="Ok")
236 ?(enable_button_for_non_vars=false) ~title ~msg uris
238 let choices = ref [] in
239 let chosen = ref false in
240 let use_only_constants = ref false in
242 GWindow.dialog ~modal:true ~title ~width:600 () in
244 GMisc.label ~text:msg
245 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
246 let scrolled_window =
247 GBin.scrolled_window ~border_width:10
248 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
250 let expected_height = 18 * List.length uris in
251 let height = if expected_height > 400 then 400 else expected_height in
252 GList.clist ~columns:1 ~packing:scrolled_window#add
253 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
254 let _ = List.map (function x -> clist#append [x]) uris in
256 GPack.hbox ~border_width:0
257 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
259 GMisc.label ~text:"None of the above. Try this one:"
260 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
262 GEdit.entry ~editable:true
263 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
265 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
267 GButton.button ~label:ok
268 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
269 let _ = okb#misc#set_sensitive false in
274 if enable_button_for_non_vars then
275 hbox#pack ~expand:false ~fill:false ~padding:5 w)
276 ~label:"Try constants only" () in
278 GButton.button ~label:"Check"
279 ~packing:(hbox#pack ~padding:5) () in
280 let _ = checkb#misc#set_sensitive false in
282 GButton.button ~label:"Abort"
283 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
285 let check_callback () =
286 assert (List.length !choices > 0) ;
287 check_window (outputhtml ()) !choices
289 ignore (window#connect#destroy GMain.Main.quit) ;
290 ignore (cancelb#connect#clicked window#destroy) ;
292 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
294 (nonvarsb#connect#clicked
296 use_only_constants := true ;
300 ignore (checkb#connect#clicked check_callback) ;
302 (clist#connect#select_row
303 (fun ~row ~column ~event ->
304 checkb#misc#set_sensitive true ;
305 okb#misc#set_sensitive true ;
306 choices := (List.nth uris row)::!choices)) ;
308 (clist#connect#unselect_row
309 (fun ~row ~column ~event ->
311 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
313 (manual_input#connect#changed
315 if manual_input#text = "" then
318 checkb#misc#set_sensitive false ;
319 okb#misc#set_sensitive false ;
320 clist#misc#set_sensitive true
324 choices := [manual_input#text] ;
325 clist#unselect_all () ;
326 checkb#misc#set_sensitive true ;
327 okb#misc#set_sensitive true ;
328 clist#misc#set_sensitive false
330 window#set_position `CENTER ;
334 if !use_only_constants then
336 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
339 if List.length !choices > 0 then !choices else raise NoChoice
344 let interactive_interpretation_choice interpretations =
345 let chosen = ref None in
348 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
349 let vbox = GPack.vbox ~packing:window#add () in
353 ("Ambiguous input since there are many well-typed interpretations." ^
354 " Please, choose one of them.")
355 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
357 GPack.notebook ~scrollable:true
358 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
361 (function interpretation ->
363 let expected_height = 18 * List.length interpretation in
364 let height = if expected_height > 400 then 400 else expected_height in
365 GList.clist ~columns:2 ~packing:notebook#append_page ~height
366 ~titles:["id" ; "URI"] ()
370 (function (id,uri) ->
371 let n = clist#append [id;uri] in
372 clist#set_row ~selectable:false n
375 clist#columns_autosize ()
378 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
380 GButton.button ~label:"Ok"
381 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
383 GButton.button ~label:"Abort"
384 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
386 ignore (window#connect#destroy GMain.Main.quit) ;
387 ignore (cancelb#connect#clicked window#destroy) ;
390 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
391 window#set_position `CENTER ;
395 None -> raise NoChoice
403 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
406 let struri = UriManager.string_of_uri uri in
407 let idx = (String.rindex struri '/') + 1 in
408 String.sub struri idx (String.length struri - idx)
410 let path = pathname ^ "/" ^ name in
412 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
416 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
417 ~ask_dtd_to_the_getter:false
420 let innertypesuri = UriManager.innertypesuri_of_uri uri in
421 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
422 Getter.register innertypesuri
423 (Configuration.annotations_url ^
424 Str.replace_first (Str.regexp "^cic:") ""
425 (UriManager.string_of_uri innertypesuri) ^ ".xml"
427 (* constant type / variable / mutual inductive types definition *)
428 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
430 (Configuration.annotations_url ^
431 Str.replace_first (Str.regexp "^cic:") ""
432 (UriManager.string_of_uri uri) ^ ".xml"
439 match UriManager.bodyuri_of_uri uri with
441 | Some bodyuri -> bodyuri
443 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
444 Getter.register bodyuri
445 (Configuration.annotations_url ^
446 Str.replace_first (Str.regexp "^cic:") ""
447 (UriManager.string_of_uri bodyuri) ^ ".xml"
454 exception OpenConjecturesStillThere;;
455 exception WrongProof;;
457 let pathname_of_annuri uristring =
458 Configuration.annotations_dir ^
459 Str.replace_first (Str.regexp "^cic:") "" uristring
462 let make_dirs dirpath =
463 ignore (Unix.system ("mkdir -p " ^ dirpath))
466 let save_obj uri obj =
468 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
469 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
471 Cic2acic.acic_object_of_cic_object obj
473 (* let's save the theorem and register it to the getter *)
474 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
476 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
481 match ProofEngine.get_proof () with
483 | Some (uri,[],bo,ty) ->
485 CicReduction.are_convertible []
486 (CicTypeChecker.type_of_aux' [] [] bo) ty
489 (*CSC: Wrong: [] is just plainly wrong *)
490 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
491 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
492 (rendering_window ())#output#load_proof uri proof
494 !qed_set_sensitive false ;
495 (* let's save the theorem and register it to the getter *)
496 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
498 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
503 | _ -> raise OpenConjecturesStillThere
506 (** save an unfinished proof on the filesystem *)
507 let save_unfinished_proof () =
508 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
509 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
510 Xml.pp ~quiet:true xml (Some prooffiletype) ;
511 output_html outputhtml
512 (`Msg (`T ("Current proof type saved to " ^ prooffiletype))) ;
513 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
514 output_html outputhtml
515 (`Msg (`T ("Current proof body saved to " ^ prooffile)))
518 (* Used to typecheck the loaded proofs *)
519 let typecheck_loaded_proof metasenv bo ty =
520 let module T = CicTypeChecker in
523 (fun metasenv ((_,context,ty) as conj) ->
524 ignore (T.type_of_aux' metasenv context ty) ;
527 ignore (T.type_of_aux' metasenv [] ty) ;
528 ignore (T.type_of_aux' metasenv [] bo)
531 let decompose_uris_choice_callback uris =
532 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
533 let module U = UriManager in
536 match MQueryMisc.cic_textual_parser_uri_of_string uri with
537 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
539 (interactive_user_uri_choice
540 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
541 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
543 (function (uri,typeno,_) ->
544 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
549 let mk_fresh_name_callback context name ~typ =
551 match ProofEngineHelpers.mk_fresh_name context name ~typ with
552 Cic.Name fresh_name -> fresh_name
553 | Cic.Anonymous -> assert false
556 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
557 ("Enter a fresh name for the hypothesis " ^
559 (List.map (function None -> None | Some (n,_) -> Some n) context))
561 Some fresh_name' -> Cic.Name fresh_name'
562 | None -> raise NoChoice
565 let refresh_proof (output : TermViewer.proof_viewer) =
567 let uri,currentproof =
568 match ProofEngine.get_proof () with
570 | Some (uri,metasenv,bo,ty) ->
571 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
572 if List.length metasenv = 0 then
574 !qed_set_sensitive true ;
578 (*Hbugs.notify*) () ;
579 (*CSC: Wrong: [] is just plainly wrong *)
581 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
583 ignore (output#load_proof uri currentproof)
586 match ProofEngine.get_proof () with
588 | Some (uri,metasenv,bo,ty) ->
589 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
590 raise (InvokeTactics.RefreshProofException e)
592 let set_proof_engine_goal g =
593 ProofEngine.goal := g
596 let refresh_goals ?(empty_notebook=true) notebook =
598 match !ProofEngine.goal with
600 if empty_notebook then
602 notebook#remove_all_pages ~skip_switch_page_event:false ;
603 notebook#set_empty_page
606 notebook#proofw#unload
609 match ProofEngine.get_proof () with
611 | Some (_,metasenv,_,_) -> metasenv
614 List.find (function (m,_,_) -> m=metano) metasenv
616 let regenerate_notebook () =
617 let skip_switch_page_event =
619 (m,_,_)::_ when m = metano -> false
622 notebook#remove_all_pages ~skip_switch_page_event ;
623 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
625 if empty_notebook then
627 regenerate_notebook () ;
628 notebook#set_current_page
629 ~may_skip_switch_page_event:false metano
633 notebook#set_current_page
634 ~may_skip_switch_page_event:true metano ;
635 notebook#proofw#load_sequent metasenv currentsequent
640 match !ProofEngine.goal with
645 match ProofEngine.get_proof () with
647 | Some (_,metasenv,_,_) -> metasenv
650 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
651 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
652 raise (InvokeTactics.RefreshSequentException e)
653 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unknown."); raise (InvokeTactics.RefreshSequentException e)
655 module InvokeTacticsCallbacks =
657 let sequent_viewer () = (rendering_window ())#notebook#proofw
658 let term_editor () = (rendering_window ())#inputt
659 let scratch_window () = (rendering_window ())#scratch_window
661 let refresh_proof () =
662 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
665 let refresh_goals () =
666 let notebook = (rendering_window ())#notebook in
667 refresh_goals notebook
669 let decompose_uris_choice_callback = decompose_uris_choice_callback
670 let mk_fresh_name_callback = mk_fresh_name_callback
671 let output_html msg = output_html (outputhtml ()) (`Msg (`T msg))
674 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
676 (* Just to initialize the Hbugs module *)
678 module Ignore = Hbugs.Initialize (InvokeTactics');;
679 Hbugs.set_describe_hint_callback (fun hint ->
681 | Hbugs_types.Use_apply_Luke term ->
682 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
683 check_window outputhtml [term]
688 let dummy_uri = "/dummy.con"
690 (** load an unfinished proof from filesystem *)
691 let load_unfinished_proof () =
692 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
693 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
694 let notebook = (rendering_window ())#notebook in
697 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
700 None -> raise NoChoice
702 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
703 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
704 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
705 typecheck_loaded_proof metasenv bo ty ;
706 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
707 refresh_proof output ;
708 set_proof_engine_goal
711 | (metano,_,_)::_ -> Some metano
713 refresh_goals notebook ;
714 output_html outputhtml
715 (`Msg (`T ("Current proof type loaded from " ^
717 output_html outputhtml
718 (`Msg (`T ("Current proof body loaded from " ^
720 !save_set_sensitive true;
723 InvokeTactics.RefreshSequentException e ->
724 output_html outputhtml
725 (`Error (`T ("Exception raised during the refresh of the " ^
726 "sequent: " ^ Printexc.to_string e)))
727 | InvokeTactics.RefreshProofException e ->
728 output_html outputhtml
729 (`Error (`T ("Exception raised during the refresh of the " ^
730 "proof: " ^ Printexc.to_string e)))
732 output_html outputhtml
733 (`Error (`T (Printexc.to_string e)))
736 let edit_aliases () =
737 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
738 let id_to_uris = inputt#id_to_uris in
739 let chosen = ref false in
742 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
744 GPack.vbox ~border_width:0 ~packing:window#add () in
745 let scrolled_window =
746 GBin.scrolled_window ~border_width:10
747 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
748 let input = GText.view ~editable:true ~width:400 ~height:100
749 ~packing:scrolled_window#add () in
751 GPack.hbox ~border_width:0
752 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
754 GButton.button ~label:"Ok"
755 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
757 GButton.button ~label:"Cancel"
758 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
759 ignore (window#connect#destroy GMain.Main.quit) ;
760 ignore (cancelb#connect#clicked window#destroy) ;
762 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
763 let dom,resolve_id = !id_to_uris in
765 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
770 match resolve_id v with
772 | Some (CicTextualParser0.Uri uri) -> uri
773 | Some (CicTextualParser0.Term _)
774 | Some CicTextualParser0.Implicit -> assert false
778 CicTextualParser0.Id id -> id
779 | CicTextualParser0.Symbol (descr,_) ->
780 (* CSC: To be implemented *)
782 )^ " " ^ (string_of_cic_textual_parser_uri uri)
788 let inputtext = input#buffer#get_text () in
790 let alfa = "[a-zA-Z_-]" in
791 let digit = "[0-9]" in
792 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
793 let blanks = "\( \|\t\|\n\)+" in
794 let nonblanks = "[^ \t\n]+" in
795 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
797 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
801 let n' = Str.search_forward regexpr inputtext n in
802 let id = CicTextualParser0.Id (Str.matched_group 2 inputtext) in
804 MQueryMisc.cic_textual_parser_uri_of_string
805 ("cic:" ^ (Str.matched_group 5 inputtext))
807 let dom,resolve_id = aux (n' + 1) in
808 if List.mem id dom then
814 Some (CicTextualParser0.Uri uri)
817 Not_found -> TermEditor.empty_id_to_uris
821 id_to_uris := (dom,resolve_id)
825 let module L = LogicalOperations in
826 let module G = Gdome in
827 let notebook = (rendering_window ())#notebook in
828 let output = (rendering_window ())#output in
829 let outputhtml = ((rendering_window ())#outputhtml (*: GHtml.xmhtml*)) in
831 output#make_sequent_of_selected_term ;
832 refresh_proof output ;
833 refresh_goals notebook
835 InvokeTactics.RefreshSequentException e ->
836 output_html outputhtml
837 (`Error (`T ("Exception raised during the refresh of the " ^
838 "sequent: " ^ Printexc.to_string e)))
839 | InvokeTactics.RefreshProofException e ->
840 output_html outputhtml
841 (`Error (`T ("Exception raised during the refresh of the " ^
842 "proof: " ^ Printexc.to_string e)))
844 output_html outputhtml
845 (`Error (`T (Printexc.to_string e)))
849 let module L = LogicalOperations in
850 let module G = Gdome in
851 let notebook = (rendering_window ())#notebook in
852 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
853 let output = (rendering_window ())#output in
855 output#focus_sequent_of_selected_term ;
856 refresh_goals notebook
858 InvokeTactics.RefreshSequentException e ->
859 output_html outputhtml
860 (`Error (`T ("Exception raised during the refresh of the " ^
861 "sequent: " ^ Printexc.to_string e)))
862 | InvokeTactics.RefreshProofException e ->
863 output_html outputhtml
864 (`Error (`T ("Exception raised during the refresh of the " ^
865 "proof: " ^ Printexc.to_string e)))
867 output_html outputhtml
868 (`Error (`T (Printexc.to_string e)))
871 exception NoPrevGoal;;
872 exception NoNextGoal;;
875 let module L = LogicalOperations in
876 let module G = Gdome in
877 let notebook = (rendering_window ())#notebook in
878 let output = (rendering_window ())#output in
879 let outputhtml = (rendering_window ())#outputhtml in
881 match ProofEngine.get_proof () with
883 | Some (_,metasenv,_,_) -> metasenv
886 refresh_goals ~empty_notebook:false notebook
888 InvokeTactics.RefreshSequentException e ->
889 output_html outputhtml
890 (`Error (`T ("Exception raised during the refresh of the " ^
891 "sequent: " ^ Printexc.to_string e)))
893 output_html outputhtml
894 (`Error (`T (Printexc.to_string e)))
898 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
901 GWindow.window ~width:800 ~border_width:2 () in
902 let scrolled_window =
903 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
905 GMathViewAux.single_selection_math_view
906 ~packing:scrolled_window#add ~width:600 ~height:400 ()
908 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
909 let href = Gdome.domString "href" in
910 let show_in_show_window_obj uri obj =
911 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
914 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
915 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
917 Cic2acic.acic_object_of_cic_object obj
920 ApplyStylesheets.mml_of_cic_object
921 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
923 window#set_title (UriManager.string_of_uri uri) ;
924 window#misc#hide () ; window#show () ;
925 mmlwidget#load_doc mml ;
928 output_html outputhtml
929 (`Error (`T (Printexc.to_string e)))
931 let show_in_show_window_uri uri =
932 let obj = CicEnvironment.get_obj uri in
933 show_in_show_window_obj uri obj
935 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
939 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
941 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
943 show_in_show_window_uri (UriManager.uri_of_string uri)
945 ignore (mmlwidget#action_toggle n')
948 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
950 show_in_show_window_obj, show_in_show_window_uri,
951 show_in_show_window_callback
954 exception NoObjectsLocated;;
956 let user_uri_choice ~title ~msg uris =
959 [] -> raise NoObjectsLocated
963 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
968 String.sub uri 4 (String.length uri - 4)
971 let locate_callback id =
972 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
973 let out = output_html outputhtml in
974 let query = MQG.locate id in
975 let result = MQI.execute mqi_handle query in
979 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
981 out (`Msg (`T "Locate Query:")) ;
982 MQueryUtil.text_of_query (fun m -> out (`Msg (`T m))) "" query;
983 out (`Msg (`T "Result:")) ;
984 MQueryUtil.text_of_result (fun m -> out (`Msg (`T m))) "" result;
985 user_uri_choice ~title:"Ambiguous input."
987 ("Ambiguous input \"" ^ id ^
988 "\". Please, choose one interpetation:")
993 let input_or_locate_uri ~title =
994 let uri = ref None in
997 ~width:400 ~modal:true ~title ~border_width:2 () in
998 let vbox = GPack.vbox ~packing:window#add () in
1000 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1002 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1004 GEdit.entry ~editable:true
1005 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1007 GButton.button ~label:"Check"
1008 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1009 let _ = checkb#misc#set_sensitive false in
1011 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1013 GMisc.label ~text:"You can also enter an indentifier to locate:"
1014 ~packing:(hbox2#pack ~padding:5) () in
1016 GEdit.entry ~editable:true
1017 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1019 GButton.button ~label:"Locate"
1020 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1021 let _ = locateb#misc#set_sensitive false in
1023 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1025 GButton.button ~label:"Ok"
1026 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1027 let _ = okb#misc#set_sensitive false in
1029 GButton.button ~label:"Cancel"
1030 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1032 ignore (window#connect#destroy GMain.Main.quit) ;
1034 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1035 let check_callback () =
1036 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1037 let uri = "cic:" ^ manual_input#text in
1039 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1040 output_html outputhtml (`Msg (`T "OK")) ;
1043 Getter.Unresolved ->
1044 output_html outputhtml
1045 (`Error (`T ("URI " ^ uri ^
1046 " does not correspond to any object."))) ;
1048 | UriManager.IllFormedUri _ ->
1049 output_html outputhtml
1050 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
1053 output_html outputhtml
1054 (`Error (`T (Printexc.to_string e))) ;
1058 (okb#connect#clicked
1060 if check_callback () then
1062 uri := Some manual_input#text ;
1066 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1068 (manual_input#connect#changed
1070 if manual_input#text = "" then
1072 checkb#misc#set_sensitive false ;
1073 okb#misc#set_sensitive false
1077 checkb#misc#set_sensitive true ;
1078 okb#misc#set_sensitive true
1081 (locate_input#connect#changed
1082 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1084 (locateb#connect#clicked
1086 let id = locate_input#text in
1087 manual_input#set_text (locate_callback id) ;
1088 locate_input#delete_text 0 (String.length id)
1093 None -> raise NoChoice
1094 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1097 exception AmbiguousInput;;
1099 (* A WIDGET TO ENTER CIC TERMS *)
1101 module ChosenTermEditor = TexTermEditor;;
1102 module ChosenTextualParser0 = TexCicTextualParser0;;
1104 module ChosenTermEditor = TermEditor;;
1105 module ChosenTextualParser0 = CicTextualParser0;;
1110 let get_metasenv () = !ChosenTextualParser0.metasenv
1111 let set_metasenv metasenv = ChosenTextualParser0.metasenv := metasenv
1113 let output_html msg = output_html (outputhtml ()) (`Msg (`T msg));;
1114 let interactive_user_uri_choice =
1115 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1116 interactive_user_uri_choice ~selection_mode ?ok
1117 ?enable_button_for_non_vars ~title ~msg;;
1118 let interactive_interpretation_choice = interactive_interpretation_choice;;
1119 let input_or_locate_uri = input_or_locate_uri;;
1123 module TexTermEditor' = ChosenTermEditor.Make(Callbacks);;
1125 (* OTHER FUNCTIONS *)
1128 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1129 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1132 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1134 None -> raise NoChoice
1136 let uri = locate_callback input in
1140 output_html outputhtml
1141 (`Error (`T (Printexc.to_string e)))
1145 exception UriAlreadyInUse;;
1146 exception NotAUriToAConstant;;
1148 let new_inductive () =
1149 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1150 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1151 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1152 let notebook = (rendering_window ())#notebook in
1154 let chosen = ref false in
1155 let inductive = ref true in
1156 let paramsno = ref 0 in
1157 let get_uri = ref (function _ -> assert false) in
1158 let get_base_uri = ref (function _ -> assert false) in
1159 let get_names = ref (function _ -> assert false) in
1160 let get_types_and_cons = ref (function _ -> assert false) in
1161 let get_context_and_subst = ref (function _ -> assert false) in
1164 ~width:600 ~modal:true ~position:`CENTER
1165 ~title:"New Block of Mutual (Co)Inductive Definitions"
1166 ~border_width:2 () in
1167 let vbox = GPack.vbox ~packing:window#add () in
1169 GPack.hbox ~border_width:0
1170 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1172 GMisc.label ~text:"Enter the URI for the new block:"
1173 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1175 GEdit.entry ~editable:true
1176 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1178 GPack.hbox ~border_width:0
1179 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1183 "Enter the number of left parameters in every arity and constructor type:"
1184 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1185 let paramsno_entry =
1186 GEdit.entry ~editable:true ~text:"0"
1187 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1189 GPack.hbox ~border_width:0
1190 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1192 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1193 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1195 GButton.radio_button ~label:"Inductive"
1196 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1198 GButton.radio_button ~label:"Coinductive"
1199 ~group:inductiveb#group
1200 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1202 GPack.hbox ~border_width:0
1203 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1205 GMisc.label ~text:"Enter the list of the names of the types:"
1206 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1208 GEdit.entry ~editable:true
1209 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1211 GPack.hbox ~border_width:0
1212 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1214 GButton.button ~label:"> Next"
1215 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1216 let _ = okb#misc#set_sensitive true in
1218 GButton.button ~label:"Abort"
1219 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1220 ignore (window#connect#destroy GMain.Main.quit) ;
1221 ignore (cancelb#connect#clicked window#destroy) ;
1225 (okb#connect#clicked
1228 let uristr = "cic:" ^ uri_entry#text in
1229 let namesstr = names_entry#text in
1230 let paramsno' = int_of_string (paramsno_entry#text) in
1231 match Str.split (Str.regexp " +") namesstr with
1233 | (he::tl) as names ->
1234 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1237 ignore (Getter.resolve uri) ;
1238 raise UriAlreadyInUse
1240 Getter.Unresolved ->
1241 get_uri := (function () -> uri) ;
1242 get_names := (function () -> names) ;
1243 inductive := inductiveb#active ;
1244 paramsno := paramsno' ;
1249 output_html outputhtml
1250 (`Error (`T (Printexc.to_string e)))
1258 GBin.frame ~label:name
1259 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1260 let vbox = GPack.vbox ~packing:frame#add () in
1261 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1263 GMisc.label ~text:("Enter its type:")
1264 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1265 let scrolled_window =
1266 GBin.scrolled_window ~border_width:5
1267 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1269 TexTermEditor'.term_editor
1271 ~width:400 ~height:20 ~packing:scrolled_window#add
1272 ~share_id_to_uris_with:inputt ()
1273 ~isnotempty_callback:
1275 (*non_empty_type := b ;*)
1276 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1279 GPack.hbox ~border_width:0
1280 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1282 GMisc.label ~text:("Enter the list of its constructors:")
1283 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1284 let cons_names_entry =
1285 GEdit.entry ~editable:true
1286 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1287 (newinputt,cons_names_entry)
1290 vbox#remove hboxn#coerce ;
1292 GPack.hbox ~border_width:0
1293 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1295 GButton.button ~label:"> Next"
1296 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1298 GButton.button ~label:"Abort"
1299 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1300 ignore (cancelb#connect#clicked window#destroy) ;
1302 (okb#connect#clicked
1305 let names = !get_names () in
1306 let types_and_cons =
1308 (fun name (newinputt,cons_names_entry) ->
1309 let consnamesstr = cons_names_entry#text in
1310 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1312 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1315 [] -> expr,cons_names
1316 | _ -> raise AmbiguousInput
1317 ) names type_widgets
1319 let uri = !get_uri () in
1321 (* Let's see if so far the definition is well-typed *)
1324 (* To test if the arities of the inductive types are well *)
1325 (* typed, we check the inductive block definition where *)
1326 (* no constructor is given to each type. *)
1329 (fun name (ty,cons) -> (name, !inductive, ty, []))
1330 names types_and_cons
1332 CicTypeChecker.typecheck_mutual_inductive_defs uri
1333 (tys,params,paramsno)
1335 get_context_and_subst :=
1339 (fun (context,subst) name (ty,_) ->
1341 (Some (Cic.Name name, Cic.Decl ty))::context,
1342 (Cic.MutInd (uri,!i,[]))::subst
1345 ) ([],[]) names types_and_cons) ;
1346 let types_and_cons' =
1348 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1349 names types_and_cons
1351 get_types_and_cons := (function () -> types_and_cons') ;
1356 output_html outputhtml
1357 (`Error (`T (Printexc.to_string e)))
1360 and phase3 name cons =
1361 let get_cons_types = ref (function () -> assert false) in
1364 ~width:600 ~modal:true ~position:`CENTER
1365 ~title:(name ^ " Constructors")
1366 ~border_width:2 () in
1367 let vbox = GPack.vbox ~packing:window2#add () in
1368 let cons_type_widgets =
1370 (function consname ->
1372 GPack.hbox ~border_width:0
1373 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1375 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1376 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1377 let scrolled_window =
1378 GBin.scrolled_window ~border_width:5
1379 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1381 TexTermEditor'.term_editor
1383 ~width:400 ~height:20 ~packing:scrolled_window#add
1384 ~share_id_to_uris_with:inputt ()
1385 ~isnotempty_callback:
1387 (* (*non_empty_type := b ;*)
1388 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1393 GPack.hbox ~border_width:0
1394 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1396 GButton.button ~label:"> Next"
1397 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1398 let _ = okb#misc#set_sensitive true in
1400 GButton.button ~label:"Abort"
1401 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1402 ignore (window2#connect#destroy GMain.Main.quit) ;
1403 ignore (cancelb#connect#clicked window2#destroy) ;
1405 (okb#connect#clicked
1409 let context,subst= !get_context_and_subst () in
1414 inputt#get_metasenv_and_term ~context ~metasenv:[]
1418 let undebrujined_expr =
1420 (fun expr t -> CicSubstitution.subst t expr) expr subst
1422 name, undebrujined_expr
1423 | _ -> raise AmbiguousInput
1424 ) cons cons_type_widgets
1426 get_cons_types := (function () -> cons_types) ;
1430 output_html outputhtml
1431 (`Error (`T (Printexc.to_string e)))
1435 let okb_pressed = !chosen in
1437 if (not okb_pressed) then
1440 assert false (* The control never reaches this point *)
1443 (!get_cons_types ())
1446 (* No more phases left or Abort pressed *)
1452 let uri = !get_uri () in
1455 let tys = !get_types_and_cons () in
1456 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1459 prerr_endline (CicPp.ppobj obj) ;
1460 CicTypeChecker.typecheck_mutual_inductive_defs uri
1461 (tys,params,!paramsno) ;
1464 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1465 prerr_endline (CicPp.ppobj obj) ;
1467 (* We already know that obj is well-typed. We need to add it to the *)
1468 (* environment in order to compute the inner-types without having to *)
1469 (* debrujin it or having to modify lots of other functions to avoid *)
1470 (* asking the environment for the MUTINDs we are defining now. *)
1471 CicEnvironment.put_inductive_definition uri obj ;
1473 show_in_show_window_obj uri obj
1476 output_html outputhtml
1477 (`Error (`T (Printexc.to_string e)))
1481 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1482 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1483 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1484 let notebook = (rendering_window ())#notebook in
1486 let chosen = ref false in
1487 let get_metasenv_and_term = ref (function _ -> assert false) in
1488 let get_uri = ref (function _ -> assert false) in
1489 let non_empty_type = ref false in
1492 ~width:600 ~modal:true ~title:"New Proof or Definition"
1493 ~border_width:2 () in
1494 let vbox = GPack.vbox ~packing:window#add () in
1496 GPack.hbox ~border_width:0
1497 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1499 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1500 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1502 GEdit.entry ~editable:true
1503 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1504 uri_entry#set_text dummy_uri;
1505 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1507 GPack.hbox ~border_width:0
1508 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1510 GMisc.label ~text:"Enter the theorem or definition type:"
1511 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1512 let scrolled_window =
1513 GBin.scrolled_window ~border_width:5
1514 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1515 (* the content of the scrolled_window is moved below (see comment) *)
1517 GPack.hbox ~border_width:0
1518 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1520 GButton.button ~label:"Ok"
1521 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1522 let _ = okb#misc#set_sensitive false in
1524 GButton.button ~label:"Cancel"
1525 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1526 (* moved here to have visibility of the ok button *)
1528 TexTermEditor'.term_editor
1530 ~width:400 ~height:100 ~packing:scrolled_window#add
1531 ~share_id_to_uris_with:inputt ()
1532 ~isnotempty_callback:
1534 non_empty_type := b ;
1535 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1538 let xxx = inputt#get_as_string in
1539 prerr_endline ("######################## " ^ xxx) ;
1540 newinputt#set_term xxx ;
1542 newinputt#set_term inputt#get_as_string ;
1546 uri_entry#connect#changed
1548 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1550 ignore (window#connect#destroy GMain.Main.quit) ;
1551 ignore (cancelb#connect#clicked window#destroy) ;
1553 (okb#connect#clicked
1557 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1558 let uristr = "cic:" ^ uri_entry#text in
1559 let uri = UriManager.uri_of_string uristr in
1560 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1561 raise NotAUriToAConstant
1565 ignore (Getter.resolve uri) ;
1566 raise UriAlreadyInUse
1568 Getter.Unresolved ->
1569 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1570 get_uri := (function () -> uri) ;
1575 output_html outputhtml
1576 (`Error (`T (Printexc.to_string e)))
1582 let metasenv,expr = !get_metasenv_and_term () in
1583 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1584 ProofEngine.set_proof
1585 (Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr)) ;
1586 set_proof_engine_goal (Some 1) ;
1587 refresh_goals notebook ;
1588 refresh_proof output ;
1589 !save_set_sensitive true ;
1591 ProofEngine.intros ~mk_fresh_name_callback () ;
1592 refresh_goals notebook ;
1593 refresh_proof output
1595 InvokeTactics.RefreshSequentException e ->
1596 output_html outputhtml
1597 (`Error (`T ("Exception raised during the refresh of the " ^
1598 "sequent: " ^ Printexc.to_string e)))
1599 | InvokeTactics.RefreshProofException e ->
1600 output_html outputhtml
1601 (`Error (`T ("Exception raised during the refresh of the " ^
1602 "proof: " ^ Printexc.to_string e)))
1604 output_html outputhtml
1605 (`Error (`T (Printexc.to_string e)))
1608 let check_term_in_scratch scratch_window metasenv context expr =
1610 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1611 let expr = Cic.Cast (expr,ty) in
1612 scratch_window#show () ;
1613 scratch_window#set_term expr ;
1614 scratch_window#set_context context ;
1615 scratch_window#set_metasenv metasenv ;
1616 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1619 print_endline ("? " ^ CicPp.ppterm expr) ;
1623 let check scratch_window () =
1624 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1625 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1627 match ProofEngine.get_proof () with
1629 | Some (_,metasenv,_,_) -> metasenv
1632 match !ProofEngine.goal with
1635 let (_,canonical_context,_) =
1636 List.find (function (m,_,_) -> m=metano) metasenv
1641 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1642 check_term_in_scratch scratch_window metasenv' context expr
1645 output_html outputhtml
1646 (`Error (`T (Printexc.to_string e)))
1650 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1652 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1655 output_html outputhtml
1656 (`Error (`T (Printexc.to_string e)))
1659 exception NotADefinition;;
1662 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1663 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1664 let notebook = (rendering_window ())#notebook in
1666 let uri = input_or_locate_uri ~title:"Open" in
1667 CicTypeChecker.typecheck uri ;
1668 let metasenv,bo,ty =
1669 match CicEnvironment.get_cooked_obj uri with
1670 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1671 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1674 | Cic.InductiveDefinition _ -> raise NotADefinition
1676 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
1677 set_proof_engine_goal None ;
1678 refresh_goals notebook ;
1679 refresh_proof output ;
1680 !save_set_sensitive true
1682 InvokeTactics.RefreshSequentException e ->
1683 output_html outputhtml
1684 (`Error (`T ("Exception raised during the refresh of the " ^
1685 "sequent: " ^ Printexc.to_string e)))
1686 | InvokeTactics.RefreshProofException e ->
1687 output_html outputhtml
1688 (`Error (`T ("Exception raised during the refresh of the " ^
1689 "proof: " ^ Printexc.to_string e)))
1691 output_html outputhtml
1692 (`Error (`T (Printexc.to_string e)))
1695 let show_query_results results =
1698 ~modal:false ~title:"Query results." ~border_width:2 () in
1699 let vbox = GPack.vbox ~packing:window#add () in
1701 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1704 ~text:"Click on a URI to show that object"
1705 ~packing:hbox#add () in
1706 let scrolled_window =
1707 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1708 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1709 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1712 (function (uri,_) ->
1716 clist#set_row ~selectable:false n
1719 clist#columns_autosize () ;
1721 (clist#connect#select_row
1722 (fun ~row ~column ~event ->
1723 let (uristr,_) = List.nth results row in
1725 MQueryMisc.cic_textual_parser_uri_of_string
1726 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1729 CicTextualParser0.ConUri uri
1730 | CicTextualParser0.VarUri uri
1731 | CicTextualParser0.IndTyUri (uri,_)
1732 | CicTextualParser0.IndConUri (uri,_,_) ->
1733 show_in_show_window_uri uri
1739 let refine_constraints (must_obj,must_rel,must_sort) =
1740 let chosen = ref false in
1741 let use_only = ref false in
1744 ~modal:true ~title:"Constraints refinement."
1745 ~width:800 ~border_width:2 () in
1746 let vbox = GPack.vbox ~packing:window#add () in
1748 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1751 ~text: "\"Only\" constraints can be enforced or not."
1752 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1754 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1755 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1758 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1759 (* Notebook for the constraints choice *)
1761 GPack.notebook ~scrollable:true
1762 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1763 (* Rel constraints *)
1766 ~text: "Constraints on Rels" () in
1768 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1771 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1774 ~text: "You can now specify the constraints on Rels."
1775 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1776 let expected_height = 25 * (List.length must_rel + 2) in
1777 let height = if expected_height > 400 then 400 else expected_height in
1778 let scrolled_window =
1779 GBin.scrolled_window ~border_width:10 ~height ~width:600
1780 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1781 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1782 let mk_depth_button (hbox:GPack.box) d =
1783 let mutable_ref = ref (Some d) in
1785 GButton.toggle_button
1786 ~label:("depth = " ^ string_of_int d)
1788 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1791 (depthb#connect#toggled
1793 let sel_depth = if depthb#active then Some d else None in
1794 mutable_ref := sel_depth
1797 let rel_constraints =
1802 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1805 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1806 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1808 | `MainHypothesis None
1809 | `MainConclusion None -> p, ref None
1810 | `MainHypothesis (Some depth')
1811 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1813 (* Sort constraints *)
1816 ~text: "Constraints on Sorts" () in
1818 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1821 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1824 ~text: "You can now specify the constraints on Sorts."
1825 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1826 let expected_height = 25 * (List.length must_sort + 2) in
1827 let height = if expected_height > 400 then 400 else expected_height in
1828 let scrolled_window =
1829 GBin.scrolled_window ~border_width:10 ~height ~width:600
1830 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1831 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1832 let sort_constraints =
1834 (function (p, sort) ->
1837 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1840 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1841 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1843 | `MainHypothesis None
1844 | `MainConclusion None -> p, ref None, sort
1845 | `MainHypothesis (Some depth')
1846 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1848 (* Obj constraints *)
1851 ~text: "Constraints on constants" () in
1853 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1856 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1859 ~text: "You can now specify the constraints on constants."
1860 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1861 let expected_height = 25 * (List.length must_obj + 2) in
1862 let height = if expected_height > 400 then 400 else expected_height in
1863 let scrolled_window =
1864 GBin.scrolled_window ~border_width:10 ~height ~width:600
1865 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1866 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1867 let obj_constraints =
1869 (function (p, uri) ->
1872 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1875 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1876 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1881 | `MainHypothesis None
1882 | `MainConclusion None -> p, ref None, uri
1883 | `MainHypothesis (Some depth')
1884 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1886 (* Confirm/abort buttons *)
1888 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1890 GButton.button ~label:"Ok"
1891 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1893 GButton.button ~label:"Abort"
1894 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1896 ignore (window#connect#destroy GMain.Main.quit) ;
1897 ignore (cancelb#connect#clicked window#destroy) ;
1899 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1900 window#set_position `CENTER ;
1904 let chosen_must_rel =
1906 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1909 let chosen_must_sort =
1911 (function (position, ref_depth, sort) ->
1912 MQGU.set_main_position position !ref_depth,sort)
1915 let chosen_must_obj =
1917 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1920 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1922 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1923 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1931 let completeSearchPattern () =
1932 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1933 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1935 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1936 let must = CGSearchPattern.get_constraints expr in
1937 let must',only = refine_constraints must in
1939 MQG.query_of_constraints (Some CGSearchPattern.universe) must' only
1941 let results = MQI.execute mqi_handle query in
1942 show_query_results results
1945 output_html outputhtml
1946 (`Error (`T (Printexc.to_string e)))
1949 let insertQuery () =
1950 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
1952 let chosen = ref None in
1955 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1956 let vbox = GPack.vbox ~packing:window#add () in
1958 GMisc.label ~text:"Insert Query. For Experts Only."
1959 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1960 let scrolled_window =
1961 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1962 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1963 let input = GText.view ~editable:true
1964 ~packing:scrolled_window#add () in
1966 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1968 GButton.button ~label:"Ok"
1969 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1971 GButton.button ~label:"Load from file..."
1972 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1974 GButton.button ~label:"Abort"
1975 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1976 ignore (window#connect#destroy GMain.Main.quit) ;
1977 ignore (cancelb#connect#clicked window#destroy) ;
1979 (okb#connect#clicked
1981 chosen := Some (input#buffer#get_text ()) ; window#destroy ())) ;
1983 (loadb#connect#clicked
1986 GToolbox.select_file ~title:"Select Query File" ()
1990 let inch = open_in filename in
1991 let rec read_file () =
1993 let line = input_line inch in
1994 line ^ "\n" ^ read_file ()
1998 let text = read_file () in
1999 input#buffer#delete input#buffer#start_iter input#buffer#end_iter ;
2000 ignore (input#buffer#insert text))) ;
2001 window#set_position `CENTER ;
2008 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
2010 show_query_results results
2013 output_html outputhtml
2014 (`Error (`T (Printexc.to_string e)))
2017 let choose_must list_of_must only =
2018 let chosen = ref None in
2019 let user_constraints = ref [] in
2022 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2023 let vbox = GPack.vbox ~packing:window#add () in
2025 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2029 ("You can now specify the genericity of the query. " ^
2030 "The more generic the slower.")
2031 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2033 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2037 "Suggestion: start with faster queries before moving to more generic ones."
2038 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2040 GPack.notebook ~scrollable:true
2041 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2044 let last = List.length list_of_must in
2050 (if !page = 1 then "More generic" else
2051 if !page = last then "More precise" else " ") () in
2052 let expected_height = 25 * (List.length must + 2) in
2053 let height = if expected_height > 400 then 400 else expected_height in
2054 let scrolled_window =
2055 GBin.scrolled_window ~border_width:10 ~height ~width:600
2056 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2058 GList.clist ~columns:2 ~packing:scrolled_window#add
2059 ~titles:["URI" ; "Position"] ()
2063 (function (position, uri) ->
2066 [uri; MQGUtil.text_of_position position]
2068 clist#set_row ~selectable:false n
2071 clist#columns_autosize ()
2074 let label = GMisc.label ~text:"User provided" () in
2076 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2078 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2081 ~text:"Select the constraints that must be satisfied and press OK."
2082 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2083 let expected_height = 25 * (List.length only + 2) in
2084 let height = if expected_height > 400 then 400 else expected_height in
2085 let scrolled_window =
2086 GBin.scrolled_window ~border_width:10 ~height ~width:600
2087 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2089 GList.clist ~columns:2 ~packing:scrolled_window#add
2090 ~selection_mode:`MULTIPLE
2091 ~titles:["URI" ; "Position"] ()
2095 (function (position, uri) ->
2098 [uri; MQGUtil.text_of_position position]
2100 clist#set_row ~selectable:true n
2103 clist#columns_autosize () ;
2105 (clist#connect#select_row
2106 (fun ~row ~column ~event ->
2107 user_constraints := (List.nth only row)::!user_constraints)) ;
2109 (clist#connect#unselect_row
2110 (fun ~row ~column ~event ->
2113 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2116 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2118 GButton.button ~label:"Ok"
2119 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2121 GButton.button ~label:"Abort"
2122 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2124 ignore (window#connect#destroy GMain.Main.quit) ;
2125 ignore (cancelb#connect#clicked window#destroy) ;
2127 (okb#connect#clicked
2128 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2129 window#set_position `CENTER ;
2133 None -> raise NoChoice
2135 if n = List.length list_of_must then
2136 (* user provided constraints *)
2139 List.nth list_of_must n
2142 let searchPattern () =
2143 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2144 let outputhtml = ((rendering_window ())#outputhtml(* : GHtml.xmhtml*)) in
2147 match ProofEngine.get_proof () with
2148 None -> assert false
2149 | Some proof -> proof
2151 match !ProofEngine.goal with
2155 TacticChaser.matchConclusion
2157 ~output_html:(fun m -> output_html outputhtml (`Msg (`T m)))
2158 ~choose_must () ~status:(proof, metano)
2161 user_uri_choice ~title:"Ambiguous input."
2162 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2165 inputt#set_term uri' ;
2166 InvokeTactics'.apply ()
2169 output_html outputhtml
2170 (`Error (`T (Printexc.to_string e)))
2173 let choose_selection mmlwidget (element : Gdome.element option) =
2174 let module G = Gdome in
2175 prerr_endline "Il bandolo" ;
2176 let rec aux element =
2177 if element#hasAttributeNS
2178 ~namespaceURI:Misc.helmns
2179 ~localName:(G.domString "xref")
2181 mmlwidget#set_selection (Some element)
2184 match element#get_parentNode with
2185 None -> assert false
2186 (*CSC: OCAML DIVERGES!
2187 | Some p -> aux (new G.element_of_node p)
2189 | Some p -> aux (new Gdome.element_of_node p)
2191 GdomeInit.DOMCastException _ ->
2193 "******* trying to select above the document root ********"
2197 | None -> mmlwidget#set_selection None
2200 (* STUFF TO BUILD THE GTK INTERFACE *)
2202 (* Stuff for the widget settings *)
2205 let export_to_postscript output =
2206 let lastdir = ref (Unix.getcwd ()) in
2209 GToolbox.select_file ~title:"Export to PostScript"
2210 ~dir:lastdir ~filename:"screenshot.ps" ()
2214 (output :> GMathView.math_view)#export_to_postscript
2215 ~filename:filename ();
2220 let activate_t1 output button_set_anti_aliasing
2221 button_set_transparency export_to_postscript_menu_item
2224 let is_set = button_t1#active in
2225 output#set_font_manager_type
2226 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2229 button_set_anti_aliasing#misc#set_sensitive true ;
2230 button_set_transparency#misc#set_sensitive true ;
2231 export_to_postscript_menu_item#misc#set_sensitive true ;
2235 button_set_anti_aliasing#misc#set_sensitive false ;
2236 button_set_transparency#misc#set_sensitive false ;
2237 export_to_postscript_menu_item#misc#set_sensitive false ;
2241 let set_anti_aliasing output button_set_anti_aliasing () =
2242 output#set_anti_aliasing button_set_anti_aliasing#active
2245 let set_transparency output button_set_transparency () =
2246 output#set_transparency button_set_transparency#active
2250 let changefont output font_size_spinb () =
2251 output#set_font_size font_size_spinb#value_as_int
2254 let set_log_verbosity output log_verbosity_spinb () =
2255 output#set_log_verbosity log_verbosity_spinb#value_as_int
2258 class settings_window output sw
2259 export_to_postscript_menu_item selection_changed_callback
2261 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2263 GPack.vbox ~packing:settings_window#add () in
2266 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2267 ~border_width:5 ~packing:vbox#add () in
2269 GButton.toggle_button ~label:"activate t1 fonts"
2270 ~packing:(table#attach ~left:0 ~top:0) () in
2271 let button_set_anti_aliasing =
2272 GButton.toggle_button ~label:"set_anti_aliasing"
2273 ~packing:(table#attach ~left:0 ~top:1) () in
2274 let button_set_transparency =
2275 GButton.toggle_button ~label:"set_transparency"
2276 ~packing:(table#attach ~left:2 ~top:1) () in
2279 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2280 ~border_width:5 ~packing:vbox#add () in
2281 let font_size_label =
2282 GMisc.label ~text:"font size:"
2283 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2284 let font_size_spinb =
2286 GData.adjustment ~value:(float_of_int output#get_font_size)
2287 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2290 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2291 let log_verbosity_label =
2292 GMisc.label ~text:"log verbosity:"
2293 ~packing:(table#attach ~left:0 ~top:1) () in
2294 let log_verbosity_spinb =
2296 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2299 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2301 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2303 GButton.button ~label:"Close"
2304 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2306 method show = settings_window#show
2308 button_set_anti_aliasing#misc#set_sensitive false ;
2309 button_set_transparency#misc#set_sensitive false ;
2310 (* Signals connection *)
2312 ignore(button_t1#connect#clicked
2313 (activate_t1 output button_set_anti_aliasing
2314 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2316 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2318 ignore(button_set_anti_aliasing#connect#toggled
2319 (set_anti_aliasing output button_set_anti_aliasing));
2320 ignore(button_set_transparency#connect#toggled
2321 (set_transparency output button_set_transparency)) ;
2323 ignore(log_verbosity_spinb#connect#changed
2324 (set_log_verbosity output log_verbosity_spinb)) ;
2325 ignore(closeb#connect#clicked settings_window#misc#hide)
2328 (* Scratch window *)
2330 class scratch_window =
2333 ~title:"MathML viewer"
2334 ~border_width:2 () in
2336 GPack.vbox ~packing:window#add () in
2338 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2340 GButton.button ~label:"Whd"
2341 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2343 GButton.button ~label:"Reduce"
2344 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2346 GButton.button ~label:"Simpl"
2347 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2348 let scrolled_window =
2349 GBin.scrolled_window ~border_width:10
2350 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2351 let sequent_viewer =
2352 TermViewer.sequent_viewer
2353 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2355 val mutable term = Cic.Rel 1 (* dummy value *)
2356 val mutable context = ([] : Cic.context) (* dummy value *)
2357 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2358 method sequent_viewer = sequent_viewer
2359 method show () = window#misc#hide () ; window#show ()
2361 method set_term t = term <- t
2362 method context = context
2363 method set_context t = context <- t
2364 method metasenv = metasenv
2365 method set_metasenv t = metasenv <- t
2368 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2369 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2370 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2371 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2372 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2375 let open_contextual_menu_for_selected_terms mmlwidget infos =
2376 let button = GdkEvent.Button.button infos in
2377 let terms_selected = List.length mmlwidget#get_selections > 0 in
2380 let time = GdkEvent.Button.time infos in
2381 let menu = GMenu.menu () in
2382 let f = new GMenu.factory menu in
2384 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2385 let reduce_menu_item =
2386 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2387 let simpl_menu_item =
2388 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2389 let _ = f#add_separator () in
2390 let generalize_menu_item =
2391 f#add_item "Generalize"
2392 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2393 let _ = f#add_separator () in
2394 let clear_menu_item =
2395 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2396 let clearbody_menu_item =
2397 f#add_item "ClearBody"
2398 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2400 whd_menu_item#misc#set_sensitive terms_selected ;
2401 reduce_menu_item#misc#set_sensitive terms_selected ;
2402 simpl_menu_item#misc#set_sensitive terms_selected ;
2403 generalize_menu_item#misc#set_sensitive terms_selected ;
2404 clear_menu_item#misc#set_sensitive terms_selected ;
2405 clearbody_menu_item#misc#set_sensitive terms_selected ;
2406 menu#popup ~button ~time
2412 let vbox1 = GPack.vbox () in
2414 val mutable proofw_ref = None
2415 val mutable compute_ref = None
2417 Lazy.force self#compute ;
2418 match proofw_ref with
2419 None -> assert false
2420 | Some proofw -> proofw
2421 method content = vbox1
2423 match compute_ref with
2424 None -> assert false
2425 | Some compute -> compute
2429 let scrolled_window1 =
2430 GBin.scrolled_window ~border_width:10
2431 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2433 TermViewer.sequent_viewer ~width:400 ~height:275
2434 ~packing:(scrolled_window1#add) () in
2435 let _ = proofw_ref <- Some proofw in
2437 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2439 GButton.button ~label:"Ring"
2440 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2442 GButton.button ~label:"Fourier"
2443 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2445 GButton.button ~label:"Reflexivity"
2446 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2448 GButton.button ~label:"Symmetry"
2449 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2451 GButton.button ~label:"Assumption"
2452 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2453 let contradictionb =
2454 GButton.button ~label:"Contradiction"
2455 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2457 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2459 GButton.button ~label:"Exists"
2460 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2462 GButton.button ~label:"Split"
2463 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2465 GButton.button ~label:"Left"
2466 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2468 GButton.button ~label:"Right"
2469 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2470 let searchpatternb =
2471 GButton.button ~label:"SearchPattern_Apply"
2472 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2474 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2476 GButton.button ~label:"Exact"
2477 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2479 GButton.button ~label:"Intros"
2480 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2482 GButton.button ~label:"Apply"
2483 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2484 let elimintrossimplb =
2485 GButton.button ~label:"ElimIntrosSimpl"
2486 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2488 GButton.button ~label:"ElimType"
2489 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2491 GButton.button ~label:"Fold_whd"
2492 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2494 GButton.button ~label:"Fold_reduce"
2495 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2497 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2499 GButton.button ~label:"Fold_simpl"
2500 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2502 GButton.button ~label:"Cut"
2503 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2505 GButton.button ~label:"Change"
2506 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2508 GButton.button ~label:"Let ... In"
2509 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2511 GButton.button ~label:"RewriteSimpl ->"
2512 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2513 let rewritebacksimplb =
2514 GButton.button ~label:"RewriteSimpl <-"
2515 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2517 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2519 GButton.button ~label:"Absurd"
2520 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2522 GButton.button ~label:"Decompose"
2523 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2525 GButton.button ~label:"Transitivity"
2526 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2528 GButton.button ~label:"Replace"
2529 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2531 GButton.button ~label:"Injection"
2532 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2534 GButton.button ~label:"Discriminate"
2535 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2536 (* Zack: spostare in una toolbar
2538 GButton.button ~label:"Generalize"
2539 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2541 GButton.button ~label:"ClearBody"
2542 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2544 GButton.button ~label:"Clear"
2545 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2547 GButton.button ~label:"Whd"
2548 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2550 GButton.button ~label:"Reduce"
2551 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2553 GButton.button ~label:"Simpl"
2554 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2557 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2558 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2559 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2560 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2561 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2562 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2563 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2564 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2565 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2566 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2567 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2568 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2569 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2570 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2571 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2572 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2573 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2574 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2575 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2576 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2577 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2578 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2579 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2580 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2581 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2582 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2583 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2584 ignore(searchpatternb#connect#clicked searchPattern) ;
2585 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2586 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2587 (* Zack: spostare in una toolbar
2588 ignore(whdb#connect#clicked whd) ;
2589 ignore(reduceb#connect#clicked reduce) ;
2590 ignore(simplb#connect#clicked simpl) ;
2591 ignore(clearbodyb#connect#clicked clearbody) ;
2592 ignore(clearb#connect#clicked clear) ;
2593 ignore(generalizeb#connect#clicked generalize) ;
2595 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2597 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2598 (open_contextual_menu_for_selected_terms proofw)) ;
2604 let vbox1 = GPack.vbox () in
2605 let scrolled_window1 =
2606 GBin.scrolled_window ~border_width:10
2607 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2609 TermViewer.sequent_viewer ~width:400 ~height:275
2610 ~packing:(scrolled_window1#add) () in
2612 method proofw = (assert false : TermViewer.sequent_viewer)
2613 method content = vbox1
2614 method compute = (assert false : unit)
2618 let empty_page = new empty_page;;
2622 val notebook = GPack.notebook ()
2624 val mutable skip_switch_page_event = false
2625 val mutable empty = true
2626 method notebook = notebook
2628 let new_page = new page () in
2630 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2631 notebook#append_page
2632 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2633 new_page#content#coerce
2634 method remove_all_pages ~skip_switch_page_event:skip =
2636 notebook#remove_page 0 (* let's remove the empty page *)
2638 List.iter (function _ -> notebook#remove_page 0) !pages ;
2640 skip_switch_page_event <- skip
2641 method set_current_page ~may_skip_switch_page_event n =
2642 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2643 let new_page = notebook#page_num page#content#coerce in
2644 if may_skip_switch_page_event && new_page <> notebook#current_page then
2645 skip_switch_page_event <- true ;
2646 notebook#goto_page new_page
2647 method set_empty_page =
2650 notebook#append_page
2651 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2652 empty_page#content#coerce
2654 let (_,_,page) = List.nth !pages notebook#current_page in
2658 (notebook#connect#switch_page
2660 let skip = skip_switch_page_event in
2661 skip_switch_page_event <- false ;
2664 let (metano,setgoal,page) = List.nth !pages i in
2665 set_proof_engine_goal (Some metano) ;
2666 Lazy.force (page#compute) ;
2668 if notify_hbugs_on_goal_change then
2669 (*Hbugs.notify *) ()
2675 let dump_environment () =
2677 let oc = open_out environmentfile in
2678 output_html (outputhtml ()) (`Msg (`T "Dumping environment ..."));
2679 CicEnvironment.dump_to_channel
2680 ~callback:(fun uri -> output_html (outputhtml ()) (`Msg (`T uri)))
2682 output_html (outputhtml ()) (`Msg (`T "... done!")) ;
2685 output_html (outputhtml ())
2686 (`Error (`T (Printf.sprintf
2687 "<h1 color=\"red\">Dump failure, uncaught exception:%s</h1>"
2688 (Printexc.to_string exc))))
2690 let restore_environment () =
2692 let ic = open_in environmentfile in
2693 output_html (outputhtml ()) (`Msg (`L [`T "Restoring environment ... " ; `BR]));
2694 CicEnvironment.restore_from_channel
2695 ~callback:(fun uri -> output_html (outputhtml ()) (`Msg (`L [`T uri ; `BR])))
2697 output_html (outputhtml ()) (`Msg (`T "... done!"));
2700 output_html (outputhtml ())
2701 (`Error (`T (Printf.sprintf
2702 "<h1 color=\"red\">Restore failure, uncaught exception:%s</h1>"
2703 (Printexc.to_string exc))))
2706 (* HTML simulator (first in its kind) *)
2710 | `L of log_msg list
2715 class logger ~width ~height ~packing ~show () =
2716 let scrolled_window =
2717 GBin.scrolled_window ~packing ~show () in
2718 let vadj = scrolled_window#vadjustment in
2720 GText.view ~editable:false ~cursor_visible:false
2721 ~width ~height ~packing:(scrolled_window#add) () in
2723 tv#buffer#create_tag
2724 [`FOREGROUND_SET true ;
2726 (Gdk.Color.alloc (Gdk.Color.get_system_colormap ()) (`NAME "green"))] in
2728 tv#buffer#create_tag
2729 [`FOREGROUND_SET true ;
2731 (Gdk.Color.alloc (Gdk.Color.get_system_colormap ()) (`NAME "red"))] in
2733 method log (m : [`Msg of log_msg | `Error of log_msg]) =
2734 let process_msg tags =
2737 `T s -> tv#buffer#insert ~tags s
2738 | `L l -> List.iter aux l
2739 | `BR -> tv#buffer#insert ~tags "\n"
2745 `Msg m -> process_msg [green] m
2746 | `Error m -> process_msg [red] m
2748 vadj#set_value (vadj#upper)
2754 class rendering_window output (notebook : notebook) =
2755 let scratch_window = new scratch_window in
2758 ~title:"gTopLevel - Helm's Proof Assistant"
2759 ~border_width:0 ~allow_shrink:false () in
2760 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2762 let handle_box = GBin.handle_box ~border_width:2
2763 ~packing:(vbox_for_menu#pack ~padding:0) () in
2764 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2765 let factory0 = new GMenu.factory menubar in
2766 let accel_group = factory0#accel_group in
2768 let file_menu = factory0#add_submenu "File" in
2769 let factory1 = new GMenu.factory file_menu ~accel_group in
2770 (* let export_to_postscript_menu_item = *)
2774 factory1#add_item "New Block of (Co)Inductive Definitions..."
2775 ~key:GdkKeysyms._B ~callback:new_inductive
2778 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2781 let reopen_menu_item =
2782 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2786 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2787 ignore (factory1#add_separator ()) ;
2789 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2790 ~callback:load_unfinished_proof) ;
2791 let save_menu_item =
2792 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2793 ~callback:save_unfinished_proof
2795 ignore (factory1#add_separator ()) ;
2796 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2797 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2799 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2801 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2802 ignore (!save_set_sensitive false);
2803 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2804 ignore (!qed_set_sensitive false);
2805 ignore (factory1#add_separator ()) ;
2807 let export_to_postscript_menu_item =
2808 factory1#add_item "Export to PostScript..."
2809 ~callback:(export_to_postscript output) in
2811 ignore (factory1#add_separator ()) ;
2813 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2814 export_to_postscript_menu_item *)
2817 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2818 let factory2 = new GMenu.factory edit_menu ~accel_group in
2819 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2820 let proveit_menu_item =
2821 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2822 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2824 let focus_menu_item =
2825 factory2#add_item "Focus" ~key:GdkKeysyms._F
2826 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2829 focus_and_proveit_set_sensitive :=
2831 proveit_menu_item#misc#set_sensitive b ;
2832 focus_menu_item#misc#set_sensitive b
2834 let _ = !focus_and_proveit_set_sensitive false in
2835 (* edit term menu *)
2836 let edit_term_menu = factory0#add_submenu "Edit Term" in
2837 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2838 let check_menu_item =
2839 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2840 ~callback:(check scratch_window) in
2841 let _ = check_menu_item#misc#set_sensitive false in
2843 let search_menu = factory0#add_submenu "Search" in
2844 let factory4 = new GMenu.factory search_menu ~accel_group in
2846 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2848 let searchPattern_menu_item =
2849 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2850 ~callback:completeSearchPattern in
2851 let _ = searchPattern_menu_item#misc#set_sensitive false in
2852 let show_menu_item =
2853 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2855 let insert_query_item =
2856 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2857 ~callback:insertQuery in
2859 let hbugs_menu = factory0#add_submenu "HBugs" in
2860 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2862 factory6#add_check_item
2863 ~active:false ~key:GdkKeysyms._F5 ~callback:(*Hbugs.toggle*)(fun _ -> ()) "HBugs enabled"
2866 factory6#add_item ~key:GdkKeysyms._Return ~callback:(*Hbugs.notify*)(fun _ -> ())
2867 "(Re)Submit status!"
2869 let _ = factory6#add_separator () in
2871 factory6#add_item ~callback:(*Hbugs.start_web_services*)(fun _ -> ()) "Start Web Services"
2874 factory6#add_item ~callback:(*Hbugs.stop_web_services*)(fun _ -> ()) "Stop Web Services"
2877 let settings_menu = factory0#add_submenu "Settings" in
2878 let factory3 = new GMenu.factory settings_menu ~accel_group in
2880 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2881 ~callback:edit_aliases in
2882 let _ = factory3#add_separator () in
2884 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2885 ~callback:(function _ -> (settings_window ())#show ()) in
2886 let _ = factory3#add_separator () in
2888 factory3#add_item "Reload Stylesheets"
2891 ApplyStylesheets.reload_stylesheets () ;
2892 if ProofEngine.get_proof () <> None then
2894 refresh_goals notebook ;
2895 refresh_proof output
2897 InvokeTactics.RefreshSequentException e ->
2898 output_html (outputhtml ())
2899 (`Error (`T ("An error occurred while refreshing the " ^
2900 "sequent: " ^ Printexc.to_string e))) ;
2901 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2902 notebook#set_empty_page
2903 | InvokeTactics.RefreshProofException e ->
2904 output_html (outputhtml ())
2905 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2909 let _ = window#add_accel_group accel_group in
2913 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2915 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2916 let scrolled_window0 =
2917 GBin.scrolled_window ~border_width:10
2918 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2919 let _ = scrolled_window0#add output#coerce in
2921 GBin.frame ~label:"Insert Term"
2922 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2923 let scrolled_window1 =
2924 GBin.scrolled_window ~border_width:5
2925 ~packing:frame#add () in
2927 TexTermEditor'.term_editor
2929 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2930 ~isnotempty_callback:
2932 check_menu_item#misc#set_sensitive b ;
2933 searchPattern_menu_item#misc#set_sensitive b) in
2935 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2937 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2939 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2943 ~width:400 ~height: 100
2947 method outputhtml = outputhtml
2948 method inputt = inputt
2949 method output = (output : TermViewer.proof_viewer)
2950 method scratch_window = scratch_window
2951 method notebook = notebook
2952 method show = window#show
2954 notebook#set_empty_page ;
2955 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2956 check_term := (check_term_in_scratch scratch_window) ;
2958 (* signal handlers here *)
2959 ignore(output#connect#selection_changed
2961 choose_selection output elem ;
2962 !focus_and_proveit_set_sensitive true
2964 ignore (output#connect#click (show_in_show_window_callback output)) ;
2965 let settings_window = new settings_window output scrolled_window0
2966 (*export_to_postscript_menu_item*)() (choose_selection output) in
2967 set_settings_window settings_window ;
2968 set_outputhtml outputhtml ;
2969 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2970 Logger.log_callback :=
2972 ~print_and_flush:(fun m -> (output_html outputhtml (`Msg (`T m)))))
2977 let initialize_everything () =
2978 let module U = Unix in
2979 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2980 let notebook = new notebook in
2981 let rendering_window' = new rendering_window output notebook in
2982 set_rendering_window rendering_window' ;
2983 let print_error_as_html prefix msg =
2984 output_html (outputhtml ()) (`Error (`T (prefix ^ msg)))
2986 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2987 Gdome_xslt.setDebugCallback
2988 (Some (print_error_as_html "XSLT Debug Message: "));
2989 rendering_window'#show () ;
2990 if restore_environment_on_boot && Sys.file_exists environmentfile then
2991 restore_environment ();
2996 ignore (GtkMain.Main.init ()) ;
2997 initialize_everything () ;
2998 MQIC.close mqi_handle(*;
3003 Sys.catch_break true;
3005 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)