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 helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
40 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
44 " <body bgColor=\"white\">"
54 Sys.getenv "GTOPLEVEL_PROOFFILE"
56 Not_found -> "/public/currentproof"
61 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
63 Not_found -> "/public/currentprooftype"
66 (*CSC: the getter should handle the innertypes, not the FS *)
70 Sys.getenv "GTOPLEVEL_INNERTYPESFILE"
72 Not_found -> "/public/innertypes"
75 let constanttypefile =
77 Sys.getenv "GTOPLEVEL_CONSTANTTYPEFILE"
79 Not_found -> "/public/constanttype"
82 let postgresqlconnectionstring =
84 Sys.getenv "POSTGRESQL_CONNECTION_STRING"
86 Not_found -> "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm"
89 let empty_id_to_uris = ([],function _ -> None);;
92 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
94 let htmlheader_and_content = ref htmlheader;;
96 let current_cic_infos = ref None;;
97 let current_goal_infos = ref None;;
98 let current_scratch_infos = ref None;;
100 let id_to_uris = ref empty_id_to_uris;;
102 let check_term = ref (fun _ _ _ -> assert false);;
103 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
105 exception RenderingWindowsNotInitialized;;
107 let set_rendering_window,rendering_window =
108 let rendering_window_ref = ref None in
109 (function rw -> rendering_window_ref := Some rw),
111 match !rendering_window_ref with
112 None -> raise RenderingWindowsNotInitialized
117 exception SettingsWindowsNotInitialized;;
119 let set_settings_window,settings_window =
120 let settings_window_ref = ref None in
121 (function rw -> settings_window_ref := Some rw),
123 match !settings_window_ref with
124 None -> raise SettingsWindowsNotInitialized
129 exception OutputHtmlNotInitialized;;
131 let set_outputhtml,outputhtml =
132 let outputhtml_ref = ref None in
133 (function rw -> outputhtml_ref := Some rw),
135 match !outputhtml_ref with
136 None -> raise OutputHtmlNotInitialized
137 | Some outputhtml -> outputhtml
141 exception QedSetSensitiveNotInitialized;;
142 let qed_set_sensitive =
143 ref (function _ -> raise QedSetSensitiveNotInitialized)
146 exception SaveSetSensitiveNotInitialized;;
147 let save_set_sensitive =
148 ref (function _ -> raise SaveSetSensitiveNotInitialized)
151 (* COMMAND LINE OPTIONS *)
157 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
160 Arg.parse argspec ignore ""
164 let term_of_cic_textual_parser_uri uri =
165 let module C = Cic in
166 let module CTP = CicTextualParser0 in
168 CTP.ConUri uri -> C.Const (uri,[])
169 | CTP.VarUri uri -> C.Var (uri,[])
170 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
171 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
174 let string_of_cic_textual_parser_uri uri =
175 let module C = Cic in
176 let module CTP = CicTextualParser0 in
179 CTP.ConUri uri -> UriManager.string_of_uri uri
180 | CTP.VarUri uri -> UriManager.string_of_uri uri
181 | CTP.IndTyUri (uri,tyno) ->
182 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
183 | CTP.IndConUri (uri,tyno,consno) ->
184 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
187 (* 4 = String.length "cic:" *)
188 String.sub uri' 4 (String.length uri' - 4)
191 let output_html outputhtml msg =
192 htmlheader_and_content := !htmlheader_and_content ^ msg ;
193 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
194 outputhtml#set_topline (-1)
197 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
201 let check_window outputhtml uris =
204 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
206 GPack.notebook ~scrollable:true ~packing:window#add () in
211 let scrolled_window =
212 GBin.scrolled_window ~border_width:10
214 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
219 GMathViewAux.single_selection_math_view
220 ~packing:scrolled_window#add ~width:400 ~height:280 () in
223 term_of_cic_textual_parser_uri
224 (Disambiguate.cic_textual_parser_uri_of_string uri)
226 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
229 let mml = !mml_of_cic_term_ref 111 expr in
230 mmlwidget#load_doc ~dom:mml
233 output_html outputhtml
234 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
239 (notebook#connect#switch_page
240 (function i -> Lazy.force (List.nth render_terms i)))
246 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
247 ?(enable_button_for_non_vars=false) ~title ~msg uris
249 let choices = ref [] in
250 let chosen = ref false in
251 let use_only_constants = ref false in
253 GWindow.dialog ~modal:true ~title ~width:600 () in
255 GMisc.label ~text:msg
256 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
257 let scrolled_window =
258 GBin.scrolled_window ~border_width:10
259 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
261 let expected_height = 18 * List.length uris in
262 let height = if expected_height > 400 then 400 else expected_height in
263 GList.clist ~columns:1 ~packing:scrolled_window#add
264 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
265 let _ = List.map (function x -> clist#append [x]) uris in
267 GPack.hbox ~border_width:0
268 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
270 GMisc.label ~text:"None of the above. Try this one:"
271 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
273 GEdit.entry ~editable:true
274 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
276 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
278 GButton.button ~label:ok
279 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
280 let _ = okb#misc#set_sensitive false in
285 if enable_button_for_non_vars then
286 hbox#pack ~expand:false ~fill:false ~padding:5 w)
287 ~label:"Try constants only" () in
289 GButton.button ~label:"Check"
290 ~packing:(hbox#pack ~padding:5) () in
291 let _ = checkb#misc#set_sensitive false in
293 GButton.button ~label:"Abort"
294 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
296 let check_callback () =
297 assert (List.length !choices > 0) ;
298 check_window (outputhtml ()) !choices
300 ignore (window#connect#destroy GMain.Main.quit) ;
301 ignore (cancelb#connect#clicked window#destroy) ;
303 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
305 (nonvarsb#connect#clicked
307 use_only_constants := true ;
311 ignore (checkb#connect#clicked check_callback) ;
313 (clist#connect#select_row
314 (fun ~row ~column ~event ->
315 checkb#misc#set_sensitive true ;
316 okb#misc#set_sensitive true ;
317 choices := (List.nth uris row)::!choices)) ;
319 (clist#connect#unselect_row
320 (fun ~row ~column ~event ->
322 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
324 (manual_input#connect#changed
326 if manual_input#text = "" then
329 checkb#misc#set_sensitive false ;
330 okb#misc#set_sensitive false ;
331 clist#misc#set_sensitive true
335 choices := [manual_input#text] ;
336 clist#unselect_all () ;
337 checkb#misc#set_sensitive true ;
338 okb#misc#set_sensitive true ;
339 clist#misc#set_sensitive false
341 window#set_position `CENTER ;
345 if !use_only_constants then
347 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
350 if List.length !choices > 0 then !choices else raise NoChoice
355 let interactive_interpretation_choice interpretations =
356 let chosen = ref None in
359 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
360 let vbox = GPack.vbox ~packing:window#add () in
364 ("Ambiguous input since there are many well-typed interpretations." ^
365 " Please, choose one of them.")
366 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
368 GPack.notebook ~scrollable:true
369 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
372 (function interpretation ->
374 let expected_height = 18 * List.length interpretation in
375 let height = if expected_height > 400 then 400 else expected_height in
376 GList.clist ~columns:2 ~packing:notebook#append_page ~height
377 ~titles:["id" ; "URI"] ()
381 (function (id,uri) ->
382 let n = clist#append [id;uri] in
383 clist#set_row ~selectable:false n
386 clist#columns_autosize ()
389 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
391 GButton.button ~label:"Ok"
392 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
394 GButton.button ~label:"Abort"
395 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
397 ignore (window#connect#destroy GMain.Main.quit) ;
398 ignore (cancelb#connect#clicked window#destroy) ;
401 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
402 window#set_position `CENTER ;
406 None -> raise NoChoice
413 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
415 let query = ref "" in
416 MQueryGenerator.set_confirm_query
417 (function q -> query := MQueryUtil.text_of_query q ; true) ;
418 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
421 let domImpl = Gdome.domImplementation ();;
423 let parseStyle name =
425 domImpl#createDocumentFromURI
427 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
429 ~uri:("styles/" ^ name) ()
431 Gdome_xslt.processStylesheet style
434 let d_c = parseStyle "drop_coercions.xsl";;
435 let tc1 = parseStyle "objtheorycontent.xsl";;
436 let hc2 = parseStyle "content_to_html.xsl";;
437 let l = parseStyle "link.xsl";;
439 let c1 = parseStyle "rootcontent.xsl";;
440 let g = parseStyle "genmmlid.xsl";;
441 let c2 = parseStyle "annotatedpres.xsl";;
444 let getterURL = Configuration.getter_url;;
445 let processorURL = Configuration.processor_url;;
447 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
448 let mml_args ~explode_all =
449 ("explodeall",(if explode_all then "true()" else "false()"))::
450 ["processorURL", "'" ^ processorURL ^ "'" ;
451 "getterURL", "'" ^ getterURL ^ "'" ;
452 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
453 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
454 "UNICODEvsSYMBOL", "'symbol'" ;
455 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
456 "encoding", "'iso-8859-1'" ;
457 "media-type", "'text/html'" ;
458 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
459 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
460 "naturalLanguage", "'yes'" ;
461 "annotations", "'no'" ;
462 "URLs_or_URIs", "'URIs'" ;
463 "topurl", "'http://phd.cs.unibo.it/helm'" ;
464 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
467 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
469 ["processorURL", "'" ^ processorURL ^ "'" ;
470 "getterURL", "'" ^ getterURL ^ "'" ;
471 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
472 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
473 "UNICODEvsSYMBOL", "'symbol'" ;
474 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
475 "encoding", "'iso-8859-1'" ;
476 "media-type", "'text/html'" ;
477 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
478 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
479 "naturalLanguage", "'no'" ;
480 "annotations", "'no'" ;
481 "explodeall", "true()" ;
482 "URLs_or_URIs", "'URIs'" ;
483 "topurl", "'http://phd.cs.unibo.it/helm'" ;
484 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
487 let parse_file filename =
488 let inch = open_in filename in
489 let rec read_lines () =
491 let line = input_line inch in
499 let applyStylesheets input styles args =
500 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
505 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
507 (*CSC: ????????????????? *)
509 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true
513 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
514 ~ask_dtd_to_the_getter:true
518 None -> Xml2Gdome.document_of_xml domImpl xml
520 Xml.pp xml (Some constanttypefile) ;
521 Xml2Gdome.document_of_xml domImpl bodyxml'
523 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
524 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
526 Xml.pp xmlinnertypes (Some innertypesfile) ;
527 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
532 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
535 let struri = UriManager.string_of_uri uri in
536 let idx = (String.rindex struri '/') + 1 in
537 String.sub struri idx (String.length struri - idx)
539 let path = pathname ^ "/" ^ name in
541 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
545 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
546 ~ask_dtd_to_the_getter:false
549 let innertypesuri = UriManager.innertypesuri_of_uri uri in
550 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
551 Getter.register innertypesuri
552 (Configuration.annotations_url ^
553 Str.replace_first (Str.regexp "^cic:") ""
554 (UriManager.string_of_uri innertypesuri) ^ ".xml"
556 (* constant type / variable / mutual inductive types definition *)
557 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
559 (Configuration.annotations_url ^
560 Str.replace_first (Str.regexp "^cic:") ""
561 (UriManager.string_of_uri uri) ^ ".xml"
568 match UriManager.bodyuri_of_uri uri with
570 | Some bodyuri -> bodyuri
572 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
573 Getter.register bodyuri
574 (Configuration.annotations_url ^
575 Str.replace_first (Str.regexp "^cic:") ""
576 (UriManager.string_of_uri bodyuri) ^ ".xml"
583 exception RefreshSequentException of exn;;
584 exception RefreshProofException of exn;;
586 let refresh_proof (output : GMathViewAux.single_selection_math_view) =
588 let uri,currentproof =
589 match !ProofEngine.proof with
591 | Some (uri,metasenv,bo,ty) ->
592 !qed_set_sensitive (List.length metasenv = 0) ;
593 (*CSC: Wrong: [] is just plainly wrong *)
594 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
597 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
598 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
600 Cic2acic.acic_object_of_cic_object currentproof
603 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
606 output#load_doc ~dom:mml ;
608 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
611 match !ProofEngine.proof with
613 | Some (uri,metasenv,bo,ty) ->
614 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
615 raise (RefreshProofException e)
618 let refresh_sequent ?(empty_notebook=true) notebook =
620 match !ProofEngine.goal with
622 if empty_notebook then
624 notebook#remove_all_pages ~skip_switch_page_event:false ;
625 notebook#set_empty_page
628 notebook#proofw#unload
631 match !ProofEngine.proof with
633 | Some (_,metasenv,_,_) -> metasenv
635 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
636 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
637 SequentPp.XmlPp.print_sequent metasenv currentsequent
639 let regenerate_notebook () =
640 let skip_switch_page_event =
642 (m,_,_)::_ when m = metano -> false
645 notebook#remove_all_pages ~skip_switch_page_event ;
646 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
648 if empty_notebook then
650 regenerate_notebook () ;
651 notebook#set_current_page ~may_skip_switch_page_event:false metano
655 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
657 applyStylesheets sequent_doc sequent_styles sequent_args
659 notebook#set_current_page ~may_skip_switch_page_event:true metano;
660 notebook#proofw#load_doc ~dom:sequent_mml
662 current_goal_infos :=
663 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
667 match !ProofEngine.goal with
672 match !ProofEngine.proof with
674 | Some (_,metasenv,_,_) -> metasenv
677 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
678 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
679 raise (RefreshSequentException e)
680 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
684 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
685 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
688 let mml_of_cic_term metano term =
690 match !ProofEngine.proof with
692 | Some (_,metasenv,_,_) -> metasenv
695 match !ProofEngine.goal with
698 let (_,canonical_context,_) =
699 List.find (function (m,_,_) -> m=metano) metasenv
703 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
704 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
707 Xml2Gdome.document_of_xml domImpl sequent_gdome
710 applyStylesheets sequent_doc sequent_styles sequent_args ;
712 current_scratch_infos :=
713 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
717 exception OpenConjecturesStillThere;;
718 exception WrongProof;;
720 let pathname_of_annuri uristring =
721 Configuration.annotations_dir ^
722 Str.replace_first (Str.regexp "^cic:") "" uristring
725 let make_dirs dirpath =
726 ignore (Unix.system ("mkdir -p " ^ dirpath))
729 let save_obj uri obj =
731 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
732 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
734 Cic2acic.acic_object_of_cic_object obj
736 (* let's save the theorem and register it to the getter *)
737 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
739 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
744 match !ProofEngine.proof with
746 | Some (uri,[],bo,ty) ->
748 CicReduction.are_convertible []
749 (CicTypeChecker.type_of_aux' [] [] bo) ty
752 (*CSC: Wrong: [] is just plainly wrong *)
753 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
755 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
756 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
758 Cic2acic.acic_object_of_cic_object proof
761 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
764 ((rendering_window ())#output : GMathViewAux.single_selection_math_view)#load_doc mml ;
765 !qed_set_sensitive false ;
766 (* let's save the theorem and register it to the getter *)
767 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
769 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
773 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
778 | _ -> raise OpenConjecturesStillThere
782 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
783 match !ProofEngine.proof with
785 | Some (uri, metasenv, bo, ty) ->
787 (*CSC: Wrong: [] is just plainly wrong *)
788 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
790 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
791 Cic2acic.acic_object_of_cic_object currentproof
795 Cic2Xml.print_object uri ~ids_to_inner_sorts
796 ~ask_dtd_to_the_getter:true acurrentproof
798 xml,Some bodyxml -> xml,bodyxml
799 | _,None -> assert false
801 Xml.pp ~quiet:true xml (Some prooffiletype) ;
802 output_html outputhtml
803 ("<h1 color=\"Green\">Current proof type saved to " ^
804 prooffiletype ^ "</h1>") ;
805 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
806 output_html outputhtml
807 ("<h1 color=\"Green\">Current proof body saved to " ^
811 (* Used to typecheck the loaded proofs *)
812 let typecheck_loaded_proof metasenv bo ty =
813 let module T = CicTypeChecker in
816 (fun metasenv ((_,context,ty) as conj) ->
817 ignore (T.type_of_aux' metasenv context ty) ;
820 ignore (T.type_of_aux' metasenv [] ty) ;
821 ignore (T.type_of_aux' metasenv [] bo)
825 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
826 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
827 let notebook = (rendering_window ())#notebook in
830 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
833 None -> raise NoChoice
835 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
836 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
837 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
838 typecheck_loaded_proof metasenv bo ty ;
840 Some (uri, metasenv, bo, ty) ;
844 | (metano,_,_)::_ -> Some metano
846 refresh_proof output ;
847 refresh_sequent notebook ;
848 output_html outputhtml
849 ("<h1 color=\"Green\">Current proof type loaded from " ^
850 prooffiletype ^ "</h1>") ;
851 output_html outputhtml
852 ("<h1 color=\"Green\">Current proof body loaded from " ^
853 prooffile ^ "</h1>") ;
854 !save_set_sensitive true
857 RefreshSequentException e ->
858 output_html outputhtml
859 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
860 "sequent: " ^ Printexc.to_string e ^ "</h1>")
861 | RefreshProofException e ->
862 output_html outputhtml
863 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
864 "proof: " ^ Printexc.to_string e ^ "</h1>")
866 output_html outputhtml
867 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
870 let edit_aliases () =
871 let chosen = ref false in
874 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
876 GPack.vbox ~border_width:0 ~packing:window#add () in
877 let scrolled_window =
878 GBin.scrolled_window ~border_width:10
879 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
880 let input = GEdit.text ~editable:true ~width:400 ~height:100
881 ~packing:scrolled_window#add () in
883 GPack.hbox ~border_width:0
884 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
886 GButton.button ~label:"Ok"
887 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
889 GButton.button ~label:"Cancel"
890 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
891 ignore (window#connect#destroy GMain.Main.quit) ;
892 ignore (cancelb#connect#clicked window#destroy) ;
894 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
895 let dom,resolve_id = !id_to_uris in
897 (input#insert_text ~pos:0
902 match resolve_id v with
907 (string_of_cic_textual_parser_uri uri)
913 let inputtext = input#get_chars 0 input#length in
915 let alfa = "[a-zA-Z_-]" in
916 let digit = "[0-9]" in
917 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
918 let blanks = "\( \|\t\|\n\)+" in
919 let nonblanks = "[^ \t\n]+" in
920 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
922 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
926 let n' = Str.search_forward regexpr inputtext n in
927 let id = Str.matched_group 2 inputtext in
929 Disambiguate.cic_textual_parser_uri_of_string
930 ("cic:" ^ (Str.matched_group 5 inputtext))
932 let dom,resolve_id = aux (n' + 1) in
933 if List.mem id dom then
937 (function id' -> if id = id' then Some uri else resolve_id id')
939 Not_found -> empty_id_to_uris
943 id_to_uris := dom,resolve_id
947 let module L = LogicalOperations in
948 let module G = Gdome in
949 let notebook = (rendering_window ())#notebook in
950 let output = (rendering_window ())#output in
951 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
952 match (rendering_window ())#output#get_selection with
955 ((node : Gdome.element)#getAttributeNS
957 ((element : G.element)#getAttributeNS
960 ~localName:(G.domString "xref"))#to_string
962 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
966 match !current_cic_infos with
967 Some (ids_to_terms, ids_to_father_ids, _, _) ->
969 L.to_sequent id ids_to_terms ids_to_father_ids ;
970 refresh_proof output ;
971 refresh_sequent notebook
972 | None -> assert false (* "ERROR: No current term!!!" *)
974 RefreshSequentException e ->
975 output_html outputhtml
976 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
977 "sequent: " ^ Printexc.to_string e ^ "</h1>")
978 | RefreshProofException e ->
979 output_html outputhtml
980 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
981 "proof: " ^ Printexc.to_string e ^ "</h1>")
983 output_html outputhtml
984 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
986 | None -> assert false (* "ERROR: No selection!!!" *)
990 let module L = LogicalOperations in
991 let module G = Gdome in
992 let notebook = (rendering_window ())#notebook in
993 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
994 match (rendering_window ())#output#get_selection with
997 ((node : Gdome.element)#getAttributeNS
999 ((element : G.element)#getAttributeNS
1001 ~namespaceURI:helmns
1002 ~localName:(G.domString "xref"))#to_string
1004 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1008 match !current_cic_infos with
1009 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1011 L.focus id ids_to_terms ids_to_father_ids ;
1012 refresh_sequent notebook
1013 | None -> assert false (* "ERROR: No current term!!!" *)
1015 RefreshSequentException e ->
1016 output_html outputhtml
1017 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1018 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1019 | RefreshProofException e ->
1020 output_html outputhtml
1021 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1022 "proof: " ^ Printexc.to_string e ^ "</h1>")
1024 output_html outputhtml
1025 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1027 | None -> assert false (* "ERROR: No selection!!!" *)
1030 exception NoPrevGoal;;
1031 exception NoNextGoal;;
1033 let setgoal metano =
1034 let module L = LogicalOperations in
1035 let module G = Gdome in
1036 let notebook = (rendering_window ())#notebook in
1037 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1039 match !ProofEngine.proof with
1040 None -> assert false
1041 | Some (_,metasenv,_,_) -> metasenv
1044 refresh_sequent ~empty_notebook:false notebook
1046 RefreshSequentException e ->
1047 output_html outputhtml
1048 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1049 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1051 output_html outputhtml
1052 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1056 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
1059 GWindow.window ~width:800 ~border_width:2 () in
1060 let scrolled_window =
1061 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1063 GMathViewAux.single_selection_math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1064 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1065 let href = Gdome.domString "href" in
1066 let show_in_show_window_obj uri obj =
1067 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1070 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1071 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1073 Cic2acic.acic_object_of_cic_object obj
1076 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1079 window#set_title (UriManager.string_of_uri uri) ;
1080 window#misc#hide () ; window#show () ;
1081 mmlwidget#load_doc mml ;
1084 output_html outputhtml
1085 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1087 let show_in_show_window_uri uri =
1088 let obj = CicEnvironment.get_obj uri in
1089 show_in_show_window_obj uri obj
1091 let show_in_show_window_callback mmlwidget (n : Gdome.element) _ =
1092 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1094 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1096 show_in_show_window_uri (UriManager.uri_of_string uri)
1098 ignore (mmlwidget#action_toggle n)
1101 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
1103 show_in_show_window_obj, show_in_show_window_uri,
1104 show_in_show_window_callback
1107 exception NoObjectsLocated;;
1109 let user_uri_choice ~title ~msg uris =
1112 [] -> raise NoObjectsLocated
1116 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1121 String.sub uri 4 (String.length uri - 4)
1124 let locate_callback id =
1125 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1126 let result = MQueryGenerator.locate id in
1130 Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format' uri)
1133 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1135 output_html outputhtml html ;
1136 user_uri_choice ~title:"Ambiguous input."
1138 ("Ambiguous input \"" ^ id ^
1139 "\". Please, choose one interpetation:")
1144 let input_or_locate_uri ~title =
1145 let uri = ref None in
1148 ~width:400 ~modal:true ~title ~border_width:2 () in
1149 let vbox = GPack.vbox ~packing:window#add () in
1151 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1153 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1155 GEdit.entry ~editable:true
1156 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1158 GButton.button ~label:"Check"
1159 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1160 let _ = checkb#misc#set_sensitive false in
1162 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1164 GMisc.label ~text:"You can also enter an indentifier to locate:"
1165 ~packing:(hbox2#pack ~padding:5) () in
1167 GEdit.entry ~editable:true
1168 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1170 GButton.button ~label:"Locate"
1171 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1172 let _ = locateb#misc#set_sensitive false in
1174 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1176 GButton.button ~label:"Ok"
1177 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1178 let _ = okb#misc#set_sensitive false in
1180 GButton.button ~label:"Cancel"
1181 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1183 ignore (window#connect#destroy GMain.Main.quit) ;
1185 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1186 let check_callback () =
1187 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1188 let uri = "cic:" ^ manual_input#text in
1190 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1191 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1194 Getter.Unresolved ->
1195 output_html outputhtml
1196 ("<h1 color=\"Red\">URI " ^ uri ^
1197 " does not correspond to any object.</h1>") ;
1199 | UriManager.IllFormedUri _ ->
1200 output_html outputhtml
1201 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1204 output_html outputhtml
1205 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1209 (okb#connect#clicked
1211 if check_callback () then
1213 uri := Some manual_input#text ;
1217 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1219 (manual_input#connect#changed
1221 if manual_input#text = "" then
1223 checkb#misc#set_sensitive false ;
1224 okb#misc#set_sensitive false
1228 checkb#misc#set_sensitive true ;
1229 okb#misc#set_sensitive true
1232 (locate_input#connect#changed
1233 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1235 (locateb#connect#clicked
1237 let id = locate_input#text in
1238 manual_input#set_text (locate_callback id) ;
1239 locate_input#delete_text 0 (String.length id)
1242 GMain.Main.main () ;
1244 None -> raise NoChoice
1245 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1248 exception AmbiguousInput;;
1250 (* A WIDGET TO ENTER CIC TERMS *)
1254 let output_html msg = output_html (outputhtml ()) msg;;
1255 let interactive_user_uri_choice =
1256 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1257 interactive_user_uri_choice ~selection_mode ?ok
1258 ?enable_button_for_non_vars ~title ~msg;;
1259 let interactive_interpretation_choice = interactive_interpretation_choice;;
1260 let input_or_locate_uri = input_or_locate_uri;;
1264 module Disambiguate' = Disambiguate.Make(Callbacks);;
1266 class term_editor ?packing ?width ?height ?isnotempty_callback () =
1267 let input = GEdit.text ~editable:true ?width ?height ?packing () in
1269 match isnotempty_callback with
1272 ignore(input#connect#changed (function () -> callback (input#length > 0)))
1275 method coerce = input#coerce
1277 input#delete_text 0 input#length
1278 (* CSC: txt is now a string, but should be of type Cic.term *)
1279 method set_term txt =
1281 ignore ((input#insert_text txt) ~pos:0)
1282 (* CSC: this method should disappear *)
1283 method get_as_string =
1284 input#get_chars 0 input#length
1285 method get_metasenv_and_term ~context ~metasenv =
1289 Some (n,_) -> Some n
1293 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
1294 let dom,mk_metasenv_and_expr =
1295 CicTextualParserContext.main
1296 ~context:name_context ~metasenv CicTextualLexer.token lexbuf
1298 let id_to_uris',metasenv,expr =
1299 Disambiguate'.disambiguate_input context metasenv dom mk_metasenv_and_expr
1300 ~id_to_uris:!id_to_uris
1302 id_to_uris := id_to_uris' ;
1307 (* OTHER FUNCTIONS *)
1310 let inputt = ((rendering_window ())#inputt : term_editor) in
1311 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1314 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1316 None -> raise NoChoice
1318 let uri = locate_callback input in
1322 output_html outputhtml
1323 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1327 exception UriAlreadyInUse;;
1328 exception NotAUriToAConstant;;
1330 let new_inductive () =
1331 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1332 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1333 let notebook = (rendering_window ())#notebook in
1335 let chosen = ref false in
1336 let inductive = ref true in
1337 let paramsno = ref 0 in
1338 let get_uri = ref (function _ -> assert false) in
1339 let get_base_uri = ref (function _ -> assert false) in
1340 let get_names = ref (function _ -> assert false) in
1341 let get_types_and_cons = ref (function _ -> assert false) in
1342 let get_context_and_subst = ref (function _ -> assert false) in
1345 ~width:600 ~modal:true ~position:`CENTER
1346 ~title:"New Block of Mutual (Co)Inductive Definitions"
1347 ~border_width:2 () in
1348 let vbox = GPack.vbox ~packing:window#add () in
1350 GPack.hbox ~border_width:0
1351 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1353 GMisc.label ~text:"Enter the URI for the new block:"
1354 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1356 GEdit.entry ~editable:true
1357 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1359 GPack.hbox ~border_width:0
1360 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1364 "Enter the number of left parameters in every arity and constructor type:"
1365 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1366 let paramsno_entry =
1367 GEdit.entry ~editable:true ~text:"0"
1368 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1370 GPack.hbox ~border_width:0
1371 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1373 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1374 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1376 GButton.radio_button ~label:"Inductive"
1377 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1379 GButton.radio_button ~label:"Coinductive"
1380 ~group:inductiveb#group
1381 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1383 GPack.hbox ~border_width:0
1384 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1386 GMisc.label ~text:"Enter the list of the names of the types:"
1387 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1389 GEdit.entry ~editable:true
1390 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1392 GPack.hbox ~border_width:0
1393 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1395 GButton.button ~label:"> Next"
1396 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1397 let _ = okb#misc#set_sensitive true in
1399 GButton.button ~label:"Abort"
1400 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1401 ignore (window#connect#destroy GMain.Main.quit) ;
1402 ignore (cancelb#connect#clicked window#destroy) ;
1406 (okb#connect#clicked
1409 let uristr = "cic:" ^ uri_entry#text in
1410 let namesstr = names_entry#text in
1411 let paramsno' = int_of_string (paramsno_entry#text) in
1412 match Str.split (Str.regexp " +") namesstr with
1414 | (he::tl) as names ->
1415 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1418 ignore (Getter.resolve uri) ;
1419 raise UriAlreadyInUse
1421 Getter.Unresolved ->
1422 get_uri := (function () -> uri) ;
1423 get_names := (function () -> names) ;
1424 inductive := inductiveb#active ;
1425 paramsno := paramsno' ;
1430 output_html outputhtml
1431 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1439 GBin.frame ~label:name
1440 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1441 let vbox = GPack.vbox ~packing:frame#add () in
1442 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1444 GMisc.label ~text:("Enter its type:")
1445 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1446 let scrolled_window =
1447 GBin.scrolled_window ~border_width:5
1448 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1450 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1451 ~isnotempty_callback:
1453 (*non_empty_type := b ;*)
1454 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1457 GPack.hbox ~border_width:0
1458 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1460 GMisc.label ~text:("Enter the list of its constructors:")
1461 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1462 let cons_names_entry =
1463 GEdit.entry ~editable:true
1464 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1465 (newinputt,cons_names_entry)
1468 vbox#remove hboxn#coerce ;
1470 GPack.hbox ~border_width:0
1471 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1473 GButton.button ~label:"> Next"
1474 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1476 GButton.button ~label:"Abort"
1477 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1478 ignore (cancelb#connect#clicked window#destroy) ;
1480 (okb#connect#clicked
1483 let names = !get_names () in
1484 let types_and_cons =
1486 (fun name (newinputt,cons_names_entry) ->
1487 let consnamesstr = cons_names_entry#text in
1488 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1490 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1493 [] -> expr,cons_names
1494 | _ -> raise AmbiguousInput
1495 ) names type_widgets
1497 let uri = !get_uri () in
1499 (* Let's see if so far the definition is well-typed *)
1502 (* To test if the arities of the inductive types are well *)
1503 (* typed, we check the inductive block definition where *)
1504 (* no constructor is given to each type. *)
1507 (fun name (ty,cons) -> (name, !inductive, ty, []))
1508 names types_and_cons
1510 CicTypeChecker.typecheck_mutual_inductive_defs uri
1511 (tys,params,paramsno)
1513 get_context_and_subst :=
1517 (fun (context,subst) name (ty,_) ->
1519 (Some (Cic.Name name, Cic.Decl ty))::context,
1520 (Cic.MutInd (uri,!i,[]))::subst
1523 ) ([],[]) names types_and_cons) ;
1524 let types_and_cons' =
1526 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1527 names types_and_cons
1529 get_types_and_cons := (function () -> types_and_cons') ;
1534 output_html outputhtml
1535 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1538 and phase3 name cons =
1539 let get_cons_types = ref (function () -> assert false) in
1542 ~width:600 ~modal:true ~position:`CENTER
1543 ~title:(name ^ " Constructors")
1544 ~border_width:2 () in
1545 let vbox = GPack.vbox ~packing:window2#add () in
1546 let cons_type_widgets =
1548 (function consname ->
1550 GPack.hbox ~border_width:0
1551 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1553 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1554 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1555 let scrolled_window =
1556 GBin.scrolled_window ~border_width:5
1557 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1559 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1560 ~isnotempty_callback:
1562 (* (*non_empty_type := b ;*)
1563 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1568 GPack.hbox ~border_width:0
1569 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1571 GButton.button ~label:"> Next"
1572 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1573 let _ = okb#misc#set_sensitive true in
1575 GButton.button ~label:"Abort"
1576 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1577 ignore (window2#connect#destroy GMain.Main.quit) ;
1578 ignore (cancelb#connect#clicked window2#destroy) ;
1580 (okb#connect#clicked
1584 let context,subst= !get_context_and_subst () in
1589 inputt#get_metasenv_and_term ~context ~metasenv:[]
1593 let undebrujined_expr =
1595 (fun expr t -> CicSubstitution.subst t expr) expr subst
1597 name, undebrujined_expr
1598 | _ -> raise AmbiguousInput
1599 ) cons cons_type_widgets
1601 get_cons_types := (function () -> cons_types) ;
1605 output_html outputhtml
1606 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1609 GMain.Main.main () ;
1610 let okb_pressed = !chosen in
1612 if (not okb_pressed) then
1615 assert false (* The control never reaches this point *)
1618 (!get_cons_types ())
1621 (* No more phases left or Abort pressed *)
1623 GMain.Main.main () ;
1627 let uri = !get_uri () in
1630 let tys = !get_types_and_cons () in
1631 let obj = Cic.InductiveDefinition tys params !paramsno in
1634 prerr_endline (CicPp.ppobj obj) ;
1635 CicTypeChecker.typecheck_mutual_inductive_defs uri
1636 (tys,params,!paramsno) ;
1639 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1640 prerr_endline (CicPp.ppobj obj) ;
1642 (* We already know that obj is well-typed. We need to add it to the *)
1643 (* environment in order to compute the inner-types without having to *)
1644 (* debrujin it or having to modify lots of other functions to avoid *)
1645 (* asking the environment for the MUTINDs we are defining now. *)
1646 CicEnvironment.put_inductive_definition uri obj ;
1648 show_in_show_window_obj uri obj
1651 output_html outputhtml
1652 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1655 let mk_fresh_name_callback context name ~typ =
1657 match ProofEngineHelpers.mk_fresh_name context name ~typ with
1658 Cic.Name fresh_name -> fresh_name
1659 | Cic.Anonymous -> assert false
1662 GToolbox.input_string ~title:"Enter a fresh hypothesis name" ~text:fresh_name
1663 ("Enter a fresh name for the hypothesis " ^
1665 (List.map (function None -> None | Some (n,_) -> Some n) context))
1667 Some fresh_name' -> Cic.Name fresh_name'
1668 | None -> raise NoChoice
1672 let inputt = ((rendering_window ())#inputt : term_editor) in
1673 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1674 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1675 let notebook = (rendering_window ())#notebook in
1677 let chosen = ref false in
1678 let get_metasenv_and_term = ref (function _ -> assert false) in
1679 let get_uri = ref (function _ -> assert false) in
1680 let non_empty_type = ref false in
1683 ~width:600 ~modal:true ~title:"New Proof or Definition"
1684 ~border_width:2 () in
1685 let vbox = GPack.vbox ~packing:window#add () in
1687 GPack.hbox ~border_width:0
1688 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1690 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1691 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1693 GEdit.entry ~editable:true
1694 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1696 GPack.hbox ~border_width:0
1697 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1699 GMisc.label ~text:"Enter the theorem or definition type:"
1700 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1701 let scrolled_window =
1702 GBin.scrolled_window ~border_width:5
1703 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1704 (* the content of the scrolled_window is moved below (see comment) *)
1706 GPack.hbox ~border_width:0
1707 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1709 GButton.button ~label:"Ok"
1710 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1711 let _ = okb#misc#set_sensitive false in
1713 GButton.button ~label:"Cancel"
1714 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1715 (* moved here to have visibility of the ok button *)
1717 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1718 ~isnotempty_callback:
1720 non_empty_type := b ;
1721 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1724 newinputt#set_term inputt#get_as_string ;
1727 uri_entry#connect#changed
1729 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1731 ignore (window#connect#destroy GMain.Main.quit) ;
1732 ignore (cancelb#connect#clicked window#destroy) ;
1734 (okb#connect#clicked
1738 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1739 let uristr = "cic:" ^ uri_entry#text in
1740 let uri = UriManager.uri_of_string uristr in
1741 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1742 raise NotAUriToAConstant
1746 ignore (Getter.resolve uri) ;
1747 raise UriAlreadyInUse
1749 Getter.Unresolved ->
1750 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1751 get_uri := (function () -> uri) ;
1756 output_html outputhtml
1757 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1760 GMain.Main.main () ;
1763 let metasenv,expr = !get_metasenv_and_term () in
1764 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1765 ProofEngine.proof :=
1766 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1767 ProofEngine.goal := Some 1 ;
1768 refresh_sequent notebook ;
1769 refresh_proof output ;
1770 !save_set_sensitive true ;
1772 ProofEngine.intros ~mk_fresh_name_callback () ;
1773 refresh_sequent notebook ;
1774 refresh_proof output
1776 RefreshSequentException e ->
1777 output_html outputhtml
1778 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1779 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1780 | RefreshProofException e ->
1781 output_html outputhtml
1782 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1783 "proof: " ^ Printexc.to_string e ^ "</h1>")
1785 output_html outputhtml
1786 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1789 let check_term_in_scratch scratch_window metasenv context expr =
1791 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1792 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1793 scratch_window#show () ;
1794 scratch_window#mmlwidget#load_doc ~dom:mml
1797 print_endline ("? " ^ CicPp.ppterm expr) ;
1801 let check scratch_window () =
1802 let inputt = ((rendering_window ())#inputt : term_editor) in
1803 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1805 match !ProofEngine.proof with
1807 | Some (_,metasenv,_,_) -> metasenv
1810 match !ProofEngine.goal with
1813 let (_,canonical_context,_) =
1814 List.find (function (m,_,_) -> m=metano) metasenv
1819 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1820 check_term_in_scratch scratch_window metasenv' context expr
1823 output_html outputhtml
1824 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1827 let decompose_uris_choice_callback uris =
1828 (* N.B.: in questo passaggio perdo l'informazione su exp_named_subst !!!! *)
1829 let module U = UriManager in
1832 match Disambiguate.cic_textual_parser_uri_of_string uri with
1833 CicTextualParser0.IndTyUri (uri,typeno) -> (uri,typeno,[])
1834 | _ -> assert false)
1835 (interactive_user_uri_choice
1836 ~selection_mode:`EXTENDED ~ok:"Ok" ~enable_button_for_non_vars:false
1837 ~title:"Decompose" ~msg:"Please, select the Inductive Types to decompose"
1839 (function (uri,typeno,_) ->
1840 U.string_of_uri uri ^ "#1/" ^ string_of_int (typeno+1)
1845 (***********************)
1847 (***********************)
1849 let call_tactic tactic () =
1850 let notebook = (rendering_window ())#notebook in
1851 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1852 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1853 let savedproof = !ProofEngine.proof in
1854 let savedgoal = !ProofEngine.goal in
1858 refresh_sequent notebook ;
1859 refresh_proof output
1861 RefreshSequentException e ->
1862 output_html outputhtml
1863 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1864 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1865 ProofEngine.proof := savedproof ;
1866 ProofEngine.goal := savedgoal ;
1867 refresh_sequent notebook
1868 | RefreshProofException e ->
1869 output_html outputhtml
1870 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1871 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1872 ProofEngine.proof := savedproof ;
1873 ProofEngine.goal := savedgoal ;
1874 refresh_sequent notebook ;
1875 refresh_proof output
1877 output_html outputhtml
1878 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1879 ProofEngine.proof := savedproof ;
1880 ProofEngine.goal := savedgoal ;
1884 let call_tactic_with_input tactic () =
1885 let notebook = (rendering_window ())#notebook in
1886 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1887 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1888 let inputt = ((rendering_window ())#inputt : term_editor) in
1889 let savedproof = !ProofEngine.proof in
1890 let savedgoal = !ProofEngine.goal in
1891 let uri,metasenv,bo,ty =
1892 match !ProofEngine.proof with
1893 None -> assert false
1894 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1896 let canonical_context =
1897 match !ProofEngine.goal with
1898 None -> assert false
1900 let (_,canonical_context,_) =
1901 List.find (function (m,_,_) -> m=metano) metasenv
1906 let metasenv',expr =
1907 inputt#get_metasenv_and_term canonical_context metasenv
1909 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1911 refresh_sequent notebook ;
1912 refresh_proof output ;
1915 RefreshSequentException e ->
1916 output_html outputhtml
1917 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1918 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1919 ProofEngine.proof := savedproof ;
1920 ProofEngine.goal := savedgoal ;
1921 refresh_sequent notebook
1922 | RefreshProofException e ->
1923 output_html outputhtml
1924 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1925 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1926 ProofEngine.proof := savedproof ;
1927 ProofEngine.goal := savedgoal ;
1928 refresh_sequent notebook ;
1929 refresh_proof output
1931 output_html outputhtml
1932 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1933 ProofEngine.proof := savedproof ;
1934 ProofEngine.goal := savedgoal ;
1937 let call_tactic_with_goal_input tactic () =
1938 let module L = LogicalOperations in
1939 let module G = Gdome in
1940 let notebook = (rendering_window ())#notebook in
1941 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1942 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1943 let savedproof = !ProofEngine.proof in
1944 let savedgoal = !ProofEngine.goal in
1945 match notebook#proofw#get_selections with
1948 ((node : Gdome.element)#getAttributeNS
1949 ~namespaceURI:helmns
1950 ~localName:(G.domString "xref"))#to_string
1952 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1956 match !current_goal_infos with
1957 Some (ids_to_terms, ids_to_father_ids,_) ->
1959 tactic (Hashtbl.find ids_to_terms id) ;
1960 refresh_sequent notebook ;
1961 refresh_proof output
1962 | None -> assert false (* "ERROR: No current term!!!" *)
1964 RefreshSequentException e ->
1965 output_html outputhtml
1966 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1967 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1968 ProofEngine.proof := savedproof ;
1969 ProofEngine.goal := savedgoal ;
1970 refresh_sequent notebook
1971 | RefreshProofException e ->
1972 output_html outputhtml
1973 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1974 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1975 ProofEngine.proof := savedproof ;
1976 ProofEngine.goal := savedgoal ;
1977 refresh_sequent notebook ;
1978 refresh_proof output
1980 output_html outputhtml
1981 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1982 ProofEngine.proof := savedproof ;
1983 ProofEngine.goal := savedgoal ;
1986 output_html outputhtml
1987 ("<h1 color=\"red\">No term selected</h1>")
1989 output_html outputhtml
1990 ("<h1 color=\"red\">Many terms selected</h1>")
1993 let call_tactic_with_input_and_goal_input tactic () =
1994 let module L = LogicalOperations in
1995 let module G = Gdome in
1996 let notebook = (rendering_window ())#notebook in
1997 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1998 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1999 let inputt = ((rendering_window ())#inputt : term_editor) in
2000 let savedproof = !ProofEngine.proof in
2001 let savedgoal = !ProofEngine.goal in
2002 match notebook#proofw#get_selections with
2005 ((node : Gdome.element)#getAttributeNS
2006 ~namespaceURI:helmns
2007 ~localName:(G.domString "xref"))#to_string
2009 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2013 match !current_goal_infos with
2014 Some (ids_to_terms, ids_to_father_ids,_) ->
2016 let uri,metasenv,bo,ty =
2017 match !ProofEngine.proof with
2018 None -> assert false
2019 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
2021 let canonical_context =
2022 match !ProofEngine.goal with
2023 None -> assert false
2025 let (_,canonical_context,_) =
2026 List.find (function (m,_,_) -> m=metano) metasenv
2028 canonical_context in
2029 let (metasenv',expr) =
2030 inputt#get_metasenv_and_term canonical_context metasenv
2032 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
2033 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
2035 refresh_sequent notebook ;
2036 refresh_proof output ;
2038 | None -> assert false (* "ERROR: No current term!!!" *)
2040 RefreshSequentException e ->
2041 output_html outputhtml
2042 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2043 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2044 ProofEngine.proof := savedproof ;
2045 ProofEngine.goal := savedgoal ;
2046 refresh_sequent notebook
2047 | RefreshProofException e ->
2048 output_html outputhtml
2049 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2050 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2051 ProofEngine.proof := savedproof ;
2052 ProofEngine.goal := savedgoal ;
2053 refresh_sequent notebook ;
2054 refresh_proof output
2056 output_html outputhtml
2057 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2058 ProofEngine.proof := savedproof ;
2059 ProofEngine.goal := savedgoal ;
2062 output_html outputhtml
2063 ("<h1 color=\"red\">No term selected</h1>")
2065 output_html outputhtml
2066 ("<h1 color=\"red\">Many terms selected</h1>")
2069 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
2070 let module L = LogicalOperations in
2071 let module G = Gdome in
2073 (scratch_window#mmlwidget : GMathViewAux.multi_selection_math_view) in
2074 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2075 let savedproof = !ProofEngine.proof in
2076 let savedgoal = !ProofEngine.goal in
2077 match mmlwidget#get_selections with
2080 ((node : Gdome.element)#getAttributeNS
2081 ~namespaceURI:helmns
2082 ~localName:(G.domString "xref"))#to_string
2084 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2088 match !current_scratch_infos with
2089 (* term is the whole goal in the scratch_area *)
2090 Some (term,ids_to_terms, ids_to_father_ids,_) ->
2092 let expr = tactic term (Hashtbl.find ids_to_terms id) in
2093 let mml = mml_of_cic_term 111 expr in
2094 scratch_window#show () ;
2095 scratch_window#mmlwidget#load_doc ~dom:mml
2096 | None -> assert false (* "ERROR: No current term!!!" *)
2099 output_html outputhtml
2100 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2103 output_html outputhtml
2104 ("<h1 color=\"red\">No term selected</h1>")
2106 output_html outputhtml
2107 ("<h1 color=\"red\">Many terms selected</h1>")
2110 let call_tactic_with_hypothesis_input tactic () =
2111 let module L = LogicalOperations in
2112 let module G = Gdome in
2113 let notebook = (rendering_window ())#notebook in
2114 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
2115 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2116 let savedproof = !ProofEngine.proof in
2117 let savedgoal = !ProofEngine.goal in
2118 match notebook#proofw#get_selections with
2121 ((node : Gdome.element)#getAttributeNS
2122 ~namespaceURI:helmns
2123 ~localName:(G.domString "xref"))#to_string
2125 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2129 match !current_goal_infos with
2130 Some (_,_,ids_to_hypotheses) ->
2132 tactic (Hashtbl.find ids_to_hypotheses id) ;
2133 refresh_sequent notebook ;
2134 refresh_proof output
2135 | None -> assert false (* "ERROR: No current term!!!" *)
2137 RefreshSequentException e ->
2138 output_html outputhtml
2139 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2140 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2141 ProofEngine.proof := savedproof ;
2142 ProofEngine.goal := savedgoal ;
2143 refresh_sequent notebook
2144 | RefreshProofException e ->
2145 output_html outputhtml
2146 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2147 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2148 ProofEngine.proof := savedproof ;
2149 ProofEngine.goal := savedgoal ;
2150 refresh_sequent notebook ;
2151 refresh_proof output
2153 output_html outputhtml
2154 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2155 ProofEngine.proof := savedproof ;
2156 ProofEngine.goal := savedgoal ;
2159 output_html outputhtml
2160 ("<h1 color=\"red\">No term selected</h1>")
2162 output_html outputhtml
2163 ("<h1 color=\"red\">Many terms selected</h1>")
2167 let intros = call_tactic (ProofEngine.intros ~mk_fresh_name_callback);;
2168 let exact = call_tactic_with_input ProofEngine.exact;;
2169 let apply = call_tactic_with_input ProofEngine.apply;;
2170 let elimintrossimpl = call_tactic_with_input ProofEngine.elim_intros_simpl;;
2171 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
2172 let whd = call_tactic_with_goal_input ProofEngine.whd;;
2173 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
2174 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
2175 let fold_whd = call_tactic_with_input ProofEngine.fold_whd;;
2176 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce;;
2177 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl;;
2178 let cut = call_tactic_with_input (ProofEngine.cut ~mk_fresh_name_callback);;
2179 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
2180 let letin = call_tactic_with_input (ProofEngine.letin ~mk_fresh_name_callback);;
2181 let ring = call_tactic ProofEngine.ring;;
2182 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
2183 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
2184 let fourier = call_tactic ProofEngine.fourier;;
2185 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
2186 let rewritebacksimpl = call_tactic_with_input ProofEngine.rewrite_back_simpl;;
2187 let replace = call_tactic_with_input_and_goal_input ProofEngine.replace;;
2188 let reflexivity = call_tactic ProofEngine.reflexivity;;
2189 let symmetry = call_tactic ProofEngine.symmetry;;
2190 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
2191 let exists = call_tactic ProofEngine.exists;;
2192 let split = call_tactic ProofEngine.split;;
2193 let left = call_tactic ProofEngine.left;;
2194 let right = call_tactic ProofEngine.right;;
2195 let assumption = call_tactic ProofEngine.assumption;;
2196 let generalize = call_tactic_with_goal_input ProofEngine.generalize;;
2197 let absurd = call_tactic_with_input ProofEngine.absurd;;
2198 let contradiction = call_tactic ProofEngine.contradiction;;
2200 call_tactic_with_input
2201 (ProofEngine.decompose ~uris_choice_callback:decompose_uris_choice_callback);;
2203 let whd_in_scratch scratch_window =
2204 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
2207 let reduce_in_scratch scratch_window =
2208 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
2211 let simpl_in_scratch scratch_window =
2212 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
2218 (**********************)
2219 (* END OF TACTICS *)
2220 (**********************)
2224 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2226 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
2229 output_html outputhtml
2230 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2233 exception NotADefinition;;
2236 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2237 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
2238 let notebook = (rendering_window ())#notebook in
2240 let uri = input_or_locate_uri ~title:"Open" in
2241 CicTypeChecker.typecheck uri ;
2242 let metasenv,bo,ty =
2243 match CicEnvironment.get_cooked_obj uri with
2244 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
2245 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
2248 | Cic.InductiveDefinition _ -> raise NotADefinition
2250 ProofEngine.proof :=
2251 Some (uri, metasenv, bo, ty) ;
2252 ProofEngine.goal := None ;
2253 refresh_sequent notebook ;
2254 refresh_proof output
2256 RefreshSequentException e ->
2257 output_html outputhtml
2258 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2259 "sequent: " ^ Printexc.to_string e ^ "</h1>")
2260 | RefreshProofException e ->
2261 output_html outputhtml
2262 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2263 "proof: " ^ Printexc.to_string e ^ "</h1>")
2265 output_html outputhtml
2266 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2269 let show_query_results results =
2272 ~modal:false ~title:"Query results." ~border_width:2 () in
2273 let vbox = GPack.vbox ~packing:window#add () in
2275 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2278 ~text:"Click on a URI to show that object"
2279 ~packing:hbox#add () in
2280 let scrolled_window =
2281 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
2282 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2283 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
2286 (function (uri,_) ->
2290 clist#set_row ~selectable:false n
2293 clist#columns_autosize () ;
2295 (clist#connect#select_row
2296 (fun ~row ~column ~event ->
2297 let (uristr,_) = List.nth results row in
2299 Disambiguate.cic_textual_parser_uri_of_string
2300 (Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format'
2303 CicTextualParser0.ConUri uri
2304 | CicTextualParser0.VarUri uri
2305 | CicTextualParser0.IndTyUri (uri,_)
2306 | CicTextualParser0.IndConUri (uri,_,_) ->
2307 show_in_show_window_uri uri
2313 let refine_constraints (must_obj,must_rel,must_sort) =
2314 let chosen = ref false in
2315 let use_only = ref false in
2318 ~modal:true ~title:"Constraints refinement."
2319 ~width:800 ~border_width:2 () in
2320 let vbox = GPack.vbox ~packing:window#add () in
2322 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2325 ~text: "\"Only\" constraints can be enforced or not."
2326 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2328 GButton.toggle_button ~label:"Enforce \"only\" constraints"
2329 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2332 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
2333 (* Notebook for the constraints choice *)
2335 GPack.notebook ~scrollable:true
2336 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2337 (* Rel constraints *)
2340 ~text: "Constraints on Rels" () in
2342 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2345 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2348 ~text: "You can now specify the constraints on Rels."
2349 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2350 let expected_height = 25 * (List.length must_rel + 2) in
2351 let height = if expected_height > 400 then 400 else expected_height in
2352 let scrolled_window =
2353 GBin.scrolled_window ~border_width:10 ~height ~width:600
2354 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2355 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2356 let rel_constraints =
2358 (function (position,depth) ->
2361 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2365 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2367 None -> position, ref None
2369 let mutable_ref = ref (Some depth') in
2371 GButton.toggle_button
2372 ~label:("depth = " ^ string_of_int depth') ~active:true
2373 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2376 (depthb#connect#toggled
2378 let sel_depth = if depthb#active then Some depth' else None in
2379 mutable_ref := sel_depth
2381 position, mutable_ref
2383 (* Sort constraints *)
2386 ~text: "Constraints on Sorts" () in
2388 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2391 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2394 ~text: "You can now specify the constraints on Sorts."
2395 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2396 let expected_height = 25 * (List.length must_sort + 2) in
2397 let height = if expected_height > 400 then 400 else expected_height in
2398 let scrolled_window =
2399 GBin.scrolled_window ~border_width:10 ~height ~width:600
2400 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2401 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2402 let sort_constraints =
2404 (function (position,depth,sort) ->
2407 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2410 ~text:(sort ^ " " ^ position)
2411 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2413 None -> position, ref None, sort
2415 let mutable_ref = ref (Some depth') in
2417 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
2419 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2422 (depthb#connect#toggled
2424 let sel_depth = if depthb#active then Some depth' else None in
2425 mutable_ref := sel_depth
2427 position, mutable_ref, sort
2429 (* Obj constraints *)
2432 ~text: "Constraints on constants" () in
2434 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2437 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2440 ~text: "You can now specify the constraints on constants."
2441 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2442 let expected_height = 25 * (List.length must_obj + 2) in
2443 let height = if expected_height > 400 then 400 else expected_height in
2444 let scrolled_window =
2445 GBin.scrolled_window ~border_width:10 ~height ~width:600
2446 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2447 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2448 let obj_constraints =
2450 (function (uri,position,depth) ->
2453 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2456 ~text:(uri ^ " " ^ position)
2457 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2459 None -> uri, position, ref None
2461 let mutable_ref = ref (Some depth') in
2463 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
2465 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2468 (depthb#connect#toggled
2470 let sel_depth = if depthb#active then Some depth' else None in
2471 mutable_ref := sel_depth
2473 uri, position, mutable_ref
2475 (* Confirm/abort buttons *)
2477 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2479 GButton.button ~label:"Ok"
2480 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2482 GButton.button ~label:"Abort"
2483 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2485 ignore (window#connect#destroy GMain.Main.quit) ;
2486 ignore (cancelb#connect#clicked window#destroy) ;
2488 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
2489 window#set_position `CENTER ;
2491 GMain.Main.main () ;
2493 let chosen_must_rel =
2495 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
2496 let chosen_must_sort =
2498 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
2501 let chosen_must_obj =
2503 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
2506 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
2508 (*CSC: ???????????????????????? I assume that must and only are the same... *)
2509 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
2517 let completeSearchPattern () =
2518 let inputt = ((rendering_window ())#inputt : term_editor) in
2519 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2521 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
2522 let must = MQueryLevels2.get_constraints expr in
2523 let must',only = refine_constraints must in
2524 let results = MQueryGenerator.searchPattern must' only in
2525 show_query_results results
2528 output_html outputhtml
2529 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2532 let insertQuery () =
2533 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2535 let chosen = ref None in
2538 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
2539 let vbox = GPack.vbox ~packing:window#add () in
2541 GMisc.label ~text:"Insert Query. For Experts Only."
2542 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2543 let scrolled_window =
2544 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
2545 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2546 let input = GEdit.text ~editable:true
2547 ~packing:scrolled_window#add () in
2549 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2551 GButton.button ~label:"Ok"
2552 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2554 GButton.button ~label:"Load from file..."
2555 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2557 GButton.button ~label:"Abort"
2558 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2559 ignore (window#connect#destroy GMain.Main.quit) ;
2560 ignore (cancelb#connect#clicked window#destroy) ;
2562 (okb#connect#clicked
2564 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
2566 (loadb#connect#clicked
2569 GToolbox.select_file ~title:"Select Query File" ()
2573 let inch = open_in filename in
2574 let rec read_file () =
2576 let line = input_line inch in
2577 line ^ "\n" ^ read_file ()
2581 let text = read_file () in
2582 input#delete_text 0 input#length ;
2583 ignore (input#insert_text text ~pos:0))) ;
2584 window#set_position `CENTER ;
2586 GMain.Main.main () ;
2591 Mqint.execute (MQueryUtil.query_of_text (Lexing.from_string q))
2593 show_query_results results
2596 output_html outputhtml
2597 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2600 let choose_must list_of_must only =
2601 let chosen = ref None in
2602 let user_constraints = ref [] in
2605 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2606 let vbox = GPack.vbox ~packing:window#add () in
2608 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2612 ("You can now specify the genericity of the query. " ^
2613 "The more generic the slower.")
2614 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2616 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2620 "Suggestion: start with faster queries before moving to more generic ones."
2621 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2623 GPack.notebook ~scrollable:true
2624 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2627 let last = List.length list_of_must in
2633 (if !page = 1 then "More generic" else
2634 if !page = last then "More precise" else " ") () in
2635 let expected_height = 25 * (List.length must + 2) in
2636 let height = if expected_height > 400 then 400 else expected_height in
2637 let scrolled_window =
2638 GBin.scrolled_window ~border_width:10 ~height ~width:600
2639 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2641 GList.clist ~columns:2 ~packing:scrolled_window#add
2642 ~titles:["URI" ; "Position"] ()
2646 (function (uri,position) ->
2649 [uri; if position then "MainConclusion" else "Conclusion"]
2651 clist#set_row ~selectable:false n
2654 clist#columns_autosize ()
2657 let label = GMisc.label ~text:"User provided" () in
2659 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2661 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2664 ~text:"Select the constraints that must be satisfied and press OK."
2665 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2666 let expected_height = 25 * (List.length only + 2) in
2667 let height = if expected_height > 400 then 400 else expected_height in
2668 let scrolled_window =
2669 GBin.scrolled_window ~border_width:10 ~height ~width:600
2670 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2672 GList.clist ~columns:2 ~packing:scrolled_window#add
2673 ~selection_mode:`EXTENDED
2674 ~titles:["URI" ; "Position"] ()
2678 (function (uri,position) ->
2681 [uri; if position then "MainConclusion" else "Conclusion"]
2683 clist#set_row ~selectable:true n
2686 clist#columns_autosize () ;
2688 (clist#connect#select_row
2689 (fun ~row ~column ~event ->
2690 user_constraints := (List.nth only row)::!user_constraints)) ;
2692 (clist#connect#unselect_row
2693 (fun ~row ~column ~event ->
2696 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2699 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2701 GButton.button ~label:"Ok"
2702 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2704 GButton.button ~label:"Abort"
2705 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2707 ignore (window#connect#destroy GMain.Main.quit) ;
2708 ignore (cancelb#connect#clicked window#destroy) ;
2710 (okb#connect#clicked
2711 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2712 window#set_position `CENTER ;
2714 GMain.Main.main () ;
2716 None -> raise NoChoice
2718 if n = List.length list_of_must then
2719 (* user provided constraints *)
2722 List.nth list_of_must n
2725 let searchPattern () =
2726 let inputt = ((rendering_window ())#inputt : term_editor) in
2727 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2730 match !ProofEngine.proof with
2731 None -> assert false
2732 | Some (_,metasenv,_,_) -> metasenv
2734 match !ProofEngine.goal with
2737 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2738 let list_of_must,only = MQueryLevels.out_restr metasenv ey ty in
2739 let must = choose_must list_of_must only in
2740 let torigth_restriction (u,b) =
2743 "http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion"
2745 "http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion"
2749 let rigth_must = List.map torigth_restriction must in
2750 let rigth_only = Some (List.map torigth_restriction only) in
2752 MQueryGenerator.searchPattern
2753 (rigth_must,[],[]) (rigth_only,None,None) in
2757 Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format' uri
2760 " <h1>Backward Query: </h1>" ^
2761 " <pre>" ^ get_last_query result ^ "</pre>"
2763 output_html outputhtml html ;
2765 let rec filter_out =
2769 let tl',exc = filter_out tl in
2772 ProofEngine.can_apply
2773 (term_of_cic_textual_parser_uri
2774 (Disambiguate.cic_textual_parser_uri_of_string uri))
2782 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2783 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2790 " <h1>Objects that can actually be applied: </h1> " ^
2791 String.concat "<br>" uris' ^ exc ^
2792 " <h1>Number of false matches: " ^
2793 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2794 " <h1>Number of good matches: " ^
2795 string_of_int (List.length uris') ^ "</h1>"
2797 output_html outputhtml html' ;
2799 user_uri_choice ~title:"Ambiguous input."
2801 "Many lemmas can be successfully applied. Please, choose one:"
2804 inputt#set_term uri' ;
2808 output_html outputhtml
2809 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2812 let choose_selection mmlwidget (element : Gdome.element option) =
2813 let module G = Gdome in
2814 let rec aux element =
2815 if element#hasAttributeNS
2816 ~namespaceURI:helmns
2817 ~localName:(G.domString "xref")
2819 mmlwidget#set_selection (Some element)
2822 match element#get_parentNode with
2823 None -> assert false
2824 (*CSC: OCAML DIVERGES!
2825 | Some p -> aux (new G.element_of_node p)
2827 | Some p -> aux (new Gdome.element_of_node p)
2829 GdomeInit.DOMCastException _ ->
2831 "******* trying to select above the document root ********"
2835 | None -> mmlwidget#set_selection None
2838 (* STUFF TO BUILD THE GTK INTERFACE *)
2840 (* Stuff for the widget settings *)
2842 let export_to_postscript (output : GMathViewAux.single_selection_math_view) =
2843 let lastdir = ref (Unix.getcwd ()) in
2846 GToolbox.select_file ~title:"Export to PostScript"
2847 ~dir:lastdir ~filename:"screenshot.ps" ()
2851 output#export_to_postscript ~filename:filename ();
2854 let activate_t1 (output : GMathViewAux.single_selection_math_view) button_set_anti_aliasing
2855 button_set_transparency export_to_postscript_menu_item
2858 let is_set = button_t1#active in
2859 output#set_font_manager_type
2860 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2863 button_set_anti_aliasing#misc#set_sensitive true ;
2864 button_set_transparency#misc#set_sensitive true ;
2865 export_to_postscript_menu_item#misc#set_sensitive true ;
2869 button_set_anti_aliasing#misc#set_sensitive false ;
2870 button_set_transparency#misc#set_sensitive false ;
2871 export_to_postscript_menu_item#misc#set_sensitive false ;
2875 let set_anti_aliasing output button_set_anti_aliasing () =
2876 output#set_anti_aliasing button_set_anti_aliasing#active
2879 let set_transparency output button_set_transparency () =
2880 output#set_transparency button_set_transparency#active
2883 let changefont output font_size_spinb () =
2884 output#set_font_size font_size_spinb#value_as_int
2887 let set_log_verbosity output log_verbosity_spinb () =
2888 output#set_log_verbosity log_verbosity_spinb#value_as_int
2891 class settings_window (output : GMathViewAux.single_selection_math_view) sw
2892 export_to_postscript_menu_item selection_changed_callback
2894 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2896 GPack.vbox ~packing:settings_window#add () in
2899 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2900 ~border_width:5 ~packing:vbox#add () in
2902 GButton.toggle_button ~label:"activate t1 fonts"
2903 ~packing:(table#attach ~left:0 ~top:0) () in
2904 let button_set_anti_aliasing =
2905 GButton.toggle_button ~label:"set_anti_aliasing"
2906 ~packing:(table#attach ~left:0 ~top:1) () in
2907 let button_set_transparency =
2908 GButton.toggle_button ~label:"set_transparency"
2909 ~packing:(table#attach ~left:2 ~top:1) () in
2912 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2913 ~border_width:5 ~packing:vbox#add () in
2914 let font_size_label =
2915 GMisc.label ~text:"font size:"
2916 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2917 let font_size_spinb =
2919 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2922 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2923 let log_verbosity_label =
2924 GMisc.label ~text:"log verbosity:"
2925 ~packing:(table#attach ~left:0 ~top:1) () in
2926 let log_verbosity_spinb =
2928 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2931 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2933 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2935 GButton.button ~label:"Close"
2936 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2938 method show = settings_window#show
2940 button_set_anti_aliasing#misc#set_sensitive false ;
2941 button_set_transparency#misc#set_sensitive false ;
2942 (* Signals connection *)
2943 ignore(button_t1#connect#clicked
2944 (activate_t1 output button_set_anti_aliasing
2945 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2946 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2947 ignore(button_set_anti_aliasing#connect#toggled
2948 (set_anti_aliasing output button_set_anti_aliasing));
2949 ignore(button_set_transparency#connect#toggled
2950 (set_transparency output button_set_transparency)) ;
2951 ignore(log_verbosity_spinb#connect#changed
2952 (set_log_verbosity output log_verbosity_spinb)) ;
2953 ignore(closeb#connect#clicked settings_window#misc#hide)
2956 (* Scratch window *)
2958 class scratch_window =
2960 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2962 GPack.vbox ~packing:window#add () in
2964 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2966 GButton.button ~label:"Whd"
2967 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2969 GButton.button ~label:"Reduce"
2970 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2972 GButton.button ~label:"Simpl"
2973 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2974 let scrolled_window =
2975 GBin.scrolled_window ~border_width:10
2976 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2978 GMathViewAux.multi_selection_math_view
2979 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2981 method mmlwidget = mmlwidget
2982 method show () = window#misc#hide () ; window#show ()
2984 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2985 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2986 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2987 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2988 ignore(simplb#connect#clicked (simpl_in_scratch self))
2992 let vbox1 = GPack.vbox () in
2994 val mutable proofw_ref = None
2995 val mutable compute_ref = None
2997 Lazy.force self#compute ;
2998 match proofw_ref with
2999 None -> assert false
3000 | Some proofw -> proofw
3001 method content = vbox1
3003 match compute_ref with
3004 None -> assert false
3005 | Some compute -> compute
3009 let scrolled_window1 =
3010 GBin.scrolled_window ~border_width:10
3011 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
3013 GMathViewAux.multi_selection_math_view ~width:400 ~height:275
3014 ~packing:(scrolled_window1#add) () in
3015 let _ = proofw_ref <- Some proofw in
3017 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3019 GButton.button ~label:"Exact"
3020 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3022 GButton.button ~label:"Intros"
3023 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3025 GButton.button ~label:"Apply"
3026 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3027 let elimintrossimplb =
3028 GButton.button ~label:"ElimIntrosSimpl"
3029 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3031 GButton.button ~label:"ElimType"
3032 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3034 GButton.button ~label:"Whd"
3035 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3037 GButton.button ~label:"Reduce"
3038 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3040 GButton.button ~label:"Simpl"
3041 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3043 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3045 GButton.button ~label:"Fold_whd"
3046 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3048 GButton.button ~label:"Fold_reduce"
3049 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3051 GButton.button ~label:"Fold_simpl"
3052 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3054 GButton.button ~label:"Cut"
3055 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3057 GButton.button ~label:"Change"
3058 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3060 GButton.button ~label:"Let ... In"
3061 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3063 GButton.button ~label:"Ring"
3064 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3066 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3068 GButton.button ~label:"ClearBody"
3069 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3071 GButton.button ~label:"Clear"
3072 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3074 GButton.button ~label:"Fourier"
3075 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3077 GButton.button ~label:"RewriteSimpl ->"
3078 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3079 let rewritebacksimplb =
3080 GButton.button ~label:"RewriteSimpl <-"
3081 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3083 GButton.button ~label:"Replace"
3084 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3086 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3088 GButton.button ~label:"Reflexivity"
3089 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3091 GButton.button ~label:"Symmetry"
3092 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3094 GButton.button ~label:"Transitivity"
3095 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3097 GButton.button ~label:"Exists"
3098 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3100 GButton.button ~label:"Split"
3101 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3103 GButton.button ~label:"Left"
3104 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3106 GButton.button ~label:"Right"
3107 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3109 GButton.button ~label:"Assumption"
3110 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3112 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3114 GButton.button ~label:"Generalize"
3115 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3117 GButton.button ~label:"Absurd"
3118 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3119 let contradictionb =
3120 GButton.button ~label:"Contradiction"
3121 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3122 let searchpatternb =
3123 GButton.button ~label:"SearchPattern_Apply"
3124 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3126 GButton.button ~label:"Decompose"
3127 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3129 ignore(exactb#connect#clicked exact) ;
3130 ignore(applyb#connect#clicked apply) ;
3131 ignore(elimintrossimplb#connect#clicked elimintrossimpl) ;
3132 ignore(elimtypeb#connect#clicked elimtype) ;
3133 ignore(whdb#connect#clicked whd) ;
3134 ignore(reduceb#connect#clicked reduce) ;
3135 ignore(simplb#connect#clicked simpl) ;
3136 ignore(foldwhdb#connect#clicked fold_whd) ;
3137 ignore(foldreduceb#connect#clicked fold_reduce) ;
3138 ignore(foldsimplb#connect#clicked fold_simpl) ;
3139 ignore(cutb#connect#clicked cut) ;
3140 ignore(changeb#connect#clicked change) ;
3141 ignore(letinb#connect#clicked letin) ;
3142 ignore(ringb#connect#clicked ring) ;
3143 ignore(clearbodyb#connect#clicked clearbody) ;
3144 ignore(clearb#connect#clicked clear) ;
3145 ignore(fourierb#connect#clicked fourier) ;
3146 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
3147 ignore(rewritebacksimplb#connect#clicked rewritebacksimpl) ;
3148 ignore(replaceb#connect#clicked replace) ;
3149 ignore(reflexivityb#connect#clicked reflexivity) ;
3150 ignore(symmetryb#connect#clicked symmetry) ;
3151 ignore(transitivityb#connect#clicked transitivity) ;
3152 ignore(existsb#connect#clicked exists) ;
3153 ignore(splitb#connect#clicked split) ;
3154 ignore(leftb#connect#clicked left) ;
3155 ignore(rightb#connect#clicked right) ;
3156 ignore(assumptionb#connect#clicked assumption) ;
3157 ignore(generalizeb#connect#clicked generalize) ;
3158 ignore(absurdb#connect#clicked absurd) ;
3159 ignore(contradictionb#connect#clicked contradiction) ;
3160 ignore(introsb#connect#clicked intros) ;
3161 ignore(searchpatternb#connect#clicked searchPattern) ;
3162 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
3163 ignore(decomposeb#connect#clicked decompose) ;
3169 let vbox1 = GPack.vbox () in
3170 let scrolled_window1 =
3171 GBin.scrolled_window ~border_width:10
3172 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
3174 GMathViewAux.single_selection_math_view ~width:400 ~height:275
3175 ~packing:(scrolled_window1#add) () in
3177 method proofw = (assert false : GMathViewAux.single_selection_math_view)
3178 method content = vbox1
3179 method compute = (assert false : unit)
3183 let empty_page = new empty_page;;
3187 val notebook = GPack.notebook ()
3189 val mutable skip_switch_page_event = false
3190 val mutable empty = true
3191 method notebook = notebook
3193 let new_page = new page () in
3195 pages := !pages @ [n,lazy (setgoal n),new_page] ;
3196 notebook#append_page
3197 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
3198 new_page#content#coerce
3199 method remove_all_pages ~skip_switch_page_event:skip =
3201 notebook#remove_page 0 (* let's remove the empty page *)
3203 List.iter (function _ -> notebook#remove_page 0) !pages ;
3205 skip_switch_page_event <- skip
3206 method set_current_page ~may_skip_switch_page_event n =
3207 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
3208 let new_page = notebook#page_num page#content#coerce in
3209 if may_skip_switch_page_event && new_page <> notebook#current_page then
3210 skip_switch_page_event <- true ;
3211 notebook#goto_page new_page
3212 method set_empty_page =
3215 notebook#append_page
3216 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
3217 empty_page#content#coerce
3219 let (_,_,page) = List.nth !pages notebook#current_page in
3223 (notebook#connect#switch_page
3225 let skip = skip_switch_page_event in
3226 skip_switch_page_event <- false ;
3229 let (metano,setgoal,page) = List.nth !pages i in
3230 ProofEngine.goal := Some metano ;
3231 Lazy.force (page#compute) ;
3240 class rendering_window output (notebook : notebook) =
3241 let scratch_window = new scratch_window in
3243 GWindow.window ~title:"MathML viewer" ~border_width:0
3244 ~allow_shrink:false () in
3245 let vbox_for_menu = GPack.vbox ~packing:window#add () in
3247 let handle_box = GBin.handle_box ~border_width:2
3248 ~packing:(vbox_for_menu#pack ~padding:0) () in
3249 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
3250 let factory0 = new GMenu.factory menubar in
3251 let accel_group = factory0#accel_group in
3253 let file_menu = factory0#add_submenu "File" in
3254 let factory1 = new GMenu.factory file_menu ~accel_group in
3255 let export_to_postscript_menu_item =
3258 factory1#add_item "New Block of (Co)Inductive Definitions..."
3259 ~key:GdkKeysyms._B ~callback:new_inductive
3262 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
3265 let reopen_menu_item =
3266 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
3270 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
3271 ignore (factory1#add_separator ()) ;
3273 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
3275 let save_menu_item =
3276 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
3279 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
3280 ignore (!save_set_sensitive false);
3281 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
3282 ignore (!qed_set_sensitive false);
3283 ignore (factory1#add_separator ()) ;
3284 let export_to_postscript_menu_item =
3285 factory1#add_item "Export to PostScript..."
3286 ~callback:(export_to_postscript output) in
3287 ignore (factory1#add_separator ()) ;
3289 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
3290 export_to_postscript_menu_item
3293 let edit_menu = factory0#add_submenu "Edit Current Proof" in
3294 let factory2 = new GMenu.factory edit_menu ~accel_group in
3295 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
3296 let proveit_menu_item =
3297 factory2#add_item "Prove It" ~key:GdkKeysyms._I
3298 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
3300 let focus_menu_item =
3301 factory2#add_item "Focus" ~key:GdkKeysyms._F
3302 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
3305 focus_and_proveit_set_sensitive :=
3307 proveit_menu_item#misc#set_sensitive b ;
3308 focus_menu_item#misc#set_sensitive b
3310 let _ = !focus_and_proveit_set_sensitive false in
3311 (* edit term menu *)
3312 let edit_term_menu = factory0#add_submenu "Edit Term" in
3313 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
3314 let check_menu_item =
3315 factory5#add_item "Check Term" ~key:GdkKeysyms._C
3316 ~callback:(check scratch_window) in
3317 let _ = check_menu_item#misc#set_sensitive false in
3319 let settings_menu = factory0#add_submenu "Search" in
3320 let factory4 = new GMenu.factory settings_menu ~accel_group in
3322 factory4#add_item "Locate..." ~key:GdkKeysyms._T
3324 let searchPattern_menu_item =
3325 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
3326 ~callback:completeSearchPattern in
3327 let _ = searchPattern_menu_item#misc#set_sensitive false in
3328 let show_menu_item =
3329 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
3331 let insert_query_item =
3332 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._U
3333 ~callback:insertQuery in
3335 let settings_menu = factory0#add_submenu "Settings" in
3336 let factory3 = new GMenu.factory settings_menu ~accel_group in
3338 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
3339 ~callback:edit_aliases in
3340 let _ = factory3#add_separator () in
3342 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
3343 ~callback:(function _ -> (settings_window ())#show ()) in
3345 let _ = window#add_accel_group accel_group in
3349 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
3351 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3352 let scrolled_window0 =
3353 GBin.scrolled_window ~border_width:10
3354 ~packing:(vbox#pack ~expand:true ~padding:5) () in
3355 let _ = scrolled_window0#add output#coerce in
3357 GBin.frame ~label:"Insert Term"
3358 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
3359 let scrolled_window1 =
3360 GBin.scrolled_window ~border_width:5
3361 ~packing:frame#add () in
3363 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add ()
3364 ~isnotempty_callback:
3366 check_menu_item#misc#set_sensitive b ;
3367 searchPattern_menu_item#misc#set_sensitive b) in
3369 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3371 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
3373 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
3377 ~source:"<html><body bgColor=\"white\"></body></html>"
3378 ~width:400 ~height: 100
3383 method outputhtml = outputhtml
3384 method inputt = inputt
3385 method output = (output : GMathViewAux.single_selection_math_view)
3386 method notebook = notebook
3387 method show = window#show
3389 notebook#set_empty_page ;
3390 export_to_postscript_menu_item#misc#set_sensitive false ;
3391 check_term := (check_term_in_scratch scratch_window) ;
3393 (* signal handlers here *)
3394 ignore(output#connect#selection_changed
3396 choose_selection output elem ;
3397 !focus_and_proveit_set_sensitive true
3399 ignore (output#connect#click (show_in_show_window_callback output)) ;
3400 let settings_window = new settings_window output scrolled_window0
3401 export_to_postscript_menu_item (choose_selection output) in
3402 set_settings_window settings_window ;
3403 set_outputhtml outputhtml ;
3404 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
3405 Logger.log_callback :=
3406 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
3411 let initialize_everything () =
3412 let module U = Unix in
3413 let output = GMathViewAux.single_selection_math_view ~width:350 ~height:280 () in
3414 let notebook = new notebook in
3415 let rendering_window' = new rendering_window output notebook in
3416 set_rendering_window rendering_window' ;
3417 mml_of_cic_term_ref := mml_of_cic_term ;
3418 rendering_window'#show () ;
3425 Mqint.set_database Mqint.postgres_db ;
3426 Mqint.init postgresqlconnectionstring ;
3428 ignore (GtkMain.Main.init ()) ;
3429 initialize_everything () ;
3430 if !usedb then Mqint.close ();