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 prooffiletype = "/home/tassi/miohelm/tmp/currentprooftype";;
68 let prooffile = "/public/sacerdot/currentproof";;
69 let prooffiletype = "/public/sacerdot/currentprooftype";;
71 (*CSC: the getter should handle the innertypes, not the FS *)
74 let innertypesfile = "/home/tassi/miohelm/tmp/innertypes";;
75 let constanttypefile = "/home/tassi/miohelm/tmp/constanttype";;
78 let innertypesfile = "/public/sacerdot/innertypes";;
79 let constanttypefile = "/public/sacerdot/constanttype";;
81 let empty_id_to_uris = ([],function _ -> None);;
84 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
86 let htmlheader_and_content = ref htmlheader;;
88 let current_cic_infos = ref None;;
89 let current_goal_infos = ref None;;
90 let current_scratch_infos = ref None;;
92 let id_to_uris = ref empty_id_to_uris;;
94 let check_term = ref (fun _ _ _ -> assert false);;
95 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
97 exception RenderingWindowsNotInitialized;;
99 let set_rendering_window,rendering_window =
100 let rendering_window_ref = ref None in
101 (function rw -> rendering_window_ref := Some rw),
103 match !rendering_window_ref with
104 None -> raise RenderingWindowsNotInitialized
109 exception SettingsWindowsNotInitialized;;
111 let set_settings_window,settings_window =
112 let settings_window_ref = ref None in
113 (function rw -> settings_window_ref := Some rw),
115 match !settings_window_ref with
116 None -> raise SettingsWindowsNotInitialized
121 exception OutputHtmlNotInitialized;;
123 let set_outputhtml,outputhtml =
124 let outputhtml_ref = ref None in
125 (function rw -> outputhtml_ref := Some rw),
127 match !outputhtml_ref with
128 None -> raise OutputHtmlNotInitialized
129 | Some outputhtml -> outputhtml
133 exception QedSetSensitiveNotInitialized;;
134 let qed_set_sensitive =
135 ref (function _ -> raise QedSetSensitiveNotInitialized)
138 exception SaveSetSensitiveNotInitialized;;
139 let save_set_sensitive =
140 ref (function _ -> raise SaveSetSensitiveNotInitialized)
143 (* COMMAND LINE OPTIONS *)
149 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
152 Arg.parse argspec ignore ""
154 (* A WIDGET TO ENTER CIC TERMS *)
156 class term_editor ?packing ?width ?height ?isnotempty_callback () =
157 let input = GEdit.text ~editable:true ?width ?height ?packing () in
159 match isnotempty_callback with
162 ignore(input#connect#changed (function () -> callback (input#length > 0)))
165 method coerce = input#coerce
167 input#delete_text 0 input#length
168 (* CSC: txt is now a string, but should be of type Cic.term *)
169 method set_term txt =
171 ignore ((input#insert_text txt) ~pos:0)
172 (* CSC: this method should disappear *)
173 method get_as_string =
174 input#get_chars 0 input#length
175 method get_term ~context ~metasenv =
176 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
177 CicTextualParserContext.main ~context ~metasenv CicTextualLexer.token lexbuf
183 exception IllFormedUri of string;;
185 let cic_textual_parser_uri_of_string uri' =
188 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
189 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
191 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
192 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
196 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
197 CicTextualParser0.IndTyUri (uri'',typeno)
200 (* Constructor of an Inductive Type *)
201 let uri'',typeno,consno =
202 CicTextualLexer.indconuri_of_uri uri'
204 CicTextualParser0.IndConUri (uri'',typeno,consno)
207 _ -> raise (IllFormedUri uri')
210 let term_of_cic_textual_parser_uri uri =
211 let module C = Cic in
212 let module CTP = CicTextualParser0 in
214 CTP.ConUri uri -> C.Const (uri,[])
215 | CTP.VarUri uri -> C.Var (uri,[])
216 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
217 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
220 let string_of_cic_textual_parser_uri uri =
221 let module C = Cic in
222 let module CTP = CicTextualParser0 in
225 CTP.ConUri uri -> UriManager.string_of_uri uri
226 | CTP.VarUri uri -> UriManager.string_of_uri uri
227 | CTP.IndTyUri (uri,tyno) ->
228 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
229 | CTP.IndConUri (uri,tyno,consno) ->
230 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
233 (* 4 = String.length "cic:" *)
234 String.sub uri' 4 (String.length uri' - 4)
237 let output_html outputhtml msg =
238 htmlheader_and_content := !htmlheader_and_content ^ msg ;
239 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
240 outputhtml#set_topline (-1)
243 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
247 let check_window outputhtml uris =
250 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
252 GPack.notebook ~scrollable:true ~packing:window#add () in
257 let scrolled_window =
258 GBin.scrolled_window ~border_width:10
260 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
266 ~packing:scrolled_window#add ~width:400 ~height:280 () in
269 term_of_cic_textual_parser_uri (cic_textual_parser_uri_of_string uri)
271 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
274 let mml = !mml_of_cic_term_ref 111 expr in
275 prerr_endline ("### " ^ CicPp.ppterm expr) ;
276 mmlwidget#load_tree ~dom:mml
279 output_html outputhtml
280 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
285 (notebook#connect#switch_page
286 (function i -> Lazy.force (List.nth render_terms i)))
292 interactive_user_uri_choice ~selection_mode ?(ok="Ok") ~title ~msg uris
294 let choices = ref [] in
295 let chosen = ref false in
297 GWindow.dialog ~modal:true ~title ~width:600 () in
299 GMisc.label ~text:msg
300 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
301 let scrolled_window =
302 GBin.scrolled_window ~border_width:10
303 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
305 let expected_height = 18 * List.length uris in
306 let height = if expected_height > 400 then 400 else expected_height in
307 GList.clist ~columns:1 ~packing:scrolled_window#add
308 ~height ~selection_mode () in
309 let _ = List.map (function x -> clist#append [x]) uris in
311 GPack.hbox ~border_width:0
312 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
314 GMisc.label ~text:"None of the above. Try this one:"
315 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
317 GEdit.entry ~editable:true
318 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
320 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
322 GButton.button ~label:ok
323 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
324 let _ = okb#misc#set_sensitive false in
326 GButton.button ~label:"Check"
327 ~packing:(hbox#pack ~padding:5) () in
328 let _ = checkb#misc#set_sensitive false in
330 GButton.button ~label:"Abort"
331 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
333 let check_callback () =
334 assert (List.length !choices > 0) ;
335 check_window (outputhtml ()) !choices
337 ignore (window#connect#destroy GMain.Main.quit) ;
338 ignore (cancelb#connect#clicked window#destroy) ;
340 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
341 ignore (checkb#connect#clicked check_callback) ;
343 (clist#connect#select_row
344 (fun ~row ~column ~event ->
345 checkb#misc#set_sensitive true ;
346 okb#misc#set_sensitive true ;
347 choices := (List.nth uris row)::!choices)) ;
349 (clist#connect#unselect_row
350 (fun ~row ~column ~event ->
352 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
354 (manual_input#connect#changed
356 if manual_input#text = "" then
359 checkb#misc#set_sensitive false ;
360 okb#misc#set_sensitive false ;
361 clist#misc#set_sensitive true
365 choices := [manual_input#text] ;
366 clist#unselect_all () ;
367 checkb#misc#set_sensitive true ;
368 okb#misc#set_sensitive true ;
369 clist#misc#set_sensitive false
371 window#set_position `CENTER ;
374 if !chosen && List.length !choices > 0 then
380 let interactive_interpretation_choice interpretations =
381 let chosen = ref None in
384 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
385 let vbox = GPack.vbox ~packing:window#add () in
389 ("Ambiguous input since there are many well-typed interpretations." ^
390 " Please, choose one of them.")
391 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
393 GPack.notebook ~scrollable:true
394 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
397 (function interpretation ->
399 let expected_height = 18 * List.length interpretation in
400 let height = if expected_height > 400 then 400 else expected_height in
401 GList.clist ~columns:2 ~packing:notebook#append_page ~height
402 ~titles:["id" ; "URI"] ()
406 (function (id,uri) ->
407 let n = clist#append [id;uri] in
408 clist#set_row ~selectable:false n
411 clist#columns_autosize ()
414 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
416 GButton.button ~label:"Ok"
417 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
419 GButton.button ~label:"Abort"
420 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
422 ignore (window#connect#destroy GMain.Main.quit) ;
423 ignore (cancelb#connect#clicked window#destroy) ;
426 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
427 window#set_position `CENTER ;
431 None -> raise NoChoice
438 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
440 let query = ref "" in
441 MQueryGenerator.set_confirm_query
442 (function q -> query := MQueryUtil.text_of_query q ; true) ;
443 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
446 let domImpl = Gdome.domImplementation ();;
448 let parseStyle name =
450 domImpl#createDocumentFromURI
452 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
454 ~uri:("styles/" ^ name) ()
456 Gdome_xslt.processStylesheet style
459 let d_c = parseStyle "drop_coercions.xsl";;
460 let tc1 = parseStyle "objtheorycontent.xsl";;
461 let hc2 = parseStyle "content_to_html.xsl";;
462 let l = parseStyle "link.xsl";;
464 let c1 = parseStyle "rootcontent.xsl";;
465 let g = parseStyle "genmmlid.xsl";;
466 let c2 = parseStyle "annotatedpres.xsl";;
469 let getterURL = Configuration.getter_url;;
470 let processorURL = Configuration.processor_url;;
472 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
473 let mml_args ~explode_all =
474 ("explodeall",(if explode_all then "true()" else "false()"))::
475 ["processorURL", "'" ^ processorURL ^ "'" ;
476 "getterURL", "'" ^ getterURL ^ "'" ;
477 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
478 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
479 "UNICODEvsSYMBOL", "'symbol'" ;
480 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
481 "encoding", "'iso-8859-1'" ;
482 "media-type", "'text/html'" ;
483 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
484 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
485 "naturalLanguage", "'yes'" ;
486 "annotations", "'no'" ;
487 "URLs_or_URIs", "'URIs'" ;
488 "topurl", "'http://phd.cs.unibo.it/helm'" ;
489 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
492 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
494 ["processorURL", "'" ^ processorURL ^ "'" ;
495 "getterURL", "'" ^ getterURL ^ "'" ;
496 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
497 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
498 "UNICODEvsSYMBOL", "'symbol'" ;
499 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
500 "encoding", "'iso-8859-1'" ;
501 "media-type", "'text/html'" ;
502 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
503 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
504 "naturalLanguage", "'no'" ;
505 "annotations", "'no'" ;
506 "explodeall", "true()" ;
507 "URLs_or_URIs", "'URIs'" ;
508 "topurl", "'http://phd.cs.unibo.it/helm'" ;
509 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
512 let parse_file filename =
513 let inch = open_in filename in
514 let rec read_lines () =
516 let line = input_line inch in
524 let applyStylesheets input styles args =
525 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
530 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
532 (*CSC: ????????????????? *)
534 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true
538 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
539 ~ask_dtd_to_the_getter:true
543 None -> Xml2Gdome.document_of_xml domImpl xml
545 Xml.pp xml (Some constanttypefile) ;
546 Xml2Gdome.document_of_xml domImpl bodyxml'
548 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
549 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
551 Xml.pp xmlinnertypes (Some innertypesfile) ;
552 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
557 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
560 let struri = UriManager.string_of_uri uri in
561 let idx = (String.rindex struri '/') + 1 in
562 String.sub struri idx (String.length struri - idx)
564 let path = pathname ^ "/" ^ name in
566 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
570 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
571 ~ask_dtd_to_the_getter:false
574 let innertypesuri = UriManager.innertypesuri_of_uri uri in
575 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
576 Getter.register innertypesuri
577 (Configuration.annotations_url ^
578 Str.replace_first (Str.regexp "^cic:") ""
579 (UriManager.string_of_uri innertypesuri) ^ ".xml"
581 (* constant type / variable / mutual inductive types definition *)
582 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
584 (Configuration.annotations_url ^
585 Str.replace_first (Str.regexp "^cic:") ""
586 (UriManager.string_of_uri uri) ^ ".xml"
593 match UriManager.bodyuri_of_uri uri with
595 | Some bodyuri -> bodyuri
597 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
598 Getter.register bodyuri
599 (Configuration.annotations_url ^
600 Str.replace_first (Str.regexp "^cic:") ""
601 (UriManager.string_of_uri bodyuri) ^ ".xml"
608 exception RefreshSequentException of exn;;
609 exception RefreshProofException of exn;;
611 let refresh_proof (output : GMathView.math_view) =
613 let uri,currentproof =
614 match !ProofEngine.proof with
616 | Some (uri,metasenv,bo,ty) ->
617 !qed_set_sensitive (List.length metasenv = 0) ;
618 (*CSC: Wrong: [] is just plainly wrong *)
619 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
622 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
623 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
625 Cic2acic.acic_object_of_cic_object currentproof
628 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
631 output#load_tree mml ;
633 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
636 match !ProofEngine.proof with
638 | Some (uri,metasenv,bo,ty) ->
639 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
640 raise (RefreshProofException e)
643 let refresh_sequent ?(empty_notebook=true) notebook =
645 match !ProofEngine.goal with
647 if empty_notebook then
649 notebook#remove_all_pages ~skip_switch_page_event:false ;
650 notebook#set_empty_page
653 notebook#proofw#unload
656 match !ProofEngine.proof with
658 | Some (_,metasenv,_,_) -> metasenv
660 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
661 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
662 SequentPp.XmlPp.print_sequent metasenv currentsequent
664 let regenerate_notebook () =
665 let skip_switch_page_event =
667 (m,_,_)::_ when m = metano -> false
670 notebook#remove_all_pages ~skip_switch_page_event ;
671 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
673 if empty_notebook then
675 regenerate_notebook () ;
676 notebook#set_current_page ~may_skip_switch_page_event:false metano
680 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
682 applyStylesheets sequent_doc sequent_styles sequent_args
684 notebook#set_current_page ~may_skip_switch_page_event:true metano;
685 notebook#proofw#load_tree ~dom:sequent_mml
687 current_goal_infos :=
688 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
692 match !ProofEngine.goal with
697 match !ProofEngine.proof with
699 | Some (_,metasenv,_,_) -> metasenv
702 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
703 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
704 raise (RefreshSequentException e)
705 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
709 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
710 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
713 let mml_of_cic_term metano term =
715 match !ProofEngine.proof with
717 | Some (_,metasenv,_,_) -> metasenv
720 match !ProofEngine.goal with
723 let (_,canonical_context,_) =
724 List.find (function (m,_,_) -> m=metano) metasenv
728 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
729 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
732 Xml2Gdome.document_of_xml domImpl sequent_gdome
735 applyStylesheets sequent_doc sequent_styles sequent_args ;
737 current_scratch_infos :=
738 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
742 exception OpenConjecturesStillThere;;
743 exception WrongProof;;
745 let pathname_of_annuri uristring =
746 Configuration.annotations_dir ^
747 Str.replace_first (Str.regexp "^cic:") "" uristring
750 let make_dirs dirpath =
751 ignore (Unix.system ("mkdir -p " ^ dirpath))
755 match !ProofEngine.proof with
757 | Some (uri,[],bo,ty) ->
759 CicReduction.are_convertible []
760 (CicTypeChecker.type_of_aux' [] [] bo) ty
763 (*CSC: Wrong: [] is just plainly wrong *)
764 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
766 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
767 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
769 Cic2acic.acic_object_of_cic_object proof
772 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
775 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
776 !qed_set_sensitive false ;
777 (* let's save the theorem and register it to the getter *)
778 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
780 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
784 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
789 | _ -> raise OpenConjecturesStillThere
793 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
794 match !ProofEngine.proof with
796 | Some (uri, metasenv, bo, ty) ->
798 (*CSC: Wrong: [] is just plainly wrong *)
799 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
801 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
802 Cic2acic.acic_object_of_cic_object currentproof
806 Cic2Xml.print_object uri ~ids_to_inner_sorts
807 ~ask_dtd_to_the_getter:true acurrentproof
809 xml,Some bodyxml -> xml,bodyxml
810 | _,None -> assert false
812 Xml.pp ~quiet:true xml (Some prooffiletype) ;
813 output_html outputhtml
814 ("<h1 color=\"Green\">Current proof type saved to " ^
815 prooffiletype ^ "</h1>") ;
816 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
817 output_html outputhtml
818 ("<h1 color=\"Green\">Current proof body saved to " ^
822 (* Used to typecheck the loaded proofs *)
823 let typecheck_loaded_proof metasenv bo ty =
824 let module T = CicTypeChecker in
827 (fun metasenv ((_,context,ty) as conj) ->
828 ignore (T.type_of_aux' metasenv context ty) ;
831 ignore (T.type_of_aux' metasenv [] ty) ;
832 ignore (T.type_of_aux' metasenv [] bo)
836 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
837 let output = ((rendering_window ())#output : GMathView.math_view) in
838 let notebook = (rendering_window ())#notebook in
841 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
844 None -> raise NoChoice
846 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
847 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
848 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
849 typecheck_loaded_proof metasenv bo ty ;
851 Some (uri, metasenv, bo, ty) ;
855 | (metano,_,_)::_ -> Some metano
857 refresh_proof output ;
858 refresh_sequent notebook ;
859 output_html outputhtml
860 ("<h1 color=\"Green\">Current proof type loaded from " ^
861 prooffiletype ^ "</h1>") ;
862 output_html outputhtml
863 ("<h1 color=\"Green\">Current proof body loaded from " ^
864 prooffile ^ "</h1>") ;
865 !save_set_sensitive true
868 RefreshSequentException e ->
869 output_html outputhtml
870 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
871 "sequent: " ^ Printexc.to_string e ^ "</h1>")
872 | RefreshProofException e ->
873 output_html outputhtml
874 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
875 "proof: " ^ Printexc.to_string e ^ "</h1>")
877 output_html outputhtml
878 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
881 let edit_aliases () =
882 let chosen = ref false in
885 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
887 GPack.vbox ~border_width:0 ~packing:window#add () in
888 let scrolled_window =
889 GBin.scrolled_window ~border_width:10
890 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
891 let input = GEdit.text ~editable:true ~width:400 ~height:100
892 ~packing:scrolled_window#add () in
894 GPack.hbox ~border_width:0
895 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
897 GButton.button ~label:"Ok"
898 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
900 GButton.button ~label:"Cancel"
901 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
902 ignore (window#connect#destroy GMain.Main.quit) ;
903 ignore (cancelb#connect#clicked window#destroy) ;
905 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
906 let dom,resolve_id = !id_to_uris in
908 (input#insert_text ~pos:0
913 match resolve_id v with
918 (string_of_cic_textual_parser_uri uri)
924 let inputtext = input#get_chars 0 input#length in
926 let alfa = "[a-zA-Z_-]" in
927 let digit = "[0-9]" in
928 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
929 let blanks = "\( \|\t\|\n\)+" in
930 let nonblanks = "[^ \t\n]+" in
931 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
933 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
937 let n' = Str.search_forward regexpr inputtext n in
938 let id = Str.matched_group 2 inputtext in
940 cic_textual_parser_uri_of_string
941 ("cic:" ^ (Str.matched_group 5 inputtext))
943 let dom,resolve_id = aux (n' + 1) in
944 if List.mem id dom then
948 (function id' -> if id = id' then Some uri else resolve_id id')
950 Not_found -> empty_id_to_uris
954 id_to_uris := dom,resolve_id
958 let module L = LogicalOperations in
959 let module G = Gdome in
960 let notebook = (rendering_window ())#notebook in
961 let output = (rendering_window ())#output in
962 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
963 match (rendering_window ())#output#get_selection with
966 ((node : Gdome.element)#getAttributeNS
968 ((element : G.element)#getAttributeNS
971 ~localName:(G.domString "xref"))#to_string
973 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
977 match !current_cic_infos with
978 Some (ids_to_terms, ids_to_father_ids, _, _) ->
980 L.to_sequent id ids_to_terms ids_to_father_ids ;
981 refresh_proof output ;
982 refresh_sequent notebook
983 | None -> assert false (* "ERROR: No current term!!!" *)
985 RefreshSequentException e ->
986 output_html outputhtml
987 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
988 "sequent: " ^ Printexc.to_string e ^ "</h1>")
989 | RefreshProofException e ->
990 output_html outputhtml
991 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
992 "proof: " ^ Printexc.to_string e ^ "</h1>")
994 output_html outputhtml
995 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
997 | None -> assert false (* "ERROR: No selection!!!" *)
1001 let module L = LogicalOperations in
1002 let module G = Gdome in
1003 let notebook = (rendering_window ())#notebook in
1004 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1005 match (rendering_window ())#output#get_selection with
1008 ((node : Gdome.element)#getAttributeNS
1009 (*CSC: OCAML DIVERGE
1010 ((element : G.element)#getAttributeNS
1012 ~namespaceURI:helmns
1013 ~localName:(G.domString "xref"))#to_string
1015 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1019 match !current_cic_infos with
1020 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1022 L.focus id ids_to_terms ids_to_father_ids ;
1023 refresh_sequent notebook
1024 | None -> assert false (* "ERROR: No current term!!!" *)
1026 RefreshSequentException e ->
1027 output_html outputhtml
1028 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1029 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1030 | RefreshProofException e ->
1031 output_html outputhtml
1032 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1033 "proof: " ^ Printexc.to_string e ^ "</h1>")
1035 output_html outputhtml
1036 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1038 | None -> assert false (* "ERROR: No selection!!!" *)
1041 exception NoPrevGoal;;
1042 exception NoNextGoal;;
1044 let setgoal metano =
1045 let module L = LogicalOperations in
1046 let module G = Gdome in
1047 let notebook = (rendering_window ())#notebook in
1048 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1050 match !ProofEngine.proof with
1051 None -> assert false
1052 | Some (_,metasenv,_,_) -> metasenv
1055 refresh_sequent ~empty_notebook:false notebook
1057 RefreshSequentException e ->
1058 output_html outputhtml
1059 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1060 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1062 output_html outputhtml
1063 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1066 let show_in_show_window, show_in_show_window_callback =
1068 GWindow.window ~width:800 ~border_width:2 () in
1069 let scrolled_window =
1070 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1072 GMathView.math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1073 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1074 let href = Gdome.domString "href" in
1075 let show_in_show_window uri =
1076 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1078 CicTypeChecker.typecheck uri ;
1079 let obj = CicEnvironment.get_cooked_obj uri in
1081 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1082 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1084 Cic2acic.acic_object_of_cic_object obj
1087 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1090 window#set_title (UriManager.string_of_uri uri) ;
1091 window#misc#hide () ; window#show () ;
1092 mmlwidget#load_tree mml ;
1095 output_html outputhtml
1096 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1098 let show_in_show_window_callback mmlwidget (n : Gdome.element) =
1099 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1101 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1103 show_in_show_window (UriManager.uri_of_string uri)
1105 if mmlwidget#get_action <> None then
1106 mmlwidget#action_toggle
1109 mmlwidget#connect#clicked (show_in_show_window_callback mmlwidget)
1111 show_in_show_window, show_in_show_window_callback
1114 exception NoObjectsLocated;;
1116 let user_uri_choice ~title ~msg uris =
1119 [] -> raise NoObjectsLocated
1123 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1128 String.sub uri 4 (String.length uri - 4)
1131 let locate_callback id =
1132 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1133 let result = MQueryGenerator.locate id in
1136 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1139 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1141 output_html outputhtml html ;
1142 user_uri_choice ~title:"Ambiguous input."
1144 ("Ambiguous input \"" ^ id ^
1145 "\". Please, choose one interpetation:")
1150 let inputt = ((rendering_window ())#inputt : term_editor) in
1151 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1154 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1156 None -> raise NoChoice
1158 let uri = locate_callback input in
1162 output_html outputhtml
1163 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1166 let input_or_locate_uri ~title =
1167 let uri = ref None in
1170 ~width:400 ~modal:true ~title ~border_width:2 () in
1171 let vbox = GPack.vbox ~packing:window#add () in
1173 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1175 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1177 GEdit.entry ~editable:true
1178 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1180 GButton.button ~label:"Check"
1181 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1182 let _ = checkb#misc#set_sensitive false in
1184 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1186 GMisc.label ~text:"You can also enter an indentifier to locate:"
1187 ~packing:(hbox2#pack ~padding:5) () in
1189 GEdit.entry ~editable:true
1190 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1192 GButton.button ~label:"Locate"
1193 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1194 let _ = locateb#misc#set_sensitive false in
1196 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1198 GButton.button ~label:"Ok"
1199 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1200 let _ = okb#misc#set_sensitive false in
1202 GButton.button ~label:"Cancel"
1203 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1205 ignore (window#connect#destroy GMain.Main.quit) ;
1207 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1208 let check_callback () =
1209 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1210 let uri = "cic:" ^ manual_input#text in
1212 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1213 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1216 Getter.Unresolved ->
1217 output_html outputhtml
1218 ("<h1 color=\"Red\">URI " ^ uri ^
1219 " does not correspond to any object.</h1>") ;
1221 | UriManager.IllFormedUri _ ->
1222 output_html outputhtml
1223 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1226 output_html outputhtml
1227 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1231 (okb#connect#clicked
1233 if check_callback () then
1235 uri := Some manual_input#text ;
1239 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1241 (manual_input#connect#changed
1243 if manual_input#text = "" then
1245 checkb#misc#set_sensitive false ;
1246 okb#misc#set_sensitive false
1250 checkb#misc#set_sensitive true ;
1251 okb#misc#set_sensitive true
1254 (locate_input#connect#changed
1255 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1257 (locateb#connect#clicked
1259 let id = locate_input#text in
1260 manual_input#set_text (locate_callback id) ;
1261 locate_input#delete_text 0 (String.length id)
1264 GMain.Main.main () ;
1266 None -> raise NoChoice
1267 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1270 let locate_one_id id =
1271 let result = MQueryGenerator.locate id in
1275 wrong_xpointer_format_from_wrong_xpointer_format' uri
1277 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
1278 output_html (rendering_window ())#outputhtml html ;
1282 [UriManager.string_of_uri
1283 (input_or_locate_uri ~title:("URI matching \"" ^ id ^ "\" unknown."))]
1286 interactive_user_uri_choice
1287 ~selection_mode:`EXTENDED
1288 ~ok:"Try every selection."
1289 ~title:"Ambiguous input."
1291 ("Ambiguous input \"" ^ id ^
1292 "\". Please, choose one or more interpretations:")
1295 List.map cic_textual_parser_uri_of_string uris'
1298 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
1299 exception AmbiguousInput;;
1301 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
1302 let known_ids,resolve_id = !id_to_uris in
1308 if List.mem he known_ids then filter tl else he::(filter tl)
1312 (* for each id in dom' we get the list of uris associated to it *)
1313 let list_of_uris = List.map locate_one_id dom' in
1314 (* and now we compute the list of all possible assignments from id to uris *)
1316 let rec aux ids list_of_uris =
1317 match ids,list_of_uris with
1318 [],[] -> [resolve_id]
1319 | id::idtl,uris::uristl ->
1320 let resolves = aux idtl uristl in
1326 function id' -> if id = id' then Some uri else f id'
1330 | _,_ -> assert false
1332 aux dom' list_of_uris
1334 let tests_no = List.length resolve_ids in
1335 if tests_no > 1 then
1336 output_html (outputhtml ())
1337 ("<h1>Disambiguation phase started: " ^
1338 string_of_int (List.length resolve_ids) ^ " cases will be tried.") ;
1339 (* now we select only the ones that generates well-typed terms *)
1345 let metasenv',expr = mk_metasenv_and_expr resolve in
1347 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
1349 (CicTypeChecker.type_of_aux' metasenv context expr) ;
1350 resolve::(filter tl)
1357 match resolve_ids' with
1358 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
1359 | [resolve_id] -> resolve_id
1363 (function resolve ->
1367 match resolve id with
1368 None -> assert false
1371 CicTextualParser0.ConUri uri
1372 | CicTextualParser0.VarUri uri ->
1373 UriManager.string_of_uri uri
1374 | CicTextualParser0.IndTyUri (uri,tyno) ->
1375 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1376 string_of_int (tyno+1) ^ ")"
1377 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
1378 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1379 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
1383 let index = interactive_interpretation_choice choices in
1384 List.nth resolve_ids' index
1386 id_to_uris := known_ids @ dom', resolve_id' ;
1387 mk_metasenv_and_expr resolve_id'
1390 exception UriAlreadyInUse;;
1391 exception NotAUriToAConstant;;
1394 let inputt = ((rendering_window ())#inputt : term_editor) in
1395 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1396 let output = ((rendering_window ())#output : GMathView.math_view) in
1397 let notebook = (rendering_window ())#notebook in
1399 let chosen = ref false in
1400 let get_parsed = ref (function _ -> assert false) in
1401 let get_uri = ref (function _ -> assert false) in
1402 let non_empty_type = ref false in
1405 ~width:600 ~modal:true ~title:"New Proof or Definition"
1406 ~border_width:2 () in
1407 let vbox = GPack.vbox ~packing:window#add () in
1409 GPack.hbox ~border_width:0
1410 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1412 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1413 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1415 GEdit.entry ~editable:true
1416 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1418 GPack.hbox ~border_width:0
1419 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1421 GMisc.label ~text:"Enter the theorem or definition type:"
1422 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1423 let scrolled_window =
1424 GBin.scrolled_window ~border_width:5
1425 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1426 (* the content of the scrolled_window is moved below (see comment) *)
1428 GPack.hbox ~border_width:0
1429 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1431 GButton.button ~label:"Ok"
1432 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1433 let _ = okb#misc#set_sensitive false in
1435 GButton.button ~label:"Cancel"
1436 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1437 (* moved here to have visibility of the ok button *)
1439 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1440 ~isnotempty_callback:
1442 non_empty_type := b ;
1443 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1446 newinputt#set_term inputt#get_as_string ;
1449 uri_entry#connect#changed
1451 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1453 ignore (window#connect#destroy GMain.Main.quit) ;
1454 ignore (cancelb#connect#clicked window#destroy) ;
1456 (okb#connect#clicked
1460 let parsed = newinputt#get_term [] [] in
1461 let uristr = "cic:" ^ uri_entry#text in
1462 let uri = UriManager.uri_of_string uristr in
1463 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1464 raise NotAUriToAConstant
1468 ignore (Getter.resolve uri) ;
1469 raise UriAlreadyInUse
1471 Getter.Unresolved ->
1472 get_parsed := (function () -> parsed) ;
1473 get_uri := (function () -> uri) ;
1478 output_html outputhtml
1479 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1482 GMain.Main.main () ;
1485 let dom,mk_metasenv_and_expr = !get_parsed () in
1487 disambiguate_input [] [] dom mk_metasenv_and_expr
1489 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1490 ProofEngine.proof :=
1491 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1492 ProofEngine.goal := Some 1 ;
1493 refresh_sequent notebook ;
1494 refresh_proof output ;
1495 !save_set_sensitive true ;
1498 RefreshSequentException e ->
1499 output_html outputhtml
1500 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1501 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1502 | RefreshProofException e ->
1503 output_html outputhtml
1504 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1505 "proof: " ^ Printexc.to_string e ^ "</h1>")
1507 output_html outputhtml
1508 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1511 let check_term_in_scratch scratch_window metasenv context expr =
1513 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1514 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1515 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1516 scratch_window#show () ;
1517 scratch_window#mmlwidget#load_tree ~dom:mml
1520 print_endline ("? " ^ CicPp.ppterm expr) ;
1524 let check scratch_window () =
1525 let inputt = ((rendering_window ())#inputt : term_editor) in
1526 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1528 match !ProofEngine.proof with
1530 | Some (_,metasenv,_,_) -> metasenv
1532 let context,names_context =
1534 match !ProofEngine.goal with
1537 let (_,canonical_context,_) =
1538 List.find (function (m,_,_) -> m=metano) metasenv
1545 Some (n,_) -> Some n
1550 let dom,mk_metasenv_and_expr = inputt#get_term names_context metasenv in
1551 let (metasenv',expr) =
1552 disambiguate_input context metasenv dom mk_metasenv_and_expr
1554 check_term_in_scratch scratch_window metasenv' context expr
1557 output_html outputhtml
1558 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1562 (***********************)
1564 (***********************)
1566 let call_tactic tactic () =
1567 let notebook = (rendering_window ())#notebook in
1568 let output = ((rendering_window ())#output : GMathView.math_view) in
1569 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1570 let savedproof = !ProofEngine.proof in
1571 let savedgoal = !ProofEngine.goal in
1575 refresh_sequent notebook ;
1576 refresh_proof output
1578 RefreshSequentException e ->
1579 output_html outputhtml
1580 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1581 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1582 ProofEngine.proof := savedproof ;
1583 ProofEngine.goal := savedgoal ;
1584 refresh_sequent notebook
1585 | RefreshProofException e ->
1586 output_html outputhtml
1587 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1588 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1589 ProofEngine.proof := savedproof ;
1590 ProofEngine.goal := savedgoal ;
1591 refresh_sequent notebook ;
1592 refresh_proof output
1594 output_html outputhtml
1595 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1596 ProofEngine.proof := savedproof ;
1597 ProofEngine.goal := savedgoal ;
1601 let call_tactic_with_input tactic () =
1602 let notebook = (rendering_window ())#notebook in
1603 let output = ((rendering_window ())#output : GMathView.math_view) in
1604 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1605 let inputt = ((rendering_window ())#inputt : term_editor) in
1606 let savedproof = !ProofEngine.proof in
1607 let savedgoal = !ProofEngine.goal in
1608 let uri,metasenv,bo,ty =
1609 match !ProofEngine.proof with
1610 None -> assert false
1611 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1613 let canonical_context =
1614 match !ProofEngine.goal with
1615 None -> assert false
1617 let (_,canonical_context,_) =
1618 List.find (function (m,_,_) -> m=metano) metasenv
1625 Some (n,_) -> Some n
1630 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv in
1631 let (metasenv',expr) =
1632 disambiguate_input canonical_context metasenv dom mk_metasenv_and_expr
1634 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1636 refresh_sequent notebook ;
1637 refresh_proof output ;
1640 RefreshSequentException e ->
1641 output_html outputhtml
1642 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1643 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1644 ProofEngine.proof := savedproof ;
1645 ProofEngine.goal := savedgoal ;
1646 refresh_sequent notebook
1647 | RefreshProofException e ->
1648 output_html outputhtml
1649 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1650 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1651 ProofEngine.proof := savedproof ;
1652 ProofEngine.goal := savedgoal ;
1653 refresh_sequent notebook ;
1654 refresh_proof output
1656 output_html outputhtml
1657 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1658 ProofEngine.proof := savedproof ;
1659 ProofEngine.goal := savedgoal ;
1662 let call_tactic_with_goal_input tactic () =
1663 let module L = LogicalOperations in
1664 let module G = Gdome in
1665 let notebook = (rendering_window ())#notebook in
1666 let output = ((rendering_window ())#output : GMathView.math_view) in
1667 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1668 let savedproof = !ProofEngine.proof in
1669 let savedgoal = !ProofEngine.goal in
1670 match notebook#proofw#get_selection with
1673 ((node : Gdome.element)#getAttributeNS
1674 ~namespaceURI:helmns
1675 ~localName:(G.domString "xref"))#to_string
1677 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1681 match !current_goal_infos with
1682 Some (ids_to_terms, ids_to_father_ids,_) ->
1684 tactic (Hashtbl.find ids_to_terms id) ;
1685 refresh_sequent notebook ;
1686 refresh_proof output
1687 | None -> assert false (* "ERROR: No current term!!!" *)
1689 RefreshSequentException e ->
1690 output_html outputhtml
1691 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1692 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1693 ProofEngine.proof := savedproof ;
1694 ProofEngine.goal := savedgoal ;
1695 refresh_sequent notebook
1696 | RefreshProofException e ->
1697 output_html outputhtml
1698 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1699 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1700 ProofEngine.proof := savedproof ;
1701 ProofEngine.goal := savedgoal ;
1702 refresh_sequent notebook ;
1703 refresh_proof output
1705 output_html outputhtml
1706 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1707 ProofEngine.proof := savedproof ;
1708 ProofEngine.goal := savedgoal ;
1711 output_html outputhtml
1712 ("<h1 color=\"red\">No term selected</h1>")
1715 let call_tactic_with_input_and_goal_input tactic () =
1716 let module L = LogicalOperations in
1717 let module G = Gdome in
1718 let notebook = (rendering_window ())#notebook in
1719 let output = ((rendering_window ())#output : GMathView.math_view) in
1720 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1721 let inputt = ((rendering_window ())#inputt : term_editor) in
1722 let savedproof = !ProofEngine.proof in
1723 let savedgoal = !ProofEngine.goal in
1724 match notebook#proofw#get_selection with
1727 ((node : Gdome.element)#getAttributeNS
1728 ~namespaceURI:helmns
1729 ~localName:(G.domString "xref"))#to_string
1731 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1735 match !current_goal_infos with
1736 Some (ids_to_terms, ids_to_father_ids,_) ->
1738 let uri,metasenv,bo,ty =
1739 match !ProofEngine.proof with
1740 None -> assert false
1741 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1743 let canonical_context =
1744 match !ProofEngine.goal with
1745 None -> assert false
1747 let (_,canonical_context,_) =
1748 List.find (function (m,_,_) -> m=metano) metasenv
1750 canonical_context in
1754 Some (n,_) -> Some n
1758 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv
1760 let (metasenv',expr) =
1761 disambiguate_input canonical_context metasenv dom
1762 mk_metasenv_and_expr
1764 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1765 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
1767 refresh_sequent notebook ;
1768 refresh_proof output ;
1770 | None -> assert false (* "ERROR: No current term!!!" *)
1772 RefreshSequentException e ->
1773 output_html outputhtml
1774 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1775 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1776 ProofEngine.proof := savedproof ;
1777 ProofEngine.goal := savedgoal ;
1778 refresh_sequent notebook
1779 | RefreshProofException e ->
1780 output_html outputhtml
1781 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1782 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1783 ProofEngine.proof := savedproof ;
1784 ProofEngine.goal := savedgoal ;
1785 refresh_sequent notebook ;
1786 refresh_proof output
1788 output_html outputhtml
1789 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1790 ProofEngine.proof := savedproof ;
1791 ProofEngine.goal := savedgoal ;
1794 output_html outputhtml
1795 ("<h1 color=\"red\">No term selected</h1>")
1798 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
1799 let module L = LogicalOperations in
1800 let module G = Gdome in
1801 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
1802 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1803 let savedproof = !ProofEngine.proof in
1804 let savedgoal = !ProofEngine.goal in
1805 match mmlwidget#get_selection with
1808 ((node : Gdome.element)#getAttributeNS
1809 ~namespaceURI:helmns
1810 ~localName:(G.domString "xref"))#to_string
1812 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1816 match !current_scratch_infos with
1817 (* term is the whole goal in the scratch_area *)
1818 Some (term,ids_to_terms, ids_to_father_ids,_) ->
1820 let expr = tactic term (Hashtbl.find ids_to_terms id) in
1821 let mml = mml_of_cic_term 111 expr in
1822 scratch_window#show () ;
1823 scratch_window#mmlwidget#load_tree ~dom:mml
1824 | None -> assert false (* "ERROR: No current term!!!" *)
1827 output_html outputhtml
1828 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1831 output_html outputhtml
1832 ("<h1 color=\"red\">No term selected</h1>")
1835 let call_tactic_with_hypothesis_input tactic () =
1836 let module L = LogicalOperations in
1837 let module G = Gdome in
1838 let notebook = (rendering_window ())#notebook in
1839 let output = ((rendering_window ())#output : GMathView.math_view) in
1840 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1841 let savedproof = !ProofEngine.proof in
1842 let savedgoal = !ProofEngine.goal in
1843 match notebook#proofw#get_selection with
1846 ((node : Gdome.element)#getAttributeNS
1847 ~namespaceURI:helmns
1848 ~localName:(G.domString "xref"))#to_string
1850 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1854 match !current_goal_infos with
1855 Some (_,_,ids_to_hypotheses) ->
1857 tactic (Hashtbl.find ids_to_hypotheses id) ;
1858 refresh_sequent notebook ;
1859 refresh_proof output
1860 | None -> assert false (* "ERROR: No current term!!!" *)
1862 RefreshSequentException e ->
1863 output_html outputhtml
1864 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1865 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1866 ProofEngine.proof := savedproof ;
1867 ProofEngine.goal := savedgoal ;
1868 refresh_sequent notebook
1869 | RefreshProofException e ->
1870 output_html outputhtml
1871 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1872 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1873 ProofEngine.proof := savedproof ;
1874 ProofEngine.goal := savedgoal ;
1875 refresh_sequent notebook ;
1876 refresh_proof output
1878 output_html outputhtml
1879 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1880 ProofEngine.proof := savedproof ;
1881 ProofEngine.goal := savedgoal ;
1884 output_html outputhtml
1885 ("<h1 color=\"red\">No term selected</h1>")
1889 let intros = call_tactic ProofEngine.intros;;
1890 let exact = call_tactic_with_input ProofEngine.exact;;
1891 let apply = call_tactic_with_input ProofEngine.apply;;
1892 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
1893 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
1894 let whd = call_tactic_with_goal_input ProofEngine.whd;;
1895 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
1896 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
1897 let fold = call_tactic_with_input ProofEngine.fold;;
1898 let cut = call_tactic_with_input ProofEngine.cut;;
1899 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
1900 let letin = call_tactic_with_input ProofEngine.letin;;
1901 let ring = call_tactic ProofEngine.ring;;
1902 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
1903 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
1904 let fourier = call_tactic ProofEngine.fourier;;
1905 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
1906 let reflexivity = call_tactic ProofEngine.reflexivity;;
1907 let symmetry = call_tactic ProofEngine.symmetry;;
1908 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
1909 let left = call_tactic ProofEngine.left;;
1910 let right = call_tactic ProofEngine.right;;
1911 let assumption = call_tactic ProofEngine.assumption;;
1913 let whd_in_scratch scratch_window =
1914 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
1917 let reduce_in_scratch scratch_window =
1918 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1921 let simpl_in_scratch scratch_window =
1922 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1928 (**********************)
1929 (* END OF TACTICS *)
1930 (**********************)
1934 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1936 show_in_show_window (input_or_locate_uri ~title:"Show")
1939 output_html outputhtml
1940 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1943 exception NotADefinition;;
1946 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1947 let output = ((rendering_window ())#output : GMathView.math_view) in
1948 let notebook = (rendering_window ())#notebook in
1950 let uri = input_or_locate_uri ~title:"Open" in
1951 CicTypeChecker.typecheck uri ;
1952 let metasenv,bo,ty =
1953 match CicEnvironment.get_cooked_obj uri with
1954 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1955 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1958 | Cic.InductiveDefinition _ -> raise NotADefinition
1960 ProofEngine.proof :=
1961 Some (uri, metasenv, bo, ty) ;
1962 ProofEngine.goal := None ;
1963 refresh_sequent notebook ;
1964 refresh_proof output
1966 RefreshSequentException e ->
1967 output_html outputhtml
1968 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1969 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1970 | RefreshProofException e ->
1971 output_html outputhtml
1972 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1973 "proof: " ^ Printexc.to_string e ^ "</h1>")
1975 output_html outputhtml
1976 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1980 let searchPattern () =
1981 let inputt = ((rendering_window ())#inputt : term_editor) in
1982 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1984 let rec get_level ?(last_invalid=false) () =
1986 GToolbox.input_string
1987 ~title:"Insert the strictness parameter for the query:"
1988 ((if last_invalid then
1989 "Invalid input (must be a non-negative natural number). Insert again "
1992 ) ^ "the strictness parameter for the query:")
1994 None -> raise NoChoice
1999 _ -> get_level ~last_invalid:true ()
2001 let level = get_level () in
2003 match !ProofEngine.proof with
2004 None -> assert false
2005 | Some (_,metasenv,_,_) -> metasenv
2007 match !ProofEngine.goal with
2010 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2011 let result = MQueryGenerator.searchPattern metasenv ey ty level in
2015 wrong_xpointer_format_from_wrong_xpointer_format' uri
2018 " <h1>Backward Query: </h1>" ^
2019 " <h2>Levels: </h2> " ^
2020 MQueryLevels.string_of_levels
2021 (MQueryLevels.levels_of_term metasenv ey ty) "<br>" ^
2022 " <pre>" ^ get_last_query result ^ "</pre>"
2024 output_html outputhtml html ;
2026 let rec filter_out =
2030 let tl',exc = filter_out tl in
2033 ProofEngine.can_apply
2034 (term_of_cic_textual_parser_uri
2035 (cic_textual_parser_uri_of_string uri))
2043 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2044 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2051 " <h1>Objects that can actually be applied: </h1> " ^
2052 String.concat "<br>" uris' ^ exc ^
2053 " <h1>Number of false matches: " ^
2054 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2055 " <h1>Number of good matches: " ^
2056 string_of_int (List.length uris') ^ "</h1>"
2058 output_html outputhtml html' ;
2060 user_uri_choice ~title:"Ambiguous input."
2062 "Many lemmas can be successfully applied. Please, choose one:"
2065 inputt#set_term uri' ;
2069 output_html outputhtml
2070 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2073 let choose_selection
2074 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
2076 let module G = Gdome in
2077 let rec aux element =
2078 if element#hasAttributeNS
2079 ~namespaceURI:helmns
2080 ~localName:(G.domString "xref")
2082 mmlwidget#set_selection (Some element)
2084 match element#get_parentNode with
2085 None -> assert false
2086 (*CSC: OCAML DIVERGES!
2087 | Some p -> aux (new G.element_of_node p)
2089 | Some p -> aux (new Gdome.element_of_node p)
2093 | None -> mmlwidget#set_selection None
2096 (* STUFF TO BUILD THE GTK INTERFACE *)
2098 (* Stuff for the widget settings *)
2100 let export_to_postscript (output : GMathView.math_view) =
2101 let lastdir = ref (Unix.getcwd ()) in
2104 GToolbox.select_file ~title:"Export to PostScript"
2105 ~dir:lastdir ~filename:"screenshot.ps" ()
2109 output#export_to_postscript ~filename:filename ();
2112 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
2113 button_set_kerning button_set_transparency export_to_postscript_menu_item
2116 let is_set = button_t1#active in
2117 output#set_font_manager_type
2118 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2121 button_set_anti_aliasing#misc#set_sensitive true ;
2122 button_set_kerning#misc#set_sensitive true ;
2123 button_set_transparency#misc#set_sensitive true ;
2124 export_to_postscript_menu_item#misc#set_sensitive true ;
2128 button_set_anti_aliasing#misc#set_sensitive false ;
2129 button_set_kerning#misc#set_sensitive false ;
2130 button_set_transparency#misc#set_sensitive false ;
2131 export_to_postscript_menu_item#misc#set_sensitive false ;
2135 let set_anti_aliasing output button_set_anti_aliasing () =
2136 output#set_anti_aliasing button_set_anti_aliasing#active
2139 let set_kerning output button_set_kerning () =
2140 output#set_kerning button_set_kerning#active
2143 let set_transparency output button_set_transparency () =
2144 output#set_transparency button_set_transparency#active
2147 let changefont output font_size_spinb () =
2148 output#set_font_size font_size_spinb#value_as_int
2151 let set_log_verbosity output log_verbosity_spinb () =
2152 output#set_log_verbosity log_verbosity_spinb#value_as_int
2155 class settings_window (output : GMathView.math_view) sw
2156 export_to_postscript_menu_item selection_changed_callback
2158 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2160 GPack.vbox ~packing:settings_window#add () in
2163 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2164 ~border_width:5 ~packing:vbox#add () in
2166 GButton.toggle_button ~label:"activate t1 fonts"
2167 ~packing:(table#attach ~left:0 ~top:0) () in
2168 let button_set_anti_aliasing =
2169 GButton.toggle_button ~label:"set_anti_aliasing"
2170 ~packing:(table#attach ~left:0 ~top:1) () in
2171 let button_set_kerning =
2172 GButton.toggle_button ~label:"set_kerning"
2173 ~packing:(table#attach ~left:1 ~top:1) () in
2174 let button_set_transparency =
2175 GButton.toggle_button ~label:"set_transparency"
2176 ~packing:(table#attach ~left:2 ~top:1) () in
2179 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2180 ~border_width:5 ~packing:vbox#add () in
2181 let font_size_label =
2182 GMisc.label ~text:"font size:"
2183 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2184 let font_size_spinb =
2186 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2189 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2190 let log_verbosity_label =
2191 GMisc.label ~text:"log verbosity:"
2192 ~packing:(table#attach ~left:0 ~top:1) () in
2193 let log_verbosity_spinb =
2195 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2198 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2200 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2202 GButton.button ~label:"Close"
2203 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2205 method show = settings_window#show
2207 button_set_anti_aliasing#misc#set_sensitive false ;
2208 button_set_kerning#misc#set_sensitive false ;
2209 button_set_transparency#misc#set_sensitive false ;
2210 (* Signals connection *)
2211 ignore(button_t1#connect#clicked
2212 (activate_t1 output button_set_anti_aliasing button_set_kerning
2213 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2214 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2215 ignore(button_set_anti_aliasing#connect#toggled
2216 (set_anti_aliasing output button_set_anti_aliasing));
2217 ignore(button_set_kerning#connect#toggled
2218 (set_kerning output button_set_kerning)) ;
2219 ignore(button_set_transparency#connect#toggled
2220 (set_transparency output button_set_transparency)) ;
2221 ignore(log_verbosity_spinb#connect#changed
2222 (set_log_verbosity output log_verbosity_spinb)) ;
2223 ignore(closeb#connect#clicked settings_window#misc#hide)
2226 (* Scratch window *)
2228 class scratch_window =
2230 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2232 GPack.vbox ~packing:window#add () in
2234 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2236 GButton.button ~label:"Whd"
2237 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2239 GButton.button ~label:"Reduce"
2240 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2242 GButton.button ~label:"Simpl"
2243 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2244 let scrolled_window =
2245 GBin.scrolled_window ~border_width:10
2246 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2249 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2251 method mmlwidget = mmlwidget
2252 method show () = window#misc#hide () ; window#show ()
2254 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2255 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2256 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2257 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2258 ignore(simplb#connect#clicked (simpl_in_scratch self))
2262 let vbox1 = GPack.vbox () in
2264 val mutable proofw_ref = None
2265 val mutable compute_ref = None
2267 Lazy.force self#compute ;
2268 match proofw_ref with
2269 None -> assert false
2270 | Some proofw -> proofw
2271 method content = vbox1
2273 match compute_ref with
2274 None -> assert false
2275 | Some compute -> compute
2279 let scrolled_window1 =
2280 GBin.scrolled_window ~border_width:10
2281 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2283 GMathView.math_view ~width:400 ~height:275
2284 ~packing:(scrolled_window1#add) () in
2285 let _ = proofw_ref <- Some proofw in
2287 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2289 GButton.button ~label:"Exact"
2290 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2292 GButton.button ~label:"Intros"
2293 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2295 GButton.button ~label:"Apply"
2296 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2297 let elimsimplintrosb =
2298 GButton.button ~label:"ElimSimplIntros"
2299 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2301 GButton.button ~label:"ElimType"
2302 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2304 GButton.button ~label:"Whd"
2305 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2307 GButton.button ~label:"Reduce"
2308 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2310 GButton.button ~label:"Simpl"
2311 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2313 GButton.button ~label:"Fold"
2314 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2316 GButton.button ~label:"Cut"
2317 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2319 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2321 GButton.button ~label:"Change"
2322 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2324 GButton.button ~label:"Let ... In"
2325 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2327 GButton.button ~label:"Ring"
2328 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2330 GButton.button ~label:"ClearBody"
2331 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2333 GButton.button ~label:"Clear"
2334 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2336 GButton.button ~label:"Fourier"
2337 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2339 GButton.button ~label:"RewriteSimpl ->"
2340 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2342 GButton.button ~label:"Reflexivity"
2343 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2345 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2347 GButton.button ~label:"Symmetry"
2348 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2350 GButton.button ~label:"Transitivity"
2351 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2353 GButton.button ~label:"Left"
2354 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2356 GButton.button ~label:"Right"
2357 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2359 GButton.button ~label:"Assumption"
2360 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2361 let searchpatternb =
2362 GButton.button ~label:"SearchPattern_Apply"
2363 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2364 ignore(exactb#connect#clicked exact) ;
2365 ignore(applyb#connect#clicked apply) ;
2366 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
2367 ignore(elimtypeb#connect#clicked elimtype) ;
2368 ignore(whdb#connect#clicked whd) ;
2369 ignore(reduceb#connect#clicked reduce) ;
2370 ignore(simplb#connect#clicked simpl) ;
2371 ignore(foldb#connect#clicked fold) ;
2372 ignore(cutb#connect#clicked cut) ;
2373 ignore(changeb#connect#clicked change) ;
2374 ignore(letinb#connect#clicked letin) ;
2375 ignore(ringb#connect#clicked ring) ;
2376 ignore(clearbodyb#connect#clicked clearbody) ;
2377 ignore(clearb#connect#clicked clear) ;
2378 ignore(fourierb#connect#clicked fourier) ;
2379 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
2380 ignore(reflexivityb#connect#clicked reflexivity) ;
2381 ignore(symmetryb#connect#clicked symmetry) ;
2382 ignore(transitivityb#connect#clicked transitivity) ;
2383 ignore(leftb#connect#clicked left) ;
2384 ignore(rightb#connect#clicked right) ;
2385 ignore(assumptionb#connect#clicked assumption) ;
2386 ignore(introsb#connect#clicked intros) ;
2387 ignore(searchpatternb#connect#clicked searchPattern) ;
2388 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2394 let vbox1 = GPack.vbox () in
2395 let scrolled_window1 =
2396 GBin.scrolled_window ~border_width:10
2397 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2399 GMathView.math_view ~width:400 ~height:275
2400 ~packing:(scrolled_window1#add) () in
2402 method proofw = (assert false : GMathView.math_view)
2403 method content = vbox1
2404 method compute = (assert false : unit)
2408 let empty_page = new empty_page;;
2412 val notebook = GPack.notebook ()
2414 val mutable skip_switch_page_event = false
2415 val mutable empty = true
2416 method notebook = notebook
2418 let new_page = new page () in
2420 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2421 notebook#append_page
2422 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2423 new_page#content#coerce
2424 method remove_all_pages ~skip_switch_page_event:skip =
2426 notebook#remove_page 0 (* let's remove the empty page *)
2428 List.iter (function _ -> notebook#remove_page 0) !pages ;
2430 skip_switch_page_event <- skip
2431 method set_current_page ~may_skip_switch_page_event n =
2432 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2433 let new_page = notebook#page_num page#content#coerce in
2434 if may_skip_switch_page_event && new_page <> notebook#current_page then
2435 skip_switch_page_event <- true ;
2436 notebook#goto_page new_page
2437 method set_empty_page =
2440 notebook#append_page
2441 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2442 empty_page#content#coerce
2444 let (_,_,page) = List.nth !pages notebook#current_page in
2448 (notebook#connect#switch_page
2450 let skip = skip_switch_page_event in
2451 skip_switch_page_event <- false ;
2454 let (metano,setgoal,page) = List.nth !pages i in
2455 ProofEngine.goal := Some metano ;
2456 Lazy.force (page#compute) ;
2465 class rendering_window output (notebook : notebook) =
2466 let scratch_window = new scratch_window in
2468 GWindow.window ~title:"MathML viewer" ~border_width:0
2469 ~allow_shrink:false () in
2470 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2472 let handle_box = GBin.handle_box ~border_width:2
2473 ~packing:(vbox_for_menu#pack ~padding:0) () in
2474 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2475 let factory0 = new GMenu.factory menubar in
2476 let accel_group = factory0#accel_group in
2478 let file_menu = factory0#add_submenu "File" in
2479 let factory1 = new GMenu.factory file_menu ~accel_group in
2480 let export_to_postscript_menu_item =
2483 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2486 let reopen_menu_item =
2487 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2491 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2492 ignore (factory1#add_separator ()) ;
2494 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2496 let save_menu_item =
2497 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
2500 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2501 ignore (!save_set_sensitive false);
2502 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2503 ignore (!qed_set_sensitive false);
2504 ignore (factory1#add_separator ()) ;
2505 let export_to_postscript_menu_item =
2506 factory1#add_item "Export to PostScript..."
2507 ~callback:(export_to_postscript output) in
2508 ignore (factory1#add_separator ()) ;
2510 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2511 export_to_postscript_menu_item
2514 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2515 let factory2 = new GMenu.factory edit_menu ~accel_group in
2516 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2517 let proveit_menu_item =
2518 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2519 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2521 let focus_menu_item =
2522 factory2#add_item "Focus" ~key:GdkKeysyms._F
2523 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2526 focus_and_proveit_set_sensitive :=
2528 proveit_menu_item#misc#set_sensitive b ;
2529 focus_menu_item#misc#set_sensitive b
2531 let _ = !focus_and_proveit_set_sensitive false in
2532 (* edit term menu *)
2533 let edit_term_menu = factory0#add_submenu "Edit Term" in
2534 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2535 let check_menu_item =
2536 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2537 ~callback:(check scratch_window) in
2538 let _ = check_menu_item#misc#set_sensitive false in
2540 let settings_menu = factory0#add_submenu "Search" in
2541 let factory4 = new GMenu.factory settings_menu ~accel_group in
2543 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2545 let show_menu_item =
2546 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2549 let settings_menu = factory0#add_submenu "Settings" in
2550 let factory3 = new GMenu.factory settings_menu ~accel_group in
2552 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2553 ~callback:edit_aliases in
2554 let _ = factory3#add_separator () in
2556 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2557 ~callback:(function _ -> (settings_window ())#show ()) in
2559 let _ = window#add_accel_group accel_group in
2563 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2565 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2566 let scrolled_window0 =
2567 GBin.scrolled_window ~border_width:10
2568 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2569 let _ = scrolled_window0#add output#coerce in
2571 GBin.frame ~label:"Insert Term"
2572 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2573 let scrolled_window1 =
2574 GBin.scrolled_window ~border_width:5
2575 ~packing:frame#add () in
2577 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2578 ~isnotempty_callback:check_menu_item#misc#set_sensitive in
2580 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2582 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2584 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2588 ~source:"<html><body bgColor=\"white\"></body></html>"
2589 ~width:400 ~height: 100
2594 method outputhtml = outputhtml
2595 method inputt = inputt
2596 method output = (output : GMathView.math_view)
2597 method notebook = notebook
2598 method show = window#show
2600 notebook#set_empty_page ;
2601 export_to_postscript_menu_item#misc#set_sensitive false ;
2602 check_term := (check_term_in_scratch scratch_window) ;
2604 (* signal handlers here *)
2605 ignore(output#connect#selection_changed
2607 choose_selection output elem ;
2608 !focus_and_proveit_set_sensitive true
2610 ignore (output#connect#clicked (show_in_show_window_callback output)) ;
2611 let settings_window = new settings_window output scrolled_window0
2612 export_to_postscript_menu_item (choose_selection output) in
2613 set_settings_window settings_window ;
2614 set_outputhtml outputhtml ;
2615 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2616 Logger.log_callback :=
2617 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2622 let initialize_everything () =
2623 let module U = Unix in
2624 let output = GMathView.math_view ~width:350 ~height:280 () in
2625 let notebook = new notebook in
2626 let rendering_window' = new rendering_window output notebook in
2627 set_rendering_window rendering_window' ;
2628 mml_of_cic_term_ref := mml_of_cic_term ;
2629 rendering_window'#show () ;
2636 Mqint.set_database Mqint.postgres_db ;
2637 (* Mqint.init "dbname=helm_mowgli" ; *)
2638 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
2639 Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm" ;
2641 ignore (GtkMain.Main.init ()) ;
2642 initialize_everything () ;
2643 if !usedb then Mqint.close ();