1 (* Copyright (C) 2000-2002, 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 (******************************************************************************)
42 let log s = prerr_string s
45 module MQI = MQueryInterpreter.Make(MQICallbacks)
47 (* GLOBAL CONSTANTS *)
49 let mqi_options = "" (* default MathQL interpreter options *)
51 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
55 " <body bgColor=\"white\">"
65 Sys.getenv "GTOPLEVEL_PROOFFILE"
67 Not_found -> "/public/currentproof"
72 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
74 Not_found -> "/public/currentprooftype"
77 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
79 let htmlheader_and_content = ref htmlheader;;
81 let check_term = ref (fun _ _ _ -> assert false);;
83 exception RenderingWindowsNotInitialized;;
85 let set_rendering_window,rendering_window =
86 let rendering_window_ref = ref None in
87 (function rw -> rendering_window_ref := Some rw),
89 match !rendering_window_ref with
90 None -> raise RenderingWindowsNotInitialized
95 exception SettingsWindowsNotInitialized;;
97 let set_settings_window,settings_window =
98 let settings_window_ref = ref None in
99 (function rw -> settings_window_ref := Some rw),
101 match !settings_window_ref with
102 None -> raise SettingsWindowsNotInitialized
107 exception OutputHtmlNotInitialized;;
109 let set_outputhtml,outputhtml =
110 let outputhtml_ref = ref None in
111 (function rw -> outputhtml_ref := Some rw),
113 match !outputhtml_ref with
114 None -> raise OutputHtmlNotInitialized
115 | Some outputhtml -> outputhtml
119 exception QedSetSensitiveNotInitialized;;
120 let qed_set_sensitive =
121 ref (function _ -> raise QedSetSensitiveNotInitialized)
124 exception SaveSetSensitiveNotInitialized;;
125 let save_set_sensitive =
126 ref (function _ -> raise SaveSetSensitiveNotInitialized)
129 (* COMMAND LINE OPTIONS *)
135 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
138 Arg.parse argspec ignore ""
142 let term_of_cic_textual_parser_uri uri =
143 let module C = Cic in
144 let module CTP = CicTextualParser0 in
146 CTP.ConUri uri -> C.Const (uri,[])
147 | CTP.VarUri uri -> C.Var (uri,[])
148 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
149 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
152 let string_of_cic_textual_parser_uri uri =
153 let module C = Cic in
154 let module CTP = CicTextualParser0 in
157 CTP.ConUri uri -> UriManager.string_of_uri uri
158 | CTP.VarUri uri -> UriManager.string_of_uri uri
159 | CTP.IndTyUri (uri,tyno) ->
160 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
161 | CTP.IndConUri (uri,tyno,consno) ->
162 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
165 (* 4 = String.length "cic:" *)
166 String.sub uri' 4 (String.length uri' - 4)
169 let output_html outputhtml msg =
170 htmlheader_and_content := !htmlheader_and_content ^ msg ;
171 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
172 outputhtml#set_topline (-1)
175 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
179 let check_window outputhtml uris =
182 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
184 GPack.notebook ~scrollable:true ~packing:window#add () in
189 let scrolled_window =
190 GBin.scrolled_window ~border_width:10
192 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
197 TermViewer.sequent_viewer
198 ~packing:scrolled_window#add ~width:400 ~height:280 () in
201 term_of_cic_textual_parser_uri
202 (MQueryMisc.cic_textual_parser_uri_of_string uri)
204 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
207 mmlwidget#load_sequent [] (111,[],expr)
210 output_html outputhtml
211 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
216 (notebook#connect#switch_page
217 (function i -> Lazy.force (List.nth render_terms i)))
223 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
224 ?(enable_button_for_non_vars=false) ~title ~msg uris
226 let choices = ref [] in
227 let chosen = ref false in
228 let use_only_constants = ref false in
230 GWindow.dialog ~modal:true ~title ~width:600 () in
232 GMisc.label ~text:msg
233 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
234 let scrolled_window =
235 GBin.scrolled_window ~border_width:10
236 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
238 let expected_height = 18 * List.length uris in
239 let height = if expected_height > 400 then 400 else expected_height in
240 GList.clist ~columns:1 ~packing:scrolled_window#add
241 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
242 let _ = List.map (function x -> clist#append [x]) uris in
244 GPack.hbox ~border_width:0
245 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
247 GMisc.label ~text:"None of the above. Try this one:"
248 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
250 GEdit.entry ~editable:true
251 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
253 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
255 GButton.button ~label:ok
256 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
257 let _ = okb#misc#set_sensitive false in
262 if enable_button_for_non_vars then
263 hbox#pack ~expand:false ~fill:false ~padding:5 w)
264 ~label:"Try constants only" () in
266 GButton.button ~label:"Check"
267 ~packing:(hbox#pack ~padding:5) () in
268 let _ = checkb#misc#set_sensitive false in
270 GButton.button ~label:"Abort"
271 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
273 let check_callback () =
274 assert (List.length !choices > 0) ;
275 check_window (outputhtml ()) !choices
277 ignore (window#connect#destroy GMain.Main.quit) ;
278 ignore (cancelb#connect#clicked window#destroy) ;
280 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
282 (nonvarsb#connect#clicked
284 use_only_constants := true ;
288 ignore (checkb#connect#clicked check_callback) ;
290 (clist#connect#select_row
291 (fun ~row ~column ~event ->
292 checkb#misc#set_sensitive true ;
293 okb#misc#set_sensitive true ;
294 choices := (List.nth uris row)::!choices)) ;
296 (clist#connect#unselect_row
297 (fun ~row ~column ~event ->
299 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
301 (manual_input#connect#changed
303 if manual_input#text = "" then
306 checkb#misc#set_sensitive false ;
307 okb#misc#set_sensitive false ;
308 clist#misc#set_sensitive true
312 choices := [manual_input#text] ;
313 clist#unselect_all () ;
314 checkb#misc#set_sensitive true ;
315 okb#misc#set_sensitive true ;
316 clist#misc#set_sensitive false
318 window#set_position `CENTER ;
322 if !use_only_constants then
324 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
327 if List.length !choices > 0 then !choices else raise NoChoice
332 let interactive_interpretation_choice interpretations =
333 let chosen = ref None in
336 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
337 let vbox = GPack.vbox ~packing:window#add () in
341 ("Ambiguous input since there are many well-typed interpretations." ^
342 " Please, choose one of them.")
343 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
345 GPack.notebook ~scrollable:true
346 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
349 (function interpretation ->
351 let expected_height = 18 * List.length interpretation in
352 let height = if expected_height > 400 then 400 else expected_height in
353 GList.clist ~columns:2 ~packing:notebook#append_page ~height
354 ~titles:["id" ; "URI"] ()
358 (function (id,uri) ->
359 let n = clist#append [id;uri] in
360 clist#set_row ~selectable:false n
363 clist#columns_autosize ()
366 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
368 GButton.button ~label:"Ok"
369 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
371 GButton.button ~label:"Abort"
372 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
374 ignore (window#connect#destroy GMain.Main.quit) ;
375 ignore (cancelb#connect#clicked window#destroy) ;
378 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
379 window#set_position `CENTER ;
383 None -> raise NoChoice
390 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
391 (* FG : THIS FUNCTION IS BECOMING A REAL NONSENSE *)
393 let query = ref "" in
394 let out s = query := ! query ^ s in
395 MQueryGenerator.set_confirm_query
397 query := ""; MQueryUtil.text_of_query out q ""; true);
399 out (!query ^ " <h1>Result:</h1> "); MQueryUtil.text_of_result out result "<br>";
404 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
407 let struri = UriManager.string_of_uri uri in
408 let idx = (String.rindex struri '/') + 1 in
409 String.sub struri idx (String.length struri - idx)
411 let path = pathname ^ "/" ^ name in
413 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
417 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
418 ~ask_dtd_to_the_getter:false
421 let innertypesuri = UriManager.innertypesuri_of_uri uri in
422 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
423 Getter.register innertypesuri
424 (Configuration.annotations_url ^
425 Str.replace_first (Str.regexp "^cic:") ""
426 (UriManager.string_of_uri innertypesuri) ^ ".xml"
428 (* constant type / variable / mutual inductive types definition *)
429 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
431 (Configuration.annotations_url ^
432 Str.replace_first (Str.regexp "^cic:") ""
433 (UriManager.string_of_uri uri) ^ ".xml"
440 match UriManager.bodyuri_of_uri uri with
442 | Some bodyuri -> bodyuri
444 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
445 Getter.register bodyuri
446 (Configuration.annotations_url ^
447 Str.replace_first (Str.regexp "^cic:") ""
448 (UriManager.string_of_uri bodyuri) ^ ".xml"
455 exception OpenConjecturesStillThere;;
456 exception WrongProof;;
458 let pathname_of_annuri uristring =
459 Configuration.annotations_dir ^
460 Str.replace_first (Str.regexp "^cic:") "" uristring
463 let make_dirs dirpath =
464 ignore (Unix.system ("mkdir -p " ^ dirpath))
467 let save_obj uri obj =
469 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
470 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
472 Cic2acic.acic_object_of_cic_object obj
474 (* let's save the theorem and register it to the getter *)
475 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
477 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
482 match !ProofEngine.proof with
484 | Some (uri,[],bo,ty) ->
486 CicReduction.are_convertible []
487 (CicTypeChecker.type_of_aux' [] [] bo) ty
490 (*CSC: Wrong: [] is just plainly wrong *)
491 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
492 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
493 (rendering_window ())#output#load_proof uri proof
495 !qed_set_sensitive false ;
496 (* let's save the theorem and register it to the getter *)
497 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
499 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
504 | _ -> raise OpenConjecturesStillThere
507 (** save an unfinished proof on the filesystem *)
508 let save_unfinished_proof () =
509 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
510 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
511 Xml.pp ~quiet:true xml (Some prooffiletype) ;
512 output_html outputhtml
513 ("<h1 color=\"Green\">Current proof type saved to " ^
514 prooffiletype ^ "</h1>") ;
515 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
516 output_html outputhtml
517 ("<h1 color=\"Green\">Current proof body saved to " ^
521 (* Used to typecheck the loaded proofs *)
522 let typecheck_loaded_proof metasenv bo ty =
523 let module T = CicTypeChecker in
526 (fun metasenv ((_,context,ty) as conj) ->
527 ignore (T.type_of_aux' metasenv context ty) ;
530 ignore (T.type_of_aux' metasenv [] ty) ;
531 ignore (T.type_of_aux' metasenv [] bo)
534 let decompose_uris_choice_callback uris =
535 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
536 let module U = UriManager in
539 match MQueryMisc.cic_textual_parser_uri_of_string uri with
540 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
542 (interactive_user_uri_choice
543 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
544 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
546 (function (uri,typeno,_) ->
547 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
552 let mk_fresh_name_callback context name ~typ =
554 match ProofEngineHelpers.mk_fresh_name context name ~typ with
555 Cic.Name fresh_name -> fresh_name
556 | Cic.Anonymous -> assert false
559 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
560 ("Enter a fresh name for the hypothesis " ^
562 (List.map (function None -> None | Some (n,_) -> Some n) context))
564 Some fresh_name' -> Cic.Name fresh_name'
565 | None -> raise NoChoice
568 let refresh_proof (output : TermViewer.proof_viewer) =
570 let uri,currentproof =
571 match !ProofEngine.proof with
573 | Some (uri,metasenv,bo,ty) ->
574 if List.length metasenv = 0 then
576 !qed_set_sensitive true ;
577 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.clear ()" ;
582 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.notify ()" ;
585 (*CSC: Wrong: [] is just plainly wrong *)
587 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
589 ignore (output#load_proof uri currentproof)
592 match !ProofEngine.proof with
594 | Some (uri,metasenv,bo,ty) ->
595 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
596 raise (InvokeTactics.RefreshProofException e)
598 let refresh_goals ?(empty_notebook=true) notebook =
600 match !ProofEngine.goal with
602 if empty_notebook then
604 notebook#remove_all_pages ~skip_switch_page_event:false ;
605 notebook#set_empty_page
608 notebook#proofw#unload
611 match !ProofEngine.proof with
613 | Some (_,metasenv,_,_) -> metasenv
616 List.find (function (m,_,_) -> m=metano) metasenv
618 let regenerate_notebook () =
619 let skip_switch_page_event =
621 (m,_,_)::_ when m = metano -> false
624 notebook#remove_all_pages ~skip_switch_page_event ;
625 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
627 if empty_notebook then
629 regenerate_notebook () ;
630 notebook#set_current_page
631 ~may_skip_switch_page_event:false metano
635 notebook#set_current_page
636 ~may_skip_switch_page_event:true metano ;
637 notebook#proofw#load_sequent metasenv currentsequent
642 match !ProofEngine.goal with
647 match !ProofEngine.proof with
649 | Some (_,metasenv,_,_) -> metasenv
652 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
653 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
654 raise (InvokeTactics.RefreshSequentException e)
655 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unknown."); raise (InvokeTactics.RefreshSequentException e)
657 module InvokeTacticsCallbacks =
659 let sequent_viewer () = (rendering_window ())#notebook#proofw
660 let term_editor () = (rendering_window ())#inputt
661 let scratch_window () = (rendering_window ())#scratch_window
663 let refresh_proof () =
664 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
667 let refresh_goals () =
668 let notebook = (rendering_window ())#notebook in
669 refresh_goals notebook
671 let decompose_uris_choice_callback = decompose_uris_choice_callback
672 let mk_fresh_name_callback = mk_fresh_name_callback
673 let output_html msg = output_html (outputhtml ()) msg
676 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
677 (* Just to initialize the Hbugs module *)
678 module Ignore = Hbugs.Initialize (InvokeTactics');;
680 (** load an unfinished proof from filesystem *)
681 let load_unfinished_proof () =
682 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
683 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
684 let notebook = (rendering_window ())#notebook in
687 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
690 None -> raise NoChoice
692 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
693 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
694 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
695 typecheck_loaded_proof metasenv bo ty ;
697 Some (uri, metasenv, bo, ty) ;
701 | (metano,_,_)::_ -> Some metano
703 refresh_proof output ;
704 refresh_goals notebook ;
705 output_html outputhtml
706 ("<h1 color=\"Green\">Current proof type loaded from " ^
707 prooffiletype ^ "</h1>") ;
708 output_html outputhtml
709 ("<h1 color=\"Green\">Current proof body loaded from " ^
710 prooffile ^ "</h1>") ;
711 !save_set_sensitive true;
714 InvokeTactics.RefreshSequentException e ->
715 output_html outputhtml
716 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
717 "sequent: " ^ Printexc.to_string e ^ "</h1>")
718 | InvokeTactics.RefreshProofException e ->
719 output_html outputhtml
720 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
721 "proof: " ^ Printexc.to_string e ^ "</h1>")
723 output_html outputhtml
724 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
727 let edit_aliases () =
728 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
729 let id_to_uris = inputt#id_to_uris in
730 let chosen = ref false in
733 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
735 GPack.vbox ~border_width:0 ~packing:window#add () in
736 let scrolled_window =
737 GBin.scrolled_window ~border_width:10
738 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
739 let input = GEdit.text ~editable:true ~width:400 ~height:100
740 ~packing:scrolled_window#add () in
742 GPack.hbox ~border_width:0
743 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
745 GButton.button ~label:"Ok"
746 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
748 GButton.button ~label:"Cancel"
749 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
750 ignore (window#connect#destroy GMain.Main.quit) ;
751 ignore (cancelb#connect#clicked window#destroy) ;
753 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
754 let dom,resolve_id = !id_to_uris in
756 (input#insert_text ~pos:0
761 match resolve_id v with
763 | Some (CicTextualParser0.Uri uri) -> uri
764 | Some (CicTextualParser0.Term _)
765 | Some CicTextualParser0.Implicit -> assert false
769 CicTextualParser0.Id id -> id
770 | CicTextualParser0.Symbol (descr,_) ->
771 (* CSC: To be implemented *)
773 )^ " " ^ (string_of_cic_textual_parser_uri uri)
779 let inputtext = input#get_chars 0 input#length in
781 let alfa = "[a-zA-Z_-]" in
782 let digit = "[0-9]" in
783 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
784 let blanks = "\( \|\t\|\n\)+" in
785 let nonblanks = "[^ \t\n]+" in
786 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
788 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
792 let n' = Str.search_forward regexpr inputtext n in
793 let id = CicTextualParser0.Id (Str.matched_group 2 inputtext) in
795 MQueryMisc.cic_textual_parser_uri_of_string
796 ("cic:" ^ (Str.matched_group 5 inputtext))
798 let dom,resolve_id = aux (n' + 1) in
799 if List.mem id dom then
805 Some (CicTextualParser0.Uri uri)
808 Not_found -> TermEditor.empty_id_to_uris
812 id_to_uris := (dom,resolve_id)
816 let module L = LogicalOperations in
817 let module G = Gdome in
818 let notebook = (rendering_window ())#notebook in
819 let output = (rendering_window ())#output in
820 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
822 output#make_sequent_of_selected_term ;
823 refresh_proof output ;
824 refresh_goals notebook
826 InvokeTactics.RefreshSequentException e ->
827 output_html outputhtml
828 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
829 "sequent: " ^ Printexc.to_string e ^ "</h1>")
830 | InvokeTactics.RefreshProofException e ->
831 output_html outputhtml
832 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
833 "proof: " ^ Printexc.to_string e ^ "</h1>")
835 output_html outputhtml
836 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
840 let module L = LogicalOperations in
841 let module G = Gdome in
842 let notebook = (rendering_window ())#notebook in
843 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
844 let output = (rendering_window ())#output in
846 output#focus_sequent_of_selected_term ;
847 refresh_goals notebook
849 InvokeTactics.RefreshSequentException e ->
850 output_html outputhtml
851 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
852 "sequent: " ^ Printexc.to_string e ^ "</h1>")
853 | InvokeTactics.RefreshProofException e ->
854 output_html outputhtml
855 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
856 "proof: " ^ Printexc.to_string e ^ "</h1>")
858 output_html outputhtml
859 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
862 exception NoPrevGoal;;
863 exception NoNextGoal;;
866 let module L = LogicalOperations in
867 let module G = Gdome in
868 let notebook = (rendering_window ())#notebook in
869 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
871 match !ProofEngine.proof with
873 | Some (_,metasenv,_,_) -> metasenv
876 refresh_goals ~empty_notebook:false notebook
878 InvokeTactics.RefreshSequentException e ->
879 output_html outputhtml
880 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
881 "sequent: " ^ Printexc.to_string e ^ "</h1>")
883 output_html outputhtml
884 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
888 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
891 GWindow.window ~width:800 ~border_width:2 () in
892 let scrolled_window =
893 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
895 GMathViewAux.single_selection_math_view
896 ~packing:scrolled_window#add ~width:600 ~height:400 ()
898 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
899 let href = Gdome.domString "href" in
900 let show_in_show_window_obj uri obj =
901 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
904 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
905 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
907 Cic2acic.acic_object_of_cic_object obj
910 ApplyStylesheets.mml_of_cic_object
911 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
913 window#set_title (UriManager.string_of_uri uri) ;
914 window#misc#hide () ; window#show () ;
915 mmlwidget#load_doc mml ;
918 output_html outputhtml
919 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
921 let show_in_show_window_uri uri =
922 let obj = CicEnvironment.get_obj uri in
923 show_in_show_window_obj uri obj
925 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
929 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
931 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
933 show_in_show_window_uri (UriManager.uri_of_string uri)
935 ignore (mmlwidget#action_toggle n')
938 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
940 show_in_show_window_obj, show_in_show_window_uri,
941 show_in_show_window_callback
944 exception NoObjectsLocated;;
946 let user_uri_choice ~title ~msg uris =
949 [] -> raise NoObjectsLocated
953 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
958 String.sub uri 4 (String.length uri - 4)
961 let locate_callback id =
962 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
963 let result = MQueryGenerator.locate id in
967 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
970 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
972 output_html outputhtml html ;
973 user_uri_choice ~title:"Ambiguous input."
975 ("Ambiguous input \"" ^ id ^
976 "\". Please, choose one interpetation:")
981 let input_or_locate_uri ~title =
982 let uri = ref None in
985 ~width:400 ~modal:true ~title ~border_width:2 () in
986 let vbox = GPack.vbox ~packing:window#add () in
988 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
990 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
992 GEdit.entry ~editable:true
993 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
995 GButton.button ~label:"Check"
996 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
997 let _ = checkb#misc#set_sensitive false in
999 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1001 GMisc.label ~text:"You can also enter an indentifier to locate:"
1002 ~packing:(hbox2#pack ~padding:5) () in
1004 GEdit.entry ~editable:true
1005 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1007 GButton.button ~label:"Locate"
1008 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1009 let _ = locateb#misc#set_sensitive false in
1011 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1013 GButton.button ~label:"Ok"
1014 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1015 let _ = okb#misc#set_sensitive false in
1017 GButton.button ~label:"Cancel"
1018 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1020 ignore (window#connect#destroy GMain.Main.quit) ;
1022 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1023 let check_callback () =
1024 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1025 let uri = "cic:" ^ manual_input#text in
1027 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1028 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1031 Getter.Unresolved ->
1032 output_html outputhtml
1033 ("<h1 color=\"Red\">URI " ^ uri ^
1034 " does not correspond to any object.</h1>") ;
1036 | UriManager.IllFormedUri _ ->
1037 output_html outputhtml
1038 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1041 output_html outputhtml
1042 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1046 (okb#connect#clicked
1048 if check_callback () then
1050 uri := Some manual_input#text ;
1054 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1056 (manual_input#connect#changed
1058 if manual_input#text = "" then
1060 checkb#misc#set_sensitive false ;
1061 okb#misc#set_sensitive false
1065 checkb#misc#set_sensitive true ;
1066 okb#misc#set_sensitive true
1069 (locate_input#connect#changed
1070 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1072 (locateb#connect#clicked
1074 let id = locate_input#text in
1075 manual_input#set_text (locate_callback id) ;
1076 locate_input#delete_text 0 (String.length id)
1081 None -> raise NoChoice
1082 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1085 exception AmbiguousInput;;
1087 (* A WIDGET TO ENTER CIC TERMS *)
1089 module ChosenTermEditor = TexTermEditor;;
1090 module ChosenTextualParser0 = TexCicTextualParser0;;
1092 module ChosenTermEditor = TermEditor;;
1093 module ChosenTextualParser0 = CicTextualParser0;;
1098 let get_metasenv () = !ChosenTextualParser0.metasenv
1099 let set_metasenv metasenv = ChosenTextualParser0.metasenv := metasenv
1101 let output_html msg = output_html (outputhtml ()) msg;;
1102 let interactive_user_uri_choice =
1103 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1104 interactive_user_uri_choice ~selection_mode ?ok
1105 ?enable_button_for_non_vars ~title ~msg;;
1106 let interactive_interpretation_choice = interactive_interpretation_choice;;
1107 let input_or_locate_uri = input_or_locate_uri;;
1111 module TexTermEditor' = ChosenTermEditor.Make(Callbacks);;
1113 (* OTHER FUNCTIONS *)
1116 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1117 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1120 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1122 None -> raise NoChoice
1124 let uri = locate_callback input in
1128 output_html outputhtml
1129 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1133 exception UriAlreadyInUse;;
1134 exception NotAUriToAConstant;;
1136 let new_inductive () =
1137 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1138 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1139 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1140 let notebook = (rendering_window ())#notebook in
1142 let chosen = ref false in
1143 let inductive = ref true in
1144 let paramsno = ref 0 in
1145 let get_uri = ref (function _ -> assert false) in
1146 let get_base_uri = ref (function _ -> assert false) in
1147 let get_names = ref (function _ -> assert false) in
1148 let get_types_and_cons = ref (function _ -> assert false) in
1149 let get_context_and_subst = ref (function _ -> assert false) in
1152 ~width:600 ~modal:true ~position:`CENTER
1153 ~title:"New Block of Mutual (Co)Inductive Definitions"
1154 ~border_width:2 () in
1155 let vbox = GPack.vbox ~packing:window#add () in
1157 GPack.hbox ~border_width:0
1158 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1160 GMisc.label ~text:"Enter the URI for the new block:"
1161 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1163 GEdit.entry ~editable:true
1164 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1166 GPack.hbox ~border_width:0
1167 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1171 "Enter the number of left parameters in every arity and constructor type:"
1172 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1173 let paramsno_entry =
1174 GEdit.entry ~editable:true ~text:"0"
1175 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1177 GPack.hbox ~border_width:0
1178 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1180 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1181 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1183 GButton.radio_button ~label:"Inductive"
1184 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1186 GButton.radio_button ~label:"Coinductive"
1187 ~group:inductiveb#group
1188 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1190 GPack.hbox ~border_width:0
1191 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1193 GMisc.label ~text:"Enter the list of the names of the types:"
1194 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1196 GEdit.entry ~editable:true
1197 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1199 GPack.hbox ~border_width:0
1200 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1202 GButton.button ~label:"> Next"
1203 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1204 let _ = okb#misc#set_sensitive true in
1206 GButton.button ~label:"Abort"
1207 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1208 ignore (window#connect#destroy GMain.Main.quit) ;
1209 ignore (cancelb#connect#clicked window#destroy) ;
1213 (okb#connect#clicked
1216 let uristr = "cic:" ^ uri_entry#text in
1217 let namesstr = names_entry#text in
1218 let paramsno' = int_of_string (paramsno_entry#text) in
1219 match Str.split (Str.regexp " +") namesstr with
1221 | (he::tl) as names ->
1222 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1225 ignore (Getter.resolve uri) ;
1226 raise UriAlreadyInUse
1228 Getter.Unresolved ->
1229 get_uri := (function () -> uri) ;
1230 get_names := (function () -> names) ;
1231 inductive := inductiveb#active ;
1232 paramsno := paramsno' ;
1237 output_html outputhtml
1238 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1246 GBin.frame ~label:name
1247 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1248 let vbox = GPack.vbox ~packing:frame#add () in
1249 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1251 GMisc.label ~text:("Enter its type:")
1252 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1253 let scrolled_window =
1254 GBin.scrolled_window ~border_width:5
1255 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1257 TexTermEditor'.term_editor
1258 ~width:400 ~height:20 ~packing:scrolled_window#add
1259 ~share_id_to_uris_with:inputt ()
1260 ~isnotempty_callback:
1262 (*non_empty_type := b ;*)
1263 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1266 GPack.hbox ~border_width:0
1267 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1269 GMisc.label ~text:("Enter the list of its constructors:")
1270 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1271 let cons_names_entry =
1272 GEdit.entry ~editable:true
1273 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1274 (newinputt,cons_names_entry)
1277 vbox#remove hboxn#coerce ;
1279 GPack.hbox ~border_width:0
1280 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1282 GButton.button ~label:"> Next"
1283 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1285 GButton.button ~label:"Abort"
1286 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1287 ignore (cancelb#connect#clicked window#destroy) ;
1289 (okb#connect#clicked
1292 let names = !get_names () in
1293 let types_and_cons =
1295 (fun name (newinputt,cons_names_entry) ->
1296 let consnamesstr = cons_names_entry#text in
1297 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1299 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1302 [] -> expr,cons_names
1303 | _ -> raise AmbiguousInput
1304 ) names type_widgets
1306 let uri = !get_uri () in
1308 (* Let's see if so far the definition is well-typed *)
1311 (* To test if the arities of the inductive types are well *)
1312 (* typed, we check the inductive block definition where *)
1313 (* no constructor is given to each type. *)
1316 (fun name (ty,cons) -> (name, !inductive, ty, []))
1317 names types_and_cons
1319 CicTypeChecker.typecheck_mutual_inductive_defs uri
1320 (tys,params,paramsno)
1322 get_context_and_subst :=
1326 (fun (context,subst) name (ty,_) ->
1328 (Some (Cic.Name name, Cic.Decl ty))::context,
1329 (Cic.MutInd (uri,!i,[]))::subst
1332 ) ([],[]) names types_and_cons) ;
1333 let types_and_cons' =
1335 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1336 names types_and_cons
1338 get_types_and_cons := (function () -> types_and_cons') ;
1343 output_html outputhtml
1344 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1347 and phase3 name cons =
1348 let get_cons_types = ref (function () -> assert false) in
1351 ~width:600 ~modal:true ~position:`CENTER
1352 ~title:(name ^ " Constructors")
1353 ~border_width:2 () in
1354 let vbox = GPack.vbox ~packing:window2#add () in
1355 let cons_type_widgets =
1357 (function consname ->
1359 GPack.hbox ~border_width:0
1360 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1362 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1363 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1364 let scrolled_window =
1365 GBin.scrolled_window ~border_width:5
1366 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1368 TexTermEditor'.term_editor
1369 ~width:400 ~height:20 ~packing:scrolled_window#add
1370 ~share_id_to_uris_with:inputt ()
1371 ~isnotempty_callback:
1373 (* (*non_empty_type := b ;*)
1374 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1379 GPack.hbox ~border_width:0
1380 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1382 GButton.button ~label:"> Next"
1383 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1384 let _ = okb#misc#set_sensitive true in
1386 GButton.button ~label:"Abort"
1387 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1388 ignore (window2#connect#destroy GMain.Main.quit) ;
1389 ignore (cancelb#connect#clicked window2#destroy) ;
1391 (okb#connect#clicked
1395 let context,subst= !get_context_and_subst () in
1400 inputt#get_metasenv_and_term ~context ~metasenv:[]
1404 let undebrujined_expr =
1406 (fun expr t -> CicSubstitution.subst t expr) expr subst
1408 name, undebrujined_expr
1409 | _ -> raise AmbiguousInput
1410 ) cons cons_type_widgets
1412 get_cons_types := (function () -> cons_types) ;
1416 output_html outputhtml
1417 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1421 let okb_pressed = !chosen in
1423 if (not okb_pressed) then
1426 assert false (* The control never reaches this point *)
1429 (!get_cons_types ())
1432 (* No more phases left or Abort pressed *)
1438 let uri = !get_uri () in
1441 let tys = !get_types_and_cons () in
1442 let obj = Cic.InductiveDefinition tys params !paramsno in
1445 prerr_endline (CicPp.ppobj obj) ;
1446 CicTypeChecker.typecheck_mutual_inductive_defs uri
1447 (tys,params,!paramsno) ;
1450 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1451 prerr_endline (CicPp.ppobj obj) ;
1453 (* We already know that obj is well-typed. We need to add it to the *)
1454 (* environment in order to compute the inner-types without having to *)
1455 (* debrujin it or having to modify lots of other functions to avoid *)
1456 (* asking the environment for the MUTINDs we are defining now. *)
1457 CicEnvironment.put_inductive_definition uri obj ;
1459 show_in_show_window_obj uri obj
1462 output_html outputhtml
1463 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1467 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1468 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1469 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1470 let notebook = (rendering_window ())#notebook in
1472 let chosen = ref false in
1473 let get_metasenv_and_term = ref (function _ -> assert false) in
1474 let get_uri = ref (function _ -> assert false) in
1475 let non_empty_type = ref false in
1478 ~width:600 ~modal:true ~title:"New Proof or Definition"
1479 ~border_width:2 () in
1480 let vbox = GPack.vbox ~packing:window#add () in
1482 GPack.hbox ~border_width:0
1483 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1485 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1486 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1488 GEdit.entry ~editable:true
1489 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1491 GPack.hbox ~border_width:0
1492 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1494 GMisc.label ~text:"Enter the theorem or definition type:"
1495 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1496 let scrolled_window =
1497 GBin.scrolled_window ~border_width:5
1498 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1499 (* the content of the scrolled_window is moved below (see comment) *)
1501 GPack.hbox ~border_width:0
1502 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1504 GButton.button ~label:"Ok"
1505 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1506 let _ = okb#misc#set_sensitive false in
1508 GButton.button ~label:"Cancel"
1509 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1510 (* moved here to have visibility of the ok button *)
1512 TexTermEditor'.term_editor ~width:400 ~height:100 ~packing:scrolled_window#add
1513 ~share_id_to_uris_with:inputt ()
1514 ~isnotempty_callback:
1516 non_empty_type := b ;
1517 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1520 newinputt#set_term inputt#get_as_string ;
1523 uri_entry#connect#changed
1525 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1527 ignore (window#connect#destroy GMain.Main.quit) ;
1528 ignore (cancelb#connect#clicked window#destroy) ;
1530 (okb#connect#clicked
1534 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1535 let uristr = "cic:" ^ uri_entry#text in
1536 let uri = UriManager.uri_of_string uristr in
1537 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1538 raise NotAUriToAConstant
1542 ignore (Getter.resolve uri) ;
1543 raise UriAlreadyInUse
1545 Getter.Unresolved ->
1546 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1547 get_uri := (function () -> uri) ;
1552 output_html outputhtml
1553 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1559 let metasenv,expr = !get_metasenv_and_term () in
1560 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1561 ProofEngine.proof :=
1562 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1563 ProofEngine.goal := Some 1 ;
1564 refresh_goals notebook ;
1565 refresh_proof output ;
1566 !save_set_sensitive true ;
1568 ProofEngine.intros ~mk_fresh_name_callback () ;
1569 refresh_goals notebook ;
1570 refresh_proof output
1572 InvokeTactics.RefreshSequentException e ->
1573 output_html outputhtml
1574 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1575 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1576 | InvokeTactics.RefreshProofException e ->
1577 output_html outputhtml
1578 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1579 "proof: " ^ Printexc.to_string e ^ "</h1>")
1581 output_html outputhtml
1582 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1585 let check_term_in_scratch scratch_window metasenv context expr =
1587 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1588 let expr = Cic.Cast (expr,ty) in
1589 scratch_window#show () ;
1590 scratch_window#set_term expr ;
1591 scratch_window#set_context context ;
1592 scratch_window#set_metasenv metasenv ;
1593 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1596 print_endline ("? " ^ CicPp.ppterm expr) ;
1600 let check scratch_window () =
1601 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1602 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1604 match !ProofEngine.proof with
1606 | Some (_,metasenv,_,_) -> metasenv
1609 match !ProofEngine.goal with
1612 let (_,canonical_context,_) =
1613 List.find (function (m,_,_) -> m=metano) metasenv
1618 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1619 check_term_in_scratch scratch_window metasenv' context expr
1622 output_html outputhtml
1623 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1627 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1629 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1632 output_html outputhtml
1633 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1636 exception NotADefinition;;
1639 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1640 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1641 let notebook = (rendering_window ())#notebook in
1643 let uri = input_or_locate_uri ~title:"Open" in
1644 CicTypeChecker.typecheck uri ;
1645 let metasenv,bo,ty =
1646 match CicEnvironment.get_cooked_obj uri with
1647 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1648 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1651 | Cic.InductiveDefinition _ -> raise NotADefinition
1653 ProofEngine.proof :=
1654 Some (uri, metasenv, bo, ty) ;
1655 ProofEngine.goal := None ;
1656 refresh_goals notebook ;
1657 refresh_proof output
1659 InvokeTactics.RefreshSequentException e ->
1660 output_html outputhtml
1661 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1662 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1663 | InvokeTactics.RefreshProofException e ->
1664 output_html outputhtml
1665 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1666 "proof: " ^ Printexc.to_string e ^ "</h1>")
1668 output_html outputhtml
1669 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1672 let show_query_results results =
1675 ~modal:false ~title:"Query results." ~border_width:2 () in
1676 let vbox = GPack.vbox ~packing:window#add () in
1678 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1681 ~text:"Click on a URI to show that object"
1682 ~packing:hbox#add () in
1683 let scrolled_window =
1684 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1685 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1686 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1689 (function (uri,_) ->
1693 clist#set_row ~selectable:false n
1696 clist#columns_autosize () ;
1698 (clist#connect#select_row
1699 (fun ~row ~column ~event ->
1700 let (uristr,_) = List.nth results row in
1702 MQueryMisc.cic_textual_parser_uri_of_string
1703 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1706 CicTextualParser0.ConUri uri
1707 | CicTextualParser0.VarUri uri
1708 | CicTextualParser0.IndTyUri (uri,_)
1709 | CicTextualParser0.IndConUri (uri,_,_) ->
1710 show_in_show_window_uri uri
1716 let refine_constraints (must_obj,must_rel,must_sort) =
1717 let chosen = ref false in
1718 let use_only = ref false in
1721 ~modal:true ~title:"Constraints refinement."
1722 ~width:800 ~border_width:2 () in
1723 let vbox = GPack.vbox ~packing:window#add () in
1725 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1728 ~text: "\"Only\" constraints can be enforced or not."
1729 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1731 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1732 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1735 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1736 (* Notebook for the constraints choice *)
1738 GPack.notebook ~scrollable:true
1739 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1740 (* Rel constraints *)
1743 ~text: "Constraints on Rels" () in
1745 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1748 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1751 ~text: "You can now specify the constraints on Rels."
1752 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1753 let expected_height = 25 * (List.length must_rel + 2) in
1754 let height = if expected_height > 400 then 400 else expected_height in
1755 let scrolled_window =
1756 GBin.scrolled_window ~border_width:10 ~height ~width:600
1757 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1758 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1759 let rel_constraints =
1761 (function (position,depth) ->
1764 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1768 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1770 None -> position, ref None
1772 let mutable_ref = ref (Some depth') in
1774 GButton.toggle_button
1775 ~label:("depth = " ^ string_of_int depth') ~active:true
1776 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1779 (depthb#connect#toggled
1781 let sel_depth = if depthb#active then Some depth' else None in
1782 mutable_ref := sel_depth
1784 position, mutable_ref
1786 (* Sort constraints *)
1789 ~text: "Constraints on Sorts" () in
1791 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1794 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1797 ~text: "You can now specify the constraints on Sorts."
1798 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1799 let expected_height = 25 * (List.length must_sort + 2) in
1800 let height = if expected_height > 400 then 400 else expected_height in
1801 let scrolled_window =
1802 GBin.scrolled_window ~border_width:10 ~height ~width:600
1803 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1804 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1805 let sort_constraints =
1807 (function (position,depth,sort) ->
1810 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1813 ~text:(sort ^ " " ^ position)
1814 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1816 None -> position, ref None, sort
1818 let mutable_ref = ref (Some depth') in
1820 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1822 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1825 (depthb#connect#toggled
1827 let sel_depth = if depthb#active then Some depth' else None in
1828 mutable_ref := sel_depth
1830 position, mutable_ref, sort
1832 (* Obj constraints *)
1835 ~text: "Constraints on constants" () in
1837 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1840 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1843 ~text: "You can now specify the constraints on constants."
1844 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1845 let expected_height = 25 * (List.length must_obj + 2) in
1846 let height = if expected_height > 400 then 400 else expected_height in
1847 let scrolled_window =
1848 GBin.scrolled_window ~border_width:10 ~height ~width:600
1849 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1850 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1851 let obj_constraints =
1853 (function (uri,position,depth) ->
1856 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1859 ~text:(uri ^ " " ^ position)
1860 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1862 None -> uri, position, ref None
1864 let mutable_ref = ref (Some depth') in
1866 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1868 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1871 (depthb#connect#toggled
1873 let sel_depth = if depthb#active then Some depth' else None in
1874 mutable_ref := sel_depth
1876 uri, position, mutable_ref
1878 (* Confirm/abort buttons *)
1880 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1882 GButton.button ~label:"Ok"
1883 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1885 GButton.button ~label:"Abort"
1886 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1888 ignore (window#connect#destroy GMain.Main.quit) ;
1889 ignore (cancelb#connect#clicked window#destroy) ;
1891 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1892 window#set_position `CENTER ;
1896 let chosen_must_rel =
1898 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
1899 let chosen_must_sort =
1901 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
1904 let chosen_must_obj =
1906 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
1909 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1911 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1912 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1920 let completeSearchPattern () =
1921 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1922 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1924 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1925 let must = MQueryLevels2.get_constraints expr in
1926 let must',only = refine_constraints must in
1927 let results = MQueryGenerator.searchPattern must' only in
1928 show_query_results results
1931 output_html outputhtml
1932 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1935 let insertQuery () =
1936 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1938 let chosen = ref None in
1941 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1942 let vbox = GPack.vbox ~packing:window#add () in
1944 GMisc.label ~text:"Insert Query. For Experts Only."
1945 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1946 let scrolled_window =
1947 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1948 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1949 let input = GEdit.text ~editable:true
1950 ~packing:scrolled_window#add () in
1952 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1954 GButton.button ~label:"Ok"
1955 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1957 GButton.button ~label:"Load from file..."
1958 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1960 GButton.button ~label:"Abort"
1961 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1962 ignore (window#connect#destroy GMain.Main.quit) ;
1963 ignore (cancelb#connect#clicked window#destroy) ;
1965 (okb#connect#clicked
1967 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
1969 (loadb#connect#clicked
1972 GToolbox.select_file ~title:"Select Query File" ()
1976 let inch = open_in filename in
1977 let rec read_file () =
1979 let line = input_line inch in
1980 line ^ "\n" ^ read_file ()
1984 let text = read_file () in
1985 input#delete_text 0 input#length ;
1986 ignore (input#insert_text text ~pos:0))) ;
1987 window#set_position `CENTER ;
1994 MQI.execute mqi_options (MQueryUtil.query_of_text (Lexing.from_string q))
1996 show_query_results results
1999 output_html outputhtml
2000 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2003 let choose_must list_of_must only =
2004 let chosen = ref None in
2005 let user_constraints = ref [] in
2008 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2009 let vbox = GPack.vbox ~packing:window#add () in
2011 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2015 ("You can now specify the genericity of the query. " ^
2016 "The more generic the slower.")
2017 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2019 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2023 "Suggestion: start with faster queries before moving to more generic ones."
2024 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2026 GPack.notebook ~scrollable:true
2027 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2030 let last = List.length list_of_must in
2036 (if !page = 1 then "More generic" else
2037 if !page = last then "More precise" else " ") () in
2038 let expected_height = 25 * (List.length must + 2) in
2039 let height = if expected_height > 400 then 400 else expected_height in
2040 let scrolled_window =
2041 GBin.scrolled_window ~border_width:10 ~height ~width:600
2042 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2044 GList.clist ~columns:2 ~packing:scrolled_window#add
2045 ~titles:["URI" ; "Position"] ()
2049 (function (uri,position) ->
2052 [uri; if position then "MainConclusion" else "Conclusion"]
2054 clist#set_row ~selectable:false n
2057 clist#columns_autosize ()
2060 let label = GMisc.label ~text:"User provided" () in
2062 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2064 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2067 ~text:"Select the constraints that must be satisfied and press OK."
2068 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2069 let expected_height = 25 * (List.length only + 2) in
2070 let height = if expected_height > 400 then 400 else expected_height in
2071 let scrolled_window =
2072 GBin.scrolled_window ~border_width:10 ~height ~width:600
2073 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2075 GList.clist ~columns:2 ~packing:scrolled_window#add
2076 ~selection_mode:`EXTENDED
2077 ~titles:["URI" ; "Position"] ()
2081 (function (uri,position) ->
2084 [uri; if position then "MainConclusion" else "Conclusion"]
2086 clist#set_row ~selectable:true n
2089 clist#columns_autosize () ;
2091 (clist#connect#select_row
2092 (fun ~row ~column ~event ->
2093 user_constraints := (List.nth only row)::!user_constraints)) ;
2095 (clist#connect#unselect_row
2096 (fun ~row ~column ~event ->
2099 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2102 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2104 GButton.button ~label:"Ok"
2105 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2107 GButton.button ~label:"Abort"
2108 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2110 ignore (window#connect#destroy GMain.Main.quit) ;
2111 ignore (cancelb#connect#clicked window#destroy) ;
2113 (okb#connect#clicked
2114 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2115 window#set_position `CENTER ;
2119 None -> raise NoChoice
2121 if n = List.length list_of_must then
2122 (* user provided constraints *)
2125 List.nth list_of_must n
2128 let searchPattern () =
2129 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2130 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2133 match !ProofEngine.proof with
2134 None -> assert false
2135 | Some proof -> proof
2137 match !ProofEngine.goal with
2141 TacticChaser.searchPattern
2142 ~output_html:(output_html outputhtml) ~choose_must ()
2143 ~status:(proof, metano)
2146 user_uri_choice ~title:"Ambiguous input."
2147 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2150 inputt#set_term uri' ;
2151 InvokeTactics'.apply ()
2154 output_html outputhtml
2155 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2158 let choose_selection mmlwidget (element : Gdome.element option) =
2159 let module G = Gdome in
2160 let rec aux element =
2161 if element#hasAttributeNS
2162 ~namespaceURI:Misc.helmns
2163 ~localName:(G.domString "xref")
2165 mmlwidget#set_selection (Some element)
2168 match element#get_parentNode with
2169 None -> assert false
2170 (*CSC: OCAML DIVERGES!
2171 | Some p -> aux (new G.element_of_node p)
2173 | Some p -> aux (new Gdome.element_of_node p)
2175 GdomeInit.DOMCastException _ ->
2177 "******* trying to select above the document root ********"
2181 | None -> mmlwidget#set_selection None
2184 (* STUFF TO BUILD THE GTK INTERFACE *)
2186 (* Stuff for the widget settings *)
2188 let export_to_postscript output =
2189 let lastdir = ref (Unix.getcwd ()) in
2192 GToolbox.select_file ~title:"Export to PostScript"
2193 ~dir:lastdir ~filename:"screenshot.ps" ()
2197 (output :> GMathView.math_view)#export_to_postscript
2198 ~filename:filename ();
2201 let activate_t1 output button_set_anti_aliasing
2202 button_set_transparency export_to_postscript_menu_item
2205 let is_set = button_t1#active in
2206 output#set_font_manager_type
2207 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2210 button_set_anti_aliasing#misc#set_sensitive true ;
2211 button_set_transparency#misc#set_sensitive true ;
2212 export_to_postscript_menu_item#misc#set_sensitive true ;
2216 button_set_anti_aliasing#misc#set_sensitive false ;
2217 button_set_transparency#misc#set_sensitive false ;
2218 export_to_postscript_menu_item#misc#set_sensitive false ;
2222 let set_anti_aliasing output button_set_anti_aliasing () =
2223 output#set_anti_aliasing button_set_anti_aliasing#active
2226 let set_transparency output button_set_transparency () =
2227 output#set_transparency button_set_transparency#active
2230 let changefont output font_size_spinb () =
2231 output#set_font_size font_size_spinb#value_as_int
2234 let set_log_verbosity output log_verbosity_spinb () =
2235 output#set_log_verbosity log_verbosity_spinb#value_as_int
2238 class settings_window output sw
2239 export_to_postscript_menu_item selection_changed_callback
2241 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2243 GPack.vbox ~packing:settings_window#add () in
2246 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2247 ~border_width:5 ~packing:vbox#add () in
2249 GButton.toggle_button ~label:"activate t1 fonts"
2250 ~packing:(table#attach ~left:0 ~top:0) () in
2251 let button_set_anti_aliasing =
2252 GButton.toggle_button ~label:"set_anti_aliasing"
2253 ~packing:(table#attach ~left:0 ~top:1) () in
2254 let button_set_transparency =
2255 GButton.toggle_button ~label:"set_transparency"
2256 ~packing:(table#attach ~left:2 ~top:1) () in
2259 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2260 ~border_width:5 ~packing:vbox#add () in
2261 let font_size_label =
2262 GMisc.label ~text:"font size:"
2263 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2264 let font_size_spinb =
2266 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2269 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2270 let log_verbosity_label =
2271 GMisc.label ~text:"log verbosity:"
2272 ~packing:(table#attach ~left:0 ~top:1) () in
2273 let log_verbosity_spinb =
2275 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2278 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2280 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2282 GButton.button ~label:"Close"
2283 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2285 method show = settings_window#show
2287 button_set_anti_aliasing#misc#set_sensitive false ;
2288 button_set_transparency#misc#set_sensitive false ;
2289 (* Signals connection *)
2290 ignore(button_t1#connect#clicked
2291 (activate_t1 output button_set_anti_aliasing
2292 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2293 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2294 ignore(button_set_anti_aliasing#connect#toggled
2295 (set_anti_aliasing output button_set_anti_aliasing));
2296 ignore(button_set_transparency#connect#toggled
2297 (set_transparency output button_set_transparency)) ;
2298 ignore(log_verbosity_spinb#connect#changed
2299 (set_log_verbosity output log_verbosity_spinb)) ;
2300 ignore(closeb#connect#clicked settings_window#misc#hide)
2303 (* Scratch window *)
2305 class scratch_window =
2308 ~title:"MathML viewer"
2309 ~border_width:2 () in
2311 GPack.vbox ~packing:window#add () in
2313 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2315 GButton.button ~label:"Whd"
2316 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2318 GButton.button ~label:"Reduce"
2319 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2321 GButton.button ~label:"Simpl"
2322 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2323 let scrolled_window =
2324 GBin.scrolled_window ~border_width:10
2325 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2326 let sequent_viewer =
2327 TermViewer.sequent_viewer
2328 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2330 val mutable term = Cic.Rel 1 (* dummy value *)
2331 val mutable context = ([] : Cic.context) (* dummy value *)
2332 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2333 method sequent_viewer = sequent_viewer
2334 method show () = window#misc#hide () ; window#show ()
2336 method set_term t = term <- t
2337 method context = context
2338 method set_context t = context <- t
2339 method metasenv = metasenv
2340 method set_metasenv t = metasenv <- t
2343 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2344 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2345 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2346 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2347 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2350 let open_contextual_menu_for_selected_terms mmlwidget infos =
2351 let button = GdkEvent.Button.button infos in
2352 let terms_selected = List.length mmlwidget#get_selections > 0 in
2355 let time = GdkEvent.Button.time infos in
2356 let menu = GMenu.menu () in
2357 let f = new GMenu.factory menu in
2359 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2360 let reduce_menu_item =
2361 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2362 let simpl_menu_item =
2363 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2364 let _ = f#add_separator () in
2365 let generalize_menu_item =
2366 f#add_item "Generalize"
2367 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2368 let _ = f#add_separator () in
2369 let clear_menu_item =
2370 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2371 let clearbody_menu_item =
2372 f#add_item "ClearBody"
2373 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2375 whd_menu_item#misc#set_sensitive terms_selected ;
2376 reduce_menu_item#misc#set_sensitive terms_selected ;
2377 simpl_menu_item#misc#set_sensitive terms_selected ;
2378 generalize_menu_item#misc#set_sensitive terms_selected ;
2379 clear_menu_item#misc#set_sensitive terms_selected ;
2380 clearbody_menu_item#misc#set_sensitive terms_selected ;
2381 menu#popup ~button ~time
2387 let vbox1 = GPack.vbox () in
2389 val mutable proofw_ref = None
2390 val mutable compute_ref = None
2392 Lazy.force self#compute ;
2393 match proofw_ref with
2394 None -> assert false
2395 | Some proofw -> proofw
2396 method content = vbox1
2398 match compute_ref with
2399 None -> assert false
2400 | Some compute -> compute
2404 let scrolled_window1 =
2405 GBin.scrolled_window ~border_width:10
2406 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2408 TermViewer.sequent_viewer ~width:400 ~height:275
2409 ~packing:(scrolled_window1#add) () in
2410 let _ = proofw_ref <- Some proofw in
2412 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2414 GButton.button ~label:"Ring"
2415 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2417 GButton.button ~label:"Fourier"
2418 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2420 GButton.button ~label:"Reflexivity"
2421 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2423 GButton.button ~label:"Symmetry"
2424 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2426 GButton.button ~label:"Assumption"
2427 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2428 let contradictionb =
2429 GButton.button ~label:"Contradiction"
2430 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2432 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2434 GButton.button ~label:"Exists"
2435 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2437 GButton.button ~label:"Split"
2438 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2440 GButton.button ~label:"Left"
2441 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2443 GButton.button ~label:"Right"
2444 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2445 let searchpatternb =
2446 GButton.button ~label:"SearchPattern_Apply"
2447 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2449 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2451 GButton.button ~label:"Exact"
2452 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2454 GButton.button ~label:"Intros"
2455 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2457 GButton.button ~label:"Apply"
2458 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2459 let elimintrossimplb =
2460 GButton.button ~label:"ElimIntrosSimpl"
2461 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2463 GButton.button ~label:"ElimType"
2464 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2466 GButton.button ~label:"Fold_whd"
2467 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2469 GButton.button ~label:"Fold_reduce"
2470 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2472 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2474 GButton.button ~label:"Fold_simpl"
2475 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2477 GButton.button ~label:"Cut"
2478 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2480 GButton.button ~label:"Change"
2481 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2483 GButton.button ~label:"Let ... In"
2484 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2486 GButton.button ~label:"RewriteSimpl ->"
2487 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2488 let rewritebacksimplb =
2489 GButton.button ~label:"RewriteSimpl <-"
2490 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2492 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2494 GButton.button ~label:"Absurd"
2495 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2497 GButton.button ~label:"Decompose"
2498 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2500 GButton.button ~label:"Transitivity"
2501 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2503 GButton.button ~label:"Replace"
2504 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2506 GButton.button ~label:"Injection"
2507 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2509 GButton.button ~label:"Discriminate"
2510 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2511 (* Zack: spostare in una toolbar
2513 GButton.button ~label:"Generalize"
2514 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2516 GButton.button ~label:"ClearBody"
2517 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2519 GButton.button ~label:"Clear"
2520 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2522 GButton.button ~label:"Whd"
2523 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2525 GButton.button ~label:"Reduce"
2526 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2528 GButton.button ~label:"Simpl"
2529 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2532 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2533 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2534 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2535 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2536 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2537 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2538 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2539 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2540 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2541 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2542 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2543 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2544 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2545 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2546 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2547 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2548 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2549 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2550 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2551 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2552 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2553 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2554 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2555 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2556 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2557 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2558 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2559 ignore(searchpatternb#connect#clicked searchPattern) ;
2560 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2561 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2562 (* Zack: spostare in una toolbar
2563 ignore(whdb#connect#clicked whd) ;
2564 ignore(reduceb#connect#clicked reduce) ;
2565 ignore(simplb#connect#clicked simpl) ;
2566 ignore(clearbodyb#connect#clicked clearbody) ;
2567 ignore(clearb#connect#clicked clear) ;
2568 ignore(generalizeb#connect#clicked generalize) ;
2570 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2572 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2573 (open_contextual_menu_for_selected_terms proofw)) ;
2579 let vbox1 = GPack.vbox () in
2580 let scrolled_window1 =
2581 GBin.scrolled_window ~border_width:10
2582 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2584 TermViewer.sequent_viewer ~width:400 ~height:275
2585 ~packing:(scrolled_window1#add) () in
2587 method proofw = (assert false : TermViewer.sequent_viewer)
2588 method content = vbox1
2589 method compute = (assert false : unit)
2593 let empty_page = new empty_page;;
2597 val notebook = GPack.notebook ()
2599 val mutable skip_switch_page_event = false
2600 val mutable empty = true
2601 method notebook = notebook
2603 let new_page = new page () in
2605 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2606 notebook#append_page
2607 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2608 new_page#content#coerce
2609 method remove_all_pages ~skip_switch_page_event:skip =
2611 notebook#remove_page 0 (* let's remove the empty page *)
2613 List.iter (function _ -> notebook#remove_page 0) !pages ;
2615 skip_switch_page_event <- skip
2616 method set_current_page ~may_skip_switch_page_event n =
2617 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2618 let new_page = notebook#page_num page#content#coerce in
2619 if may_skip_switch_page_event && new_page <> notebook#current_page then
2620 skip_switch_page_event <- true ;
2621 notebook#goto_page new_page
2622 method set_empty_page =
2625 notebook#append_page
2626 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2627 empty_page#content#coerce
2629 let (_,_,page) = List.nth !pages notebook#current_page in
2633 (notebook#connect#switch_page
2635 let skip = skip_switch_page_event in
2636 skip_switch_page_event <- false ;
2639 let (metano,setgoal,page) = List.nth !pages i in
2640 ProofEngine.goal := Some metano ;
2641 Lazy.force (page#compute) ;
2650 class rendering_window output (notebook : notebook) =
2651 let scratch_window = new scratch_window in
2654 ~title:"gTopLevel - Helm's Proof Assistant"
2655 ~border_width:0 ~allow_shrink:false () in
2656 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2658 let handle_box = GBin.handle_box ~border_width:2
2659 ~packing:(vbox_for_menu#pack ~padding:0) () in
2660 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2661 let factory0 = new GMenu.factory menubar in
2662 let accel_group = factory0#accel_group in
2664 let file_menu = factory0#add_submenu "File" in
2665 let factory1 = new GMenu.factory file_menu ~accel_group in
2666 let export_to_postscript_menu_item =
2669 factory1#add_item "New Block of (Co)Inductive Definitions..."
2670 ~key:GdkKeysyms._B ~callback:new_inductive
2673 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2676 let reopen_menu_item =
2677 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2681 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2682 ignore (factory1#add_separator ()) ;
2684 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2685 ~callback:load_unfinished_proof) ;
2686 let save_menu_item =
2687 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2688 ~callback:save_unfinished_proof
2691 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2692 ignore (!save_set_sensitive false);
2693 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2694 ignore (!qed_set_sensitive false);
2695 ignore (factory1#add_separator ()) ;
2696 let export_to_postscript_menu_item =
2697 factory1#add_item "Export to PostScript..."
2698 ~callback:(export_to_postscript output) in
2699 ignore (factory1#add_separator ()) ;
2701 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2702 export_to_postscript_menu_item
2705 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2706 let factory2 = new GMenu.factory edit_menu ~accel_group in
2707 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2708 let proveit_menu_item =
2709 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2710 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2712 let focus_menu_item =
2713 factory2#add_item "Focus" ~key:GdkKeysyms._F
2714 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2717 focus_and_proveit_set_sensitive :=
2719 proveit_menu_item#misc#set_sensitive b ;
2720 focus_menu_item#misc#set_sensitive b
2722 let _ = !focus_and_proveit_set_sensitive false in
2723 (* edit term menu *)
2724 let edit_term_menu = factory0#add_submenu "Edit Term" in
2725 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2726 let check_menu_item =
2727 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2728 ~callback:(check scratch_window) in
2729 let _ = check_menu_item#misc#set_sensitive false in
2731 let search_menu = factory0#add_submenu "Search" in
2732 let factory4 = new GMenu.factory search_menu ~accel_group in
2734 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2736 let searchPattern_menu_item =
2737 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2738 ~callback:completeSearchPattern in
2739 let _ = searchPattern_menu_item#misc#set_sensitive false in
2740 let show_menu_item =
2741 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2743 let insert_query_item =
2744 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2745 ~callback:insertQuery in
2747 let hbugs_menu = factory0#add_submenu "HBugs" in
2748 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2749 let toggle_hbugs_menu_item =
2750 factory6#add_check_item
2751 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2754 let settings_menu = factory0#add_submenu "Settings" in
2755 let factory3 = new GMenu.factory settings_menu ~accel_group in
2757 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2758 ~callback:edit_aliases in
2759 let _ = factory3#add_separator () in
2761 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2762 ~callback:(function _ -> (settings_window ())#show ()) in
2764 let _ = window#add_accel_group accel_group in
2768 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2770 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2771 let scrolled_window0 =
2772 GBin.scrolled_window ~border_width:10
2773 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2774 let _ = scrolled_window0#add output#coerce in
2776 GBin.frame ~label:"Insert Term"
2777 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2778 let scrolled_window1 =
2779 GBin.scrolled_window ~border_width:5
2780 ~packing:frame#add () in
2782 TexTermEditor'.term_editor
2783 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2784 ~isnotempty_callback:
2786 check_menu_item#misc#set_sensitive b ;
2787 searchPattern_menu_item#misc#set_sensitive b) in
2789 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2791 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2793 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2797 ~source:"<html><body bgColor=\"white\"></body></html>"
2798 ~width:400 ~height: 100
2803 method outputhtml = outputhtml
2804 method inputt = inputt
2805 method output = (output : TermViewer.proof_viewer)
2806 method scratch_window = scratch_window
2807 method notebook = notebook
2808 method show = window#show
2810 notebook#set_empty_page ;
2811 export_to_postscript_menu_item#misc#set_sensitive false ;
2812 check_term := (check_term_in_scratch scratch_window) ;
2814 (* signal handlers here *)
2815 ignore(output#connect#selection_changed
2817 choose_selection output elem ;
2818 !focus_and_proveit_set_sensitive true
2820 ignore (output#connect#click (show_in_show_window_callback output)) ;
2821 let settings_window = new settings_window output scrolled_window0
2822 export_to_postscript_menu_item (choose_selection output) in
2823 set_settings_window settings_window ;
2824 set_outputhtml outputhtml ;
2825 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2826 Logger.log_callback :=
2827 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2832 let initialize_everything () =
2833 let module U = Unix in
2834 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2835 let notebook = new notebook in
2836 let rendering_window' = new rendering_window output notebook in
2837 set_rendering_window rendering_window' ;
2838 let print_error_as_html prefix msg =
2839 output_html (outputhtml ())
2840 ("<h1 color=\"red\">" ^ prefix ^ msg ^ "</h1>")
2842 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2843 Gdome_xslt.setDebugCallback
2844 (Some (print_error_as_html "XSLT Debug Message: "));
2845 rendering_window'#show () ;
2846 (* Hbugs.toggle true; *)
2851 if !usedb then ignore (MQI.init mqi_options) ;
2852 ignore (GtkMain.Main.init ()) ;
2853 initialize_everything () ;
2854 if !usedb then MQI.close mqi_options;
2859 Sys.catch_break true;
2861 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)