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 ""
156 let cic_textual_parser_uri_of_string uri' =
158 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
159 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
161 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
162 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
166 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
167 CicTextualParser0.IndTyUri (uri'',typeno)
170 (* Constructor of an Inductive Type *)
171 let uri'',typeno,consno =
172 CicTextualLexer.indconuri_of_uri uri'
174 CicTextualParser0.IndConUri (uri'',typeno,consno)
178 let term_of_cic_textual_parser_uri uri =
179 let module C = Cic in
180 let module CTP = CicTextualParser0 in
182 CTP.ConUri uri -> C.Const (uri,[])
183 | CTP.VarUri uri -> C.Var (uri,[])
184 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
185 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
188 let string_of_cic_textual_parser_uri uri =
189 let module C = Cic in
190 let module CTP = CicTextualParser0 in
193 CTP.ConUri uri -> UriManager.string_of_uri uri
194 | CTP.VarUri uri -> UriManager.string_of_uri uri
195 | CTP.IndTyUri (uri,tyno) ->
196 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
197 | CTP.IndConUri (uri,tyno,consno) ->
198 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
201 (* 4 = String.length "cic:" *)
202 String.sub uri' 4 (String.length uri' - 4)
205 let output_html outputhtml msg =
206 htmlheader_and_content := !htmlheader_and_content ^ msg ;
207 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
208 outputhtml#set_topline (-1)
211 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
215 let check_window outputhtml uris =
218 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
220 GPack.notebook ~scrollable:true ~packing:window#add () in
225 let scrolled_window =
226 GBin.scrolled_window ~border_width:10
228 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
234 ~packing:scrolled_window#add ~width:400 ~height:280 () in
237 term_of_cic_textual_parser_uri (cic_textual_parser_uri_of_string uri)
239 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
242 let mml = !mml_of_cic_term_ref 111 expr in
243 prerr_endline ("### " ^ CicPp.ppterm expr) ;
244 mmlwidget#load_tree ~dom:mml
247 output_html outputhtml
248 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
253 (notebook#connect#switch_page
254 (function i -> Lazy.force (List.nth render_terms i)))
260 interactive_user_uri_choice ~selection_mode ?(ok="Ok") ~title ~msg uris
262 let choices = ref [] in
263 let chosen = ref false in
265 GWindow.dialog ~modal:true ~title ~width:600 () in
267 GMisc.label ~text:msg
268 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
269 let scrolled_window =
270 GBin.scrolled_window ~border_width:10
271 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
273 let expected_height = 18 * List.length uris in
274 let height = if expected_height > 400 then 400 else expected_height in
275 GList.clist ~columns:1 ~packing:scrolled_window#add
276 ~height ~selection_mode () in
277 let _ = List.map (function x -> clist#append [x]) uris in
279 GPack.hbox ~border_width:0
280 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
282 GMisc.label ~text:"None of the above. Try this one:"
283 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
285 GEdit.entry ~editable:true
286 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
288 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
290 GButton.button ~label:ok
291 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
292 let _ = okb#misc#set_sensitive false in
294 GButton.button ~label:"Check"
295 ~packing:(hbox#pack ~padding:5) () in
296 let _ = checkb#misc#set_sensitive false in
298 GButton.button ~label:"Abort"
299 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
301 let check_callback () =
302 assert (List.length !choices > 0) ;
303 check_window (outputhtml ()) !choices
305 ignore (window#connect#destroy GMain.Main.quit) ;
306 ignore (cancelb#connect#clicked window#destroy) ;
308 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
309 ignore (checkb#connect#clicked check_callback) ;
311 (clist#connect#select_row
312 (fun ~row ~column ~event ->
313 checkb#misc#set_sensitive true ;
314 okb#misc#set_sensitive true ;
315 choices := (List.nth uris row)::!choices)) ;
317 (clist#connect#unselect_row
318 (fun ~row ~column ~event ->
320 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
322 (manual_input#connect#changed
324 if manual_input#text = "" then
327 checkb#misc#set_sensitive false ;
328 okb#misc#set_sensitive false ;
329 clist#misc#set_sensitive true
333 choices := [manual_input#text] ;
334 clist#unselect_all () ;
335 checkb#misc#set_sensitive true ;
336 okb#misc#set_sensitive true ;
337 clist#misc#set_sensitive false
339 window#set_position `CENTER ;
342 if !chosen && List.length !choices > 0 then
348 let interactive_interpretation_choice interpretations =
349 let chosen = ref None in
352 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
353 let vbox = GPack.vbox ~packing:window#add () in
357 ("Ambiguous input since there are many well-typed interpretations." ^
358 " Please, choose one of them.")
359 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
361 GPack.notebook ~scrollable:true
362 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
365 (function interpretation ->
367 let expected_height = 18 * List.length interpretation in
368 let height = if expected_height > 400 then 400 else expected_height in
369 GList.clist ~columns:2 ~packing:notebook#append_page ~height
370 ~titles:["id" ; "URI"] ()
374 (function (id,uri) ->
375 let n = clist#append [id;uri] in
376 clist#set_row ~selectable:false n
379 clist#columns_autosize ()
382 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
384 GButton.button ~label:"Ok"
385 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
387 GButton.button ~label:"Abort"
388 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
390 ignore (window#connect#destroy GMain.Main.quit) ;
391 ignore (cancelb#connect#clicked window#destroy) ;
394 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
395 window#set_position `CENTER ;
399 None -> raise NoChoice
406 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
408 let query = ref "" in
409 MQueryGenerator.set_confirm_query
410 (function q -> query := MQueryUtil.text_of_query q ; true) ;
411 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
414 let register_alias (id,uri) =
415 let dom,resolve_id = !id_to_uris in
417 (if List.mem id dom then dom else id::dom),
418 function id' -> if id' = id then Some uri else resolve_id id'
421 let domImpl = Gdome.domImplementation ();;
423 let parseStyle name =
425 domImpl#createDocumentFromURI
427 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
429 ~uri:("styles/" ^ name) ()
431 Gdome_xslt.processStylesheet style
434 let d_c = parseStyle "drop_coercions.xsl";;
435 let tc1 = parseStyle "objtheorycontent.xsl";;
436 let hc2 = parseStyle "content_to_html.xsl";;
437 let l = parseStyle "link.xsl";;
439 let c1 = parseStyle "rootcontent.xsl";;
440 let g = parseStyle "genmmlid.xsl";;
441 let c2 = parseStyle "annotatedpres.xsl";;
444 let getterURL = Configuration.getter_url;;
445 let processorURL = Configuration.processor_url;;
447 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
448 let mml_args ~explode_all =
449 ("explodeall",(if explode_all then "true()" else "false()"))::
450 ["processorURL", "'" ^ processorURL ^ "'" ;
451 "getterURL", "'" ^ getterURL ^ "'" ;
452 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
453 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
454 "UNICODEvsSYMBOL", "'symbol'" ;
455 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
456 "encoding", "'iso-8859-1'" ;
457 "media-type", "'text/html'" ;
458 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
459 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
460 "naturalLanguage", "'yes'" ;
461 "annotations", "'no'" ;
462 "URLs_or_URIs", "'URIs'" ;
463 "topurl", "'http://phd.cs.unibo.it/helm'" ;
464 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
467 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
469 ["processorURL", "'" ^ processorURL ^ "'" ;
470 "getterURL", "'" ^ getterURL ^ "'" ;
471 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
472 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
473 "UNICODEvsSYMBOL", "'symbol'" ;
474 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
475 "encoding", "'iso-8859-1'" ;
476 "media-type", "'text/html'" ;
477 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
478 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
479 "naturalLanguage", "'no'" ;
480 "annotations", "'no'" ;
481 "explodeall", "true()" ;
482 "URLs_or_URIs", "'URIs'" ;
483 "topurl", "'http://phd.cs.unibo.it/helm'" ;
484 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
487 let parse_file filename =
488 let inch = open_in filename in
489 let rec read_lines () =
491 let line = input_line inch in
499 let applyStylesheets input styles args =
500 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
505 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
507 (*CSC: ????????????????? *)
509 Cic2Xml.print_object uri ~ids_to_inner_sorts annobj
512 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts
517 None -> Xml2Gdome.document_of_xml domImpl xml
519 Xml.pp xml (Some constanttypefile) ;
520 Xml2Gdome.document_of_xml domImpl bodyxml'
522 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
523 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
525 Xml.pp xmlinnertypes (Some innertypesfile) ;
526 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
533 exception RefreshSequentException of exn;;
534 exception RefreshProofException of exn;;
536 let refresh_proof (output : GMathView.math_view) =
538 let uri,currentproof =
539 match !ProofEngine.proof with
541 | Some (uri,metasenv,bo,ty) ->
542 !qed_set_sensitive (List.length metasenv = 0) ;
543 (*CSC: Wrong: [] is just plainly wrong *)
544 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
547 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
548 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
550 Cic2acic.acic_object_of_cic_object currentproof
553 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
556 output#load_tree mml ;
558 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
561 match !ProofEngine.proof with
563 | Some (uri,metasenv,bo,ty) ->
564 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
565 raise (RefreshProofException e)
568 let refresh_sequent ?(empty_notebook=true) notebook =
570 match !ProofEngine.goal with
572 if empty_notebook then
574 notebook#remove_all_pages ~skip_switch_page_event:false ;
575 notebook#set_empty_page
578 notebook#proofw#unload
581 match !ProofEngine.proof with
583 | Some (_,metasenv,_,_) -> metasenv
585 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
586 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
587 SequentPp.XmlPp.print_sequent metasenv currentsequent
589 let regenerate_notebook () =
590 let skip_switch_page_event =
592 (m,_,_)::_ when m = metano -> false
595 notebook#remove_all_pages ~skip_switch_page_event ;
596 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
598 if empty_notebook then
600 regenerate_notebook () ;
601 notebook#set_current_page ~may_skip_switch_page_event:false metano
605 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
607 applyStylesheets sequent_doc sequent_styles sequent_args
609 notebook#set_current_page ~may_skip_switch_page_event:true metano;
610 notebook#proofw#load_tree ~dom:sequent_mml
612 current_goal_infos :=
613 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
617 match !ProofEngine.goal with
622 match !ProofEngine.proof with
624 | Some (_,metasenv,_,_) -> metasenv
627 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
628 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
629 raise (RefreshSequentException e)
630 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
634 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
635 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
638 let mml_of_cic_term metano term =
640 match !ProofEngine.proof with
642 | Some (_,metasenv,_,_) -> metasenv
645 match !ProofEngine.goal with
648 let (_,canonical_context,_) =
649 List.find (function (m,_,_) -> m=metano) metasenv
653 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
654 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
657 Xml2Gdome.document_of_xml domImpl sequent_gdome
660 applyStylesheets sequent_doc sequent_styles sequent_args ;
662 current_scratch_infos :=
663 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
667 exception OpenConjecturesStillThere;;
668 exception WrongProof;;
671 match !ProofEngine.proof with
673 | Some (uri,[],bo,ty) ->
675 CicReduction.are_convertible []
676 (CicTypeChecker.type_of_aux' [] [] bo) ty
679 (*CSC: Wrong: [] is just plainly wrong *)
680 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
682 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
683 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
685 Cic2acic.acic_object_of_cic_object proof
688 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
691 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
694 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
699 | _ -> raise OpenConjecturesStillThere
703 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
704 let dtdname = "/home/tassi/miohelm/helm/dtd/cic.dtd";;
706 let dtdname = "/projects/helm/V7_mowgli/dtd/cic.dtd";;
709 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
710 match !ProofEngine.proof with
712 | Some (uri, metasenv, bo, ty) ->
714 (*CSC: Wrong: [] is just plainly wrong *)
715 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
717 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
718 Cic2acic.acic_object_of_cic_object currentproof
721 match Cic2Xml.print_object uri ~ids_to_inner_sorts acurrentproof with
722 xml,Some bodyxml -> xml,bodyxml
723 | _,None -> assert false
725 Xml.pp ~quiet:true xml (Some prooffiletype) ;
726 output_html outputhtml
727 ("<h1 color=\"Green\">Current proof type saved to " ^
728 prooffiletype ^ "</h1>") ;
729 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
730 output_html outputhtml
731 ("<h1 color=\"Green\">Current proof body saved to " ^
735 (* Used to typecheck the loaded proofs *)
736 let typecheck_loaded_proof metasenv bo ty =
737 let module T = CicTypeChecker in
740 (fun metasenv ((_,context,ty) as conj) ->
741 ignore (T.type_of_aux' metasenv context ty) ;
744 ignore (T.type_of_aux' metasenv [] ty) ;
745 ignore (T.type_of_aux' metasenv [] bo)
749 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
750 let output = ((rendering_window ())#output : GMathView.math_view) in
751 let notebook = (rendering_window ())#notebook in
753 let uri = UriManager.uri_of_string "cic:/dummy.con" in
754 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
755 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
756 typecheck_loaded_proof metasenv bo ty ;
758 Some (uri, metasenv, bo, ty) ;
762 | (metano,_,_)::_ -> Some metano
764 refresh_proof output ;
765 refresh_sequent notebook ;
766 output_html outputhtml
767 ("<h1 color=\"Green\">Current proof type loaded from " ^
768 prooffiletype ^ "</h1>") ;
769 output_html outputhtml
770 ("<h1 color=\"Green\">Current proof body loaded from " ^
771 prooffile ^ "</h1>") ;
772 !save_set_sensitive true
775 RefreshSequentException e ->
776 output_html outputhtml
777 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
778 "sequent: " ^ Printexc.to_string e ^ "</h1>")
779 | RefreshProofException e ->
780 output_html outputhtml
781 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
782 "proof: " ^ Printexc.to_string e ^ "</h1>")
784 output_html outputhtml
785 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
788 let edit_aliases () =
789 let inputt = ((rendering_window ())#inputt : GEdit.text) in
790 let dom,resolve_id = !id_to_uris in
791 let inputlen = inputt#length in
792 inputt#delete_text 0 inputlen ;
794 inputt#insert_text ~pos:0
799 match resolve_id v with
804 (string_of_cic_textual_parser_uri uri)
807 id_to_uris := empty_id_to_uris
811 let module L = LogicalOperations in
812 let module G = Gdome in
813 let notebook = (rendering_window ())#notebook in
814 let output = (rendering_window ())#output in
815 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
816 match (rendering_window ())#output#get_selection with
819 ((node : Gdome.element)#getAttributeNS
821 ((element : G.element)#getAttributeNS
824 ~localName:(G.domString "xref"))#to_string
826 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
830 match !current_cic_infos with
831 Some (ids_to_terms, ids_to_father_ids, _, _) ->
833 L.to_sequent id ids_to_terms ids_to_father_ids ;
834 refresh_proof output ;
835 refresh_sequent notebook
836 | None -> assert false (* "ERROR: No current term!!!" *)
838 RefreshSequentException e ->
839 output_html outputhtml
840 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
841 "sequent: " ^ Printexc.to_string e ^ "</h1>")
842 | RefreshProofException e ->
843 output_html outputhtml
844 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
845 "proof: " ^ Printexc.to_string e ^ "</h1>")
847 output_html outputhtml
848 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
850 | None -> assert false (* "ERROR: No selection!!!" *)
854 let module L = LogicalOperations in
855 let module G = Gdome in
856 let notebook = (rendering_window ())#notebook in
857 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
858 match (rendering_window ())#output#get_selection with
861 ((node : Gdome.element)#getAttributeNS
863 ((element : G.element)#getAttributeNS
866 ~localName:(G.domString "xref"))#to_string
868 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
872 match !current_cic_infos with
873 Some (ids_to_terms, ids_to_father_ids, _, _) ->
875 L.focus id ids_to_terms ids_to_father_ids ;
876 refresh_sequent notebook
877 | None -> assert false (* "ERROR: No current term!!!" *)
879 RefreshSequentException e ->
880 output_html outputhtml
881 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
882 "sequent: " ^ Printexc.to_string e ^ "</h1>")
883 | RefreshProofException e ->
884 output_html outputhtml
885 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
886 "proof: " ^ Printexc.to_string e ^ "</h1>")
888 output_html outputhtml
889 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
891 | None -> assert false (* "ERROR: No selection!!!" *)
894 exception NoPrevGoal;;
895 exception NoNextGoal;;
898 let module L = LogicalOperations in
899 let module G = Gdome in
900 let notebook = (rendering_window ())#notebook in
901 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
903 match !ProofEngine.proof with
905 | Some (_,metasenv,_,_) -> metasenv
908 refresh_sequent ~empty_notebook:false notebook
910 RefreshSequentException e ->
911 output_html outputhtml
912 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
913 "sequent: " ^ Printexc.to_string e ^ "</h1>")
915 output_html outputhtml
916 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
919 let show_in_show_window, show_in_show_window_callback =
921 GWindow.window ~width:800 ~border_width:2 () in
922 let scrolled_window =
923 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
925 GMathView.math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
926 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
927 let href = Gdome.domString "href" in
928 let show_in_show_window uri =
929 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
931 CicTypeChecker.typecheck uri ;
932 let obj = CicEnvironment.get_cooked_obj uri in
934 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
935 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
937 Cic2acic.acic_object_of_cic_object obj
940 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
943 window#set_title (UriManager.string_of_uri uri) ;
944 window#misc#hide () ; window#show () ;
945 mmlwidget#load_tree mml ;
948 output_html outputhtml
949 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
951 let show_in_show_window_callback mmlwidget (n : Gdome.element) =
952 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
954 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
956 show_in_show_window (UriManager.uri_of_string uri)
958 if mmlwidget#get_action <> None then
959 mmlwidget#action_toggle
962 mmlwidget#connect#clicked (show_in_show_window_callback mmlwidget)
964 show_in_show_window, show_in_show_window_callback
967 exception NoObjectsLocated;;
969 let user_uri_choice ~title ~msg uris =
972 [] -> raise NoObjectsLocated
976 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
981 String.sub uri 4 (String.length uri - 4)
984 let locate_callback id =
985 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
986 let result = MQueryGenerator.locate id in
989 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
992 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
994 output_html outputhtml html ;
995 user_uri_choice ~title:"Ambiguous input."
997 ("Ambiguous input \"" ^ id ^
998 "\". Please, choose one interpetation:")
1003 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1004 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1007 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1009 None -> raise NoChoice
1011 let uri = locate_callback input in
1012 inputt#delete_text 0 inputt#length ;
1013 ignore ((inputt#insert_text uri) ~pos:0)
1016 output_html outputhtml
1017 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1020 let input_or_locate_uri ~title =
1021 let uri = ref None in
1024 ~width:400 ~modal:true ~title ~border_width:2 () in
1025 let vbox = GPack.vbox ~packing:window#add () in
1027 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1029 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1031 GEdit.entry ~editable:true
1032 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1034 GButton.button ~label:"Check"
1035 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1036 let _ = checkb#misc#set_sensitive false in
1038 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1040 GMisc.label ~text:"You can also enter an indentifier to locate:"
1041 ~packing:(hbox2#pack ~padding:5) () in
1043 GEdit.entry ~editable:true
1044 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1046 GButton.button ~label:"Locate"
1047 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1048 let _ = locateb#misc#set_sensitive false in
1050 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1052 GButton.button ~label:"Ok"
1053 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1054 let _ = okb#misc#set_sensitive false in
1056 GButton.button ~label:"Cancel"
1057 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1059 ignore (window#connect#destroy GMain.Main.quit) ;
1061 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1062 let check_callback () =
1063 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1064 let uri = "cic:" ^ manual_input#text in
1066 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1067 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1070 Getter.Unresolved ->
1071 output_html outputhtml
1072 ("<h1 color=\"Red\">URI " ^ uri ^
1073 " does not correspond to any object.</h1>") ;
1075 | UriManager.IllFormedUri _ ->
1076 output_html outputhtml
1077 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1080 output_html outputhtml
1081 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1085 (okb#connect#clicked
1087 if check_callback () then
1089 uri := Some manual_input#text ;
1093 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1095 (manual_input#connect#changed
1097 if manual_input#text = "" then
1099 checkb#misc#set_sensitive false ;
1100 okb#misc#set_sensitive false
1104 checkb#misc#set_sensitive true ;
1105 okb#misc#set_sensitive true
1108 (locate_input#connect#changed
1109 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1111 (locateb#connect#clicked
1113 let id = locate_input#text in
1114 manual_input#set_text (locate_callback id) ;
1115 locate_input#delete_text 0 (String.length id)
1118 GMain.Main.main () ;
1120 None -> raise NoChoice
1121 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1124 let locate_one_id id =
1125 let result = MQueryGenerator.locate id in
1129 wrong_xpointer_format_from_wrong_xpointer_format' uri
1131 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
1132 output_html (rendering_window ())#outputhtml html ;
1136 [UriManager.string_of_uri
1137 (input_or_locate_uri ~title:("URI matching \"" ^ id ^ "\" unknown."))]
1140 interactive_user_uri_choice
1141 ~selection_mode:`EXTENDED
1142 ~ok:"Try every selection."
1143 ~title:"Ambiguous input."
1145 ("Ambiguous input \"" ^ id ^
1146 "\". Please, choose one or more interpretations:")
1149 List.map cic_textual_parser_uri_of_string uris'
1152 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
1153 exception AmbiguousInput;;
1155 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
1156 let known_ids,resolve_id = !id_to_uris in
1162 if List.mem he known_ids then filter tl else he::(filter tl)
1166 (* for each id in dom' we get the list of uris associated to it *)
1167 let list_of_uris = List.map locate_one_id dom' in
1168 (* and now we compute the list of all possible assignments from id to uris *)
1170 let rec aux ids list_of_uris =
1171 match ids,list_of_uris with
1172 [],[] -> [resolve_id]
1173 | id::idtl,uris::uristl ->
1174 let resolves = aux idtl uristl in
1180 function id' -> if id = id' then Some uri else f id'
1184 | _,_ -> assert false
1186 aux dom' list_of_uris
1188 let tests_no = List.length resolve_ids in
1189 if tests_no > 1 then
1190 output_html (outputhtml ())
1191 ("<h1>Disambiguation phase started: " ^
1192 string_of_int (List.length resolve_ids) ^ " cases will be tried.") ;
1193 (* now we select only the ones that generates well-typed terms *)
1199 let metasenv',expr = mk_metasenv_and_expr resolve in
1201 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
1203 (CicTypeChecker.type_of_aux' metasenv context expr) ;
1204 resolve::(filter tl)
1211 match resolve_ids' with
1212 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
1213 | [resolve_id] -> resolve_id
1217 (function resolve ->
1221 match resolve id with
1222 None -> assert false
1225 CicTextualParser0.ConUri uri
1226 | CicTextualParser0.VarUri uri ->
1227 UriManager.string_of_uri uri
1228 | CicTextualParser0.IndTyUri (uri,tyno) ->
1229 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1230 string_of_int (tyno+1) ^ ")"
1231 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
1232 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1233 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
1237 let index = interactive_interpretation_choice choices in
1238 List.nth resolve_ids' index
1240 id_to_uris := known_ids @ dom', resolve_id' ;
1241 mk_metasenv_and_expr resolve_id'
1245 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1246 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1247 let output = ((rendering_window ())#output : GMathView.math_view) in
1248 let notebook = (rendering_window ())#notebook in
1249 let inputlen = inputt#length in
1250 let input = inputt#get_chars 0 inputlen ^ "\n" in
1251 (* Do something interesting *)
1252 let lexbuf = Lexing.from_string input in
1255 (* Execute the actions *)
1257 CicTextualParserContext.main [] [] CicTextualLexer.token
1258 lexbuf register_alias
1261 | Some (dom,mk_metasenv_and_expr) ->
1263 disambiguate_input [] [] dom mk_metasenv_and_expr
1265 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1266 ProofEngine.proof :=
1267 Some (UriManager.uri_of_string "cic:/dummy.con",
1268 (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1269 ProofEngine.goal := Some 1 ;
1270 refresh_sequent notebook ;
1271 refresh_proof output ;
1272 !save_set_sensitive true
1275 CicTextualParser0.Eof ->
1276 inputt#delete_text 0 inputlen
1277 | RefreshSequentException e ->
1278 output_html outputhtml
1279 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1280 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1281 | RefreshProofException e ->
1282 output_html outputhtml
1283 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1284 "proof: " ^ Printexc.to_string e ^ "</h1>")
1286 output_html outputhtml
1287 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1290 let check_term_in_scratch scratch_window metasenv context expr =
1292 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1293 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1294 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1295 scratch_window#show () ;
1296 scratch_window#mmlwidget#load_tree ~dom:mml
1299 print_endline ("? " ^ CicPp.ppterm expr) ;
1303 let check scratch_window () =
1304 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1305 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1306 let inputlen = inputt#length in
1307 let input = inputt#get_chars 0 inputlen ^ "\n" in
1309 match !ProofEngine.proof with
1310 None -> UriManager.uri_of_string "cic:/dummy.con", []
1311 | Some (curi,metasenv,_,_) -> curi,metasenv
1313 let context,names_context =
1315 match !ProofEngine.goal with
1318 let (_,canonical_context,_) =
1319 List.find (function (m,_,_) -> m=metano) metasenv
1326 Some (n,_) -> Some n
1330 let lexbuf = Lexing.from_string input in
1333 (* Execute the actions *)
1335 CicTextualParserContext.main names_context metasenv CicTextualLexer.token
1336 lexbuf register_alias
1339 | Some (dom,mk_metasenv_and_expr) ->
1340 let (metasenv',expr) =
1341 disambiguate_input context metasenv dom mk_metasenv_and_expr
1343 check_term_in_scratch scratch_window metasenv' context expr
1346 CicTextualParser0.Eof -> ()
1348 output_html outputhtml
1349 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1353 (***********************)
1355 (***********************)
1357 let call_tactic tactic () =
1358 let notebook = (rendering_window ())#notebook in
1359 let output = ((rendering_window ())#output : GMathView.math_view) in
1360 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1361 let savedproof = !ProofEngine.proof in
1362 let savedgoal = !ProofEngine.goal in
1366 refresh_sequent notebook ;
1367 refresh_proof output
1369 RefreshSequentException e ->
1370 output_html outputhtml
1371 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1372 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1373 ProofEngine.proof := savedproof ;
1374 ProofEngine.goal := savedgoal ;
1375 refresh_sequent notebook
1376 | RefreshProofException e ->
1377 output_html outputhtml
1378 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1379 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1380 ProofEngine.proof := savedproof ;
1381 ProofEngine.goal := savedgoal ;
1382 refresh_sequent notebook ;
1383 refresh_proof output
1385 output_html outputhtml
1386 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1387 ProofEngine.proof := savedproof ;
1388 ProofEngine.goal := savedgoal ;
1392 let call_tactic_with_input tactic () =
1393 let notebook = (rendering_window ())#notebook in
1394 let output = ((rendering_window ())#output : GMathView.math_view) in
1395 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1396 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1397 let savedproof = !ProofEngine.proof in
1398 let savedgoal = !ProofEngine.goal in
1399 (*CSC: Gran cut&paste da sotto... *)
1400 let inputlen = inputt#length in
1401 let input = inputt#get_chars 0 inputlen ^ "\n" in
1402 let lexbuf = Lexing.from_string input in
1404 match !ProofEngine.proof with
1405 None -> assert false
1406 | Some (curi,_,_,_) -> curi
1408 let uri,metasenv,bo,ty =
1409 match !ProofEngine.proof with
1410 None -> assert false
1411 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1413 let canonical_context =
1414 match !ProofEngine.goal with
1415 None -> assert false
1417 let (_,canonical_context,_) =
1418 List.find (function (m,_,_) -> m=metano) metasenv
1425 Some (n,_) -> Some n
1432 CicTextualParserContext.main context metasenv CicTextualLexer.token
1433 lexbuf register_alias
1436 | Some (dom,mk_metasenv_and_expr) ->
1437 let (metasenv',expr) =
1438 disambiguate_input canonical_context metasenv dom
1439 mk_metasenv_and_expr
1441 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1443 refresh_sequent notebook ;
1444 refresh_proof output
1447 CicTextualParser0.Eof ->
1448 inputt#delete_text 0 inputlen
1449 | RefreshSequentException e ->
1450 output_html outputhtml
1451 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1452 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1453 ProofEngine.proof := savedproof ;
1454 ProofEngine.goal := savedgoal ;
1455 refresh_sequent notebook
1456 | RefreshProofException e ->
1457 output_html outputhtml
1458 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1459 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1460 ProofEngine.proof := savedproof ;
1461 ProofEngine.goal := savedgoal ;
1462 refresh_sequent notebook ;
1463 refresh_proof output
1465 output_html outputhtml
1466 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1467 ProofEngine.proof := savedproof ;
1468 ProofEngine.goal := savedgoal ;
1471 let call_tactic_with_goal_input tactic () =
1472 let module L = LogicalOperations in
1473 let module G = Gdome in
1474 let notebook = (rendering_window ())#notebook in
1475 let output = ((rendering_window ())#output : GMathView.math_view) in
1476 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1477 let savedproof = !ProofEngine.proof in
1478 let savedgoal = !ProofEngine.goal in
1479 match notebook#proofw#get_selection with
1482 ((node : Gdome.element)#getAttributeNS
1483 ~namespaceURI:helmns
1484 ~localName:(G.domString "xref"))#to_string
1486 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1490 match !current_goal_infos with
1491 Some (ids_to_terms, ids_to_father_ids,_) ->
1493 tactic (Hashtbl.find ids_to_terms id) ;
1494 refresh_sequent notebook ;
1495 refresh_proof output
1496 | None -> assert false (* "ERROR: No current term!!!" *)
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 ProofEngine.proof := savedproof ;
1503 ProofEngine.goal := savedgoal ;
1504 refresh_sequent notebook
1505 | RefreshProofException e ->
1506 output_html outputhtml
1507 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1508 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1509 ProofEngine.proof := savedproof ;
1510 ProofEngine.goal := savedgoal ;
1511 refresh_sequent notebook ;
1512 refresh_proof output
1514 output_html outputhtml
1515 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1516 ProofEngine.proof := savedproof ;
1517 ProofEngine.goal := savedgoal ;
1520 output_html outputhtml
1521 ("<h1 color=\"red\">No term selected</h1>")
1524 let call_tactic_with_input_and_goal_input tactic () =
1525 let module L = LogicalOperations in
1526 let module G = Gdome in
1527 let notebook = (rendering_window ())#notebook in
1528 let output = ((rendering_window ())#output : GMathView.math_view) in
1529 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1530 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1531 let savedproof = !ProofEngine.proof in
1532 let savedgoal = !ProofEngine.goal in
1533 match notebook#proofw#get_selection with
1536 ((node : Gdome.element)#getAttributeNS
1537 ~namespaceURI:helmns
1538 ~localName:(G.domString "xref"))#to_string
1540 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1544 match !current_goal_infos with
1545 Some (ids_to_terms, ids_to_father_ids,_) ->
1547 (* Let's parse the input *)
1548 let inputlen = inputt#length in
1549 let input = inputt#get_chars 0 inputlen ^ "\n" in
1550 let lexbuf = Lexing.from_string input in
1552 match !ProofEngine.proof with
1553 None -> assert false
1554 | Some (curi,_,_,_) -> curi
1556 let uri,metasenv,bo,ty =
1557 match !ProofEngine.proof with
1558 None -> assert false
1559 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1561 let canonical_context =
1562 match !ProofEngine.goal with
1563 None -> assert false
1565 let (_,canonical_context,_) =
1566 List.find (function (m,_,_) -> m=metano) metasenv
1568 canonical_context in
1572 Some (n,_) -> Some n
1580 CicTextualParserContext.main context metasenv
1581 CicTextualLexer.token lexbuf register_alias
1584 | Some (dom,mk_metasenv_and_expr) ->
1585 let (metasenv',expr) =
1586 disambiguate_input canonical_context metasenv dom
1587 mk_metasenv_and_expr
1589 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1590 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
1592 refresh_sequent notebook ;
1593 refresh_proof output
1596 CicTextualParser0.Eof ->
1597 inputt#delete_text 0 inputlen
1599 | None -> assert false (* "ERROR: No current term!!!" *)
1601 RefreshSequentException e ->
1602 output_html outputhtml
1603 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1604 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1605 ProofEngine.proof := savedproof ;
1606 ProofEngine.goal := savedgoal ;
1607 refresh_sequent notebook
1608 | RefreshProofException e ->
1609 output_html outputhtml
1610 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1611 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1612 ProofEngine.proof := savedproof ;
1613 ProofEngine.goal := savedgoal ;
1614 refresh_sequent notebook ;
1615 refresh_proof output
1617 output_html outputhtml
1618 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1619 ProofEngine.proof := savedproof ;
1620 ProofEngine.goal := savedgoal ;
1623 output_html outputhtml
1624 ("<h1 color=\"red\">No term selected</h1>")
1627 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
1628 let module L = LogicalOperations in
1629 let module G = Gdome in
1630 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
1631 let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
1632 let savedproof = !ProofEngine.proof in
1633 let savedgoal = !ProofEngine.goal in
1634 match mmlwidget#get_selection with
1637 ((node : Gdome.element)#getAttributeNS
1638 ~namespaceURI:helmns
1639 ~localName:(G.domString "xref"))#to_string
1641 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1645 match !current_scratch_infos with
1646 (* term is the whole goal in the scratch_area *)
1647 Some (term,ids_to_terms, ids_to_father_ids,_) ->
1649 let expr = tactic term (Hashtbl.find ids_to_terms id) in
1650 let mml = mml_of_cic_term 111 expr in
1651 scratch_window#show () ;
1652 scratch_window#mmlwidget#load_tree ~dom:mml
1653 | None -> assert false (* "ERROR: No current term!!!" *)
1656 output_html outputhtml
1657 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1660 output_html outputhtml
1661 ("<h1 color=\"red\">No term selected</h1>")
1664 let call_tactic_with_hypothesis_input tactic () =
1665 let module L = LogicalOperations in
1666 let module G = Gdome in
1667 let notebook = (rendering_window ())#notebook in
1668 let output = ((rendering_window ())#output : GMathView.math_view) in
1669 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1670 let savedproof = !ProofEngine.proof in
1671 let savedgoal = !ProofEngine.goal in
1672 match notebook#proofw#get_selection with
1675 ((node : Gdome.element)#getAttributeNS
1676 ~namespaceURI:helmns
1677 ~localName:(G.domString "xref"))#to_string
1679 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1683 match !current_goal_infos with
1684 Some (_,_,ids_to_hypotheses) ->
1686 tactic (Hashtbl.find ids_to_hypotheses id) ;
1687 refresh_sequent notebook ;
1688 refresh_proof output
1689 | None -> assert false (* "ERROR: No current term!!!" *)
1691 RefreshSequentException e ->
1692 output_html outputhtml
1693 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1694 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1695 ProofEngine.proof := savedproof ;
1696 ProofEngine.goal := savedgoal ;
1697 refresh_sequent notebook
1698 | RefreshProofException e ->
1699 output_html outputhtml
1700 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1701 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1702 ProofEngine.proof := savedproof ;
1703 ProofEngine.goal := savedgoal ;
1704 refresh_sequent notebook ;
1705 refresh_proof output
1707 output_html outputhtml
1708 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1709 ProofEngine.proof := savedproof ;
1710 ProofEngine.goal := savedgoal ;
1713 output_html outputhtml
1714 ("<h1 color=\"red\">No term selected</h1>")
1718 let intros = call_tactic ProofEngine.intros;;
1719 let exact = call_tactic_with_input ProofEngine.exact;;
1720 let apply = call_tactic_with_input ProofEngine.apply;;
1721 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
1722 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
1723 let whd = call_tactic_with_goal_input ProofEngine.whd;;
1724 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
1725 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
1726 let fold = call_tactic_with_input ProofEngine.fold;;
1727 let cut = call_tactic_with_input ProofEngine.cut;;
1728 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
1729 let letin = call_tactic_with_input ProofEngine.letin;;
1730 let ring = call_tactic ProofEngine.ring;;
1731 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
1732 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
1733 let fourier = call_tactic ProofEngine.fourier;;
1734 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
1735 let reflexivity = call_tactic ProofEngine.reflexivity;;
1736 let symmetry = call_tactic ProofEngine.symmetry;;
1737 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
1738 let left = call_tactic ProofEngine.left;;
1739 let right = call_tactic ProofEngine.right;;
1740 let assumption = call_tactic ProofEngine.assumption;;
1742 let whd_in_scratch scratch_window =
1743 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
1746 let reduce_in_scratch scratch_window =
1747 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1750 let simpl_in_scratch scratch_window =
1751 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1757 (**********************)
1758 (* END OF TACTICS *)
1759 (**********************)
1763 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1765 show_in_show_window (input_or_locate_uri ~title:"Show")
1768 output_html outputhtml
1769 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1772 exception NotADefinition;;
1775 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1776 let output = ((rendering_window ())#output : GMathView.math_view) in
1777 let notebook = (rendering_window ())#notebook in
1779 let uri = input_or_locate_uri ~title:"Open" in
1780 CicTypeChecker.typecheck uri ;
1781 let metasenv,bo,ty =
1782 match CicEnvironment.get_cooked_obj uri with
1783 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1784 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1787 | Cic.InductiveDefinition _ -> raise NotADefinition
1789 ProofEngine.proof :=
1790 Some (uri, metasenv, bo, ty) ;
1791 ProofEngine.goal := None ;
1792 refresh_sequent notebook ;
1793 refresh_proof output
1795 RefreshSequentException e ->
1796 output_html outputhtml
1797 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1798 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1799 | RefreshProofException e ->
1800 output_html outputhtml
1801 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1802 "proof: " ^ Printexc.to_string e ^ "</h1>")
1804 output_html outputhtml
1805 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1809 let searchPattern () =
1810 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1811 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1813 let rec get_level ?(last_invalid=false) () =
1815 GToolbox.input_string
1816 ~title:"Insert the strictness parameter for the query:"
1817 ((if last_invalid then
1818 "Invalid input (must be a non-negative natural number). Insert again "
1821 ) ^ "the strictness parameter for the query:")
1823 None -> raise NoChoice
1828 _ -> get_level ~last_invalid:true ()
1830 let level = get_level () in
1832 match !ProofEngine.proof with
1833 None -> assert false
1834 | Some (_,metasenv,_,_) -> metasenv
1836 match !ProofEngine.goal with
1839 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
1840 let result = MQueryGenerator.searchPattern metasenv ey ty level in
1844 wrong_xpointer_format_from_wrong_xpointer_format' uri
1847 " <h1>Backward Query: </h1>" ^
1848 " <h2>Levels: </h2> " ^
1849 MQueryGenerator.string_of_levels
1850 (MQueryGenerator.levels_of_term metasenv ey ty) "<br>" ^
1851 " <pre>" ^ get_last_query result ^ "</pre>"
1853 output_html outputhtml html ;
1855 let rec filter_out =
1859 let tl',exc = filter_out tl in
1862 ProofEngine.can_apply
1863 (term_of_cic_textual_parser_uri
1864 (cic_textual_parser_uri_of_string uri))
1872 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
1873 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
1880 " <h1>Objects that can actually be applied: </h1> " ^
1881 String.concat "<br>" uris' ^ exc ^
1882 " <h1>Number of false matches: " ^
1883 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
1884 " <h1>Number of good matches: " ^
1885 string_of_int (List.length uris') ^ "</h1>"
1887 output_html outputhtml html' ;
1889 user_uri_choice ~title:"Ambiguous input."
1891 "Many lemmas can be successfully applied. Please, choose one:"
1894 inputt#delete_text 0 inputt#length ;
1895 ignore ((inputt#insert_text uri') ~pos:0) ;
1899 output_html outputhtml
1900 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1903 let choose_selection
1904 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
1906 let module G = Gdome in
1907 let rec aux element =
1908 if element#hasAttributeNS
1909 ~namespaceURI:helmns
1910 ~localName:(G.domString "xref")
1912 mmlwidget#set_selection (Some element)
1914 match element#get_parentNode with
1915 None -> assert false
1916 (*CSC: OCAML DIVERGES!
1917 | Some p -> aux (new G.element_of_node p)
1919 | Some p -> aux (new Gdome.element_of_node p)
1923 | None -> mmlwidget#set_selection None
1926 (* STUFF TO BUILD THE GTK INTERFACE *)
1928 (* Stuff for the widget settings *)
1930 let export_to_postscript (output : GMathView.math_view) =
1931 let lastdir = ref (Unix.getcwd ()) in
1934 GToolbox.select_file ~title:"Export to PostScript"
1935 ~dir:lastdir ~filename:"screenshot.ps" ()
1939 output#export_to_postscript ~filename:filename ();
1942 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
1943 button_set_kerning button_set_transparency export_to_postscript_menu_item
1946 let is_set = button_t1#active in
1947 output#set_font_manager_type
1948 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
1951 button_set_anti_aliasing#misc#set_sensitive true ;
1952 button_set_kerning#misc#set_sensitive true ;
1953 button_set_transparency#misc#set_sensitive true ;
1954 export_to_postscript_menu_item#misc#set_sensitive true ;
1958 button_set_anti_aliasing#misc#set_sensitive false ;
1959 button_set_kerning#misc#set_sensitive false ;
1960 button_set_transparency#misc#set_sensitive false ;
1961 export_to_postscript_menu_item#misc#set_sensitive false ;
1965 let set_anti_aliasing output button_set_anti_aliasing () =
1966 output#set_anti_aliasing button_set_anti_aliasing#active
1969 let set_kerning output button_set_kerning () =
1970 output#set_kerning button_set_kerning#active
1973 let set_transparency output button_set_transparency () =
1974 output#set_transparency button_set_transparency#active
1977 let changefont output font_size_spinb () =
1978 output#set_font_size font_size_spinb#value_as_int
1981 let set_log_verbosity output log_verbosity_spinb () =
1982 output#set_log_verbosity log_verbosity_spinb#value_as_int
1985 class settings_window (output : GMathView.math_view) sw
1986 export_to_postscript_menu_item selection_changed_callback
1988 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
1990 GPack.vbox ~packing:settings_window#add () in
1993 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1994 ~border_width:5 ~packing:vbox#add () in
1996 GButton.toggle_button ~label:"activate t1 fonts"
1997 ~packing:(table#attach ~left:0 ~top:0) () in
1998 let button_set_anti_aliasing =
1999 GButton.toggle_button ~label:"set_anti_aliasing"
2000 ~packing:(table#attach ~left:0 ~top:1) () in
2001 let button_set_kerning =
2002 GButton.toggle_button ~label:"set_kerning"
2003 ~packing:(table#attach ~left:1 ~top:1) () in
2004 let button_set_transparency =
2005 GButton.toggle_button ~label:"set_transparency"
2006 ~packing:(table#attach ~left:2 ~top:1) () in
2009 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2010 ~border_width:5 ~packing:vbox#add () in
2011 let font_size_label =
2012 GMisc.label ~text:"font size:"
2013 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2014 let font_size_spinb =
2016 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2019 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2020 let log_verbosity_label =
2021 GMisc.label ~text:"log verbosity:"
2022 ~packing:(table#attach ~left:0 ~top:1) () in
2023 let log_verbosity_spinb =
2025 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2028 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2030 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2032 GButton.button ~label:"Close"
2033 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2035 method show = settings_window#show
2037 button_set_anti_aliasing#misc#set_sensitive false ;
2038 button_set_kerning#misc#set_sensitive false ;
2039 button_set_transparency#misc#set_sensitive false ;
2040 (* Signals connection *)
2041 ignore(button_t1#connect#clicked
2042 (activate_t1 output button_set_anti_aliasing button_set_kerning
2043 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2044 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2045 ignore(button_set_anti_aliasing#connect#toggled
2046 (set_anti_aliasing output button_set_anti_aliasing));
2047 ignore(button_set_kerning#connect#toggled
2048 (set_kerning output button_set_kerning)) ;
2049 ignore(button_set_transparency#connect#toggled
2050 (set_transparency output button_set_transparency)) ;
2051 ignore(log_verbosity_spinb#connect#changed
2052 (set_log_verbosity output log_verbosity_spinb)) ;
2053 ignore(closeb#connect#clicked settings_window#misc#hide)
2056 (* Scratch window *)
2058 class scratch_window outputhtml =
2060 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2062 GPack.vbox ~packing:window#add () in
2064 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2066 GButton.button ~label:"Whd"
2067 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2069 GButton.button ~label:"Reduce"
2070 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2072 GButton.button ~label:"Simpl"
2073 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2074 let scrolled_window =
2075 GBin.scrolled_window ~border_width:10
2076 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2079 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2081 method outputhtml = outputhtml
2082 method mmlwidget = mmlwidget
2083 method show () = window#misc#hide () ; window#show ()
2085 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2086 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2087 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2088 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2089 ignore(simplb#connect#clicked (simpl_in_scratch self))
2093 let vbox1 = GPack.vbox () in
2095 val mutable proofw_ref = None
2096 val mutable compute_ref = None
2098 Lazy.force self#compute ;
2099 match proofw_ref with
2100 None -> assert false
2101 | Some proofw -> proofw
2102 method content = vbox1
2104 match compute_ref with
2105 None -> assert false
2106 | Some compute -> compute
2110 let scrolled_window1 =
2111 GBin.scrolled_window ~border_width:10
2112 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2114 GMathView.math_view ~width:400 ~height:275
2115 ~packing:(scrolled_window1#add) () in
2116 let _ = proofw_ref <- Some proofw in
2118 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2120 GButton.button ~label:"Exact"
2121 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2123 GButton.button ~label:"Intros"
2124 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2126 GButton.button ~label:"Apply"
2127 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2128 let elimsimplintrosb =
2129 GButton.button ~label:"ElimSimplIntros"
2130 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2132 GButton.button ~label:"ElimType"
2133 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2135 GButton.button ~label:"Whd"
2136 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2138 GButton.button ~label:"Reduce"
2139 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2141 GButton.button ~label:"Simpl"
2142 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2144 GButton.button ~label:"Fold"
2145 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2147 GButton.button ~label:"Cut"
2148 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2150 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2152 GButton.button ~label:"Change"
2153 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2155 GButton.button ~label:"Let ... In"
2156 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2158 GButton.button ~label:"Ring"
2159 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2161 GButton.button ~label:"ClearBody"
2162 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2164 GButton.button ~label:"Clear"
2165 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2167 GButton.button ~label:"Fourier"
2168 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2170 GButton.button ~label:"RewriteSimpl ->"
2171 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2173 GButton.button ~label:"Reflexivity"
2174 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2176 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2178 GButton.button ~label:"Symmetry"
2179 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2181 GButton.button ~label:"Transitivity"
2182 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2184 GButton.button ~label:"Left"
2185 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2187 GButton.button ~label:"Right"
2188 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2190 GButton.button ~label:"Assumption"
2191 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2192 let searchpatternb =
2193 GButton.button ~label:"SearchPattern_Apply"
2194 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
2195 ignore(exactb#connect#clicked exact) ;
2196 ignore(applyb#connect#clicked apply) ;
2197 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
2198 ignore(elimtypeb#connect#clicked elimtype) ;
2199 ignore(whdb#connect#clicked whd) ;
2200 ignore(reduceb#connect#clicked reduce) ;
2201 ignore(simplb#connect#clicked simpl) ;
2202 ignore(foldb#connect#clicked fold) ;
2203 ignore(cutb#connect#clicked cut) ;
2204 ignore(changeb#connect#clicked change) ;
2205 ignore(letinb#connect#clicked letin) ;
2206 ignore(ringb#connect#clicked ring) ;
2207 ignore(clearbodyb#connect#clicked clearbody) ;
2208 ignore(clearb#connect#clicked clear) ;
2209 ignore(fourierb#connect#clicked fourier) ;
2210 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
2211 ignore(reflexivityb#connect#clicked reflexivity) ;
2212 ignore(symmetryb#connect#clicked symmetry) ;
2213 ignore(transitivityb#connect#clicked transitivity) ;
2214 ignore(leftb#connect#clicked left) ;
2215 ignore(rightb#connect#clicked right) ;
2216 ignore(assumptionb#connect#clicked assumption) ;
2217 ignore(introsb#connect#clicked intros) ;
2218 ignore(searchpatternb#connect#clicked searchPattern) ;
2219 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
2225 let vbox1 = GPack.vbox () in
2226 let scrolled_window1 =
2227 GBin.scrolled_window ~border_width:10
2228 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2230 GMathView.math_view ~width:400 ~height:275
2231 ~packing:(scrolled_window1#add) () in
2233 method proofw = (assert false : GMathView.math_view)
2234 method content = vbox1
2235 method compute = (assert false : unit)
2239 let empty_page = new empty_page;;
2243 val notebook = GPack.notebook ()
2245 val mutable skip_switch_page_event = false
2246 val mutable empty = true
2247 method notebook = notebook
2249 let new_page = new page () in
2251 pages := !pages @ [n,lazy (setgoal n),new_page] ;
2252 notebook#append_page
2253 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
2254 new_page#content#coerce
2255 method remove_all_pages ~skip_switch_page_event:skip =
2257 notebook#remove_page 0 (* let's remove the empty page *)
2259 List.iter (function _ -> notebook#remove_page 0) !pages ;
2261 skip_switch_page_event <- skip
2262 method set_current_page ~may_skip_switch_page_event n =
2263 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
2264 let new_page = notebook#page_num page#content#coerce in
2265 if may_skip_switch_page_event && new_page <> notebook#current_page then
2266 skip_switch_page_event <- true ;
2267 notebook#goto_page new_page
2268 method set_empty_page =
2271 notebook#append_page
2272 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
2273 empty_page#content#coerce
2275 let (_,_,page) = List.nth !pages notebook#current_page in
2279 (notebook#connect#switch_page
2281 let skip = skip_switch_page_event in
2282 skip_switch_page_event <- false ;
2285 let (metano,setgoal,page) = List.nth !pages i in
2286 ProofEngine.goal := Some metano ;
2287 Lazy.force (page#compute) ;
2296 class rendering_window output (notebook : notebook) =
2298 GWindow.window ~title:"MathML viewer" ~border_width:2
2299 ~allow_shrink:false () in
2300 let vbox_for_menu = GPack.vbox ~packing:window#add () in
2302 let menubar = GMenu.menu_bar ~packing:vbox_for_menu#pack () in
2303 let factory0 = new GMenu.factory menubar in
2304 let accel_group = factory0#accel_group in
2306 let file_menu = factory0#add_submenu "File" in
2307 let factory1 = new GMenu.factory file_menu ~accel_group in
2308 let export_to_postscript_menu_item =
2311 (factory1#add_item "Load Unfinished Proof" ~key:GdkKeysyms._L
2313 let save_menu_item =
2314 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
2316 let reopen_menu_item =
2317 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
2321 factory1#add_item "Qed" ~key:GdkKeysyms._Q ~callback:qed in
2323 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
2324 ignore (!save_set_sensitive false);
2325 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
2326 ignore (!qed_set_sensitive false);
2327 ignore (factory1#add_separator ()) ;
2328 let export_to_postscript_menu_item =
2329 factory1#add_item "Export to PostScript..." ~key:GdkKeysyms._E
2330 ~callback:(export_to_postscript output) in
2331 ignore (factory1#add_separator ()) ;
2333 (factory1#add_item "Exit" ~key:GdkKeysyms._C ~callback:GMain.Main.quit) ;
2334 export_to_postscript_menu_item
2337 let edit_menu = factory0#add_submenu "Edit current proof" in
2338 let factory2 = new GMenu.factory edit_menu ~accel_group in
2339 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2340 let proveit_menu_item =
2341 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2342 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2344 let focus_menu_item =
2345 factory2#add_item "Focus" ~key:GdkKeysyms._F
2346 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2349 focus_and_proveit_set_sensitive :=
2351 proveit_menu_item#misc#set_sensitive b ;
2352 focus_menu_item#misc#set_sensitive b
2354 let _ = !focus_and_proveit_set_sensitive false in
2356 let settings_menu = factory0#add_submenu "Search" in
2357 let factory4 = new GMenu.factory settings_menu ~accel_group in
2359 factory4#add_item "Locate..." ~key:GdkKeysyms._T
2361 let show_menu_item =
2362 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
2365 let settings_menu = factory0#add_submenu "Settings" in
2366 let factory3 = new GMenu.factory settings_menu ~accel_group in
2368 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2369 ~callback:edit_aliases in
2370 let _ = factory3#add_separator () in
2372 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2373 ~callback:(function _ -> (settings_window ())#show ()) in
2375 let _ = window#add_accel_group accel_group in
2379 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2381 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2382 let scrolled_window0 =
2383 GBin.scrolled_window ~border_width:10
2384 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2385 let _ = scrolled_window0#add output#coerce in
2387 GBin.frame ~label:"Term input"
2388 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2390 GPack.vbox ~packing:frame#add () in
2392 GPack.hbox ~border_width:5 ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2394 GButton.button ~label:"State"
2395 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2397 GButton.button ~label:"Check"
2398 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2399 let scrolled_window1 =
2400 GBin.scrolled_window ~border_width:5
2401 ~packing:(vbox'#pack ~expand:true ~padding:0) () in
2402 let inputt = GEdit.text ~editable:true ~width:400 ~height:100
2403 ~packing:scrolled_window1#add () in
2405 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2407 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2409 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
2413 ~source:"<html><body bgColor=\"white\"></body></html>"
2414 ~width:400 ~height: 100
2418 let scratch_window = new scratch_window outputhtml in
2420 method outputhtml = outputhtml
2421 method inputt = inputt
2422 method output = (output : GMathView.math_view)
2423 method notebook = notebook
2424 method show = window#show
2426 notebook#set_empty_page ;
2427 export_to_postscript_menu_item#misc#set_sensitive false ;
2428 check_term := (check_term_in_scratch scratch_window) ;
2430 (* signal handlers here *)
2431 ignore(output#connect#selection_changed
2433 choose_selection output elem ;
2434 !focus_and_proveit_set_sensitive true
2436 ignore (output#connect#clicked (show_in_show_window_callback output)) ;
2437 let settings_window = new settings_window output scrolled_window0
2438 export_to_postscript_menu_item (choose_selection output) in
2439 set_settings_window settings_window ;
2440 set_outputhtml outputhtml ;
2441 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2442 ignore(stateb#connect#clicked state) ;
2443 ignore(checkb#connect#clicked (check scratch_window)) ;
2444 Logger.log_callback :=
2445 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2450 let initialize_everything () =
2451 let module U = Unix in
2452 let output = GMathView.math_view ~width:350 ~height:280 () in
2453 let notebook = new notebook in
2454 let rendering_window' = new rendering_window output notebook in
2455 set_rendering_window rendering_window' ;
2456 mml_of_cic_term_ref := mml_of_cic_term ;
2457 rendering_window'#show () ;
2463 Mqint.init "dbname=helm_mowgli" ;
2464 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
2465 ignore (GtkMain.Main.init ()) ;
2466 initialize_everything () ;
2467 if !usedb then Mqint.close ();