1 (* Copyright (C) 2000, 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 (******************************************************************************)
36 (* GLOBAL CONSTANTS *)
38 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
42 " <body bgColor=\"white\">"
50 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
52 let htmlheader_and_content = ref htmlheader;;
54 let current_cic_infos = ref None;;
55 let current_goal_infos = ref None;;
56 let current_scratch_infos = ref None;;
61 let domImpl = Gdome.domImplementation ();;
65 domImpl#createDocumentFromURI
67 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
69 ~uri:("styles/" ^ name) ()
71 Gdome_xslt.processStylesheet style
74 let d_c = parseStyle "drop_coercions.xsl";;
75 let tc1 = parseStyle "objtheorycontent.xsl";;
76 let hc2 = parseStyle "content_to_html.xsl";;
77 let l = parseStyle "link.xsl";;
79 let c1 = parseStyle "rootcontent.xsl";;
80 let g = parseStyle "genmmlid.xsl";;
81 let c2 = parseStyle "annotatedpres.xsl";;
84 let getterURL = Configuration.getter_url;;
85 let processorURL = Configuration.processor_url;;
87 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
89 ["processorURL", "'" ^ processorURL ^ "'" ;
90 "getterURL", "'" ^ getterURL ^ "'" ;
91 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
92 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
93 "UNICODEvsSYMBOL", "'symbol'" ;
94 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
95 "encoding", "'iso-8859-1'" ;
96 "media-type", "'text/html'" ;
97 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
98 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
99 "naturalLanguage", "'yes'" ;
100 "annotations", "'no'" ;
101 "explodeall", "'true()'" ;
102 "topurl", "'http://phd.cs.unibo.it/helm'" ;
103 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
106 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
108 ["processorURL", "'" ^ processorURL ^ "'" ;
109 "getterURL", "'" ^ getterURL ^ "'" ;
110 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
111 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
112 "UNICODEvsSYMBOL", "'symbol'" ;
113 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
114 "encoding", "'iso-8859-1'" ;
115 "media-type", "'text/html'" ;
116 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
117 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
118 "naturalLanguage", "'no'" ;
119 "annotations", "'no'" ;
120 "explodeall", "'true()'" ;
121 "topurl", "'http://phd.cs.unibo.it/helm'" ;
122 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
125 let parse_file filename =
126 let inch = open_in filename in
127 let rec read_lines () =
129 let line = input_line inch in
137 let applyStylesheets input styles args =
138 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
142 let mml_of_cic_object uri annobj ids_to_inner_sorts ids_to_inner_types =
144 Cic2Xml.print_object uri ids_to_inner_sorts annobj
147 Cic2Xml.print_inner_types uri ids_to_inner_sorts
150 let input = Xml2Gdome.document_of_xml domImpl xml in
151 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
152 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
154 Xml.pp xmlinnertypes (Some "/public/sacerdot/innertypes") ;
155 let output = applyStylesheets input mml_styles mml_args in
162 exception RefreshSequentException of exn;;
163 exception RefreshProofException of exn;;
165 let refresh_proof (output : GMathView.math_view) =
167 let uri,currentproof =
168 match !ProofEngine.proof with
170 | Some (uri,metasenv,bo,ty) ->
171 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty))
174 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
175 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
177 Cic2acic.acic_object_of_cic_object currentproof
180 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
182 output#load_tree mml ;
184 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
187 match !ProofEngine.proof with
189 | Some (uri,metasenv,bo,ty) ->
190 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty))) ; flush stderr ;
191 raise (RefreshProofException e)
194 let refresh_sequent (proofw : GMathView.math_view) =
196 match !ProofEngine.goal with
197 None -> proofw#unload
200 match !ProofEngine.proof with
202 | Some (_,metasenv,_,_) -> metasenv
204 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
205 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
206 SequentPp.XmlPp.print_sequent metasenv currentsequent
209 Xml2Gdome.document_of_xml domImpl sequent_gdome
212 applyStylesheets sequent_doc sequent_styles sequent_args
214 proofw#load_tree ~dom:sequent_mml ;
215 current_goal_infos :=
216 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
220 match !ProofEngine.goal with
225 match !ProofEngine.proof with
227 | Some (_,metasenv,_,_) -> metasenv
229 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
230 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
231 raise (RefreshSequentException e)
235 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
236 ~name:"/public/sacerdot/guruguru1" ~indent:true ()) ;
239 let mml_of_cic_term metano term =
241 match !ProofEngine.proof with
243 | Some (_,metasenv,_,_) -> metasenv
246 match !ProofEngine.goal with
249 let (_,canonical_context,_) =
250 List.find (function (m,_,_) -> m=metano) metasenv
254 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
255 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
258 Xml2Gdome.document_of_xml domImpl sequent_gdome
261 applyStylesheets sequent_doc sequent_styles sequent_args ;
263 current_scratch_infos :=
264 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
268 let output_html outputhtml msg =
269 htmlheader_and_content := !htmlheader_and_content ^ msg ;
270 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
271 outputhtml#set_topline (-1)
274 (***********************)
276 (***********************)
278 let call_tactic tactic rendering_window () =
279 let proofw = (rendering_window#proofw : GMathView.math_view) in
280 let output = (rendering_window#output : GMathView.math_view) in
281 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
282 let savedproof = !ProofEngine.proof in
283 let savedgoal = !ProofEngine.goal in
287 refresh_sequent proofw ;
290 RefreshSequentException e ->
291 output_html outputhtml
292 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
293 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
294 ProofEngine.proof := savedproof ;
295 ProofEngine.goal := savedgoal ;
296 refresh_sequent proofw
297 | RefreshProofException e ->
298 output_html outputhtml
299 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
300 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
301 ProofEngine.proof := savedproof ;
302 ProofEngine.goal := savedgoal ;
303 refresh_sequent proofw ;
306 output_html outputhtml
307 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
308 ProofEngine.proof := savedproof ;
309 ProofEngine.goal := savedgoal ;
313 let call_tactic_with_input tactic rendering_window () =
314 let proofw = (rendering_window#proofw : GMathView.math_view) in
315 let output = (rendering_window#output : GMathView.math_view) in
316 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
317 let inputt = (rendering_window#inputt : GEdit.text) in
318 let savedproof = !ProofEngine.proof in
319 let savedgoal = !ProofEngine.goal in
320 (*CSC: Gran cut&paste da sotto... *)
321 let inputlen = inputt#length in
322 let input = inputt#get_chars 0 inputlen ^ "\n" in
323 let lexbuf = Lexing.from_string input in
325 match !ProofEngine.proof with
327 | Some (curi,_,_,_) -> curi
330 match !ProofEngine.proof with
332 | Some (_,metasenv,_,_) -> metasenv
339 (match !ProofEngine.goal with
342 let (_,canonical_context,_) =
343 List.find (function (m,_,_) -> m=metano) metasenv
351 CicTextualParserContext.main curi context CicTextualLexer.token lexbuf
356 refresh_sequent proofw ;
360 CicTextualParser0.Eof ->
361 inputt#delete_text 0 inputlen
362 | RefreshSequentException e ->
363 output_html outputhtml
364 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
365 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
366 ProofEngine.proof := savedproof ;
367 ProofEngine.goal := savedgoal ;
368 refresh_sequent proofw
369 | RefreshProofException e ->
370 output_html outputhtml
371 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
372 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
373 ProofEngine.proof := savedproof ;
374 ProofEngine.goal := savedgoal ;
375 refresh_sequent proofw ;
378 output_html outputhtml
379 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
380 ProofEngine.proof := savedproof ;
381 ProofEngine.goal := savedgoal ;
384 let call_tactic_with_goal_input tactic rendering_window () =
385 let module L = LogicalOperations in
386 let module G = Gdome in
387 let proofw = (rendering_window#proofw : GMathView.math_view) in
388 let output = (rendering_window#output : GMathView.math_view) in
389 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
390 let savedproof = !ProofEngine.proof in
391 let savedgoal = !ProofEngine.goal in
392 match proofw#get_selection with
395 ((node : Gdome.element)#getAttributeNS
397 ~localName:(G.domString "xref"))#to_string
399 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
403 match !current_goal_infos with
404 Some (ids_to_terms, ids_to_father_ids,_) ->
406 tactic (Hashtbl.find ids_to_terms id) ;
407 refresh_sequent rendering_window#proofw ;
408 refresh_proof rendering_window#output
409 | None -> assert false (* "ERROR: No current term!!!" *)
411 RefreshSequentException e ->
412 output_html outputhtml
413 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
414 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
415 ProofEngine.proof := savedproof ;
416 ProofEngine.goal := savedgoal ;
417 refresh_sequent proofw
418 | RefreshProofException e ->
419 output_html outputhtml
420 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
421 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
422 ProofEngine.proof := savedproof ;
423 ProofEngine.goal := savedgoal ;
424 refresh_sequent proofw ;
427 output_html outputhtml
428 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
429 ProofEngine.proof := savedproof ;
430 ProofEngine.goal := savedgoal ;
433 output_html outputhtml
434 ("<h1 color=\"red\">No term selected</h1>")
437 let call_tactic_with_input_and_goal_input tactic rendering_window () =
438 let module L = LogicalOperations in
439 let module G = Gdome in
440 let proofw = (rendering_window#proofw : GMathView.math_view) in
441 let output = (rendering_window#output : GMathView.math_view) in
442 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
443 let inputt = (rendering_window#inputt : GEdit.text) in
444 let savedproof = !ProofEngine.proof in
445 let savedgoal = !ProofEngine.goal in
446 match proofw#get_selection with
449 ((node : Gdome.element)#getAttributeNS
451 ~localName:(G.domString "xref"))#to_string
453 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
457 match !current_goal_infos with
458 Some (ids_to_terms, ids_to_father_ids,_) ->
460 (* Let's parse the input *)
461 let inputlen = inputt#length in
462 let input = inputt#get_chars 0 inputlen ^ "\n" in
463 let lexbuf = Lexing.from_string input in
465 match !ProofEngine.proof with
467 | Some (curi,_,_,_) -> curi
470 match !ProofEngine.proof with
472 | Some (_,metasenv,_,_) -> metasenv
479 (match !ProofEngine.goal with
482 let (_,canonical_context,_) =
483 List.find (function (m,_,_) -> m=metano) metasenv
492 CicTextualParserContext.main curi context
493 CicTextualLexer.token lexbuf
497 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
499 refresh_sequent proofw ;
503 CicTextualParser0.Eof ->
504 inputt#delete_text 0 inputlen
506 | None -> assert false (* "ERROR: No current term!!!" *)
508 RefreshSequentException e ->
509 output_html outputhtml
510 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
511 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
512 ProofEngine.proof := savedproof ;
513 ProofEngine.goal := savedgoal ;
514 refresh_sequent proofw
515 | RefreshProofException e ->
516 output_html outputhtml
517 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
518 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
519 ProofEngine.proof := savedproof ;
520 ProofEngine.goal := savedgoal ;
521 refresh_sequent proofw ;
524 output_html outputhtml
525 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
526 ProofEngine.proof := savedproof ;
527 ProofEngine.goal := savedgoal ;
530 output_html outputhtml
531 ("<h1 color=\"red\">No term selected</h1>")
534 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
535 let module L = LogicalOperations in
536 let module G = Gdome in
537 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
538 let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
539 let savedproof = !ProofEngine.proof in
540 let savedgoal = !ProofEngine.goal in
541 match mmlwidget#get_selection with
544 ((node : Gdome.element)#getAttributeNS
546 ~localName:(G.domString "xref"))#to_string
548 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
552 match !current_scratch_infos with
553 (* term is the whole goal in the scratch_area *)
554 Some (term,ids_to_terms, ids_to_father_ids,_) ->
556 let expr = tactic term (Hashtbl.find ids_to_terms id) in
557 let mml = mml_of_cic_term 111 expr in
558 scratch_window#show () ;
559 scratch_window#mmlwidget#load_tree ~dom:mml
560 | None -> assert false (* "ERROR: No current term!!!" *)
563 output_html outputhtml
564 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
567 output_html outputhtml
568 ("<h1 color=\"red\">No term selected</h1>")
571 let intros rendering_window = call_tactic ProofEngine.intros rendering_window;;
572 let exact rendering_window =
573 call_tactic_with_input ProofEngine.exact rendering_window
575 let apply rendering_window =
576 call_tactic_with_input ProofEngine.apply rendering_window
578 let elimintrossimpl rendering_window =
579 call_tactic_with_input ProofEngine.elim_intros_simpl rendering_window
581 let whd rendering_window =
582 call_tactic_with_goal_input ProofEngine.whd rendering_window
584 let reduce rendering_window =
585 call_tactic_with_goal_input ProofEngine.reduce rendering_window
587 let simpl rendering_window =
588 call_tactic_with_goal_input ProofEngine.simpl rendering_window
590 let fold rendering_window =
591 call_tactic_with_input ProofEngine.fold rendering_window
593 let cut rendering_window =
594 call_tactic_with_input ProofEngine.cut rendering_window
596 let change rendering_window =
597 call_tactic_with_input_and_goal_input ProofEngine.change rendering_window
599 let letin rendering_window =
600 call_tactic_with_input ProofEngine.letin rendering_window
604 let whd_in_scratch scratch_window =
605 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
608 let reduce_in_scratch scratch_window =
609 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
612 let simpl_in_scratch scratch_window =
613 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
619 (**********************)
621 (**********************)
623 exception OpenConjecturesStillThere;;
624 exception WrongProof;;
626 let qed rendering_window () =
627 match !ProofEngine.proof with
629 | Some (uri,[],bo,ty) ->
631 CicReduction.are_convertible []
632 (CicTypeChecker.type_of_aux' [] [] bo) ty
635 (*CSC: Wrong: [] is just plainly wrong *)
636 let proof = Cic.Definition (UriManager.name_of_uri uri,bo,ty,[]) in
638 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
639 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
641 Cic2acic.acic_object_of_cic_object proof
644 mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
646 (rendering_window#output : GMathView.math_view)#load_tree mml ;
649 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
654 | _ -> raise OpenConjecturesStillThere
658 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
660 let dtdname = "/projects/helm/V7/dtd/cic.dtd";;
662 let save rendering_window () =
663 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
664 match !ProofEngine.proof with
666 | Some (uri, metasenv, bo, ty) ->
668 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty)
670 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
671 Cic2acic.acic_object_of_cic_object currentproof
673 let xml = Cic2Xml.print_object uri ids_to_inner_sorts acurrentproof in
675 [< Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
677 ("<!DOCTYPE CurrentProof SYSTEM \"" ^ dtdname ^ "\">\n\n") ;
681 Xml.pp ~quiet:true xml' (Some "/public/sacerdot/currentproof") ;
682 output_html outputhtml
683 ("<h1 color=\"Green\">Current proof saved to " ^
684 "/public/sacerdot/currentproof</h1>")
687 let load rendering_window () =
688 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
689 let output = (rendering_window#output : GMathView.math_view) in
690 let proofw = (rendering_window#proofw : GMathView.math_view) in
692 let uri = UriManager.uri_of_string "cic:/dummy.con" in
693 match CicParser.obj_of_xml "/public/sacerdot/currentproof" uri with
694 Cic.CurrentProof (_,metasenv,bo,ty) ->
696 Some (uri, metasenv, bo, ty) ;
700 | (metano,_,_)::_ -> Some metano
702 refresh_proof output ;
703 refresh_sequent proofw ;
704 output_html outputhtml
705 ("<h1 color=\"Green\">Current proof loaded from " ^
706 "/public/sacerdot/currentproof</h1>")
709 RefreshSequentException e ->
710 output_html outputhtml
711 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
712 "sequent: " ^ Printexc.to_string e ^ "</h1>")
713 | RefreshProofException e ->
714 output_html outputhtml
715 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
716 "proof: " ^ Printexc.to_string e ^ "</h1>")
718 output_html outputhtml
719 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
722 let proveit rendering_window () =
723 let module L = LogicalOperations in
724 let module G = Gdome in
725 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
726 match rendering_window#output#get_selection with
729 ((node : Gdome.element)#getAttributeNS
731 ((element : G.element)#getAttributeNS
734 ~localName:(G.domString "xref"))#to_string
736 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
740 match !current_cic_infos with
741 Some (ids_to_terms, ids_to_father_ids, _, _) ->
743 L.to_sequent id ids_to_terms ids_to_father_ids ;
744 refresh_proof rendering_window#output ;
745 refresh_sequent rendering_window#proofw
746 | None -> assert false (* "ERROR: No current term!!!" *)
748 RefreshSequentException e ->
749 output_html outputhtml
750 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
751 "sequent: " ^ Printexc.to_string e ^ "</h1>")
752 | RefreshProofException e ->
753 output_html outputhtml
754 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
755 "proof: " ^ Printexc.to_string e ^ "</h1>")
757 output_html outputhtml
758 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
760 | None -> assert false (* "ERROR: No selection!!!" *)
763 let focus rendering_window () =
764 let module L = LogicalOperations in
765 let module G = Gdome in
766 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
767 match rendering_window#output#get_selection with
770 ((node : Gdome.element)#getAttributeNS
772 ((element : G.element)#getAttributeNS
775 ~localName:(G.domString "xref"))#to_string
777 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
781 match !current_cic_infos with
782 Some (ids_to_terms, ids_to_father_ids, _, _) ->
784 L.focus id ids_to_terms ids_to_father_ids ;
785 refresh_sequent rendering_window#proofw
786 | None -> assert false (* "ERROR: No current term!!!" *)
788 RefreshSequentException e ->
789 output_html outputhtml
790 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
791 "sequent: " ^ Printexc.to_string e ^ "</h1>")
792 | RefreshProofException e ->
793 output_html outputhtml
794 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
795 "proof: " ^ Printexc.to_string e ^ "</h1>")
797 output_html outputhtml
798 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
800 | None -> assert false (* "ERROR: No selection!!!" *)
803 exception NoPrevGoal;;
804 exception NoNextGoal;;
806 let prevgoal metasenv metano =
810 | [(m,_,_)] -> raise NoPrevGoal
811 | (n,_,_)::(m,_,_)::_ when m=metano -> n
817 let nextgoal metasenv metano =
821 | [(m,_,_)] when m = metano -> raise NoNextGoal
822 | (m,_,_)::(n,_,_)::_ when m=metano -> n
828 let prev_or_next_goal select_goal rendering_window () =
829 let module L = LogicalOperations in
830 let module G = Gdome in
831 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
833 match !ProofEngine.proof with
835 | Some (_,metasenv,_,_) -> metasenv
838 match !ProofEngine.goal with
843 ProofEngine.goal := Some (select_goal metasenv metano) ;
844 refresh_sequent rendering_window#proofw
846 RefreshSequentException e ->
847 output_html outputhtml
848 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
849 "sequent: " ^ Printexc.to_string e ^ "</h1>")
851 output_html outputhtml
852 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
855 exception NotADefinition;;
857 let open_ rendering_window () =
858 let inputt = (rendering_window#inputt : GEdit.text) in
859 let oldinputt = (rendering_window#oldinputt : GEdit.text) in
860 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
861 let output = (rendering_window#output : GMathView.math_view) in
862 let proofw = (rendering_window#proofw : GMathView.math_view) in
863 let inputlen = inputt#length in
864 let input = inputt#get_chars 0 inputlen ^ "\n" in
866 let uri = UriManager.uri_of_string ("cic:" ^ input) in
867 CicTypeChecker.typecheck uri ;
869 match CicEnvironment.get_cooked_obj uri 0 with
870 Cic.Definition (_,bo,ty,_) -> [],bo,ty
871 | Cic.CurrentProof (_,metasenv,bo,ty) -> metasenv,bo,ty
874 | Cic.InductiveDefinition _ -> raise NotADefinition
877 Some (uri, metasenv, bo, ty) ;
878 ProofEngine.goal := None ;
879 refresh_sequent proofw ;
880 refresh_proof output ;
881 inputt#delete_text 0 inputlen ;
882 ignore(oldinputt#insert_text input oldinputt#length)
884 RefreshSequentException e ->
885 output_html outputhtml
886 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
887 "sequent: " ^ Printexc.to_string e ^ "</h1>")
888 | RefreshProofException e ->
889 output_html outputhtml
890 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
891 "proof: " ^ Printexc.to_string e ^ "</h1>")
893 output_html outputhtml
894 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
897 let state rendering_window () =
898 let inputt = (rendering_window#inputt : GEdit.text) in
899 let oldinputt = (rendering_window#oldinputt : GEdit.text) in
900 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
901 let output = (rendering_window#output : GMathView.math_view) in
902 let proofw = (rendering_window#proofw : GMathView.math_view) in
903 let inputlen = inputt#length in
904 let input = inputt#get_chars 0 inputlen ^ "\n" in
905 (* Do something interesting *)
906 let lexbuf = Lexing.from_string input in
909 (* Execute the actions *)
910 match CicTextualParser.main CicTextualLexer.token lexbuf with
913 let _ = CicTypeChecker.type_of_aux' [] [] expr in
915 Some (UriManager.uri_of_string "cic:/dummy.con",
916 [1,[],expr], Cic.Meta (1,[]), expr) ;
917 ProofEngine.goal := Some 1 ;
918 refresh_sequent proofw ;
919 refresh_proof output ;
922 CicTextualParser0.Eof ->
923 inputt#delete_text 0 inputlen ;
924 ignore(oldinputt#insert_text input oldinputt#length)
925 | RefreshSequentException e ->
926 output_html outputhtml
927 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
928 "sequent: " ^ Printexc.to_string e ^ "</h1>")
929 | RefreshProofException e ->
930 output_html outputhtml
931 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
932 "proof: " ^ Printexc.to_string e ^ "</h1>")
934 output_html outputhtml
935 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
938 let check rendering_window scratch_window () =
939 let inputt = (rendering_window#inputt : GEdit.text) in
940 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
941 let output = (rendering_window#output : GMathView.math_view) in
942 let proofw = (rendering_window#proofw : GMathView.math_view) in
943 let inputlen = inputt#length in
944 let input = inputt#get_chars 0 inputlen ^ "\n" in
946 match !ProofEngine.proof with
947 None -> UriManager.uri_of_string "cic:/dummy.con", []
948 | Some (curi,metasenv,_,_) -> curi,metasenv
950 let context,names_context =
952 match !ProofEngine.goal with
955 let (_,canonical_context,_) =
956 List.find (function (m,_,_) -> m=metano) metasenv
967 (* Do something interesting *)
968 let lexbuf = Lexing.from_string input in
971 (* Execute the actions *)
973 CicTextualParserContext.main curi names_context CicTextualLexer.token
979 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
980 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
981 scratch_window#show () ;
982 scratch_window#mmlwidget#load_tree ~dom:mml
985 print_endline ("? " ^ CicPp.ppterm expr) ;
989 CicTextualParser0.Eof -> ()
991 output_html outputhtml
992 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
995 let locate rendering_window () =
996 let inputt = (rendering_window#inputt : GEdit.text) in
997 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
998 let inputlen = inputt#length in
999 let input = inputt#get_chars 0 inputlen in
1000 output_html outputhtml (
1002 match Str.split (Str.regexp "[ \t]+") input with
1005 inputt#delete_text 0 inputlen;
1008 e -> "<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>"
1012 let backward rendering_window () =
1013 let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1014 let inputt = (rendering_window#inputt : GEdit.text) in
1015 let inputlen = inputt#length in
1016 let input = inputt#get_chars 0 inputlen in
1017 let level = int_of_string input in
1019 match !ProofEngine.proof with
1020 None -> assert false
1021 | Some (_,metasenv,_,_) -> metasenv
1024 match !ProofEngine.goal with
1028 List.find (function (m,_,_) -> m=metano) metasenv
1030 Mquery.backward ty level
1032 output_html outputhtml result
1034 let choose_selection
1035 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
1037 let module G = Gdome in
1038 let rec aux element =
1039 if element#hasAttributeNS
1040 ~namespaceURI:helmns
1041 ~localName:(G.domString "xref")
1043 mmlwidget#set_selection (Some element)
1045 match element#get_parentNode with
1046 None -> assert false
1047 (*CSC: OCAML DIVERGES!
1048 | Some p -> aux (new G.element_of_node p)
1050 | Some p -> aux (new Gdome.element_of_node p)
1054 | None -> mmlwidget#set_selection None
1057 (* STUFF TO BUILD THE GTK INTERFACE *)
1059 (* Stuff for the widget settings *)
1061 let export_to_postscript (output : GMathView.math_view) () =
1062 output#export_to_postscript ~filename:"output.ps" ();
1065 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
1066 button_set_kerning button_set_transparency button_export_to_postscript
1069 let is_set = button_t1#active in
1070 output#set_font_manager_type
1071 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
1074 button_set_anti_aliasing#misc#set_sensitive true ;
1075 button_set_kerning#misc#set_sensitive true ;
1076 button_set_transparency#misc#set_sensitive true ;
1077 button_export_to_postscript#misc#set_sensitive true ;
1081 button_set_anti_aliasing#misc#set_sensitive false ;
1082 button_set_kerning#misc#set_sensitive false ;
1083 button_set_transparency#misc#set_sensitive false ;
1084 button_export_to_postscript#misc#set_sensitive false ;
1088 let set_anti_aliasing output button_set_anti_aliasing () =
1089 output#set_anti_aliasing button_set_anti_aliasing#active
1092 let set_kerning output button_set_kerning () =
1093 output#set_kerning button_set_kerning#active
1096 let set_transparency output button_set_transparency () =
1097 output#set_transparency button_set_transparency#active
1100 let changefont output font_size_spinb () =
1101 output#set_font_size font_size_spinb#value_as_int
1104 let set_log_verbosity output log_verbosity_spinb () =
1105 output#set_log_verbosity log_verbosity_spinb#value_as_int
1108 class settings_window (output : GMathView.math_view) sw
1109 button_export_to_postscript selection_changed_callback
1111 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
1113 GPack.vbox ~packing:settings_window#add () in
1116 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1117 ~border_width:5 ~packing:vbox#add () in
1119 GButton.toggle_button ~label:"activate t1 fonts"
1120 ~packing:(table#attach ~left:0 ~top:0) () in
1121 let button_set_anti_aliasing =
1122 GButton.toggle_button ~label:"set_anti_aliasing"
1123 ~packing:(table#attach ~left:0 ~top:1) () in
1124 let button_set_kerning =
1125 GButton.toggle_button ~label:"set_kerning"
1126 ~packing:(table#attach ~left:1 ~top:1) () in
1127 let button_set_transparency =
1128 GButton.toggle_button ~label:"set_transparency"
1129 ~packing:(table#attach ~left:2 ~top:1) () in
1132 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1133 ~border_width:5 ~packing:vbox#add () in
1134 let font_size_label =
1135 GMisc.label ~text:"font size:"
1136 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
1137 let font_size_spinb =
1139 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
1142 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
1143 let log_verbosity_label =
1144 GMisc.label ~text:"log verbosity:"
1145 ~packing:(table#attach ~left:0 ~top:1) () in
1146 let log_verbosity_spinb =
1148 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
1151 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
1153 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1155 GButton.button ~label:"Close"
1156 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1158 method show = settings_window#show
1160 button_set_anti_aliasing#misc#set_sensitive false ;
1161 button_set_kerning#misc#set_sensitive false ;
1162 button_set_transparency#misc#set_sensitive false ;
1163 (* Signals connection *)
1164 ignore(button_t1#connect#clicked
1165 (activate_t1 output button_set_anti_aliasing button_set_kerning
1166 button_set_transparency button_export_to_postscript button_t1)) ;
1167 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
1168 ignore(button_set_anti_aliasing#connect#toggled
1169 (set_anti_aliasing output button_set_anti_aliasing));
1170 ignore(button_set_kerning#connect#toggled
1171 (set_kerning output button_set_kerning)) ;
1172 ignore(button_set_transparency#connect#toggled
1173 (set_transparency output button_set_transparency)) ;
1174 ignore(log_verbosity_spinb#connect#changed
1175 (set_log_verbosity output log_verbosity_spinb)) ;
1176 ignore(closeb#connect#clicked settings_window#misc#hide)
1179 (* Scratch window *)
1181 class scratch_window outputhtml =
1183 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1185 GPack.vbox ~packing:window#add () in
1187 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1189 GButton.button ~label:"Whd"
1190 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1192 GButton.button ~label:"Reduce"
1193 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1195 GButton.button ~label:"Simpl"
1196 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1197 let scrolled_window =
1198 GBin.scrolled_window ~border_width:10
1199 ~packing:(vbox#pack ~expand:true ~padding:5) () in
1202 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
1204 method outputhtml = outputhtml
1205 method mmlwidget = mmlwidget
1206 method show () = window#misc#hide () ; window#show ()
1208 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
1209 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
1210 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
1211 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
1212 ignore(simplb#connect#clicked (simpl_in_scratch self))
1217 class rendering_window output proofw (label : GMisc.label) =
1219 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1221 GPack.hbox ~packing:window#add () in
1223 GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1224 let _ = vbox#pack ~expand:false ~fill:false ~padding:5 label#coerce in
1225 let scrolled_window0 =
1226 GBin.scrolled_window ~border_width:10
1227 ~packing:(vbox#pack ~expand:true ~padding:5) () in
1228 let _ = scrolled_window0#add output#coerce in
1230 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1232 GButton.button ~label:"Settings"
1233 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1234 let button_export_to_postscript =
1235 GButton.button ~label:"export_to_postscript"
1236 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1238 GButton.button ~label:"Qed"
1239 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1241 GButton.button ~label:"Save"
1242 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1244 GButton.button ~label:"Load"
1245 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1247 GButton.button ~label:"Close"
1248 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1250 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1252 GButton.button ~label:"Prove It"
1253 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1255 GButton.button ~label:"Focus"
1256 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1258 GButton.button ~label:"<"
1259 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1261 GButton.button ~label:">"
1262 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1263 let oldinputt = GEdit.text ~editable:false ~width:400 ~height:180
1264 ~packing:(vbox#pack ~padding:5) () in
1266 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1268 GButton.button ~label:"State"
1269 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1271 GButton.button ~label:"Open"
1272 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1274 GButton.button ~label:"Check"
1275 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1277 GButton.button ~label:"Locate"
1278 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1280 GButton.button ~label:"Backward"
1281 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1282 let inputt = GEdit.text ~editable:true ~width:400 ~height: 100
1283 ~packing:(vbox#pack ~padding:5) () in
1285 GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1286 let scrolled_window1 =
1287 GBin.scrolled_window ~border_width:10
1288 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
1289 let _ = scrolled_window1#add proofw#coerce in
1291 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1293 GButton.button ~label:"Exact"
1294 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1296 GButton.button ~label:"Intros"
1297 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1299 GButton.button ~label:"Apply"
1300 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1301 let elimintrossimplb =
1302 GButton.button ~label:"ElimIntrosSimpl"
1303 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1305 GButton.button ~label:"Whd"
1306 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1308 GButton.button ~label:"Reduce"
1309 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1311 GButton.button ~label:"Simpl"
1312 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1314 GButton.button ~label:"Fold"
1315 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1317 GButton.button ~label:"Cut"
1318 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1320 GButton.button ~label:"Change"
1321 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1323 GButton.button ~label:"Let ... In"
1324 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1327 ~source:"<html><body bgColor=\"white\"></body></html>"
1328 ~width:400 ~height: 200
1329 ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5)
1331 let scratch_window = new scratch_window outputhtml in
1333 method outputhtml = outputhtml
1334 method oldinputt = oldinputt
1335 method inputt = inputt
1336 method output = (output : GMathView.math_view)
1337 method proofw = (proofw : GMathView.math_view)
1338 method show = window#show
1340 button_export_to_postscript#misc#set_sensitive false ;
1342 (* signal handlers here *)
1343 ignore(output#connect#selection_changed
1344 (function elem -> proofw#unload ; choose_selection output elem)) ;
1345 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
1346 ignore(closeb#connect#clicked (fun _ -> GMain.Main.quit ())) ;
1347 let settings_window = new settings_window output scrolled_window0
1348 button_export_to_postscript (choose_selection output) in
1349 ignore(settingsb#connect#clicked settings_window#show) ;
1350 ignore(button_export_to_postscript#connect#clicked (export_to_postscript output)) ;
1351 ignore(qedb#connect#clicked (qed self)) ;
1352 ignore(saveb#connect#clicked (save self)) ;
1353 ignore(loadb#connect#clicked (load self)) ;
1354 ignore(proveitb#connect#clicked (proveit self)) ;
1355 ignore(focusb#connect#clicked (focus self)) ;
1356 ignore(prevgoalb#connect#clicked (prev_or_next_goal prevgoal self)) ;
1357 ignore(nextgoalb#connect#clicked (prev_or_next_goal nextgoal self)) ;
1358 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
1359 ignore(stateb#connect#clicked (state self)) ;
1360 ignore(openb#connect#clicked (open_ self)) ;
1361 ignore(checkb#connect#clicked (check self scratch_window)) ;
1362 ignore(locateb#connect#clicked (locate self)) ;
1363 ignore(backwardb#connect#clicked (backward self)) ;
1364 ignore(exactb#connect#clicked (exact self)) ;
1365 ignore(applyb#connect#clicked (apply self)) ;
1366 ignore(elimintrossimplb#connect#clicked (elimintrossimpl self)) ;
1367 ignore(whdb#connect#clicked (whd self)) ;
1368 ignore(reduceb#connect#clicked (reduce self)) ;
1369 ignore(simplb#connect#clicked (simpl self)) ;
1370 ignore(foldb#connect#clicked (fold self)) ;
1371 ignore(cutb#connect#clicked (cut self)) ;
1372 ignore(changeb#connect#clicked (change self)) ;
1373 ignore(letinb#connect#clicked (letin self)) ;
1374 ignore(introsb#connect#clicked (intros self)) ;
1375 Logger.log_callback :=
1376 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
1381 let initialize_everything () =
1382 let module U = Unix in
1383 let output = GMathView.math_view ~width:400 ~height:280 ()
1384 and proofw = GMathView.math_view ~width:400 ~height:275 ()
1385 and label = GMisc.label ~text:"gTopLevel" () in
1386 let rendering_window =
1387 new rendering_window output proofw label
1389 rendering_window#show () ;
1394 CicCooking.init () ;
1396 ignore (GtkMain.Main.init ()) ;
1397 initialize_everything () ;