1 (* Copyright (C) 2000-2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
34 (******************************************************************************)
36 let debug_level = ref 1
37 let debug_print ?(level = 1) s = if !debug_level >= level then prerr_endline s
38 let error s = prerr_endline ("E: " ^ s)
39 let warning s = prerr_endline ("W: " ^ s)
45 module MQI = MQueryInterpreter
47 module MQGT = MQGTypes
49 module MQG = MQueryGenerator
51 (* GLOBAL CONSTANTS *)
53 let configuration_file = "triciclo.conf.xml"
55 let mqi_debug_fun s = debug_print ~level:2 s
56 let mqi_flags = [MQIC.Postgres ; MQIC.Stat ; MQIC.Warn ; MQIC.Log]
57 let mqi_handle = MQIC.init mqi_flags mqi_debug_fun
59 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
61 let restore_environment_on_boot = true ;;
62 let notify_hbugs_on_goal_change = false ;;
64 let auto_disambiguation = ref true ;;
66 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
68 let check_term = ref (fun _ _ _ -> assert false);;
70 exception RenderingWindowsNotInitialized;;
72 let set_rendering_window,rendering_window =
73 let rendering_window_ref = ref None in
74 (function rw -> rendering_window_ref := Some rw),
76 match !rendering_window_ref with
77 None -> raise RenderingWindowsNotInitialized
82 exception SettingsWindowsNotInitialized;;
84 let set_settings_window,settings_window =
85 let settings_window_ref = ref None in
86 (function rw -> settings_window_ref := Some rw),
88 match !settings_window_ref with
89 None -> raise SettingsWindowsNotInitialized
94 exception QedSetSensitiveNotInitialized;;
95 let qed_set_sensitive =
96 ref (function _ -> raise QedSetSensitiveNotInitialized)
99 exception SaveSetSensitiveNotInitialized;;
100 let save_set_sensitive =
101 ref (function _ -> raise SaveSetSensitiveNotInitialized)
104 (* COMMAND LINE OPTIONS *)
110 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
113 Arg.parse argspec ignore ""
117 let term_of_cic_textual_parser_uri uri =
118 let module C = Cic in
119 let module CTP = CicTextualParser0 in
121 CTP.ConUri uri -> C.Const (uri,[])
122 | CTP.VarUri uri -> C.Var (uri,[])
123 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
124 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
127 let string_of_cic_textual_parser_uri uri =
128 let module C = Cic in
129 let module CTP = CicTextualParser0 in
132 CTP.ConUri uri -> UriManager.string_of_uri uri
133 | CTP.VarUri uri -> UriManager.string_of_uri uri
134 | CTP.IndTyUri (uri,tyno) ->
135 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
136 | CTP.IndConUri (uri,tyno,consno) ->
137 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
140 (* 4 = String.length "cic:" *)
141 String.sub uri' 4 (String.length uri' - 4)
144 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
148 let check_window uris =
151 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
153 GPack.notebook ~scrollable:true ~packing:window#add () in
158 let scrolled_window =
159 GBin.scrolled_window ~border_width:10
161 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
166 TermViewer.sequent_viewer
167 ~packing:scrolled_window#add ~width:400 ~height:280 () in
170 term_of_cic_textual_parser_uri
171 (MQueryMisc.cic_textual_parser_uri_of_string uri)
173 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
176 mmlwidget#load_sequent [] (111,[],expr)
179 HelmLogger.log (`Error (`T (Printexc.to_string e)))
184 (notebook#connect#switch_page
186 Lazy.force (List.nth render_terms i)))
192 interactive_user_uri_choice ~(selection_mode:[`MULTIPLE|`SINGLE]) ?(ok="Ok")
193 ?(enable_button_for_non_vars=false) ~title ~msg uris
195 let only_constant_choices =
198 (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
201 if selection_mode <> `SINGLE && !auto_disambiguation then
202 Lazy.force only_constant_choices
204 let choices = ref [] in
205 let chosen = ref false in
206 let use_only_constants = ref false in
208 GWindow.dialog ~modal:true ~title ~width:600 () in
210 GMisc.label ~text:msg
211 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
212 let scrolled_window =
213 GBin.scrolled_window ~border_width:10
214 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
216 let expected_height = 18 * List.length uris in
217 let height = if expected_height > 400 then 400 else expected_height in
218 GList.clist ~columns:1 ~packing:scrolled_window#add
219 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
220 let _ = List.map (function x -> clist#append [x]) uris in
222 GPack.hbox ~border_width:0
223 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
225 GMisc.label ~text:"None of the above. Try this one:"
226 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
228 GEdit.entry ~editable:true
229 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
231 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
233 GButton.button ~label:ok
234 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
235 let _ = okb#misc#set_sensitive false in
240 if enable_button_for_non_vars then
241 hbox#pack ~expand:false ~fill:false ~padding:5 w)
242 ~label:"Try constants only" () in
247 if enable_button_for_non_vars then
248 hbox#pack ~expand:false ~fill:false ~padding:5 w)
251 GButton.button ~label:"Check"
252 ~packing:(hbox#pack ~padding:5) () in
253 let _ = checkb#misc#set_sensitive false in
255 GButton.button ~label:"Abort"
256 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
258 let check_callback () =
259 assert (List.length !choices > 0) ;
260 check_window !choices
262 ignore (window#connect#destroy GMain.Main.quit) ;
263 ignore (cancelb#connect#clicked window#destroy) ;
265 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
267 (nonvarsb#connect#clicked
269 use_only_constants := true ;
273 ignore (autob#connect#clicked (fun () ->
274 auto_disambiguation := true;
275 (rendering_window ())#set_auto_disambiguation true;
276 use_only_constants := true ;
279 ignore (checkb#connect#clicked check_callback) ;
281 (clist#connect#select_row
282 (fun ~row ~column ~event ->
283 checkb#misc#set_sensitive true ;
284 okb#misc#set_sensitive true ;
285 choices := (List.nth uris row)::!choices)) ;
287 (clist#connect#unselect_row
288 (fun ~row ~column ~event ->
290 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
292 (manual_input#connect#changed
294 if manual_input#text = "" then
297 checkb#misc#set_sensitive false ;
298 okb#misc#set_sensitive false ;
299 clist#misc#set_sensitive true
303 choices := [manual_input#text] ;
304 clist#unselect_all () ;
305 checkb#misc#set_sensitive true ;
306 okb#misc#set_sensitive true ;
307 clist#misc#set_sensitive false
309 window#set_position `CENTER ;
313 if !use_only_constants then
314 Lazy.force only_constant_choices
316 if List.length !choices > 0 then !choices else raise NoChoice
322 let interactive_interpretation_choice interpretations =
323 let chosen = ref None in
326 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
327 let vbox = GPack.vbox ~packing:window#add () in
331 ("Ambiguous input since there are many well-typed interpretations." ^
332 " Please, choose one of them.")
333 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
335 GPack.notebook ~scrollable:true
336 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
339 (function interpretation ->
341 let expected_height = 18 * List.length interpretation in
342 let height = if expected_height > 400 then 400 else expected_height in
343 GList.clist ~columns:2 ~packing:notebook#append_page ~height
344 ~titles:["id" ; "URI"] ()
348 (function (id,uri) ->
349 let n = clist#append [id;uri] in
350 clist#set_row ~selectable:false n
353 clist#columns_autosize ()
356 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
358 GButton.button ~label:"Ok"
359 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
361 GButton.button ~label:"Abort"
362 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
364 ignore (window#connect#destroy GMain.Main.quit) ;
365 ignore (cancelb#connect#clicked window#destroy) ;
368 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
369 window#set_position `CENTER ;
373 None -> raise NoChoice
381 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
384 let struri = UriManager.string_of_uri uri in
385 let idx = (String.rindex struri '/') + 1 in
386 String.sub struri idx (String.length struri - idx)
388 let path = pathname ^ "/" ^ name in
390 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
394 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
395 ~ask_dtd_to_the_getter:false
398 let innertypesuri = UriManager.innertypesuri_of_uri uri in
399 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
400 Http_getter.register' innertypesuri
401 (Helm_registry.get "annotations.url" ^
402 Str.replace_first (Str.regexp "^cic:") ""
403 (UriManager.string_of_uri innertypesuri) ^ ".xml"
405 (* constant type / variable / mutual inductive types definition *)
406 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
407 Http_getter.register' uri
408 (Helm_registry.get "annotations.url" ^
409 Str.replace_first (Str.regexp "^cic:") ""
410 (UriManager.string_of_uri uri) ^ ".xml"
417 match UriManager.bodyuri_of_uri uri with
419 | Some bodyuri -> bodyuri
421 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
422 Http_getter.register' bodyuri
423 (Helm_registry.get "annotations.url" ^
424 Str.replace_first (Str.regexp "^cic:") ""
425 (UriManager.string_of_uri bodyuri) ^ ".xml"
432 exception OpenConjecturesStillThere;;
433 exception WrongProof;;
435 let pathname_of_annuri uristring =
436 Helm_registry.get "annotations.dir" ^
437 Str.replace_first (Str.regexp "^cic:") "" uristring
440 let make_dirs dirpath =
441 ignore (Unix.system ("mkdir -p " ^ dirpath))
444 let save_obj uri obj =
446 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
447 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
449 Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
451 (* let's save the theorem and register it to the getter *)
452 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
454 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
459 match ProofEngine.get_proof () with
461 | Some (uri,[],bo,ty) ->
463 CicReduction.are_convertible []
464 (CicTypeChecker.type_of_aux' [] [] bo) ty
467 (*CSC: Wrong: [] is just plainly wrong *)
468 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
469 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
470 (rendering_window ())#output#load_proof uri proof
472 !qed_set_sensitive false ;
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 | _ -> raise OpenConjecturesStillThere
484 (** save an unfinished proof on the filesystem *)
485 let save_unfinished_proof () =
486 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
487 let proof_file_type = Helm_registry.get "triciclo.proof_file_type" in
488 let proof_file = Helm_registry.get "triciclo.proof_file" in
489 Xml.pp ~quiet:true xml (Some proof_file_type) ;
491 (`Msg (`T ("Current proof type saved to " ^ proof_file_type))) ;
492 Xml.pp ~quiet:true bodyxml (Some proof_file) ;
494 (`Msg (`T ("Current proof body saved to " ^ proof_file)))
497 (* Used to typecheck the loaded proofs *)
498 let typecheck_loaded_proof metasenv bo ty =
499 let module T = CicTypeChecker in
502 (fun metasenv ((_,context,ty) as conj) ->
503 ignore (T.type_of_aux' metasenv context ty) ;
506 ignore (T.type_of_aux' metasenv [] ty) ;
507 ignore (T.type_of_aux' metasenv [] bo)
510 let decompose_uris_choice_callback uris =
511 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
512 let module U = UriManager in
515 match MQueryMisc.cic_textual_parser_uri_of_string uri with
516 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
518 (interactive_user_uri_choice
519 ~selection_mode:`MULTIPLE ~ok:"Ok" ~enable_button_for_non_vars:false
520 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
522 (function (uri,typeno,_) ->
523 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
528 let mk_fresh_name_callback metasenv context name ~typ =
530 match FreshNamesGenerator.mk_fresh_name metasenv context name ~typ with
531 Cic.Name fresh_name -> fresh_name
532 | Cic.Anonymous -> assert false
535 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
536 ("Enter a fresh name for the hypothesis " ^
538 (List.map (function None -> None | Some (n,_) -> Some n) context))
540 Some fresh_name' -> Cic.Name fresh_name'
541 | None -> raise NoChoice
544 let refresh_proof (output : TermViewer.proof_viewer) =
546 let uri,currentproof =
547 match ProofEngine.get_proof () with
549 | Some (uri,metasenv,bo,ty) ->
550 ProofEngine.set_proof (Some (uri,metasenv,bo,ty)) ;
551 if List.length metasenv = 0 then
553 !qed_set_sensitive true ;
558 (*CSC: Wrong: [] is just plainly wrong *)
560 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
562 ignore (output#load_proof uri currentproof)
565 match ProofEngine.get_proof () with
567 | Some (uri,metasenv,bo,ty) ->
568 debug_print ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[])));
569 raise (InvokeTactics.RefreshProofException e)
571 let set_proof_engine_goal g =
572 ProofEngine.goal := g
575 let refresh_goals ?(empty_notebook=true) notebook =
577 match !ProofEngine.goal with
579 if empty_notebook then
581 notebook#remove_all_pages ~skip_switch_page_event:false ;
582 notebook#set_empty_page
585 notebook#proofw#unload
588 match ProofEngine.get_proof () with
590 | Some (_,metasenv,_,_) -> metasenv
593 List.find (function (m,_,_) -> m=metano) metasenv
595 let regenerate_notebook () =
596 let skip_switch_page_event =
598 (m,_,_)::_ when m = metano -> false
601 notebook#remove_all_pages ~skip_switch_page_event ;
602 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
604 if empty_notebook then
606 regenerate_notebook () ;
607 notebook#set_current_page
608 ~may_skip_switch_page_event:false metano
612 notebook#set_current_page
613 ~may_skip_switch_page_event:true metano ;
614 notebook#proofw#load_sequent metasenv currentsequent
619 match !ProofEngine.goal with
624 match ProofEngine.get_proof () with
626 | Some (_,metasenv,_,_) -> metasenv
629 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
631 ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent);
632 raise (InvokeTactics.RefreshSequentException e)
634 debug_print ("Offending sequent " ^ string_of_int metano ^ " unknown.");
635 raise (InvokeTactics.RefreshSequentException e)
637 module InvokeTacticsCallbacks =
639 let sequent_viewer () = (rendering_window ())#notebook#proofw
640 let term_editor () = (rendering_window ())#inputt
641 let scratch_window () = (rendering_window ())#scratch_window
643 let refresh_proof () =
644 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
647 let refresh_goals () =
648 let notebook = (rendering_window ())#notebook in
649 refresh_goals notebook
651 let decompose_uris_choice_callback = decompose_uris_choice_callback
652 let mk_fresh_name_callback = mk_fresh_name_callback
655 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
657 (* Just to initialize the Hbugs module *)
658 module Ignore = Hbugs.Initialize (InvokeTactics');;
659 Hbugs.set_describe_hint_callback (fun hint ->
661 | Hbugs_types.Use_apply_Luke term -> check_window [term]
665 let dummy_uri = "/dummy.con"
667 (** load an unfinished proof from filesystem *)
668 let load_unfinished_proof () =
669 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
670 let notebook = (rendering_window ())#notebook in
673 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:dummy_uri
676 None -> raise NoChoice
678 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
679 let proof_file_type = Helm_registry.get "triciclo.proof_file_type" in
680 let proof_file = Helm_registry.get "triciclo.proof_file" in
681 match CicParser.obj_of_xml proof_file_type (Some proof_file) with
682 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
683 typecheck_loaded_proof metasenv bo ty ;
684 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
685 refresh_proof output ;
686 set_proof_engine_goal
689 | (metano,_,_)::_ -> Some metano
691 refresh_goals notebook ;
693 (`Msg (`T ("Current proof type loaded from " ^ proof_file_type)));
695 (`Msg (`T ("Current proof body loaded from " ^ proof_file))) ;
696 !save_set_sensitive true;
699 InvokeTactics.RefreshSequentException e ->
701 (`Error (`T ("Exception raised during the refresh of the " ^
702 "sequent: " ^ Printexc.to_string e)))
703 | InvokeTactics.RefreshProofException e ->
705 (`Error (`T ("Exception raised during the refresh of the " ^
706 "proof: " ^ Printexc.to_string e)))
709 (`Error (`T (Printexc.to_string e)))
712 let clear_aliases () =
713 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
714 inputt#environment :=
715 DisambiguatingParser.EnvironmentP3.of_string
716 DisambiguatingParser.EnvironmentP3.empty
719 let edit_aliases () =
720 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
721 let disambiguation_env = inputt#environment in
722 let chosen_aliases = ref None in
725 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
727 GPack.vbox ~border_width:0 ~packing:window#add () in
728 let scrolled_window =
729 GBin.scrolled_window ~border_width:10
730 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
731 let input = GText.view ~editable:true ~width:400 ~height:100
732 ~packing:scrolled_window#add () in
734 GPack.hbox ~border_width:0
735 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
737 GButton.button ~label:"Ok"
738 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
740 GButton.button ~label:"Clear"
741 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
743 GButton.button ~label:"Cancel"
744 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
745 ignore (window#connect#destroy GMain.Main.quit) ;
746 ignore (cancelb#connect#clicked window#destroy) ;
747 ignore (clearb#connect#clicked (fun () ->
748 input#buffer#set_text DisambiguatingParser.EnvironmentP3.empty)) ;
749 ignore (okb#connect#clicked (fun () ->
750 chosen_aliases := Some (input#buffer#get_text ());
753 (input#buffer#insert ~iter:(input#buffer#get_iter_at_char 0)
754 (DisambiguatingParser.EnvironmentP3.to_string !disambiguation_env ^ "\n"));
757 match !chosen_aliases with
759 | Some raw_aliases ->
760 let new_disambiguation_env =
762 DisambiguatingParser.EnvironmentP3.of_string raw_aliases
766 ("Error while parsing aliases: " ^ Printexc.to_string e)));
769 disambiguation_env := new_disambiguation_env
773 let module L = LogicalOperations in
774 let module G = Gdome in
775 let notebook = (rendering_window ())#notebook in
776 let output = (rendering_window ())#output in
778 output#make_sequent_of_selected_term ;
779 refresh_proof output ;
780 refresh_goals notebook
782 InvokeTactics.RefreshSequentException e ->
784 (`Error (`T ("Exception raised during the refresh of the " ^
785 "sequent: " ^ Printexc.to_string e)))
786 | InvokeTactics.RefreshProofException e ->
788 (`Error (`T ("Exception raised during the refresh of the " ^
789 "proof: " ^ Printexc.to_string e)))
792 (`Error (`T (Printexc.to_string e)))
796 let module L = LogicalOperations in
797 let module G = Gdome in
798 let notebook = (rendering_window ())#notebook in
799 let output = (rendering_window ())#output in
801 output#focus_sequent_of_selected_term ;
802 refresh_goals notebook
804 InvokeTactics.RefreshSequentException e ->
806 (`Error (`T ("Exception raised during the refresh of the " ^
807 "sequent: " ^ Printexc.to_string e)))
808 | InvokeTactics.RefreshProofException e ->
810 (`Error (`T ("Exception raised during the refresh of the " ^
811 "proof: " ^ Printexc.to_string e)))
814 (`Error (`T (Printexc.to_string e)))
817 exception NoPrevGoal;;
818 exception NoNextGoal;;
821 let module L = LogicalOperations in
822 let module G = Gdome in
823 let notebook = (rendering_window ())#notebook in
824 let output = (rendering_window ())#output in
826 match ProofEngine.get_proof () with
828 | Some (_,metasenv,_,_) -> metasenv
831 refresh_goals ~empty_notebook:false notebook
833 InvokeTactics.RefreshSequentException e ->
835 (`Error (`T ("Exception raised during the refresh of the " ^
836 "sequent: " ^ Printexc.to_string e)))
839 (`Error (`T (Printexc.to_string e)))
843 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
846 GWindow.window ~width:800 ~border_width:2 () in
847 let scrolled_window =
848 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
850 GMathViewAux.single_selection_math_view
851 ~packing:scrolled_window#add ~width:600 ~height:400 ()
853 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
854 let href = Gdome.domString "href" in
855 let show_in_show_window_obj uri obj =
858 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
859 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
861 Cic2acic.acic_object_of_cic_object obj
864 ChosenTransformer.mml_of_cic_object
865 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
867 window#set_title (UriManager.string_of_uri uri) ;
868 window#misc#hide () ; window#show () ;
869 mmlwidget#load_doc mml ;
873 (`Error (`T (Printexc.to_string e)))
875 let show_in_show_window_uri uri =
876 let obj = CicEnvironment.get_obj uri in
877 show_in_show_window_obj uri obj
879 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
883 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
885 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
887 show_in_show_window_uri (UriManager.uri_of_string uri)
889 ignore (mmlwidget#action_toggle n')
892 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
894 show_in_show_window_obj, show_in_show_window_uri,
895 show_in_show_window_callback
898 exception NoObjectsLocated;;
900 let user_uri_choice ~title ~msg uris =
903 [] -> raise NoObjectsLocated
907 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
912 String.sub uri 4 (String.length uri - 4)
915 let locate_callback id =
916 let query = MQG.locate id in
917 let result = MQI.execute mqi_handle query in
921 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
923 HelmLogger.log (`Msg (`T "Locate Query:")) ;
924 MQueryUtil.text_of_query (fun m -> HelmLogger.log (`Msg (`T m))) "" query;
925 HelmLogger.log (`Msg (`T "Result:")) ;
926 MQueryUtil.text_of_result (fun m -> HelmLogger.log (`Msg (`T m))) "" result;
927 user_uri_choice ~title:"Ambiguous input."
929 ("Ambiguous input \"" ^ id ^
930 "\". Please, choose one interpetation:")
935 let input_or_locate_uri ~title =
936 let uri = ref None in
939 ~width:400 ~modal:true ~title ~border_width:2 () in
940 let vbox = GPack.vbox ~packing:window#add () in
942 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
944 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
946 GEdit.entry ~editable:true
947 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
949 GButton.button ~label:"Check"
950 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
951 let _ = checkb#misc#set_sensitive false in
953 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
955 GMisc.label ~text:"You can also enter an indentifier to locate:"
956 ~packing:(hbox2#pack ~padding:5) () in
958 GEdit.entry ~editable:true
959 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
961 GButton.button ~label:"Locate"
962 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
963 let _ = locateb#misc#set_sensitive false in
965 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
967 GButton.button ~label:"Ok"
968 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
969 let _ = okb#misc#set_sensitive false in
971 GButton.button ~label:"Cancel"
972 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
974 ignore (window#connect#destroy GMain.Main.quit) ;
976 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
977 let check_callback () =
978 let uri = "cic:" ^ manual_input#text in
980 ignore (Http_getter.resolve' (UriManager.uri_of_string uri)) ;
981 HelmLogger.log (`Msg (`T "OK")) ;
984 Http_getter_types.Unresolvable_URI _ ->
986 (`Error (`T ("URI " ^ uri ^
987 " does not correspond to any object."))) ;
989 | UriManager.IllFormedUri _ ->
991 (`Error (`T ("URI " ^ uri ^ " is not well-formed."))) ;
995 (`Error (`T (Printexc.to_string e))) ;
1001 if check_callback () then
1003 uri := Some manual_input#text ;
1007 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1009 (manual_input#connect#changed
1011 if manual_input#text = "" then
1013 checkb#misc#set_sensitive false ;
1014 okb#misc#set_sensitive false
1018 checkb#misc#set_sensitive true ;
1019 okb#misc#set_sensitive true
1022 (locate_input#connect#changed
1023 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1025 (locateb#connect#clicked
1027 let id = locate_input#text in
1028 manual_input#set_text (locate_callback id) ;
1029 locate_input#delete_text 0 (String.length id)
1034 None -> raise NoChoice
1035 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1038 exception AmbiguousInput;;
1040 (* A WIDGET TO ENTER CIC TERMS *)
1042 module DisambiguateCallbacks =
1044 let interactive_user_uri_choice =
1045 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1046 interactive_user_uri_choice ~selection_mode ?ok
1047 ?enable_button_for_non_vars ~title ~msg
1048 let interactive_interpretation_choice = interactive_interpretation_choice
1049 let input_or_locate_uri = input_or_locate_uri
1053 module TermEditor' = ChosenTermEditor.Make (DisambiguateCallbacks);;
1055 (* OTHER FUNCTIONS *)
1058 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1061 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1063 None -> raise NoChoice
1065 let uri = locate_callback input in
1070 (`Error (`T (Printexc.to_string e)))
1074 exception UriAlreadyInUse;;
1075 exception NotAUriToAConstant;;
1077 let new_inductive () =
1078 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1079 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1080 let notebook = (rendering_window ())#notebook in
1082 let chosen = ref false in
1083 let inductive = ref true in
1084 let paramsno = ref 0 in
1085 let get_uri = ref (function _ -> assert false) in
1086 let get_base_uri = ref (function _ -> assert false) in
1087 let get_names = ref (function _ -> assert false) in
1088 let get_types_and_cons = ref (function _ -> assert false) in
1089 let get_context_and_subst = ref (function _ -> assert false) in
1092 ~width:600 ~modal:true ~position:`CENTER
1093 ~title:"New Block of Mutual (Co)Inductive Definitions"
1094 ~border_width:2 () in
1095 let vbox = GPack.vbox ~packing:window#add () in
1097 GPack.hbox ~border_width:0
1098 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1100 GMisc.label ~text:"Enter the URI for the new block:"
1101 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1103 GEdit.entry ~editable:true
1104 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1106 GPack.hbox ~border_width:0
1107 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1111 "Enter the number of left parameters in every arity and constructor type:"
1112 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1113 let paramsno_entry =
1114 GEdit.entry ~editable:true ~text:"0"
1115 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1117 GPack.hbox ~border_width:0
1118 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1120 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1121 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1123 GButton.radio_button ~label:"Inductive"
1124 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1126 GButton.radio_button ~label:"Coinductive"
1127 ~group:inductiveb#group
1128 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1130 GPack.hbox ~border_width:0
1131 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1133 GMisc.label ~text:"Enter the list of the names of the types:"
1134 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1136 GEdit.entry ~editable:true
1137 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1139 GPack.hbox ~border_width:0
1140 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1142 GButton.button ~label:"> Next"
1143 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1144 let _ = okb#misc#set_sensitive true in
1146 GButton.button ~label:"Abort"
1147 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1148 ignore (window#connect#destroy GMain.Main.quit) ;
1149 ignore (cancelb#connect#clicked window#destroy) ;
1153 (okb#connect#clicked
1156 let uristr = "cic:" ^ uri_entry#text in
1157 let namesstr = names_entry#text in
1158 let paramsno' = int_of_string (paramsno_entry#text) in
1159 match Str.split (Str.regexp " +") namesstr with
1161 | (he::tl) as names ->
1162 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1165 ignore (Http_getter.resolve' uri) ;
1166 raise UriAlreadyInUse
1167 with Http_getter_types.Unresolvable_URI _ ->
1168 get_uri := (function () -> uri) ;
1169 get_names := (function () -> names) ;
1170 inductive := inductiveb#active ;
1171 paramsno := paramsno' ;
1177 (`Error (`T (Printexc.to_string e)))
1185 GBin.frame ~label:name
1186 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1187 let vbox = GPack.vbox ~packing:frame#add () in
1188 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1190 GMisc.label ~text:("Enter its type:")
1191 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1192 let scrolled_window =
1193 GBin.scrolled_window ~border_width:5
1194 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1196 TermEditor'.term_editor
1198 ~width:400 ~height:20 ~packing:scrolled_window#add
1199 ~share_environment_with:inputt ()
1200 ~isnotempty_callback:
1202 (*non_empty_type := b ;*)
1203 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1206 GPack.hbox ~border_width:0
1207 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1209 GMisc.label ~text:("Enter the list of its constructors:")
1210 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1211 let cons_names_entry =
1212 GEdit.entry ~editable:true
1213 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1214 (newinputt,cons_names_entry)
1217 vbox#remove hboxn#coerce ;
1219 GPack.hbox ~border_width:0
1220 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1222 GButton.button ~label:"> Next"
1223 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1225 GButton.button ~label:"Abort"
1226 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1227 ignore (cancelb#connect#clicked window#destroy) ;
1229 (okb#connect#clicked
1232 let names = !get_names () in
1233 let types_and_cons =
1235 (fun name (newinputt,cons_names_entry) ->
1236 let consnamesstr = cons_names_entry#text in
1237 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1239 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1242 [] -> expr,cons_names
1243 | _ -> raise AmbiguousInput
1244 ) names type_widgets
1246 let uri = !get_uri () in
1248 (* Let's see if so far the definition is well-typed *)
1251 (* To test if the arities of the inductive types are well *)
1252 (* typed, we check the inductive block definition where *)
1253 (* no constructor is given to each type. *)
1256 (fun name (ty,cons) -> (name, !inductive, ty, []))
1257 names types_and_cons
1259 CicTypeChecker.typecheck_mutual_inductive_defs uri
1260 (tys,params,paramsno)
1262 get_context_and_subst :=
1266 (fun (context,subst) name (ty,_) ->
1268 (Some (Cic.Name name, Cic.Decl ty))::context,
1269 (Cic.MutInd (uri,!i,[]))::subst
1272 ) ([],[]) names types_and_cons) ;
1273 let types_and_cons' =
1275 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1276 names types_and_cons
1278 get_types_and_cons := (function () -> types_and_cons') ;
1284 (`Error (`T (Printexc.to_string e)))
1287 and phase3 name cons =
1288 let get_cons_types = ref (function () -> assert false) in
1291 ~width:600 ~modal:true ~position:`CENTER
1292 ~title:(name ^ " Constructors")
1293 ~border_width:2 () in
1294 let vbox = GPack.vbox ~packing:window2#add () in
1295 let cons_type_widgets =
1297 (function consname ->
1299 GPack.hbox ~border_width:0
1300 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1302 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1303 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1304 let scrolled_window =
1305 GBin.scrolled_window ~border_width:5
1306 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1308 TermEditor'.term_editor
1310 ~width:400 ~height:20 ~packing:scrolled_window#add
1311 ~share_environment_with:inputt ()
1312 ~isnotempty_callback:
1314 (* (*non_empty_type := b ;*)
1315 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1320 GPack.hbox ~border_width:0
1321 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1323 GButton.button ~label:"> Next"
1324 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1325 let _ = okb#misc#set_sensitive true in
1327 GButton.button ~label:"Abort"
1328 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1329 ignore (window2#connect#destroy GMain.Main.quit) ;
1330 ignore (cancelb#connect#clicked window2#destroy) ;
1332 (okb#connect#clicked
1336 let context,subst= !get_context_and_subst () in
1341 inputt#get_metasenv_and_term ~context ~metasenv:[]
1345 let undebrujined_expr =
1347 (fun expr t -> CicSubstitution.subst t expr) expr subst
1349 name, undebrujined_expr
1350 | _ -> raise AmbiguousInput
1351 ) cons cons_type_widgets
1353 get_cons_types := (function () -> cons_types) ;
1358 (`Error (`T (Printexc.to_string e)))
1362 let okb_pressed = !chosen in
1364 if (not okb_pressed) then
1367 assert false (* The control never reaches this point *)
1370 (!get_cons_types ())
1373 (* No more phases left or Abort pressed *)
1379 let uri = !get_uri () in
1382 let tys = !get_types_and_cons () in
1383 let obj = Cic.InductiveDefinition(tys,params,!paramsno) in
1386 debug_print (CicPp.ppobj obj);
1387 CicTypeChecker.typecheck_mutual_inductive_defs uri
1388 (tys,params,!paramsno) ;
1391 debug_print "Offending mutual (co)inductive type declaration:" ;
1392 debug_print (CicPp.ppobj obj) ;
1394 (* We already know that obj is well-typed. We need to add it to the *)
1395 (* environment in order to compute the inner-types without having to *)
1396 (* debrujin it or having to modify lots of other functions to avoid *)
1397 (* asking the environment for the MUTINDs we are defining now. *)
1398 CicEnvironment.put_inductive_definition uri obj ;
1400 show_in_show_window_obj uri obj
1404 (`Error (`T (Printexc.to_string e)))
1408 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1409 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1410 let notebook = (rendering_window ())#notebook in
1412 let chosen = ref false in
1413 let get_metasenv_and_term = ref (function _ -> assert false) in
1414 let get_uri = ref (function _ -> assert false) in
1415 let non_empty_type = ref false in
1418 ~width:600 ~modal:true ~title:"New Proof or Definition"
1419 ~border_width:2 () in
1420 let vbox = GPack.vbox ~packing:window#add () in
1422 GPack.hbox ~border_width:0
1423 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1425 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1426 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1428 GEdit.entry ~editable:true
1429 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1430 uri_entry#set_text dummy_uri;
1431 uri_entry#select_region ~start:1 ~stop:(String.length dummy_uri);
1433 GPack.hbox ~border_width:0
1434 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1436 GMisc.label ~text:"Enter the theorem or definition type:"
1437 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1438 let scrolled_window =
1439 GBin.scrolled_window ~border_width:5
1440 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1441 (* the content of the scrolled_window is moved below (see comment) *)
1443 GPack.hbox ~border_width:0
1444 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1446 GButton.button ~label:"Ok"
1447 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1448 let _ = okb#misc#set_sensitive false in
1450 GButton.button ~label:"Cancel"
1451 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1452 (* moved here to have visibility of the ok button *)
1454 TermEditor'.term_editor
1456 ~width:400 ~height:100 ~packing:scrolled_window#add
1457 ~share_environment_with:inputt ()
1458 ~isnotempty_callback:
1460 non_empty_type := b ;
1461 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1464 newinputt#set_term inputt#get_as_string ;
1467 uri_entry#connect#changed
1469 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1471 ignore (window#connect#destroy GMain.Main.quit) ;
1472 ignore (cancelb#connect#clicked window#destroy) ;
1474 (okb#connect#clicked
1478 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1479 let uristr = "cic:" ^ uri_entry#text in
1480 let uri = UriManager.uri_of_string uristr in
1481 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1482 raise NotAUriToAConstant
1486 ignore (Http_getter.resolve' uri) ;
1487 raise UriAlreadyInUse
1488 with Http_getter_types.Unresolvable_URI _ ->
1489 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1490 get_uri := (function () -> uri) ;
1496 (`Error (`T (Printexc.to_string e)))
1502 let metasenv,expr = !get_metasenv_and_term () in
1503 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1504 ProofEngine.set_proof
1505 (Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr)) ;
1506 set_proof_engine_goal (Some 1) ;
1507 refresh_goals notebook ;
1508 refresh_proof output ;
1509 !save_set_sensitive true ;
1511 ProofEngine.intros ~mk_fresh_name_callback () ;
1512 refresh_goals notebook ;
1513 refresh_proof output
1515 InvokeTactics.RefreshSequentException e ->
1517 (`Error (`T ("Exception raised during the refresh of the " ^
1518 "sequent: " ^ Printexc.to_string e)))
1519 | InvokeTactics.RefreshProofException e ->
1521 (`Error (`T ("Exception raised during the refresh of the " ^
1522 "proof: " ^ Printexc.to_string e)))
1525 (`Error (`T (Printexc.to_string e)))
1528 let check_term_in_scratch scratch_window metasenv context expr =
1530 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1531 let expr = Cic.Cast (expr,ty) in
1532 scratch_window#show () ;
1533 scratch_window#set_term expr ;
1534 scratch_window#set_context context ;
1535 scratch_window#set_metasenv metasenv ;
1536 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1539 print_endline ("? " ^ CicPp.ppterm expr) ;
1543 let check scratch_window () =
1544 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1546 match ProofEngine.get_proof () with
1548 | Some (_,metasenv,_,_) -> metasenv
1551 match !ProofEngine.goal with
1554 let (_,canonical_context,_) =
1555 List.find (function (m,_,_) -> m=metano) metasenv
1560 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1561 check_term_in_scratch scratch_window metasenv' context expr
1565 (`Error (`T (Printexc.to_string e)))
1570 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1574 (`Error (`T (Printexc.to_string e)))
1577 exception NotADefinition;;
1580 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1581 let notebook = (rendering_window ())#notebook in
1583 let uri = input_or_locate_uri ~title:"Open" in
1584 CicTypeChecker.typecheck uri ;
1585 let metasenv,bo,ty =
1586 match CicEnvironment.get_cooked_obj uri with
1587 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1588 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1591 | Cic.InductiveDefinition _ -> raise NotADefinition
1593 ProofEngine.set_proof (Some (uri, metasenv, bo, ty)) ;
1594 set_proof_engine_goal None ;
1595 refresh_goals notebook ;
1596 refresh_proof output ;
1597 !save_set_sensitive true
1599 InvokeTactics.RefreshSequentException e ->
1601 (`Error (`T ("Exception raised during the refresh of the " ^
1602 "sequent: " ^ Printexc.to_string e)))
1603 | InvokeTactics.RefreshProofException e ->
1605 (`Error (`T ("Exception raised during the refresh of the " ^
1606 "proof: " ^ Printexc.to_string e)))
1609 (`Error (`T (Printexc.to_string e)))
1612 let show_query_results results =
1615 ~modal:false ~title:"Query results." ~border_width:2 () in
1616 let vbox = GPack.vbox ~packing:window#add () in
1618 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1621 ~text:"Click on a URI to show that object"
1622 ~packing:hbox#add () in
1623 let scrolled_window =
1624 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1625 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1626 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1629 (function (uri,_) ->
1633 clist#set_row ~selectable:false n
1636 clist#columns_autosize () ;
1638 (clist#connect#select_row
1639 (fun ~row ~column ~event ->
1640 let (uristr,_) = List.nth results row in
1642 MQueryMisc.cic_textual_parser_uri_of_string
1643 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1646 CicTextualParser0.ConUri uri
1647 | CicTextualParser0.VarUri uri
1648 | CicTextualParser0.IndTyUri (uri,_)
1649 | CicTextualParser0.IndConUri (uri,_,_) ->
1650 show_in_show_window_uri uri
1656 let refine_constraints (must_obj,must_rel,must_sort) =
1657 let chosen = ref false in
1658 let use_only = ref false in
1661 ~modal:true ~title:"Constraints refinement."
1662 ~width:800 ~border_width:2 () in
1663 let vbox = GPack.vbox ~packing:window#add () in
1665 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1668 ~text: "\"Only\" constraints can be enforced or not."
1669 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1671 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1672 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1675 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1676 (* Notebook for the constraints choice *)
1678 GPack.notebook ~scrollable:true
1679 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1680 (* Rel constraints *)
1683 ~text: "Constraints on Rels" () in
1685 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1688 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1691 ~text: "You can now specify the constraints on Rels."
1692 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1693 let expected_height = 25 * (List.length must_rel + 2) in
1694 let height = if expected_height > 400 then 400 else expected_height in
1695 let scrolled_window =
1696 GBin.scrolled_window ~border_width:10 ~height ~width:600
1697 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1698 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1699 let mk_depth_button (hbox:GPack.box) d =
1700 let mutable_ref = ref (Some d) in
1702 GButton.toggle_button
1703 ~label:("depth = " ^ string_of_int d)
1705 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1708 (depthb#connect#toggled
1710 let sel_depth = if depthb#active then Some d else None in
1711 mutable_ref := sel_depth
1714 let rel_constraints =
1719 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1722 ~text:(MQGU.text_of_position (p:>MQGT.full_position))
1723 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1725 | `MainHypothesis None
1726 | `MainConclusion None -> p, ref None
1727 | `MainHypothesis (Some depth')
1728 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth'
1730 (* Sort constraints *)
1733 ~text: "Constraints on Sorts" () in
1735 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1738 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1741 ~text: "You can now specify the constraints on Sorts."
1742 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1743 let expected_height = 25 * (List.length must_sort + 2) in
1744 let height = if expected_height > 400 then 400 else expected_height in
1745 let scrolled_window =
1746 GBin.scrolled_window ~border_width:10 ~height ~width:600
1747 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1748 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1749 let sort_constraints =
1751 (function (p, sort) ->
1754 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1757 ~text:(MQGU.text_of_sort sort ^ " " ^ MQGU.text_of_position (p:>MQGT.full_position))
1758 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1760 | `MainHypothesis None
1761 | `MainConclusion None -> p, ref None, sort
1762 | `MainHypothesis (Some depth')
1763 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', sort
1765 (* Obj constraints *)
1768 ~text: "Constraints on constants" () in
1770 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1773 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1776 ~text: "You can now specify the constraints on constants."
1777 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1778 let expected_height = 25 * (List.length must_obj + 2) in
1779 let height = if expected_height > 400 then 400 else expected_height in
1780 let scrolled_window =
1781 GBin.scrolled_window ~border_width:10 ~height ~width:600
1782 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1783 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1784 let obj_constraints =
1786 (function (p, uri) ->
1789 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1792 ~text:(uri ^ " " ^ (MQGU.text_of_position p))
1793 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1798 | `MainHypothesis None
1799 | `MainConclusion None -> p, ref None, uri
1800 | `MainHypothesis (Some depth')
1801 | `MainConclusion (Some depth') -> p, mk_depth_button hbox depth', uri
1803 (* Confirm/abort buttons *)
1805 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1807 GButton.button ~label:"Ok"
1808 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1810 GButton.button ~label:"Abort"
1811 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1813 ignore (window#connect#destroy GMain.Main.quit) ;
1814 ignore (cancelb#connect#clicked window#destroy) ;
1816 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1817 window#set_position `CENTER ;
1821 let chosen_must_rel =
1823 (function (position, ref_depth) -> MQGU.set_main_position position !ref_depth)
1826 let chosen_must_sort =
1828 (function (position, ref_depth, sort) ->
1829 MQGU.set_main_position position !ref_depth,sort)
1832 let chosen_must_obj =
1834 (function (position, ref_depth, uri) -> MQGU.set_full_position position !ref_depth, uri)
1837 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1839 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1840 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1848 let completeSearchPattern () =
1849 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1851 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1852 let must = CGSearchPattern.get_constraints expr in
1853 let must',only = refine_constraints must in
1855 MQG.query_of_constraints (Some CGSearchPattern.universe) must' only
1857 let results = MQI.execute mqi_handle query in
1858 show_query_results results
1862 (`Error (`T (Printexc.to_string e)))
1865 let insertQuery () =
1867 let chosen = ref None in
1870 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1871 let vbox = GPack.vbox ~packing:window#add () in
1873 GMisc.label ~text:"Insert Query. For Experts Only."
1874 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1875 let scrolled_window =
1876 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1877 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1878 let input = GText.view ~editable:true
1879 ~packing:scrolled_window#add () in
1881 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1883 GButton.button ~label:"Ok"
1884 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1886 GButton.button ~label:"Load from file..."
1887 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1889 GButton.button ~label:"Abort"
1890 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1891 ignore (window#connect#destroy GMain.Main.quit) ;
1892 ignore (cancelb#connect#clicked window#destroy) ;
1894 (okb#connect#clicked
1896 chosen := Some (input#buffer#get_text ()) ; window#destroy ())) ;
1898 (loadb#connect#clicked
1901 GToolbox.select_file ~title:"Select Query File" ()
1905 let inch = open_in filename in
1906 let rec read_file () =
1908 let line = input_line inch in
1909 line ^ "\n" ^ read_file ()
1913 let text = read_file () in
1914 input#buffer#delete input#buffer#start_iter input#buffer#end_iter ;
1915 ignore (input#buffer#insert text))) ;
1916 window#set_position `CENTER ;
1923 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1925 show_query_results results
1929 (`Error (`T (Printexc.to_string e)))
1932 let choose_must list_of_must only =
1933 let chosen = ref None in
1934 let user_constraints = ref [] in
1937 ~modal:true ~title:"Query refinement." ~border_width:2 () in
1938 let vbox = GPack.vbox ~packing:window#add () in
1940 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1944 ("You can now specify the genericity of the query. " ^
1945 "The more generic the slower.")
1946 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1948 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1952 "Suggestion: start with faster queries before moving to more generic ones."
1953 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1955 GPack.notebook ~scrollable:true
1956 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1959 let last = List.length list_of_must in
1965 (if !page = 1 then "More generic" else
1966 if !page = last then "More precise" else " ") () in
1967 let expected_height = 25 * (List.length must + 2) in
1968 let height = if expected_height > 400 then 400 else expected_height in
1969 let scrolled_window =
1970 GBin.scrolled_window ~border_width:10 ~height ~width:600
1971 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1973 GList.clist ~columns:2 ~packing:scrolled_window#add
1974 ~titles:["URI" ; "Position"] ()
1978 (function (position, uri) ->
1981 [uri; MQGUtil.text_of_position position]
1983 clist#set_row ~selectable:false n
1986 clist#columns_autosize ()
1989 let label = GMisc.label ~text:"User provided" () in
1991 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
1993 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1996 ~text:"Select the constraints that must be satisfied and press OK."
1997 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1998 let expected_height = 25 * (List.length only + 2) in
1999 let height = if expected_height > 400 then 400 else expected_height in
2000 let scrolled_window =
2001 GBin.scrolled_window ~border_width:10 ~height ~width:600
2002 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2004 GList.clist ~columns:2 ~packing:scrolled_window#add
2005 ~selection_mode:`MULTIPLE
2006 ~titles:["URI" ; "Position"] ()
2010 (function (position, uri) ->
2013 [uri; MQGUtil.text_of_position position]
2015 clist#set_row ~selectable:true n
2018 clist#columns_autosize () ;
2020 (clist#connect#select_row
2021 (fun ~row ~column ~event ->
2022 user_constraints := (List.nth only row)::!user_constraints)) ;
2024 (clist#connect#unselect_row
2025 (fun ~row ~column ~event ->
2028 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2031 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2033 GButton.button ~label:"Ok"
2034 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2036 GButton.button ~label:"Abort"
2037 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2039 ignore (window#connect#destroy GMain.Main.quit) ;
2040 ignore (cancelb#connect#clicked window#destroy) ;
2042 (okb#connect#clicked
2043 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2044 window#set_position `CENTER ;
2048 None -> raise NoChoice
2050 if n = List.length list_of_must then
2051 (* user provided constraints *)
2054 List.nth list_of_must n
2057 let searchPattern () =
2058 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2061 match ProofEngine.get_proof () with
2062 None -> assert false
2063 | Some proof -> proof
2065 match !ProofEngine.goal with
2069 TacticChaser.matchConclusion mqi_handle
2070 ~choose_must () ~status:(proof, metano)
2073 user_uri_choice ~title:"Ambiguous input."
2074 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2077 inputt#set_term uri' ;
2078 InvokeTactics'.apply ()
2082 (`Error (`T (Printexc.to_string e)))
2085 let choose_selection mmlwidget (element : Gdome.element option) =
2086 let module G = Gdome in
2087 let rec aux element =
2088 if element#hasAttributeNS
2089 ~namespaceURI:Misc.helmns
2090 ~localName:(G.domString "xref")
2092 mmlwidget#set_selection (Some element)
2095 match element#get_parentNode with
2096 None -> assert false
2097 (*CSC: OCAML DIVERGES!
2098 | Some p -> aux (new G.element_of_node p)
2100 | Some p -> aux (new Gdome.element_of_node p)
2102 GdomeInit.DOMCastException _ ->
2104 "******* trying to select above the document root ********"
2108 | None -> mmlwidget#set_selection None
2111 (* STUFF TO BUILD THE GTK INTERFACE *)
2113 (* Stuff for the widget settings *)
2116 let export_to_postscript output =
2117 let lastdir = ref (Unix.getcwd ()) in
2120 GToolbox.select_file ~title:"Export to PostScript"
2121 ~dir:lastdir ~filename:"screenshot.ps" ()
2125 (output :> GMathView.math_view)#export_to_postscript
2126 ~filename:filename ();
2131 let activate_t1 output button_set_anti_aliasing
2132 button_set_transparency export_to_postscript_menu_item
2135 let is_set = button_t1#active in
2136 output#set_font_manager_type
2137 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2140 button_set_anti_aliasing#misc#set_sensitive true ;
2141 button_set_transparency#misc#set_sensitive true ;
2142 export_to_postscript_menu_item#misc#set_sensitive true ;
2146 button_set_anti_aliasing#misc#set_sensitive false ;
2147 button_set_transparency#misc#set_sensitive false ;
2148 export_to_postscript_menu_item#misc#set_sensitive false ;
2152 let set_anti_aliasing output button_set_anti_aliasing () =
2153 output#set_anti_aliasing button_set_anti_aliasing#active
2156 let set_transparency output button_set_transparency () =
2157 output#set_transparency button_set_transparency#active
2161 let changefont output font_size_spinb () =
2162 output#set_font_size font_size_spinb#value_as_int
2165 let set_log_verbosity output log_verbosity_spinb () =
2166 output#set_log_verbosity log_verbosity_spinb#value_as_int
2169 class settings_window output sw
2170 export_to_postscript_menu_item selection_changed_callback
2172 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2174 GPack.vbox ~packing:settings_window#add () in
2177 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2178 ~border_width:5 ~packing:vbox#add () in
2180 GButton.toggle_button ~label:"activate t1 fonts"
2181 ~packing:(table#attach ~left:0 ~top:0) () in
2182 let button_set_anti_aliasing =
2183 GButton.toggle_button ~label:"set_anti_aliasing"
2184 ~packing:(table#attach ~left:0 ~top:1) () in
2185 let button_set_transparency =
2186 GButton.toggle_button ~label:"set_transparency"
2187 ~packing:(table#attach ~left:2 ~top:1) () in
2190 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2191 ~border_width:5 ~packing:vbox#add () in
2192 let font_size_label =
2193 GMisc.label ~text:"font size:"
2194 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2195 let font_size_spinb =
2197 GData.adjustment ~value:(float_of_int output#get_font_size)
2198 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2201 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2202 let log_verbosity_label =
2203 GMisc.label ~text:"log verbosity:"
2204 ~packing:(table#attach ~left:0 ~top:1) () in
2205 let log_verbosity_spinb =
2207 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2210 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2212 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2214 GButton.button ~label:"Close"
2215 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2217 method show = settings_window#show
2219 button_set_anti_aliasing#misc#set_sensitive false ;
2220 button_set_transparency#misc#set_sensitive false ;
2221 (* Signals connection *)
2223 ignore(button_t1#connect#clicked
2224 (activate_t1 output button_set_anti_aliasing
2225 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2227 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2229 ignore(button_set_anti_aliasing#connect#toggled
2230 (set_anti_aliasing output button_set_anti_aliasing));
2231 ignore(button_set_transparency#connect#toggled
2232 (set_transparency output button_set_transparency)) ;
2234 ignore(log_verbosity_spinb#connect#changed
2235 (set_log_verbosity output log_verbosity_spinb)) ;
2236 ignore(closeb#connect#clicked settings_window#misc#hide)
2239 (* Scratch window *)
2241 class scratch_window =
2244 ~title:"MathML viewer"
2245 ~border_width:2 () in
2247 GPack.vbox ~packing:window#add () in
2249 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2251 GButton.button ~label:"Whd"
2252 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2254 GButton.button ~label:"Reduce"
2255 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2257 GButton.button ~label:"Simpl"
2258 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2259 let scrolled_window =
2260 GBin.scrolled_window ~border_width:10
2261 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2262 let sequent_viewer =
2263 TermViewer.sequent_viewer
2264 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2266 val mutable term = Cic.Rel 1 (* dummy value *)
2267 val mutable context = ([] : Cic.context) (* dummy value *)
2268 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2269 method sequent_viewer = sequent_viewer
2270 method show () = window#misc#hide () ; window#show ()
2272 method set_term t = term <- t
2273 method context = context
2274 method set_context t = context <- t
2275 method metasenv = metasenv
2276 method set_metasenv t = metasenv <- t
2279 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2280 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2281 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2282 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2283 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2286 let open_contextual_menu_for_selected_terms mmlwidget infos =
2287 let button = GdkEvent.Button.button infos in
2288 let terms_selected = List.length mmlwidget#get_selections > 0 in
2291 let time = GdkEvent.Button.time infos in
2292 let menu = GMenu.menu () in
2293 let f = new GMenu.factory menu in
2295 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2296 let reduce_menu_item =
2297 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2298 let simpl_menu_item =
2299 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2300 let _ = f#add_separator () in
2301 let generalize_menu_item =
2302 f#add_item "Generalize"
2303 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2304 let _ = f#add_separator () in
2305 let clear_menu_item =
2306 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2307 let clearbody_menu_item =
2308 f#add_item "ClearBody"
2309 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2311 whd_menu_item#misc#set_sensitive terms_selected ;
2312 reduce_menu_item#misc#set_sensitive terms_selected ;
2313 simpl_menu_item#misc#set_sensitive terms_selected ;
2314 generalize_menu_item#misc#set_sensitive terms_selected ;
2315 clear_menu_item#misc#set_sensitive terms_selected ;
2316 clearbody_menu_item#misc#set_sensitive terms_selected ;
2317 menu#popup ~button ~time
2323 let vbox1 = GPack.vbox () in
2325 val mutable proofw_ref = None
2326 val mutable compute_ref = None
2328 Lazy.force self#compute ;
2329 match proofw_ref with
2330 None -> assert false
2331 | Some proofw -> proofw
2332 method content = vbox1
2334 match compute_ref with
2335 None -> assert false
2336 | Some compute -> compute
2340 let scrolled_window1 =
2341 GBin.scrolled_window ~border_width:10
2342 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2344 TermViewer.sequent_viewer ~width:400 ~height:275
2345 ~packing:(scrolled_window1#add) () in
2346 let _ = proofw_ref <- Some proofw in
2348 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2350 GButton.button ~label:"Ring"
2351 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2353 GButton.button ~label:"Fourier"
2354 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2356 GButton.button ~label:"Reflexivity"
2357 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2359 GButton.button ~label:"Symmetry"
2360 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2362 GButton.button ~label:"Assumption"
2363 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2364 let contradictionb =
2365 GButton.button ~label:"Contradiction"
2366 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2368 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2370 GButton.button ~label:"Exists"
2371 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2373 GButton.button ~label:"Split"
2374 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2376 GButton.button ~label:"Left"
2377 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2379 GButton.button ~label:"Right"
2380 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2381 let searchpatternb =
2382 GButton.button ~label:"SearchPattern_Apply"
2383 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2385 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2387 GButton.button ~label:"Exact"
2388 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2390 GButton.button ~label:"Intros"
2391 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2393 GButton.button ~label:"Apply"
2394 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2395 let elimintrossimplb =
2396 GButton.button ~label:"ElimIntrosSimpl"
2397 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2399 GButton.button ~label:"ElimType"
2400 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2402 GButton.button ~label:"Fold_whd"
2403 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2405 GButton.button ~label:"Fold_reduce"
2406 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2408 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2410 GButton.button ~label:"Fold_simpl"
2411 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2413 GButton.button ~label:"Cut"
2414 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2416 GButton.button ~label:"Change"
2417 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2419 GButton.button ~label:"Let ... In"
2420 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2422 GButton.button ~label:"RewriteSimpl ->"
2423 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2424 let rewritebacksimplb =
2425 GButton.button ~label:"RewriteSimpl <-"
2426 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2428 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2430 GButton.button ~label:"Absurd"
2431 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2433 GButton.button ~label:"Decompose"
2434 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2436 GButton.button ~label:"Transitivity"
2437 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2439 GButton.button ~label:"Replace"
2440 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2442 GButton.button ~label:"Injection"
2443 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2445 GButton.button ~label:"Discriminate"
2446 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2447 (* Zack: spostare in una toolbar
2449 GButton.button ~label:"Generalize"
2450 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2452 GButton.button ~label:"ClearBody"
2453 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2455 GButton.button ~label:"Clear"
2456 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2458 GButton.button ~label:"Whd"
2459 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2461 GButton.button ~label:"Reduce"
2462 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2464 GButton.button ~label:"Simpl"
2465 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2468 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2469 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2470 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2471 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2472 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2473 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2474 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2475 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2476 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2477 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2478 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2479 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2480 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2481 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2482 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2483 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2484 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2485 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2486 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2487 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2488 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2489 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2490 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2491 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2492 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2493 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2494 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2495 ignore(searchpatternb#connect#clicked searchPattern) ;
2496 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2497 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2498 (* Zack: spostare in una toolbar
2499 ignore(whdb#connect#clicked whd) ;
2500 ignore(reduceb#connect#clicked reduce) ;
2501 ignore(simplb#connect#clicked simpl) ;
2502 ignore(clearbodyb#connect#clicked clearbody) ;
2503 ignore(clearb#connect#clicked clear) ;
2504 ignore(generalizeb#connect#clicked generalize) ;
2506 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2508 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2509 (open_contextual_menu_for_selected_terms proofw)) ;
2515 let vbox1 = GPack.vbox () in
2516 let scrolled_window1 =
2517 GBin.scrolled_window ~border_width:10
2518 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2520 TermViewer.sequent_viewer ~width:400 ~height:275
2521 ~packing:(scrolled_window1#add) () in
2523 method proofw = (assert false : TermViewer.sequent_viewer)
2524 method content = vbox1
2525 method compute = (assert false : unit)
2529 let empty_page = new empty_page;;
2533 val notebook = GPack.notebook ()
2535 val mutable skip_switch_page_event = false
2536 val mutable empty = true
2537 method notebook = notebook
2539 let new_page = new page () in
2541 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2542 notebook#append_page
2543 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2544 new_page#content#coerce
2545 method remove_all_pages ~skip_switch_page_event:skip =
2547 notebook#remove_page 0 (* let's remove the empty page *)
2549 List.iter (function _ -> notebook#remove_page 0) !pages ;
2551 skip_switch_page_event <- skip
2552 method set_current_page ~may_skip_switch_page_event n =
2553 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2554 let new_page = notebook#page_num page#content#coerce in
2555 if may_skip_switch_page_event && new_page <> notebook#current_page then
2556 skip_switch_page_event <- true ;
2557 notebook#goto_page new_page
2558 method set_empty_page =
2561 notebook#append_page
2562 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2563 empty_page#content#coerce
2565 let (_,_,page) = List.nth !pages notebook#current_page in
2569 (notebook#connect#switch_page
2571 let skip = skip_switch_page_event in
2572 skip_switch_page_event <- false ;
2575 let (metano,setgoal,page) = List.nth !pages i in
2576 set_proof_engine_goal (Some metano) ;
2577 Lazy.force (page#compute) ;
2579 if notify_hbugs_on_goal_change then
2586 let dump_environment () =
2588 let oc = open_out (Helm_registry.get "triciclo.environment_file") in
2589 HelmLogger.log (`Msg (`T "Dumping environment ..."));
2590 CicEnvironment.dump_to_channel oc;
2591 HelmLogger.log (`Msg (`T "... done!")) ;
2595 (`Error (`T (Printf.sprintf "Dump failure, uncaught exception:%s"
2596 (Printexc.to_string exc))))
2598 let restore_environment () =
2600 let ic = open_in (Helm_registry.get "triciclo.environment_file") in
2601 HelmLogger.log (`Msg (`T "Restoring environment ... "));
2602 CicEnvironment.restore_from_channel ic;
2603 HelmLogger.log (`Msg (`T "... done!"));
2607 (`Error (`T (Printf.sprintf "Restore failure, uncaught exception:%s"
2608 (Printexc.to_string exc))))
2613 class rendering_window output (notebook : notebook) =
2614 let scratch_window = new scratch_window in
2617 ~title:"gTopLevel - Helm's Proof Assistant"
2618 ~border_width:0 ~allow_shrink:false () in
2619 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2621 let handle_box = GBin.handle_box ~border_width:2
2622 ~packing:(vbox_for_menu#pack ~padding:0) () in
2623 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2624 let factory0 = new GMenu.factory menubar in
2625 let accel_group = factory0#accel_group in
2627 let file_menu = factory0#add_submenu "File" in
2628 let factory1 = new GMenu.factory file_menu ~accel_group in
2629 (* let export_to_postscript_menu_item = *)
2633 factory1#add_item "New Block of (Co)Inductive Definitions..."
2634 ~key:GdkKeysyms._B ~callback:new_inductive
2637 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2640 let reopen_menu_item =
2641 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2645 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2646 ignore (factory1#add_separator ()) ;
2648 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2649 ~callback:load_unfinished_proof) ;
2650 let save_menu_item =
2651 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2652 ~callback:save_unfinished_proof
2654 ignore (factory1#add_separator ()) ;
2655 ignore (factory1#add_item "Clear Environment" ~callback:CicEnvironment.empty);
2656 ignore (factory1#add_item "Dump Environment" ~callback:dump_environment);
2658 (factory1#add_item "Restore Environment" ~callback:restore_environment);
2660 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2661 ignore (!save_set_sensitive false);
2662 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2663 ignore (!qed_set_sensitive false);
2664 ignore (factory1#add_separator ()) ;
2666 let export_to_postscript_menu_item =
2667 factory1#add_item "Export to PostScript..."
2668 ~callback:(export_to_postscript output) in
2670 ignore (factory1#add_separator ()) ;
2672 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) (*;
2673 export_to_postscript_menu_item *)
2676 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2677 let factory2 = new GMenu.factory edit_menu ~accel_group in
2678 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2679 let proveit_menu_item =
2680 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2681 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2683 let focus_menu_item =
2684 factory2#add_item "Focus" ~key:GdkKeysyms._F
2685 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2688 focus_and_proveit_set_sensitive :=
2690 proveit_menu_item#misc#set_sensitive b ;
2691 focus_menu_item#misc#set_sensitive b
2693 let _ = !focus_and_proveit_set_sensitive false in
2694 (* edit term menu *)
2695 let edit_term_menu = factory0#add_submenu "Edit Term" in
2696 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2697 let check_menu_item =
2698 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2699 ~callback:(check scratch_window) in
2700 let _ = check_menu_item#misc#set_sensitive false in
2702 let search_menu = factory0#add_submenu "Search" in
2703 let factory4 = new GMenu.factory search_menu ~accel_group in
2705 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2707 let searchPattern_menu_item =
2708 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2709 ~callback:completeSearchPattern in
2710 let _ = searchPattern_menu_item#misc#set_sensitive false in
2711 let show_menu_item =
2712 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2714 let insert_query_item =
2715 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2716 ~callback:insertQuery in
2718 let hbugs_menu = factory0#add_submenu "HBugs" in
2719 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2721 factory6#add_check_item
2722 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2725 factory6#add_item ~key:GdkKeysyms._Return ~callback:Hbugs.notify
2726 "(Re)Submit status!"
2728 let _ = factory6#add_separator () in
2730 factory6#add_item ~callback:Hbugs.start_web_services "Start Web Services"
2733 factory6#add_item ~callback:Hbugs.stop_web_services "Stop Web Services"
2736 let settings_menu = factory0#add_submenu "Settings" in
2737 let factory3 = new GMenu.factory settings_menu ~accel_group in
2739 factory3#add_item "Edit Aliases..." ~key:GdkKeysyms._A
2740 ~callback:edit_aliases in
2742 factory3#add_item "Clear Aliases" ~key:GdkKeysyms._K
2743 ~callback:clear_aliases in
2745 factory3#add_check_item "Auto disambiguation"
2746 ~callback:(fun checked -> auto_disambiguation := checked) in
2747 let _ = factory3#add_separator () in
2749 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2750 ~callback:(function _ -> (settings_window ())#show ()) in
2751 let _ = factory3#add_separator () in
2753 factory3#add_item "Reload Stylesheets"
2756 ChosenTransformer.reload_stylesheets () ;
2757 if ProofEngine.get_proof () <> None then
2759 refresh_goals notebook ;
2760 refresh_proof output
2762 InvokeTactics.RefreshSequentException e ->
2764 (`Error (`T ("An error occurred while refreshing the " ^
2765 "sequent: " ^ Printexc.to_string e))) ;
2766 (*notebook#remove_all_pages ~skip_switch_page_event:false ;*)
2767 notebook#set_empty_page
2768 | InvokeTactics.RefreshProofException e ->
2770 (`Error (`T ("An error occurred while refreshing the proof: " ^ Printexc.to_string e))) ;
2774 let _ = window#add_accel_group accel_group in
2778 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2780 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2781 let scrolled_window0 =
2782 GBin.scrolled_window ~border_width:10
2783 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2784 let _ = scrolled_window0#add output#coerce in
2786 GBin.frame ~label:"Insert Term"
2787 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2788 let scrolled_window1 =
2789 GBin.scrolled_window ~border_width:5
2790 ~packing:frame#add () in
2792 TermEditor'.term_editor
2794 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2795 ~isnotempty_callback:
2797 check_menu_item#misc#set_sensitive b ;
2798 searchPattern_menu_item#misc#set_sensitive b) in
2800 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2802 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2804 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2807 new HelmGtkLogger.html_logger
2808 ~width:400 ~height: 100 ~show:true ~packing:frame#add ()
2811 method inputt = inputt
2812 method output = (output : TermViewer.proof_viewer)
2813 method scratch_window = scratch_window
2814 method notebook = notebook
2815 method show = window#show
2816 method set_auto_disambiguation set = autoitem#set_active set
2818 notebook#set_empty_page ;
2819 (*export_to_postscript_menu_item#misc#set_sensitive false ;*)
2820 check_term := (check_term_in_scratch scratch_window) ;
2822 (* signal handlers here *)
2823 ignore(output#connect#selection_changed
2825 choose_selection output elem ;
2826 !focus_and_proveit_set_sensitive true
2828 ignore (output#connect#click (show_in_show_window_callback output)) ;
2829 let settings_window = new settings_window output scrolled_window0
2830 (*export_to_postscript_menu_item*)() (choose_selection output) in
2831 set_settings_window settings_window ;
2832 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true ))
2837 let initialize_everything () =
2838 if not (Sys.file_exists configuration_file) then begin
2839 eprintf "E: Can't find configuration file '%s'\n" configuration_file;
2842 Helm_registry.load_from configuration_file;
2843 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2844 let notebook = new notebook in
2845 let rendering_window' = new rendering_window output notebook in
2846 rendering_window'#set_auto_disambiguation !auto_disambiguation;
2847 set_rendering_window rendering_window';
2848 let print_error_as_html prefix msg =
2849 HelmLogger.log (`Error (`T (prefix ^ msg)))
2851 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2852 Gdome_xslt.setDebugCallback
2853 (Some (print_error_as_html "XSLT Debug Message: "));
2854 rendering_window'#show () ;
2855 if restore_environment_on_boot &&
2856 Sys.file_exists (Helm_registry.get "triciclo.environment_file")
2858 restore_environment ();
2863 ignore (GtkMain.Main.init ()) ;
2864 initialize_everything () ;
2865 MQIC.close mqi_handle;
2870 Sys.catch_break true;
2872 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)