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 (* CSC: quick fix: a function from [uri#xpointer(path)] to [uri#path] *)
38 let wrong_xpointer_format_from_wrong_xpointer_format' uri =
40 let index_sharp = String.index uri '#' in
41 let index_rest = index_sharp + 10 in
42 let baseuri = String.sub uri 0 index_sharp in
43 let rest = String.sub uri index_rest (String.length uri - index_rest - 1) in
48 (* GLOBAL CONSTANTS *)
50 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
51 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
55 " <body bgColor=\"white\">"
64 let prooffile = "/home/tassi/miohelm/tmp/currentproof";;
65 let prooffile = "/public/sacerdot/currentproof";;
68 let prooffile = "/public/sacerdot/currentproof";;
69 let prooffiletype = "/public/sacerdot/currentprooftype";;
71 (*CSC: the getter should handle the innertypes, not the FS *)
73 let innertypesfile = "/home/tassi/miohelm/tmp/innertypes";;
74 let innertypesfile = "/public/sacerdot/innertypes";;
77 let innertypesfile = "/public/sacerdot/innertypes";;
78 let constanttypefile = "/public/sacerdot/constanttype";;
80 let empty_id_to_uris = ([],function _ -> None);;
83 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
85 let htmlheader_and_content = ref htmlheader;;
87 let current_cic_infos = ref None;;
88 let current_goal_infos = ref None;;
89 let current_scratch_infos = ref None;;
91 let id_to_uris = ref empty_id_to_uris;;
93 let check_term = ref (fun _ _ _ -> assert false);;
94 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
96 exception RenderingWindowsNotInitialized;;
98 let set_rendering_window,rendering_window =
99 let rendering_window_ref = ref None in
100 (function rw -> rendering_window_ref := Some rw),
102 match !rendering_window_ref with
103 None -> raise RenderingWindowsNotInitialized
108 exception SettingsWindowsNotInitialized;;
110 let set_settings_window,settings_window =
111 let settings_window_ref = ref None in
112 (function rw -> settings_window_ref := Some rw),
114 match !settings_window_ref with
115 None -> raise SettingsWindowsNotInitialized
120 exception OutputHtmlNotInitialized;;
122 let set_outputhtml,outputhtml =
123 let outputhtml_ref = ref None in
124 (function rw -> outputhtml_ref := Some rw),
126 match !outputhtml_ref with
127 None -> raise OutputHtmlNotInitialized
128 | Some outputhtml -> outputhtml
132 exception QedSetSensitiveNotInitialized;;
133 let qed_set_sensitive =
134 ref (function _ -> raise QedSetSensitiveNotInitialized)
137 exception SaveSetSensitiveNotInitialized;;
138 let save_set_sensitive =
139 ref (function _ -> raise SaveSetSensitiveNotInitialized)
142 (* COMMAND LINE OPTIONS *)
148 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
151 Arg.parse argspec ignore ""
153 (* A WIDGET TO ENTER CIC TERMS *)
155 class term_editor ?packing ?width ?height ?changed_callback () =
156 let input = GEdit.text ~editable:true ?width ?height ?packing () in
158 match changed_callback with
161 ignore(input#connect#changed (function () -> callback (input#length > 0)))
164 method coerce = input#coerce
166 input#delete_text 0 input#length
167 (* CSC: txt is now a string, but should be of type Cic.term *)
168 method set_term txt =
170 ignore ((input#insert_text txt) ~pos:0)
171 (* CSC: this method should disappear *)
172 method get_as_string =
173 input#get_chars 0 input#length
174 method get_term ~context ~metasenv =
175 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
176 CicTextualParserContext.main ~context ~metasenv CicTextualLexer.token lexbuf
182 exception IllFormedUri of string;;
184 let cic_textual_parser_uri_of_string uri' =
187 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
188 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
190 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
191 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
195 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
196 CicTextualParser0.IndTyUri (uri'',typeno)
199 (* Constructor of an Inductive Type *)
200 let uri'',typeno,consno =
201 CicTextualLexer.indconuri_of_uri uri'
203 CicTextualParser0.IndConUri (uri'',typeno,consno)
206 _ -> raise (IllFormedUri uri')
209 let term_of_cic_textual_parser_uri uri =
210 let module C = Cic in
211 let module CTP = CicTextualParser0 in
213 CTP.ConUri uri -> C.Const (uri,[])
214 | CTP.VarUri uri -> C.Var (uri,[])
215 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
216 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
219 let string_of_cic_textual_parser_uri uri =
220 let module C = Cic in
221 let module CTP = CicTextualParser0 in
224 CTP.ConUri uri -> UriManager.string_of_uri uri
225 | CTP.VarUri uri -> UriManager.string_of_uri uri
226 | CTP.IndTyUri (uri,tyno) ->
227 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
228 | CTP.IndConUri (uri,tyno,consno) ->
229 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
232 (* 4 = String.length "cic:" *)
233 String.sub uri' 4 (String.length uri' - 4)
236 let output_html outputhtml msg =
237 htmlheader_and_content := !htmlheader_and_content ^ msg ;
238 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
239 outputhtml#set_topline (-1)
242 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
246 let check_window outputhtml uris =
249 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
251 GPack.notebook ~scrollable:true ~packing:window#add () in
256 let scrolled_window =
257 GBin.scrolled_window ~border_width:10
259 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
265 ~packing:scrolled_window#add ~width:400 ~height:280 () in
268 term_of_cic_textual_parser_uri (cic_textual_parser_uri_of_string uri)
270 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
273 let mml = !mml_of_cic_term_ref 111 expr in
274 prerr_endline ("### " ^ CicPp.ppterm expr) ;
275 mmlwidget#load_tree ~dom:mml
278 output_html outputhtml
279 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
284 (notebook#connect#switch_page
285 (function i -> Lazy.force (List.nth render_terms i)))
291 interactive_user_uri_choice ~selection_mode ?(ok="Ok") ~title ~msg uris
293 let choices = ref [] in
294 let chosen = ref false in
296 GWindow.dialog ~modal:true ~title ~width:600 () in
298 GMisc.label ~text:msg
299 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
300 let scrolled_window =
301 GBin.scrolled_window ~border_width:10
302 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
304 let expected_height = 18 * List.length uris in
305 let height = if expected_height > 400 then 400 else expected_height in
306 GList.clist ~columns:1 ~packing:scrolled_window#add
307 ~height ~selection_mode () in
308 let _ = List.map (function x -> clist#append [x]) uris in
310 GPack.hbox ~border_width:0
311 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
313 GMisc.label ~text:"None of the above. Try this one:"
314 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
316 GEdit.entry ~editable:true
317 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
319 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
321 GButton.button ~label:ok
322 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
323 let _ = okb#misc#set_sensitive false in
325 GButton.button ~label:"Check"
326 ~packing:(hbox#pack ~padding:5) () in
327 let _ = checkb#misc#set_sensitive false in
329 GButton.button ~label:"Abort"
330 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
332 let check_callback () =
333 assert (List.length !choices > 0) ;
334 check_window (outputhtml ()) !choices
336 ignore (window#connect#destroy GMain.Main.quit) ;
337 ignore (cancelb#connect#clicked window#destroy) ;
339 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
340 ignore (checkb#connect#clicked check_callback) ;
342 (clist#connect#select_row
343 (fun ~row ~column ~event ->
344 checkb#misc#set_sensitive true ;
345 okb#misc#set_sensitive true ;
346 choices := (List.nth uris row)::!choices)) ;
348 (clist#connect#unselect_row
349 (fun ~row ~column ~event ->
351 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
353 (manual_input#connect#changed
355 if manual_input#text = "" then
358 checkb#misc#set_sensitive false ;
359 okb#misc#set_sensitive false ;
360 clist#misc#set_sensitive true
364 choices := [manual_input#text] ;
365 clist#unselect_all () ;
366 checkb#misc#set_sensitive true ;
367 okb#misc#set_sensitive true ;
368 clist#misc#set_sensitive false
370 window#set_position `CENTER ;
373 if !chosen && List.length !choices > 0 then
379 let interactive_interpretation_choice interpretations =
380 let chosen = ref None in
383 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
384 let vbox = GPack.vbox ~packing:window#add () in
388 ("Ambiguous input since there are many well-typed interpretations." ^
389 " Please, choose one of them.")
390 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
392 GPack.notebook ~scrollable:true
393 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
396 (function interpretation ->
398 let expected_height = 18 * List.length interpretation in
399 let height = if expected_height > 400 then 400 else expected_height in
400 GList.clist ~columns:2 ~packing:notebook#append_page ~height
401 ~titles:["id" ; "URI"] ()
405 (function (id,uri) ->
406 let n = clist#append [id;uri] in
407 clist#set_row ~selectable:false n
410 clist#columns_autosize ()
413 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
415 GButton.button ~label:"Ok"
416 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
418 GButton.button ~label:"Abort"
419 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
421 ignore (window#connect#destroy GMain.Main.quit) ;
422 ignore (cancelb#connect#clicked window#destroy) ;
425 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
426 window#set_position `CENTER ;
430 None -> raise NoChoice
437 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
439 let query = ref "" in
440 MQueryGenerator.set_confirm_query
441 (function q -> query := MQueryUtil.text_of_query q ; true) ;
442 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
445 let domImpl = Gdome.domImplementation ();;
447 let parseStyle name =
449 domImpl#createDocumentFromURI
451 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
453 ~uri:("styles/" ^ name) ()
455 Gdome_xslt.processStylesheet style
458 let d_c = parseStyle "drop_coercions.xsl";;
459 let tc1 = parseStyle "objtheorycontent.xsl";;
460 let hc2 = parseStyle "content_to_html.xsl";;
461 let l = parseStyle "link.xsl";;
463 let c1 = parseStyle "rootcontent.xsl";;
464 let g = parseStyle "genmmlid.xsl";;
465 let c2 = parseStyle "annotatedpres.xsl";;
468 let getterURL = Configuration.getter_url;;
469 let processorURL = Configuration.processor_url;;
471 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
472 let mml_args ~explode_all =
473 ("explodeall",(if explode_all then "true()" else "false()"))::
474 ["processorURL", "'" ^ processorURL ^ "'" ;
475 "getterURL", "'" ^ getterURL ^ "'" ;
476 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
477 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
478 "UNICODEvsSYMBOL", "'symbol'" ;
479 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
480 "encoding", "'iso-8859-1'" ;
481 "media-type", "'text/html'" ;
482 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
483 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
484 "naturalLanguage", "'yes'" ;
485 "annotations", "'no'" ;
486 "URLs_or_URIs", "'URIs'" ;
487 "topurl", "'http://phd.cs.unibo.it/helm'" ;
488 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
491 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
493 ["processorURL", "'" ^ processorURL ^ "'" ;
494 "getterURL", "'" ^ getterURL ^ "'" ;
495 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
496 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
497 "UNICODEvsSYMBOL", "'symbol'" ;
498 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
499 "encoding", "'iso-8859-1'" ;
500 "media-type", "'text/html'" ;
501 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
502 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
503 "naturalLanguage", "'no'" ;
504 "annotations", "'no'" ;
505 "explodeall", "true()" ;
506 "URLs_or_URIs", "'URIs'" ;
507 "topurl", "'http://phd.cs.unibo.it/helm'" ;
508 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
511 let parse_file filename =
512 let inch = open_in filename in
513 let rec read_lines () =
515 let line = input_line inch in
523 let applyStylesheets input styles args =
524 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
529 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
531 (*CSC: ????????????????? *)
533 Cic2Xml.print_object uri ~ids_to_inner_sorts annobj
536 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts
541 None -> Xml2Gdome.document_of_xml domImpl xml
543 Xml.pp xml (Some constanttypefile) ;
544 Xml2Gdome.document_of_xml domImpl bodyxml'
546 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
547 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
549 Xml.pp xmlinnertypes (Some innertypesfile) ;
550 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
557 exception RefreshSequentException of exn;;
558 exception RefreshProofException of exn;;
560 let refresh_proof (output : GMathView.math_view) =
562 let uri,currentproof =
563 match !ProofEngine.proof with
565 | Some (uri,metasenv,bo,ty) ->
566 !qed_set_sensitive (List.length metasenv = 0) ;
567 (*CSC: Wrong: [] is just plainly wrong *)
568 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
571 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
572 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
574 Cic2acic.acic_object_of_cic_object currentproof
577 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
580 output#load_tree mml ;
582 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
585 match !ProofEngine.proof with
587 | Some (uri,metasenv,bo,ty) ->
588 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
589 raise (RefreshProofException e)
592 let refresh_sequent ?(empty_notebook=true) notebook =
594 match !ProofEngine.goal with
596 if empty_notebook then
598 notebook#remove_all_pages ~skip_switch_page_event:false ;
599 notebook#set_empty_page
602 notebook#proofw#unload
605 match !ProofEngine.proof with
607 | Some (_,metasenv,_,_) -> metasenv
609 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
610 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
611 SequentPp.XmlPp.print_sequent metasenv currentsequent
613 let regenerate_notebook () =
614 let skip_switch_page_event =
616 (m,_,_)::_ when m = metano -> false
619 notebook#remove_all_pages ~skip_switch_page_event ;
620 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
622 if empty_notebook then
624 regenerate_notebook () ;
625 notebook#set_current_page ~may_skip_switch_page_event:false metano
629 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
631 applyStylesheets sequent_doc sequent_styles sequent_args
633 notebook#set_current_page ~may_skip_switch_page_event:true metano;
634 notebook#proofw#load_tree ~dom:sequent_mml
636 current_goal_infos :=
637 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
641 match !ProofEngine.goal with
646 match !ProofEngine.proof with
648 | Some (_,metasenv,_,_) -> metasenv
651 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
652 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
653 raise (RefreshSequentException e)
654 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
658 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
659 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
662 let mml_of_cic_term metano term =
664 match !ProofEngine.proof with
666 | Some (_,metasenv,_,_) -> metasenv
669 match !ProofEngine.goal with
672 let (_,canonical_context,_) =
673 List.find (function (m,_,_) -> m=metano) metasenv
677 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
678 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
681 Xml2Gdome.document_of_xml domImpl sequent_gdome
684 applyStylesheets sequent_doc sequent_styles sequent_args ;
686 current_scratch_infos :=
687 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
691 exception OpenConjecturesStillThere;;
692 exception WrongProof;;
695 match !ProofEngine.proof with
697 | Some (uri,[],bo,ty) ->
699 CicReduction.are_convertible []
700 (CicTypeChecker.type_of_aux' [] [] bo) ty
703 (*CSC: Wrong: [] is just plainly wrong *)
704 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
706 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
707 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
709 Cic2acic.acic_object_of_cic_object proof
712 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
715 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
718 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
723 | _ -> raise OpenConjecturesStillThere
727 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
728 let dtdname = "/home/tassi/miohelm/helm/dtd/cic.dtd";;
730 let dtdname = "/projects/helm/V7_mowgli/dtd/cic.dtd";;
733 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
734 match !ProofEngine.proof with
736 | Some (uri, metasenv, bo, ty) ->
738 (*CSC: Wrong: [] is just plainly wrong *)
739 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
741 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
742 Cic2acic.acic_object_of_cic_object currentproof
745 match Cic2Xml.print_object uri ~ids_to_inner_sorts acurrentproof with
746 xml,Some bodyxml -> xml,bodyxml
747 | _,None -> assert false
749 Xml.pp ~quiet:true xml (Some prooffiletype) ;
750 output_html outputhtml
751 ("<h1 color=\"Green\">Current proof type saved to " ^
752 prooffiletype ^ "</h1>") ;
753 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
754 output_html outputhtml
755 ("<h1 color=\"Green\">Current proof body saved to " ^
759 (* Used to typecheck the loaded proofs *)
760 let typecheck_loaded_proof metasenv bo ty =
761 let module T = CicTypeChecker in
764 (fun metasenv ((_,context,ty) as conj) ->
765 ignore (T.type_of_aux' metasenv context ty) ;
768 ignore (T.type_of_aux' metasenv [] ty) ;
769 ignore (T.type_of_aux' metasenv [] bo)
773 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
774 let output = ((rendering_window ())#output : GMathView.math_view) in
775 let notebook = (rendering_window ())#notebook in
777 let uri = UriManager.uri_of_string "cic:/dummy.con" in
778 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
779 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
780 typecheck_loaded_proof metasenv bo ty ;
782 Some (uri, metasenv, bo, ty) ;
786 | (metano,_,_)::_ -> Some metano
788 refresh_proof output ;
789 refresh_sequent notebook ;
790 output_html outputhtml
791 ("<h1 color=\"Green\">Current proof type loaded from " ^
792 prooffiletype ^ "</h1>") ;
793 output_html outputhtml
794 ("<h1 color=\"Green\">Current proof body loaded from " ^
795 prooffile ^ "</h1>") ;
796 !save_set_sensitive true
799 RefreshSequentException e ->
800 output_html outputhtml
801 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
802 "sequent: " ^ Printexc.to_string e ^ "</h1>")
803 | RefreshProofException e ->
804 output_html outputhtml
805 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
806 "proof: " ^ Printexc.to_string e ^ "</h1>")
808 output_html outputhtml
809 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
812 let edit_aliases () =
813 let chosen = ref false in
816 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
818 GPack.vbox ~border_width:0 ~packing:window#add () in
819 let scrolled_window =
820 GBin.scrolled_window ~border_width:10
821 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
822 let input = GEdit.text ~editable:true ~width:400 ~height:100
823 ~packing:scrolled_window#add () in
825 GPack.hbox ~border_width:0
826 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
828 GButton.button ~label:"Ok"
829 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
831 GButton.button ~label:"Cancel"
832 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
833 ignore (window#connect#destroy GMain.Main.quit) ;
834 ignore (cancelb#connect#clicked window#destroy) ;
836 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
837 let dom,resolve_id = !id_to_uris in
839 (input#insert_text ~pos:0
844 match resolve_id v with
849 (string_of_cic_textual_parser_uri uri)
855 let inputtext = input#get_chars 0 input#length in
857 let alfa = "[a-zA-Z_-]" in
858 let digit = "[0-9]" in
859 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
860 let blanks = "\( \|\t\|\n\)+" in
861 let nonblanks = "[^ \t\n]+" in
862 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
864 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
868 let n' = Str.search_forward regexpr inputtext n in
869 let id = Str.matched_group 2 inputtext in
871 cic_textual_parser_uri_of_string
872 ("cic:" ^ (Str.matched_group 5 inputtext))
874 let dom,resolve_id = aux (n' + 1) in
875 if List.mem id dom then
879 (function id' -> if id = id' then Some uri else resolve_id id')
881 Not_found -> empty_id_to_uris
885 id_to_uris := dom,resolve_id
889 let module L = LogicalOperations in
890 let module G = Gdome in
891 let notebook = (rendering_window ())#notebook in
892 let output = (rendering_window ())#output in
893 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
894 match (rendering_window ())#output#get_selection with
897 ((node : Gdome.element)#getAttributeNS
899 ((element : G.element)#getAttributeNS
902 ~localName:(G.domString "xref"))#to_string
904 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
908 match !current_cic_infos with
909 Some (ids_to_terms, ids_to_father_ids, _, _) ->
911 L.to_sequent id ids_to_terms ids_to_father_ids ;
912 refresh_proof output ;
913 refresh_sequent notebook
914 | None -> assert false (* "ERROR: No current term!!!" *)
916 RefreshSequentException e ->
917 output_html outputhtml
918 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
919 "sequent: " ^ Printexc.to_string e ^ "</h1>")
920 | RefreshProofException e ->
921 output_html outputhtml
922 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
923 "proof: " ^ Printexc.to_string e ^ "</h1>")
925 output_html outputhtml
926 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
928 | None -> assert false (* "ERROR: No selection!!!" *)
932 let module L = LogicalOperations in
933 let module G = Gdome in
934 let notebook = (rendering_window ())#notebook in
935 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
936 match (rendering_window ())#output#get_selection with
939 ((node : Gdome.element)#getAttributeNS
941 ((element : G.element)#getAttributeNS
944 ~localName:(G.domString "xref"))#to_string
946 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
950 match !current_cic_infos with
951 Some (ids_to_terms, ids_to_father_ids, _, _) ->
953 L.focus id ids_to_terms ids_to_father_ids ;
954 refresh_sequent notebook
955 | None -> assert false (* "ERROR: No current term!!!" *)
957 RefreshSequentException e ->
958 output_html outputhtml
959 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
960 "sequent: " ^ Printexc.to_string e ^ "</h1>")
961 | RefreshProofException e ->
962 output_html outputhtml
963 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
964 "proof: " ^ Printexc.to_string e ^ "</h1>")
966 output_html outputhtml
967 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
969 | None -> assert false (* "ERROR: No selection!!!" *)
972 exception NoPrevGoal;;
973 exception NoNextGoal;;
976 let module L = LogicalOperations in
977 let module G = Gdome in
978 let notebook = (rendering_window ())#notebook in
979 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
981 match !ProofEngine.proof with
983 | Some (_,metasenv,_,_) -> metasenv
986 refresh_sequent ~empty_notebook:false notebook
988 RefreshSequentException e ->
989 output_html outputhtml
990 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
991 "sequent: " ^ Printexc.to_string e ^ "</h1>")
993 output_html outputhtml
994 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
997 let show_in_show_window, show_in_show_window_callback =
999 GWindow.window ~width:800 ~border_width:2 () in
1000 let scrolled_window =
1001 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1003 GMathView.math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1004 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1005 let href = Gdome.domString "href" in
1006 let show_in_show_window uri =
1007 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1009 CicTypeChecker.typecheck uri ;
1010 let obj = CicEnvironment.get_cooked_obj uri in
1012 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1013 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1015 Cic2acic.acic_object_of_cic_object obj
1018 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1021 window#set_title (UriManager.string_of_uri uri) ;
1022 window#misc#hide () ; window#show () ;
1023 mmlwidget#load_tree mml ;
1026 output_html outputhtml
1027 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1029 let show_in_show_window_callback mmlwidget (n : Gdome.element) =
1030 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1032 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1034 show_in_show_window (UriManager.uri_of_string uri)
1036 if mmlwidget#get_action <> None then
1037 mmlwidget#action_toggle
1040 mmlwidget#connect#clicked (show_in_show_window_callback mmlwidget)
1042 show_in_show_window, show_in_show_window_callback
1045 exception NoObjectsLocated;;
1047 let user_uri_choice ~title ~msg uris =
1050 [] -> raise NoObjectsLocated
1054 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1059 String.sub uri 4 (String.length uri - 4)
1062 let locate_callback id =
1063 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1064 let result = MQueryGenerator.locate id in
1067 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1070 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1072 output_html outputhtml html ;
1073 user_uri_choice ~title:"Ambiguous input."
1075 ("Ambiguous input \"" ^ id ^
1076 "\". Please, choose one interpetation:")
1081 let inputt = ((rendering_window ())#inputt : term_editor) in
1082 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1085 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1087 None -> raise NoChoice
1089 let uri = locate_callback input in
1093 output_html outputhtml
1094 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1097 let input_or_locate_uri ~title =
1098 let uri = ref None in
1101 ~width:400 ~modal:true ~title ~border_width:2 () in
1102 let vbox = GPack.vbox ~packing:window#add () in
1104 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1106 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1108 GEdit.entry ~editable:true
1109 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1111 GButton.button ~label:"Check"
1112 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1113 let _ = checkb#misc#set_sensitive false in
1115 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1117 GMisc.label ~text:"You can also enter an indentifier to locate:"
1118 ~packing:(hbox2#pack ~padding:5) () in
1120 GEdit.entry ~editable:true
1121 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1123 GButton.button ~label:"Locate"
1124 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1125 let _ = locateb#misc#set_sensitive false in
1127 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1129 GButton.button ~label:"Ok"
1130 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1131 let _ = okb#misc#set_sensitive false in
1133 GButton.button ~label:"Cancel"
1134 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1136 ignore (window#connect#destroy GMain.Main.quit) ;
1138 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1139 let check_callback () =
1140 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1141 let uri = "cic:" ^ manual_input#text in
1143 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1144 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1147 Getter.Unresolved ->
1148 output_html outputhtml
1149 ("<h1 color=\"Red\">URI " ^ uri ^
1150 " does not correspond to any object.</h1>") ;
1152 | UriManager.IllFormedUri _ ->
1153 output_html outputhtml
1154 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1157 output_html outputhtml
1158 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1162 (okb#connect#clicked
1164 if check_callback () then
1166 uri := Some manual_input#text ;
1170 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1172 (manual_input#connect#changed
1174 if manual_input#text = "" then
1176 checkb#misc#set_sensitive false ;
1177 okb#misc#set_sensitive false
1181 checkb#misc#set_sensitive true ;
1182 okb#misc#set_sensitive true
1185 (locate_input#connect#changed
1186 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1188 (locateb#connect#clicked
1190 let id = locate_input#text in
1191 manual_input#set_text (locate_callback id) ;
1192 locate_input#delete_text 0 (String.length id)
1195 GMain.Main.main () ;
1197 None -> raise NoChoice
1198 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1201 let locate_one_id id =
1202 let result = MQueryGenerator.locate id in
1206 wrong_xpointer_format_from_wrong_xpointer_format' uri
1208 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
1209 output_html (rendering_window ())#outputhtml html ;
1213 [UriManager.string_of_uri
1214 (input_or_locate_uri ~title:("URI matching \"" ^ id ^ "\" unknown."))]
1217 interactive_user_uri_choice
1218 ~selection_mode:`EXTENDED
1219 ~ok:"Try every selection."
1220 ~title:"Ambiguous input."
1222 ("Ambiguous input \"" ^ id ^
1223 "\". Please, choose one or more interpretations:")
1226 List.map cic_textual_parser_uri_of_string uris'
1229 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
1230 exception AmbiguousInput;;
1232 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
1233 let known_ids,resolve_id = !id_to_uris in
1239 if List.mem he known_ids then filter tl else he::(filter tl)
1243 (* for each id in dom' we get the list of uris associated to it *)
1244 let list_of_uris = List.map locate_one_id dom' in
1245 (* and now we compute the list of all possible assignments from id to uris *)
1247 let rec aux ids list_of_uris =
1248 match ids,list_of_uris with
1249 [],[] -> [resolve_id]
1250 | id::idtl,uris::uristl ->
1251 let resolves = aux idtl uristl in
1257 function id' -> if id = id' then Some uri else f id'
1261 | _,_ -> assert false
1263 aux dom' list_of_uris
1265 let tests_no = List.length resolve_ids in
1266 if tests_no > 1 then
1267 output_html (outputhtml ())
1268 ("<h1>Disambiguation phase started: " ^
1269 string_of_int (List.length resolve_ids) ^ " cases will be tried.") ;
1270 (* now we select only the ones that generates well-typed terms *)
1276 let metasenv',expr = mk_metasenv_and_expr resolve in
1278 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
1280 (CicTypeChecker.type_of_aux' metasenv context expr) ;
1281 resolve::(filter tl)
1288 match resolve_ids' with
1289 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
1290 | [resolve_id] -> resolve_id
1294 (function resolve ->
1298 match resolve id with
1299 None -> assert false
1302 CicTextualParser0.ConUri uri
1303 | CicTextualParser0.VarUri uri ->
1304 UriManager.string_of_uri uri
1305 | CicTextualParser0.IndTyUri (uri,tyno) ->
1306 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1307 string_of_int (tyno+1) ^ ")"
1308 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
1309 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1310 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
1314 let index = interactive_interpretation_choice choices in
1315 List.nth resolve_ids' index
1317 id_to_uris := known_ids @ dom', resolve_id' ;
1318 mk_metasenv_and_expr resolve_id'
1321 exception UriAlreadyInUse;;
1322 exception NotAUriToAConstant;;
1325 let inputt = ((rendering_window ())#inputt : term_editor) in
1326 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1327 let output = ((rendering_window ())#output : GMathView.math_view) in
1328 let notebook = (rendering_window ())#notebook in
1330 let chosen = ref false in
1331 let get_parsed = ref (function _ -> assert false) in
1332 let get_uri = ref (function _ -> assert false) in
1333 let non_empty_type = ref false in
1336 ~width:600 ~modal:true ~title:"New Proof or Definition" ~border_width:2 () in
1337 let vbox = GPack.vbox ~packing:window#add () in
1339 GPack.hbox ~border_width:0
1340 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1342 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1343 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1345 GEdit.entry ~editable:true
1346 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1348 GPack.hbox ~border_width:0
1349 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1351 GMisc.label ~text:"Enter the theorem or definition type:"
1352 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1353 let scrolled_window =
1354 GBin.scrolled_window ~border_width:5
1355 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1356 (* the content of the scrolled_window is moved below (see comment) *)
1358 GPack.hbox ~border_width:0
1359 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1361 GButton.button ~label:"Ok"
1362 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1363 let _ = okb#misc#set_sensitive false in
1365 GButton.button ~label:"Cancel"
1366 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1367 (* moved here to have visibility of the ok button *)
1369 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1372 non_empty_type := b ;
1373 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1376 newinputt#set_term inputt#get_as_string ;
1379 uri_entry#connect#changed
1381 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1383 ignore (window#connect#destroy GMain.Main.quit) ;
1384 ignore (cancelb#connect#clicked window#destroy) ;
1386 (okb#connect#clicked
1390 let parsed = newinputt#get_term [] [] in
1391 let uristr = "cic:" ^ uri_entry#text in
1392 let uri = UriManager.uri_of_string uristr in
1393 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1394 raise NotAUriToAConstant
1398 ignore (Getter.resolve uri) ;
1399 raise UriAlreadyInUse
1401 Getter.Unresolved ->
1402 get_parsed := (function () -> parsed) ;
1403 get_uri := (function () -> uri) ;
1408 output_html outputhtml
1409 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1412 GMain.Main.main () ;
1415 let dom,mk_metasenv_and_expr = !get_parsed () in
1417 disambiguate_input [] [] dom mk_metasenv_and_expr
1419 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1420 ProofEngine.proof :=
1421 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1422 ProofEngine.goal := Some 1 ;
1423 refresh_sequent notebook ;
1424 refresh_proof output ;
1425 !save_set_sensitive true ;
1428 RefreshSequentException e ->
1429 output_html outputhtml
1430 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1431 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1432 | RefreshProofException e ->
1433 output_html outputhtml
1434 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1435 "proof: " ^ Printexc.to_string e ^ "</h1>")
1437 output_html outputhtml
1438 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1441 let check_term_in_scratch scratch_window metasenv context expr =
1443 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1444 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1445 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1446 scratch_window#show () ;
1447 scratch_window#mmlwidget#load_tree ~dom:mml
1450 print_endline ("? " ^ CicPp.ppterm expr) ;
1454 let check scratch_window () =
1455 let inputt = ((rendering_window ())#inputt : term_editor) in
1456 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1458 match !ProofEngine.proof with
1460 | Some (_,metasenv,_,_) -> metasenv
1462 let context,names_context =
1464 match !ProofEngine.goal with
1467 let (_,canonical_context,_) =
1468 List.find (function (m,_,_) -> m=metano) metasenv
1475 Some (n,_) -> Some n
1480 let dom,mk_metasenv_and_expr = inputt#get_term names_context metasenv in
1481 let (metasenv',expr) =
1482 disambiguate_input context metasenv dom mk_metasenv_and_expr
1484 check_term_in_scratch scratch_window metasenv' context expr
1487 output_html outputhtml
1488 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1492 (***********************)
1494 (***********************)
1496 let call_tactic tactic () =
1497 let notebook = (rendering_window ())#notebook in
1498 let output = ((rendering_window ())#output : GMathView.math_view) in
1499 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1500 let savedproof = !ProofEngine.proof in
1501 let savedgoal = !ProofEngine.goal in
1505 refresh_sequent notebook ;
1506 refresh_proof output
1508 RefreshSequentException e ->
1509 output_html outputhtml
1510 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1511 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1512 ProofEngine.proof := savedproof ;
1513 ProofEngine.goal := savedgoal ;
1514 refresh_sequent notebook
1515 | RefreshProofException e ->
1516 output_html outputhtml
1517 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1518 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1519 ProofEngine.proof := savedproof ;
1520 ProofEngine.goal := savedgoal ;
1521 refresh_sequent notebook ;
1522 refresh_proof output
1524 output_html outputhtml
1525 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1526 ProofEngine.proof := savedproof ;
1527 ProofEngine.goal := savedgoal ;
1531 let call_tactic_with_input tactic () =
1532 let notebook = (rendering_window ())#notebook in
1533 let output = ((rendering_window ())#output : GMathView.math_view) in
1534 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1535 let inputt = ((rendering_window ())#inputt : term_editor) in
1536 let savedproof = !ProofEngine.proof in
1537 let savedgoal = !ProofEngine.goal in
1538 let uri,metasenv,bo,ty =
1539 match !ProofEngine.proof with
1540 None -> assert false
1541 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1543 let canonical_context =
1544 match !ProofEngine.goal with
1545 None -> assert false
1547 let (_,canonical_context,_) =
1548 List.find (function (m,_,_) -> m=metano) metasenv
1555 Some (n,_) -> Some n
1560 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv in
1561 let (metasenv',expr) =
1562 disambiguate_input canonical_context metasenv dom mk_metasenv_and_expr
1564 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1566 refresh_sequent notebook ;
1567 refresh_proof output ;
1570 RefreshSequentException e ->
1571 output_html outputhtml
1572 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1573 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1574 ProofEngine.proof := savedproof ;
1575 ProofEngine.goal := savedgoal ;
1576 refresh_sequent notebook
1577 | RefreshProofException e ->
1578 output_html outputhtml
1579 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1580 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1581 ProofEngine.proof := savedproof ;
1582 ProofEngine.goal := savedgoal ;
1583 refresh_sequent notebook ;
1584 refresh_proof output
1586 output_html outputhtml
1587 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1588 ProofEngine.proof := savedproof ;
1589 ProofEngine.goal := savedgoal ;
1592 let call_tactic_with_goal_input tactic () =
1593 let module L = LogicalOperations in
1594 let module G = Gdome in
1595 let notebook = (rendering_window ())#notebook in
1596 let output = ((rendering_window ())#output : GMathView.math_view) in
1597 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1598 let savedproof = !ProofEngine.proof in
1599 let savedgoal = !ProofEngine.goal in
1600 match notebook#proofw#get_selection with
1603 ((node : Gdome.element)#getAttributeNS
1604 ~namespaceURI:helmns
1605 ~localName:(G.domString "xref"))#to_string
1607 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1611 match !current_goal_infos with
1612 Some (ids_to_terms, ids_to_father_ids,_) ->
1614 tactic (Hashtbl.find ids_to_terms id) ;
1615 refresh_sequent notebook ;
1616 refresh_proof output
1617 | None -> assert false (* "ERROR: No current term!!!" *)
1619 RefreshSequentException e ->
1620 output_html outputhtml
1621 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1622 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1623 ProofEngine.proof := savedproof ;
1624 ProofEngine.goal := savedgoal ;
1625 refresh_sequent notebook
1626 | RefreshProofException e ->
1627 output_html outputhtml
1628 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1629 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1630 ProofEngine.proof := savedproof ;
1631 ProofEngine.goal := savedgoal ;
1632 refresh_sequent notebook ;
1633 refresh_proof output
1635 output_html outputhtml
1636 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1637 ProofEngine.proof := savedproof ;
1638 ProofEngine.goal := savedgoal ;
1641 output_html outputhtml
1642 ("<h1 color=\"red\">No term selected</h1>")
1645 let call_tactic_with_input_and_goal_input tactic () =
1646 let module L = LogicalOperations in
1647 let module G = Gdome in
1648 let notebook = (rendering_window ())#notebook in
1649 let output = ((rendering_window ())#output : GMathView.math_view) in
1650 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1651 let inputt = ((rendering_window ())#inputt : term_editor) in
1652 let savedproof = !ProofEngine.proof in
1653 let savedgoal = !ProofEngine.goal in
1654 match notebook#proofw#get_selection with
1657 ((node : Gdome.element)#getAttributeNS
1658 ~namespaceURI:helmns
1659 ~localName:(G.domString "xref"))#to_string
1661 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1665 match !current_goal_infos with
1666 Some (ids_to_terms, ids_to_father_ids,_) ->
1668 let uri,metasenv,bo,ty =
1669 match !ProofEngine.proof with
1670 None -> assert false
1671 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1673 let canonical_context =
1674 match !ProofEngine.goal with
1675 None -> assert false
1677 let (_,canonical_context,_) =
1678 List.find (function (m,_,_) -> m=metano) metasenv
1680 canonical_context in
1684 Some (n,_) -> Some n
1688 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv
1690 let (metasenv',expr) =
1691 disambiguate_input canonical_context metasenv dom
1692 mk_metasenv_and_expr
1694 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1695 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
1697 refresh_sequent notebook ;
1698 refresh_proof output ;
1700 | None -> assert false (* "ERROR: No current term!!!" *)
1702 RefreshSequentException e ->
1703 output_html outputhtml
1704 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1705 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1706 ProofEngine.proof := savedproof ;
1707 ProofEngine.goal := savedgoal ;
1708 refresh_sequent notebook
1709 | RefreshProofException e ->
1710 output_html outputhtml
1711 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1712 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1713 ProofEngine.proof := savedproof ;
1714 ProofEngine.goal := savedgoal ;
1715 refresh_sequent notebook ;
1716 refresh_proof output
1718 output_html outputhtml
1719 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1720 ProofEngine.proof := savedproof ;
1721 ProofEngine.goal := savedgoal ;
1724 output_html outputhtml
1725 ("<h1 color=\"red\">No term selected</h1>")
1728 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
1729 let module L = LogicalOperations in
1730 let module G = Gdome in
1731 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
1732 let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
1733 let savedproof = !ProofEngine.proof in
1734 let savedgoal = !ProofEngine.goal in
1735 match mmlwidget#get_selection with
1738 ((node : Gdome.element)#getAttributeNS
1739 ~namespaceURI:helmns
1740 ~localName:(G.domString "xref"))#to_string
1742 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1746 match !current_scratch_infos with
1747 (* term is the whole goal in the scratch_area *)
1748 Some (term,ids_to_terms, ids_to_father_ids,_) ->
1750 let expr = tactic term (Hashtbl.find ids_to_terms id) in
1751 let mml = mml_of_cic_term 111 expr in
1752 scratch_window#show () ;
1753 scratch_window#mmlwidget#load_tree ~dom:mml
1754 | None -> assert false (* "ERROR: No current term!!!" *)
1757 output_html outputhtml
1758 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1761 output_html outputhtml
1762 ("<h1 color=\"red\">No term selected</h1>")
1765 let call_tactic_with_hypothesis_input tactic () =
1766 let module L = LogicalOperations in
1767 let module G = Gdome in
1768 let notebook = (rendering_window ())#notebook in
1769 let output = ((rendering_window ())#output : GMathView.math_view) in
1770 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1771 let savedproof = !ProofEngine.proof in
1772 let savedgoal = !ProofEngine.goal in
1773 match notebook#proofw#get_selection with
1776 ((node : Gdome.element)#getAttributeNS
1777 ~namespaceURI:helmns
1778 ~localName:(G.domString "xref"))#to_string
1780 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1784 match !current_goal_infos with
1785 Some (_,_,ids_to_hypotheses) ->
1787 tactic (Hashtbl.find ids_to_hypotheses id) ;
1788 refresh_sequent notebook ;
1789 refresh_proof output
1790 | None -> assert false (* "ERROR: No current term!!!" *)
1792 RefreshSequentException e ->
1793 output_html outputhtml
1794 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1795 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1796 ProofEngine.proof := savedproof ;
1797 ProofEngine.goal := savedgoal ;
1798 refresh_sequent notebook
1799 | RefreshProofException e ->
1800 output_html outputhtml
1801 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1802 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1803 ProofEngine.proof := savedproof ;
1804 ProofEngine.goal := savedgoal ;
1805 refresh_sequent notebook ;
1806 refresh_proof output
1808 output_html outputhtml
1809 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1810 ProofEngine.proof := savedproof ;
1811 ProofEngine.goal := savedgoal ;
1814 output_html outputhtml
1815 ("<h1 color=\"red\">No term selected</h1>")
1819 let intros = call_tactic ProofEngine.intros;;
1820 let exact = call_tactic_with_input ProofEngine.exact;;
1821 let apply = call_tactic_with_input ProofEngine.apply;;
1822 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
1823 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
1824 let whd = call_tactic_with_goal_input ProofEngine.whd;;
1825 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
1826 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
1827 let fold = call_tactic_with_input ProofEngine.fold;;
1828 let cut = call_tactic_with_input ProofEngine.cut;;
1829 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
1830 let letin = call_tactic_with_input ProofEngine.letin;;
1831 let ring = call_tactic ProofEngine.ring;;
1832 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
1833 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
1834 let fourier = call_tactic ProofEngine.fourier;;
1835 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
1836 let reflexivity = call_tactic ProofEngine.reflexivity;;
1837 let symmetry = call_tactic ProofEngine.symmetry;;
1838 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
1839 let left = call_tactic ProofEngine.left;;
1840 let right = call_tactic ProofEngine.right;;
1841 let assumption = call_tactic ProofEngine.assumption;;
1843 let whd_in_scratch scratch_window =
1844 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
1847 let reduce_in_scratch scratch_window =
1848 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1851 let simpl_in_scratch scratch_window =
1852 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1858 (**********************)
1859 (* END OF TACTICS *)
1860 (**********************)
1864 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1866 show_in_show_window (input_or_locate_uri ~title:"Show")
1869 output_html outputhtml
1870 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1873 exception NotADefinition;;
1876 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1877 let output = ((rendering_window ())#output : GMathView.math_view) in
1878 let notebook = (rendering_window ())#notebook in
1880 let uri = input_or_locate_uri ~title:"Open" in
1881 CicTypeChecker.typecheck uri ;
1882 let metasenv,bo,ty =
1883 match CicEnvironment.get_cooked_obj uri with
1884 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1885 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1888 | Cic.InductiveDefinition _ -> raise NotADefinition
1890 ProofEngine.proof :=
1891 Some (uri, metasenv, bo, ty) ;
1892 ProofEngine.goal := None ;
1893 refresh_sequent notebook ;
1894 refresh_proof output
1896 RefreshSequentException e ->
1897 output_html outputhtml
1898 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1899 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1900 | RefreshProofException e ->
1901 output_html outputhtml
1902 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1903 "proof: " ^ Printexc.to_string e ^ "</h1>")
1905 output_html outputhtml
1906 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1910 let searchPattern () =
1911 let inputt = ((rendering_window ())#inputt : term_editor) in
1912 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1914 let rec get_level ?(last_invalid=false) () =
1916 GToolbox.input_string
1917 ~title:"Insert the strictness parameter for the query:"
1918 ((if last_invalid then
1919 "Invalid input (must be a non-negative natural number). Insert again "
1922 ) ^ "the strictness parameter for the query:")
1924 None -> raise NoChoice
1929 _ -> get_level ~last_invalid:true ()
1931 let level = get_level () in
1933 match !ProofEngine.proof with
1934 None -> assert false
1935 | Some (_,metasenv,_,_) -> metasenv
1937 match !ProofEngine.goal with
1940 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
1941 let result = MQueryGenerator.searchPattern metasenv ey ty level in
1945 wrong_xpointer_format_from_wrong_xpointer_format' uri
1948 " <h1>Backward Query: </h1>" ^
1949 " <h2>Levels: </h2> " ^
1950 MQueryGenerator.string_of_levels
1951 (MQueryGenerator.levels_of_term metasenv ey ty) "<br>" ^
1952 " <pre>" ^ get_last_query result ^ "</pre>"
1954 output_html outputhtml html ;
1956 let rec filter_out =
1960 let tl',exc = filter_out tl in
1963 ProofEngine.can_apply
1964 (term_of_cic_textual_parser_uri
1965 (cic_textual_parser_uri_of_string uri))
1973 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
1974 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
1981 " <h1>Objects that can actually be applied: </h1> " ^
1982 String.concat "<br>" uris' ^ exc ^
1983 " <h1>Number of false matches: " ^
1984 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
1985 " <h1>Number of good matches: " ^
1986 string_of_int (List.length uris') ^ "</h1>"
1988 output_html outputhtml html' ;
1990 user_uri_choice ~title:"Ambiguous input."
1992 "Many lemmas can be successfully applied. Please, choose one:"
1995 inputt#set_term uri' ;
1999 output_html outputhtml
2000 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2003 let choose_selection
2004 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
2006 let module G = Gdome in
2007 let rec aux element =
2008 if element#hasAttributeNS
2009 ~namespaceURI:helmns
2010 ~localName:(G.domString "xref")
2012 mmlwidget#set_selection (Some element)
2014 match element#get_parentNode with
2015 None -> assert false
2016 (*CSC: OCAML DIVERGES!
2017 | Some p -> aux (new G.element_of_node p)
2019 | Some p -> aux (new Gdome.element_of_node p)
2023 | None -> mmlwidget#set_selection None
2026 (* STUFF TO BUILD THE GTK INTERFACE *)
2028 (* Stuff for the widget settings *)
2030 let export_to_postscript (output : GMathView.math_view) =
2031 let lastdir = ref (Unix.getcwd ()) in
2034 GToolbox.select_file ~title:"Export to PostScript"
2035 ~dir:lastdir ~filename:"screenshot.ps" ()
2039 output#export_to_postscript ~filename:filename ();
2042 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
2043 button_set_kerning button_set_transparency export_to_postscript_menu_item
2046 let is_set = button_t1#active in
2047 output#set_font_manager_type
2048 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2051 button_set_anti_aliasing#misc#set_sensitive true ;
2052 button_set_kerning#misc#set_sensitive true ;
2053 button_set_transparency#misc#set_sensitive true ;
2054 export_to_postscript_menu_item#misc#set_sensitive true ;
2058 button_set_anti_aliasing#misc#set_sensitive false ;
2059 button_set_kerning#misc#set_sensitive false ;
2060 button_set_transparency#misc#set_sensitive false ;
2061 export_to_postscript_menu_item#misc#set_sensitive false ;
2065 let set_anti_aliasing output button_set_anti_aliasing () =
2066 output#set_anti_aliasing button_set_anti_aliasing#active
2069 let set_kerning output button_set_kerning () =
2070 output#set_kerning button_set_kerning#active
2073 let set_transparency output button_set_transparency () =
2074 output#set_transparency button_set_transparency#active
2077 let changefont output font_size_spinb () =
2078 output#set_font_size font_size_spinb#value_as_int
2081 let set_log_verbosity output log_verbosity_spinb () =
2082 output#set_log_verbosity log_verbosity_spinb#value_as_int
2085 class settings_window (output : GMathView.math_view) sw
2086 export_to_postscript_menu_item selection_changed_callback
2088 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2090 GPack.vbox ~packing:settings_window#add () in
2093 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2094 ~border_width:5 ~packing:vbox#add () in
2096 GButton.toggle_button ~label:"activate t1 fonts"
2097 ~packing:(table#attach ~left:0 ~top:0) () in
2098 let button_set_anti_aliasing =
2099 GButton.toggle_button ~label:"set_anti_aliasing"
2100 ~packing:(table#attach ~left:0 ~top:1) () in
2101 let button_set_kerning =
2102 GButton.toggle_button ~label:"set_kerning"
2103 ~packing:(table#attach ~left:1 ~top:1) () in
2104 let button_set_transparency =
2105 GButton.toggle_button ~label:"set_transparency"
2106 ~packing:(table#attach ~left:2 ~top:1) () in
2109 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2110 ~border_width:5 ~packing:vbox#add () in
2111 let font_size_label =
2112 GMisc.label ~text:"font size:"
2113 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2114 let font_size_spinb =
2116 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2119 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2120 let log_verbosity_label =
2121 GMisc.label ~text:"log verbosity:"
2122 ~packing:(table#attach ~left:0 ~top:1) () in
2123 let log_verbosity_spinb =
2125 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2128 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2130 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2132 GButton.button ~label:"Close"
2133 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2135 method show = settings_window#show
2137 button_set_anti_aliasing#misc#set_sensitive false ;
2138 button_set_kerning#misc#set_sensitive false ;
2139 button_set_transparency#misc#set_sensitive false ;
2140 (* Signals connection *)
2141 ignore(button_t1#connect#clicked
2142 (activate_t1 output button_set_anti_aliasing button_set_kerning
2143 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2144 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2145 ignore(button_set_anti_aliasing#connect#toggled
2146 (set_anti_aliasing output button_set_anti_aliasing));
2147 ignore(button_set_kerning#connect#toggled
2148 (set_kerning output button_set_kerning)) ;
2149 ignore(button_set_transparency#connect#toggled
2150 (set_transparency output button_set_transparency)) ;
2151 ignore(log_verbosity_spinb#connect#changed
2152 (set_log_verbosity output log_verbosity_spinb)) ;
2153 ignore(closeb#connect#clicked settings_window#misc#hide)
2156 (* Scratch window *)
2158 class scratch_window outputhtml =
2160 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2162 GPack.vbox ~packing:window#add () in
2164 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2166 GButton.button ~label:"Whd"
2167 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2169 GButton.button ~label:"Reduce"
2170 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2172 GButton.button ~label:"Simpl"
2173 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2174 let scrolled_window =
2175 GBin.scrolled_window ~border_width:10
2176 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2179 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2181 method outputhtml = outputhtml
2182 method mmlwidget = mmlwidget
2183 method show () = window#misc#hide () ; window#show ()
2185 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2186 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2187 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2188 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2189 ignore(simplb#connect#clicked (simpl_in_scratch self))
2193 let vbox1 = GPack.vbox () in
2195 val mutable proofw_ref = None
2196 val mutable compute_ref = None
2198 Lazy.force self#compute ;
2199 match proofw_ref with
2200 None -> assert false
2201 | Some proofw -> proofw
2202 method content = vbox1
2204 match compute_ref with
2205 None -> assert false
2206 | Some compute -> compute
2210 let scrolled_window1 =
2211 GBin.scrolled_window ~border_width:10
2212 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2214 GMathView.math_view ~width:400 ~height:275
2215 ~packing:(scrolled_window1#add) () in
2216 let _ = proofw_ref <- Some proofw in
2218 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2220 GButton.button ~label:"Exact"
2221 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2223 GButton.button ~label:"Intros"
2224 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2226 GButton.button ~label:"Apply"
2227 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2228 let elimsimplintrosb =
2229 GButton.button ~label:"ElimSimplIntros"
2230 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2232 GButton.button ~label:"ElimType"
2233 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2235 GButton.button ~label:"Whd"
2236 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2238 GButton.button ~label:"Reduce"
2239 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2241 GButton.button ~label:"Simpl"
2242 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2244 GButton.button ~label:"Fold"
2245 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2247 GButton.button ~label:"Cut"
2248 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2250 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2252 GButton.button ~label:"Change"
2253 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2255 GButton.button ~label:"Let ... In"
2256 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2258 GButton.button ~label:"Ring"
2259 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2261 GButton.button ~label:"ClearBody"
2262 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2264 GButton.button ~label:"Clear"
2265 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2267 GButton.button ~label:"Fourier"
2268 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2270 GButton.button ~label:"RewriteSimpl ->"
2271 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2273 GButton.button ~label:"Reflexivity"
2274 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2276 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2278 GButton.button ~label:"Symmetry"
2279 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2281 GButton.button ~label:"Transitivity"
2282 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2284 GButton.button ~label:"Left"
2285 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2287 GButton.button ~label:"Right"
2288 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2290 GButton.button ~label:"Assumption"
2291 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2292 let searchpatternb =
2293 GButton.button ~label:"SearchPattern_Apply"
2294 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2295 ignore(exactb#connect#clicked exact) ;
2296 ignore(applyb#connect#clicked apply) ;
2297 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
2298 ignore(elimtypeb#connect#clicked elimtype) ;
2299 ignore(whdb#connect#clicked whd) ;
2300 ignore(reduceb#connect#clicked reduce) ;
2301 ignore(simplb#connect#clicked simpl) ;
2302 ignore(foldb#connect#clicked fold) ;
2303 ignore(cutb#connect#clicked cut) ;
2304 ignore(changeb#connect#clicked change) ;
2305 ignore(letinb#connect#clicked letin) ;
2306 ignore(ringb#connect#clicked ring) ;
2307 ignore(clearbodyb#connect#clicked clearbody) ;
2308 ignore(clearb#connect#clicked clear) ;
2309 ignore(fourierb#connect#clicked fourier) ;
2310 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
2311 ignore(reflexivityb#connect#clicked reflexivity) ;
2312 ignore(symmetryb#connect#clicked symmetry) ;
2313 ignore(transitivityb#connect#clicked transitivity) ;
2314 ignore(leftb#connect#clicked left) ;
2315 ignore(rightb#connect#clicked right) ;
2316 ignore(assumptionb#connect#clicked assumption) ;
2317 ignore(introsb#connect#clicked intros) ;
2318 ignore(searchpatternb#connect#clicked searchPattern) ;
2319 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2325 let vbox1 = GPack.vbox () in
2326 let scrolled_window1 =
2327 GBin.scrolled_window ~border_width:10
2328 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2330 GMathView.math_view ~width:400 ~height:275
2331 ~packing:(scrolled_window1#add) () in
2333 method proofw = (assert false : GMathView.math_view)
2334 method content = vbox1
2335 method compute = (assert false : unit)
2339 let empty_page = new empty_page;;
2343 val notebook = GPack.notebook ()
2345 val mutable skip_switch_page_event = false
2346 val mutable empty = true
2347 method notebook = notebook
2349 let new_page = new page () in
2351 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2352 notebook#append_page
2353 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2354 new_page#content#coerce
2355 method remove_all_pages ~skip_switch_page_event:skip =
2357 notebook#remove_page 0 (* let's remove the empty page *)
2359 List.iter (function _ -> notebook#remove_page 0) !pages ;
2361 skip_switch_page_event <- skip
2362 method set_current_page ~may_skip_switch_page_event n =
2363 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2364 let new_page = notebook#page_num page#content#coerce in
2365 if may_skip_switch_page_event && new_page <> notebook#current_page then
2366 skip_switch_page_event <- true ;
2367 notebook#goto_page new_page
2368 method set_empty_page =
2371 notebook#append_page
2372 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2373 empty_page#content#coerce
2375 let (_,_,page) = List.nth !pages notebook#current_page in
2379 (notebook#connect#switch_page
2381 let skip = skip_switch_page_event in
2382 skip_switch_page_event <- false ;
2385 let (metano,setgoal,page) = List.nth !pages i in
2386 ProofEngine.goal := Some metano ;
2387 Lazy.force (page#compute) ;
2396 class rendering_window output (notebook : notebook) =
2398 GWindow.window ~title:"MathML viewer" ~border_width:2
2399 ~allow_shrink:false () in
2400 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2402 let menubar = GMenu.menu_bar ~packing:vbox_for_menu#pack () in
2403 let factory0 = new GMenu.factory menubar in
2404 let accel_group = factory0#accel_group in
2406 let file_menu = factory0#add_submenu "File" in
2407 let factory1 = new GMenu.factory file_menu ~accel_group in
2408 let export_to_postscript_menu_item =
2411 factory1#add_item "New Proof or Definition" ~key:GdkKeysyms._N
2414 let reopen_menu_item =
2415 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2419 factory1#add_item "Qed" ~key:GdkKeysyms._Q ~callback:qed in
2420 ignore (factory1#add_separator ()) ;
2422 (factory1#add_item "Load Unfinished Proof" ~key:GdkKeysyms._L
2424 let save_menu_item =
2425 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
2428 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2429 ignore (!save_set_sensitive false);
2430 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2431 ignore (!qed_set_sensitive false);
2432 ignore (factory1#add_separator ()) ;
2433 let export_to_postscript_menu_item =
2434 factory1#add_item "Export to PostScript..." ~key:GdkKeysyms._E
2435 ~callback:(export_to_postscript output) in
2436 ignore (factory1#add_separator ()) ;
2438 (factory1#add_item "Exit" ~key:GdkKeysyms._C ~callback:GMain.Main.quit) ;
2439 export_to_postscript_menu_item
2442 let edit_menu = factory0#add_submenu "Edit current proof" in
2443 let factory2 = new GMenu.factory edit_menu ~accel_group in
2444 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2445 let proveit_menu_item =
2446 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2447 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2449 let focus_menu_item =
2450 factory2#add_item "Focus" ~key:GdkKeysyms._F
2451 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2454 focus_and_proveit_set_sensitive :=
2456 proveit_menu_item#misc#set_sensitive b ;
2457 focus_menu_item#misc#set_sensitive b
2459 let _ = !focus_and_proveit_set_sensitive false in
2461 let settings_menu = factory0#add_submenu "Search" in
2462 let factory4 = new GMenu.factory settings_menu ~accel_group in
2464 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2466 let show_menu_item =
2467 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2470 let settings_menu = factory0#add_submenu "Settings" in
2471 let factory3 = new GMenu.factory settings_menu ~accel_group in
2473 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2474 ~callback:edit_aliases in
2475 let _ = factory3#add_separator () in
2477 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2478 ~callback:(function _ -> (settings_window ())#show ()) in
2480 let _ = window#add_accel_group accel_group in
2484 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2486 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2487 let scrolled_window0 =
2488 GBin.scrolled_window ~border_width:10
2489 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2490 let _ = scrolled_window0#add output#coerce in
2492 GBin.frame ~label:"Term input"
2493 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2495 GPack.vbox ~packing:frame#add () in
2497 GPack.hbox ~border_width:5 ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2499 GButton.button ~label:"Check"
2500 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2501 let scrolled_window1 =
2502 GBin.scrolled_window ~border_width:5
2503 ~packing:(vbox'#pack ~expand:true ~padding:0) () in
2505 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add () in
2507 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2509 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2511 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2515 ~source:"<html><body bgColor=\"white\"></body></html>"
2516 ~width:400 ~height: 100
2520 let scratch_window = new scratch_window outputhtml in
2522 method outputhtml = outputhtml
2523 method inputt = inputt
2524 method output = (output : GMathView.math_view)
2525 method notebook = notebook
2526 method show = window#show
2528 notebook#set_empty_page ;
2529 export_to_postscript_menu_item#misc#set_sensitive false ;
2530 check_term := (check_term_in_scratch scratch_window) ;
2532 (* signal handlers here *)
2533 ignore(output#connect#selection_changed
2535 choose_selection output elem ;
2536 !focus_and_proveit_set_sensitive true
2538 ignore (output#connect#clicked (show_in_show_window_callback output)) ;
2539 let settings_window = new settings_window output scrolled_window0
2540 export_to_postscript_menu_item (choose_selection output) in
2541 set_settings_window settings_window ;
2542 set_outputhtml outputhtml ;
2543 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2544 ignore(checkb#connect#clicked (check scratch_window)) ;
2545 Logger.log_callback :=
2546 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2551 let initialize_everything () =
2552 let module U = Unix in
2553 let output = GMathView.math_view ~width:350 ~height:280 () in
2554 let notebook = new notebook in
2555 let rendering_window' = new rendering_window output notebook in
2556 set_rendering_window rendering_window' ;
2557 mml_of_cic_term_ref := mml_of_cic_term ;
2558 rendering_window'#show () ;
2564 Mqint.init "dbname=helm_mowgli" ;
2565 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
2566 ignore (GtkMain.Main.init ()) ;
2567 initialize_everything () ;
2568 if !usedb then Mqint.close ();