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";;
54 " <body bgColor=\"white\">"
63 let prooffile = "/home/tassi/miohelm/tmp/currentproof";;
64 let prooffile = "/public/sacerdot/currentproof";;
67 let prooffile = "/public/sacerdot/currentproof";;
68 let prooffiletype = "/public/sacerdot/currentprooftype";;
70 (*CSC: the getter should handle the innertypes, not the FS *)
72 let innertypesfile = "/home/tassi/miohelm/tmp/innertypes";;
73 let innertypesfile = "/public/sacerdot/innertypes";;
76 let innertypesfile = "/public/sacerdot/innertypes";;
77 let constanttypefile = "/public/sacerdot/constanttype";;
80 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
82 let htmlheader_and_content = ref htmlheader;;
84 let current_cic_infos = ref None;;
85 let current_goal_infos = ref None;;
86 let current_scratch_infos = ref None;;
88 let id_to_uris = ref ([],function _ -> None);;
90 let check_term = ref (fun _ _ _ -> assert false);;
91 let rendering_window = ref None;;
93 (* COMMAND LINE OPTIONS *)
99 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
102 Arg.parse argspec ignore ""
107 let cic_textual_parser_uri_of_uri uri' =
109 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
110 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
112 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
113 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
117 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
118 CicTextualParser0.IndTyUri (uri'',typeno)
121 (* Constructor of an Inductive Type *)
122 let uri'',typeno,consno =
123 CicTextualLexer.indconuri_of_uri uri'
125 CicTextualParser0.IndConUri (uri'',typeno,consno)
130 let term_of_uri uri =
131 let module C = Cic in
132 let module CTP = CicTextualParser0 in
133 match (cic_textual_parser_uri_of_uri uri) with
134 CTP.ConUri uri -> C.Const (uri,[])
135 | CTP.VarUri uri -> C.Var (uri,[])
136 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
137 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
140 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
144 let interactive_user_uri_choice ?(cancel="Cancel") ~title ~msg uris =
145 let choice = ref None in
146 let window = GWindow.dialog ~modal:true ~title () in
148 GMisc.label ~text:msg ~packing:window#vbox#add () in
149 let vbox = GPack.vbox ~border_width:10
150 ~packing:(window#action_area#pack ~expand:true ~padding:4) () in
151 let hbox1 = GPack.hbox ~border_width:10 ~packing:vbox#add () in
153 GEdit.combo ~popdown_strings:uris ~packing:hbox1#add () in
155 GButton.button ~label:"Check"
156 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
157 let hbox = GPack.hbox ~border_width:10 ~packing:vbox#add () in
159 GButton.button ~label:"Ok"
160 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
162 GButton.button ~label:cancel
163 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
166 choice := Some combo#entry#text ;
169 let check_callback () = !check_term [] [] (term_of_uri combo#entry#text) in
170 ignore (window#connect#destroy GMain.Main.quit) ;
171 ignore (cancelb#connect#clicked window#destroy) ;
172 ignore (okb#connect#clicked ok_callback) ;
173 ignore (checkb#connect#clicked check_callback) ;
174 window#set_position `CENTER ;
178 None -> raise NoChoice
184 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
186 let query = ref "" in
187 MQueryGenerator.set_confirm_query
188 (function q -> query := MQueryUtil.text_of_query q ; true) ;
189 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
192 let register_alias (id,uri) =
193 let dom,resolve_id = !id_to_uris in
195 (if List.mem id dom then dom else id::dom),
196 function id' -> if id' = id then Some uri else resolve_id id'
199 let output_html outputhtml msg =
200 htmlheader_and_content := !htmlheader_and_content ^ msg ;
201 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
202 outputhtml#set_topline (-1)
205 let locate_one_id id =
206 let result = MQueryGenerator.locate id in
210 wrong_xpointer_format_from_wrong_xpointer_format' uri
212 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
214 match !rendering_window with
216 | Some rw -> output_html rw#outputhtml html ;
222 (GToolbox.input_string ~title:"Unknown input"
223 ("No URI matching \"" ^ id ^ "\" found. Please enter its URI"))
225 None -> raise NoChoice
226 | Some uri -> ["cic:" ^ uri]
231 [interactive_user_uri_choice
232 ~cancel:"Try every possibility."
233 ~title:"Ambiguous input."
235 ("Ambiguous input \"" ^ id ^
236 "\". Please, choose one interpretation:")
242 List.map cic_textual_parser_uri_of_uri uris'
245 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
246 exception AmbiguousInput;;
248 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
249 let known_ids,resolve_id = !id_to_uris in
255 if List.mem he known_ids then filter tl else he::(filter tl)
259 (* for each id in dom' we get the list of uris associated to it *)
260 let list_of_uris = List.map locate_one_id dom' in
261 (* and now we compute the list of all possible assignments from id to uris *)
263 let rec aux ids list_of_uris =
264 match ids,list_of_uris with
265 [],[] -> [resolve_id]
266 | id::idtl,uris::uristl ->
267 let resolves = aux idtl uristl in
273 function id' -> if id = id' then Some uri else f id'
277 | _,_ -> assert false
279 aux dom' list_of_uris
281 prerr_endline ("##### NE DISAMBIGUO: " ^ string_of_int (List.length resolve_ids)) ;
282 (* now we select only the ones that generates well-typed terms *)
288 let metasenv',expr = mk_metasenv_and_expr resolve in
290 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
292 (CicTypeChecker.type_of_aux' metasenv context expr) ;
300 match resolve_ids' with
301 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
302 | [resolve_id] -> resolve_id
311 match resolve id with
315 CicTextualParser0.ConUri uri
316 | CicTextualParser0.VarUri uri ->
317 UriManager.string_of_uri uri
318 | CicTextualParser0.IndTyUri (uri,tyno) ->
319 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
320 string_of_int (tyno+1) ^ ")"
321 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
322 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
323 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
329 GToolbox.question_box ~title:"Ambiguous input."
331 ~default:1 "Ambiguous input. Please, choose one interpretation."
334 List.nth resolve_ids' (choice - 1)
336 (* No choice from the user *)
339 id_to_uris := known_ids @ dom', resolve_id' ;
340 mk_metasenv_and_expr resolve_id'
343 let domImpl = Gdome.domImplementation ();;
345 let parseStyle name =
347 domImpl#createDocumentFromURI
349 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
351 ~uri:("styles/" ^ name) ()
353 Gdome_xslt.processStylesheet style
356 let d_c = parseStyle "drop_coercions.xsl";;
357 let tc1 = parseStyle "objtheorycontent.xsl";;
358 let hc2 = parseStyle "content_to_html.xsl";;
359 let l = parseStyle "link.xsl";;
361 let c1 = parseStyle "rootcontent.xsl";;
362 let g = parseStyle "genmmlid.xsl";;
363 let c2 = parseStyle "annotatedpres.xsl";;
366 let getterURL = Configuration.getter_url;;
367 let processorURL = Configuration.processor_url;;
369 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
371 ["processorURL", "'" ^ processorURL ^ "'" ;
372 "getterURL", "'" ^ getterURL ^ "'" ;
373 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
374 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
375 "UNICODEvsSYMBOL", "'symbol'" ;
376 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
377 "encoding", "'iso-8859-1'" ;
378 "media-type", "'text/html'" ;
379 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
380 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
381 "naturalLanguage", "'yes'" ;
382 "annotations", "'no'" ;
383 "explodeall", "'true()'" ;
384 "topurl", "'http://phd.cs.unibo.it/helm'" ;
385 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
388 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
390 ["processorURL", "'" ^ processorURL ^ "'" ;
391 "getterURL", "'" ^ getterURL ^ "'" ;
392 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
393 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
394 "UNICODEvsSYMBOL", "'symbol'" ;
395 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
396 "encoding", "'iso-8859-1'" ;
397 "media-type", "'text/html'" ;
398 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
399 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
400 "naturalLanguage", "'no'" ;
401 "annotations", "'no'" ;
402 "explodeall", "'true()'" ;
403 "topurl", "'http://phd.cs.unibo.it/helm'" ;
404 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
407 let parse_file filename =
408 let inch = open_in filename in
409 let rec read_lines () =
411 let line = input_line inch in
419 let applyStylesheets input styles args =
420 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
424 let mml_of_cic_object uri annobj ids_to_inner_sorts ids_to_inner_types =
425 (*CSC: ????????????????? *)
427 Cic2Xml.print_object uri ~ids_to_inner_sorts annobj
430 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts
435 None -> Xml2Gdome.document_of_xml domImpl xml
437 Xml.pp xml (Some constanttypefile) ;
438 Xml2Gdome.document_of_xml domImpl bodyxml'
440 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
441 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
443 Xml.pp xmlinnertypes (Some innertypesfile) ;
444 let output = applyStylesheets input mml_styles mml_args in
451 exception RefreshSequentException of exn;;
452 exception RefreshProofException of exn;;
454 let refresh_proof (output : GMathView.math_view) =
456 let uri,currentproof =
457 match !ProofEngine.proof with
459 | Some (uri,metasenv,bo,ty) ->
460 (*CSC: Wrong: [] is just plainly wrong *)
461 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
464 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
465 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
467 Cic2acic.acic_object_of_cic_object currentproof
470 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
472 output#load_tree mml ;
474 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
477 match !ProofEngine.proof with
479 | Some (uri,metasenv,bo,ty) ->
480 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
481 raise (RefreshProofException e)
484 let refresh_sequent (proofw : GMathView.math_view) =
486 match !ProofEngine.goal with
487 None -> proofw#unload
490 match !ProofEngine.proof with
492 | Some (_,metasenv,_,_) -> metasenv
494 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
495 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
496 SequentPp.XmlPp.print_sequent metasenv currentsequent
499 Xml2Gdome.document_of_xml domImpl sequent_gdome
502 applyStylesheets sequent_doc sequent_styles sequent_args
504 proofw#load_tree ~dom:sequent_mml ;
505 current_goal_infos :=
506 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
510 match !ProofEngine.goal with
515 match !ProofEngine.proof with
517 | Some (_,metasenv,_,_) -> metasenv
519 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
520 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
521 raise (RefreshSequentException e)
525 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
526 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
529 let mml_of_cic_term metano term =
531 match !ProofEngine.proof with
533 | Some (_,metasenv,_,_) -> metasenv
536 match !ProofEngine.goal with
539 let (_,canonical_context,_) =
540 List.find (function (m,_,_) -> m=metano) metasenv
544 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
545 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
548 Xml2Gdome.document_of_xml domImpl sequent_gdome
551 applyStylesheets sequent_doc sequent_styles sequent_args ;
553 current_scratch_infos :=
554 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
558 (***********************)
560 (***********************)
562 let call_tactic tactic rendering_window () =
563 let proofw = (rendering_window#proofw : GMathView.math_view) in
564 let output = (rendering_window#output : GMathView.math_view) in
565 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
566 let savedproof = !ProofEngine.proof in
567 let savedgoal = !ProofEngine.goal in
571 refresh_sequent proofw ;
574 RefreshSequentException e ->
575 output_html outputhtml
576 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
577 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
578 ProofEngine.proof := savedproof ;
579 ProofEngine.goal := savedgoal ;
580 refresh_sequent proofw
581 | RefreshProofException e ->
582 output_html outputhtml
583 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
584 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
585 ProofEngine.proof := savedproof ;
586 ProofEngine.goal := savedgoal ;
587 refresh_sequent proofw ;
590 output_html outputhtml
591 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
592 ProofEngine.proof := savedproof ;
593 ProofEngine.goal := savedgoal ;
597 let call_tactic_with_input tactic rendering_window () =
598 let proofw = (rendering_window#proofw : GMathView.math_view) in
599 let output = (rendering_window#output : GMathView.math_view) in
600 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
601 let inputt = (rendering_window#inputt : GEdit.text) in
602 let savedproof = !ProofEngine.proof in
603 let savedgoal = !ProofEngine.goal in
604 (*CSC: Gran cut&paste da sotto... *)
605 let inputlen = inputt#length in
606 let input = inputt#get_chars 0 inputlen ^ "\n" in
607 let lexbuf = Lexing.from_string input in
609 match !ProofEngine.proof with
611 | Some (curi,_,_,_) -> curi
613 let uri,metasenv,bo,ty =
614 match !ProofEngine.proof with
616 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
618 let canonical_context =
619 match !ProofEngine.goal with
622 let (_,canonical_context,_) =
623 List.find (function (m,_,_) -> m=metano) metasenv
637 CicTextualParserContext.main context metasenv CicTextualLexer.token
638 lexbuf register_alias
641 | Some (dom,mk_metasenv_and_expr) ->
642 let (metasenv',expr) =
643 disambiguate_input canonical_context metasenv dom
646 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
648 refresh_sequent proofw ;
652 CicTextualParser0.Eof ->
653 inputt#delete_text 0 inputlen
654 | RefreshSequentException e ->
655 output_html outputhtml
656 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
657 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
658 ProofEngine.proof := savedproof ;
659 ProofEngine.goal := savedgoal ;
660 refresh_sequent proofw
661 | RefreshProofException e ->
662 output_html outputhtml
663 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
664 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
665 ProofEngine.proof := savedproof ;
666 ProofEngine.goal := savedgoal ;
667 refresh_sequent proofw ;
670 output_html outputhtml
671 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
672 ProofEngine.proof := savedproof ;
673 ProofEngine.goal := savedgoal ;
676 let call_tactic_with_goal_input tactic rendering_window () =
677 let module L = LogicalOperations in
678 let module G = Gdome in
679 let proofw = (rendering_window#proofw : GMathView.math_view) in
680 let output = (rendering_window#output : GMathView.math_view) in
681 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
682 let savedproof = !ProofEngine.proof in
683 let savedgoal = !ProofEngine.goal in
684 match proofw#get_selection with
687 ((node : Gdome.element)#getAttributeNS
689 ~localName:(G.domString "xref"))#to_string
691 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
695 match !current_goal_infos with
696 Some (ids_to_terms, ids_to_father_ids,_) ->
698 tactic (Hashtbl.find ids_to_terms id) ;
699 refresh_sequent rendering_window#proofw ;
700 refresh_proof rendering_window#output
701 | None -> assert false (* "ERROR: No current term!!!" *)
703 RefreshSequentException e ->
704 output_html outputhtml
705 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
706 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
707 ProofEngine.proof := savedproof ;
708 ProofEngine.goal := savedgoal ;
709 refresh_sequent proofw
710 | RefreshProofException e ->
711 output_html outputhtml
712 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
713 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
714 ProofEngine.proof := savedproof ;
715 ProofEngine.goal := savedgoal ;
716 refresh_sequent proofw ;
719 output_html outputhtml
720 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
721 ProofEngine.proof := savedproof ;
722 ProofEngine.goal := savedgoal ;
725 output_html outputhtml
726 ("<h1 color=\"red\">No term selected</h1>")
729 let call_tactic_with_input_and_goal_input tactic rendering_window () =
730 let module L = LogicalOperations in
731 let module G = Gdome in
732 let proofw = (rendering_window#proofw : GMathView.math_view) in
733 let output = (rendering_window#output : GMathView.math_view) in
734 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
735 let inputt = (rendering_window#inputt : GEdit.text) in
736 let savedproof = !ProofEngine.proof in
737 let savedgoal = !ProofEngine.goal in
738 match proofw#get_selection with
741 ((node : Gdome.element)#getAttributeNS
743 ~localName:(G.domString "xref"))#to_string
745 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
749 match !current_goal_infos with
750 Some (ids_to_terms, ids_to_father_ids,_) ->
752 (* Let's parse the input *)
753 let inputlen = inputt#length in
754 let input = inputt#get_chars 0 inputlen ^ "\n" in
755 let lexbuf = Lexing.from_string input in
757 match !ProofEngine.proof with
759 | Some (curi,_,_,_) -> curi
761 let uri,metasenv,bo,ty =
762 match !ProofEngine.proof with
764 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
766 let canonical_context =
767 match !ProofEngine.goal with
770 let (_,canonical_context,_) =
771 List.find (function (m,_,_) -> m=metano) metasenv
785 CicTextualParserContext.main context metasenv
786 CicTextualLexer.token lexbuf register_alias
789 | Some (dom,mk_metasenv_and_expr) ->
790 let (metasenv',expr) =
791 disambiguate_input canonical_context metasenv dom
794 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
795 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
797 refresh_sequent proofw ;
801 CicTextualParser0.Eof ->
802 inputt#delete_text 0 inputlen
804 | None -> assert false (* "ERROR: No current term!!!" *)
806 RefreshSequentException e ->
807 output_html outputhtml
808 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
809 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
810 ProofEngine.proof := savedproof ;
811 ProofEngine.goal := savedgoal ;
812 refresh_sequent proofw
813 | RefreshProofException e ->
814 output_html outputhtml
815 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
816 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
817 ProofEngine.proof := savedproof ;
818 ProofEngine.goal := savedgoal ;
819 refresh_sequent proofw ;
822 output_html outputhtml
823 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
824 ProofEngine.proof := savedproof ;
825 ProofEngine.goal := savedgoal ;
828 output_html outputhtml
829 ("<h1 color=\"red\">No term selected</h1>")
832 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
833 let module L = LogicalOperations in
834 let module G = Gdome in
835 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
836 let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
837 let savedproof = !ProofEngine.proof in
838 let savedgoal = !ProofEngine.goal in
839 match mmlwidget#get_selection with
842 ((node : Gdome.element)#getAttributeNS
844 ~localName:(G.domString "xref"))#to_string
846 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
850 match !current_scratch_infos with
851 (* term is the whole goal in the scratch_area *)
852 Some (term,ids_to_terms, ids_to_father_ids,_) ->
854 let expr = tactic term (Hashtbl.find ids_to_terms id) in
855 let mml = mml_of_cic_term 111 expr in
856 scratch_window#show () ;
857 scratch_window#mmlwidget#load_tree ~dom:mml
858 | None -> assert false (* "ERROR: No current term!!!" *)
861 output_html outputhtml
862 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
865 output_html outputhtml
866 ("<h1 color=\"red\">No term selected</h1>")
869 let call_tactic_with_hypothesis_input tactic rendering_window () =
870 let module L = LogicalOperations in
871 let module G = Gdome in
872 let proofw = (rendering_window#proofw : GMathView.math_view) in
873 let output = (rendering_window#output : GMathView.math_view) in
874 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
875 let savedproof = !ProofEngine.proof in
876 let savedgoal = !ProofEngine.goal in
877 match proofw#get_selection with
880 ((node : Gdome.element)#getAttributeNS
882 ~localName:(G.domString "xref"))#to_string
884 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
888 match !current_goal_infos with
889 Some (_,_,ids_to_hypotheses) ->
891 tactic (Hashtbl.find ids_to_hypotheses id) ;
892 refresh_sequent rendering_window#proofw ;
893 refresh_proof rendering_window#output
894 | None -> assert false (* "ERROR: No current term!!!" *)
896 RefreshSequentException e ->
897 output_html outputhtml
898 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
899 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
900 ProofEngine.proof := savedproof ;
901 ProofEngine.goal := savedgoal ;
902 refresh_sequent proofw
903 | RefreshProofException e ->
904 output_html outputhtml
905 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
906 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
907 ProofEngine.proof := savedproof ;
908 ProofEngine.goal := savedgoal ;
909 refresh_sequent proofw ;
912 output_html outputhtml
913 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
914 ProofEngine.proof := savedproof ;
915 ProofEngine.goal := savedgoal ;
918 output_html outputhtml
919 ("<h1 color=\"red\">No term selected</h1>")
923 let intros rendering_window = call_tactic ProofEngine.intros rendering_window;;
924 let exact rendering_window =
925 call_tactic_with_input ProofEngine.exact rendering_window
927 let apply rendering_window =
928 call_tactic_with_input ProofEngine.apply rendering_window
930 let elimsimplintros rendering_window =
931 call_tactic_with_input ProofEngine.elim_simpl_intros rendering_window
933 let elimtype rendering_window =
934 call_tactic_with_input ProofEngine.elim_type rendering_window
936 let whd rendering_window =
937 call_tactic_with_goal_input ProofEngine.whd rendering_window
939 let reduce rendering_window =
940 call_tactic_with_goal_input ProofEngine.reduce rendering_window
942 let simpl rendering_window =
943 call_tactic_with_goal_input ProofEngine.simpl rendering_window
945 let fold rendering_window =
946 call_tactic_with_input ProofEngine.fold rendering_window
948 let cut rendering_window =
949 call_tactic_with_input ProofEngine.cut rendering_window
951 let change rendering_window =
952 call_tactic_with_input_and_goal_input ProofEngine.change rendering_window
954 let letin rendering_window =
955 call_tactic_with_input ProofEngine.letin rendering_window
957 let ring rendering_window = call_tactic ProofEngine.ring rendering_window;;
958 let clearbody rendering_window =
959 call_tactic_with_hypothesis_input ProofEngine.clearbody rendering_window
961 let clear rendering_window =
962 call_tactic_with_hypothesis_input ProofEngine.clear rendering_window
964 let fourier rendering_window =
965 call_tactic ProofEngine.fourier rendering_window
967 let rewritesimpl rendering_window =
968 call_tactic_with_input ProofEngine.rewrite_simpl rendering_window
970 let reflexivity rendering_window =
971 call_tactic ProofEngine.reflexivity rendering_window
973 let symmetry rendering_window =
974 call_tactic ProofEngine.symmetry rendering_window
976 let transitivity rendering_window =
977 call_tactic_with_input ProofEngine.transitivity rendering_window
979 let left rendering_window =
980 call_tactic ProofEngine.left rendering_window
982 let right rendering_window =
983 call_tactic ProofEngine.right rendering_window
985 let assumption rendering_window =
986 call_tactic ProofEngine.assumption rendering_window
989 let prova_tatticali rendering_window =
990 call_tactic ProofEngine.prova_tatticali rendering_window
995 let whd_in_scratch scratch_window =
996 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
999 let reduce_in_scratch scratch_window =
1000 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1003 let simpl_in_scratch scratch_window =
1004 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1010 (**********************)
1011 (* END OF TACTICS *)
1012 (**********************)
1014 exception OpenConjecturesStillThere;;
1015 exception WrongProof;;
1017 let qed rendering_window () =
1018 match !ProofEngine.proof with
1019 None -> assert false
1020 | Some (uri,[],bo,ty) ->
1022 CicReduction.are_convertible []
1023 (CicTypeChecker.type_of_aux' [] [] bo) ty
1026 (*CSC: Wrong: [] is just plainly wrong *)
1027 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
1029 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1030 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1032 Cic2acic.acic_object_of_cic_object proof
1035 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
1037 (rendering_window#output : GMathView.math_view)#load_tree mml ;
1038 current_cic_infos :=
1040 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
1045 | _ -> raise OpenConjecturesStillThere
1049 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
1050 let dtdname = "/home/tassi/miohelm/helm/dtd/cic.dtd";;
1052 let dtdname = "/projects/helm/V7_mowgli/dtd/cic.dtd";;
1054 let save rendering_window () =
1055 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1056 match !ProofEngine.proof with
1057 None -> assert false
1058 | Some (uri, metasenv, bo, ty) ->
1060 (*CSC: Wrong: [] is just plainly wrong *)
1061 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
1063 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
1064 Cic2acic.acic_object_of_cic_object currentproof
1067 match Cic2Xml.print_object uri ~ids_to_inner_sorts acurrentproof with
1068 xml,Some bodyxml -> xml,bodyxml
1069 | _,None -> assert false
1071 Xml.pp ~quiet:true xml (Some prooffiletype) ;
1072 output_html outputhtml
1073 ("<h1 color=\"Green\">Current proof type saved to " ^
1074 prooffiletype ^ "</h1>") ;
1075 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
1076 output_html outputhtml
1077 ("<h1 color=\"Green\">Current proof body saved to " ^
1078 prooffile ^ "</h1>")
1081 (* Used to typecheck the loaded proofs *)
1082 let typecheck_loaded_proof metasenv bo ty =
1083 let module T = CicTypeChecker in
1086 (fun metasenv ((_,context,ty) as conj) ->
1087 ignore (T.type_of_aux' metasenv context ty) ;
1090 ignore (T.type_of_aux' metasenv [] ty) ;
1091 ignore (T.type_of_aux' metasenv [] bo)
1094 (*CSC: ancora da implementare *)
1095 let load rendering_window () =
1096 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1097 let output = (rendering_window#output : GMathView.math_view) in
1098 let proofw = (rendering_window#proofw : GMathView.math_view) in
1100 let uri = UriManager.uri_of_string "cic:/dummy.con" in
1101 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
1102 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
1103 typecheck_loaded_proof metasenv bo ty ;
1104 ProofEngine.proof :=
1105 Some (uri, metasenv, bo, ty) ;
1107 (match metasenv with
1109 | (metano,_,_)::_ -> Some metano
1111 refresh_proof output ;
1112 refresh_sequent proofw ;
1113 output_html outputhtml
1114 ("<h1 color=\"Green\">Current proof type loaded from " ^
1115 prooffiletype ^ "</h1>") ;
1116 output_html outputhtml
1117 ("<h1 color=\"Green\">Current proof body loaded from " ^
1118 prooffile ^ "</h1>")
1121 RefreshSequentException e ->
1122 output_html outputhtml
1123 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1124 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1125 | RefreshProofException e ->
1126 output_html outputhtml
1127 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1128 "proof: " ^ Printexc.to_string e ^ "</h1>")
1130 output_html outputhtml
1131 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1134 let proveit rendering_window () =
1135 let module L = LogicalOperations in
1136 let module G = Gdome in
1137 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1138 match rendering_window#output#get_selection with
1141 ((node : Gdome.element)#getAttributeNS
1142 (*CSC: OCAML DIVERGE
1143 ((element : G.element)#getAttributeNS
1145 ~namespaceURI:helmns
1146 ~localName:(G.domString "xref"))#to_string
1148 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1152 match !current_cic_infos with
1153 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1155 L.to_sequent id ids_to_terms ids_to_father_ids ;
1156 refresh_proof rendering_window#output ;
1157 refresh_sequent rendering_window#proofw
1158 | None -> assert false (* "ERROR: No current term!!!" *)
1160 RefreshSequentException e ->
1161 output_html outputhtml
1162 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1163 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1164 | RefreshProofException e ->
1165 output_html outputhtml
1166 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1167 "proof: " ^ Printexc.to_string e ^ "</h1>")
1169 output_html outputhtml
1170 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1172 | None -> assert false (* "ERROR: No selection!!!" *)
1175 let focus rendering_window () =
1176 let module L = LogicalOperations in
1177 let module G = Gdome in
1178 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1179 match rendering_window#output#get_selection with
1182 ((node : Gdome.element)#getAttributeNS
1183 (*CSC: OCAML DIVERGE
1184 ((element : G.element)#getAttributeNS
1186 ~namespaceURI:helmns
1187 ~localName:(G.domString "xref"))#to_string
1189 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1193 match !current_cic_infos with
1194 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1196 L.focus id ids_to_terms ids_to_father_ids ;
1197 refresh_sequent rendering_window#proofw
1198 | None -> assert false (* "ERROR: No current term!!!" *)
1200 RefreshSequentException e ->
1201 output_html outputhtml
1202 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1203 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1204 | RefreshProofException e ->
1205 output_html outputhtml
1206 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1207 "proof: " ^ Printexc.to_string e ^ "</h1>")
1209 output_html outputhtml
1210 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1212 | None -> assert false (* "ERROR: No selection!!!" *)
1215 exception NoPrevGoal;;
1216 exception NoNextGoal;;
1218 let prevgoal metasenv metano =
1222 | [(m,_,_)] -> raise NoPrevGoal
1223 | (n,_,_)::(m,_,_)::_ when m=metano -> n
1229 let nextgoal metasenv metano =
1233 | [(m,_,_)] when m = metano -> raise NoNextGoal
1234 | (m,_,_)::(n,_,_)::_ when m=metano -> n
1240 let prev_or_next_goal select_goal rendering_window () =
1241 let module L = LogicalOperations in
1242 let module G = Gdome in
1243 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1245 match !ProofEngine.proof with
1246 None -> assert false
1247 | Some (_,metasenv,_,_) -> metasenv
1250 match !ProofEngine.goal with
1251 None -> assert false
1255 ProofEngine.goal := Some (select_goal metasenv metano) ;
1256 refresh_sequent rendering_window#proofw
1258 RefreshSequentException e ->
1259 output_html outputhtml
1260 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1261 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1263 output_html outputhtml
1264 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1267 exception NotADefinition;;
1269 let open_ rendering_window () =
1270 let inputt = (rendering_window#inputt : GEdit.text) in
1271 let oldinputt = (rendering_window#oldinputt : GEdit.text) in
1272 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1273 let output = (rendering_window#output : GMathView.math_view) in
1274 let proofw = (rendering_window#proofw : GMathView.math_view) in
1275 let inputlen = inputt#length in
1276 let input = inputt#get_chars 0 inputlen in
1278 let uri = UriManager.uri_of_string ("cic:" ^ input) in
1279 CicTypeChecker.typecheck uri ;
1280 let metasenv,bo,ty =
1281 match CicEnvironment.get_cooked_obj uri with
1282 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1283 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1286 | Cic.InductiveDefinition _ -> raise NotADefinition
1288 ProofEngine.proof :=
1289 Some (uri, metasenv, bo, ty) ;
1290 ProofEngine.goal := None ;
1291 refresh_sequent proofw ;
1292 refresh_proof output ;
1293 inputt#delete_text 0 inputlen ;
1294 ignore(oldinputt#insert_text input oldinputt#length)
1296 RefreshSequentException e ->
1297 output_html outputhtml
1298 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1299 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1300 | RefreshProofException e ->
1301 output_html outputhtml
1302 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1303 "proof: " ^ Printexc.to_string e ^ "</h1>")
1305 output_html outputhtml
1306 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1309 let state rendering_window () =
1310 let inputt = (rendering_window#inputt : GEdit.text) in
1311 let oldinputt = (rendering_window#oldinputt : GEdit.text) in
1312 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1313 let output = (rendering_window#output : GMathView.math_view) in
1314 let proofw = (rendering_window#proofw : GMathView.math_view) in
1315 let inputlen = inputt#length in
1316 let input = inputt#get_chars 0 inputlen ^ "\n" in
1317 (* Do something interesting *)
1318 let lexbuf = Lexing.from_string input in
1321 (* Execute the actions *)
1323 CicTextualParserContext.main [] [] CicTextualLexer.token
1324 lexbuf register_alias
1327 | Some (dom,mk_metasenv_and_expr) ->
1329 disambiguate_input [] [] dom mk_metasenv_and_expr
1331 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1332 ProofEngine.proof :=
1333 Some (UriManager.uri_of_string "cic:/dummy.con",
1334 (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1335 ProofEngine.goal := Some 1 ;
1336 refresh_sequent proofw ;
1337 refresh_proof output ;
1340 CicTextualParser0.Eof ->
1341 inputt#delete_text 0 inputlen ;
1342 ignore(oldinputt#insert_text input oldinputt#length)
1343 | RefreshSequentException e ->
1344 output_html outputhtml
1345 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1346 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1347 | RefreshProofException e ->
1348 output_html outputhtml
1349 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1350 "proof: " ^ Printexc.to_string e ^ "</h1>")
1352 output_html outputhtml
1353 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1356 let check_term_in_scratch scratch_window metasenv context expr =
1358 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1359 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1360 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1361 scratch_window#show () ;
1362 scratch_window#mmlwidget#load_tree ~dom:mml
1365 print_endline ("? " ^ CicPp.ppterm expr) ;
1369 let check rendering_window scratch_window () =
1370 let inputt = (rendering_window#inputt : GEdit.text) in
1371 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1372 let inputlen = inputt#length in
1373 let input = inputt#get_chars 0 inputlen ^ "\n" in
1375 match !ProofEngine.proof with
1376 None -> UriManager.uri_of_string "cic:/dummy.con", []
1377 | Some (curi,metasenv,_,_) -> curi,metasenv
1379 let context,names_context =
1381 match !ProofEngine.goal with
1384 let (_,canonical_context,_) =
1385 List.find (function (m,_,_) -> m=metano) metasenv
1392 Some (n,_) -> Some n
1396 let lexbuf = Lexing.from_string input in
1399 (* Execute the actions *)
1401 CicTextualParserContext.main names_context metasenv CicTextualLexer.token
1402 lexbuf register_alias
1405 | Some (dom,mk_metasenv_and_expr) ->
1406 let (metasenv',expr) =
1407 disambiguate_input context metasenv dom mk_metasenv_and_expr
1409 check_term_in_scratch scratch_window metasenv' context expr
1412 CicTextualParser0.Eof -> ()
1414 output_html outputhtml
1415 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1418 exception NoObjectsLocated;;
1420 let user_uri_choice ~title ~msg uris =
1423 [] -> raise NoObjectsLocated
1426 interactive_user_uri_choice ~title ~msg uris
1428 String.sub uri 4 (String.length uri - 4)
1431 let locate rendering_window () =
1432 let inputt = (rendering_window#inputt : GEdit.text) in
1433 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1434 let inputlen = inputt#length in
1435 let input = inputt#get_chars 0 inputlen in
1437 match Str.split (Str.regexp "[ \t]+") input with
1440 inputt#delete_text 0 inputlen ;
1441 let result = MQueryGenerator.locate head in
1444 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1446 let html = (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>") in
1447 output_html outputhtml html ;
1449 user_uri_choice ~title:"Ambiguous input."
1451 ("Ambiguous input \"" ^ head ^
1452 "\". Please, choose one interpetation:")
1455 ignore ((inputt#insert_text uri') ~pos:0)
1458 output_html outputhtml
1459 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1462 let searchPattern rendering_window () =
1463 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1464 let inputt = (rendering_window#inputt : GEdit.text) in
1465 let inputlen = inputt#length in
1466 let input = inputt#get_chars 0 inputlen in
1467 let level = int_of_string input in
1469 match !ProofEngine.proof with
1470 None -> assert false
1471 | Some (_,metasenv,_,_) -> metasenv
1474 match !ProofEngine.goal with
1477 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
1478 let result = MQueryGenerator.searchPattern metasenv ey ty level in
1481 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1484 " <h1>Backward Query: </h1>" ^
1485 " <h2>Levels: </h2> " ^
1486 MQueryGenerator.string_of_levels
1487 (MQueryGenerator.levels_of_term metasenv ey ty) "<br>" ^
1488 " <pre>" ^ get_last_query result ^ "</pre>"
1490 output_html outputhtml html ;
1492 let rec filter_out =
1496 let tl',exc = filter_out tl in
1498 if ProofEngine.can_apply (term_of_uri uri) then
1505 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
1506 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
1513 " <h1>Objects that can actually be applied: </h1> " ^
1514 String.concat "<br>" uris' ^ exc ^
1515 " <h1>Number of false matches: " ^
1516 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
1517 " <h1>Number of good matches: " ^
1518 string_of_int (List.length uris') ^ "</h1>"
1520 output_html outputhtml html' ;
1522 user_uri_choice ~title:"Ambiguous input."
1523 ~msg:"Many lemmas can be successfully applied. Please, choose one:"
1526 inputt#delete_text 0 inputlen ;
1527 ignore ((inputt#insert_text uri') ~pos:0)
1530 output_html outputhtml
1531 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1534 let choose_selection
1535 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
1537 let module G = Gdome in
1538 let rec aux element =
1539 if element#hasAttributeNS
1540 ~namespaceURI:helmns
1541 ~localName:(G.domString "xref")
1543 mmlwidget#set_selection (Some element)
1545 match element#get_parentNode with
1546 None -> assert false
1547 (*CSC: OCAML DIVERGES!
1548 | Some p -> aux (new G.element_of_node p)
1550 | Some p -> aux (new Gdome.element_of_node p)
1554 | None -> mmlwidget#set_selection None
1557 (* STUFF TO BUILD THE GTK INTERFACE *)
1559 (* Stuff for the widget settings *)
1561 let export_to_postscript (output : GMathView.math_view) () =
1562 output#export_to_postscript ~filename:"output.ps" ();
1565 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
1566 button_set_kerning button_set_transparency button_export_to_postscript
1569 let is_set = button_t1#active in
1570 output#set_font_manager_type
1571 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
1574 button_set_anti_aliasing#misc#set_sensitive true ;
1575 button_set_kerning#misc#set_sensitive true ;
1576 button_set_transparency#misc#set_sensitive true ;
1577 button_export_to_postscript#misc#set_sensitive true ;
1581 button_set_anti_aliasing#misc#set_sensitive false ;
1582 button_set_kerning#misc#set_sensitive false ;
1583 button_set_transparency#misc#set_sensitive false ;
1584 button_export_to_postscript#misc#set_sensitive false ;
1588 let set_anti_aliasing output button_set_anti_aliasing () =
1589 output#set_anti_aliasing button_set_anti_aliasing#active
1592 let set_kerning output button_set_kerning () =
1593 output#set_kerning button_set_kerning#active
1596 let set_transparency output button_set_transparency () =
1597 output#set_transparency button_set_transparency#active
1600 let changefont output font_size_spinb () =
1601 output#set_font_size font_size_spinb#value_as_int
1604 let set_log_verbosity output log_verbosity_spinb () =
1605 output#set_log_verbosity log_verbosity_spinb#value_as_int
1608 class settings_window (output : GMathView.math_view) sw
1609 button_export_to_postscript selection_changed_callback
1611 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
1613 GPack.vbox ~packing:settings_window#add () in
1616 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1617 ~border_width:5 ~packing:vbox#add () in
1619 GButton.toggle_button ~label:"activate t1 fonts"
1620 ~packing:(table#attach ~left:0 ~top:0) () in
1621 let button_set_anti_aliasing =
1622 GButton.toggle_button ~label:"set_anti_aliasing"
1623 ~packing:(table#attach ~left:0 ~top:1) () in
1624 let button_set_kerning =
1625 GButton.toggle_button ~label:"set_kerning"
1626 ~packing:(table#attach ~left:1 ~top:1) () in
1627 let button_set_transparency =
1628 GButton.toggle_button ~label:"set_transparency"
1629 ~packing:(table#attach ~left:2 ~top:1) () in
1632 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1633 ~border_width:5 ~packing:vbox#add () in
1634 let font_size_label =
1635 GMisc.label ~text:"font size:"
1636 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
1637 let font_size_spinb =
1639 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
1642 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
1643 let log_verbosity_label =
1644 GMisc.label ~text:"log verbosity:"
1645 ~packing:(table#attach ~left:0 ~top:1) () in
1646 let log_verbosity_spinb =
1648 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
1651 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
1653 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1655 GButton.button ~label:"Close"
1656 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1658 method show = settings_window#show
1660 button_set_anti_aliasing#misc#set_sensitive false ;
1661 button_set_kerning#misc#set_sensitive false ;
1662 button_set_transparency#misc#set_sensitive false ;
1663 (* Signals connection *)
1664 ignore(button_t1#connect#clicked
1665 (activate_t1 output button_set_anti_aliasing button_set_kerning
1666 button_set_transparency button_export_to_postscript button_t1)) ;
1667 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
1668 ignore(button_set_anti_aliasing#connect#toggled
1669 (set_anti_aliasing output button_set_anti_aliasing));
1670 ignore(button_set_kerning#connect#toggled
1671 (set_kerning output button_set_kerning)) ;
1672 ignore(button_set_transparency#connect#toggled
1673 (set_transparency output button_set_transparency)) ;
1674 ignore(log_verbosity_spinb#connect#changed
1675 (set_log_verbosity output log_verbosity_spinb)) ;
1676 ignore(closeb#connect#clicked settings_window#misc#hide)
1679 (* Scratch window *)
1681 class scratch_window outputhtml =
1683 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1685 GPack.vbox ~packing:window#add () in
1687 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1689 GButton.button ~label:"Whd"
1690 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1692 GButton.button ~label:"Reduce"
1693 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1695 GButton.button ~label:"Simpl"
1696 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1697 let scrolled_window =
1698 GBin.scrolled_window ~border_width:10
1699 ~packing:(vbox#pack ~expand:true ~padding:5) () in
1702 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
1704 method outputhtml = outputhtml
1705 method mmlwidget = mmlwidget
1706 method show () = window#misc#hide () ; window#show ()
1708 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
1709 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
1710 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
1711 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
1712 ignore(simplb#connect#clicked (simpl_in_scratch self))
1717 class rendering_window output proofw (label : GMisc.label) =
1719 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1721 GPack.hbox ~packing:window#add () in
1723 GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1724 let _ = vbox#pack ~expand:false ~fill:false ~padding:5 label#coerce in
1725 let scrolled_window0 =
1726 GBin.scrolled_window ~border_width:10
1727 ~packing:(vbox#pack ~expand:true ~padding:5) () in
1728 let _ = scrolled_window0#add output#coerce in
1730 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1732 GButton.button ~label:"Settings"
1733 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1734 let button_export_to_postscript =
1735 GButton.button ~label:"export_to_postscript"
1736 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1738 GButton.button ~label:"Qed"
1739 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1741 GButton.button ~label:"Save"
1742 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1744 GButton.button ~label:"Load"
1745 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1747 GButton.button ~label:"Close"
1748 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1750 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1752 GButton.button ~label:"Prove It"
1753 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1755 GButton.button ~label:"Focus"
1756 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1758 GButton.button ~label:"<"
1759 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1761 GButton.button ~label:">"
1762 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1763 let oldinputt = GEdit.text ~editable:false ~width:400 ~height:180
1764 ~packing:(vbox#pack ~padding:5) () in
1766 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1768 GButton.button ~label:"State"
1769 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1771 GButton.button ~label:"Open"
1772 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1774 GButton.button ~label:"Check"
1775 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1777 GButton.button ~label:"Locate"
1778 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1779 let searchpatternb =
1780 GButton.button ~label:"SearchPattern"
1781 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1782 let inputt = GEdit.text ~editable:true ~width:400 ~height: 100
1783 ~packing:(vbox#pack ~padding:5) () in
1785 GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1786 let scrolled_window1 =
1787 GBin.scrolled_window ~border_width:10
1788 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
1789 let _ = scrolled_window1#add proofw#coerce in
1791 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1793 GButton.button ~label:"Exact"
1794 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1796 GButton.button ~label:"Intros"
1797 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1799 GButton.button ~label:"Apply"
1800 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1801 let elimsimplintrosb =
1802 GButton.button ~label:"ElimSimplIntros"
1803 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1805 GButton.button ~label:"ElimType"
1806 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1808 GButton.button ~label:"Whd"
1809 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1811 GButton.button ~label:"Reduce"
1812 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1814 GButton.button ~label:"Simpl"
1815 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1817 GButton.button ~label:"Fold"
1818 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1820 GButton.button ~label:"Cut"
1821 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1823 GButton.button ~label:"Change"
1824 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1826 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1828 GButton.button ~label:"Let ... In"
1829 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1831 GButton.button ~label:"Ring"
1832 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1834 GButton.button ~label:"ClearBody"
1835 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1837 GButton.button ~label:"Clear"
1838 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1840 GButton.button ~label:"Fourier"
1841 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1843 GButton.button ~label:"RewriteSimpl ->"
1844 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1846 GButton.button ~label:"Reflexivity"
1847 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1849 GButton.button ~label:"Symmetry"
1850 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1852 GButton.button ~label:"Transitivity"
1853 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1855 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1857 GButton.button ~label:"Left"
1858 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1860 GButton.button ~label:"Right"
1861 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1863 GButton.button ~label:"Assumption"
1864 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1866 let prova_tatticalib =
1867 GButton.button ~label:"Prova_tatticali"
1868 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1872 ~source:"<html><body bgColor=\"white\"></body></html>"
1873 ~width:400 ~height: 200
1874 ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5)
1876 let scratch_window = new scratch_window outputhtml in
1878 method outputhtml = outputhtml
1879 method oldinputt = oldinputt
1880 method inputt = inputt
1881 method output = (output : GMathView.math_view)
1882 method proofw = (proofw : GMathView.math_view)
1883 method show = window#show
1885 button_export_to_postscript#misc#set_sensitive false ;
1886 check_term := (check_term_in_scratch scratch_window) ;
1888 (* signal handlers here *)
1889 ignore(output#connect#selection_changed
1890 (function elem -> proofw#unload ; choose_selection output elem)) ;
1891 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
1892 ignore(closeb#connect#clicked (fun _ -> GMain.Main.quit ())) ;
1893 let settings_window = new settings_window output scrolled_window0
1894 button_export_to_postscript (choose_selection output) in
1895 ignore(settingsb#connect#clicked settings_window#show) ;
1896 ignore(button_export_to_postscript#connect#clicked (export_to_postscript output)) ;
1897 ignore(qedb#connect#clicked (qed self)) ;
1898 ignore(saveb#connect#clicked (save self)) ;
1899 ignore(loadb#connect#clicked (load self)) ;
1900 ignore(proveitb#connect#clicked (proveit self)) ;
1901 ignore(focusb#connect#clicked (focus self)) ;
1902 ignore(prevgoalb#connect#clicked (prev_or_next_goal prevgoal self)) ;
1903 ignore(nextgoalb#connect#clicked (prev_or_next_goal nextgoal self)) ;
1904 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
1905 ignore(stateb#connect#clicked (state self)) ;
1906 ignore(openb#connect#clicked (open_ self)) ;
1907 ignore(checkb#connect#clicked (check self scratch_window)) ;
1908 ignore(locateb#connect#clicked (locate self)) ;
1909 ignore(searchpatternb#connect#clicked (searchPattern self)) ;
1910 ignore(exactb#connect#clicked (exact self)) ;
1911 ignore(applyb#connect#clicked (apply self)) ;
1912 ignore(elimsimplintrosb#connect#clicked (elimsimplintros self)) ;
1913 ignore(elimtypeb#connect#clicked (elimtype self)) ;
1914 ignore(whdb#connect#clicked (whd self)) ;
1915 ignore(reduceb#connect#clicked (reduce self)) ;
1916 ignore(simplb#connect#clicked (simpl self)) ;
1917 ignore(foldb#connect#clicked (fold self)) ;
1918 ignore(cutb#connect#clicked (cut self)) ;
1919 ignore(changeb#connect#clicked (change self)) ;
1920 ignore(letinb#connect#clicked (letin self)) ;
1921 ignore(ringb#connect#clicked (ring self)) ;
1922 ignore(clearbodyb#connect#clicked (clearbody self)) ;
1923 ignore(clearb#connect#clicked (clear self)) ;
1924 ignore(fourierb#connect#clicked (fourier self)) ;
1925 ignore(rewritesimplb#connect#clicked (rewritesimpl self)) ;
1926 ignore(reflexivityb#connect#clicked (reflexivity self)) ;
1927 ignore(symmetryb#connect#clicked (symmetry self)) ;
1928 ignore(transitivityb#connect#clicked (transitivity self)) ;
1929 ignore(leftb#connect#clicked (left self)) ;
1930 ignore(rightb#connect#clicked (right self)) ;
1931 ignore(assumptionb#connect#clicked (assumption self)) ;
1933 ignore(prova_tatticalib#connect#clicked (prova_tatticali self)) ;
1935 ignore(introsb#connect#clicked (intros self)) ;
1936 Logger.log_callback :=
1937 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
1942 let initialize_everything () =
1943 let module U = Unix in
1944 let output = GMathView.math_view ~width:350 ~height:280 ()
1945 and proofw = GMathView.math_view ~width:400 ~height:275 ()
1946 and label = GMisc.label ~text:"gTopLevel" () in
1947 let rendering_window' =
1948 new rendering_window output proofw label
1950 rendering_window := Some rendering_window' ;
1951 rendering_window'#show () ;
1957 (* Mqint.init "dbname=helm_mowgli" ; *)
1958 Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ;
1959 ignore (GtkMain.Main.init ()) ;
1960 initialize_everything () ;
1961 if !usedb then Mqint.close ();