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 (******************************************************************************)
40 module MQI = MQueryInterpreter
42 module MQG = MQueryGenerator
44 (* GLOBAL CONSTANTS *)
46 let mqi_flags = [] (* default MathQL interpreter options *)
47 let mqi_handle = MQIC.init mqi_flags prerr_string
49 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
53 " <body bgColor=\"white\">"
63 Sys.getenv "GTOPLEVEL_PROOFFILE"
65 Not_found -> "/public/currentproof"
70 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
72 Not_found -> "/public/currentprooftype"
75 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
77 let htmlheader_and_content = ref htmlheader;;
79 let check_term = ref (fun _ _ _ -> assert false);;
81 exception RenderingWindowsNotInitialized;;
83 let set_rendering_window,rendering_window =
84 let rendering_window_ref = ref None in
85 (function rw -> rendering_window_ref := Some rw),
87 match !rendering_window_ref with
88 None -> raise RenderingWindowsNotInitialized
93 exception SettingsWindowsNotInitialized;;
95 let set_settings_window,settings_window =
96 let settings_window_ref = ref None in
97 (function rw -> settings_window_ref := Some rw),
99 match !settings_window_ref with
100 None -> raise SettingsWindowsNotInitialized
105 exception OutputHtmlNotInitialized;;
107 let set_outputhtml,outputhtml =
108 let outputhtml_ref = ref None in
109 (function rw -> outputhtml_ref := Some rw),
111 match !outputhtml_ref with
112 None -> raise OutputHtmlNotInitialized
113 | Some outputhtml -> outputhtml
117 exception QedSetSensitiveNotInitialized;;
118 let qed_set_sensitive =
119 ref (function _ -> raise QedSetSensitiveNotInitialized)
122 exception SaveSetSensitiveNotInitialized;;
123 let save_set_sensitive =
124 ref (function _ -> raise SaveSetSensitiveNotInitialized)
127 (* COMMAND LINE OPTIONS *)
133 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
136 Arg.parse argspec ignore ""
140 let term_of_cic_textual_parser_uri uri =
141 let module C = Cic in
142 let module CTP = CicTextualParser0 in
144 CTP.ConUri uri -> C.Const (uri,[])
145 | CTP.VarUri uri -> C.Var (uri,[])
146 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
147 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
150 let string_of_cic_textual_parser_uri uri =
151 let module C = Cic in
152 let module CTP = CicTextualParser0 in
155 CTP.ConUri uri -> UriManager.string_of_uri uri
156 | CTP.VarUri uri -> UriManager.string_of_uri uri
157 | CTP.IndTyUri (uri,tyno) ->
158 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
159 | CTP.IndConUri (uri,tyno,consno) ->
160 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
163 (* 4 = String.length "cic:" *)
164 String.sub uri' 4 (String.length uri' - 4)
167 let output_html outputhtml msg =
168 htmlheader_and_content := !htmlheader_and_content ^ msg ;
169 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
170 outputhtml#set_topline (-1)
173 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
177 let check_window outputhtml uris =
180 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
182 GPack.notebook ~scrollable:true ~packing:window#add () in
187 let scrolled_window =
188 GBin.scrolled_window ~border_width:10
190 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
195 TermViewer.sequent_viewer
196 ~packing:scrolled_window#add ~width:400 ~height:280 () in
199 term_of_cic_textual_parser_uri
200 (MQueryMisc.cic_textual_parser_uri_of_string uri)
202 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
205 mmlwidget#load_sequent [] (111,[],expr)
208 output_html outputhtml
209 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
214 (notebook#connect#switch_page
215 (function i -> Lazy.force (List.nth render_terms i)))
221 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
222 ?(enable_button_for_non_vars=false) ~title ~msg uris
224 let choices = ref [] in
225 let chosen = ref false in
226 let use_only_constants = ref false in
228 GWindow.dialog ~modal:true ~title ~width:600 () in
230 GMisc.label ~text:msg
231 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
232 let scrolled_window =
233 GBin.scrolled_window ~border_width:10
234 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
236 let expected_height = 18 * List.length uris in
237 let height = if expected_height > 400 then 400 else expected_height in
238 GList.clist ~columns:1 ~packing:scrolled_window#add
239 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
240 let _ = List.map (function x -> clist#append [x]) uris in
242 GPack.hbox ~border_width:0
243 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
245 GMisc.label ~text:"None of the above. Try this one:"
246 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
248 GEdit.entry ~editable:true
249 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
251 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
253 GButton.button ~label:ok
254 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
255 let _ = okb#misc#set_sensitive false in
260 if enable_button_for_non_vars then
261 hbox#pack ~expand:false ~fill:false ~padding:5 w)
262 ~label:"Try constants only" () in
264 GButton.button ~label:"Check"
265 ~packing:(hbox#pack ~padding:5) () in
266 let _ = checkb#misc#set_sensitive false in
268 GButton.button ~label:"Abort"
269 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
271 let check_callback () =
272 assert (List.length !choices > 0) ;
273 check_window (outputhtml ()) !choices
275 ignore (window#connect#destroy GMain.Main.quit) ;
276 ignore (cancelb#connect#clicked window#destroy) ;
278 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
280 (nonvarsb#connect#clicked
282 use_only_constants := true ;
286 ignore (checkb#connect#clicked check_callback) ;
288 (clist#connect#select_row
289 (fun ~row ~column ~event ->
290 checkb#misc#set_sensitive true ;
291 okb#misc#set_sensitive true ;
292 choices := (List.nth uris row)::!choices)) ;
294 (clist#connect#unselect_row
295 (fun ~row ~column ~event ->
297 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
299 (manual_input#connect#changed
301 if manual_input#text = "" then
304 checkb#misc#set_sensitive false ;
305 okb#misc#set_sensitive false ;
306 clist#misc#set_sensitive true
310 choices := [manual_input#text] ;
311 clist#unselect_all () ;
312 checkb#misc#set_sensitive true ;
313 okb#misc#set_sensitive true ;
314 clist#misc#set_sensitive false
316 window#set_position `CENTER ;
320 if !use_only_constants then
322 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
325 if List.length !choices > 0 then !choices else raise NoChoice
330 let interactive_interpretation_choice interpretations =
331 let chosen = ref None in
334 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
335 let vbox = GPack.vbox ~packing:window#add () in
339 ("Ambiguous input since there are many well-typed interpretations." ^
340 " Please, choose one of them.")
341 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
343 GPack.notebook ~scrollable:true
344 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
347 (function interpretation ->
349 let expected_height = 18 * List.length interpretation in
350 let height = if expected_height > 400 then 400 else expected_height in
351 GList.clist ~columns:2 ~packing:notebook#append_page ~height
352 ~titles:["id" ; "URI"] ()
356 (function (id,uri) ->
357 let n = clist#append [id;uri] in
358 clist#set_row ~selectable:false n
361 clist#columns_autosize ()
364 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
366 GButton.button ~label:"Ok"
367 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
369 GButton.button ~label:"Abort"
370 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
372 ignore (window#connect#destroy GMain.Main.quit) ;
373 ignore (cancelb#connect#clicked window#destroy) ;
376 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
377 window#set_position `CENTER ;
381 None -> raise NoChoice
389 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
392 let struri = UriManager.string_of_uri uri in
393 let idx = (String.rindex struri '/') + 1 in
394 String.sub struri idx (String.length struri - idx)
396 let path = pathname ^ "/" ^ name in
398 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
402 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
403 ~ask_dtd_to_the_getter:false
406 let innertypesuri = UriManager.innertypesuri_of_uri uri in
407 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
408 Getter.register innertypesuri
409 (Configuration.annotations_url ^
410 Str.replace_first (Str.regexp "^cic:") ""
411 (UriManager.string_of_uri innertypesuri) ^ ".xml"
413 (* constant type / variable / mutual inductive types definition *)
414 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
416 (Configuration.annotations_url ^
417 Str.replace_first (Str.regexp "^cic:") ""
418 (UriManager.string_of_uri uri) ^ ".xml"
425 match UriManager.bodyuri_of_uri uri with
427 | Some bodyuri -> bodyuri
429 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
430 Getter.register bodyuri
431 (Configuration.annotations_url ^
432 Str.replace_first (Str.regexp "^cic:") ""
433 (UriManager.string_of_uri bodyuri) ^ ".xml"
440 exception OpenConjecturesStillThere;;
441 exception WrongProof;;
443 let pathname_of_annuri uristring =
444 Configuration.annotations_dir ^
445 Str.replace_first (Str.regexp "^cic:") "" uristring
448 let make_dirs dirpath =
449 ignore (Unix.system ("mkdir -p " ^ dirpath))
452 let save_obj uri obj =
454 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
455 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
457 Cic2acic.acic_object_of_cic_object obj
459 (* let's save the theorem and register it to the getter *)
460 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
462 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
467 match !ProofEngine.proof with
469 | Some (uri,[],bo,ty) ->
471 CicReduction.are_convertible []
472 (CicTypeChecker.type_of_aux' [] [] bo) ty
475 (*CSC: Wrong: [] is just plainly wrong *)
476 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
477 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
478 (rendering_window ())#output#load_proof uri proof
480 !qed_set_sensitive false ;
481 (* let's save the theorem and register it to the getter *)
482 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
484 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
489 | _ -> raise OpenConjecturesStillThere
492 (** save an unfinished proof on the filesystem *)
493 let save_unfinished_proof () =
494 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
495 let (xml, bodyxml) = ProofEngine.get_current_status_as_xml () in
496 Xml.pp ~quiet:true xml (Some prooffiletype) ;
497 output_html outputhtml
498 ("<h1 color=\"Green\">Current proof type saved to " ^
499 prooffiletype ^ "</h1>") ;
500 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
501 output_html outputhtml
502 ("<h1 color=\"Green\">Current proof body saved to " ^
506 (* Used to typecheck the loaded proofs *)
507 let typecheck_loaded_proof metasenv bo ty =
508 let module T = CicTypeChecker in
511 (fun metasenv ((_,context,ty) as conj) ->
512 ignore (T.type_of_aux' metasenv context ty) ;
515 ignore (T.type_of_aux' metasenv [] ty) ;
516 ignore (T.type_of_aux' metasenv [] bo)
519 let decompose_uris_choice_callback uris =
520 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
521 let module U = UriManager in
524 match MQueryMisc.cic_textual_parser_uri_of_string uri with
525 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
527 (interactive_user_uri_choice
528 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
529 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
531 (function (uri,typeno,_) ->
532 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
537 let mk_fresh_name_callback context name ~typ =
539 match ProofEngineHelpers.mk_fresh_name context name ~typ with
540 Cic.Name fresh_name -> fresh_name
541 | Cic.Anonymous -> assert false
544 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
545 ("Enter a fresh name for the hypothesis " ^
547 (List.map (function None -> None | Some (n,_) -> Some n) context))
549 Some fresh_name' -> Cic.Name fresh_name'
550 | None -> raise NoChoice
553 let refresh_proof (output : TermViewer.proof_viewer) =
555 let uri,currentproof =
556 match !ProofEngine.proof with
558 | Some (uri,metasenv,bo,ty) ->
559 if List.length metasenv = 0 then
561 !qed_set_sensitive true ;
562 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.clear ()" ;
567 prerr_endline "CSC: ###### REFRESH_PROOF, Hbugs.notify ()" ;
570 (*CSC: Wrong: [] is just plainly wrong *)
572 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
574 ignore (output#load_proof uri currentproof)
577 match !ProofEngine.proof with
579 | Some (uri,metasenv,bo,ty) ->
580 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
581 raise (InvokeTactics.RefreshProofException e)
583 let refresh_goals ?(empty_notebook=true) notebook =
585 match !ProofEngine.goal with
587 if empty_notebook then
589 notebook#remove_all_pages ~skip_switch_page_event:false ;
590 notebook#set_empty_page
593 notebook#proofw#unload
596 match !ProofEngine.proof with
598 | Some (_,metasenv,_,_) -> metasenv
601 List.find (function (m,_,_) -> m=metano) metasenv
603 let regenerate_notebook () =
604 let skip_switch_page_event =
606 (m,_,_)::_ when m = metano -> false
609 notebook#remove_all_pages ~skip_switch_page_event ;
610 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
612 if empty_notebook then
614 regenerate_notebook () ;
615 notebook#set_current_page
616 ~may_skip_switch_page_event:false metano
620 notebook#set_current_page
621 ~may_skip_switch_page_event:true metano ;
622 notebook#proofw#load_sequent metasenv currentsequent
627 match !ProofEngine.goal with
632 match !ProofEngine.proof with
634 | Some (_,metasenv,_,_) -> metasenv
637 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
638 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
639 raise (InvokeTactics.RefreshSequentException e)
640 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unknown."); raise (InvokeTactics.RefreshSequentException e)
642 module InvokeTacticsCallbacks =
644 let sequent_viewer () = (rendering_window ())#notebook#proofw
645 let term_editor () = (rendering_window ())#inputt
646 let scratch_window () = (rendering_window ())#scratch_window
648 let refresh_proof () =
649 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
652 let refresh_goals () =
653 let notebook = (rendering_window ())#notebook in
654 refresh_goals notebook
656 let decompose_uris_choice_callback = decompose_uris_choice_callback
657 let mk_fresh_name_callback = mk_fresh_name_callback
658 let output_html msg = output_html (outputhtml ()) msg
661 module InvokeTactics' = InvokeTactics.Make (InvokeTacticsCallbacks);;
662 (* Just to initialize the Hbugs module *)
663 module Ignore = Hbugs.Initialize (InvokeTactics');;
665 (** load an unfinished proof from filesystem *)
666 let load_unfinished_proof () =
667 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
668 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
669 let notebook = (rendering_window ())#notebook in
672 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
675 None -> raise NoChoice
677 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
678 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
679 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
680 typecheck_loaded_proof metasenv bo ty ;
682 Some (uri, metasenv, bo, ty) ;
686 | (metano,_,_)::_ -> Some metano
688 refresh_proof output ;
689 refresh_goals notebook ;
690 output_html outputhtml
691 ("<h1 color=\"Green\">Current proof type loaded from " ^
692 prooffiletype ^ "</h1>") ;
693 output_html outputhtml
694 ("<h1 color=\"Green\">Current proof body loaded from " ^
695 prooffile ^ "</h1>") ;
696 !save_set_sensitive true;
699 InvokeTactics.RefreshSequentException e ->
700 output_html outputhtml
701 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
702 "sequent: " ^ Printexc.to_string e ^ "</h1>")
703 | InvokeTactics.RefreshProofException e ->
704 output_html outputhtml
705 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
706 "proof: " ^ Printexc.to_string e ^ "</h1>")
708 output_html outputhtml
709 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
712 let edit_aliases () =
713 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
714 let id_to_uris = inputt#id_to_uris in
715 let chosen = ref false in
718 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
720 GPack.vbox ~border_width:0 ~packing:window#add () in
721 let scrolled_window =
722 GBin.scrolled_window ~border_width:10
723 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
724 let input = GEdit.text ~editable:true ~width:400 ~height:100
725 ~packing:scrolled_window#add () in
727 GPack.hbox ~border_width:0
728 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
730 GButton.button ~label:"Ok"
731 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
733 GButton.button ~label:"Cancel"
734 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
735 ignore (window#connect#destroy GMain.Main.quit) ;
736 ignore (cancelb#connect#clicked window#destroy) ;
738 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
739 let dom,resolve_id = !id_to_uris in
741 (input#insert_text ~pos:0
746 match resolve_id v with
748 | Some (CicTextualParser0.Uri uri) -> uri
749 | Some (CicTextualParser0.Term _)
750 | Some CicTextualParser0.Implicit -> assert false
754 CicTextualParser0.Id id -> id
755 | CicTextualParser0.Symbol (descr,_) ->
756 (* CSC: To be implemented *)
758 )^ " " ^ (string_of_cic_textual_parser_uri uri)
764 let inputtext = input#get_chars 0 input#length in
766 let alfa = "[a-zA-Z_-]" in
767 let digit = "[0-9]" in
768 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
769 let blanks = "\( \|\t\|\n\)+" in
770 let nonblanks = "[^ \t\n]+" in
771 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
773 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
777 let n' = Str.search_forward regexpr inputtext n in
778 let id = CicTextualParser0.Id (Str.matched_group 2 inputtext) in
780 MQueryMisc.cic_textual_parser_uri_of_string
781 ("cic:" ^ (Str.matched_group 5 inputtext))
783 let dom,resolve_id = aux (n' + 1) in
784 if List.mem id dom then
790 Some (CicTextualParser0.Uri uri)
793 Not_found -> TermEditor.empty_id_to_uris
797 id_to_uris := (dom,resolve_id)
801 let module L = LogicalOperations in
802 let module G = Gdome in
803 let notebook = (rendering_window ())#notebook in
804 let output = (rendering_window ())#output in
805 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
807 output#make_sequent_of_selected_term ;
808 refresh_proof output ;
809 refresh_goals notebook
811 InvokeTactics.RefreshSequentException e ->
812 output_html outputhtml
813 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
814 "sequent: " ^ Printexc.to_string e ^ "</h1>")
815 | InvokeTactics.RefreshProofException e ->
816 output_html outputhtml
817 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
818 "proof: " ^ Printexc.to_string e ^ "</h1>")
820 output_html outputhtml
821 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
825 let module L = LogicalOperations in
826 let module G = Gdome in
827 let notebook = (rendering_window ())#notebook in
828 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
829 let output = (rendering_window ())#output in
831 output#focus_sequent_of_selected_term ;
832 refresh_goals notebook
834 InvokeTactics.RefreshSequentException e ->
835 output_html outputhtml
836 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
837 "sequent: " ^ Printexc.to_string e ^ "</h1>")
838 | InvokeTactics.RefreshProofException e ->
839 output_html outputhtml
840 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
841 "proof: " ^ Printexc.to_string e ^ "</h1>")
843 output_html outputhtml
844 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
847 exception NoPrevGoal;;
848 exception NoNextGoal;;
851 let module L = LogicalOperations in
852 let module G = Gdome in
853 let notebook = (rendering_window ())#notebook in
854 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
856 match !ProofEngine.proof with
858 | Some (_,metasenv,_,_) -> metasenv
861 refresh_goals ~empty_notebook:false notebook
863 InvokeTactics.RefreshSequentException e ->
864 output_html outputhtml
865 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
866 "sequent: " ^ Printexc.to_string e ^ "</h1>")
868 output_html outputhtml
869 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
873 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
876 GWindow.window ~width:800 ~border_width:2 () in
877 let scrolled_window =
878 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
880 GMathViewAux.single_selection_math_view
881 ~packing:scrolled_window#add ~width:600 ~height:400 ()
883 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
884 let href = Gdome.domString "href" in
885 let show_in_show_window_obj uri obj =
886 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
889 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
890 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
892 Cic2acic.acic_object_of_cic_object obj
895 ApplyStylesheets.mml_of_cic_object
896 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
898 window#set_title (UriManager.string_of_uri uri) ;
899 window#misc#hide () ; window#show () ;
900 mmlwidget#load_doc mml ;
903 output_html outputhtml
904 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
906 let show_in_show_window_uri uri =
907 let obj = CicEnvironment.get_obj uri in
908 show_in_show_window_obj uri obj
910 let show_in_show_window_callback mmlwidget (n : Gdome.element option) _ =
914 if n'#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
916 (n'#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
918 show_in_show_window_uri (UriManager.uri_of_string uri)
920 ignore (mmlwidget#action_toggle n')
923 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
925 show_in_show_window_obj, show_in_show_window_uri,
926 show_in_show_window_callback
929 exception NoObjectsLocated;;
931 let user_uri_choice ~title ~msg uris =
934 [] -> raise NoObjectsLocated
938 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
943 String.sub uri 4 (String.length uri - 4)
946 let locate_callback id =
947 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
948 let out = output_html outputhtml in
949 let query = MQG.locate id in
950 let result = MQI.execute mqi_handle query in
954 MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
956 out "<h1>Locate Query: </h1><pre>";
957 MQueryUtil.text_of_query out query "";
958 out "<h1>Result:</h1>";
959 MQueryUtil.text_of_result out result "<br>";
960 user_uri_choice ~title:"Ambiguous input."
962 ("Ambiguous input \"" ^ id ^
963 "\". Please, choose one interpetation:")
968 let input_or_locate_uri ~title =
969 let uri = ref None in
972 ~width:400 ~modal:true ~title ~border_width:2 () in
973 let vbox = GPack.vbox ~packing:window#add () in
975 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
977 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
979 GEdit.entry ~editable:true
980 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
982 GButton.button ~label:"Check"
983 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
984 let _ = checkb#misc#set_sensitive false in
986 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
988 GMisc.label ~text:"You can also enter an indentifier to locate:"
989 ~packing:(hbox2#pack ~padding:5) () in
991 GEdit.entry ~editable:true
992 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
994 GButton.button ~label:"Locate"
995 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
996 let _ = locateb#misc#set_sensitive false in
998 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1000 GButton.button ~label:"Ok"
1001 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1002 let _ = okb#misc#set_sensitive false in
1004 GButton.button ~label:"Cancel"
1005 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1007 ignore (window#connect#destroy GMain.Main.quit) ;
1009 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1010 let check_callback () =
1011 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1012 let uri = "cic:" ^ manual_input#text in
1014 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1015 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1018 Getter.Unresolved ->
1019 output_html outputhtml
1020 ("<h1 color=\"Red\">URI " ^ uri ^
1021 " does not correspond to any object.</h1>") ;
1023 | UriManager.IllFormedUri _ ->
1024 output_html outputhtml
1025 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1028 output_html outputhtml
1029 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1033 (okb#connect#clicked
1035 if check_callback () then
1037 uri := Some manual_input#text ;
1041 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1043 (manual_input#connect#changed
1045 if manual_input#text = "" then
1047 checkb#misc#set_sensitive false ;
1048 okb#misc#set_sensitive false
1052 checkb#misc#set_sensitive true ;
1053 okb#misc#set_sensitive true
1056 (locate_input#connect#changed
1057 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1059 (locateb#connect#clicked
1061 let id = locate_input#text in
1062 manual_input#set_text (locate_callback id) ;
1063 locate_input#delete_text 0 (String.length id)
1068 None -> raise NoChoice
1069 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1072 exception AmbiguousInput;;
1074 (* A WIDGET TO ENTER CIC TERMS *)
1076 module ChosenTermEditor = TexTermEditor;;
1077 module ChosenTextualParser0 = TexCicTextualParser0;;
1079 module ChosenTermEditor = TermEditor;;
1080 module ChosenTextualParser0 = CicTextualParser0;;
1085 let get_metasenv () = !ChosenTextualParser0.metasenv
1086 let set_metasenv metasenv = ChosenTextualParser0.metasenv := metasenv
1088 let output_html msg = output_html (outputhtml ()) msg;;
1089 let interactive_user_uri_choice =
1090 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1091 interactive_user_uri_choice ~selection_mode ?ok
1092 ?enable_button_for_non_vars ~title ~msg;;
1093 let interactive_interpretation_choice = interactive_interpretation_choice;;
1094 let input_or_locate_uri = input_or_locate_uri;;
1098 module TexTermEditor' = ChosenTermEditor.Make(Callbacks);;
1100 (* OTHER FUNCTIONS *)
1103 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1104 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1107 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1109 None -> raise NoChoice
1111 let uri = locate_callback input in
1115 output_html outputhtml
1116 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1120 exception UriAlreadyInUse;;
1121 exception NotAUriToAConstant;;
1123 let new_inductive () =
1124 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1125 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1126 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1127 let notebook = (rendering_window ())#notebook in
1129 let chosen = ref false in
1130 let inductive = ref true in
1131 let paramsno = ref 0 in
1132 let get_uri = ref (function _ -> assert false) in
1133 let get_base_uri = ref (function _ -> assert false) in
1134 let get_names = ref (function _ -> assert false) in
1135 let get_types_and_cons = ref (function _ -> assert false) in
1136 let get_context_and_subst = ref (function _ -> assert false) in
1139 ~width:600 ~modal:true ~position:`CENTER
1140 ~title:"New Block of Mutual (Co)Inductive Definitions"
1141 ~border_width:2 () in
1142 let vbox = GPack.vbox ~packing:window#add () in
1144 GPack.hbox ~border_width:0
1145 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1147 GMisc.label ~text:"Enter the URI for the new block:"
1148 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1150 GEdit.entry ~editable:true
1151 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1153 GPack.hbox ~border_width:0
1154 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1158 "Enter the number of left parameters in every arity and constructor type:"
1159 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1160 let paramsno_entry =
1161 GEdit.entry ~editable:true ~text:"0"
1162 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1164 GPack.hbox ~border_width:0
1165 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1167 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1168 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1170 GButton.radio_button ~label:"Inductive"
1171 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1173 GButton.radio_button ~label:"Coinductive"
1174 ~group:inductiveb#group
1175 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1177 GPack.hbox ~border_width:0
1178 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1180 GMisc.label ~text:"Enter the list of the names of the types:"
1181 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1183 GEdit.entry ~editable:true
1184 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1186 GPack.hbox ~border_width:0
1187 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1189 GButton.button ~label:"> Next"
1190 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1191 let _ = okb#misc#set_sensitive true in
1193 GButton.button ~label:"Abort"
1194 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1195 ignore (window#connect#destroy GMain.Main.quit) ;
1196 ignore (cancelb#connect#clicked window#destroy) ;
1200 (okb#connect#clicked
1203 let uristr = "cic:" ^ uri_entry#text in
1204 let namesstr = names_entry#text in
1205 let paramsno' = int_of_string (paramsno_entry#text) in
1206 match Str.split (Str.regexp " +") namesstr with
1208 | (he::tl) as names ->
1209 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1212 ignore (Getter.resolve uri) ;
1213 raise UriAlreadyInUse
1215 Getter.Unresolved ->
1216 get_uri := (function () -> uri) ;
1217 get_names := (function () -> names) ;
1218 inductive := inductiveb#active ;
1219 paramsno := paramsno' ;
1224 output_html outputhtml
1225 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1233 GBin.frame ~label:name
1234 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1235 let vbox = GPack.vbox ~packing:frame#add () in
1236 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1238 GMisc.label ~text:("Enter its type:")
1239 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1240 let scrolled_window =
1241 GBin.scrolled_window ~border_width:5
1242 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1244 TexTermEditor'.term_editor
1246 ~width:400 ~height:20 ~packing:scrolled_window#add
1247 ~share_id_to_uris_with:inputt ()
1248 ~isnotempty_callback:
1250 (*non_empty_type := b ;*)
1251 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1254 GPack.hbox ~border_width:0
1255 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1257 GMisc.label ~text:("Enter the list of its constructors:")
1258 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1259 let cons_names_entry =
1260 GEdit.entry ~editable:true
1261 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1262 (newinputt,cons_names_entry)
1265 vbox#remove hboxn#coerce ;
1267 GPack.hbox ~border_width:0
1268 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1270 GButton.button ~label:"> Next"
1271 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1273 GButton.button ~label:"Abort"
1274 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1275 ignore (cancelb#connect#clicked window#destroy) ;
1277 (okb#connect#clicked
1280 let names = !get_names () in
1281 let types_and_cons =
1283 (fun name (newinputt,cons_names_entry) ->
1284 let consnamesstr = cons_names_entry#text in
1285 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1287 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1290 [] -> expr,cons_names
1291 | _ -> raise AmbiguousInput
1292 ) names type_widgets
1294 let uri = !get_uri () in
1296 (* Let's see if so far the definition is well-typed *)
1299 (* To test if the arities of the inductive types are well *)
1300 (* typed, we check the inductive block definition where *)
1301 (* no constructor is given to each type. *)
1304 (fun name (ty,cons) -> (name, !inductive, ty, []))
1305 names types_and_cons
1307 CicTypeChecker.typecheck_mutual_inductive_defs uri
1308 (tys,params,paramsno)
1310 get_context_and_subst :=
1314 (fun (context,subst) name (ty,_) ->
1316 (Some (Cic.Name name, Cic.Decl ty))::context,
1317 (Cic.MutInd (uri,!i,[]))::subst
1320 ) ([],[]) names types_and_cons) ;
1321 let types_and_cons' =
1323 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1324 names types_and_cons
1326 get_types_and_cons := (function () -> types_and_cons') ;
1331 output_html outputhtml
1332 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1335 and phase3 name cons =
1336 let get_cons_types = ref (function () -> assert false) in
1339 ~width:600 ~modal:true ~position:`CENTER
1340 ~title:(name ^ " Constructors")
1341 ~border_width:2 () in
1342 let vbox = GPack.vbox ~packing:window2#add () in
1343 let cons_type_widgets =
1345 (function consname ->
1347 GPack.hbox ~border_width:0
1348 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1350 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1351 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1352 let scrolled_window =
1353 GBin.scrolled_window ~border_width:5
1354 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1356 TexTermEditor'.term_editor
1358 ~width:400 ~height:20 ~packing:scrolled_window#add
1359 ~share_id_to_uris_with:inputt ()
1360 ~isnotempty_callback:
1362 (* (*non_empty_type := b ;*)
1363 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1368 GPack.hbox ~border_width:0
1369 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1371 GButton.button ~label:"> Next"
1372 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1373 let _ = okb#misc#set_sensitive true in
1375 GButton.button ~label:"Abort"
1376 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1377 ignore (window2#connect#destroy GMain.Main.quit) ;
1378 ignore (cancelb#connect#clicked window2#destroy) ;
1380 (okb#connect#clicked
1384 let context,subst= !get_context_and_subst () in
1389 inputt#get_metasenv_and_term ~context ~metasenv:[]
1393 let undebrujined_expr =
1395 (fun expr t -> CicSubstitution.subst t expr) expr subst
1397 name, undebrujined_expr
1398 | _ -> raise AmbiguousInput
1399 ) cons cons_type_widgets
1401 get_cons_types := (function () -> cons_types) ;
1405 output_html outputhtml
1406 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1410 let okb_pressed = !chosen in
1412 if (not okb_pressed) then
1415 assert false (* The control never reaches this point *)
1418 (!get_cons_types ())
1421 (* No more phases left or Abort pressed *)
1427 let uri = !get_uri () in
1430 let tys = !get_types_and_cons () in
1431 let obj = Cic.InductiveDefinition tys params !paramsno in
1434 prerr_endline (CicPp.ppobj obj) ;
1435 CicTypeChecker.typecheck_mutual_inductive_defs uri
1436 (tys,params,!paramsno) ;
1439 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1440 prerr_endline (CicPp.ppobj obj) ;
1442 (* We already know that obj is well-typed. We need to add it to the *)
1443 (* environment in order to compute the inner-types without having to *)
1444 (* debrujin it or having to modify lots of other functions to avoid *)
1445 (* asking the environment for the MUTINDs we are defining now. *)
1446 CicEnvironment.put_inductive_definition uri obj ;
1448 show_in_show_window_obj uri obj
1451 output_html outputhtml
1452 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1456 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1457 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1458 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1459 let notebook = (rendering_window ())#notebook in
1461 let chosen = ref false in
1462 let get_metasenv_and_term = ref (function _ -> assert false) in
1463 let get_uri = ref (function _ -> assert false) in
1464 let non_empty_type = ref false in
1467 ~width:600 ~modal:true ~title:"New Proof or Definition"
1468 ~border_width:2 () in
1469 let vbox = GPack.vbox ~packing:window#add () in
1471 GPack.hbox ~border_width:0
1472 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1474 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1475 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1477 GEdit.entry ~editable:true
1478 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1480 GPack.hbox ~border_width:0
1481 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1483 GMisc.label ~text:"Enter the theorem or definition type:"
1484 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1485 let scrolled_window =
1486 GBin.scrolled_window ~border_width:5
1487 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1488 (* the content of the scrolled_window is moved below (see comment) *)
1490 GPack.hbox ~border_width:0
1491 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1493 GButton.button ~label:"Ok"
1494 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1495 let _ = okb#misc#set_sensitive false in
1497 GButton.button ~label:"Cancel"
1498 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1499 (* moved here to have visibility of the ok button *)
1501 TexTermEditor'.term_editor
1503 ~width:400 ~height:100 ~packing:scrolled_window#add
1504 ~share_id_to_uris_with:inputt ()
1505 ~isnotempty_callback:
1507 non_empty_type := b ;
1508 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1511 let xxx = inputt#get_as_string in
1512 prerr_endline ("######################## " ^ xxx) ;
1513 newinputt#set_term xxx ;
1515 newinputt#set_term inputt#get_as_string ;
1519 uri_entry#connect#changed
1521 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1523 ignore (window#connect#destroy GMain.Main.quit) ;
1524 ignore (cancelb#connect#clicked window#destroy) ;
1526 (okb#connect#clicked
1530 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1531 let uristr = "cic:" ^ uri_entry#text in
1532 let uri = UriManager.uri_of_string uristr in
1533 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1534 raise NotAUriToAConstant
1538 ignore (Getter.resolve uri) ;
1539 raise UriAlreadyInUse
1541 Getter.Unresolved ->
1542 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1543 get_uri := (function () -> uri) ;
1548 output_html outputhtml
1549 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1555 let metasenv,expr = !get_metasenv_and_term () in
1556 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1557 ProofEngine.proof :=
1558 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1559 ProofEngine.goal := Some 1 ;
1560 refresh_goals notebook ;
1561 refresh_proof output ;
1562 !save_set_sensitive true ;
1564 ProofEngine.intros ~mk_fresh_name_callback () ;
1565 refresh_goals notebook ;
1566 refresh_proof output
1568 InvokeTactics.RefreshSequentException e ->
1569 output_html outputhtml
1570 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1571 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1572 | InvokeTactics.RefreshProofException e ->
1573 output_html outputhtml
1574 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1575 "proof: " ^ Printexc.to_string e ^ "</h1>")
1577 output_html outputhtml
1578 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1581 let check_term_in_scratch scratch_window metasenv context expr =
1583 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1584 let expr = Cic.Cast (expr,ty) in
1585 scratch_window#show () ;
1586 scratch_window#set_term expr ;
1587 scratch_window#set_context context ;
1588 scratch_window#set_metasenv metasenv ;
1589 scratch_window#sequent_viewer#load_sequent metasenv (111,context,expr)
1592 print_endline ("? " ^ CicPp.ppterm expr) ;
1596 let check scratch_window () =
1597 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1598 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1600 match !ProofEngine.proof with
1602 | Some (_,metasenv,_,_) -> metasenv
1605 match !ProofEngine.goal with
1608 let (_,canonical_context,_) =
1609 List.find (function (m,_,_) -> m=metano) metasenv
1614 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1615 check_term_in_scratch scratch_window metasenv' context expr
1618 output_html outputhtml
1619 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1623 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1625 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1628 output_html outputhtml
1629 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1632 exception NotADefinition;;
1635 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1636 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1637 let notebook = (rendering_window ())#notebook in
1639 let uri = input_or_locate_uri ~title:"Open" in
1640 CicTypeChecker.typecheck uri ;
1641 let metasenv,bo,ty =
1642 match CicEnvironment.get_cooked_obj uri with
1643 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1644 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1647 | Cic.InductiveDefinition _ -> raise NotADefinition
1649 ProofEngine.proof :=
1650 Some (uri, metasenv, bo, ty) ;
1651 ProofEngine.goal := None ;
1652 refresh_goals notebook ;
1653 refresh_proof output
1655 InvokeTactics.RefreshSequentException e ->
1656 output_html outputhtml
1657 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1658 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1659 | InvokeTactics.RefreshProofException e ->
1660 output_html outputhtml
1661 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1662 "proof: " ^ Printexc.to_string e ^ "</h1>")
1664 output_html outputhtml
1665 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1668 let show_query_results results =
1671 ~modal:false ~title:"Query results." ~border_width:2 () in
1672 let vbox = GPack.vbox ~packing:window#add () in
1674 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1677 ~text:"Click on a URI to show that object"
1678 ~packing:hbox#add () in
1679 let scrolled_window =
1680 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1681 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1682 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1685 (function (uri,_) ->
1689 clist#set_row ~selectable:false n
1692 clist#columns_autosize () ;
1694 (clist#connect#select_row
1695 (fun ~row ~column ~event ->
1696 let (uristr,_) = List.nth results row in
1698 MQueryMisc.cic_textual_parser_uri_of_string
1699 (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
1702 CicTextualParser0.ConUri uri
1703 | CicTextualParser0.VarUri uri
1704 | CicTextualParser0.IndTyUri (uri,_)
1705 | CicTextualParser0.IndConUri (uri,_,_) ->
1706 show_in_show_window_uri uri
1712 let refine_constraints (must_obj,must_rel,must_sort) =
1713 let chosen = ref false in
1714 let use_only = ref false in
1717 ~modal:true ~title:"Constraints refinement."
1718 ~width:800 ~border_width:2 () in
1719 let vbox = GPack.vbox ~packing:window#add () in
1721 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1724 ~text: "\"Only\" constraints can be enforced or not."
1725 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1727 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1728 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1731 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1732 (* Notebook for the constraints choice *)
1734 GPack.notebook ~scrollable:true
1735 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1736 (* Rel constraints *)
1739 ~text: "Constraints on Rels" () in
1741 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1744 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1747 ~text: "You can now specify the constraints on Rels."
1748 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1749 let expected_height = 25 * (List.length must_rel + 2) in
1750 let height = if expected_height > 400 then 400 else expected_height in
1751 let scrolled_window =
1752 GBin.scrolled_window ~border_width:10 ~height ~width:600
1753 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1754 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1755 let rel_constraints =
1757 (function (position,depth) ->
1760 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1764 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1766 None -> position, ref None
1768 let mutable_ref = ref (Some depth') in
1770 GButton.toggle_button
1771 ~label:("depth = " ^ string_of_int depth') ~active:true
1772 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1775 (depthb#connect#toggled
1777 let sel_depth = if depthb#active then Some depth' else None in
1778 mutable_ref := sel_depth
1780 position, mutable_ref
1782 (* Sort constraints *)
1785 ~text: "Constraints on Sorts" () in
1787 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1790 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1793 ~text: "You can now specify the constraints on Sorts."
1794 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1795 let expected_height = 25 * (List.length must_sort + 2) in
1796 let height = if expected_height > 400 then 400 else expected_height in
1797 let scrolled_window =
1798 GBin.scrolled_window ~border_width:10 ~height ~width:600
1799 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1800 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1801 let sort_constraints =
1803 (function (position,depth,sort) ->
1806 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1809 ~text:(sort ^ " " ^ position)
1810 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1812 None -> position, ref None, sort
1814 let mutable_ref = ref (Some depth') in
1816 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1818 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1821 (depthb#connect#toggled
1823 let sel_depth = if depthb#active then Some depth' else None in
1824 mutable_ref := sel_depth
1826 position, mutable_ref, sort
1828 (* Obj constraints *)
1831 ~text: "Constraints on constants" () in
1833 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1836 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1839 ~text: "You can now specify the constraints on constants."
1840 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1841 let expected_height = 25 * (List.length must_obj + 2) in
1842 let height = if expected_height > 400 then 400 else expected_height in
1843 let scrolled_window =
1844 GBin.scrolled_window ~border_width:10 ~height ~width:600
1845 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1846 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1847 let obj_constraints =
1849 (function (uri,position,depth) ->
1852 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1855 ~text:(uri ^ " " ^ position)
1856 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1858 None -> uri, position, ref None
1860 let mutable_ref = ref (Some depth') in
1862 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1864 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1867 (depthb#connect#toggled
1869 let sel_depth = if depthb#active then Some depth' else None in
1870 mutable_ref := sel_depth
1872 uri, position, mutable_ref
1874 (* Confirm/abort buttons *)
1876 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1878 GButton.button ~label:"Ok"
1879 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1881 GButton.button ~label:"Abort"
1882 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1884 ignore (window#connect#destroy GMain.Main.quit) ;
1885 ignore (cancelb#connect#clicked window#destroy) ;
1887 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1888 window#set_position `CENTER ;
1892 let chosen_must_rel =
1894 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
1895 let chosen_must_sort =
1897 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
1900 let chosen_must_obj =
1902 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
1905 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1907 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1908 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1916 let completeSearchPattern () =
1917 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1918 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1920 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1921 let must = MQueryLevels2.get_constraints expr in
1922 let must',only = refine_constraints must in
1923 let query = MQG.query_of_constraints None must' only in
1924 let results = MQI.execute mqi_handle query in
1925 show_query_results results
1928 output_html outputhtml
1929 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1932 let insertQuery () =
1933 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1935 let chosen = ref None in
1938 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1939 let vbox = GPack.vbox ~packing:window#add () in
1941 GMisc.label ~text:"Insert Query. For Experts Only."
1942 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1943 let scrolled_window =
1944 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1945 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1946 let input = GEdit.text ~editable:true
1947 ~packing:scrolled_window#add () in
1949 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1951 GButton.button ~label:"Ok"
1952 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1954 GButton.button ~label:"Load from file..."
1955 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1957 GButton.button ~label:"Abort"
1958 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1959 ignore (window#connect#destroy GMain.Main.quit) ;
1960 ignore (cancelb#connect#clicked window#destroy) ;
1962 (okb#connect#clicked
1964 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
1966 (loadb#connect#clicked
1969 GToolbox.select_file ~title:"Select Query File" ()
1973 let inch = open_in filename in
1974 let rec read_file () =
1976 let line = input_line inch in
1977 line ^ "\n" ^ read_file ()
1981 let text = read_file () in
1982 input#delete_text 0 input#length ;
1983 ignore (input#insert_text text ~pos:0))) ;
1984 window#set_position `CENTER ;
1991 MQI.execute mqi_handle (MQueryUtil.query_of_text (Lexing.from_string q))
1993 show_query_results results
1996 output_html outputhtml
1997 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2000 let choose_must list_of_must only =
2001 let chosen = ref None in
2002 let user_constraints = ref [] in
2005 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2006 let vbox = GPack.vbox ~packing:window#add () in
2008 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2012 ("You can now specify the genericity of the query. " ^
2013 "The more generic the slower.")
2014 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2016 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2020 "Suggestion: start with faster queries before moving to more generic ones."
2021 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2023 GPack.notebook ~scrollable:true
2024 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2027 let last = List.length list_of_must in
2033 (if !page = 1 then "More generic" else
2034 if !page = last then "More precise" else " ") () in
2035 let expected_height = 25 * (List.length must + 2) in
2036 let height = if expected_height > 400 then 400 else expected_height in
2037 let scrolled_window =
2038 GBin.scrolled_window ~border_width:10 ~height ~width:600
2039 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2041 GList.clist ~columns:2 ~packing:scrolled_window#add
2042 ~titles:["URI" ; "Position"] ()
2046 (function (uri,position) ->
2049 [uri; if position then "MainConclusion" else "Conclusion"]
2051 clist#set_row ~selectable:false n
2054 clist#columns_autosize ()
2057 let label = GMisc.label ~text:"User provided" () in
2059 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2061 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2064 ~text:"Select the constraints that must be satisfied and press OK."
2065 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2066 let expected_height = 25 * (List.length only + 2) in
2067 let height = if expected_height > 400 then 400 else expected_height in
2068 let scrolled_window =
2069 GBin.scrolled_window ~border_width:10 ~height ~width:600
2070 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2072 GList.clist ~columns:2 ~packing:scrolled_window#add
2073 ~selection_mode:`EXTENDED
2074 ~titles:["URI" ; "Position"] ()
2078 (function (uri,position) ->
2081 [uri; if position then "MainConclusion" else "Conclusion"]
2083 clist#set_row ~selectable:true n
2086 clist#columns_autosize () ;
2088 (clist#connect#select_row
2089 (fun ~row ~column ~event ->
2090 user_constraints := (List.nth only row)::!user_constraints)) ;
2092 (clist#connect#unselect_row
2093 (fun ~row ~column ~event ->
2096 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2099 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2101 GButton.button ~label:"Ok"
2102 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2104 GButton.button ~label:"Abort"
2105 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2107 ignore (window#connect#destroy GMain.Main.quit) ;
2108 ignore (cancelb#connect#clicked window#destroy) ;
2110 (okb#connect#clicked
2111 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2112 window#set_position `CENTER ;
2116 None -> raise NoChoice
2118 if n = List.length list_of_must then
2119 (* user provided constraints *)
2122 List.nth list_of_must n
2125 let searchPattern () =
2126 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2127 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2130 match !ProofEngine.proof with
2131 None -> assert false
2132 | Some proof -> proof
2134 match !ProofEngine.goal with
2138 TacticChaser.searchPattern
2140 ~output_html:(output_html outputhtml) ~choose_must ()
2141 ~status:(proof, metano)
2144 user_uri_choice ~title:"Ambiguous input."
2145 ~msg: "Many lemmas can be successfully applied. Please, choose one:"
2148 inputt#set_term uri' ;
2149 InvokeTactics'.apply ()
2152 output_html outputhtml
2153 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2156 let choose_selection mmlwidget (element : Gdome.element option) =
2157 let module G = Gdome in
2158 let rec aux element =
2159 if element#hasAttributeNS
2160 ~namespaceURI:Misc.helmns
2161 ~localName:(G.domString "xref")
2163 mmlwidget#set_selection (Some element)
2166 match element#get_parentNode with
2167 None -> assert false
2168 (*CSC: OCAML DIVERGES!
2169 | Some p -> aux (new G.element_of_node p)
2171 | Some p -> aux (new Gdome.element_of_node p)
2173 GdomeInit.DOMCastException _ ->
2175 "******* trying to select above the document root ********"
2179 | None -> mmlwidget#set_selection None
2182 (* STUFF TO BUILD THE GTK INTERFACE *)
2184 (* Stuff for the widget settings *)
2186 let export_to_postscript output =
2187 let lastdir = ref (Unix.getcwd ()) in
2190 GToolbox.select_file ~title:"Export to PostScript"
2191 ~dir:lastdir ~filename:"screenshot.ps" ()
2195 (output :> GMathView.math_view)#export_to_postscript
2196 ~filename:filename ();
2199 let activate_t1 output button_set_anti_aliasing
2200 button_set_transparency export_to_postscript_menu_item
2203 let is_set = button_t1#active in
2204 output#set_font_manager_type
2205 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2208 button_set_anti_aliasing#misc#set_sensitive true ;
2209 button_set_transparency#misc#set_sensitive true ;
2210 export_to_postscript_menu_item#misc#set_sensitive true ;
2214 button_set_anti_aliasing#misc#set_sensitive false ;
2215 button_set_transparency#misc#set_sensitive false ;
2216 export_to_postscript_menu_item#misc#set_sensitive false ;
2220 let set_anti_aliasing output button_set_anti_aliasing () =
2221 output#set_anti_aliasing button_set_anti_aliasing#active
2224 let set_transparency output button_set_transparency () =
2225 output#set_transparency button_set_transparency#active
2228 let changefont output font_size_spinb () =
2229 output#set_font_size font_size_spinb#value_as_int
2232 let set_log_verbosity output log_verbosity_spinb () =
2233 output#set_log_verbosity log_verbosity_spinb#value_as_int
2236 class settings_window output sw
2237 export_to_postscript_menu_item selection_changed_callback
2239 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2241 GPack.vbox ~packing:settings_window#add () in
2244 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2245 ~border_width:5 ~packing:vbox#add () in
2247 GButton.toggle_button ~label:"activate t1 fonts"
2248 ~packing:(table#attach ~left:0 ~top:0) () in
2249 let button_set_anti_aliasing =
2250 GButton.toggle_button ~label:"set_anti_aliasing"
2251 ~packing:(table#attach ~left:0 ~top:1) () in
2252 let button_set_transparency =
2253 GButton.toggle_button ~label:"set_transparency"
2254 ~packing:(table#attach ~left:2 ~top:1) () in
2257 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2258 ~border_width:5 ~packing:vbox#add () in
2259 let font_size_label =
2260 GMisc.label ~text:"font size:"
2261 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2262 let font_size_spinb =
2264 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2267 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2268 let log_verbosity_label =
2269 GMisc.label ~text:"log verbosity:"
2270 ~packing:(table#attach ~left:0 ~top:1) () in
2271 let log_verbosity_spinb =
2273 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2276 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2278 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2280 GButton.button ~label:"Close"
2281 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2283 method show = settings_window#show
2285 button_set_anti_aliasing#misc#set_sensitive false ;
2286 button_set_transparency#misc#set_sensitive false ;
2287 (* Signals connection *)
2288 ignore(button_t1#connect#clicked
2289 (activate_t1 output button_set_anti_aliasing
2290 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2291 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2292 ignore(button_set_anti_aliasing#connect#toggled
2293 (set_anti_aliasing output button_set_anti_aliasing));
2294 ignore(button_set_transparency#connect#toggled
2295 (set_transparency output button_set_transparency)) ;
2296 ignore(log_verbosity_spinb#connect#changed
2297 (set_log_verbosity output log_verbosity_spinb)) ;
2298 ignore(closeb#connect#clicked settings_window#misc#hide)
2301 (* Scratch window *)
2303 class scratch_window =
2306 ~title:"MathML viewer"
2307 ~border_width:2 () in
2309 GPack.vbox ~packing:window#add () in
2311 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2313 GButton.button ~label:"Whd"
2314 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2316 GButton.button ~label:"Reduce"
2317 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2319 GButton.button ~label:"Simpl"
2320 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2321 let scrolled_window =
2322 GBin.scrolled_window ~border_width:10
2323 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2324 let sequent_viewer =
2325 TermViewer.sequent_viewer
2326 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2328 val mutable term = Cic.Rel 1 (* dummy value *)
2329 val mutable context = ([] : Cic.context) (* dummy value *)
2330 val mutable metasenv = ([] : Cic.metasenv) (* dummy value *)
2331 method sequent_viewer = sequent_viewer
2332 method show () = window#misc#hide () ; window#show ()
2334 method set_term t = term <- t
2335 method context = context
2336 method set_context t = context <- t
2337 method metasenv = metasenv
2338 method set_metasenv t = metasenv <- t
2341 (sequent_viewer#connect#selection_changed (choose_selection sequent_viewer));
2342 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2343 ignore(whdb#connect#clicked InvokeTactics'.whd_in_scratch) ;
2344 ignore(reduceb#connect#clicked InvokeTactics'.reduce_in_scratch) ;
2345 ignore(simplb#connect#clicked InvokeTactics'.simpl_in_scratch)
2348 let open_contextual_menu_for_selected_terms mmlwidget infos =
2349 let button = GdkEvent.Button.button infos in
2350 let terms_selected = List.length mmlwidget#get_selections > 0 in
2353 let time = GdkEvent.Button.time infos in
2354 let menu = GMenu.menu () in
2355 let f = new GMenu.factory menu in
2357 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2358 let reduce_menu_item =
2359 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2360 let simpl_menu_item =
2361 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2362 let _ = f#add_separator () in
2363 let generalize_menu_item =
2364 f#add_item "Generalize"
2365 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2366 let _ = f#add_separator () in
2367 let clear_menu_item =
2368 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2369 let clearbody_menu_item =
2370 f#add_item "ClearBody"
2371 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2373 whd_menu_item#misc#set_sensitive terms_selected ;
2374 reduce_menu_item#misc#set_sensitive terms_selected ;
2375 simpl_menu_item#misc#set_sensitive terms_selected ;
2376 generalize_menu_item#misc#set_sensitive terms_selected ;
2377 clear_menu_item#misc#set_sensitive terms_selected ;
2378 clearbody_menu_item#misc#set_sensitive terms_selected ;
2379 menu#popup ~button ~time
2385 let vbox1 = GPack.vbox () in
2387 val mutable proofw_ref = None
2388 val mutable compute_ref = None
2390 Lazy.force self#compute ;
2391 match proofw_ref with
2392 None -> assert false
2393 | Some proofw -> proofw
2394 method content = vbox1
2396 match compute_ref with
2397 None -> assert false
2398 | Some compute -> compute
2402 let scrolled_window1 =
2403 GBin.scrolled_window ~border_width:10
2404 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2406 TermViewer.sequent_viewer ~width:400 ~height:275
2407 ~packing:(scrolled_window1#add) () in
2408 let _ = proofw_ref <- Some proofw in
2410 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2412 GButton.button ~label:"Ring"
2413 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2415 GButton.button ~label:"Fourier"
2416 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2418 GButton.button ~label:"Reflexivity"
2419 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2421 GButton.button ~label:"Symmetry"
2422 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2424 GButton.button ~label:"Assumption"
2425 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2426 let contradictionb =
2427 GButton.button ~label:"Contradiction"
2428 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2430 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2432 GButton.button ~label:"Exists"
2433 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2435 GButton.button ~label:"Split"
2436 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2438 GButton.button ~label:"Left"
2439 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2441 GButton.button ~label:"Right"
2442 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2443 let searchpatternb =
2444 GButton.button ~label:"SearchPattern_Apply"
2445 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2447 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2449 GButton.button ~label:"Exact"
2450 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2452 GButton.button ~label:"Intros"
2453 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2455 GButton.button ~label:"Apply"
2456 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2457 let elimintrossimplb =
2458 GButton.button ~label:"ElimIntrosSimpl"
2459 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2461 GButton.button ~label:"ElimType"
2462 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2464 GButton.button ~label:"Fold_whd"
2465 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2467 GButton.button ~label:"Fold_reduce"
2468 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2470 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2472 GButton.button ~label:"Fold_simpl"
2473 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2475 GButton.button ~label:"Cut"
2476 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2478 GButton.button ~label:"Change"
2479 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2481 GButton.button ~label:"Let ... In"
2482 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2484 GButton.button ~label:"RewriteSimpl ->"
2485 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2486 let rewritebacksimplb =
2487 GButton.button ~label:"RewriteSimpl <-"
2488 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2490 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2492 GButton.button ~label:"Absurd"
2493 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2495 GButton.button ~label:"Decompose"
2496 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2498 GButton.button ~label:"Transitivity"
2499 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2501 GButton.button ~label:"Replace"
2502 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2504 GButton.button ~label:"Injection"
2505 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2507 GButton.button ~label:"Discriminate"
2508 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2509 (* Zack: spostare in una toolbar
2511 GButton.button ~label:"Generalize"
2512 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2514 GButton.button ~label:"ClearBody"
2515 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2517 GButton.button ~label:"Clear"
2518 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2520 GButton.button ~label:"Whd"
2521 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2523 GButton.button ~label:"Reduce"
2524 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2526 GButton.button ~label:"Simpl"
2527 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2530 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2531 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2532 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2533 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2534 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2535 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2536 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2537 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2538 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2539 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2540 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2541 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2542 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2543 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2544 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2545 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2546 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2547 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2548 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2549 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2550 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2551 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2552 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2553 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2554 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2555 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2556 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2557 ignore(searchpatternb#connect#clicked searchPattern) ;
2558 ignore(injectionb#connect#clicked InvokeTactics'.injection) ;
2559 ignore(discriminateb#connect#clicked InvokeTactics'.discriminate) ;
2560 (* Zack: spostare in una toolbar
2561 ignore(whdb#connect#clicked whd) ;
2562 ignore(reduceb#connect#clicked reduce) ;
2563 ignore(simplb#connect#clicked simpl) ;
2564 ignore(clearbodyb#connect#clicked clearbody) ;
2565 ignore(clearb#connect#clicked clear) ;
2566 ignore(generalizeb#connect#clicked generalize) ;
2568 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2570 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2571 (open_contextual_menu_for_selected_terms proofw)) ;
2577 let vbox1 = GPack.vbox () in
2578 let scrolled_window1 =
2579 GBin.scrolled_window ~border_width:10
2580 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2582 TermViewer.sequent_viewer ~width:400 ~height:275
2583 ~packing:(scrolled_window1#add) () in
2585 method proofw = (assert false : TermViewer.sequent_viewer)
2586 method content = vbox1
2587 method compute = (assert false : unit)
2591 let empty_page = new empty_page;;
2595 val notebook = GPack.notebook ()
2597 val mutable skip_switch_page_event = false
2598 val mutable empty = true
2599 method notebook = notebook
2601 let new_page = new page () in
2603 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2604 notebook#append_page
2605 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2606 new_page#content#coerce
2607 method remove_all_pages ~skip_switch_page_event:skip =
2609 notebook#remove_page 0 (* let's remove the empty page *)
2611 List.iter (function _ -> notebook#remove_page 0) !pages ;
2613 skip_switch_page_event <- skip
2614 method set_current_page ~may_skip_switch_page_event n =
2615 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2616 let new_page = notebook#page_num page#content#coerce in
2617 if may_skip_switch_page_event && new_page <> notebook#current_page then
2618 skip_switch_page_event <- true ;
2619 notebook#goto_page new_page
2620 method set_empty_page =
2623 notebook#append_page
2624 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2625 empty_page#content#coerce
2627 let (_,_,page) = List.nth !pages notebook#current_page in
2631 (notebook#connect#switch_page
2633 let skip = skip_switch_page_event in
2634 skip_switch_page_event <- false ;
2637 let (metano,setgoal,page) = List.nth !pages i in
2638 ProofEngine.goal := Some metano ;
2639 Lazy.force (page#compute) ;
2648 class rendering_window output (notebook : notebook) =
2649 let scratch_window = new scratch_window in
2652 ~title:"gTopLevel - Helm's Proof Assistant"
2653 ~border_width:0 ~allow_shrink:false () in
2654 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2656 let handle_box = GBin.handle_box ~border_width:2
2657 ~packing:(vbox_for_menu#pack ~padding:0) () in
2658 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2659 let factory0 = new GMenu.factory menubar in
2660 let accel_group = factory0#accel_group in
2662 let file_menu = factory0#add_submenu "File" in
2663 let factory1 = new GMenu.factory file_menu ~accel_group in
2664 let export_to_postscript_menu_item =
2667 factory1#add_item "New Block of (Co)Inductive Definitions..."
2668 ~key:GdkKeysyms._B ~callback:new_inductive
2671 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2674 let reopen_menu_item =
2675 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2679 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2680 ignore (factory1#add_separator ()) ;
2682 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2683 ~callback:load_unfinished_proof) ;
2684 let save_menu_item =
2685 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S
2686 ~callback:save_unfinished_proof
2689 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2690 ignore (!save_set_sensitive false);
2691 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2692 ignore (!qed_set_sensitive false);
2693 ignore (factory1#add_separator ()) ;
2694 let export_to_postscript_menu_item =
2695 factory1#add_item "Export to PostScript..."
2696 ~callback:(export_to_postscript output) in
2697 ignore (factory1#add_separator ()) ;
2699 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2700 export_to_postscript_menu_item
2703 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2704 let factory2 = new GMenu.factory edit_menu ~accel_group in
2705 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2706 let proveit_menu_item =
2707 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2708 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2710 let focus_menu_item =
2711 factory2#add_item "Focus" ~key:GdkKeysyms._F
2712 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2715 focus_and_proveit_set_sensitive :=
2717 proveit_menu_item#misc#set_sensitive b ;
2718 focus_menu_item#misc#set_sensitive b
2720 let _ = !focus_and_proveit_set_sensitive false in
2721 (* edit term menu *)
2722 let edit_term_menu = factory0#add_submenu "Edit Term" in
2723 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2724 let check_menu_item =
2725 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2726 ~callback:(check scratch_window) in
2727 let _ = check_menu_item#misc#set_sensitive false in
2729 let search_menu = factory0#add_submenu "Search" in
2730 let factory4 = new GMenu.factory search_menu ~accel_group in
2732 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2734 let searchPattern_menu_item =
2735 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2736 ~callback:completeSearchPattern in
2737 let _ = searchPattern_menu_item#misc#set_sensitive false in
2738 let show_menu_item =
2739 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2741 let insert_query_item =
2742 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._Y
2743 ~callback:insertQuery in
2745 let hbugs_menu = factory0#add_submenu "HBugs" in
2746 let factory6 = new GMenu.factory hbugs_menu ~accel_group in
2747 let toggle_hbugs_menu_item =
2748 factory6#add_check_item
2749 ~active:false ~key:GdkKeysyms._F5 ~callback:Hbugs.toggle "HBugs enabled"
2752 let settings_menu = factory0#add_submenu "Settings" in
2753 let factory3 = new GMenu.factory settings_menu ~accel_group in
2755 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2756 ~callback:edit_aliases in
2757 let _ = factory3#add_separator () in
2759 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2760 ~callback:(function _ -> (settings_window ())#show ()) in
2762 let _ = window#add_accel_group accel_group in
2766 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2768 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2769 let scrolled_window0 =
2770 GBin.scrolled_window ~border_width:10
2771 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2772 let _ = scrolled_window0#add output#coerce in
2774 GBin.frame ~label:"Insert Term"
2775 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2776 let scrolled_window1 =
2777 GBin.scrolled_window ~border_width:5
2778 ~packing:frame#add () in
2780 TexTermEditor'.term_editor
2782 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2783 ~isnotempty_callback:
2785 check_menu_item#misc#set_sensitive b ;
2786 searchPattern_menu_item#misc#set_sensitive b) in
2788 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2790 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2792 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2796 ~source:"<html><body bgColor=\"white\"></body></html>"
2797 ~width:400 ~height: 100
2802 method outputhtml = outputhtml
2803 method inputt = inputt
2804 method output = (output : TermViewer.proof_viewer)
2805 method scratch_window = scratch_window
2806 method notebook = notebook
2807 method show = window#show
2809 notebook#set_empty_page ;
2810 export_to_postscript_menu_item#misc#set_sensitive false ;
2811 check_term := (check_term_in_scratch scratch_window) ;
2813 (* signal handlers here *)
2814 ignore(output#connect#selection_changed
2816 choose_selection output elem ;
2817 !focus_and_proveit_set_sensitive true
2819 ignore (output#connect#click (show_in_show_window_callback output)) ;
2820 let settings_window = new settings_window output scrolled_window0
2821 export_to_postscript_menu_item (choose_selection output) in
2822 set_settings_window settings_window ;
2823 set_outputhtml outputhtml ;
2824 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2825 Logger.log_callback :=
2826 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2831 let initialize_everything () =
2832 let module U = Unix in
2833 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2834 let notebook = new notebook in
2835 let rendering_window' = new rendering_window output notebook in
2836 set_rendering_window rendering_window' ;
2837 let print_error_as_html prefix msg =
2838 output_html (outputhtml ())
2839 ("<h1 color=\"red\">" ^ prefix ^ msg ^ "</h1>")
2841 Gdome_xslt.setErrorCallback (Some (print_error_as_html "XSLT Error: "));
2842 Gdome_xslt.setDebugCallback
2843 (Some (print_error_as_html "XSLT Debug Message: "));
2844 rendering_window'#show () ;
2845 (* Hbugs.toggle true; *)
2850 ignore (GtkMain.Main.init ()) ;
2851 initialize_everything () ;
2852 MQIC.close mqi_handle;
2857 Sys.catch_break true;
2859 with Sys.Break -> () (* exit nicely, invoking at_exit functions *)