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 ?isnotempty_callback () =
156 let input = GEdit.text ~editable:true ?width ?height ?packing () in
158 match isnotempty_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 ~ask_dtd_to_the_getter:true
537 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
538 ~ask_dtd_to_the_getter:true
542 None -> Xml2Gdome.document_of_xml domImpl xml
544 Xml.pp xml (Some constanttypefile) ;
545 Xml2Gdome.document_of_xml domImpl bodyxml'
547 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
548 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
550 Xml.pp xmlinnertypes (Some innertypesfile) ;
551 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
556 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
559 let struri = UriManager.string_of_uri uri in
560 let idx = (String.rindex struri '/') + 1 in
561 String.sub struri idx (String.length struri - idx)
563 let path = pathname ^ "/" ^ name in
565 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
569 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
570 ~ask_dtd_to_the_getter:false
573 let innertypesuri = UriManager.innertypesuri_of_uri uri in
574 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
575 Getter.register innertypesuri
576 (Configuration.annotations_url ^
577 Str.replace_first (Str.regexp "^cic:") ""
578 (UriManager.string_of_uri innertypesuri) ^ ".xml"
580 (* constant type / variable / mutual inductive types definition *)
581 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
583 (Configuration.annotations_url ^
584 Str.replace_first (Str.regexp "^cic:") ""
585 (UriManager.string_of_uri uri) ^ ".xml"
592 match UriManager.bodyuri_of_uri uri with
594 | Some bodyuri -> bodyuri
596 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
597 Getter.register bodyuri
598 (Configuration.annotations_url ^
599 Str.replace_first (Str.regexp "^cic:") ""
600 (UriManager.string_of_uri bodyuri) ^ ".xml"
607 exception RefreshSequentException of exn;;
608 exception RefreshProofException of exn;;
610 let refresh_proof (output : GMathView.math_view) =
612 let uri,currentproof =
613 match !ProofEngine.proof with
615 | Some (uri,metasenv,bo,ty) ->
616 !qed_set_sensitive (List.length metasenv = 0) ;
617 (*CSC: Wrong: [] is just plainly wrong *)
618 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
621 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
622 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
624 Cic2acic.acic_object_of_cic_object currentproof
627 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
630 output#load_tree mml ;
632 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
635 match !ProofEngine.proof with
637 | Some (uri,metasenv,bo,ty) ->
638 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
639 raise (RefreshProofException e)
642 let refresh_sequent ?(empty_notebook=true) notebook =
644 match !ProofEngine.goal with
646 if empty_notebook then
648 notebook#remove_all_pages ~skip_switch_page_event:false ;
649 notebook#set_empty_page
652 notebook#proofw#unload
655 match !ProofEngine.proof with
657 | Some (_,metasenv,_,_) -> metasenv
659 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
660 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
661 SequentPp.XmlPp.print_sequent metasenv currentsequent
663 let regenerate_notebook () =
664 let skip_switch_page_event =
666 (m,_,_)::_ when m = metano -> false
669 notebook#remove_all_pages ~skip_switch_page_event ;
670 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
672 if empty_notebook then
674 regenerate_notebook () ;
675 notebook#set_current_page ~may_skip_switch_page_event:false metano
679 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
681 applyStylesheets sequent_doc sequent_styles sequent_args
683 notebook#set_current_page ~may_skip_switch_page_event:true metano;
684 notebook#proofw#load_tree ~dom:sequent_mml
686 current_goal_infos :=
687 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
691 match !ProofEngine.goal with
696 match !ProofEngine.proof with
698 | Some (_,metasenv,_,_) -> metasenv
701 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
702 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
703 raise (RefreshSequentException e)
704 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
708 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
709 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
712 let mml_of_cic_term metano term =
714 match !ProofEngine.proof with
716 | Some (_,metasenv,_,_) -> metasenv
719 match !ProofEngine.goal with
722 let (_,canonical_context,_) =
723 List.find (function (m,_,_) -> m=metano) metasenv
727 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
728 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
731 Xml2Gdome.document_of_xml domImpl sequent_gdome
734 applyStylesheets sequent_doc sequent_styles sequent_args ;
736 current_scratch_infos :=
737 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
741 exception OpenConjecturesStillThere;;
742 exception WrongProof;;
744 let pathname_of_annuri uristring =
745 Configuration.annotations_dir ^
746 Str.replace_first (Str.regexp "^cic:") "" uristring
749 let make_dirs dirpath =
750 ignore (Unix.system ("mkdir -p " ^ dirpath))
754 match !ProofEngine.proof with
756 | Some (uri,[],bo,ty) ->
758 CicReduction.are_convertible []
759 (CicTypeChecker.type_of_aux' [] [] bo) ty
762 (*CSC: Wrong: [] is just plainly wrong *)
763 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
765 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
766 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
768 Cic2acic.acic_object_of_cic_object proof
771 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
774 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
775 !qed_set_sensitive false ;
776 (* let's save the theorem and register it to the getter *)
777 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
779 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
783 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
788 | _ -> raise OpenConjecturesStillThere
792 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
793 match !ProofEngine.proof with
795 | Some (uri, metasenv, bo, ty) ->
797 (*CSC: Wrong: [] is just plainly wrong *)
798 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
800 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
801 Cic2acic.acic_object_of_cic_object currentproof
805 Cic2Xml.print_object uri ~ids_to_inner_sorts
806 ~ask_dtd_to_the_getter:true acurrentproof
808 xml,Some bodyxml -> xml,bodyxml
809 | _,None -> assert false
811 Xml.pp ~quiet:true xml (Some prooffiletype) ;
812 output_html outputhtml
813 ("<h1 color=\"Green\">Current proof type saved to " ^
814 prooffiletype ^ "</h1>") ;
815 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
816 output_html outputhtml
817 ("<h1 color=\"Green\">Current proof body saved to " ^
821 (* Used to typecheck the loaded proofs *)
822 let typecheck_loaded_proof metasenv bo ty =
823 let module T = CicTypeChecker in
826 (fun metasenv ((_,context,ty) as conj) ->
827 ignore (T.type_of_aux' metasenv context ty) ;
830 ignore (T.type_of_aux' metasenv [] ty) ;
831 ignore (T.type_of_aux' metasenv [] bo)
835 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
836 let output = ((rendering_window ())#output : GMathView.math_view) in
837 let notebook = (rendering_window ())#notebook in
840 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
843 None -> raise NoChoice
845 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
846 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
847 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
848 typecheck_loaded_proof metasenv bo ty ;
850 Some (uri, metasenv, bo, ty) ;
854 | (metano,_,_)::_ -> Some metano
856 refresh_proof output ;
857 refresh_sequent notebook ;
858 output_html outputhtml
859 ("<h1 color=\"Green\">Current proof type loaded from " ^
860 prooffiletype ^ "</h1>") ;
861 output_html outputhtml
862 ("<h1 color=\"Green\">Current proof body loaded from " ^
863 prooffile ^ "</h1>") ;
864 !save_set_sensitive true
867 RefreshSequentException e ->
868 output_html outputhtml
869 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
870 "sequent: " ^ Printexc.to_string e ^ "</h1>")
871 | RefreshProofException e ->
872 output_html outputhtml
873 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
874 "proof: " ^ Printexc.to_string e ^ "</h1>")
876 output_html outputhtml
877 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
880 let edit_aliases () =
881 let chosen = ref false in
884 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
886 GPack.vbox ~border_width:0 ~packing:window#add () in
887 let scrolled_window =
888 GBin.scrolled_window ~border_width:10
889 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
890 let input = GEdit.text ~editable:true ~width:400 ~height:100
891 ~packing:scrolled_window#add () in
893 GPack.hbox ~border_width:0
894 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
896 GButton.button ~label:"Ok"
897 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
899 GButton.button ~label:"Cancel"
900 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
901 ignore (window#connect#destroy GMain.Main.quit) ;
902 ignore (cancelb#connect#clicked window#destroy) ;
904 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
905 let dom,resolve_id = !id_to_uris in
907 (input#insert_text ~pos:0
912 match resolve_id v with
917 (string_of_cic_textual_parser_uri uri)
923 let inputtext = input#get_chars 0 input#length in
925 let alfa = "[a-zA-Z_-]" in
926 let digit = "[0-9]" in
927 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
928 let blanks = "\( \|\t\|\n\)+" in
929 let nonblanks = "[^ \t\n]+" in
930 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
932 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
936 let n' = Str.search_forward regexpr inputtext n in
937 let id = Str.matched_group 2 inputtext in
939 cic_textual_parser_uri_of_string
940 ("cic:" ^ (Str.matched_group 5 inputtext))
942 let dom,resolve_id = aux (n' + 1) in
943 if List.mem id dom then
947 (function id' -> if id = id' then Some uri else resolve_id id')
949 Not_found -> empty_id_to_uris
953 id_to_uris := dom,resolve_id
957 let module L = LogicalOperations in
958 let module G = Gdome in
959 let notebook = (rendering_window ())#notebook in
960 let output = (rendering_window ())#output in
961 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
962 match (rendering_window ())#output#get_selection with
965 ((node : Gdome.element)#getAttributeNS
967 ((element : G.element)#getAttributeNS
970 ~localName:(G.domString "xref"))#to_string
972 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
976 match !current_cic_infos with
977 Some (ids_to_terms, ids_to_father_ids, _, _) ->
979 L.to_sequent id ids_to_terms ids_to_father_ids ;
980 refresh_proof output ;
981 refresh_sequent notebook
982 | None -> assert false (* "ERROR: No current term!!!" *)
984 RefreshSequentException e ->
985 output_html outputhtml
986 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
987 "sequent: " ^ Printexc.to_string e ^ "</h1>")
988 | RefreshProofException e ->
989 output_html outputhtml
990 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
991 "proof: " ^ Printexc.to_string e ^ "</h1>")
993 output_html outputhtml
994 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
996 | None -> assert false (* "ERROR: No selection!!!" *)
1000 let module L = LogicalOperations in
1001 let module G = Gdome in
1002 let notebook = (rendering_window ())#notebook in
1003 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1004 match (rendering_window ())#output#get_selection with
1007 ((node : Gdome.element)#getAttributeNS
1008 (*CSC: OCAML DIVERGE
1009 ((element : G.element)#getAttributeNS
1011 ~namespaceURI:helmns
1012 ~localName:(G.domString "xref"))#to_string
1014 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1018 match !current_cic_infos with
1019 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1021 L.focus id ids_to_terms ids_to_father_ids ;
1022 refresh_sequent notebook
1023 | None -> assert false (* "ERROR: No current term!!!" *)
1025 RefreshSequentException e ->
1026 output_html outputhtml
1027 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1028 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1029 | RefreshProofException e ->
1030 output_html outputhtml
1031 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1032 "proof: " ^ Printexc.to_string e ^ "</h1>")
1034 output_html outputhtml
1035 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1037 | None -> assert false (* "ERROR: No selection!!!" *)
1040 exception NoPrevGoal;;
1041 exception NoNextGoal;;
1043 let setgoal metano =
1044 let module L = LogicalOperations in
1045 let module G = Gdome in
1046 let notebook = (rendering_window ())#notebook in
1047 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1049 match !ProofEngine.proof with
1050 None -> assert false
1051 | Some (_,metasenv,_,_) -> metasenv
1054 refresh_sequent ~empty_notebook:false notebook
1056 RefreshSequentException e ->
1057 output_html outputhtml
1058 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1059 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1061 output_html outputhtml
1062 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1065 let show_in_show_window, show_in_show_window_callback =
1067 GWindow.window ~width:800 ~border_width:2 () in
1068 let scrolled_window =
1069 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1071 GMathView.math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1072 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1073 let href = Gdome.domString "href" in
1074 let show_in_show_window uri =
1075 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1077 CicTypeChecker.typecheck uri ;
1078 let obj = CicEnvironment.get_cooked_obj uri in
1080 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1081 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1083 Cic2acic.acic_object_of_cic_object obj
1086 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1089 window#set_title (UriManager.string_of_uri uri) ;
1090 window#misc#hide () ; window#show () ;
1091 mmlwidget#load_tree mml ;
1094 output_html outputhtml
1095 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1097 let show_in_show_window_callback mmlwidget (n : Gdome.element) =
1098 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1100 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1102 show_in_show_window (UriManager.uri_of_string uri)
1104 if mmlwidget#get_action <> None then
1105 mmlwidget#action_toggle
1108 mmlwidget#connect#clicked (show_in_show_window_callback mmlwidget)
1110 show_in_show_window, show_in_show_window_callback
1113 exception NoObjectsLocated;;
1115 let user_uri_choice ~title ~msg uris =
1118 [] -> raise NoObjectsLocated
1122 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1127 String.sub uri 4 (String.length uri - 4)
1130 let locate_callback id =
1131 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1132 let result = MQueryGenerator.locate id in
1135 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1138 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1140 output_html outputhtml html ;
1141 user_uri_choice ~title:"Ambiguous input."
1143 ("Ambiguous input \"" ^ id ^
1144 "\". Please, choose one interpetation:")
1149 let inputt = ((rendering_window ())#inputt : term_editor) in
1150 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1153 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1155 None -> raise NoChoice
1157 let uri = locate_callback input in
1161 output_html outputhtml
1162 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1165 let input_or_locate_uri ~title =
1166 let uri = ref None in
1169 ~width:400 ~modal:true ~title ~border_width:2 () in
1170 let vbox = GPack.vbox ~packing:window#add () in
1172 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1174 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1176 GEdit.entry ~editable:true
1177 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1179 GButton.button ~label:"Check"
1180 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1181 let _ = checkb#misc#set_sensitive false in
1183 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1185 GMisc.label ~text:"You can also enter an indentifier to locate:"
1186 ~packing:(hbox2#pack ~padding:5) () in
1188 GEdit.entry ~editable:true
1189 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1191 GButton.button ~label:"Locate"
1192 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1193 let _ = locateb#misc#set_sensitive false in
1195 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1197 GButton.button ~label:"Ok"
1198 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1199 let _ = okb#misc#set_sensitive false in
1201 GButton.button ~label:"Cancel"
1202 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1204 ignore (window#connect#destroy GMain.Main.quit) ;
1206 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1207 let check_callback () =
1208 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1209 let uri = "cic:" ^ manual_input#text in
1211 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1212 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1215 Getter.Unresolved ->
1216 output_html outputhtml
1217 ("<h1 color=\"Red\">URI " ^ uri ^
1218 " does not correspond to any object.</h1>") ;
1220 | UriManager.IllFormedUri _ ->
1221 output_html outputhtml
1222 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1225 output_html outputhtml
1226 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1230 (okb#connect#clicked
1232 if check_callback () then
1234 uri := Some manual_input#text ;
1238 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1240 (manual_input#connect#changed
1242 if manual_input#text = "" then
1244 checkb#misc#set_sensitive false ;
1245 okb#misc#set_sensitive false
1249 checkb#misc#set_sensitive true ;
1250 okb#misc#set_sensitive true
1253 (locate_input#connect#changed
1254 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1256 (locateb#connect#clicked
1258 let id = locate_input#text in
1259 manual_input#set_text (locate_callback id) ;
1260 locate_input#delete_text 0 (String.length id)
1263 GMain.Main.main () ;
1265 None -> raise NoChoice
1266 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1269 let locate_one_id id =
1270 let result = MQueryGenerator.locate id in
1274 wrong_xpointer_format_from_wrong_xpointer_format' uri
1276 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
1277 output_html (rendering_window ())#outputhtml html ;
1281 [UriManager.string_of_uri
1282 (input_or_locate_uri ~title:("URI matching \"" ^ id ^ "\" unknown."))]
1285 interactive_user_uri_choice
1286 ~selection_mode:`EXTENDED
1287 ~ok:"Try every selection."
1288 ~title:"Ambiguous input."
1290 ("Ambiguous input \"" ^ id ^
1291 "\". Please, choose one or more interpretations:")
1294 List.map cic_textual_parser_uri_of_string uris'
1297 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
1298 exception AmbiguousInput;;
1300 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
1301 let known_ids,resolve_id = !id_to_uris in
1307 if List.mem he known_ids then filter tl else he::(filter tl)
1311 (* for each id in dom' we get the list of uris associated to it *)
1312 let list_of_uris = List.map locate_one_id dom' in
1313 (* and now we compute the list of all possible assignments from id to uris *)
1315 let rec aux ids list_of_uris =
1316 match ids,list_of_uris with
1317 [],[] -> [resolve_id]
1318 | id::idtl,uris::uristl ->
1319 let resolves = aux idtl uristl in
1325 function id' -> if id = id' then Some uri else f id'
1329 | _,_ -> assert false
1331 aux dom' list_of_uris
1333 let tests_no = List.length resolve_ids in
1334 if tests_no > 1 then
1335 output_html (outputhtml ())
1336 ("<h1>Disambiguation phase started: " ^
1337 string_of_int (List.length resolve_ids) ^ " cases will be tried.") ;
1338 (* now we select only the ones that generates well-typed terms *)
1344 let metasenv',expr = mk_metasenv_and_expr resolve in
1346 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
1348 (CicTypeChecker.type_of_aux' metasenv context expr) ;
1349 resolve::(filter tl)
1356 match resolve_ids' with
1357 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
1358 | [resolve_id] -> resolve_id
1362 (function resolve ->
1366 match resolve id with
1367 None -> assert false
1370 CicTextualParser0.ConUri uri
1371 | CicTextualParser0.VarUri uri ->
1372 UriManager.string_of_uri uri
1373 | CicTextualParser0.IndTyUri (uri,tyno) ->
1374 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1375 string_of_int (tyno+1) ^ ")"
1376 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
1377 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1378 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
1382 let index = interactive_interpretation_choice choices in
1383 List.nth resolve_ids' index
1385 id_to_uris := known_ids @ dom', resolve_id' ;
1386 mk_metasenv_and_expr resolve_id'
1389 exception UriAlreadyInUse;;
1390 exception NotAUriToAConstant;;
1393 let inputt = ((rendering_window ())#inputt : term_editor) in
1394 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1395 let output = ((rendering_window ())#output : GMathView.math_view) in
1396 let notebook = (rendering_window ())#notebook in
1398 let chosen = ref false in
1399 let get_parsed = ref (function _ -> assert false) in
1400 let get_uri = ref (function _ -> assert false) in
1401 let non_empty_type = ref false in
1404 ~width:600 ~modal:true ~title:"New Proof or Definition"
1405 ~border_width:2 () in
1406 let vbox = GPack.vbox ~packing:window#add () in
1408 GPack.hbox ~border_width:0
1409 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1411 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1412 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1414 GEdit.entry ~editable:true
1415 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1417 GPack.hbox ~border_width:0
1418 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1420 GMisc.label ~text:"Enter the theorem or definition type:"
1421 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1422 let scrolled_window =
1423 GBin.scrolled_window ~border_width:5
1424 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1425 (* the content of the scrolled_window is moved below (see comment) *)
1427 GPack.hbox ~border_width:0
1428 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1430 GButton.button ~label:"Ok"
1431 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1432 let _ = okb#misc#set_sensitive false in
1434 GButton.button ~label:"Cancel"
1435 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1436 (* moved here to have visibility of the ok button *)
1438 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1439 ~isnotempty_callback:
1441 non_empty_type := b ;
1442 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1445 newinputt#set_term inputt#get_as_string ;
1448 uri_entry#connect#changed
1450 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1452 ignore (window#connect#destroy GMain.Main.quit) ;
1453 ignore (cancelb#connect#clicked window#destroy) ;
1455 (okb#connect#clicked
1459 let parsed = newinputt#get_term [] [] in
1460 let uristr = "cic:" ^ uri_entry#text in
1461 let uri = UriManager.uri_of_string uristr in
1462 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1463 raise NotAUriToAConstant
1467 ignore (Getter.resolve uri) ;
1468 raise UriAlreadyInUse
1470 Getter.Unresolved ->
1471 get_parsed := (function () -> parsed) ;
1472 get_uri := (function () -> uri) ;
1477 output_html outputhtml
1478 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1481 GMain.Main.main () ;
1484 let dom,mk_metasenv_and_expr = !get_parsed () in
1486 disambiguate_input [] [] dom mk_metasenv_and_expr
1488 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1489 ProofEngine.proof :=
1490 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1491 ProofEngine.goal := Some 1 ;
1492 refresh_sequent notebook ;
1493 refresh_proof output ;
1494 !save_set_sensitive true ;
1497 RefreshSequentException e ->
1498 output_html outputhtml
1499 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1500 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1501 | RefreshProofException e ->
1502 output_html outputhtml
1503 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1504 "proof: " ^ Printexc.to_string e ^ "</h1>")
1506 output_html outputhtml
1507 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1510 let check_term_in_scratch scratch_window metasenv context expr =
1512 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1513 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1514 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1515 scratch_window#show () ;
1516 scratch_window#mmlwidget#load_tree ~dom:mml
1519 print_endline ("? " ^ CicPp.ppterm expr) ;
1523 let check scratch_window () =
1524 let inputt = ((rendering_window ())#inputt : term_editor) in
1525 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1527 match !ProofEngine.proof with
1529 | Some (_,metasenv,_,_) -> metasenv
1531 let context,names_context =
1533 match !ProofEngine.goal with
1536 let (_,canonical_context,_) =
1537 List.find (function (m,_,_) -> m=metano) metasenv
1544 Some (n,_) -> Some n
1549 let dom,mk_metasenv_and_expr = inputt#get_term names_context metasenv in
1550 let (metasenv',expr) =
1551 disambiguate_input context metasenv dom mk_metasenv_and_expr
1553 check_term_in_scratch scratch_window metasenv' context expr
1556 output_html outputhtml
1557 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1561 (***********************)
1563 (***********************)
1565 let call_tactic tactic () =
1566 let notebook = (rendering_window ())#notebook in
1567 let output = ((rendering_window ())#output : GMathView.math_view) in
1568 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1569 let savedproof = !ProofEngine.proof in
1570 let savedgoal = !ProofEngine.goal in
1574 refresh_sequent notebook ;
1575 refresh_proof output
1577 RefreshSequentException e ->
1578 output_html outputhtml
1579 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1580 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1581 ProofEngine.proof := savedproof ;
1582 ProofEngine.goal := savedgoal ;
1583 refresh_sequent notebook
1584 | RefreshProofException e ->
1585 output_html outputhtml
1586 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1587 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1588 ProofEngine.proof := savedproof ;
1589 ProofEngine.goal := savedgoal ;
1590 refresh_sequent notebook ;
1591 refresh_proof output
1593 output_html outputhtml
1594 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1595 ProofEngine.proof := savedproof ;
1596 ProofEngine.goal := savedgoal ;
1600 let call_tactic_with_input tactic () =
1601 let notebook = (rendering_window ())#notebook in
1602 let output = ((rendering_window ())#output : GMathView.math_view) in
1603 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1604 let inputt = ((rendering_window ())#inputt : term_editor) in
1605 let savedproof = !ProofEngine.proof in
1606 let savedgoal = !ProofEngine.goal in
1607 let uri,metasenv,bo,ty =
1608 match !ProofEngine.proof with
1609 None -> assert false
1610 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1612 let canonical_context =
1613 match !ProofEngine.goal with
1614 None -> assert false
1616 let (_,canonical_context,_) =
1617 List.find (function (m,_,_) -> m=metano) metasenv
1624 Some (n,_) -> Some n
1629 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv in
1630 let (metasenv',expr) =
1631 disambiguate_input canonical_context metasenv dom mk_metasenv_and_expr
1633 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1635 refresh_sequent notebook ;
1636 refresh_proof output ;
1639 RefreshSequentException e ->
1640 output_html outputhtml
1641 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1642 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1643 ProofEngine.proof := savedproof ;
1644 ProofEngine.goal := savedgoal ;
1645 refresh_sequent notebook
1646 | RefreshProofException e ->
1647 output_html outputhtml
1648 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1649 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1650 ProofEngine.proof := savedproof ;
1651 ProofEngine.goal := savedgoal ;
1652 refresh_sequent notebook ;
1653 refresh_proof output
1655 output_html outputhtml
1656 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1657 ProofEngine.proof := savedproof ;
1658 ProofEngine.goal := savedgoal ;
1661 let call_tactic_with_goal_input tactic () =
1662 let module L = LogicalOperations in
1663 let module G = Gdome in
1664 let notebook = (rendering_window ())#notebook in
1665 let output = ((rendering_window ())#output : GMathView.math_view) in
1666 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1667 let savedproof = !ProofEngine.proof in
1668 let savedgoal = !ProofEngine.goal in
1669 match notebook#proofw#get_selection with
1672 ((node : Gdome.element)#getAttributeNS
1673 ~namespaceURI:helmns
1674 ~localName:(G.domString "xref"))#to_string
1676 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1680 match !current_goal_infos with
1681 Some (ids_to_terms, ids_to_father_ids,_) ->
1683 tactic (Hashtbl.find ids_to_terms id) ;
1684 refresh_sequent notebook ;
1685 refresh_proof output
1686 | None -> assert false (* "ERROR: No current term!!!" *)
1688 RefreshSequentException e ->
1689 output_html outputhtml
1690 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1691 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1692 ProofEngine.proof := savedproof ;
1693 ProofEngine.goal := savedgoal ;
1694 refresh_sequent notebook
1695 | RefreshProofException e ->
1696 output_html outputhtml
1697 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1698 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1699 ProofEngine.proof := savedproof ;
1700 ProofEngine.goal := savedgoal ;
1701 refresh_sequent notebook ;
1702 refresh_proof output
1704 output_html outputhtml
1705 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1706 ProofEngine.proof := savedproof ;
1707 ProofEngine.goal := savedgoal ;
1710 output_html outputhtml
1711 ("<h1 color=\"red\">No term selected</h1>")
1714 let call_tactic_with_input_and_goal_input tactic () =
1715 let module L = LogicalOperations in
1716 let module G = Gdome in
1717 let notebook = (rendering_window ())#notebook in
1718 let output = ((rendering_window ())#output : GMathView.math_view) in
1719 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1720 let inputt = ((rendering_window ())#inputt : term_editor) in
1721 let savedproof = !ProofEngine.proof in
1722 let savedgoal = !ProofEngine.goal in
1723 match notebook#proofw#get_selection with
1726 ((node : Gdome.element)#getAttributeNS
1727 ~namespaceURI:helmns
1728 ~localName:(G.domString "xref"))#to_string
1730 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1734 match !current_goal_infos with
1735 Some (ids_to_terms, ids_to_father_ids,_) ->
1737 let uri,metasenv,bo,ty =
1738 match !ProofEngine.proof with
1739 None -> assert false
1740 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1742 let canonical_context =
1743 match !ProofEngine.goal with
1744 None -> assert false
1746 let (_,canonical_context,_) =
1747 List.find (function (m,_,_) -> m=metano) metasenv
1749 canonical_context in
1753 Some (n,_) -> Some n
1757 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv
1759 let (metasenv',expr) =
1760 disambiguate_input canonical_context metasenv dom
1761 mk_metasenv_and_expr
1763 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1764 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
1766 refresh_sequent notebook ;
1767 refresh_proof output ;
1769 | None -> assert false (* "ERROR: No current term!!!" *)
1771 RefreshSequentException e ->
1772 output_html outputhtml
1773 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1774 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1775 ProofEngine.proof := savedproof ;
1776 ProofEngine.goal := savedgoal ;
1777 refresh_sequent notebook
1778 | RefreshProofException e ->
1779 output_html outputhtml
1780 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1781 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1782 ProofEngine.proof := savedproof ;
1783 ProofEngine.goal := savedgoal ;
1784 refresh_sequent notebook ;
1785 refresh_proof output
1787 output_html outputhtml
1788 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1789 ProofEngine.proof := savedproof ;
1790 ProofEngine.goal := savedgoal ;
1793 output_html outputhtml
1794 ("<h1 color=\"red\">No term selected</h1>")
1797 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
1798 let module L = LogicalOperations in
1799 let module G = Gdome in
1800 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
1801 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1802 let savedproof = !ProofEngine.proof in
1803 let savedgoal = !ProofEngine.goal in
1804 match mmlwidget#get_selection with
1807 ((node : Gdome.element)#getAttributeNS
1808 ~namespaceURI:helmns
1809 ~localName:(G.domString "xref"))#to_string
1811 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1815 match !current_scratch_infos with
1816 (* term is the whole goal in the scratch_area *)
1817 Some (term,ids_to_terms, ids_to_father_ids,_) ->
1819 let expr = tactic term (Hashtbl.find ids_to_terms id) in
1820 let mml = mml_of_cic_term 111 expr in
1821 scratch_window#show () ;
1822 scratch_window#mmlwidget#load_tree ~dom:mml
1823 | None -> assert false (* "ERROR: No current term!!!" *)
1826 output_html outputhtml
1827 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1830 output_html outputhtml
1831 ("<h1 color=\"red\">No term selected</h1>")
1834 let call_tactic_with_hypothesis_input tactic () =
1835 let module L = LogicalOperations in
1836 let module G = Gdome in
1837 let notebook = (rendering_window ())#notebook in
1838 let output = ((rendering_window ())#output : GMathView.math_view) in
1839 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1840 let savedproof = !ProofEngine.proof in
1841 let savedgoal = !ProofEngine.goal in
1842 match notebook#proofw#get_selection with
1845 ((node : Gdome.element)#getAttributeNS
1846 ~namespaceURI:helmns
1847 ~localName:(G.domString "xref"))#to_string
1849 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1853 match !current_goal_infos with
1854 Some (_,_,ids_to_hypotheses) ->
1856 tactic (Hashtbl.find ids_to_hypotheses id) ;
1857 refresh_sequent notebook ;
1858 refresh_proof output
1859 | None -> assert false (* "ERROR: No current term!!!" *)
1861 RefreshSequentException e ->
1862 output_html outputhtml
1863 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1864 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1865 ProofEngine.proof := savedproof ;
1866 ProofEngine.goal := savedgoal ;
1867 refresh_sequent notebook
1868 | RefreshProofException e ->
1869 output_html outputhtml
1870 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1871 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1872 ProofEngine.proof := savedproof ;
1873 ProofEngine.goal := savedgoal ;
1874 refresh_sequent notebook ;
1875 refresh_proof output
1877 output_html outputhtml
1878 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1879 ProofEngine.proof := savedproof ;
1880 ProofEngine.goal := savedgoal ;
1883 output_html outputhtml
1884 ("<h1 color=\"red\">No term selected</h1>")
1888 let intros = call_tactic ProofEngine.intros;;
1889 let exact = call_tactic_with_input ProofEngine.exact;;
1890 let apply = call_tactic_with_input ProofEngine.apply;;
1891 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
1892 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
1893 let whd = call_tactic_with_goal_input ProofEngine.whd;;
1894 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
1895 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
1896 let fold = call_tactic_with_input ProofEngine.fold;;
1897 let cut = call_tactic_with_input ProofEngine.cut;;
1898 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
1899 let letin = call_tactic_with_input ProofEngine.letin;;
1900 let ring = call_tactic ProofEngine.ring;;
1901 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
1902 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
1903 let fourier = call_tactic ProofEngine.fourier;;
1904 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
1905 let reflexivity = call_tactic ProofEngine.reflexivity;;
1906 let symmetry = call_tactic ProofEngine.symmetry;;
1907 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
1908 let left = call_tactic ProofEngine.left;;
1909 let right = call_tactic ProofEngine.right;;
1910 let assumption = call_tactic ProofEngine.assumption;;
1912 let whd_in_scratch scratch_window =
1913 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
1916 let reduce_in_scratch scratch_window =
1917 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1920 let simpl_in_scratch scratch_window =
1921 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1927 (**********************)
1928 (* END OF TACTICS *)
1929 (**********************)
1933 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1935 show_in_show_window (input_or_locate_uri ~title:"Show")
1938 output_html outputhtml
1939 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1942 exception NotADefinition;;
1945 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1946 let output = ((rendering_window ())#output : GMathView.math_view) in
1947 let notebook = (rendering_window ())#notebook in
1949 let uri = input_or_locate_uri ~title:"Open" in
1950 CicTypeChecker.typecheck uri ;
1951 let metasenv,bo,ty =
1952 match CicEnvironment.get_cooked_obj uri with
1953 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1954 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1957 | Cic.InductiveDefinition _ -> raise NotADefinition
1959 ProofEngine.proof :=
1960 Some (uri, metasenv, bo, ty) ;
1961 ProofEngine.goal := None ;
1962 refresh_sequent notebook ;
1963 refresh_proof output
1965 RefreshSequentException e ->
1966 output_html outputhtml
1967 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1968 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1969 | RefreshProofException e ->
1970 output_html outputhtml
1971 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1972 "proof: " ^ Printexc.to_string e ^ "</h1>")
1974 output_html outputhtml
1975 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1979 let searchPattern () =
1980 let inputt = ((rendering_window ())#inputt : term_editor) in
1981 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1983 let rec get_level ?(last_invalid=false) () =
1985 GToolbox.input_string
1986 ~title:"Insert the strictness parameter for the query:"
1987 ((if last_invalid then
1988 "Invalid input (must be a non-negative natural number). Insert again "
1991 ) ^ "the strictness parameter for the query:")
1993 None -> raise NoChoice
1998 _ -> get_level ~last_invalid:true ()
2000 let level = get_level () in
2002 match !ProofEngine.proof with
2003 None -> assert false
2004 | Some (_,metasenv,_,_) -> metasenv
2006 match !ProofEngine.goal with
2009 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2010 let result = MQueryGenerator.searchPattern metasenv ey ty level in
2014 wrong_xpointer_format_from_wrong_xpointer_format' uri
2017 " <h1>Backward Query: </h1>" ^
2018 " <h2>Levels: </h2> " ^
2019 MQueryGenerator.string_of_levels
2020 (MQueryGenerator.levels_of_term metasenv ey ty) "<br>" ^
2021 " <pre>" ^ get_last_query result ^ "</pre>"
2023 output_html outputhtml html ;
2025 let rec filter_out =
2029 let tl',exc = filter_out tl in
2032 ProofEngine.can_apply
2033 (term_of_cic_textual_parser_uri
2034 (cic_textual_parser_uri_of_string uri))
2042 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2043 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2050 " <h1>Objects that can actually be applied: </h1> " ^
2051 String.concat "<br>" uris' ^ exc ^
2052 " <h1>Number of false matches: " ^
2053 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2054 " <h1>Number of good matches: " ^
2055 string_of_int (List.length uris') ^ "</h1>"
2057 output_html outputhtml html' ;
2059 user_uri_choice ~title:"Ambiguous input."
2061 "Many lemmas can be successfully applied. Please, choose one:"
2064 inputt#set_term uri' ;
2068 output_html outputhtml
2069 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2072 let choose_selection
2073 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
2075 let module G = Gdome in
2076 let rec aux element =
2077 if element#hasAttributeNS
2078 ~namespaceURI:helmns
2079 ~localName:(G.domString "xref")
2081 mmlwidget#set_selection (Some element)
2083 match element#get_parentNode with
2084 None -> assert false
2085 (*CSC: OCAML DIVERGES!
2086 | Some p -> aux (new G.element_of_node p)
2088 | Some p -> aux (new Gdome.element_of_node p)
2092 | None -> mmlwidget#set_selection None
2095 (* STUFF TO BUILD THE GTK INTERFACE *)
2097 (* Stuff for the widget settings *)
2099 let export_to_postscript (output : GMathView.math_view) =
2100 let lastdir = ref (Unix.getcwd ()) in
2103 GToolbox.select_file ~title:"Export to PostScript"
2104 ~dir:lastdir ~filename:"screenshot.ps" ()
2108 output#export_to_postscript ~filename:filename ();
2111 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
2112 button_set_kerning button_set_transparency export_to_postscript_menu_item
2115 let is_set = button_t1#active in
2116 output#set_font_manager_type
2117 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2120 button_set_anti_aliasing#misc#set_sensitive true ;
2121 button_set_kerning#misc#set_sensitive true ;
2122 button_set_transparency#misc#set_sensitive true ;
2123 export_to_postscript_menu_item#misc#set_sensitive true ;
2127 button_set_anti_aliasing#misc#set_sensitive false ;
2128 button_set_kerning#misc#set_sensitive false ;
2129 button_set_transparency#misc#set_sensitive false ;
2130 export_to_postscript_menu_item#misc#set_sensitive false ;
2134 let set_anti_aliasing output button_set_anti_aliasing () =
2135 output#set_anti_aliasing button_set_anti_aliasing#active
2138 let set_kerning output button_set_kerning () =
2139 output#set_kerning button_set_kerning#active
2142 let set_transparency output button_set_transparency () =
2143 output#set_transparency button_set_transparency#active
2146 let changefont output font_size_spinb () =
2147 output#set_font_size font_size_spinb#value_as_int
2150 let set_log_verbosity output log_verbosity_spinb () =
2151 output#set_log_verbosity log_verbosity_spinb#value_as_int
2154 class settings_window (output : GMathView.math_view) sw
2155 export_to_postscript_menu_item selection_changed_callback
2157 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2159 GPack.vbox ~packing:settings_window#add () in
2162 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2163 ~border_width:5 ~packing:vbox#add () in
2165 GButton.toggle_button ~label:"activate t1 fonts"
2166 ~packing:(table#attach ~left:0 ~top:0) () in
2167 let button_set_anti_aliasing =
2168 GButton.toggle_button ~label:"set_anti_aliasing"
2169 ~packing:(table#attach ~left:0 ~top:1) () in
2170 let button_set_kerning =
2171 GButton.toggle_button ~label:"set_kerning"
2172 ~packing:(table#attach ~left:1 ~top:1) () in
2173 let button_set_transparency =
2174 GButton.toggle_button ~label:"set_transparency"
2175 ~packing:(table#attach ~left:2 ~top:1) () in
2178 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2179 ~border_width:5 ~packing:vbox#add () in
2180 let font_size_label =
2181 GMisc.label ~text:"font size:"
2182 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2183 let font_size_spinb =
2185 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2188 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2189 let log_verbosity_label =
2190 GMisc.label ~text:"log verbosity:"
2191 ~packing:(table#attach ~left:0 ~top:1) () in
2192 let log_verbosity_spinb =
2194 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2197 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2199 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2201 GButton.button ~label:"Close"
2202 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2204 method show = settings_window#show
2206 button_set_anti_aliasing#misc#set_sensitive false ;
2207 button_set_kerning#misc#set_sensitive false ;
2208 button_set_transparency#misc#set_sensitive false ;
2209 (* Signals connection *)
2210 ignore(button_t1#connect#clicked
2211 (activate_t1 output button_set_anti_aliasing button_set_kerning
2212 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2213 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2214 ignore(button_set_anti_aliasing#connect#toggled
2215 (set_anti_aliasing output button_set_anti_aliasing));
2216 ignore(button_set_kerning#connect#toggled
2217 (set_kerning output button_set_kerning)) ;
2218 ignore(button_set_transparency#connect#toggled
2219 (set_transparency output button_set_transparency)) ;
2220 ignore(log_verbosity_spinb#connect#changed
2221 (set_log_verbosity output log_verbosity_spinb)) ;
2222 ignore(closeb#connect#clicked settings_window#misc#hide)
2225 (* Scratch window *)
2227 class scratch_window =
2229 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2231 GPack.vbox ~packing:window#add () in
2233 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2235 GButton.button ~label:"Whd"
2236 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2238 GButton.button ~label:"Reduce"
2239 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2241 GButton.button ~label:"Simpl"
2242 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2243 let scrolled_window =
2244 GBin.scrolled_window ~border_width:10
2245 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2248 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2250 method mmlwidget = mmlwidget
2251 method show () = window#misc#hide () ; window#show ()
2253 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2254 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2255 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2256 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2257 ignore(simplb#connect#clicked (simpl_in_scratch self))
2261 let vbox1 = GPack.vbox () in
2263 val mutable proofw_ref = None
2264 val mutable compute_ref = None
2266 Lazy.force self#compute ;
2267 match proofw_ref with
2268 None -> assert false
2269 | Some proofw -> proofw
2270 method content = vbox1
2272 match compute_ref with
2273 None -> assert false
2274 | Some compute -> compute
2278 let scrolled_window1 =
2279 GBin.scrolled_window ~border_width:10
2280 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2282 GMathView.math_view ~width:400 ~height:275
2283 ~packing:(scrolled_window1#add) () in
2284 let _ = proofw_ref <- Some proofw in
2286 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2288 GButton.button ~label:"Exact"
2289 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2291 GButton.button ~label:"Intros"
2292 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2294 GButton.button ~label:"Apply"
2295 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2296 let elimsimplintrosb =
2297 GButton.button ~label:"ElimSimplIntros"
2298 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2300 GButton.button ~label:"ElimType"
2301 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2303 GButton.button ~label:"Whd"
2304 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2306 GButton.button ~label:"Reduce"
2307 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2309 GButton.button ~label:"Simpl"
2310 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2312 GButton.button ~label:"Fold"
2313 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2315 GButton.button ~label:"Cut"
2316 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2318 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2320 GButton.button ~label:"Change"
2321 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2323 GButton.button ~label:"Let ... In"
2324 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2326 GButton.button ~label:"Ring"
2327 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2329 GButton.button ~label:"ClearBody"
2330 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2332 GButton.button ~label:"Clear"
2333 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2335 GButton.button ~label:"Fourier"
2336 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2338 GButton.button ~label:"RewriteSimpl ->"
2339 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2341 GButton.button ~label:"Reflexivity"
2342 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2344 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2346 GButton.button ~label:"Symmetry"
2347 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2349 GButton.button ~label:"Transitivity"
2350 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2352 GButton.button ~label:"Left"
2353 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2355 GButton.button ~label:"Right"
2356 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2358 GButton.button ~label:"Assumption"
2359 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2360 let searchpatternb =
2361 GButton.button ~label:"SearchPattern_Apply"
2362 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2363 ignore(exactb#connect#clicked exact) ;
2364 ignore(applyb#connect#clicked apply) ;
2365 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
2366 ignore(elimtypeb#connect#clicked elimtype) ;
2367 ignore(whdb#connect#clicked whd) ;
2368 ignore(reduceb#connect#clicked reduce) ;
2369 ignore(simplb#connect#clicked simpl) ;
2370 ignore(foldb#connect#clicked fold) ;
2371 ignore(cutb#connect#clicked cut) ;
2372 ignore(changeb#connect#clicked change) ;
2373 ignore(letinb#connect#clicked letin) ;
2374 ignore(ringb#connect#clicked ring) ;
2375 ignore(clearbodyb#connect#clicked clearbody) ;
2376 ignore(clearb#connect#clicked clear) ;
2377 ignore(fourierb#connect#clicked fourier) ;
2378 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
2379 ignore(reflexivityb#connect#clicked reflexivity) ;
2380 ignore(symmetryb#connect#clicked symmetry) ;
2381 ignore(transitivityb#connect#clicked transitivity) ;
2382 ignore(leftb#connect#clicked left) ;
2383 ignore(rightb#connect#clicked right) ;
2384 ignore(assumptionb#connect#clicked assumption) ;
2385 ignore(introsb#connect#clicked intros) ;
2386 ignore(searchpatternb#connect#clicked searchPattern) ;
2387 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2393 let vbox1 = GPack.vbox () in
2394 let scrolled_window1 =
2395 GBin.scrolled_window ~border_width:10
2396 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2398 GMathView.math_view ~width:400 ~height:275
2399 ~packing:(scrolled_window1#add) () in
2401 method proofw = (assert false : GMathView.math_view)
2402 method content = vbox1
2403 method compute = (assert false : unit)
2407 let empty_page = new empty_page;;
2411 val notebook = GPack.notebook ()
2413 val mutable skip_switch_page_event = false
2414 val mutable empty = true
2415 method notebook = notebook
2417 let new_page = new page () in
2419 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2420 notebook#append_page
2421 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2422 new_page#content#coerce
2423 method remove_all_pages ~skip_switch_page_event:skip =
2425 notebook#remove_page 0 (* let's remove the empty page *)
2427 List.iter (function _ -> notebook#remove_page 0) !pages ;
2429 skip_switch_page_event <- skip
2430 method set_current_page ~may_skip_switch_page_event n =
2431 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2432 let new_page = notebook#page_num page#content#coerce in
2433 if may_skip_switch_page_event && new_page <> notebook#current_page then
2434 skip_switch_page_event <- true ;
2435 notebook#goto_page new_page
2436 method set_empty_page =
2439 notebook#append_page
2440 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2441 empty_page#content#coerce
2443 let (_,_,page) = List.nth !pages notebook#current_page in
2447 (notebook#connect#switch_page
2449 let skip = skip_switch_page_event in
2450 skip_switch_page_event <- false ;
2453 let (metano,setgoal,page) = List.nth !pages i in
2454 ProofEngine.goal := Some metano ;
2455 Lazy.force (page#compute) ;
2464 class rendering_window output (notebook : notebook) =
2465 let scratch_window = new scratch_window in
2467 GWindow.window ~title:"MathML viewer" ~border_width:0
2468 ~allow_shrink:false () in
2469 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2471 let handle_box = GBin.handle_box ~border_width:2
2472 ~packing:(vbox_for_menu#pack ~padding:0) () in
2473 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
2474 let factory0 = new GMenu.factory menubar in
2475 let accel_group = factory0#accel_group in
2477 let file_menu = factory0#add_submenu "File" in
2478 let factory1 = new GMenu.factory file_menu ~accel_group in
2479 let export_to_postscript_menu_item =
2482 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
2485 let reopen_menu_item =
2486 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2490 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
2491 ignore (factory1#add_separator ()) ;
2493 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
2495 let save_menu_item =
2496 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
2499 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2500 ignore (!save_set_sensitive false);
2501 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2502 ignore (!qed_set_sensitive false);
2503 ignore (factory1#add_separator ()) ;
2504 let export_to_postscript_menu_item =
2505 factory1#add_item "Export to PostScript..."
2506 ~callback:(export_to_postscript output) in
2507 ignore (factory1#add_separator ()) ;
2509 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
2510 export_to_postscript_menu_item
2513 let edit_menu = factory0#add_submenu "Edit Current Proof" in
2514 let factory2 = new GMenu.factory edit_menu ~accel_group in
2515 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2516 let proveit_menu_item =
2517 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2518 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2520 let focus_menu_item =
2521 factory2#add_item "Focus" ~key:GdkKeysyms._F
2522 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2525 focus_and_proveit_set_sensitive :=
2527 proveit_menu_item#misc#set_sensitive b ;
2528 focus_menu_item#misc#set_sensitive b
2530 let _ = !focus_and_proveit_set_sensitive false in
2531 (* edit term menu *)
2532 let edit_term_menu = factory0#add_submenu "Edit Term" in
2533 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
2534 let check_menu_item =
2535 factory5#add_item "Check Term" ~key:GdkKeysyms._C
2536 ~callback:(check scratch_window) in
2537 let _ = check_menu_item#misc#set_sensitive false in
2539 let settings_menu = factory0#add_submenu "Search" in
2540 let factory4 = new GMenu.factory settings_menu ~accel_group in
2542 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2544 let show_menu_item =
2545 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2548 let settings_menu = factory0#add_submenu "Settings" in
2549 let factory3 = new GMenu.factory settings_menu ~accel_group in
2551 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2552 ~callback:edit_aliases in
2553 let _ = factory3#add_separator () in
2555 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2556 ~callback:(function _ -> (settings_window ())#show ()) in
2558 let _ = window#add_accel_group accel_group in
2562 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2564 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2565 let scrolled_window0 =
2566 GBin.scrolled_window ~border_width:10
2567 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2568 let _ = scrolled_window0#add output#coerce in
2570 GBin.frame ~label:"Insert Term"
2571 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2572 let scrolled_window1 =
2573 GBin.scrolled_window ~border_width:5
2574 ~packing:frame#add () in
2576 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add ()
2577 ~isnotempty_callback:check_menu_item#misc#set_sensitive in
2579 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2581 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2583 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2587 ~source:"<html><body bgColor=\"white\"></body></html>"
2588 ~width:400 ~height: 100
2593 method outputhtml = outputhtml
2594 method inputt = inputt
2595 method output = (output : GMathView.math_view)
2596 method notebook = notebook
2597 method show = window#show
2599 notebook#set_empty_page ;
2600 export_to_postscript_menu_item#misc#set_sensitive false ;
2601 check_term := (check_term_in_scratch scratch_window) ;
2603 (* signal handlers here *)
2604 ignore(output#connect#selection_changed
2606 choose_selection output elem ;
2607 !focus_and_proveit_set_sensitive true
2609 ignore (output#connect#clicked (show_in_show_window_callback output)) ;
2610 let settings_window = new settings_window output scrolled_window0
2611 export_to_postscript_menu_item (choose_selection output) in
2612 set_settings_window settings_window ;
2613 set_outputhtml outputhtml ;
2614 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2615 Logger.log_callback :=
2616 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2621 let initialize_everything () =
2622 let module U = Unix in
2623 let output = GMathView.math_view ~width:350 ~height:280 () in
2624 let notebook = new notebook in
2625 let rendering_window' = new rendering_window output notebook in
2626 set_rendering_window rendering_window' ;
2627 mml_of_cic_term_ref := mml_of_cic_term ;
2628 rendering_window'#show () ;
2634 Mqint.init "dbname=helm_mowgli" ;
2635 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
2636 ignore (GtkMain.Main.init ()) ;
2637 initialize_everything () ;
2638 if !usedb then Mqint.close ();