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";;
79 let empty_id_to_uris = ([],function _ -> None);;
82 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
84 let htmlheader_and_content = ref htmlheader;;
86 let current_cic_infos = ref None;;
87 let current_goal_infos = ref None;;
88 let current_scratch_infos = ref None;;
90 let id_to_uris = ref empty_id_to_uris;;
92 let check_term = ref (fun _ _ _ -> assert false);;
93 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
95 exception RenderingWindowsNotInitialized;;
97 let set_rendering_window,rendering_window =
98 let rendering_window_ref = ref None in
99 (function rw -> rendering_window_ref := Some rw),
101 match !rendering_window_ref with
102 None -> raise RenderingWindowsNotInitialized
107 exception SettingsWindowsNotInitialized;;
109 let set_settings_window,settings_window =
110 let settings_window_ref = ref None in
111 (function rw -> settings_window_ref := Some rw),
113 match !settings_window_ref with
114 None -> raise SettingsWindowsNotInitialized
119 exception OutputHtmlNotInitialized;;
121 let set_outputhtml,outputhtml =
122 let outputhtml_ref = ref None in
123 (function rw -> outputhtml_ref := Some rw),
125 match !outputhtml_ref with
126 None -> raise OutputHtmlNotInitialized
127 | Some outputhtml -> outputhtml
131 (* COMMAND LINE OPTIONS *)
137 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
140 Arg.parse argspec ignore ""
145 let cic_textual_parser_uri_of_string uri' =
147 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
148 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
150 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
151 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
155 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
156 CicTextualParser0.IndTyUri (uri'',typeno)
159 (* Constructor of an Inductive Type *)
160 let uri'',typeno,consno =
161 CicTextualLexer.indconuri_of_uri uri'
163 CicTextualParser0.IndConUri (uri'',typeno,consno)
167 let term_of_cic_textual_parser_uri uri =
168 let module C = Cic in
169 let module CTP = CicTextualParser0 in
171 CTP.ConUri uri -> C.Const (uri,[])
172 | CTP.VarUri uri -> C.Var (uri,[])
173 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
174 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
177 let string_of_cic_textual_parser_uri uri =
178 let module C = Cic in
179 let module CTP = CicTextualParser0 in
182 CTP.ConUri uri -> UriManager.string_of_uri uri
183 | CTP.VarUri uri -> UriManager.string_of_uri uri
184 | CTP.IndTyUri (uri,tyno) ->
185 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
186 | CTP.IndConUri (uri,tyno,consno) ->
187 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
190 (* 4 = String.length "cic:" *)
191 String.sub uri' 4 (String.length uri' - 4)
194 let output_html outputhtml msg =
195 htmlheader_and_content := !htmlheader_and_content ^ msg ;
196 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
197 outputhtml#set_topline (-1)
200 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
204 let check_window outputhtml uris_and_terms =
207 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
209 GPack.notebook ~scrollable:true ~packing:window#add () in
212 (function (uri,expr) ->
213 let scrolled_window =
214 GBin.scrolled_window ~border_width:10
216 (notebook#append_page
217 ~tab_label:((GMisc.label ~text:uri ())#coerce)
222 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
224 let mml = !mml_of_cic_term_ref 111 expr in
225 prerr_endline ("### " ^ CicPp.ppterm expr) ;
226 mmlwidget#load_tree ~dom:mml
229 output_html outputhtml
230 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
238 interactive_user_uri_choice ~selection_mode ?(ok="Ok") ~title ~msg uris
240 let choices = ref [] in
241 let chosen = ref false in
243 GWindow.dialog ~modal:true ~title ~width:600 () in
245 GMisc.label ~text:msg
246 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
247 let scrolled_window =
248 GBin.scrolled_window ~border_width:10
249 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
251 let expected_height = 8 * List.length uris in
252 let height = if expected_height > 400 then 400 else expected_height in
253 GList.clist ~columns:1 ~packing:scrolled_window#add
254 ~height ~selection_mode () in
255 let _ = List.map (function x -> clist#append [x]) uris in
257 GPack.hbox ~border_width:0
258 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
260 GMisc.label ~text:"None of the above. Try this one:"
261 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
263 GEdit.entry ~editable:true
264 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
266 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
268 GButton.button ~label:ok
269 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
270 let _ = okb#misc#set_sensitive false in
272 GButton.button ~label:"Check"
273 ~packing:(hbox#pack ~padding:5) () in
274 let _ = checkb#misc#set_sensitive false in
276 GButton.button ~label:"Abort"
277 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
279 let check_callback () =
280 assert (List.length !choices > 0) ;
281 check_window (outputhtml ())
285 term_of_cic_textual_parser_uri
286 (cic_textual_parser_uri_of_string uri)
289 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
292 ignore (window#connect#destroy GMain.Main.quit) ;
293 ignore (cancelb#connect#clicked window#destroy) ;
295 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
296 ignore (checkb#connect#clicked check_callback) ;
298 (clist#connect#select_row
299 (fun ~row ~column ~event ->
300 checkb#misc#set_sensitive true ;
301 okb#misc#set_sensitive true ;
302 choices := (List.nth uris row)::!choices)) ;
304 (clist#connect#unselect_row
305 (fun ~row ~column ~event ->
307 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
309 (manual_input#connect#changed
311 if manual_input#text = "" then
314 checkb#misc#set_sensitive false ;
315 okb#misc#set_sensitive false ;
316 clist#misc#set_sensitive true
320 choices := [manual_input#text] ;
321 clist#unselect_all () ;
322 checkb#misc#set_sensitive true ;
323 okb#misc#set_sensitive true ;
324 clist#misc#set_sensitive false
326 window#set_position `CENTER ;
329 if !chosen or List.length !choices > 0 then
337 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
339 let query = ref "" in
340 MQueryGenerator.set_confirm_query
341 (function q -> query := MQueryUtil.text_of_query q ; true) ;
342 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
345 let register_alias (id,uri) =
346 let dom,resolve_id = !id_to_uris in
348 (if List.mem id dom then dom else id::dom),
349 function id' -> if id' = id then Some uri else resolve_id id'
352 let locate_one_id id =
353 let result = MQueryGenerator.locate id in
357 wrong_xpointer_format_from_wrong_xpointer_format' uri
359 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
360 output_html (rendering_window ())#outputhtml html ;
365 (GToolbox.input_string ~title:"Unknown input"
366 ("No URI matching \"" ^ id ^ "\" found. Please enter its URI"))
368 None -> raise NoChoice
369 | Some uri -> ["cic:" ^ uri]
373 interactive_user_uri_choice
374 ~selection_mode:`EXTENDED
375 ~ok:"Try all the sections."
376 ~title:"Ambiguous input."
378 ("Ambiguous input \"" ^ id ^
379 "\". Please, choose one or more interpretations:")
382 List.map cic_textual_parser_uri_of_string uris'
385 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
386 exception AmbiguousInput;;
388 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
389 let known_ids,resolve_id = !id_to_uris in
395 if List.mem he known_ids then filter tl else he::(filter tl)
399 (* for each id in dom' we get the list of uris associated to it *)
400 let list_of_uris = List.map locate_one_id dom' in
401 (* and now we compute the list of all possible assignments from id to uris *)
403 let rec aux ids list_of_uris =
404 match ids,list_of_uris with
405 [],[] -> [resolve_id]
406 | id::idtl,uris::uristl ->
407 let resolves = aux idtl uristl in
413 function id' -> if id = id' then Some uri else f id'
417 | _,_ -> assert false
419 aux dom' list_of_uris
421 prerr_endline ("##### NE DISAMBIGUO: " ^ string_of_int (List.length resolve_ids)) ;
422 (* now we select only the ones that generates well-typed terms *)
428 let metasenv',expr = mk_metasenv_and_expr resolve in
430 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
432 (CicTypeChecker.type_of_aux' metasenv context expr) ;
440 match resolve_ids' with
441 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
442 | [resolve_id] -> resolve_id
451 match resolve id with
455 CicTextualParser0.ConUri uri
456 | CicTextualParser0.VarUri uri ->
457 UriManager.string_of_uri uri
458 | CicTextualParser0.IndTyUri (uri,tyno) ->
459 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
460 string_of_int (tyno+1) ^ ")"
461 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
462 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
463 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
469 GToolbox.question_box ~title:"Ambiguous input."
471 ~default:1 "Ambiguous input. Please, choose one interpretation."
474 List.nth resolve_ids' (choice - 1)
476 (* No choice from the user *)
479 id_to_uris := known_ids @ dom', resolve_id' ;
480 mk_metasenv_and_expr resolve_id'
483 let domImpl = Gdome.domImplementation ();;
485 let parseStyle name =
487 domImpl#createDocumentFromURI
489 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
491 ~uri:("styles/" ^ name) ()
493 Gdome_xslt.processStylesheet style
496 let d_c = parseStyle "drop_coercions.xsl";;
497 let tc1 = parseStyle "objtheorycontent.xsl";;
498 let hc2 = parseStyle "content_to_html.xsl";;
499 let l = parseStyle "link.xsl";;
501 let c1 = parseStyle "rootcontent.xsl";;
502 let g = parseStyle "genmmlid.xsl";;
503 let c2 = parseStyle "annotatedpres.xsl";;
506 let getterURL = Configuration.getter_url;;
507 let processorURL = Configuration.processor_url;;
509 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
511 ["processorURL", "'" ^ processorURL ^ "'" ;
512 "getterURL", "'" ^ getterURL ^ "'" ;
513 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
514 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
515 "UNICODEvsSYMBOL", "'symbol'" ;
516 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
517 "encoding", "'iso-8859-1'" ;
518 "media-type", "'text/html'" ;
519 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
520 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
521 "naturalLanguage", "'yes'" ;
522 "annotations", "'no'" ;
523 "explodeall", "'true()'" ;
524 "topurl", "'http://phd.cs.unibo.it/helm'" ;
525 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
528 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
530 ["processorURL", "'" ^ processorURL ^ "'" ;
531 "getterURL", "'" ^ getterURL ^ "'" ;
532 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
533 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
534 "UNICODEvsSYMBOL", "'symbol'" ;
535 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
536 "encoding", "'iso-8859-1'" ;
537 "media-type", "'text/html'" ;
538 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
539 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
540 "naturalLanguage", "'no'" ;
541 "annotations", "'no'" ;
542 "explodeall", "'true()'" ;
543 "topurl", "'http://phd.cs.unibo.it/helm'" ;
544 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
547 let parse_file filename =
548 let inch = open_in filename in
549 let rec read_lines () =
551 let line = input_line inch in
559 let applyStylesheets input styles args =
560 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
564 let mml_of_cic_object uri annobj ids_to_inner_sorts ids_to_inner_types =
565 (*CSC: ????????????????? *)
567 Cic2Xml.print_object uri ~ids_to_inner_sorts annobj
570 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts
575 None -> Xml2Gdome.document_of_xml domImpl xml
577 Xml.pp xml (Some constanttypefile) ;
578 Xml2Gdome.document_of_xml domImpl bodyxml'
580 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
581 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
583 Xml.pp xmlinnertypes (Some innertypesfile) ;
584 let output = applyStylesheets input mml_styles mml_args in
591 exception RefreshSequentException of exn;;
592 exception RefreshProofException of exn;;
594 let refresh_proof (output : GMathView.math_view) =
596 let uri,currentproof =
597 match !ProofEngine.proof with
599 | Some (uri,metasenv,bo,ty) ->
600 (*CSC: Wrong: [] is just plainly wrong *)
601 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
604 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
605 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
607 Cic2acic.acic_object_of_cic_object currentproof
610 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
612 output#load_tree mml ;
614 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
617 match !ProofEngine.proof with
619 | Some (uri,metasenv,bo,ty) ->
620 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
621 raise (RefreshProofException e)
624 let refresh_sequent ?(empty_notebook=true) notebook =
626 match !ProofEngine.goal with
628 if empty_notebook then
630 notebook#remove_all_pages ;
631 notebook#set_empty_page
634 notebook#proofw#unload
637 match !ProofEngine.proof with
639 | Some (_,metasenv,_,_) -> metasenv
641 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
642 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
643 SequentPp.XmlPp.print_sequent metasenv currentsequent
646 Xml2Gdome.document_of_xml domImpl sequent_gdome
649 applyStylesheets sequent_doc sequent_styles sequent_args
651 if empty_notebook then
653 notebook#remove_all_pages ;
654 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
656 notebook#set_current_page metano ;
657 notebook#proofw#load_tree ~dom:sequent_mml ;
658 current_goal_infos :=
659 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
663 match !ProofEngine.goal with
668 match !ProofEngine.proof with
670 | Some (_,metasenv,_,_) -> metasenv
672 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
673 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
674 raise (RefreshSequentException e)
678 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
679 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
682 let mml_of_cic_term metano term =
684 match !ProofEngine.proof with
686 | Some (_,metasenv,_,_) -> metasenv
689 match !ProofEngine.goal with
692 let (_,canonical_context,_) =
693 List.find (function (m,_,_) -> m=metano) metasenv
697 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
698 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
701 Xml2Gdome.document_of_xml domImpl sequent_gdome
704 applyStylesheets sequent_doc sequent_styles sequent_args ;
706 current_scratch_infos :=
707 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
711 (***********************)
713 (***********************)
715 let call_tactic tactic () =
716 let notebook = (rendering_window ())#notebook in
717 let output = ((rendering_window ())#output : GMathView.math_view) in
718 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
719 let savedproof = !ProofEngine.proof in
720 let savedgoal = !ProofEngine.goal in
724 refresh_sequent notebook ;
727 RefreshSequentException e ->
728 output_html outputhtml
729 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
730 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
731 ProofEngine.proof := savedproof ;
732 ProofEngine.goal := savedgoal ;
733 refresh_sequent notebook
734 | RefreshProofException e ->
735 output_html outputhtml
736 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
737 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
738 ProofEngine.proof := savedproof ;
739 ProofEngine.goal := savedgoal ;
740 refresh_sequent notebook ;
743 output_html outputhtml
744 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
745 ProofEngine.proof := savedproof ;
746 ProofEngine.goal := savedgoal ;
750 let call_tactic_with_input tactic () =
751 let notebook = (rendering_window ())#notebook in
752 let output = ((rendering_window ())#output : GMathView.math_view) in
753 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
754 let inputt = ((rendering_window ())#inputt : GEdit.text) in
755 let savedproof = !ProofEngine.proof in
756 let savedgoal = !ProofEngine.goal in
757 (*CSC: Gran cut&paste da sotto... *)
758 let inputlen = inputt#length in
759 let input = inputt#get_chars 0 inputlen ^ "\n" in
760 let lexbuf = Lexing.from_string input in
762 match !ProofEngine.proof with
764 | Some (curi,_,_,_) -> curi
766 let uri,metasenv,bo,ty =
767 match !ProofEngine.proof with
769 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
771 let canonical_context =
772 match !ProofEngine.goal with
775 let (_,canonical_context,_) =
776 List.find (function (m,_,_) -> m=metano) metasenv
790 CicTextualParserContext.main context metasenv CicTextualLexer.token
791 lexbuf register_alias
794 | Some (dom,mk_metasenv_and_expr) ->
795 let (metasenv',expr) =
796 disambiguate_input canonical_context metasenv dom
799 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
801 refresh_sequent notebook ;
805 CicTextualParser0.Eof ->
806 inputt#delete_text 0 inputlen
807 | RefreshSequentException e ->
808 output_html outputhtml
809 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
810 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
811 ProofEngine.proof := savedproof ;
812 ProofEngine.goal := savedgoal ;
813 refresh_sequent notebook
814 | RefreshProofException e ->
815 output_html outputhtml
816 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
817 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
818 ProofEngine.proof := savedproof ;
819 ProofEngine.goal := savedgoal ;
820 refresh_sequent notebook ;
823 output_html outputhtml
824 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
825 ProofEngine.proof := savedproof ;
826 ProofEngine.goal := savedgoal ;
829 let call_tactic_with_goal_input tactic () =
830 let module L = LogicalOperations in
831 let module G = Gdome in
832 let notebook = (rendering_window ())#notebook in
833 let output = ((rendering_window ())#output : GMathView.math_view) in
834 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
835 let savedproof = !ProofEngine.proof in
836 let savedgoal = !ProofEngine.goal in
837 match notebook#proofw#get_selection with
840 ((node : Gdome.element)#getAttributeNS
842 ~localName:(G.domString "xref"))#to_string
844 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
848 match !current_goal_infos with
849 Some (ids_to_terms, ids_to_father_ids,_) ->
851 tactic (Hashtbl.find ids_to_terms id) ;
852 refresh_sequent notebook ;
854 | None -> assert false (* "ERROR: No current term!!!" *)
856 RefreshSequentException e ->
857 output_html outputhtml
858 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
859 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
860 ProofEngine.proof := savedproof ;
861 ProofEngine.goal := savedgoal ;
862 refresh_sequent notebook
863 | RefreshProofException e ->
864 output_html outputhtml
865 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
866 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
867 ProofEngine.proof := savedproof ;
868 ProofEngine.goal := savedgoal ;
869 refresh_sequent notebook ;
872 output_html outputhtml
873 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
874 ProofEngine.proof := savedproof ;
875 ProofEngine.goal := savedgoal ;
878 output_html outputhtml
879 ("<h1 color=\"red\">No term selected</h1>")
882 let call_tactic_with_input_and_goal_input tactic () =
883 let module L = LogicalOperations in
884 let module G = Gdome in
885 let notebook = (rendering_window ())#notebook in
886 let output = ((rendering_window ())#output : GMathView.math_view) in
887 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
888 let inputt = ((rendering_window ())#inputt : GEdit.text) in
889 let savedproof = !ProofEngine.proof in
890 let savedgoal = !ProofEngine.goal in
891 match notebook#proofw#get_selection with
894 ((node : Gdome.element)#getAttributeNS
896 ~localName:(G.domString "xref"))#to_string
898 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
902 match !current_goal_infos with
903 Some (ids_to_terms, ids_to_father_ids,_) ->
905 (* Let's parse the input *)
906 let inputlen = inputt#length in
907 let input = inputt#get_chars 0 inputlen ^ "\n" in
908 let lexbuf = Lexing.from_string input in
910 match !ProofEngine.proof with
912 | Some (curi,_,_,_) -> curi
914 let uri,metasenv,bo,ty =
915 match !ProofEngine.proof with
917 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
919 let canonical_context =
920 match !ProofEngine.goal with
923 let (_,canonical_context,_) =
924 List.find (function (m,_,_) -> m=metano) metasenv
938 CicTextualParserContext.main context metasenv
939 CicTextualLexer.token lexbuf register_alias
942 | Some (dom,mk_metasenv_and_expr) ->
943 let (metasenv',expr) =
944 disambiguate_input canonical_context metasenv dom
947 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
948 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
950 refresh_sequent notebook ;
954 CicTextualParser0.Eof ->
955 inputt#delete_text 0 inputlen
957 | None -> assert false (* "ERROR: No current term!!!" *)
959 RefreshSequentException e ->
960 output_html outputhtml
961 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
962 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
963 ProofEngine.proof := savedproof ;
964 ProofEngine.goal := savedgoal ;
965 refresh_sequent notebook
966 | RefreshProofException e ->
967 output_html outputhtml
968 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
969 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
970 ProofEngine.proof := savedproof ;
971 ProofEngine.goal := savedgoal ;
972 refresh_sequent notebook ;
975 output_html outputhtml
976 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
977 ProofEngine.proof := savedproof ;
978 ProofEngine.goal := savedgoal ;
981 output_html outputhtml
982 ("<h1 color=\"red\">No term selected</h1>")
985 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
986 let module L = LogicalOperations in
987 let module G = Gdome in
988 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
989 let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
990 let savedproof = !ProofEngine.proof in
991 let savedgoal = !ProofEngine.goal in
992 match mmlwidget#get_selection with
995 ((node : Gdome.element)#getAttributeNS
997 ~localName:(G.domString "xref"))#to_string
999 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1003 match !current_scratch_infos with
1004 (* term is the whole goal in the scratch_area *)
1005 Some (term,ids_to_terms, ids_to_father_ids,_) ->
1007 let expr = tactic term (Hashtbl.find ids_to_terms id) in
1008 let mml = mml_of_cic_term 111 expr in
1009 scratch_window#show () ;
1010 scratch_window#mmlwidget#load_tree ~dom:mml
1011 | None -> assert false (* "ERROR: No current term!!!" *)
1014 output_html outputhtml
1015 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1018 output_html outputhtml
1019 ("<h1 color=\"red\">No term selected</h1>")
1022 let call_tactic_with_hypothesis_input tactic () =
1023 let module L = LogicalOperations in
1024 let module G = Gdome in
1025 let notebook = (rendering_window ())#notebook in
1026 let output = ((rendering_window ())#output : GMathView.math_view) in
1027 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1028 let savedproof = !ProofEngine.proof in
1029 let savedgoal = !ProofEngine.goal in
1030 match notebook#proofw#get_selection with
1033 ((node : Gdome.element)#getAttributeNS
1034 ~namespaceURI:helmns
1035 ~localName:(G.domString "xref"))#to_string
1037 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1041 match !current_goal_infos with
1042 Some (_,_,ids_to_hypotheses) ->
1044 tactic (Hashtbl.find ids_to_hypotheses id) ;
1045 refresh_sequent notebook ;
1046 refresh_proof output
1047 | None -> assert false (* "ERROR: No current term!!!" *)
1049 RefreshSequentException e ->
1050 output_html outputhtml
1051 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1052 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1053 ProofEngine.proof := savedproof ;
1054 ProofEngine.goal := savedgoal ;
1055 refresh_sequent notebook
1056 | RefreshProofException e ->
1057 output_html outputhtml
1058 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1059 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1060 ProofEngine.proof := savedproof ;
1061 ProofEngine.goal := savedgoal ;
1062 refresh_sequent notebook ;
1063 refresh_proof output
1065 output_html outputhtml
1066 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1067 ProofEngine.proof := savedproof ;
1068 ProofEngine.goal := savedgoal ;
1071 output_html outputhtml
1072 ("<h1 color=\"red\">No term selected</h1>")
1076 let intros = call_tactic ProofEngine.intros;;
1077 let exact = call_tactic_with_input ProofEngine.exact;;
1078 let apply = call_tactic_with_input ProofEngine.apply;;
1079 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
1080 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
1081 let whd = call_tactic_with_goal_input ProofEngine.whd;;
1082 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
1083 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
1084 let fold = call_tactic_with_input ProofEngine.fold;;
1085 let cut = call_tactic_with_input ProofEngine.cut;;
1086 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
1087 let letin = call_tactic_with_input ProofEngine.letin;;
1088 let ring = call_tactic ProofEngine.ring;;
1089 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
1090 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
1091 let fourier = call_tactic ProofEngine.fourier;;
1092 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
1093 let reflexivity = call_tactic ProofEngine.reflexivity;;
1094 let symmetry = call_tactic ProofEngine.symmetry;;
1095 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
1096 let left = call_tactic ProofEngine.left;;
1097 let right = call_tactic ProofEngine.right;;
1098 let assumption = call_tactic ProofEngine.assumption;;
1100 let whd_in_scratch scratch_window =
1101 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
1104 let reduce_in_scratch scratch_window =
1105 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
1108 let simpl_in_scratch scratch_window =
1109 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
1115 (**********************)
1116 (* END OF TACTICS *)
1117 (**********************)
1119 exception OpenConjecturesStillThere;;
1120 exception WrongProof;;
1123 match !ProofEngine.proof with
1124 None -> assert false
1125 | Some (uri,[],bo,ty) ->
1127 CicReduction.are_convertible []
1128 (CicTypeChecker.type_of_aux' [] [] bo) ty
1131 (*CSC: Wrong: [] is just plainly wrong *)
1132 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
1134 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1135 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1137 Cic2acic.acic_object_of_cic_object proof
1140 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
1142 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
1143 current_cic_infos :=
1145 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
1150 | _ -> raise OpenConjecturesStillThere
1154 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
1155 let dtdname = "/home/tassi/miohelm/helm/dtd/cic.dtd";;
1157 let dtdname = "/projects/helm/V7_mowgli/dtd/cic.dtd";;
1160 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1161 match !ProofEngine.proof with
1162 None -> assert false
1163 | Some (uri, metasenv, bo, ty) ->
1165 (*CSC: Wrong: [] is just plainly wrong *)
1166 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
1168 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
1169 Cic2acic.acic_object_of_cic_object currentproof
1172 match Cic2Xml.print_object uri ~ids_to_inner_sorts acurrentproof with
1173 xml,Some bodyxml -> xml,bodyxml
1174 | _,None -> assert false
1176 Xml.pp ~quiet:true xml (Some prooffiletype) ;
1177 output_html outputhtml
1178 ("<h1 color=\"Green\">Current proof type saved to " ^
1179 prooffiletype ^ "</h1>") ;
1180 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
1181 output_html outputhtml
1182 ("<h1 color=\"Green\">Current proof body saved to " ^
1183 prooffile ^ "</h1>")
1186 (* Used to typecheck the loaded proofs *)
1187 let typecheck_loaded_proof metasenv bo ty =
1188 let module T = CicTypeChecker in
1191 (fun metasenv ((_,context,ty) as conj) ->
1192 ignore (T.type_of_aux' metasenv context ty) ;
1195 ignore (T.type_of_aux' metasenv [] ty) ;
1196 ignore (T.type_of_aux' metasenv [] bo)
1200 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1201 let output = ((rendering_window ())#output : GMathView.math_view) in
1202 let notebook = (rendering_window ())#notebook in
1204 let uri = UriManager.uri_of_string "cic:/dummy.con" in
1205 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
1206 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
1207 typecheck_loaded_proof metasenv bo ty ;
1208 ProofEngine.proof :=
1209 Some (uri, metasenv, bo, ty) ;
1211 (match metasenv with
1213 | (metano,_,_)::_ -> Some metano
1215 refresh_proof output ;
1216 refresh_sequent notebook ;
1217 output_html outputhtml
1218 ("<h1 color=\"Green\">Current proof type loaded from " ^
1219 prooffiletype ^ "</h1>") ;
1220 output_html outputhtml
1221 ("<h1 color=\"Green\">Current proof body loaded from " ^
1222 prooffile ^ "</h1>")
1225 RefreshSequentException e ->
1226 output_html outputhtml
1227 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1228 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1229 | RefreshProofException e ->
1230 output_html outputhtml
1231 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1232 "proof: " ^ Printexc.to_string e ^ "</h1>")
1234 output_html outputhtml
1235 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1238 let edit_aliases () =
1239 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1240 let dom,resolve_id = !id_to_uris in
1241 let inputlen = inputt#length in
1242 inputt#delete_text 0 inputlen ;
1244 inputt#insert_text ~pos:0
1249 match resolve_id v with
1250 None -> assert false
1253 "alias " ^ v ^ " " ^
1254 (string_of_cic_textual_parser_uri uri)
1257 id_to_uris := empty_id_to_uris
1261 let module L = LogicalOperations in
1262 let module G = Gdome in
1263 let notebook = (rendering_window ())#notebook in
1264 let output = (rendering_window ())#output in
1265 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1266 match (rendering_window ())#output#get_selection with
1269 ((node : Gdome.element)#getAttributeNS
1270 (*CSC: OCAML DIVERGE
1271 ((element : G.element)#getAttributeNS
1273 ~namespaceURI:helmns
1274 ~localName:(G.domString "xref"))#to_string
1276 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1280 match !current_cic_infos with
1281 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1283 L.to_sequent id ids_to_terms ids_to_father_ids ;
1284 refresh_proof output ;
1285 refresh_sequent notebook
1286 | None -> assert false (* "ERROR: No current term!!!" *)
1288 RefreshSequentException e ->
1289 output_html outputhtml
1290 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1291 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1292 | RefreshProofException e ->
1293 output_html outputhtml
1294 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1295 "proof: " ^ Printexc.to_string e ^ "</h1>")
1297 output_html outputhtml
1298 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1300 | None -> assert false (* "ERROR: No selection!!!" *)
1304 let module L = LogicalOperations in
1305 let module G = Gdome in
1306 let notebook = (rendering_window ())#notebook in
1307 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1308 match (rendering_window ())#output#get_selection with
1311 ((node : Gdome.element)#getAttributeNS
1312 (*CSC: OCAML DIVERGE
1313 ((element : G.element)#getAttributeNS
1315 ~namespaceURI:helmns
1316 ~localName:(G.domString "xref"))#to_string
1318 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1322 match !current_cic_infos with
1323 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1325 L.focus id ids_to_terms ids_to_father_ids ;
1326 refresh_sequent notebook
1327 | None -> assert false (* "ERROR: No current term!!!" *)
1329 RefreshSequentException e ->
1330 output_html outputhtml
1331 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1332 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1333 | RefreshProofException e ->
1334 output_html outputhtml
1335 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1336 "proof: " ^ Printexc.to_string e ^ "</h1>")
1338 output_html outputhtml
1339 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1341 | None -> assert false (* "ERROR: No selection!!!" *)
1344 exception NoPrevGoal;;
1345 exception NoNextGoal;;
1347 let setgoal metano =
1348 let module L = LogicalOperations in
1349 let module G = Gdome in
1350 let notebook = (rendering_window ())#notebook in
1351 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1353 match !ProofEngine.proof with
1354 None -> assert false
1355 | Some (_,metasenv,_,_) -> metasenv
1358 ProofEngine.goal := Some metano ;
1359 refresh_sequent ~empty_notebook:false notebook ;
1361 RefreshSequentException e ->
1362 output_html outputhtml
1363 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1364 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1366 output_html outputhtml
1367 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1370 exception NotADefinition;;
1373 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1374 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1375 let output = ((rendering_window ())#output : GMathView.math_view) in
1376 let notebook = (rendering_window ())#notebook in
1377 let inputlen = inputt#length in
1378 let input = inputt#get_chars 0 inputlen in
1380 let uri = UriManager.uri_of_string ("cic:" ^ input) in
1381 CicTypeChecker.typecheck uri ;
1382 let metasenv,bo,ty =
1383 match CicEnvironment.get_cooked_obj uri with
1384 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
1385 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
1388 | Cic.InductiveDefinition _ -> raise NotADefinition
1390 ProofEngine.proof :=
1391 Some (uri, metasenv, bo, ty) ;
1392 ProofEngine.goal := None ;
1393 refresh_sequent notebook ;
1394 refresh_proof output ;
1395 inputt#delete_text 0 inputlen
1397 RefreshSequentException e ->
1398 output_html outputhtml
1399 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1400 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1401 | RefreshProofException e ->
1402 output_html outputhtml
1403 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1404 "proof: " ^ Printexc.to_string e ^ "</h1>")
1406 output_html outputhtml
1407 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1411 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1412 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1413 let output = ((rendering_window ())#output : GMathView.math_view) in
1414 let notebook = (rendering_window ())#notebook in
1415 let inputlen = inputt#length in
1416 let input = inputt#get_chars 0 inputlen ^ "\n" in
1417 (* Do something interesting *)
1418 let lexbuf = Lexing.from_string input in
1421 (* Execute the actions *)
1423 CicTextualParserContext.main [] [] CicTextualLexer.token
1424 lexbuf register_alias
1427 | Some (dom,mk_metasenv_and_expr) ->
1429 disambiguate_input [] [] dom mk_metasenv_and_expr
1431 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1432 ProofEngine.proof :=
1433 Some (UriManager.uri_of_string "cic:/dummy.con",
1434 (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1435 ProofEngine.goal := Some 1 ;
1436 refresh_sequent notebook ;
1437 refresh_proof output ;
1440 CicTextualParser0.Eof ->
1441 inputt#delete_text 0 inputlen
1442 | RefreshSequentException e ->
1443 output_html outputhtml
1444 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1445 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1446 | RefreshProofException e ->
1447 output_html outputhtml
1448 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1449 "proof: " ^ Printexc.to_string e ^ "</h1>")
1451 output_html outputhtml
1452 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1455 let check_term_in_scratch scratch_window metasenv context expr =
1457 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1458 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1459 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1460 scratch_window#show () ;
1461 scratch_window#mmlwidget#load_tree ~dom:mml
1464 print_endline ("? " ^ CicPp.ppterm expr) ;
1468 let check scratch_window () =
1469 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1470 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1471 let inputlen = inputt#length in
1472 let input = inputt#get_chars 0 inputlen ^ "\n" in
1474 match !ProofEngine.proof with
1475 None -> UriManager.uri_of_string "cic:/dummy.con", []
1476 | Some (curi,metasenv,_,_) -> curi,metasenv
1478 let context,names_context =
1480 match !ProofEngine.goal with
1483 let (_,canonical_context,_) =
1484 List.find (function (m,_,_) -> m=metano) metasenv
1491 Some (n,_) -> Some n
1495 let lexbuf = Lexing.from_string input in
1498 (* Execute the actions *)
1500 CicTextualParserContext.main names_context metasenv CicTextualLexer.token
1501 lexbuf register_alias
1504 | Some (dom,mk_metasenv_and_expr) ->
1505 let (metasenv',expr) =
1506 disambiguate_input context metasenv dom mk_metasenv_and_expr
1508 check_term_in_scratch scratch_window metasenv' context expr
1511 CicTextualParser0.Eof -> ()
1513 output_html outputhtml
1514 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1517 exception NoObjectsLocated;;
1519 let user_uri_choice ~title ~msg uris =
1522 [] -> raise NoObjectsLocated
1526 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1531 String.sub uri 4 (String.length uri - 4)
1535 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1536 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1537 let inputlen = inputt#length in
1538 let input = inputt#get_chars 0 inputlen in
1540 match Str.split (Str.regexp "[ \t]+") input with
1543 inputt#delete_text 0 inputlen ;
1544 let result = MQueryGenerator.locate head in
1547 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1549 let html = (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>") in
1550 output_html outputhtml html ;
1552 user_uri_choice ~title:"Ambiguous input."
1554 ("Ambiguous input \"" ^ head ^
1555 "\". Please, choose one interpetation:")
1558 ignore ((inputt#insert_text uri') ~pos:0)
1561 output_html outputhtml
1562 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1565 let searchPattern () =
1566 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1567 let inputt = ((rendering_window ())#inputt : GEdit.text) in
1568 let inputlen = inputt#length in
1569 let input = inputt#get_chars 0 inputlen in
1570 let level = int_of_string input in
1572 match !ProofEngine.proof with
1573 None -> assert false
1574 | Some (_,metasenv,_,_) -> metasenv
1577 match !ProofEngine.goal with
1580 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
1581 let result = MQueryGenerator.searchPattern metasenv ey ty level in
1584 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1587 " <h1>Backward Query: </h1>" ^
1588 " <h2>Levels: </h2> " ^
1589 MQueryGenerator.string_of_levels
1590 (MQueryGenerator.levels_of_term metasenv ey ty) "<br>" ^
1591 " <pre>" ^ get_last_query result ^ "</pre>"
1593 output_html outputhtml html ;
1595 let rec filter_out =
1599 let tl',exc = filter_out tl in
1602 ProofEngine.can_apply
1603 (term_of_cic_textual_parser_uri
1604 (cic_textual_parser_uri_of_string uri))
1612 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
1613 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
1620 " <h1>Objects that can actually be applied: </h1> " ^
1621 String.concat "<br>" uris' ^ exc ^
1622 " <h1>Number of false matches: " ^
1623 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
1624 " <h1>Number of good matches: " ^
1625 string_of_int (List.length uris') ^ "</h1>"
1627 output_html outputhtml html' ;
1629 user_uri_choice ~title:"Ambiguous input."
1630 ~msg:"Many lemmas can be successfully applied. Please, choose one:"
1633 inputt#delete_text 0 inputlen ;
1634 ignore ((inputt#insert_text uri') ~pos:0)
1637 output_html outputhtml
1638 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1641 let choose_selection
1642 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
1644 let module G = Gdome in
1645 let rec aux element =
1646 if element#hasAttributeNS
1647 ~namespaceURI:helmns
1648 ~localName:(G.domString "xref")
1650 mmlwidget#set_selection (Some element)
1652 match element#get_parentNode with
1653 None -> assert false
1654 (*CSC: OCAML DIVERGES!
1655 | Some p -> aux (new G.element_of_node p)
1657 | Some p -> aux (new Gdome.element_of_node p)
1661 | None -> mmlwidget#set_selection None
1664 (* STUFF TO BUILD THE GTK INTERFACE *)
1666 (* Stuff for the widget settings *)
1668 let export_to_postscript (output : GMathView.math_view) =
1669 let lastdir = ref (Unix.getcwd ()) in
1672 GToolbox.select_file ~title:"Export to PostScript"
1673 ~dir:lastdir ~filename:"screenshot.ps" ()
1677 output#export_to_postscript ~filename:filename ();
1680 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
1681 button_set_kerning button_set_transparency export_to_postscript_menu_item
1684 let is_set = button_t1#active in
1685 output#set_font_manager_type
1686 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
1689 button_set_anti_aliasing#misc#set_sensitive true ;
1690 button_set_kerning#misc#set_sensitive true ;
1691 button_set_transparency#misc#set_sensitive true ;
1692 export_to_postscript_menu_item#misc#set_sensitive true ;
1696 button_set_anti_aliasing#misc#set_sensitive false ;
1697 button_set_kerning#misc#set_sensitive false ;
1698 button_set_transparency#misc#set_sensitive false ;
1699 export_to_postscript_menu_item#misc#set_sensitive false ;
1703 let set_anti_aliasing output button_set_anti_aliasing () =
1704 output#set_anti_aliasing button_set_anti_aliasing#active
1707 let set_kerning output button_set_kerning () =
1708 output#set_kerning button_set_kerning#active
1711 let set_transparency output button_set_transparency () =
1712 output#set_transparency button_set_transparency#active
1715 let changefont output font_size_spinb () =
1716 output#set_font_size font_size_spinb#value_as_int
1719 let set_log_verbosity output log_verbosity_spinb () =
1720 output#set_log_verbosity log_verbosity_spinb#value_as_int
1723 class settings_window (output : GMathView.math_view) sw
1724 export_to_postscript_menu_item selection_changed_callback
1726 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
1728 GPack.vbox ~packing:settings_window#add () in
1731 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1732 ~border_width:5 ~packing:vbox#add () in
1734 GButton.toggle_button ~label:"activate t1 fonts"
1735 ~packing:(table#attach ~left:0 ~top:0) () in
1736 let button_set_anti_aliasing =
1737 GButton.toggle_button ~label:"set_anti_aliasing"
1738 ~packing:(table#attach ~left:0 ~top:1) () in
1739 let button_set_kerning =
1740 GButton.toggle_button ~label:"set_kerning"
1741 ~packing:(table#attach ~left:1 ~top:1) () in
1742 let button_set_transparency =
1743 GButton.toggle_button ~label:"set_transparency"
1744 ~packing:(table#attach ~left:2 ~top:1) () in
1747 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1748 ~border_width:5 ~packing:vbox#add () in
1749 let font_size_label =
1750 GMisc.label ~text:"font size:"
1751 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
1752 let font_size_spinb =
1754 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
1757 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
1758 let log_verbosity_label =
1759 GMisc.label ~text:"log verbosity:"
1760 ~packing:(table#attach ~left:0 ~top:1) () in
1761 let log_verbosity_spinb =
1763 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
1766 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
1768 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1770 GButton.button ~label:"Close"
1771 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1773 method show = settings_window#show
1775 button_set_anti_aliasing#misc#set_sensitive false ;
1776 button_set_kerning#misc#set_sensitive false ;
1777 button_set_transparency#misc#set_sensitive false ;
1778 (* Signals connection *)
1779 ignore(button_t1#connect#clicked
1780 (activate_t1 output button_set_anti_aliasing button_set_kerning
1781 button_set_transparency export_to_postscript_menu_item button_t1)) ;
1782 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
1783 ignore(button_set_anti_aliasing#connect#toggled
1784 (set_anti_aliasing output button_set_anti_aliasing));
1785 ignore(button_set_kerning#connect#toggled
1786 (set_kerning output button_set_kerning)) ;
1787 ignore(button_set_transparency#connect#toggled
1788 (set_transparency output button_set_transparency)) ;
1789 ignore(log_verbosity_spinb#connect#changed
1790 (set_log_verbosity output log_verbosity_spinb)) ;
1791 ignore(closeb#connect#clicked settings_window#misc#hide)
1794 (* Scratch window *)
1796 class scratch_window outputhtml =
1798 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1800 GPack.vbox ~packing:window#add () in
1802 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1804 GButton.button ~label:"Whd"
1805 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1807 GButton.button ~label:"Reduce"
1808 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1810 GButton.button ~label:"Simpl"
1811 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1812 let scrolled_window =
1813 GBin.scrolled_window ~border_width:10
1814 ~packing:(vbox#pack ~expand:true ~padding:5) () in
1817 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
1819 method outputhtml = outputhtml
1820 method mmlwidget = mmlwidget
1821 method show () = window#misc#hide () ; window#show ()
1823 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
1824 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
1825 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
1826 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
1827 ignore(simplb#connect#clicked (simpl_in_scratch self))
1831 let vbox1 = GPack.vbox () in
1832 let scrolled_window1 =
1833 GBin.scrolled_window ~border_width:10
1834 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
1836 GMathView.math_view ~width:400 ~height:275
1837 ~packing:(scrolled_window1#add) () in
1839 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1841 GButton.button ~label:"Exact"
1842 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1844 GButton.button ~label:"Intros"
1845 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1847 GButton.button ~label:"Apply"
1848 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1849 let elimsimplintrosb =
1850 GButton.button ~label:"ElimSimplIntros"
1851 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1853 GButton.button ~label:"ElimType"
1854 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1856 GButton.button ~label:"Whd"
1857 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1859 GButton.button ~label:"Reduce"
1860 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1862 GButton.button ~label:"Simpl"
1863 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1865 GButton.button ~label:"Fold"
1866 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1868 GButton.button ~label:"Cut"
1869 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1871 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1873 GButton.button ~label:"Change"
1874 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1876 GButton.button ~label:"Let ... In"
1877 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1879 GButton.button ~label:"Ring"
1880 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1882 GButton.button ~label:"ClearBody"
1883 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1885 GButton.button ~label:"Clear"
1886 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1888 GButton.button ~label:"Fourier"
1889 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1891 GButton.button ~label:"RewriteSimpl ->"
1892 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1894 GButton.button ~label:"Reflexivity"
1895 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1897 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1899 GButton.button ~label:"Symmetry"
1900 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1902 GButton.button ~label:"Transitivity"
1903 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1905 GButton.button ~label:"Left"
1906 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1908 GButton.button ~label:"Right"
1909 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1911 GButton.button ~label:"Assumption"
1912 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
1914 method proofw = proofw
1915 method content = vbox1
1917 ignore(exactb#connect#clicked exact) ;
1918 ignore(applyb#connect#clicked apply) ;
1919 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
1920 ignore(elimtypeb#connect#clicked elimtype) ;
1921 ignore(whdb#connect#clicked whd) ;
1922 ignore(reduceb#connect#clicked reduce) ;
1923 ignore(simplb#connect#clicked simpl) ;
1924 ignore(foldb#connect#clicked fold) ;
1925 ignore(cutb#connect#clicked cut) ;
1926 ignore(changeb#connect#clicked change) ;
1927 ignore(letinb#connect#clicked letin) ;
1928 ignore(ringb#connect#clicked ring) ;
1929 ignore(clearbodyb#connect#clicked clearbody) ;
1930 ignore(clearb#connect#clicked clear) ;
1931 ignore(fourierb#connect#clicked fourier) ;
1932 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
1933 ignore(reflexivityb#connect#clicked reflexivity) ;
1934 ignore(symmetryb#connect#clicked symmetry) ;
1935 ignore(transitivityb#connect#clicked transitivity) ;
1936 ignore(leftb#connect#clicked left) ;
1937 ignore(rightb#connect#clicked right) ;
1938 ignore(assumptionb#connect#clicked assumption) ;
1939 ignore(introsb#connect#clicked intros) ;
1941 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
1947 val notebook = GPack.notebook ()
1949 val mutable skip_switch_page_event = false
1950 method notebook = notebook
1952 let new_page = new page () in
1953 pages := !pages @ [n,new_page] ;
1954 notebook#append_page
1955 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
1956 new_page#content#coerce
1957 method remove_all_pages =
1958 List.iter (function _ -> notebook#remove_page 0) !pages ;
1960 method set_current_page n =
1961 let (_,page) = List.find (function (m,_) -> m=n) !pages in
1962 let new_page = notebook#page_num page#content#coerce in
1963 if new_page <> notebook#current_page then
1964 skip_switch_page_event <- true ;
1965 notebook#goto_page new_page
1966 method set_empty_page = self#add_page (-1)
1968 (snd (List.nth !pages notebook#current_page))#proofw
1971 (notebook#connect#switch_page
1973 let skip = skip_switch_page_event in
1974 skip_switch_page_event <- false ;
1977 let metano = fst (List.nth !pages i) in
1986 class rendering_window output (notebook : notebook) =
1988 GWindow.window ~title:"MathML viewer" ~border_width:2
1989 ~allow_shrink:false () in
1990 let vbox_for_menu = GPack.vbox ~packing:window#add () in
1992 let menubar = GMenu.menu_bar ~packing:vbox_for_menu#pack () in
1993 let factory0 = new GMenu.factory menubar in
1994 let accel_group = factory0#accel_group in
1996 let file_menu = factory0#add_submenu "File" in
1997 let factory1 = new GMenu.factory file_menu ~accel_group in
1998 let export_to_postscript_menu_item =
2001 (factory1#add_item "Load" ~key:GdkKeysyms._L ~callback:load) ;
2002 ignore (factory1#add_item "Save" ~key:GdkKeysyms._S ~callback:save) ;
2003 ignore (factory1#add_separator ()) ;
2004 let export_to_postscript_menu_item =
2005 factory1#add_item "Export to PostScript..." ~key:GdkKeysyms._E
2006 ~callback:(export_to_postscript output) in
2007 ignore (factory1#add_separator ()) ;
2009 (factory1#add_item "Exit" ~key:GdkKeysyms._C ~callback:GMain.Main.quit) ;
2010 export_to_postscript_menu_item
2013 let edit_menu = factory0#add_submenu "Edit" in
2014 let factory2 = new GMenu.factory edit_menu ~accel_group in
2015 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
2016 let proveit_menu_item =
2017 factory2#add_item "Prove It" ~key:GdkKeysyms._I
2018 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
2020 let focus_menu_item =
2021 factory2#add_item "Focus" ~key:GdkKeysyms._F
2022 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
2025 focus_and_proveit_set_sensitive :=
2027 proveit_menu_item#misc#set_sensitive b ;
2028 focus_menu_item#misc#set_sensitive b
2030 let _ = factory2#add_separator () in
2031 let _ = factory2#add_item "Qed" ~key:GdkKeysyms._Q ~callback:qed in
2032 let _ = !focus_and_proveit_set_sensitive false in
2034 let settings_menu = factory0#add_submenu "Settings" in
2035 let factory3 = new GMenu.factory settings_menu ~accel_group in
2037 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
2038 ~callback:edit_aliases in
2039 let _ = factory3#add_separator () in
2041 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
2042 ~callback:(function _ -> (settings_window ())#show ()) in
2044 let _ = window#add_accel_group accel_group in
2048 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
2050 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2051 let scrolled_window0 =
2052 GBin.scrolled_window ~border_width:10
2053 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2054 let _ = scrolled_window0#add output#coerce in
2056 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2058 GButton.button ~label:"State"
2059 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2061 GButton.button ~label:"Open"
2062 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2064 GButton.button ~label:"Check"
2065 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2067 GButton.button ~label:"Locate"
2068 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2069 let searchpatternb =
2070 GButton.button ~label:"SearchPattern"
2071 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2072 let scrolled_window1 =
2073 GBin.scrolled_window ~border_width:10
2074 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2075 let inputt = GEdit.text ~editable:true ~width:400 ~height:100
2076 ~packing:scrolled_window1#add () in
2078 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
2080 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
2081 let frame = GBin.frame ~packing:(vboxl#pack ~expand:true ~padding:5) () in
2084 ~source:"<html><body bgColor=\"white\"></body></html>"
2085 ~width:400 ~height: 100
2089 let scratch_window = new scratch_window outputhtml in
2091 method outputhtml = outputhtml
2092 method inputt = inputt
2093 method output = (output : GMathView.math_view)
2094 method notebook = notebook
2095 method show = window#show
2097 notebook#set_empty_page ;
2098 export_to_postscript_menu_item#misc#set_sensitive false ;
2099 check_term := (check_term_in_scratch scratch_window) ;
2101 (* signal handlers here *)
2102 ignore(output#connect#selection_changed
2104 notebook#proofw#unload ;
2105 choose_selection output elem ;
2106 !focus_and_proveit_set_sensitive true
2108 let settings_window = new settings_window output scrolled_window0
2109 export_to_postscript_menu_item (choose_selection output) in
2110 set_settings_window settings_window ;
2111 set_outputhtml outputhtml ;
2112 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
2113 ignore(stateb#connect#clicked state) ;
2114 ignore(openb#connect#clicked open_) ;
2115 ignore(checkb#connect#clicked (check scratch_window)) ;
2116 ignore(locateb#connect#clicked locate) ;
2117 ignore(searchpatternb#connect#clicked searchPattern) ;
2118 Logger.log_callback :=
2119 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
2124 let initialize_everything () =
2125 let module U = Unix in
2126 let output = GMathView.math_view ~width:350 ~height:280 () in
2127 let notebook = new notebook in
2128 let rendering_window' = new rendering_window output notebook in
2129 set_rendering_window rendering_window' ;
2130 mml_of_cic_term_ref := mml_of_cic_term ;
2131 rendering_window'#show () ;
2137 Mqint.init "dbname=helm_mowgli" ;
2138 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
2139 ignore (GtkMain.Main.init ()) ;
2140 initialize_everything () ;
2141 if !usedb then Mqint.close ();