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 (******************************************************************************)
37 (* GLOBAL CONSTANTS *)
39 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
43 " <body bgColor=\"white\">"
53 Sys.getenv "GTOPLEVEL_PROOFFILE"
55 Not_found -> "/public/currentproof"
60 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
62 Not_found -> "/public/currentprooftype"
65 let postgresqlconnectionstring =
67 Sys.getenv "POSTGRESQL_CONNECTION_STRING"
69 Not_found -> "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm"
72 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
74 let htmlheader_and_content = ref htmlheader;;
76 let current_scratch_infos = ref None
78 let check_term = ref (fun _ _ _ -> assert false);;
80 exception RenderingWindowsNotInitialized;;
82 let set_rendering_window,rendering_window =
83 let rendering_window_ref = ref None in
84 (function rw -> rendering_window_ref := Some rw),
86 match !rendering_window_ref with
87 None -> raise RenderingWindowsNotInitialized
92 exception SettingsWindowsNotInitialized;;
94 let set_settings_window,settings_window =
95 let settings_window_ref = ref None in
96 (function rw -> settings_window_ref := Some rw),
98 match !settings_window_ref with
99 None -> raise SettingsWindowsNotInitialized
104 exception OutputHtmlNotInitialized;;
106 let set_outputhtml,outputhtml =
107 let outputhtml_ref = ref None in
108 (function rw -> outputhtml_ref := Some rw),
110 match !outputhtml_ref with
111 None -> raise OutputHtmlNotInitialized
112 | Some outputhtml -> outputhtml
116 exception QedSetSensitiveNotInitialized;;
117 let qed_set_sensitive =
118 ref (function _ -> raise QedSetSensitiveNotInitialized)
121 exception SaveSetSensitiveNotInitialized;;
122 let save_set_sensitive =
123 ref (function _ -> raise SaveSetSensitiveNotInitialized)
126 (* COMMAND LINE OPTIONS *)
132 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
135 Arg.parse argspec ignore ""
139 let term_of_cic_textual_parser_uri uri =
140 let module C = Cic in
141 let module CTP = CicTextualParser0 in
143 CTP.ConUri uri -> C.Const (uri,[])
144 | CTP.VarUri uri -> C.Var (uri,[])
145 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
146 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
149 let string_of_cic_textual_parser_uri uri =
150 let module C = Cic in
151 let module CTP = CicTextualParser0 in
154 CTP.ConUri uri -> UriManager.string_of_uri uri
155 | CTP.VarUri uri -> UriManager.string_of_uri uri
156 | CTP.IndTyUri (uri,tyno) ->
157 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
158 | CTP.IndConUri (uri,tyno,consno) ->
159 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
162 (* 4 = String.length "cic:" *)
163 String.sub uri' 4 (String.length uri' - 4)
166 let output_html outputhtml msg =
167 htmlheader_and_content := !htmlheader_and_content ^ msg ;
168 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
169 outputhtml#set_topline (-1)
172 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
176 let check_window outputhtml uris =
179 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
181 GPack.notebook ~scrollable:true ~packing:window#add () in
186 let scrolled_window =
187 GBin.scrolled_window ~border_width:10
189 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
194 GMathViewAux.single_selection_math_view
195 ~packing:scrolled_window#add ~width:400 ~height:280 () in
198 term_of_cic_textual_parser_uri
199 (Misc.cic_textual_parser_uri_of_string uri)
201 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
204 let mml,scratch_infos =
205 ApplyStylesheets.mml_of_cic_term 111 expr
207 current_scratch_infos := Some scratch_infos ;
208 mmlwidget#load_doc ~dom:mml
211 output_html outputhtml
212 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
217 (notebook#connect#switch_page
218 (function i -> Lazy.force (List.nth render_terms i)))
224 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
225 ?(enable_button_for_non_vars=false) ~title ~msg uris
227 let choices = ref [] in
228 let chosen = ref false in
229 let use_only_constants = ref false in
231 GWindow.dialog ~modal:true ~title ~width:600 () in
233 GMisc.label ~text:msg
234 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
235 let scrolled_window =
236 GBin.scrolled_window ~border_width:10
237 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
239 let expected_height = 18 * List.length uris in
240 let height = if expected_height > 400 then 400 else expected_height in
241 GList.clist ~columns:1 ~packing:scrolled_window#add
242 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
243 let _ = List.map (function x -> clist#append [x]) uris in
245 GPack.hbox ~border_width:0
246 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
248 GMisc.label ~text:"None of the above. Try this one:"
249 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
251 GEdit.entry ~editable:true
252 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
254 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
256 GButton.button ~label:ok
257 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
258 let _ = okb#misc#set_sensitive false in
263 if enable_button_for_non_vars then
264 hbox#pack ~expand:false ~fill:false ~padding:5 w)
265 ~label:"Try constants only" () in
267 GButton.button ~label:"Check"
268 ~packing:(hbox#pack ~padding:5) () in
269 let _ = checkb#misc#set_sensitive false in
271 GButton.button ~label:"Abort"
272 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
274 let check_callback () =
275 assert (List.length !choices > 0) ;
276 check_window (outputhtml ()) !choices
278 ignore (window#connect#destroy GMain.Main.quit) ;
279 ignore (cancelb#connect#clicked window#destroy) ;
281 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
283 (nonvarsb#connect#clicked
285 use_only_constants := true ;
289 ignore (checkb#connect#clicked check_callback) ;
291 (clist#connect#select_row
292 (fun ~row ~column ~event ->
293 checkb#misc#set_sensitive true ;
294 okb#misc#set_sensitive true ;
295 choices := (List.nth uris row)::!choices)) ;
297 (clist#connect#unselect_row
298 (fun ~row ~column ~event ->
300 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
302 (manual_input#connect#changed
304 if manual_input#text = "" then
307 checkb#misc#set_sensitive false ;
308 okb#misc#set_sensitive false ;
309 clist#misc#set_sensitive true
313 choices := [manual_input#text] ;
314 clist#unselect_all () ;
315 checkb#misc#set_sensitive true ;
316 okb#misc#set_sensitive true ;
317 clist#misc#set_sensitive false
319 window#set_position `CENTER ;
323 if !use_only_constants then
325 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
328 if List.length !choices > 0 then !choices else raise NoChoice
333 let interactive_interpretation_choice interpretations =
334 let chosen = ref None in
337 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
338 let vbox = GPack.vbox ~packing:window#add () in
342 ("Ambiguous input since there are many well-typed interpretations." ^
343 " Please, choose one of them.")
344 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
346 GPack.notebook ~scrollable:true
347 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
350 (function interpretation ->
352 let expected_height = 18 * List.length interpretation in
353 let height = if expected_height > 400 then 400 else expected_height in
354 GList.clist ~columns:2 ~packing:notebook#append_page ~height
355 ~titles:["id" ; "URI"] ()
359 (function (id,uri) ->
360 let n = clist#append [id;uri] in
361 clist#set_row ~selectable:false n
364 clist#columns_autosize ()
367 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
369 GButton.button ~label:"Ok"
370 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
372 GButton.button ~label:"Abort"
373 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
375 ignore (window#connect#destroy GMain.Main.quit) ;
376 ignore (cancelb#connect#clicked window#destroy) ;
379 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
380 window#set_position `CENTER ;
384 None -> raise NoChoice
391 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
393 let query = ref "" in
394 MQueryGenerator.set_confirm_query
395 (function q -> query := MQueryUtil.text_of_query q ; true) ;
396 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
400 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
403 let struri = UriManager.string_of_uri uri in
404 let idx = (String.rindex struri '/') + 1 in
405 String.sub struri idx (String.length struri - idx)
407 let path = pathname ^ "/" ^ name in
409 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
413 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
414 ~ask_dtd_to_the_getter:false
417 let innertypesuri = UriManager.innertypesuri_of_uri uri in
418 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
419 Getter.register innertypesuri
420 (Configuration.annotations_url ^
421 Str.replace_first (Str.regexp "^cic:") ""
422 (UriManager.string_of_uri innertypesuri) ^ ".xml"
424 (* constant type / variable / mutual inductive types definition *)
425 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
427 (Configuration.annotations_url ^
428 Str.replace_first (Str.regexp "^cic:") ""
429 (UriManager.string_of_uri uri) ^ ".xml"
436 match UriManager.bodyuri_of_uri uri with
438 | Some bodyuri -> bodyuri
440 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
441 Getter.register bodyuri
442 (Configuration.annotations_url ^
443 Str.replace_first (Str.regexp "^cic:") ""
444 (UriManager.string_of_uri bodyuri) ^ ".xml"
452 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
453 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
456 exception OpenConjecturesStillThere;;
457 exception WrongProof;;
459 let pathname_of_annuri uristring =
460 Configuration.annotations_dir ^
461 Str.replace_first (Str.regexp "^cic:") "" uristring
464 let make_dirs dirpath =
465 ignore (Unix.system ("mkdir -p " ^ dirpath))
468 let save_obj uri obj =
470 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
471 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
473 Cic2acic.acic_object_of_cic_object obj
475 (* let's save the theorem and register it to the getter *)
476 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
478 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
483 match !ProofEngine.proof with
485 | Some (uri,[],bo,ty) ->
487 CicReduction.are_convertible []
488 (CicTypeChecker.type_of_aux' [] [] bo) ty
491 (*CSC: Wrong: [] is just plainly wrong *)
492 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
493 let (acic,ids_to_inner_types,ids_to_inner_sorts) =
494 (rendering_window ())#output#load_proof uri proof
496 !qed_set_sensitive false ;
497 (* let's save the theorem and register it to the getter *)
498 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
500 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
505 | _ -> raise OpenConjecturesStillThere
509 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
510 match !ProofEngine.proof with
512 | Some (uri, metasenv, bo, ty) ->
514 (*CSC: Wrong: [] is just plainly wrong *)
515 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
517 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
518 Cic2acic.acic_object_of_cic_object currentproof
522 Cic2Xml.print_object uri ~ids_to_inner_sorts
523 ~ask_dtd_to_the_getter:true acurrentproof
525 xml,Some bodyxml -> xml,bodyxml
526 | _,None -> assert false
528 Xml.pp ~quiet:true xml (Some prooffiletype) ;
529 output_html outputhtml
530 ("<h1 color=\"Green\">Current proof type saved to " ^
531 prooffiletype ^ "</h1>") ;
532 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
533 output_html outputhtml
534 ("<h1 color=\"Green\">Current proof body saved to " ^
538 (* Used to typecheck the loaded proofs *)
539 let typecheck_loaded_proof metasenv bo ty =
540 let module T = CicTypeChecker in
543 (fun metasenv ((_,context,ty) as conj) ->
544 ignore (T.type_of_aux' metasenv context ty) ;
547 ignore (T.type_of_aux' metasenv [] ty) ;
548 ignore (T.type_of_aux' metasenv [] bo)
551 let decompose_uris_choice_callback uris =
552 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
553 let module U = UriManager in
556 match Misc.cic_textual_parser_uri_of_string uri with
557 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
559 (interactive_user_uri_choice
560 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
561 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
563 (function (uri,typeno,_) ->
564 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
569 let mk_fresh_name_callback context name ~typ =
571 match ProofEngineHelpers.mk_fresh_name context name ~typ with
572 Cic.Name fresh_name -> fresh_name
573 | Cic.Anonymous -> assert false
576 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
577 ("Enter a fresh name for the hypothesis " ^
579 (List.map (function None -> None | Some (n,_) -> Some n) context))
581 Some fresh_name' -> Cic.Name fresh_name'
582 | None -> raise NoChoice
585 let refresh_proof (output : TermViewer.proof_viewer) =
587 let uri,currentproof =
588 match !ProofEngine.proof with
590 | Some (uri,metasenv,bo,ty) ->
591 !qed_set_sensitive (List.length metasenv = 0) ;
592 (*CSC: Wrong: [] is just plainly wrong *)
594 (Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
596 ignore (output#load_proof uri currentproof)
599 match !ProofEngine.proof with
601 | Some (uri,metasenv,bo,ty) ->
602 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
603 raise (InvokeTactics.RefreshProofException e)
605 let refresh_goals ?(empty_notebook=true) notebook =
607 match !ProofEngine.goal with
609 if empty_notebook then
611 notebook#remove_all_pages ~skip_switch_page_event:false ;
612 notebook#set_empty_page
615 notebook#proofw#unload
618 match !ProofEngine.proof with
620 | Some (_,metasenv,_,_) -> metasenv
623 List.find (function (m,_,_) -> m=metano) metasenv
625 let regenerate_notebook () =
626 let skip_switch_page_event =
628 (m,_,_)::_ when m = metano -> false
631 notebook#remove_all_pages ~skip_switch_page_event ;
632 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
634 if empty_notebook then
636 regenerate_notebook () ;
637 notebook#set_current_page
638 ~may_skip_switch_page_event:false metano
642 notebook#set_current_page
643 ~may_skip_switch_page_event:true metano ;
644 notebook#proofw#load_sequent metasenv currentsequent
649 match !ProofEngine.goal with
654 match !ProofEngine.proof with
656 | Some (_,metasenv,_,_) -> metasenv
659 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
660 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
661 raise (InvokeTactics.RefreshSequentException e)
662 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unknown."); raise (InvokeTactics.RefreshSequentException e)
665 module InvokeTacticsCallbacks =
667 let sequent_viewer () = (rendering_window ())#notebook#proofw
668 let term_editor () = ((rendering_window ())#inputt : TermEditor.term_editor)
669 let get_current_scratch_infos () = !current_scratch_infos
670 let set_current_scratch_infos scratch_infos =
671 current_scratch_infos := scratch_infos
673 let refresh_proof () =
674 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
677 let refresh_goals () =
678 let notebook = (rendering_window ())#notebook in
679 refresh_goals notebook
681 let decompose_uris_choice_callback = decompose_uris_choice_callback
682 let mk_fresh_name_callback = mk_fresh_name_callback
683 let output_html msg = output_html (outputhtml ()) msg
687 module InvokeTactics' = InvokeTactics.Make(InvokeTacticsCallbacks);;
691 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
692 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
693 let notebook = (rendering_window ())#notebook in
696 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
699 None -> raise NoChoice
701 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
702 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
703 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
704 typecheck_loaded_proof metasenv bo ty ;
706 Some (uri, metasenv, bo, ty) ;
710 | (metano,_,_)::_ -> Some metano
712 refresh_proof output ;
713 refresh_goals notebook ;
714 output_html outputhtml
715 ("<h1 color=\"Green\">Current proof type loaded from " ^
716 prooffiletype ^ "</h1>") ;
717 output_html outputhtml
718 ("<h1 color=\"Green\">Current proof body loaded from " ^
719 prooffile ^ "</h1>") ;
720 !save_set_sensitive true
723 InvokeTactics.RefreshSequentException e ->
724 output_html outputhtml
725 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
726 "sequent: " ^ Printexc.to_string e ^ "</h1>")
727 | InvokeTactics.RefreshProofException e ->
728 output_html outputhtml
729 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
730 "proof: " ^ Printexc.to_string e ^ "</h1>")
732 output_html outputhtml
733 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
736 let edit_aliases () =
737 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
738 let id_to_uris = inputt#id_to_uris in
739 let chosen = ref false in
742 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
744 GPack.vbox ~border_width:0 ~packing:window#add () in
745 let scrolled_window =
746 GBin.scrolled_window ~border_width:10
747 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
748 let input = GEdit.text ~editable:true ~width:400 ~height:100
749 ~packing:scrolled_window#add () in
751 GPack.hbox ~border_width:0
752 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
754 GButton.button ~label:"Ok"
755 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
757 GButton.button ~label:"Cancel"
758 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
759 ignore (window#connect#destroy GMain.Main.quit) ;
760 ignore (cancelb#connect#clicked window#destroy) ;
762 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
763 let dom,resolve_id = !id_to_uris in
765 (input#insert_text ~pos:0
770 match resolve_id v with
775 (string_of_cic_textual_parser_uri uri)
781 let inputtext = input#get_chars 0 input#length in
783 let alfa = "[a-zA-Z_-]" in
784 let digit = "[0-9]" in
785 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
786 let blanks = "\( \|\t\|\n\)+" in
787 let nonblanks = "[^ \t\n]+" in
788 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
790 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
794 let n' = Str.search_forward regexpr inputtext n in
795 let id = Str.matched_group 2 inputtext in
797 Misc.cic_textual_parser_uri_of_string
798 ("cic:" ^ (Str.matched_group 5 inputtext))
800 let dom,resolve_id = aux (n' + 1) in
801 if List.mem id dom then
805 (function id' -> if id = id' then Some uri else resolve_id id')
807 Not_found -> TermEditor.empty_id_to_uris
811 id_to_uris := (dom,resolve_id)
815 let module L = LogicalOperations in
816 let module G = Gdome in
817 let notebook = (rendering_window ())#notebook in
818 let output = (rendering_window ())#output in
819 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
821 output#make_sequent_of_selected_term ;
822 refresh_proof output ;
823 refresh_goals notebook
825 InvokeTactics.RefreshSequentException e ->
826 output_html outputhtml
827 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
828 "sequent: " ^ Printexc.to_string e ^ "</h1>")
829 | InvokeTactics.RefreshProofException e ->
830 output_html outputhtml
831 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
832 "proof: " ^ Printexc.to_string e ^ "</h1>")
834 output_html outputhtml
835 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
839 let module L = LogicalOperations in
840 let module G = Gdome in
841 let notebook = (rendering_window ())#notebook in
842 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
843 let output = (rendering_window ())#output in
845 output#focus_sequent_of_selected_term ;
846 refresh_goals notebook
848 InvokeTactics.RefreshSequentException e ->
849 output_html outputhtml
850 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
851 "sequent: " ^ Printexc.to_string e ^ "</h1>")
852 | InvokeTactics.RefreshProofException e ->
853 output_html outputhtml
854 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
855 "proof: " ^ Printexc.to_string e ^ "</h1>")
857 output_html outputhtml
858 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
861 exception NoPrevGoal;;
862 exception NoNextGoal;;
865 let module L = LogicalOperations in
866 let module G = Gdome in
867 let notebook = (rendering_window ())#notebook in
868 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
870 match !ProofEngine.proof with
872 | Some (_,metasenv,_,_) -> metasenv
875 refresh_goals ~empty_notebook:false notebook
877 InvokeTactics.RefreshSequentException e ->
878 output_html outputhtml
879 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
880 "sequent: " ^ Printexc.to_string e ^ "</h1>")
882 output_html outputhtml
883 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
887 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
890 GWindow.window ~width:800 ~border_width:2 () in
891 let scrolled_window =
892 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
894 GMathViewAux.single_selection_math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
895 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
896 let href = Gdome.domString "href" in
897 let show_in_show_window_obj uri obj =
898 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
901 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
902 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
904 Cic2acic.acic_object_of_cic_object obj
907 ApplyStylesheets.mml_of_cic_object
908 ~explode_all:false uri acic ids_to_inner_sorts ids_to_inner_types
910 window#set_title (UriManager.string_of_uri uri) ;
911 window#misc#hide () ; window#show () ;
912 mmlwidget#load_doc mml ;
915 output_html outputhtml
916 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
918 let show_in_show_window_uri uri =
919 let obj = CicEnvironment.get_obj uri in
920 show_in_show_window_obj uri obj
922 let show_in_show_window_callback mmlwidget (n : Gdome.element) _ =
923 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
925 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
927 show_in_show_window_uri (UriManager.uri_of_string uri)
929 ignore (mmlwidget#action_toggle n)
932 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
934 show_in_show_window_obj, show_in_show_window_uri,
935 show_in_show_window_callback
938 exception NoObjectsLocated;;
940 let user_uri_choice ~title ~msg uris =
943 [] -> raise NoObjectsLocated
947 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
952 String.sub uri 4 (String.length uri - 4)
955 let locate_callback id =
956 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
957 let result = MQueryGenerator.locate id in
961 Misc.wrong_xpointer_format_from_wrong_xpointer_format' uri)
964 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
966 output_html outputhtml html ;
967 user_uri_choice ~title:"Ambiguous input."
969 ("Ambiguous input \"" ^ id ^
970 "\". Please, choose one interpetation:")
975 let input_or_locate_uri ~title =
976 let uri = ref None in
979 ~width:400 ~modal:true ~title ~border_width:2 () in
980 let vbox = GPack.vbox ~packing:window#add () in
982 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
984 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
986 GEdit.entry ~editable:true
987 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
989 GButton.button ~label:"Check"
990 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
991 let _ = checkb#misc#set_sensitive false in
993 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
995 GMisc.label ~text:"You can also enter an indentifier to locate:"
996 ~packing:(hbox2#pack ~padding:5) () in
998 GEdit.entry ~editable:true
999 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1001 GButton.button ~label:"Locate"
1002 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1003 let _ = locateb#misc#set_sensitive false in
1005 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1007 GButton.button ~label:"Ok"
1008 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1009 let _ = okb#misc#set_sensitive false in
1011 GButton.button ~label:"Cancel"
1012 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1014 ignore (window#connect#destroy GMain.Main.quit) ;
1016 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1017 let check_callback () =
1018 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1019 let uri = "cic:" ^ manual_input#text in
1021 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1022 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1025 Getter.Unresolved ->
1026 output_html outputhtml
1027 ("<h1 color=\"Red\">URI " ^ uri ^
1028 " does not correspond to any object.</h1>") ;
1030 | UriManager.IllFormedUri _ ->
1031 output_html outputhtml
1032 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1035 output_html outputhtml
1036 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1040 (okb#connect#clicked
1042 if check_callback () then
1044 uri := Some manual_input#text ;
1048 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1050 (manual_input#connect#changed
1052 if manual_input#text = "" then
1054 checkb#misc#set_sensitive false ;
1055 okb#misc#set_sensitive false
1059 checkb#misc#set_sensitive true ;
1060 okb#misc#set_sensitive true
1063 (locate_input#connect#changed
1064 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1066 (locateb#connect#clicked
1068 let id = locate_input#text in
1069 manual_input#set_text (locate_callback id) ;
1070 locate_input#delete_text 0 (String.length id)
1073 GMain.Main.main () ;
1075 None -> raise NoChoice
1076 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1079 exception AmbiguousInput;;
1081 (* A WIDGET TO ENTER CIC TERMS *)
1085 let output_html msg = output_html (outputhtml ()) msg;;
1086 let interactive_user_uri_choice =
1087 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1088 interactive_user_uri_choice ~selection_mode ?ok
1089 ?enable_button_for_non_vars ~title ~msg;;
1090 let interactive_interpretation_choice = interactive_interpretation_choice;;
1091 let input_or_locate_uri = input_or_locate_uri;;
1095 module TermEditor' = TermEditor.Make(Callbacks);;
1097 (* OTHER FUNCTIONS *)
1100 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1101 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1104 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1106 None -> raise NoChoice
1108 let uri = locate_callback input in
1112 output_html outputhtml
1113 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1117 exception UriAlreadyInUse;;
1118 exception NotAUriToAConstant;;
1120 let new_inductive () =
1121 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1122 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1123 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1124 let notebook = (rendering_window ())#notebook in
1126 let chosen = ref false in
1127 let inductive = ref true in
1128 let paramsno = ref 0 in
1129 let get_uri = ref (function _ -> assert false) in
1130 let get_base_uri = ref (function _ -> assert false) in
1131 let get_names = ref (function _ -> assert false) in
1132 let get_types_and_cons = ref (function _ -> assert false) in
1133 let get_context_and_subst = ref (function _ -> assert false) in
1136 ~width:600 ~modal:true ~position:`CENTER
1137 ~title:"New Block of Mutual (Co)Inductive Definitions"
1138 ~border_width:2 () in
1139 let vbox = GPack.vbox ~packing:window#add () in
1141 GPack.hbox ~border_width:0
1142 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1144 GMisc.label ~text:"Enter the URI for the new block:"
1145 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1147 GEdit.entry ~editable:true
1148 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1150 GPack.hbox ~border_width:0
1151 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1155 "Enter the number of left parameters in every arity and constructor type:"
1156 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1157 let paramsno_entry =
1158 GEdit.entry ~editable:true ~text:"0"
1159 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1161 GPack.hbox ~border_width:0
1162 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1164 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1165 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1167 GButton.radio_button ~label:"Inductive"
1168 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1170 GButton.radio_button ~label:"Coinductive"
1171 ~group:inductiveb#group
1172 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1174 GPack.hbox ~border_width:0
1175 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1177 GMisc.label ~text:"Enter the list of the names of the types:"
1178 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1180 GEdit.entry ~editable:true
1181 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1183 GPack.hbox ~border_width:0
1184 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1186 GButton.button ~label:"> Next"
1187 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1188 let _ = okb#misc#set_sensitive true in
1190 GButton.button ~label:"Abort"
1191 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1192 ignore (window#connect#destroy GMain.Main.quit) ;
1193 ignore (cancelb#connect#clicked window#destroy) ;
1197 (okb#connect#clicked
1200 let uristr = "cic:" ^ uri_entry#text in
1201 let namesstr = names_entry#text in
1202 let paramsno' = int_of_string (paramsno_entry#text) in
1203 match Str.split (Str.regexp " +") namesstr with
1205 | (he::tl) as names ->
1206 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1209 ignore (Getter.resolve uri) ;
1210 raise UriAlreadyInUse
1212 Getter.Unresolved ->
1213 get_uri := (function () -> uri) ;
1214 get_names := (function () -> names) ;
1215 inductive := inductiveb#active ;
1216 paramsno := paramsno' ;
1221 output_html outputhtml
1222 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1230 GBin.frame ~label:name
1231 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1232 let vbox = GPack.vbox ~packing:frame#add () in
1233 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1235 GMisc.label ~text:("Enter its type:")
1236 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1237 let scrolled_window =
1238 GBin.scrolled_window ~border_width:5
1239 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1241 TermEditor'.term_editor
1242 ~width:400 ~height:20 ~packing:scrolled_window#add
1243 ~share_id_to_uris_with:inputt ()
1244 ~isnotempty_callback:
1246 (*non_empty_type := b ;*)
1247 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1250 GPack.hbox ~border_width:0
1251 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1253 GMisc.label ~text:("Enter the list of its constructors:")
1254 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1255 let cons_names_entry =
1256 GEdit.entry ~editable:true
1257 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1258 (newinputt,cons_names_entry)
1261 vbox#remove hboxn#coerce ;
1263 GPack.hbox ~border_width:0
1264 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1266 GButton.button ~label:"> Next"
1267 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1269 GButton.button ~label:"Abort"
1270 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1271 ignore (cancelb#connect#clicked window#destroy) ;
1273 (okb#connect#clicked
1276 let names = !get_names () in
1277 let types_and_cons =
1279 (fun name (newinputt,cons_names_entry) ->
1280 let consnamesstr = cons_names_entry#text in
1281 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1283 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1286 [] -> expr,cons_names
1287 | _ -> raise AmbiguousInput
1288 ) names type_widgets
1290 let uri = !get_uri () in
1292 (* Let's see if so far the definition is well-typed *)
1295 (* To test if the arities of the inductive types are well *)
1296 (* typed, we check the inductive block definition where *)
1297 (* no constructor is given to each type. *)
1300 (fun name (ty,cons) -> (name, !inductive, ty, []))
1301 names types_and_cons
1303 CicTypeChecker.typecheck_mutual_inductive_defs uri
1304 (tys,params,paramsno)
1306 get_context_and_subst :=
1310 (fun (context,subst) name (ty,_) ->
1312 (Some (Cic.Name name, Cic.Decl ty))::context,
1313 (Cic.MutInd (uri,!i,[]))::subst
1316 ) ([],[]) names types_and_cons) ;
1317 let types_and_cons' =
1319 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1320 names types_and_cons
1322 get_types_and_cons := (function () -> types_and_cons') ;
1327 output_html outputhtml
1328 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1331 and phase3 name cons =
1332 let get_cons_types = ref (function () -> assert false) in
1335 ~width:600 ~modal:true ~position:`CENTER
1336 ~title:(name ^ " Constructors")
1337 ~border_width:2 () in
1338 let vbox = GPack.vbox ~packing:window2#add () in
1339 let cons_type_widgets =
1341 (function consname ->
1343 GPack.hbox ~border_width:0
1344 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1346 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1347 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1348 let scrolled_window =
1349 GBin.scrolled_window ~border_width:5
1350 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1352 TermEditor'.term_editor
1353 ~width:400 ~height:20 ~packing:scrolled_window#add
1354 ~share_id_to_uris_with:inputt ()
1355 ~isnotempty_callback:
1357 (* (*non_empty_type := b ;*)
1358 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1363 GPack.hbox ~border_width:0
1364 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1366 GButton.button ~label:"> Next"
1367 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1368 let _ = okb#misc#set_sensitive true in
1370 GButton.button ~label:"Abort"
1371 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1372 ignore (window2#connect#destroy GMain.Main.quit) ;
1373 ignore (cancelb#connect#clicked window2#destroy) ;
1375 (okb#connect#clicked
1379 let context,subst= !get_context_and_subst () in
1384 inputt#get_metasenv_and_term ~context ~metasenv:[]
1388 let undebrujined_expr =
1390 (fun expr t -> CicSubstitution.subst t expr) expr subst
1392 name, undebrujined_expr
1393 | _ -> raise AmbiguousInput
1394 ) cons cons_type_widgets
1396 get_cons_types := (function () -> cons_types) ;
1400 output_html outputhtml
1401 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1404 GMain.Main.main () ;
1405 let okb_pressed = !chosen in
1407 if (not okb_pressed) then
1410 assert false (* The control never reaches this point *)
1413 (!get_cons_types ())
1416 (* No more phases left or Abort pressed *)
1418 GMain.Main.main () ;
1422 let uri = !get_uri () in
1425 let tys = !get_types_and_cons () in
1426 let obj = Cic.InductiveDefinition tys params !paramsno in
1429 prerr_endline (CicPp.ppobj obj) ;
1430 CicTypeChecker.typecheck_mutual_inductive_defs uri
1431 (tys,params,!paramsno) ;
1434 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1435 prerr_endline (CicPp.ppobj obj) ;
1437 (* We already know that obj is well-typed. We need to add it to the *)
1438 (* environment in order to compute the inner-types without having to *)
1439 (* debrujin it or having to modify lots of other functions to avoid *)
1440 (* asking the environment for the MUTINDs we are defining now. *)
1441 CicEnvironment.put_inductive_definition uri obj ;
1443 show_in_show_window_obj uri obj
1446 output_html outputhtml
1447 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1451 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1452 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1453 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1454 let notebook = (rendering_window ())#notebook in
1456 let chosen = ref false in
1457 let get_metasenv_and_term = ref (function _ -> assert false) in
1458 let get_uri = ref (function _ -> assert false) in
1459 let non_empty_type = ref false in
1462 ~width:600 ~modal:true ~title:"New Proof or Definition"
1463 ~border_width:2 () in
1464 let vbox = GPack.vbox ~packing:window#add () in
1466 GPack.hbox ~border_width:0
1467 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1469 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1470 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1472 GEdit.entry ~editable:true
1473 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1475 GPack.hbox ~border_width:0
1476 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1478 GMisc.label ~text:"Enter the theorem or definition type:"
1479 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1480 let scrolled_window =
1481 GBin.scrolled_window ~border_width:5
1482 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1483 (* the content of the scrolled_window is moved below (see comment) *)
1485 GPack.hbox ~border_width:0
1486 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1488 GButton.button ~label:"Ok"
1489 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1490 let _ = okb#misc#set_sensitive false in
1492 GButton.button ~label:"Cancel"
1493 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1494 (* moved here to have visibility of the ok button *)
1496 TermEditor'.term_editor ~width:400 ~height:100 ~packing:scrolled_window#add
1497 ~share_id_to_uris_with:inputt ()
1498 ~isnotempty_callback:
1500 non_empty_type := b ;
1501 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1504 newinputt#set_term inputt#get_as_string ;
1507 uri_entry#connect#changed
1509 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1511 ignore (window#connect#destroy GMain.Main.quit) ;
1512 ignore (cancelb#connect#clicked window#destroy) ;
1514 (okb#connect#clicked
1518 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1519 let uristr = "cic:" ^ uri_entry#text in
1520 let uri = UriManager.uri_of_string uristr in
1521 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1522 raise NotAUriToAConstant
1526 ignore (Getter.resolve uri) ;
1527 raise UriAlreadyInUse
1529 Getter.Unresolved ->
1530 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1531 get_uri := (function () -> uri) ;
1536 output_html outputhtml
1537 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1540 GMain.Main.main () ;
1543 let metasenv,expr = !get_metasenv_and_term () in
1544 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1545 ProofEngine.proof :=
1546 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1547 ProofEngine.goal := Some 1 ;
1548 refresh_goals notebook ;
1549 refresh_proof output ;
1550 !save_set_sensitive true ;
1552 ProofEngine.intros ~mk_fresh_name_callback () ;
1553 refresh_goals notebook ;
1554 refresh_proof output
1556 InvokeTactics.RefreshSequentException e ->
1557 output_html outputhtml
1558 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1559 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1560 | InvokeTactics.RefreshProofException e ->
1561 output_html outputhtml
1562 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1563 "proof: " ^ Printexc.to_string e ^ "</h1>")
1565 output_html outputhtml
1566 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1569 let check_term_in_scratch scratch_window metasenv context expr =
1571 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1572 let mml,scratch_infos =
1573 ApplyStylesheets.mml_of_cic_term 111 (Cic.Cast (expr,ty))
1575 current_scratch_infos := Some scratch_infos ;
1576 scratch_window#show () ;
1577 scratch_window#mmlwidget#load_doc ~dom:mml
1580 print_endline ("? " ^ CicPp.ppterm expr) ;
1584 let check scratch_window () =
1585 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1586 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1588 match !ProofEngine.proof with
1590 | Some (_,metasenv,_,_) -> metasenv
1593 match !ProofEngine.goal with
1596 let (_,canonical_context,_) =
1597 List.find (function (m,_,_) -> m=metano) metasenv
1602 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1603 check_term_in_scratch scratch_window metasenv' context expr
1606 output_html outputhtml
1607 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1611 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1613 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
1616 output_html outputhtml
1617 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1620 exception NotADefinition;;
1623 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1624 let output = ((rendering_window ())#output : TermViewer.proof_viewer) in
1625 let notebook = (rendering_window ())#notebook in
1627 let uri = input_or_locate_uri ~title:"Open" in
1628 CicTypeChecker.typecheck uri ;
1629 let metasenv,bo,ty =
1630 match CicEnvironment.get_cooked_obj uri with
1631 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1632 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1635 | Cic.InductiveDefinition _ -> raise NotADefinition
1637 ProofEngine.proof :=
1638 Some (uri, metasenv, bo, ty) ;
1639 ProofEngine.goal := None ;
1640 refresh_goals notebook ;
1641 refresh_proof output
1643 InvokeTactics.RefreshSequentException e ->
1644 output_html outputhtml
1645 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1646 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1647 | InvokeTactics.RefreshProofException e ->
1648 output_html outputhtml
1649 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1650 "proof: " ^ Printexc.to_string e ^ "</h1>")
1652 output_html outputhtml
1653 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1656 let show_query_results results =
1659 ~modal:false ~title:"Query results." ~border_width:2 () in
1660 let vbox = GPack.vbox ~packing:window#add () in
1662 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1665 ~text:"Click on a URI to show that object"
1666 ~packing:hbox#add () in
1667 let scrolled_window =
1668 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1669 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1670 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
1673 (function (uri,_) ->
1677 clist#set_row ~selectable:false n
1680 clist#columns_autosize () ;
1682 (clist#connect#select_row
1683 (fun ~row ~column ~event ->
1684 let (uristr,_) = List.nth results row in
1686 Misc.cic_textual_parser_uri_of_string
1687 (Misc.wrong_xpointer_format_from_wrong_xpointer_format'
1690 CicTextualParser0.ConUri uri
1691 | CicTextualParser0.VarUri uri
1692 | CicTextualParser0.IndTyUri (uri,_)
1693 | CicTextualParser0.IndConUri (uri,_,_) ->
1694 show_in_show_window_uri uri
1700 let refine_constraints (must_obj,must_rel,must_sort) =
1701 let chosen = ref false in
1702 let use_only = ref false in
1705 ~modal:true ~title:"Constraints refinement."
1706 ~width:800 ~border_width:2 () in
1707 let vbox = GPack.vbox ~packing:window#add () in
1709 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1712 ~text: "\"Only\" constraints can be enforced or not."
1713 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1715 GButton.toggle_button ~label:"Enforce \"only\" constraints"
1716 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1719 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
1720 (* Notebook for the constraints choice *)
1722 GPack.notebook ~scrollable:true
1723 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1724 (* Rel constraints *)
1727 ~text: "Constraints on Rels" () in
1729 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1732 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1735 ~text: "You can now specify the constraints on Rels."
1736 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1737 let expected_height = 25 * (List.length must_rel + 2) in
1738 let height = if expected_height > 400 then 400 else expected_height in
1739 let scrolled_window =
1740 GBin.scrolled_window ~border_width:10 ~height ~width:600
1741 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1742 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1743 let rel_constraints =
1745 (function (position,depth) ->
1748 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1752 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1754 None -> position, ref None
1756 let mutable_ref = ref (Some depth') in
1758 GButton.toggle_button
1759 ~label:("depth = " ^ string_of_int depth') ~active:true
1760 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1763 (depthb#connect#toggled
1765 let sel_depth = if depthb#active then Some depth' else None in
1766 mutable_ref := sel_depth
1768 position, mutable_ref
1770 (* Sort constraints *)
1773 ~text: "Constraints on Sorts" () in
1775 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1778 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1781 ~text: "You can now specify the constraints on Sorts."
1782 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1783 let expected_height = 25 * (List.length must_sort + 2) in
1784 let height = if expected_height > 400 then 400 else expected_height in
1785 let scrolled_window =
1786 GBin.scrolled_window ~border_width:10 ~height ~width:600
1787 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1788 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1789 let sort_constraints =
1791 (function (position,depth,sort) ->
1794 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1797 ~text:(sort ^ " " ^ position)
1798 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1800 None -> position, ref None, sort
1802 let mutable_ref = ref (Some depth') in
1804 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1806 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1809 (depthb#connect#toggled
1811 let sel_depth = if depthb#active then Some depth' else None in
1812 mutable_ref := sel_depth
1814 position, mutable_ref, sort
1816 (* Obj constraints *)
1819 ~text: "Constraints on constants" () in
1821 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
1824 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
1827 ~text: "You can now specify the constraints on constants."
1828 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1829 let expected_height = 25 * (List.length must_obj + 2) in
1830 let height = if expected_height > 400 then 400 else expected_height in
1831 let scrolled_window =
1832 GBin.scrolled_window ~border_width:10 ~height ~width:600
1833 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
1834 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
1835 let obj_constraints =
1837 (function (uri,position,depth) ->
1840 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
1843 ~text:(uri ^ " " ^ position)
1844 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1846 None -> uri, position, ref None
1848 let mutable_ref = ref (Some depth') in
1850 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
1852 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1855 (depthb#connect#toggled
1857 let sel_depth = if depthb#active then Some depth' else None in
1858 mutable_ref := sel_depth
1860 uri, position, mutable_ref
1862 (* Confirm/abort buttons *)
1864 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1866 GButton.button ~label:"Ok"
1867 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1869 GButton.button ~label:"Abort"
1870 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
1872 ignore (window#connect#destroy GMain.Main.quit) ;
1873 ignore (cancelb#connect#clicked window#destroy) ;
1875 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
1876 window#set_position `CENTER ;
1878 GMain.Main.main () ;
1880 let chosen_must_rel =
1882 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
1883 let chosen_must_sort =
1885 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
1888 let chosen_must_obj =
1890 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
1893 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
1895 (*CSC: ???????????????????????? I assume that must and only are the same... *)
1896 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
1904 let completeSearchPattern () =
1905 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
1906 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1908 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
1909 let must = MQueryLevels2.get_constraints expr in
1910 let must',only = refine_constraints must in
1911 let results = MQueryGenerator.searchPattern must' only in
1912 show_query_results results
1915 output_html outputhtml
1916 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1919 let insertQuery () =
1920 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1922 let chosen = ref None in
1925 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
1926 let vbox = GPack.vbox ~packing:window#add () in
1928 GMisc.label ~text:"Insert Query. For Experts Only."
1929 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1930 let scrolled_window =
1931 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
1932 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1933 let input = GEdit.text ~editable:true
1934 ~packing:scrolled_window#add () in
1936 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1938 GButton.button ~label:"Ok"
1939 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1941 GButton.button ~label:"Load from file..."
1942 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1944 GButton.button ~label:"Abort"
1945 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1946 ignore (window#connect#destroy GMain.Main.quit) ;
1947 ignore (cancelb#connect#clicked window#destroy) ;
1949 (okb#connect#clicked
1951 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
1953 (loadb#connect#clicked
1956 GToolbox.select_file ~title:"Select Query File" ()
1960 let inch = open_in filename in
1961 let rec read_file () =
1963 let line = input_line inch in
1964 line ^ "\n" ^ read_file ()
1968 let text = read_file () in
1969 input#delete_text 0 input#length ;
1970 ignore (input#insert_text text ~pos:0))) ;
1971 window#set_position `CENTER ;
1973 GMain.Main.main () ;
1978 Mqint.execute (MQueryUtil.query_of_text (Lexing.from_string q))
1980 show_query_results results
1983 output_html outputhtml
1984 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1987 let choose_must list_of_must only =
1988 let chosen = ref None in
1989 let user_constraints = ref [] in
1992 ~modal:true ~title:"Query refinement." ~border_width:2 () in
1993 let vbox = GPack.vbox ~packing:window#add () in
1995 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1999 ("You can now specify the genericity of the query. " ^
2000 "The more generic the slower.")
2001 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2003 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2007 "Suggestion: start with faster queries before moving to more generic ones."
2008 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2010 GPack.notebook ~scrollable:true
2011 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2014 let last = List.length list_of_must in
2020 (if !page = 1 then "More generic" else
2021 if !page = last then "More precise" else " ") () in
2022 let expected_height = 25 * (List.length must + 2) in
2023 let height = if expected_height > 400 then 400 else expected_height in
2024 let scrolled_window =
2025 GBin.scrolled_window ~border_width:10 ~height ~width:600
2026 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2028 GList.clist ~columns:2 ~packing:scrolled_window#add
2029 ~titles:["URI" ; "Position"] ()
2033 (function (uri,position) ->
2036 [uri; if position then "MainConclusion" else "Conclusion"]
2038 clist#set_row ~selectable:false n
2041 clist#columns_autosize ()
2044 let label = GMisc.label ~text:"User provided" () in
2046 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2048 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2051 ~text:"Select the constraints that must be satisfied and press OK."
2052 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2053 let expected_height = 25 * (List.length only + 2) in
2054 let height = if expected_height > 400 then 400 else expected_height in
2055 let scrolled_window =
2056 GBin.scrolled_window ~border_width:10 ~height ~width:600
2057 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2059 GList.clist ~columns:2 ~packing:scrolled_window#add
2060 ~selection_mode:`EXTENDED
2061 ~titles:["URI" ; "Position"] ()
2065 (function (uri,position) ->
2068 [uri; if position then "MainConclusion" else "Conclusion"]
2070 clist#set_row ~selectable:true n
2073 clist#columns_autosize () ;
2075 (clist#connect#select_row
2076 (fun ~row ~column ~event ->
2077 user_constraints := (List.nth only row)::!user_constraints)) ;
2079 (clist#connect#unselect_row
2080 (fun ~row ~column ~event ->
2083 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2086 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2088 GButton.button ~label:"Ok"
2089 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2091 GButton.button ~label:"Abort"
2092 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2094 ignore (window#connect#destroy GMain.Main.quit) ;
2095 ignore (cancelb#connect#clicked window#destroy) ;
2097 (okb#connect#clicked
2098 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2099 window#set_position `CENTER ;
2101 GMain.Main.main () ;
2103 None -> raise NoChoice
2105 if n = List.length list_of_must then
2106 (* user provided constraints *)
2109 List.nth list_of_must n
2112 let searchPattern () =
2113 let inputt = ((rendering_window ())#inputt : TermEditor.term_editor) in
2114 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2117 match !ProofEngine.proof with
2118 None -> assert false
2119 | Some (_,metasenv,_,_) -> metasenv
2121 match !ProofEngine.goal with
2124 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2125 let list_of_must,only = MQueryLevels.out_restr metasenv ey ty in
2126 let must = choose_must list_of_must only in
2127 let torigth_restriction (u,b) =
2130 "http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion"
2132 "http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion"
2136 let rigth_must = List.map torigth_restriction must in
2137 let rigth_only = Some (List.map torigth_restriction only) in
2139 MQueryGenerator.searchPattern
2140 (rigth_must,[],[]) (rigth_only,None,None) in
2144 Misc.wrong_xpointer_format_from_wrong_xpointer_format' uri
2147 " <h1>Backward Query: </h1>" ^
2148 " <pre>" ^ get_last_query result ^ "</pre>"
2150 output_html outputhtml html ;
2152 let rec filter_out =
2156 let tl',exc = filter_out tl in
2159 ProofEngine.can_apply
2160 (term_of_cic_textual_parser_uri
2161 (Misc.cic_textual_parser_uri_of_string uri))
2169 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2170 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2177 " <h1>Objects that can actually be applied: </h1> " ^
2178 String.concat "<br>" uris' ^ exc ^
2179 " <h1>Number of false matches: " ^
2180 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2181 " <h1>Number of good matches: " ^
2182 string_of_int (List.length uris') ^ "</h1>"
2184 output_html outputhtml html' ;
2186 user_uri_choice ~title:"Ambiguous input."
2188 "Many lemmas can be successfully applied. Please, choose one:"
2191 inputt#set_term uri' ;
2192 InvokeTactics'.apply ()
2195 output_html outputhtml
2196 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2199 let choose_selection mmlwidget (element : Gdome.element option) =
2200 let module G = Gdome in
2201 let rec aux element =
2202 if element#hasAttributeNS
2203 ~namespaceURI:Misc.helmns
2204 ~localName:(G.domString "xref")
2206 mmlwidget#set_selection (Some element)
2209 match element#get_parentNode with
2210 None -> assert false
2211 (*CSC: OCAML DIVERGES!
2212 | Some p -> aux (new G.element_of_node p)
2214 | Some p -> aux (new Gdome.element_of_node p)
2216 GdomeInit.DOMCastException _ ->
2218 "******* trying to select above the document root ********"
2222 | None -> mmlwidget#set_selection None
2225 (* STUFF TO BUILD THE GTK INTERFACE *)
2227 (* Stuff for the widget settings *)
2229 let export_to_postscript output =
2230 let lastdir = ref (Unix.getcwd ()) in
2233 GToolbox.select_file ~title:"Export to PostScript"
2234 ~dir:lastdir ~filename:"screenshot.ps" ()
2238 (output :> GMathView.math_view)#export_to_postscript
2239 ~filename:filename ();
2242 let activate_t1 output button_set_anti_aliasing
2243 button_set_transparency export_to_postscript_menu_item
2246 let is_set = button_t1#active in
2247 output#set_font_manager_type
2248 ~fm_type:(if is_set then `font_manager_t1 else `font_manager_gtk) ;
2251 button_set_anti_aliasing#misc#set_sensitive true ;
2252 button_set_transparency#misc#set_sensitive true ;
2253 export_to_postscript_menu_item#misc#set_sensitive true ;
2257 button_set_anti_aliasing#misc#set_sensitive false ;
2258 button_set_transparency#misc#set_sensitive false ;
2259 export_to_postscript_menu_item#misc#set_sensitive false ;
2263 let set_anti_aliasing output button_set_anti_aliasing () =
2264 output#set_anti_aliasing button_set_anti_aliasing#active
2267 let set_transparency output button_set_transparency () =
2268 output#set_transparency button_set_transparency#active
2271 let changefont output font_size_spinb () =
2272 output#set_font_size font_size_spinb#value_as_int
2275 let set_log_verbosity output log_verbosity_spinb () =
2276 output#set_log_verbosity log_verbosity_spinb#value_as_int
2279 class settings_window output sw
2280 export_to_postscript_menu_item selection_changed_callback
2282 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2284 GPack.vbox ~packing:settings_window#add () in
2287 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2288 ~border_width:5 ~packing:vbox#add () in
2290 GButton.toggle_button ~label:"activate t1 fonts"
2291 ~packing:(table#attach ~left:0 ~top:0) () in
2292 let button_set_anti_aliasing =
2293 GButton.toggle_button ~label:"set_anti_aliasing"
2294 ~packing:(table#attach ~left:0 ~top:1) () in
2295 let button_set_transparency =
2296 GButton.toggle_button ~label:"set_transparency"
2297 ~packing:(table#attach ~left:2 ~top:1) () in
2300 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2301 ~border_width:5 ~packing:vbox#add () in
2302 let font_size_label =
2303 GMisc.label ~text:"font size:"
2304 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2305 let font_size_spinb =
2307 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2310 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2311 let log_verbosity_label =
2312 GMisc.label ~text:"log verbosity:"
2313 ~packing:(table#attach ~left:0 ~top:1) () in
2314 let log_verbosity_spinb =
2316 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2319 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2321 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2323 GButton.button ~label:"Close"
2324 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2326 method show = settings_window#show
2328 button_set_anti_aliasing#misc#set_sensitive false ;
2329 button_set_transparency#misc#set_sensitive false ;
2330 (* Signals connection *)
2331 ignore(button_t1#connect#clicked
2332 (activate_t1 output button_set_anti_aliasing
2333 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2334 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2335 ignore(button_set_anti_aliasing#connect#toggled
2336 (set_anti_aliasing output button_set_anti_aliasing));
2337 ignore(button_set_transparency#connect#toggled
2338 (set_transparency output button_set_transparency)) ;
2339 ignore(log_verbosity_spinb#connect#changed
2340 (set_log_verbosity output log_verbosity_spinb)) ;
2341 ignore(closeb#connect#clicked settings_window#misc#hide)
2344 (* Scratch window *)
2346 class scratch_window =
2348 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2350 GPack.vbox ~packing:window#add () in
2352 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2354 GButton.button ~label:"Whd"
2355 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2357 GButton.button ~label:"Reduce"
2358 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2360 GButton.button ~label:"Simpl"
2361 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2362 let scrolled_window =
2363 GBin.scrolled_window ~border_width:10
2364 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2366 GMathViewAux.multi_selection_math_view
2367 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2369 method mmlwidget = mmlwidget
2370 method show () = window#misc#hide () ; window#show ()
2372 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2373 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2374 ignore(whdb#connect#clicked (InvokeTactics'.whd_in_scratch self)) ;
2375 ignore(reduceb#connect#clicked (InvokeTactics'.reduce_in_scratch self)) ;
2376 ignore(simplb#connect#clicked (InvokeTactics'.simpl_in_scratch self))
2379 let open_contextual_menu_for_selected_terms mmlwidget infos =
2380 let button = GdkEvent.Button.button infos in
2381 let terms_selected = List.length mmlwidget#get_selections > 0 in
2384 let time = GdkEvent.Button.time infos in
2385 let menu = GMenu.menu () in
2386 let f = new GMenu.factory menu in
2388 f#add_item "Whd" ~key:GdkKeysyms._W ~callback:InvokeTactics'.whd in
2389 let reduce_menu_item =
2390 f#add_item "Reduce" ~key:GdkKeysyms._R ~callback:InvokeTactics'.reduce in
2391 let simpl_menu_item =
2392 f#add_item "Simpl" ~key:GdkKeysyms._S ~callback:InvokeTactics'.simpl in
2393 let _ = f#add_separator () in
2394 let generalize_menu_item =
2395 f#add_item "Generalize"
2396 ~key:GdkKeysyms._G ~callback:InvokeTactics'.generalize in
2397 let _ = f#add_separator () in
2398 let clear_menu_item =
2399 f#add_item "Clear" ~key:GdkKeysyms._C ~callback:InvokeTactics'.clear in
2400 let clearbody_menu_item =
2401 f#add_item "ClearBody"
2402 ~key:GdkKeysyms._B ~callback:InvokeTactics'.clearbody
2404 whd_menu_item#misc#set_sensitive terms_selected ;
2405 reduce_menu_item#misc#set_sensitive terms_selected ;
2406 simpl_menu_item#misc#set_sensitive terms_selected ;
2407 generalize_menu_item#misc#set_sensitive terms_selected ;
2408 clear_menu_item#misc#set_sensitive terms_selected ;
2409 clearbody_menu_item#misc#set_sensitive terms_selected ;
2410 menu#popup ~button ~time
2416 let vbox1 = GPack.vbox () in
2418 val mutable proofw_ref = None
2419 val mutable compute_ref = None
2421 Lazy.force self#compute ;
2422 match proofw_ref with
2423 None -> assert false
2424 | Some proofw -> proofw
2425 method content = vbox1
2427 match compute_ref with
2428 None -> assert false
2429 | Some compute -> compute
2433 let scrolled_window1 =
2434 GBin.scrolled_window ~border_width:10
2435 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2437 TermViewer.sequent_viewer ~width:400 ~height:275
2438 ~packing:(scrolled_window1#add) () in
2439 let _ = proofw_ref <- Some proofw in
2441 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2443 GButton.button ~label:"Ring"
2444 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2446 GButton.button ~label:"Fourier"
2447 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2449 GButton.button ~label:"Reflexivity"
2450 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2452 GButton.button ~label:"Symmetry"
2453 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2455 GButton.button ~label:"Assumption"
2456 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2457 let contradictionb =
2458 GButton.button ~label:"Contradiction"
2459 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2461 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2463 GButton.button ~label:"Exists"
2464 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2466 GButton.button ~label:"Split"
2467 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2469 GButton.button ~label:"Left"
2470 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2472 GButton.button ~label:"Right"
2473 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2474 let searchpatternb =
2475 GButton.button ~label:"SearchPattern_Apply"
2476 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2478 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2480 GButton.button ~label:"Exact"
2481 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2483 GButton.button ~label:"Intros"
2484 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2486 GButton.button ~label:"Apply"
2487 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2488 let elimintrossimplb =
2489 GButton.button ~label:"ElimIntrosSimpl"
2490 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2492 GButton.button ~label:"ElimType"
2493 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2495 GButton.button ~label:"Fold_whd"
2496 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2498 GButton.button ~label:"Fold_reduce"
2499 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2501 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2503 GButton.button ~label:"Fold_simpl"
2504 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2506 GButton.button ~label:"Cut"
2507 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2509 GButton.button ~label:"Change"
2510 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2512 GButton.button ~label:"Let ... In"
2513 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2515 GButton.button ~label:"RewriteSimpl ->"
2516 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2517 let rewritebacksimplb =
2518 GButton.button ~label:"RewriteSimpl <-"
2519 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
2521 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2523 GButton.button ~label:"Absurd"
2524 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2526 GButton.button ~label:"Decompose"
2527 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2529 GButton.button ~label:"Transitivity"
2530 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2532 GButton.button ~label:"Replace"
2533 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2534 (* Zack: spostare in una toolbar
2536 GButton.button ~label:"Generalize"
2537 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
2539 GButton.button ~label:"ClearBody"
2540 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2542 GButton.button ~label:"Clear"
2543 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2545 GButton.button ~label:"Whd"
2546 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2548 GButton.button ~label:"Reduce"
2549 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2551 GButton.button ~label:"Simpl"
2552 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2555 ignore(exactb#connect#clicked InvokeTactics'.exact) ;
2556 ignore(applyb#connect#clicked InvokeTactics'.apply) ;
2557 ignore(elimintrossimplb#connect#clicked InvokeTactics'.elimintrossimpl) ;
2558 ignore(elimtypeb#connect#clicked InvokeTactics'.elimtype) ;
2559 ignore(foldwhdb#connect#clicked InvokeTactics'.fold_whd) ;
2560 ignore(foldreduceb#connect#clicked InvokeTactics'.fold_reduce) ;
2561 ignore(foldsimplb#connect#clicked InvokeTactics'.fold_simpl) ;
2562 ignore(cutb#connect#clicked InvokeTactics'.cut) ;
2563 ignore(changeb#connect#clicked InvokeTactics'.change) ;
2564 ignore(letinb#connect#clicked InvokeTactics'.letin) ;
2565 ignore(ringb#connect#clicked InvokeTactics'.ring) ;
2566 ignore(fourierb#connect#clicked InvokeTactics'.fourier) ;
2567 ignore(rewritesimplb#connect#clicked InvokeTactics'.rewritesimpl) ;
2568 ignore(rewritebacksimplb#connect#clicked InvokeTactics'.rewritebacksimpl) ;
2569 ignore(replaceb#connect#clicked InvokeTactics'.replace) ;
2570 ignore(reflexivityb#connect#clicked InvokeTactics'.reflexivity) ;
2571 ignore(symmetryb#connect#clicked InvokeTactics'.symmetry) ;
2572 ignore(transitivityb#connect#clicked InvokeTactics'.transitivity) ;
2573 ignore(existsb#connect#clicked InvokeTactics'.exists) ;
2574 ignore(splitb#connect#clicked InvokeTactics'.split) ;
2575 ignore(leftb#connect#clicked InvokeTactics'.left) ;
2576 ignore(rightb#connect#clicked InvokeTactics'.right) ;
2577 ignore(assumptionb#connect#clicked InvokeTactics'.assumption) ;
2578 ignore(absurdb#connect#clicked InvokeTactics'.absurd) ;
2579 ignore(contradictionb#connect#clicked InvokeTactics'.contradiction) ;
2580 ignore(introsb#connect#clicked InvokeTactics'.intros) ;
2581 ignore(decomposeb#connect#clicked InvokeTactics'.decompose) ;
2582 ignore(searchpatternb#connect#clicked searchPattern) ;
2583 (* Zack: spostare in una toolbar
2584 ignore(whdb#connect#clicked whd) ;
2585 ignore(reduceb#connect#clicked reduce) ;
2586 ignore(simplb#connect#clicked simpl) ;
2587 ignore(clearbodyb#connect#clicked clearbody) ;
2588 ignore(clearb#connect#clicked clear) ;
2589 ignore(generalizeb#connect#clicked generalize) ;
2591 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2593 ((new GObj.event_ops proofw#as_widget)#connect#button_press
2594 (open_contextual_menu_for_selected_terms proofw)) ;
2600 let vbox1 = GPack.vbox () in
2601 let scrolled_window1 =
2602 GBin.scrolled_window ~border_width:10
2603 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2605 TermViewer.sequent_viewer ~width:400 ~height:275
2606 ~packing:(scrolled_window1#add) () in
2608 method proofw = (assert false : TermViewer.sequent_viewer)
2609 method content = vbox1
2610 method compute = (assert false : unit)
2614 let empty_page = new empty_page;;
2618 val notebook = GPack.notebook ()
2620 val mutable skip_switch_page_event = false
2621 val mutable empty = true
2622 method notebook = notebook
2624 let new_page = new page () in
2626 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2627 notebook#append_page
2628 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2629 new_page#content#coerce
2630 method remove_all_pages ~skip_switch_page_event:skip =
2632 notebook#remove_page 0 (* let's remove the empty page *)
2634 List.iter (function _ -> notebook#remove_page 0) !pages ;
2636 skip_switch_page_event <- skip
2637 method set_current_page ~may_skip_switch_page_event n =
2638 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2639 let new_page = notebook#page_num page#content#coerce in
2640 if may_skip_switch_page_event && new_page <> notebook#current_page then
2641 skip_switch_page_event <- true ;
2642 notebook#goto_page new_page
2643 method set_empty_page =
2646 notebook#append_page
2647 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2648 empty_page#content#coerce
2650 let (_,_,page) = List.nth !pages notebook#current_page in
2654 (notebook#connect#switch_page
2656 let skip = skip_switch_page_event in
2657 skip_switch_page_event <- false ;
2660 let (metano,setgoal,page) = List.nth !pages i in
2661 ProofEngine.goal := Some metano ;
2662 Lazy.force (page#compute) ;
2671 class rendering_window output (notebook : notebook) =
2672 let scratch_window = new scratch_window in
2674 GWindow.window ~title:"MathML viewer" ~border_width:0
2675 ~allow_shrink:false () in
2676 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2678 let handle_box = GBin.handle_box ~border_width:2
2679 ~packing:(vbox_for_menu#pack ~padding:0) () in
2680 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2681 let factory0 = new GMenu.factory menubar in
2682 let accel_group = factory0#accel_group in
2684 let file_menu = factory0#add_submenu "File" in
2685 let factory1 = new GMenu.factory file_menu ~accel_group in
2686 let export_to_postscript_menu_item =
2689 factory1#add_item "New Block of (Co)Inductive Definitions..."
2690 ~key:GdkKeysyms._B ~callback:new_inductive
2693 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2696 let reopen_menu_item =
2697 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2701 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2702 ignore (factory1#add_separator ()) ;
2704 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2706 let save_menu_item =
2707 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
2710 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2711 ignore (!save_set_sensitive false);
2712 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2713 ignore (!qed_set_sensitive false);
2714 ignore (factory1#add_separator ()) ;
2715 let export_to_postscript_menu_item =
2716 factory1#add_item "Export to PostScript..."
2717 ~callback:(export_to_postscript output) in
2718 ignore (factory1#add_separator ()) ;
2720 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2721 export_to_postscript_menu_item
2724 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2725 let factory2 = new GMenu.factory edit_menu ~accel_group in
2726 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2727 let proveit_menu_item =
2728 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2729 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2731 let focus_menu_item =
2732 factory2#add_item "Focus" ~key:GdkKeysyms._F
2733 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2736 focus_and_proveit_set_sensitive :=
2738 proveit_menu_item#misc#set_sensitive b ;
2739 focus_menu_item#misc#set_sensitive b
2741 let _ = !focus_and_proveit_set_sensitive false in
2742 (* edit term menu *)
2743 let edit_term_menu = factory0#add_submenu "Edit Term" in
2744 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2745 let check_menu_item =
2746 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2747 ~callback:(check scratch_window) in
2748 let _ = check_menu_item#misc#set_sensitive false in
2750 let settings_menu = factory0#add_submenu "Search" in
2751 let factory4 = new GMenu.factory settings_menu ~accel_group in
2753 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2755 let searchPattern_menu_item =
2756 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
2757 ~callback:completeSearchPattern in
2758 let _ = searchPattern_menu_item#misc#set_sensitive false in
2759 let show_menu_item =
2760 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2762 let insert_query_item =
2763 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._U
2764 ~callback:insertQuery in
2766 let settings_menu = factory0#add_submenu "Settings" in
2767 let factory3 = new GMenu.factory settings_menu ~accel_group in
2769 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2770 ~callback:edit_aliases in
2771 let _ = factory3#add_separator () in
2773 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2774 ~callback:(function _ -> (settings_window ())#show ()) in
2776 let _ = window#add_accel_group accel_group in
2780 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2782 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2783 let scrolled_window0 =
2784 GBin.scrolled_window ~border_width:10
2785 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2786 let _ = scrolled_window0#add output#coerce in
2788 GBin.frame ~label:"Insert Term"
2789 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2790 let scrolled_window1 =
2791 GBin.scrolled_window ~border_width:5
2792 ~packing:frame#add () in
2794 TermEditor'.term_editor
2795 ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2796 ~isnotempty_callback:
2798 check_menu_item#misc#set_sensitive b ;
2799 searchPattern_menu_item#misc#set_sensitive b) in
2801 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2803 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2805 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2809 ~source:"<html><body bgColor=\"white\"></body></html>"
2810 ~width:400 ~height: 100
2815 method outputhtml = outputhtml
2816 method inputt = inputt
2817 method output = (output : TermViewer.proof_viewer)
2818 method notebook = notebook
2819 method show = window#show
2821 notebook#set_empty_page ;
2822 export_to_postscript_menu_item#misc#set_sensitive false ;
2823 check_term := (check_term_in_scratch scratch_window) ;
2825 (* signal handlers here *)
2826 ignore(output#connect#selection_changed
2828 choose_selection output elem ;
2829 !focus_and_proveit_set_sensitive true
2831 ignore (output#connect#click (show_in_show_window_callback output)) ;
2832 let settings_window = new settings_window output scrolled_window0
2833 export_to_postscript_menu_item (choose_selection output) in
2834 set_settings_window settings_window ;
2835 set_outputhtml outputhtml ;
2836 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2837 Logger.log_callback :=
2838 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2843 let initialize_everything () =
2844 let module U = Unix in
2845 let output = TermViewer.proof_viewer ~width:350 ~height:280 () in
2846 let notebook = new notebook in
2847 let rendering_window' = new rendering_window output notebook in
2848 set_rendering_window rendering_window' ;
2849 rendering_window'#show () ;
2856 Mqint.set_database Mqint.postgres_db ;
2857 Mqint.init postgresqlconnectionstring ;
2859 ignore (GtkMain.Main.init ()) ;
2860 initialize_everything () ;
2861 if !usedb then Mqint.close ();