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 (* GLOBAL CONSTANTS *)
39 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
40 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
44 " <body bgColor=\"white\">"
54 Sys.getenv "GTOPLEVEL_PROOFFILE"
56 Not_found -> "/public/currentproof"
61 Sys.getenv "GTOPLEVEL_PROOFFILETYPE"
63 Not_found -> "/public/currentprooftype"
66 (*CSC: the getter should handle the innertypes, not the FS *)
70 Sys.getenv "GTOPLEVEL_INNERTYPESFILE"
72 Not_found -> "/public/innertypes"
75 let constanttypefile =
77 Sys.getenv "GTOPLEVEL_CONSTANTTYPEFILE"
79 Not_found -> "/public/constanttype"
82 let postgresqlconnectionstring =
84 Sys.getenv "POSTGRESQL_CONNECTION_STRING"
86 Not_found -> "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm"
89 let empty_id_to_uris = ([],function _ -> None);;
92 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
94 let htmlheader_and_content = ref htmlheader;;
96 let current_cic_infos = ref None;;
97 let current_goal_infos = ref None;;
98 let current_scratch_infos = ref None;;
100 let id_to_uris = ref empty_id_to_uris;;
102 let check_term = ref (fun _ _ _ -> assert false);;
103 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
105 exception RenderingWindowsNotInitialized;;
107 let set_rendering_window,rendering_window =
108 let rendering_window_ref = ref None in
109 (function rw -> rendering_window_ref := Some rw),
111 match !rendering_window_ref with
112 None -> raise RenderingWindowsNotInitialized
117 exception SettingsWindowsNotInitialized;;
119 let set_settings_window,settings_window =
120 let settings_window_ref = ref None in
121 (function rw -> settings_window_ref := Some rw),
123 match !settings_window_ref with
124 None -> raise SettingsWindowsNotInitialized
129 exception OutputHtmlNotInitialized;;
131 let set_outputhtml,outputhtml =
132 let outputhtml_ref = ref None in
133 (function rw -> outputhtml_ref := Some rw),
135 match !outputhtml_ref with
136 None -> raise OutputHtmlNotInitialized
137 | Some outputhtml -> outputhtml
141 exception QedSetSensitiveNotInitialized;;
142 let qed_set_sensitive =
143 ref (function _ -> raise QedSetSensitiveNotInitialized)
146 exception SaveSetSensitiveNotInitialized;;
147 let save_set_sensitive =
148 ref (function _ -> raise SaveSetSensitiveNotInitialized)
151 (* COMMAND LINE OPTIONS *)
157 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
160 Arg.parse argspec ignore ""
164 let term_of_cic_textual_parser_uri uri =
165 let module C = Cic in
166 let module CTP = CicTextualParser0 in
168 CTP.ConUri uri -> C.Const (uri,[])
169 | CTP.VarUri uri -> C.Var (uri,[])
170 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
171 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
174 let string_of_cic_textual_parser_uri uri =
175 let module C = Cic in
176 let module CTP = CicTextualParser0 in
179 CTP.ConUri uri -> UriManager.string_of_uri uri
180 | CTP.VarUri uri -> UriManager.string_of_uri uri
181 | CTP.IndTyUri (uri,tyno) ->
182 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
183 | CTP.IndConUri (uri,tyno,consno) ->
184 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
187 (* 4 = String.length "cic:" *)
188 String.sub uri' 4 (String.length uri' - 4)
191 let output_html outputhtml msg =
192 htmlheader_and_content := !htmlheader_and_content ^ msg ;
193 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
194 outputhtml#set_topline (-1)
197 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
201 let check_window outputhtml uris =
204 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
206 GPack.notebook ~scrollable:true ~packing:window#add () in
211 let scrolled_window =
212 GBin.scrolled_window ~border_width:10
214 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
219 GMathViewAux.single_selection_math_view
220 ~packing:scrolled_window#add ~width:400 ~height:280 () in
223 term_of_cic_textual_parser_uri
224 (Disambiguate.cic_textual_parser_uri_of_string uri)
226 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
229 let mml = !mml_of_cic_term_ref 111 expr in
230 mmlwidget#load_doc ~dom:mml
233 output_html outputhtml
234 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
239 (notebook#connect#switch_page
240 (function i -> Lazy.force (List.nth render_terms i)))
246 interactive_user_uri_choice ~(selection_mode:[`SINGLE|`EXTENDED]) ?(ok="Ok")
247 ?(enable_button_for_non_vars=false) ~title ~msg uris
249 let choices = ref [] in
250 let chosen = ref false in
251 let use_only_constants = ref false in
253 GWindow.dialog ~modal:true ~title ~width:600 () in
255 GMisc.label ~text:msg
256 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
257 let scrolled_window =
258 GBin.scrolled_window ~border_width:10
259 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
261 let expected_height = 18 * List.length uris in
262 let height = if expected_height > 400 then 400 else expected_height in
263 GList.clist ~columns:1 ~packing:scrolled_window#add
264 ~height ~selection_mode:(selection_mode :> Gtk.Tags.selection_mode) () in
265 let _ = List.map (function x -> clist#append [x]) uris in
267 GPack.hbox ~border_width:0
268 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
270 GMisc.label ~text:"None of the above. Try this one:"
271 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
273 GEdit.entry ~editable:true
274 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
276 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
278 GButton.button ~label:ok
279 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
280 let _ = okb#misc#set_sensitive false in
285 if enable_button_for_non_vars then
286 hbox#pack ~expand:false ~fill:false ~padding:5 w)
287 ~label:"Try constants only" () in
289 GButton.button ~label:"Check"
290 ~packing:(hbox#pack ~padding:5) () in
291 let _ = checkb#misc#set_sensitive false in
293 GButton.button ~label:"Abort"
294 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
296 let check_callback () =
297 assert (List.length !choices > 0) ;
298 check_window (outputhtml ()) !choices
300 ignore (window#connect#destroy GMain.Main.quit) ;
301 ignore (cancelb#connect#clicked window#destroy) ;
303 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
305 (nonvarsb#connect#clicked
307 use_only_constants := true ;
311 ignore (checkb#connect#clicked check_callback) ;
313 (clist#connect#select_row
314 (fun ~row ~column ~event ->
315 checkb#misc#set_sensitive true ;
316 okb#misc#set_sensitive true ;
317 choices := (List.nth uris row)::!choices)) ;
319 (clist#connect#unselect_row
320 (fun ~row ~column ~event ->
322 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
324 (manual_input#connect#changed
326 if manual_input#text = "" then
329 checkb#misc#set_sensitive false ;
330 okb#misc#set_sensitive false ;
331 clist#misc#set_sensitive true
335 choices := [manual_input#text] ;
336 clist#unselect_all () ;
337 checkb#misc#set_sensitive true ;
338 okb#misc#set_sensitive true ;
339 clist#misc#set_sensitive false
341 window#set_position `CENTER ;
345 if !use_only_constants then
347 (function uri -> not (String.sub uri (String.length uri - 4) 4 = ".var"))
350 if List.length !choices > 0 then !choices else raise NoChoice
355 EliminationTactics.interactive_user_uri_choice :=
356 (fun ~selection_mode -> interactive_user_uri_choice ~selection_mode:selection_mode);;
358 let interactive_interpretation_choice interpretations =
359 let chosen = ref None in
362 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
363 let vbox = GPack.vbox ~packing:window#add () in
367 ("Ambiguous input since there are many well-typed interpretations." ^
368 " Please, choose one of them.")
369 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
371 GPack.notebook ~scrollable:true
372 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
375 (function interpretation ->
377 let expected_height = 18 * List.length interpretation in
378 let height = if expected_height > 400 then 400 else expected_height in
379 GList.clist ~columns:2 ~packing:notebook#append_page ~height
380 ~titles:["id" ; "URI"] ()
384 (function (id,uri) ->
385 let n = clist#append [id;uri] in
386 clist#set_row ~selectable:false n
389 clist#columns_autosize ()
392 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
394 GButton.button ~label:"Ok"
395 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
397 GButton.button ~label:"Abort"
398 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
400 ignore (window#connect#destroy GMain.Main.quit) ;
401 ignore (cancelb#connect#clicked window#destroy) ;
404 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
405 window#set_position `CENTER ;
409 None -> raise NoChoice
416 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
418 let query = ref "" in
419 MQueryGenerator.set_confirm_query
420 (function q -> query := MQueryUtil.text_of_query q ; true) ;
421 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
424 let domImpl = Gdome.domImplementation ();;
426 let parseStyle name =
428 domImpl#createDocumentFromURI
430 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
432 ~uri:("styles/" ^ name) ()
434 Gdome_xslt.processStylesheet style
437 let d_c = parseStyle "drop_coercions.xsl";;
438 let tc1 = parseStyle "objtheorycontent.xsl";;
439 let hc2 = parseStyle "content_to_html.xsl";;
440 let l = parseStyle "link.xsl";;
442 let c1 = parseStyle "rootcontent.xsl";;
443 let g = parseStyle "genmmlid.xsl";;
444 let c2 = parseStyle "annotatedpres.xsl";;
447 let getterURL = Configuration.getter_url;;
448 let processorURL = Configuration.processor_url;;
450 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
451 let mml_args ~explode_all =
452 ("explodeall",(if explode_all then "true()" else "false()"))::
453 ["processorURL", "'" ^ processorURL ^ "'" ;
454 "getterURL", "'" ^ getterURL ^ "'" ;
455 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
456 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
457 "UNICODEvsSYMBOL", "'symbol'" ;
458 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
459 "encoding", "'iso-8859-1'" ;
460 "media-type", "'text/html'" ;
461 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
462 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
463 "naturalLanguage", "'yes'" ;
464 "annotations", "'no'" ;
465 "URLs_or_URIs", "'URIs'" ;
466 "topurl", "'http://phd.cs.unibo.it/helm'" ;
467 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
470 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
472 ["processorURL", "'" ^ processorURL ^ "'" ;
473 "getterURL", "'" ^ getterURL ^ "'" ;
474 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
475 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
476 "UNICODEvsSYMBOL", "'symbol'" ;
477 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
478 "encoding", "'iso-8859-1'" ;
479 "media-type", "'text/html'" ;
480 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
481 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
482 "naturalLanguage", "'no'" ;
483 "annotations", "'no'" ;
484 "explodeall", "true()" ;
485 "URLs_or_URIs", "'URIs'" ;
486 "topurl", "'http://phd.cs.unibo.it/helm'" ;
487 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
490 let parse_file filename =
491 let inch = open_in filename in
492 let rec read_lines () =
494 let line = input_line inch in
502 let applyStylesheets input styles args =
503 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
508 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
510 (*CSC: ????????????????? *)
512 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true
516 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
517 ~ask_dtd_to_the_getter:true
521 None -> Xml2Gdome.document_of_xml domImpl xml
523 Xml.pp xml (Some constanttypefile) ;
524 Xml2Gdome.document_of_xml domImpl bodyxml'
526 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
527 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
529 Xml.pp xmlinnertypes (Some innertypesfile) ;
530 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
535 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
538 let struri = UriManager.string_of_uri uri in
539 let idx = (String.rindex struri '/') + 1 in
540 String.sub struri idx (String.length struri - idx)
542 let path = pathname ^ "/" ^ name in
544 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
548 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
549 ~ask_dtd_to_the_getter:false
552 let innertypesuri = UriManager.innertypesuri_of_uri uri in
553 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
554 Getter.register innertypesuri
555 (Configuration.annotations_url ^
556 Str.replace_first (Str.regexp "^cic:") ""
557 (UriManager.string_of_uri innertypesuri) ^ ".xml"
559 (* constant type / variable / mutual inductive types definition *)
560 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
562 (Configuration.annotations_url ^
563 Str.replace_first (Str.regexp "^cic:") ""
564 (UriManager.string_of_uri uri) ^ ".xml"
571 match UriManager.bodyuri_of_uri uri with
573 | Some bodyuri -> bodyuri
575 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
576 Getter.register bodyuri
577 (Configuration.annotations_url ^
578 Str.replace_first (Str.regexp "^cic:") ""
579 (UriManager.string_of_uri bodyuri) ^ ".xml"
586 exception RefreshSequentException of exn;;
587 exception RefreshProofException of exn;;
589 let refresh_proof (output : GMathViewAux.single_selection_math_view) =
591 let uri,currentproof =
592 match !ProofEngine.proof with
594 | Some (uri,metasenv,bo,ty) ->
595 !qed_set_sensitive (List.length metasenv = 0) ;
596 (*CSC: Wrong: [] is just plainly wrong *)
597 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
600 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
601 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
603 Cic2acic.acic_object_of_cic_object currentproof
606 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
609 output#load_doc ~dom:mml ;
611 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
614 match !ProofEngine.proof with
616 | Some (uri,metasenv,bo,ty) ->
617 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
618 raise (RefreshProofException e)
621 let refresh_sequent ?(empty_notebook=true) notebook =
623 match !ProofEngine.goal with
625 if empty_notebook then
627 notebook#remove_all_pages ~skip_switch_page_event:false ;
628 notebook#set_empty_page
631 notebook#proofw#unload
634 match !ProofEngine.proof with
636 | Some (_,metasenv,_,_) -> metasenv
638 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
639 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
640 SequentPp.XmlPp.print_sequent metasenv currentsequent
642 let regenerate_notebook () =
643 let skip_switch_page_event =
645 (m,_,_)::_ when m = metano -> false
648 notebook#remove_all_pages ~skip_switch_page_event ;
649 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
651 if empty_notebook then
653 regenerate_notebook () ;
654 notebook#set_current_page ~may_skip_switch_page_event:false metano
658 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
660 applyStylesheets sequent_doc sequent_styles sequent_args
662 notebook#set_current_page ~may_skip_switch_page_event:true metano;
663 notebook#proofw#load_doc ~dom:sequent_mml
665 current_goal_infos :=
666 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
670 match !ProofEngine.goal with
675 match !ProofEngine.proof with
677 | Some (_,metasenv,_,_) -> metasenv
680 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
681 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
682 raise (RefreshSequentException e)
683 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
687 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
688 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
691 let mml_of_cic_term metano term =
693 match !ProofEngine.proof with
695 | Some (_,metasenv,_,_) -> metasenv
698 match !ProofEngine.goal with
701 let (_,canonical_context,_) =
702 List.find (function (m,_,_) -> m=metano) metasenv
706 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
707 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
710 Xml2Gdome.document_of_xml domImpl sequent_gdome
713 applyStylesheets sequent_doc sequent_styles sequent_args ;
715 current_scratch_infos :=
716 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
720 exception OpenConjecturesStillThere;;
721 exception WrongProof;;
723 let pathname_of_annuri uristring =
724 Configuration.annotations_dir ^
725 Str.replace_first (Str.regexp "^cic:") "" uristring
728 let make_dirs dirpath =
729 ignore (Unix.system ("mkdir -p " ^ dirpath))
732 let save_obj uri obj =
734 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
735 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
737 Cic2acic.acic_object_of_cic_object obj
739 (* let's save the theorem and register it to the getter *)
740 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
742 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
747 match !ProofEngine.proof with
749 | Some (uri,[],bo,ty) ->
751 CicReduction.are_convertible []
752 (CicTypeChecker.type_of_aux' [] [] bo) ty
755 (*CSC: Wrong: [] is just plainly wrong *)
756 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
758 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
759 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
761 Cic2acic.acic_object_of_cic_object proof
764 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
767 ((rendering_window ())#output : GMathViewAux.single_selection_math_view)#load_doc mml ;
768 !qed_set_sensitive false ;
769 (* let's save the theorem and register it to the getter *)
770 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
772 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
776 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
781 | _ -> raise OpenConjecturesStillThere
785 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
786 match !ProofEngine.proof with
788 | Some (uri, metasenv, bo, ty) ->
790 (*CSC: Wrong: [] is just plainly wrong *)
791 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
793 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
794 Cic2acic.acic_object_of_cic_object currentproof
798 Cic2Xml.print_object uri ~ids_to_inner_sorts
799 ~ask_dtd_to_the_getter:true acurrentproof
801 xml,Some bodyxml -> xml,bodyxml
802 | _,None -> assert false
804 Xml.pp ~quiet:true xml (Some prooffiletype) ;
805 output_html outputhtml
806 ("<h1 color=\"Green\">Current proof type saved to " ^
807 prooffiletype ^ "</h1>") ;
808 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
809 output_html outputhtml
810 ("<h1 color=\"Green\">Current proof body saved to " ^
814 (* Used to typecheck the loaded proofs *)
815 let typecheck_loaded_proof metasenv bo ty =
816 let module T = CicTypeChecker in
819 (fun metasenv ((_,context,ty) as conj) ->
820 ignore (T.type_of_aux' metasenv context ty) ;
823 ignore (T.type_of_aux' metasenv [] ty) ;
824 ignore (T.type_of_aux' metasenv [] bo)
828 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
829 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
830 let notebook = (rendering_window ())#notebook in
833 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
836 None -> raise NoChoice
838 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
839 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
840 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
841 typecheck_loaded_proof metasenv bo ty ;
843 Some (uri, metasenv, bo, ty) ;
847 | (metano,_,_)::_ -> Some metano
849 refresh_proof output ;
850 refresh_sequent notebook ;
851 output_html outputhtml
852 ("<h1 color=\"Green\">Current proof type loaded from " ^
853 prooffiletype ^ "</h1>") ;
854 output_html outputhtml
855 ("<h1 color=\"Green\">Current proof body loaded from " ^
856 prooffile ^ "</h1>") ;
857 !save_set_sensitive true
860 RefreshSequentException e ->
861 output_html outputhtml
862 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
863 "sequent: " ^ Printexc.to_string e ^ "</h1>")
864 | RefreshProofException e ->
865 output_html outputhtml
866 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
867 "proof: " ^ Printexc.to_string e ^ "</h1>")
869 output_html outputhtml
870 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
873 let edit_aliases () =
874 let chosen = ref false in
877 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
879 GPack.vbox ~border_width:0 ~packing:window#add () in
880 let scrolled_window =
881 GBin.scrolled_window ~border_width:10
882 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
883 let input = GEdit.text ~editable:true ~width:400 ~height:100
884 ~packing:scrolled_window#add () in
886 GPack.hbox ~border_width:0
887 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
889 GButton.button ~label:"Ok"
890 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
892 GButton.button ~label:"Cancel"
893 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
894 ignore (window#connect#destroy GMain.Main.quit) ;
895 ignore (cancelb#connect#clicked window#destroy) ;
897 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
898 let dom,resolve_id = !id_to_uris in
900 (input#insert_text ~pos:0
905 match resolve_id v with
910 (string_of_cic_textual_parser_uri uri)
916 let inputtext = input#get_chars 0 input#length in
918 let alfa = "[a-zA-Z_-]" in
919 let digit = "[0-9]" in
920 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
921 let blanks = "\( \|\t\|\n\)+" in
922 let nonblanks = "[^ \t\n]+" in
923 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
925 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
929 let n' = Str.search_forward regexpr inputtext n in
930 let id = Str.matched_group 2 inputtext in
932 Disambiguate.cic_textual_parser_uri_of_string
933 ("cic:" ^ (Str.matched_group 5 inputtext))
935 let dom,resolve_id = aux (n' + 1) in
936 if List.mem id dom then
940 (function id' -> if id = id' then Some uri else resolve_id id')
942 Not_found -> empty_id_to_uris
946 id_to_uris := dom,resolve_id
950 let module L = LogicalOperations in
951 let module G = Gdome in
952 let notebook = (rendering_window ())#notebook in
953 let output = (rendering_window ())#output in
954 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
955 match (rendering_window ())#output#get_selection with
958 ((node : Gdome.element)#getAttributeNS
960 ((element : G.element)#getAttributeNS
963 ~localName:(G.domString "xref"))#to_string
965 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
969 match !current_cic_infos with
970 Some (ids_to_terms, ids_to_father_ids, _, _) ->
972 L.to_sequent id ids_to_terms ids_to_father_ids ;
973 refresh_proof output ;
974 refresh_sequent notebook
975 | None -> assert false (* "ERROR: No current term!!!" *)
977 RefreshSequentException e ->
978 output_html outputhtml
979 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
980 "sequent: " ^ Printexc.to_string e ^ "</h1>")
981 | RefreshProofException e ->
982 output_html outputhtml
983 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
984 "proof: " ^ Printexc.to_string e ^ "</h1>")
986 output_html outputhtml
987 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
989 | None -> assert false (* "ERROR: No selection!!!" *)
993 let module L = LogicalOperations in
994 let module G = Gdome in
995 let notebook = (rendering_window ())#notebook in
996 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
997 match (rendering_window ())#output#get_selection with
1000 ((node : Gdome.element)#getAttributeNS
1001 (*CSC: OCAML DIVERGE
1002 ((element : G.element)#getAttributeNS
1004 ~namespaceURI:helmns
1005 ~localName:(G.domString "xref"))#to_string
1007 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1011 match !current_cic_infos with
1012 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1014 L.focus id ids_to_terms ids_to_father_ids ;
1015 refresh_sequent notebook
1016 | None -> assert false (* "ERROR: No current term!!!" *)
1018 RefreshSequentException e ->
1019 output_html outputhtml
1020 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1021 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1022 | RefreshProofException e ->
1023 output_html outputhtml
1024 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1025 "proof: " ^ Printexc.to_string e ^ "</h1>")
1027 output_html outputhtml
1028 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1030 | None -> assert false (* "ERROR: No selection!!!" *)
1033 exception NoPrevGoal;;
1034 exception NoNextGoal;;
1036 let setgoal metano =
1037 let module L = LogicalOperations in
1038 let module G = Gdome in
1039 let notebook = (rendering_window ())#notebook in
1040 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1042 match !ProofEngine.proof with
1043 None -> assert false
1044 | Some (_,metasenv,_,_) -> metasenv
1047 refresh_sequent ~empty_notebook:false notebook
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>")
1054 output_html outputhtml
1055 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1059 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
1062 GWindow.window ~width:800 ~border_width:2 () in
1063 let scrolled_window =
1064 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1066 GMathViewAux.single_selection_math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1067 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1068 let href = Gdome.domString "href" in
1069 let show_in_show_window_obj uri obj =
1070 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1073 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1074 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1076 Cic2acic.acic_object_of_cic_object obj
1079 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1082 window#set_title (UriManager.string_of_uri uri) ;
1083 window#misc#hide () ; window#show () ;
1084 mmlwidget#load_doc mml ;
1087 output_html outputhtml
1088 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1090 let show_in_show_window_uri uri =
1091 let obj = CicEnvironment.get_obj uri in
1092 show_in_show_window_obj uri obj
1094 let show_in_show_window_callback mmlwidget (n : Gdome.element) _ =
1095 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1097 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1099 show_in_show_window_uri (UriManager.uri_of_string uri)
1102 "'get_action' and 'action_toggle' not yet implemented in lablgtkmathview 0.3.99"
1103 (* TODO commented out because not yet implemented in lablgtkmathview 0.3.99 *)
1105 if mmlwidget#get_action <> None then
1106 mmlwidget#action_toggle
1110 mmlwidget#connect#click (show_in_show_window_callback mmlwidget)
1112 show_in_show_window_obj, show_in_show_window_uri,
1113 show_in_show_window_callback
1116 exception NoObjectsLocated;;
1118 let user_uri_choice ~title ~msg uris =
1121 [] -> raise NoObjectsLocated
1125 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1130 String.sub uri 4 (String.length uri - 4)
1133 let locate_callback id =
1134 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1135 let result = MQueryGenerator.locate id in
1139 Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format' uri)
1142 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1144 output_html outputhtml html ;
1145 user_uri_choice ~title:"Ambiguous input."
1147 ("Ambiguous input \"" ^ id ^
1148 "\". Please, choose one interpetation:")
1153 let input_or_locate_uri ~title =
1154 let uri = ref None in
1157 ~width:400 ~modal:true ~title ~border_width:2 () in
1158 let vbox = GPack.vbox ~packing:window#add () in
1160 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1162 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1164 GEdit.entry ~editable:true
1165 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1167 GButton.button ~label:"Check"
1168 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1169 let _ = checkb#misc#set_sensitive false in
1171 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1173 GMisc.label ~text:"You can also enter an indentifier to locate:"
1174 ~packing:(hbox2#pack ~padding:5) () in
1176 GEdit.entry ~editable:true
1177 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1179 GButton.button ~label:"Locate"
1180 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1181 let _ = locateb#misc#set_sensitive false in
1183 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1185 GButton.button ~label:"Ok"
1186 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1187 let _ = okb#misc#set_sensitive false in
1189 GButton.button ~label:"Cancel"
1190 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1192 ignore (window#connect#destroy GMain.Main.quit) ;
1194 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1195 let check_callback () =
1196 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1197 let uri = "cic:" ^ manual_input#text in
1199 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1200 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1203 Getter.Unresolved ->
1204 output_html outputhtml
1205 ("<h1 color=\"Red\">URI " ^ uri ^
1206 " does not correspond to any object.</h1>") ;
1208 | UriManager.IllFormedUri _ ->
1209 output_html outputhtml
1210 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1213 output_html outputhtml
1214 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1218 (okb#connect#clicked
1220 if check_callback () then
1222 uri := Some manual_input#text ;
1226 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1228 (manual_input#connect#changed
1230 if manual_input#text = "" then
1232 checkb#misc#set_sensitive false ;
1233 okb#misc#set_sensitive false
1237 checkb#misc#set_sensitive true ;
1238 okb#misc#set_sensitive true
1241 (locate_input#connect#changed
1242 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1244 (locateb#connect#clicked
1246 let id = locate_input#text in
1247 manual_input#set_text (locate_callback id) ;
1248 locate_input#delete_text 0 (String.length id)
1251 GMain.Main.main () ;
1253 None -> raise NoChoice
1254 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1257 exception AmbiguousInput;;
1259 (* A WIDGET TO ENTER CIC TERMS *)
1263 let output_html msg = output_html (outputhtml ()) msg;;
1264 let interactive_user_uri_choice =
1265 fun ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id ->
1266 interactive_user_uri_choice ~selection_mode ?ok
1267 ?enable_button_for_non_vars ~title ~msg;;
1268 let interactive_interpretation_choice = interactive_interpretation_choice;;
1269 let input_or_locate_uri = input_or_locate_uri;;
1273 module Disambiguate' = Disambiguate.Make(Callbacks);;
1275 class term_editor ?packing ?width ?height ?isnotempty_callback () =
1276 let input = GEdit.text ~editable:true ?width ?height ?packing () in
1278 match isnotempty_callback with
1281 ignore(input#connect#changed (function () -> callback (input#length > 0)))
1284 method coerce = input#coerce
1286 input#delete_text 0 input#length
1287 (* CSC: txt is now a string, but should be of type Cic.term *)
1288 method set_term txt =
1290 ignore ((input#insert_text txt) ~pos:0)
1291 (* CSC: this method should disappear *)
1292 method get_as_string =
1293 input#get_chars 0 input#length
1294 method get_metasenv_and_term ~context ~metasenv =
1298 Some (n,_) -> Some n
1302 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
1303 let dom,mk_metasenv_and_expr =
1304 CicTextualParserContext.main
1305 ~context:name_context ~metasenv CicTextualLexer.token lexbuf
1307 let id_to_uris',metasenv,expr =
1308 Disambiguate'.disambiguate_input context metasenv dom mk_metasenv_and_expr
1309 ~id_to_uris:!id_to_uris
1311 id_to_uris := id_to_uris' ;
1316 (* OTHER FUNCTIONS *)
1319 let inputt = ((rendering_window ())#inputt : term_editor) in
1320 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1323 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1325 None -> raise NoChoice
1327 let uri = locate_callback input in
1331 output_html outputhtml
1332 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1336 exception UriAlreadyInUse;;
1337 exception NotAUriToAConstant;;
1339 let new_inductive () =
1340 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1341 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1342 let notebook = (rendering_window ())#notebook in
1344 let chosen = ref false in
1345 let inductive = ref true in
1346 let paramsno = ref 0 in
1347 let get_uri = ref (function _ -> assert false) in
1348 let get_base_uri = ref (function _ -> assert false) in
1349 let get_names = ref (function _ -> assert false) in
1350 let get_types_and_cons = ref (function _ -> assert false) in
1351 let get_context_and_subst = ref (function _ -> assert false) in
1354 ~width:600 ~modal:true ~position:`CENTER
1355 ~title:"New Block of Mutual (Co)Inductive Definitions"
1356 ~border_width:2 () in
1357 let vbox = GPack.vbox ~packing:window#add () in
1359 GPack.hbox ~border_width:0
1360 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1362 GMisc.label ~text:"Enter the URI for the new block:"
1363 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1365 GEdit.entry ~editable:true
1366 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1368 GPack.hbox ~border_width:0
1369 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1373 "Enter the number of left parameters in every arity and constructor type:"
1374 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1375 let paramsno_entry =
1376 GEdit.entry ~editable:true ~text:"0"
1377 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1379 GPack.hbox ~border_width:0
1380 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1382 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1383 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1385 GButton.radio_button ~label:"Inductive"
1386 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1388 GButton.radio_button ~label:"Coinductive"
1389 ~group:inductiveb#group
1390 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1392 GPack.hbox ~border_width:0
1393 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1395 GMisc.label ~text:"Enter the list of the names of the types:"
1396 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1398 GEdit.entry ~editable:true
1399 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1401 GPack.hbox ~border_width:0
1402 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1404 GButton.button ~label:"> Next"
1405 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1406 let _ = okb#misc#set_sensitive true in
1408 GButton.button ~label:"Abort"
1409 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1410 ignore (window#connect#destroy GMain.Main.quit) ;
1411 ignore (cancelb#connect#clicked window#destroy) ;
1415 (okb#connect#clicked
1418 let uristr = "cic:" ^ uri_entry#text in
1419 let namesstr = names_entry#text in
1420 let paramsno' = int_of_string (paramsno_entry#text) in
1421 match Str.split (Str.regexp " +") namesstr with
1423 | (he::tl) as names ->
1424 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1427 ignore (Getter.resolve uri) ;
1428 raise UriAlreadyInUse
1430 Getter.Unresolved ->
1431 get_uri := (function () -> uri) ;
1432 get_names := (function () -> names) ;
1433 inductive := inductiveb#active ;
1434 paramsno := paramsno' ;
1439 output_html outputhtml
1440 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1448 GBin.frame ~label:name
1449 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1450 let vbox = GPack.vbox ~packing:frame#add () in
1451 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1453 GMisc.label ~text:("Enter its type:")
1454 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1455 let scrolled_window =
1456 GBin.scrolled_window ~border_width:5
1457 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1459 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1460 ~isnotempty_callback:
1462 (*non_empty_type := b ;*)
1463 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1466 GPack.hbox ~border_width:0
1467 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1469 GMisc.label ~text:("Enter the list of its constructors:")
1470 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1471 let cons_names_entry =
1472 GEdit.entry ~editable:true
1473 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1474 (newinputt,cons_names_entry)
1477 vbox#remove hboxn#coerce ;
1479 GPack.hbox ~border_width:0
1480 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1482 GButton.button ~label:"> Next"
1483 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1485 GButton.button ~label:"Abort"
1486 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1487 ignore (cancelb#connect#clicked window#destroy) ;
1489 (okb#connect#clicked
1492 let names = !get_names () in
1493 let types_and_cons =
1495 (fun name (newinputt,cons_names_entry) ->
1496 let consnamesstr = cons_names_entry#text in
1497 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1499 newinputt#get_metasenv_and_term ~context:[] ~metasenv:[]
1502 [] -> expr,cons_names
1503 | _ -> raise AmbiguousInput
1504 ) names type_widgets
1506 let uri = !get_uri () in
1508 (* Let's see if so far the definition is well-typed *)
1511 (* To test if the arities of the inductive types are well *)
1512 (* typed, we check the inductive block definition where *)
1513 (* no constructor is given to each type. *)
1516 (fun name (ty,cons) -> (name, !inductive, ty, []))
1517 names types_and_cons
1519 CicTypeChecker.typecheck_mutual_inductive_defs uri
1520 (tys,params,paramsno)
1522 get_context_and_subst :=
1526 (fun (context,subst) name (ty,_) ->
1528 (Some (Cic.Name name, Cic.Decl ty))::context,
1529 (Cic.MutInd (uri,!i,[]))::subst
1532 ) ([],[]) names types_and_cons) ;
1533 let types_and_cons' =
1535 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1536 names types_and_cons
1538 get_types_and_cons := (function () -> types_and_cons') ;
1543 output_html outputhtml
1544 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1547 and phase3 name cons =
1548 let get_cons_types = ref (function () -> assert false) in
1551 ~width:600 ~modal:true ~position:`CENTER
1552 ~title:(name ^ " Constructors")
1553 ~border_width:2 () in
1554 let vbox = GPack.vbox ~packing:window2#add () in
1555 let cons_type_widgets =
1557 (function consname ->
1559 GPack.hbox ~border_width:0
1560 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1562 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1563 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1564 let scrolled_window =
1565 GBin.scrolled_window ~border_width:5
1566 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1568 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1569 ~isnotempty_callback:
1571 (* (*non_empty_type := b ;*)
1572 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1577 GPack.hbox ~border_width:0
1578 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1580 GButton.button ~label:"> Next"
1581 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1582 let _ = okb#misc#set_sensitive true in
1584 GButton.button ~label:"Abort"
1585 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1586 ignore (window2#connect#destroy GMain.Main.quit) ;
1587 ignore (cancelb#connect#clicked window2#destroy) ;
1589 (okb#connect#clicked
1593 let context,subst= !get_context_and_subst () in
1598 inputt#get_metasenv_and_term ~context ~metasenv:[]
1602 let undebrujined_expr =
1604 (fun expr t -> CicSubstitution.subst t expr) expr subst
1606 name, undebrujined_expr
1607 | _ -> raise AmbiguousInput
1608 ) cons cons_type_widgets
1610 get_cons_types := (function () -> cons_types) ;
1614 output_html outputhtml
1615 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1618 GMain.Main.main () ;
1619 let okb_pressed = !chosen in
1621 if (not okb_pressed) then
1624 assert false (* The control never reaches this point *)
1627 (!get_cons_types ())
1630 (* No more phases left or Abort pressed *)
1632 GMain.Main.main () ;
1636 let uri = !get_uri () in
1639 let tys = !get_types_and_cons () in
1640 let obj = Cic.InductiveDefinition tys params !paramsno in
1643 prerr_endline (CicPp.ppobj obj) ;
1644 CicTypeChecker.typecheck_mutual_inductive_defs uri
1645 (tys,params,!paramsno) ;
1648 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1649 prerr_endline (CicPp.ppobj obj) ;
1651 (* We already know that obj is well-typed. We need to add it to the *)
1652 (* environment in order to compute the inner-types without having to *)
1653 (* debrujin it or having to modify lots of other functions to avoid *)
1654 (* asking the environment for the MUTINDs we are defining now. *)
1655 CicEnvironment.put_inductive_definition uri obj ;
1657 show_in_show_window_obj uri obj
1660 output_html outputhtml
1661 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1665 let inputt = ((rendering_window ())#inputt : term_editor) in
1666 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1667 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1668 let notebook = (rendering_window ())#notebook in
1670 let chosen = ref false in
1671 let get_metasenv_and_term = ref (function _ -> assert false) in
1672 let get_uri = ref (function _ -> assert false) in
1673 let non_empty_type = ref false in
1676 ~width:600 ~modal:true ~title:"New Proof or Definition"
1677 ~border_width:2 () in
1678 let vbox = GPack.vbox ~packing:window#add () in
1680 GPack.hbox ~border_width:0
1681 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1683 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1684 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1686 GEdit.entry ~editable:true
1687 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1689 GPack.hbox ~border_width:0
1690 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1692 GMisc.label ~text:"Enter the theorem or definition type:"
1693 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1694 let scrolled_window =
1695 GBin.scrolled_window ~border_width:5
1696 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1697 (* the content of the scrolled_window is moved below (see comment) *)
1699 GPack.hbox ~border_width:0
1700 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1702 GButton.button ~label:"Ok"
1703 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1704 let _ = okb#misc#set_sensitive false in
1706 GButton.button ~label:"Cancel"
1707 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1708 (* moved here to have visibility of the ok button *)
1710 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1711 ~isnotempty_callback:
1713 non_empty_type := b ;
1714 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1717 newinputt#set_term inputt#get_as_string ;
1720 uri_entry#connect#changed
1722 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1724 ignore (window#connect#destroy GMain.Main.quit) ;
1725 ignore (cancelb#connect#clicked window#destroy) ;
1727 (okb#connect#clicked
1731 let metasenv,parsed = newinputt#get_metasenv_and_term [] [] in
1732 let uristr = "cic:" ^ uri_entry#text in
1733 let uri = UriManager.uri_of_string uristr in
1734 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1735 raise NotAUriToAConstant
1739 ignore (Getter.resolve uri) ;
1740 raise UriAlreadyInUse
1742 Getter.Unresolved ->
1743 get_metasenv_and_term := (function () -> metasenv,parsed) ;
1744 get_uri := (function () -> uri) ;
1749 output_html outputhtml
1750 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1753 GMain.Main.main () ;
1756 let metasenv,expr = !get_metasenv_and_term () in
1757 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1758 ProofEngine.proof :=
1759 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1760 ProofEngine.goal := Some 1 ;
1761 refresh_sequent notebook ;
1762 refresh_proof output ;
1763 !save_set_sensitive true ;
1766 RefreshSequentException e ->
1767 output_html outputhtml
1768 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1769 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1770 | RefreshProofException e ->
1771 output_html outputhtml
1772 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1773 "proof: " ^ Printexc.to_string e ^ "</h1>")
1775 output_html outputhtml
1776 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1779 let check_term_in_scratch scratch_window metasenv context expr =
1781 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1782 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1783 scratch_window#show () ;
1784 scratch_window#mmlwidget#load_doc ~dom:mml
1787 print_endline ("? " ^ CicPp.ppterm expr) ;
1791 let check scratch_window () =
1792 let inputt = ((rendering_window ())#inputt : term_editor) in
1793 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1795 match !ProofEngine.proof with
1797 | Some (_,metasenv,_,_) -> metasenv
1800 match !ProofEngine.goal with
1803 let (_,canonical_context,_) =
1804 List.find (function (m,_,_) -> m=metano) metasenv
1809 let metasenv',expr = inputt#get_metasenv_and_term context metasenv in
1810 check_term_in_scratch scratch_window metasenv' context expr
1813 output_html outputhtml
1814 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1818 (***********************)
1820 (***********************)
1822 let call_tactic tactic () =
1823 let notebook = (rendering_window ())#notebook in
1824 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1825 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1826 let savedproof = !ProofEngine.proof in
1827 let savedgoal = !ProofEngine.goal in
1831 refresh_sequent notebook ;
1832 refresh_proof output
1834 RefreshSequentException e ->
1835 output_html outputhtml
1836 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1837 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1838 ProofEngine.proof := savedproof ;
1839 ProofEngine.goal := savedgoal ;
1840 refresh_sequent notebook
1841 | RefreshProofException e ->
1842 output_html outputhtml
1843 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1844 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1845 ProofEngine.proof := savedproof ;
1846 ProofEngine.goal := savedgoal ;
1847 refresh_sequent notebook ;
1848 refresh_proof output
1850 output_html outputhtml
1851 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1852 ProofEngine.proof := savedproof ;
1853 ProofEngine.goal := savedgoal ;
1857 let call_tactic_with_input tactic () =
1858 let notebook = (rendering_window ())#notebook in
1859 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1860 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1861 let inputt = ((rendering_window ())#inputt : term_editor) in
1862 let savedproof = !ProofEngine.proof in
1863 let savedgoal = !ProofEngine.goal in
1864 let uri,metasenv,bo,ty =
1865 match !ProofEngine.proof with
1866 None -> assert false
1867 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1869 let canonical_context =
1870 match !ProofEngine.goal with
1871 None -> assert false
1873 let (_,canonical_context,_) =
1874 List.find (function (m,_,_) -> m=metano) metasenv
1879 let metasenv',expr =
1880 inputt#get_metasenv_and_term canonical_context metasenv
1882 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
1884 refresh_sequent notebook ;
1885 refresh_proof output ;
1888 RefreshSequentException e ->
1889 output_html outputhtml
1890 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1891 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1892 ProofEngine.proof := savedproof ;
1893 ProofEngine.goal := savedgoal ;
1894 refresh_sequent notebook
1895 | RefreshProofException e ->
1896 output_html outputhtml
1897 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1898 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1899 ProofEngine.proof := savedproof ;
1900 ProofEngine.goal := savedgoal ;
1901 refresh_sequent notebook ;
1902 refresh_proof output
1904 output_html outputhtml
1905 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1906 ProofEngine.proof := savedproof ;
1907 ProofEngine.goal := savedgoal ;
1910 let call_tactic_with_goal_input tactic () =
1911 let module L = LogicalOperations in
1912 let module G = Gdome in
1913 let notebook = (rendering_window ())#notebook in
1914 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1915 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1916 let savedproof = !ProofEngine.proof in
1917 let savedgoal = !ProofEngine.goal in
1918 match notebook#proofw#get_selection with
1921 ((node : Gdome.element)#getAttributeNS
1922 ~namespaceURI:helmns
1923 ~localName:(G.domString "xref"))#to_string
1925 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1929 match !current_goal_infos with
1930 Some (ids_to_terms, ids_to_father_ids,_) ->
1932 tactic (Hashtbl.find ids_to_terms id) ;
1933 refresh_sequent notebook ;
1934 refresh_proof output
1935 | None -> assert false (* "ERROR: No current term!!!" *)
1937 RefreshSequentException e ->
1938 output_html outputhtml
1939 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1940 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1941 ProofEngine.proof := savedproof ;
1942 ProofEngine.goal := savedgoal ;
1943 refresh_sequent notebook
1944 | RefreshProofException e ->
1945 output_html outputhtml
1946 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1947 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1948 ProofEngine.proof := savedproof ;
1949 ProofEngine.goal := savedgoal ;
1950 refresh_sequent notebook ;
1951 refresh_proof output
1953 output_html outputhtml
1954 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1955 ProofEngine.proof := savedproof ;
1956 ProofEngine.goal := savedgoal ;
1959 output_html outputhtml
1960 ("<h1 color=\"red\">No term selected</h1>")
1963 let call_tactic_with_input_and_goal_input tactic () =
1964 let module L = LogicalOperations in
1965 let module G = Gdome in
1966 let notebook = (rendering_window ())#notebook in
1967 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
1968 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1969 let inputt = ((rendering_window ())#inputt : term_editor) in
1970 let savedproof = !ProofEngine.proof in
1971 let savedgoal = !ProofEngine.goal in
1972 match notebook#proofw#get_selection with
1975 ((node : Gdome.element)#getAttributeNS
1976 ~namespaceURI:helmns
1977 ~localName:(G.domString "xref"))#to_string
1979 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1983 match !current_goal_infos with
1984 Some (ids_to_terms, ids_to_father_ids,_) ->
1986 let uri,metasenv,bo,ty =
1987 match !ProofEngine.proof with
1988 None -> assert false
1989 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1991 let canonical_context =
1992 match !ProofEngine.goal with
1993 None -> assert false
1995 let (_,canonical_context,_) =
1996 List.find (function (m,_,_) -> m=metano) metasenv
1998 canonical_context in
1999 let (metasenv',expr) =
2000 inputt#get_metasenv_and_term canonical_context metasenv
2002 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
2003 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
2005 refresh_sequent notebook ;
2006 refresh_proof output ;
2008 | None -> assert false (* "ERROR: No current term!!!" *)
2010 RefreshSequentException e ->
2011 output_html outputhtml
2012 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2013 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2014 ProofEngine.proof := savedproof ;
2015 ProofEngine.goal := savedgoal ;
2016 refresh_sequent notebook
2017 | RefreshProofException e ->
2018 output_html outputhtml
2019 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2020 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2021 ProofEngine.proof := savedproof ;
2022 ProofEngine.goal := savedgoal ;
2023 refresh_sequent notebook ;
2024 refresh_proof output
2026 output_html outputhtml
2027 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2028 ProofEngine.proof := savedproof ;
2029 ProofEngine.goal := savedgoal ;
2032 output_html outputhtml
2033 ("<h1 color=\"red\">No term selected</h1>")
2036 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
2037 let module L = LogicalOperations in
2038 let module G = Gdome in
2039 let mmlwidget = (scratch_window#mmlwidget : GMathViewAux.single_selection_math_view) in
2040 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2041 let savedproof = !ProofEngine.proof in
2042 let savedgoal = !ProofEngine.goal in
2043 match mmlwidget#get_selection with
2046 ((node : Gdome.element)#getAttributeNS
2047 ~namespaceURI:helmns
2048 ~localName:(G.domString "xref"))#to_string
2050 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2054 match !current_scratch_infos with
2055 (* term is the whole goal in the scratch_area *)
2056 Some (term,ids_to_terms, ids_to_father_ids,_) ->
2058 let expr = tactic term (Hashtbl.find ids_to_terms id) in
2059 let mml = mml_of_cic_term 111 expr in
2060 scratch_window#show () ;
2061 scratch_window#mmlwidget#load_doc ~dom:mml
2062 | None -> assert false (* "ERROR: No current term!!!" *)
2065 output_html outputhtml
2066 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2069 output_html outputhtml
2070 ("<h1 color=\"red\">No term selected</h1>")
2073 let call_tactic_with_hypothesis_input tactic () =
2074 let module L = LogicalOperations in
2075 let module G = Gdome in
2076 let notebook = (rendering_window ())#notebook in
2077 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
2078 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2079 let savedproof = !ProofEngine.proof in
2080 let savedgoal = !ProofEngine.goal in
2081 match notebook#proofw#get_selection with
2084 ((node : Gdome.element)#getAttributeNS
2085 ~namespaceURI:helmns
2086 ~localName:(G.domString "xref"))#to_string
2088 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2092 match !current_goal_infos with
2093 Some (_,_,ids_to_hypotheses) ->
2095 tactic (Hashtbl.find ids_to_hypotheses id) ;
2096 refresh_sequent notebook ;
2097 refresh_proof output
2098 | None -> assert false (* "ERROR: No current term!!!" *)
2100 RefreshSequentException e ->
2101 output_html outputhtml
2102 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2103 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2104 ProofEngine.proof := savedproof ;
2105 ProofEngine.goal := savedgoal ;
2106 refresh_sequent notebook
2107 | RefreshProofException e ->
2108 output_html outputhtml
2109 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2110 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2111 ProofEngine.proof := savedproof ;
2112 ProofEngine.goal := savedgoal ;
2113 refresh_sequent notebook ;
2114 refresh_proof output
2116 output_html outputhtml
2117 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2118 ProofEngine.proof := savedproof ;
2119 ProofEngine.goal := savedgoal ;
2122 output_html outputhtml
2123 ("<h1 color=\"red\">No term selected</h1>")
2127 let intros = call_tactic ProofEngine.intros;;
2128 let exact = call_tactic_with_input ProofEngine.exact;;
2129 let apply = call_tactic_with_input ProofEngine.apply;;
2130 let elimintrossimpl = call_tactic_with_input ProofEngine.elim_intros_simpl;;
2131 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
2132 let whd = call_tactic_with_goal_input ProofEngine.whd;;
2133 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
2134 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
2135 let fold_whd = call_tactic_with_input ProofEngine.fold_whd;;
2136 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce;;
2137 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl;;
2138 let cut = call_tactic_with_input ProofEngine.cut;;
2139 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
2140 let letin = call_tactic_with_input ProofEngine.letin;;
2141 let ring = call_tactic ProofEngine.ring;;
2142 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
2143 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
2144 let fourier = call_tactic ProofEngine.fourier;;
2145 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
2146 let rewritebacksimpl = call_tactic_with_input ProofEngine.rewrite_back_simpl;;
2147 let replace = call_tactic_with_input_and_goal_input ProofEngine.replace;;
2148 let reflexivity = call_tactic ProofEngine.reflexivity;;
2149 let symmetry = call_tactic ProofEngine.symmetry;;
2150 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
2151 let exists = call_tactic ProofEngine.exists;;
2152 let split = call_tactic ProofEngine.split;;
2153 let left = call_tactic ProofEngine.left;;
2154 let right = call_tactic ProofEngine.right;;
2155 let assumption = call_tactic ProofEngine.assumption;;
2156 let generalize = call_tactic_with_goal_input ProofEngine.generalize;;
2157 let absurd = call_tactic_with_input ProofEngine.absurd;;
2158 let contradiction = call_tactic ProofEngine.contradiction;;
2159 let decompose = call_tactic_with_input ProofEngine.decompose;;
2161 let whd_in_scratch scratch_window =
2162 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
2165 let reduce_in_scratch scratch_window =
2166 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
2169 let simpl_in_scratch scratch_window =
2170 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
2176 (**********************)
2177 (* END OF TACTICS *)
2178 (**********************)
2182 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2184 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
2187 output_html outputhtml
2188 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2191 exception NotADefinition;;
2194 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2195 let output = ((rendering_window ())#output : GMathViewAux.single_selection_math_view) in
2196 let notebook = (rendering_window ())#notebook in
2198 let uri = input_or_locate_uri ~title:"Open" in
2199 CicTypeChecker.typecheck uri ;
2200 let metasenv,bo,ty =
2201 match CicEnvironment.get_cooked_obj uri with
2202 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
2203 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
2206 | Cic.InductiveDefinition _ -> raise NotADefinition
2208 ProofEngine.proof :=
2209 Some (uri, metasenv, bo, ty) ;
2210 ProofEngine.goal := None ;
2211 refresh_sequent notebook ;
2212 refresh_proof output
2214 RefreshSequentException e ->
2215 output_html outputhtml
2216 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2217 "sequent: " ^ Printexc.to_string e ^ "</h1>")
2218 | RefreshProofException e ->
2219 output_html outputhtml
2220 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2221 "proof: " ^ Printexc.to_string e ^ "</h1>")
2223 output_html outputhtml
2224 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2227 let show_query_results results =
2230 ~modal:false ~title:"Query results." ~border_width:2 () in
2231 let vbox = GPack.vbox ~packing:window#add () in
2233 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2236 ~text:"Click on a URI to show that object"
2237 ~packing:hbox#add () in
2238 let scrolled_window =
2239 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
2240 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2241 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
2244 (function (uri,_) ->
2248 clist#set_row ~selectable:false n
2251 clist#columns_autosize () ;
2253 (clist#connect#select_row
2254 (fun ~row ~column ~event ->
2255 let (uristr,_) = List.nth results row in
2257 Disambiguate.cic_textual_parser_uri_of_string
2258 (Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format'
2261 CicTextualParser0.ConUri uri
2262 | CicTextualParser0.VarUri uri
2263 | CicTextualParser0.IndTyUri (uri,_)
2264 | CicTextualParser0.IndConUri (uri,_,_) ->
2265 show_in_show_window_uri uri
2271 let refine_constraints (must_obj,must_rel,must_sort) =
2272 let chosen = ref false in
2273 let use_only = ref false in
2276 ~modal:true ~title:"Constraints refinement."
2277 ~width:800 ~border_width:2 () in
2278 let vbox = GPack.vbox ~packing:window#add () in
2280 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2283 ~text: "\"Only\" constraints can be enforced or not."
2284 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2286 GButton.toggle_button ~label:"Enforce \"only\" constraints"
2287 ~active:false ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2290 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
2291 (* Notebook for the constraints choice *)
2293 GPack.notebook ~scrollable:true
2294 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2295 (* Rel constraints *)
2298 ~text: "Constraints on Rels" () in
2300 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2303 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2306 ~text: "You can now specify the constraints on Rels."
2307 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2308 let expected_height = 25 * (List.length must_rel + 2) in
2309 let height = if expected_height > 400 then 400 else expected_height in
2310 let scrolled_window =
2311 GBin.scrolled_window ~border_width:10 ~height ~width:600
2312 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2313 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2314 let rel_constraints =
2316 (function (position,depth) ->
2319 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2323 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2325 None -> position, ref None
2327 let mutable_ref = ref (Some depth') in
2329 GButton.toggle_button
2330 ~label:("depth = " ^ string_of_int depth') ~active:true
2331 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2334 (depthb#connect#toggled
2336 let sel_depth = if depthb#active then Some depth' else None in
2337 mutable_ref := sel_depth
2339 position, mutable_ref
2341 (* Sort constraints *)
2344 ~text: "Constraints on Sorts" () in
2346 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2349 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2352 ~text: "You can now specify the constraints on Sorts."
2353 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2354 let expected_height = 25 * (List.length must_sort + 2) in
2355 let height = if expected_height > 400 then 400 else expected_height in
2356 let scrolled_window =
2357 GBin.scrolled_window ~border_width:10 ~height ~width:600
2358 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2359 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2360 let sort_constraints =
2362 (function (position,depth,sort) ->
2365 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2368 ~text:(sort ^ " " ^ position)
2369 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2371 None -> position, ref None, sort
2373 let mutable_ref = ref (Some depth') in
2375 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
2377 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2380 (depthb#connect#toggled
2382 let sel_depth = if depthb#active then Some depth' else None in
2383 mutable_ref := sel_depth
2385 position, mutable_ref, sort
2387 (* Obj constraints *)
2390 ~text: "Constraints on constants" () in
2392 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce)
2395 GPack.hbox ~packing:(vbox'#pack ~expand:false ~fill:false ~padding:5) () in
2398 ~text: "You can now specify the constraints on constants."
2399 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2400 let expected_height = 25 * (List.length must_obj + 2) in
2401 let height = if expected_height > 400 then 400 else expected_height in
2402 let scrolled_window =
2403 GBin.scrolled_window ~border_width:10 ~height ~width:600
2404 ~packing:(vbox'#pack ~expand:true ~fill:true ~padding:5) () in
2405 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2406 let obj_constraints =
2408 (function (uri,position,depth) ->
2411 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2414 ~text:(uri ^ " " ^ position)
2415 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2417 None -> uri, position, ref None
2419 let mutable_ref = ref (Some depth') in
2421 GButton.toggle_button ~label:("depth = " ^ string_of_int depth')
2423 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2426 (depthb#connect#toggled
2428 let sel_depth = if depthb#active then Some depth' else None in
2429 mutable_ref := sel_depth
2431 uri, position, mutable_ref
2433 (* Confirm/abort buttons *)
2435 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2437 GButton.button ~label:"Ok"
2438 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2440 GButton.button ~label:"Abort"
2441 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2443 ignore (window#connect#destroy GMain.Main.quit) ;
2444 ignore (cancelb#connect#clicked window#destroy) ;
2446 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
2447 window#set_position `CENTER ;
2449 GMain.Main.main () ;
2451 let chosen_must_rel =
2453 (function (position,ref_depth) -> position,!ref_depth) rel_constraints in
2454 let chosen_must_sort =
2456 (function (position,ref_depth,sort) -> position,!ref_depth,sort)
2459 let chosen_must_obj =
2461 (function (uri,position,ref_depth) -> uri,position,!ref_depth)
2464 (chosen_must_obj,chosen_must_rel,chosen_must_sort),
2466 (*CSC: ???????????????????????? I assume that must and only are the same... *)
2467 Some chosen_must_obj,Some chosen_must_rel,Some chosen_must_sort
2475 let completeSearchPattern () =
2476 let inputt = ((rendering_window ())#inputt : term_editor) in
2477 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2479 let metasenv,expr = inputt#get_metasenv_and_term ~context:[] ~metasenv:[] in
2480 let must = MQueryLevels2.get_constraints expr in
2481 let must',only = refine_constraints must in
2482 let results = MQueryGenerator.searchPattern must' only in
2483 show_query_results results
2486 output_html outputhtml
2487 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2490 let insertQuery () =
2491 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2493 let chosen = ref None in
2496 ~modal:true ~title:"Insert Query (Experts Only)" ~border_width:2 () in
2497 let vbox = GPack.vbox ~packing:window#add () in
2499 GMisc.label ~text:"Insert Query. For Experts Only."
2500 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2501 let scrolled_window =
2502 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
2503 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2504 let input = GEdit.text ~editable:true
2505 ~packing:scrolled_window#add () in
2507 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2509 GButton.button ~label:"Ok"
2510 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2512 GButton.button ~label:"Load from file..."
2513 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2515 GButton.button ~label:"Abort"
2516 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2517 ignore (window#connect#destroy GMain.Main.quit) ;
2518 ignore (cancelb#connect#clicked window#destroy) ;
2520 (okb#connect#clicked
2522 chosen := Some (input#get_chars 0 input#length) ; window#destroy ())) ;
2524 (loadb#connect#clicked
2527 GToolbox.select_file ~title:"Select Query File" ()
2531 let inch = open_in filename in
2532 let rec read_file () =
2534 let line = input_line inch in
2535 line ^ "\n" ^ read_file ()
2539 let text = read_file () in
2540 input#delete_text 0 input#length ;
2541 ignore (input#insert_text text ~pos:0))) ;
2542 window#set_position `CENTER ;
2544 GMain.Main.main () ;
2549 Mqint.execute (MQueryUtil.query_of_text (Lexing.from_string q))
2551 show_query_results results
2554 output_html outputhtml
2555 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2558 let choose_must list_of_must only =
2559 let chosen = ref None in
2560 let user_constraints = ref [] in
2563 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2564 let vbox = GPack.vbox ~packing:window#add () in
2566 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2570 ("You can now specify the genericity of the query. " ^
2571 "The more generic the slower.")
2572 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2574 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2578 "Suggestion: start with faster queries before moving to more generic ones."
2579 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2581 GPack.notebook ~scrollable:true
2582 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2585 let last = List.length list_of_must in
2591 (if !page = 1 then "More generic" else
2592 if !page = last then "More precise" else " ") () in
2593 let expected_height = 25 * (List.length must + 2) in
2594 let height = if expected_height > 400 then 400 else expected_height in
2595 let scrolled_window =
2596 GBin.scrolled_window ~border_width:10 ~height ~width:600
2597 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2599 GList.clist ~columns:2 ~packing:scrolled_window#add
2600 ~titles:["URI" ; "Position"] ()
2604 (function (uri,position) ->
2607 [uri; if position then "MainConclusion" else "Conclusion"]
2609 clist#set_row ~selectable:false n
2612 clist#columns_autosize ()
2615 let label = GMisc.label ~text:"User provided" () in
2617 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2619 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2622 ~text:"Select the constraints that must be satisfied and press OK."
2623 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2624 let expected_height = 25 * (List.length only + 2) in
2625 let height = if expected_height > 400 then 400 else expected_height in
2626 let scrolled_window =
2627 GBin.scrolled_window ~border_width:10 ~height ~width:600
2628 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2630 GList.clist ~columns:2 ~packing:scrolled_window#add
2631 ~selection_mode:`EXTENDED
2632 ~titles:["URI" ; "Position"] ()
2636 (function (uri,position) ->
2639 [uri; if position then "MainConclusion" else "Conclusion"]
2641 clist#set_row ~selectable:true n
2644 clist#columns_autosize () ;
2646 (clist#connect#select_row
2647 (fun ~row ~column ~event ->
2648 user_constraints := (List.nth only row)::!user_constraints)) ;
2650 (clist#connect#unselect_row
2651 (fun ~row ~column ~event ->
2654 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2657 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2659 GButton.button ~label:"Ok"
2660 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2662 GButton.button ~label:"Abort"
2663 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2665 ignore (window#connect#destroy GMain.Main.quit) ;
2666 ignore (cancelb#connect#clicked window#destroy) ;
2668 (okb#connect#clicked
2669 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2670 window#set_position `CENTER ;
2672 GMain.Main.main () ;
2674 None -> raise NoChoice
2676 if n = List.length list_of_must then
2677 (* user provided constraints *)
2680 List.nth list_of_must n
2683 let searchPattern () =
2684 let inputt = ((rendering_window ())#inputt : term_editor) in
2685 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2688 match !ProofEngine.proof with
2689 None -> assert false
2690 | Some (_,metasenv,_,_) -> metasenv
2692 match !ProofEngine.goal with
2695 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2696 let list_of_must,only = MQueryLevels.out_restr metasenv ey ty in
2697 let must = choose_must list_of_must only in
2698 let torigth_restriction (u,b) =
2701 "http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion"
2703 "http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion"
2707 let rigth_must = List.map torigth_restriction must in
2708 let rigth_only = Some (List.map torigth_restriction only) in
2710 MQueryGenerator.searchPattern
2711 (rigth_must,[],[]) (rigth_only,None,None) in
2715 Disambiguate.wrong_xpointer_format_from_wrong_xpointer_format' uri
2718 " <h1>Backward Query: </h1>" ^
2719 " <pre>" ^ get_last_query result ^ "</pre>"
2721 output_html outputhtml html ;
2723 let rec filter_out =
2727 let tl',exc = filter_out tl in
2730 ProofEngine.can_apply
2731 (term_of_cic_textual_parser_uri
2732 (Disambiguate.cic_textual_parser_uri_of_string uri))
2740 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2741 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2748 " <h1>Objects that can actually be applied: </h1> " ^
2749 String.concat "<br>" uris' ^ exc ^
2750 " <h1>Number of false matches: " ^
2751 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2752 " <h1>Number of good matches: " ^
2753 string_of_int (List.length uris') ^ "</h1>"
2755 output_html outputhtml html' ;
2757 user_uri_choice ~title:"Ambiguous input."
2759 "Many lemmas can be successfully applied. Please, choose one:"
2762 inputt#set_term uri' ;
2766 output_html outputhtml
2767 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2770 let choose_selection
2771 (mmlwidget : GMathViewAux.single_selection_math_view) (element : Gdome.element option)
2773 let module G = Gdome in
2774 let rec aux element =
2775 if element#hasAttributeNS
2776 ~namespaceURI:helmns
2777 ~localName:(G.domString "xref")
2779 mmlwidget#set_selection (Some element)
2782 match element#get_parentNode with
2783 None -> assert false
2784 (*CSC: OCAML DIVERGES!
2785 | Some p -> aux (new G.element_of_node p)
2787 | Some p -> aux (new Gdome.element_of_node p)
2789 GdomeInit.DOMCastException _ ->
2790 Printf.printf "******* trying to select above the document root ********\n" ; flush stdout
2795 | None -> mmlwidget#set_selection None
2798 (* STUFF TO BUILD THE GTK INTERFACE *)
2800 (* Stuff for the widget settings *)
2802 let export_to_postscript (output : GMathViewAux.single_selection_math_view) =
2803 let lastdir = ref (Unix.getcwd ()) in
2806 GToolbox.select_file ~title:"Export to PostScript"
2807 ~dir:lastdir ~filename:"screenshot.ps" ()
2811 output#export_to_postscript ~filename:filename ();
2814 let activate_t1 (output : GMathViewAux.single_selection_math_view) button_set_anti_aliasing
2815 button_set_transparency export_to_postscript_menu_item
2818 let is_set = button_t1#active in
2819 output#set_font_manager_type
2820 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2823 button_set_anti_aliasing#misc#set_sensitive true ;
2824 button_set_transparency#misc#set_sensitive true ;
2825 export_to_postscript_menu_item#misc#set_sensitive true ;
2829 button_set_anti_aliasing#misc#set_sensitive false ;
2830 button_set_transparency#misc#set_sensitive false ;
2831 export_to_postscript_menu_item#misc#set_sensitive false ;
2835 let set_anti_aliasing output button_set_anti_aliasing () =
2836 output#set_anti_aliasing button_set_anti_aliasing#active
2839 let set_transparency output button_set_transparency () =
2840 output#set_transparency button_set_transparency#active
2843 let changefont output font_size_spinb () =
2844 output#set_font_size font_size_spinb#value_as_int
2847 let set_log_verbosity output log_verbosity_spinb () =
2848 output#set_log_verbosity log_verbosity_spinb#value_as_int
2851 class settings_window (output : GMathViewAux.single_selection_math_view) sw
2852 export_to_postscript_menu_item selection_changed_callback
2854 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2856 GPack.vbox ~packing:settings_window#add () in
2859 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2860 ~border_width:5 ~packing:vbox#add () in
2862 GButton.toggle_button ~label:"activate t1 fonts"
2863 ~packing:(table#attach ~left:0 ~top:0) () in
2864 let button_set_anti_aliasing =
2865 GButton.toggle_button ~label:"set_anti_aliasing"
2866 ~packing:(table#attach ~left:0 ~top:1) () in
2867 let button_set_transparency =
2868 GButton.toggle_button ~label:"set_transparency"
2869 ~packing:(table#attach ~left:2 ~top:1) () in
2872 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2873 ~border_width:5 ~packing:vbox#add () in
2874 let font_size_label =
2875 GMisc.label ~text:"font size:"
2876 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2877 let font_size_spinb =
2879 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2882 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2883 let log_verbosity_label =
2884 GMisc.label ~text:"log verbosity:"
2885 ~packing:(table#attach ~left:0 ~top:1) () in
2886 let log_verbosity_spinb =
2888 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2891 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2893 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2895 GButton.button ~label:"Close"
2896 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2898 method show = settings_window#show
2900 button_set_anti_aliasing#misc#set_sensitive false ;
2901 button_set_transparency#misc#set_sensitive false ;
2902 (* Signals connection *)
2903 ignore(button_t1#connect#clicked
2904 (activate_t1 output button_set_anti_aliasing
2905 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2906 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2907 ignore(button_set_anti_aliasing#connect#toggled
2908 (set_anti_aliasing output button_set_anti_aliasing));
2909 ignore(button_set_transparency#connect#toggled
2910 (set_transparency output button_set_transparency)) ;
2911 ignore(log_verbosity_spinb#connect#changed
2912 (set_log_verbosity output log_verbosity_spinb)) ;
2913 ignore(closeb#connect#clicked settings_window#misc#hide)
2916 (* Scratch window *)
2918 class scratch_window =
2920 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2922 GPack.vbox ~packing:window#add () in
2924 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2926 GButton.button ~label:"Whd"
2927 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2929 GButton.button ~label:"Reduce"
2930 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2932 GButton.button ~label:"Simpl"
2933 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2934 let scrolled_window =
2935 GBin.scrolled_window ~border_width:10
2936 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2938 GMathViewAux.single_selection_math_view
2939 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2941 method mmlwidget = mmlwidget
2942 method show () = window#misc#hide () ; window#show ()
2944 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2945 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2946 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2947 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2948 ignore(simplb#connect#clicked (simpl_in_scratch self))
2952 let vbox1 = GPack.vbox () in
2954 val mutable proofw_ref = None
2955 val mutable compute_ref = None
2957 Lazy.force self#compute ;
2958 match proofw_ref with
2959 None -> assert false
2960 | Some proofw -> proofw
2961 method content = vbox1
2963 match compute_ref with
2964 None -> assert false
2965 | Some compute -> compute
2969 let scrolled_window1 =
2970 GBin.scrolled_window ~border_width:10
2971 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2973 GMathViewAux.single_selection_math_view ~width:400 ~height:275
2974 ~packing:(scrolled_window1#add) () in
2975 let _ = proofw_ref <- Some proofw in
2977 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2979 GButton.button ~label:"Exact"
2980 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2982 GButton.button ~label:"Intros"
2983 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2985 GButton.button ~label:"Apply"
2986 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2987 let elimintrossimplb =
2988 GButton.button ~label:"ElimIntrosSimpl"
2989 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2991 GButton.button ~label:"ElimType"
2992 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2994 GButton.button ~label:"Whd"
2995 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2997 GButton.button ~label:"Reduce"
2998 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3000 GButton.button ~label:"Simpl"
3001 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
3003 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3005 GButton.button ~label:"Fold_whd"
3006 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3008 GButton.button ~label:"Fold_reduce"
3009 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3011 GButton.button ~label:"Fold_simpl"
3012 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3014 GButton.button ~label:"Cut"
3015 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3017 GButton.button ~label:"Change"
3018 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3020 GButton.button ~label:"Let ... In"
3021 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3023 GButton.button ~label:"Ring"
3024 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3026 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3028 GButton.button ~label:"ClearBody"
3029 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3031 GButton.button ~label:"Clear"
3032 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3034 GButton.button ~label:"Fourier"
3035 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3037 GButton.button ~label:"RewriteSimpl ->"
3038 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3039 let rewritebacksimplb =
3040 GButton.button ~label:"RewriteSimpl <-"
3041 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3043 GButton.button ~label:"Replace"
3044 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3046 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3048 GButton.button ~label:"Reflexivity"
3049 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3051 GButton.button ~label:"Symmetry"
3052 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3054 GButton.button ~label:"Transitivity"
3055 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3057 GButton.button ~label:"Exists"
3058 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3060 GButton.button ~label:"Split"
3061 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3063 GButton.button ~label:"Left"
3064 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3066 GButton.button ~label:"Right"
3067 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3069 GButton.button ~label:"Assumption"
3070 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3072 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3074 GButton.button ~label:"Generalize"
3075 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3077 GButton.button ~label:"Absurd"
3078 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3079 let contradictionb =
3080 GButton.button ~label:"Contradiction"
3081 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3082 let searchpatternb =
3083 GButton.button ~label:"SearchPattern_Apply"
3084 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3086 GButton.button ~label:"Decompose"
3087 ~packing:(hbox7#pack ~expand:false ~fill:false ~padding:5) () in
3089 ignore(exactb#connect#clicked exact) ;
3090 ignore(applyb#connect#clicked apply) ;
3091 ignore(elimintrossimplb#connect#clicked elimintrossimpl) ;
3092 ignore(elimtypeb#connect#clicked elimtype) ;
3093 ignore(whdb#connect#clicked whd) ;
3094 ignore(reduceb#connect#clicked reduce) ;
3095 ignore(simplb#connect#clicked simpl) ;
3096 ignore(foldwhdb#connect#clicked fold_whd) ;
3097 ignore(foldreduceb#connect#clicked fold_reduce) ;
3098 ignore(foldsimplb#connect#clicked fold_simpl) ;
3099 ignore(cutb#connect#clicked cut) ;
3100 ignore(changeb#connect#clicked change) ;
3101 ignore(letinb#connect#clicked letin) ;
3102 ignore(ringb#connect#clicked ring) ;
3103 ignore(clearbodyb#connect#clicked clearbody) ;
3104 ignore(clearb#connect#clicked clear) ;
3105 ignore(fourierb#connect#clicked fourier) ;
3106 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
3107 ignore(rewritebacksimplb#connect#clicked rewritebacksimpl) ;
3108 ignore(replaceb#connect#clicked replace) ;
3109 ignore(reflexivityb#connect#clicked reflexivity) ;
3110 ignore(symmetryb#connect#clicked symmetry) ;
3111 ignore(transitivityb#connect#clicked transitivity) ;
3112 ignore(existsb#connect#clicked exists) ;
3113 ignore(splitb#connect#clicked split) ;
3114 ignore(leftb#connect#clicked left) ;
3115 ignore(rightb#connect#clicked right) ;
3116 ignore(assumptionb#connect#clicked assumption) ;
3117 ignore(generalizeb#connect#clicked generalize) ;
3118 ignore(absurdb#connect#clicked absurd) ;
3119 ignore(contradictionb#connect#clicked contradiction) ;
3120 ignore(introsb#connect#clicked intros) ;
3121 ignore(searchpatternb#connect#clicked searchPattern) ;
3122 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
3123 ignore(decomposeb#connect#clicked decompose) ;
3129 let vbox1 = GPack.vbox () in
3130 let scrolled_window1 =
3131 GBin.scrolled_window ~border_width:10
3132 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
3134 GMathViewAux.single_selection_math_view ~width:400 ~height:275
3135 ~packing:(scrolled_window1#add) () in
3137 method proofw = (assert false : GMathViewAux.single_selection_math_view)
3138 method content = vbox1
3139 method compute = (assert false : unit)
3143 let empty_page = new empty_page;;
3147 val notebook = GPack.notebook ()
3149 val mutable skip_switch_page_event = false
3150 val mutable empty = true
3151 method notebook = notebook
3153 let new_page = new page () in
3155 pages := !pages @ [n,lazy (setgoal n),new_page] ;
3156 notebook#append_page
3157 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
3158 new_page#content#coerce
3159 method remove_all_pages ~skip_switch_page_event:skip =
3161 notebook#remove_page 0 (* let's remove the empty page *)
3163 List.iter (function _ -> notebook#remove_page 0) !pages ;
3165 skip_switch_page_event <- skip
3166 method set_current_page ~may_skip_switch_page_event n =
3167 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
3168 let new_page = notebook#page_num page#content#coerce in
3169 if may_skip_switch_page_event && new_page <> notebook#current_page then
3170 skip_switch_page_event <- true ;
3171 notebook#goto_page new_page
3172 method set_empty_page =
3175 notebook#append_page
3176 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
3177 empty_page#content#coerce
3179 let (_,_,page) = List.nth !pages notebook#current_page in
3183 (notebook#connect#switch_page
3185 let skip = skip_switch_page_event in
3186 skip_switch_page_event <- false ;
3189 let (metano,setgoal,page) = List.nth !pages i in
3190 ProofEngine.goal := Some metano ;
3191 Lazy.force (page#compute) ;
3200 class rendering_window output (notebook : notebook) =
3201 let scratch_window = new scratch_window in
3203 GWindow.window ~title:"MathML viewer" ~border_width:0
3204 ~allow_shrink:false () in
3205 let vbox_for_menu = GPack.vbox ~packing:window#add () in
3207 let handle_box = GBin.handle_box ~border_width:2
3208 ~packing:(vbox_for_menu#pack ~padding:0) () in
3209 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
3210 let factory0 = new GMenu.factory menubar in
3211 let accel_group = factory0#accel_group in
3213 let file_menu = factory0#add_submenu "File" in
3214 let factory1 = new GMenu.factory file_menu ~accel_group in
3215 let export_to_postscript_menu_item =
3218 factory1#add_item "New Block of (Co)Inductive Definitions..."
3219 ~key:GdkKeysyms._B ~callback:new_inductive
3222 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
3225 let reopen_menu_item =
3226 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
3230 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
3231 ignore (factory1#add_separator ()) ;
3233 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
3235 let save_menu_item =
3236 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
3239 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
3240 ignore (!save_set_sensitive false);
3241 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
3242 ignore (!qed_set_sensitive false);
3243 ignore (factory1#add_separator ()) ;
3244 let export_to_postscript_menu_item =
3245 factory1#add_item "Export to PostScript..."
3246 ~callback:(export_to_postscript output) in
3247 ignore (factory1#add_separator ()) ;
3249 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
3250 export_to_postscript_menu_item
3253 let edit_menu = factory0#add_submenu "Edit Current Proof" in
3254 let factory2 = new GMenu.factory edit_menu ~accel_group in
3255 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
3256 let proveit_menu_item =
3257 factory2#add_item "Prove It" ~key:GdkKeysyms._I
3258 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
3260 let focus_menu_item =
3261 factory2#add_item "Focus" ~key:GdkKeysyms._F
3262 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
3265 focus_and_proveit_set_sensitive :=
3267 proveit_menu_item#misc#set_sensitive b ;
3268 focus_menu_item#misc#set_sensitive b
3270 let _ = !focus_and_proveit_set_sensitive false in
3271 (* edit term menu *)
3272 let edit_term_menu = factory0#add_submenu "Edit Term" in
3273 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
3274 let check_menu_item =
3275 factory5#add_item "Check Term" ~key:GdkKeysyms._C
3276 ~callback:(check scratch_window) in
3277 let _ = check_menu_item#misc#set_sensitive false in
3279 let settings_menu = factory0#add_submenu "Search" in
3280 let factory4 = new GMenu.factory settings_menu ~accel_group in
3282 factory4#add_item "Locate..." ~key:GdkKeysyms._T
3284 let searchPattern_menu_item =
3285 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
3286 ~callback:completeSearchPattern in
3287 let _ = searchPattern_menu_item#misc#set_sensitive false in
3288 let show_menu_item =
3289 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
3291 let insert_query_item =
3292 factory4#add_item "Insert Query (Experts Only)..." ~key:GdkKeysyms._U
3293 ~callback:insertQuery in
3295 let settings_menu = factory0#add_submenu "Settings" in
3296 let factory3 = new GMenu.factory settings_menu ~accel_group in
3298 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
3299 ~callback:edit_aliases in
3300 let _ = factory3#add_separator () in
3302 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
3303 ~callback:(function _ -> (settings_window ())#show ()) in
3305 let _ = window#add_accel_group accel_group in
3309 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
3311 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3312 let scrolled_window0 =
3313 GBin.scrolled_window ~border_width:10
3314 ~packing:(vbox#pack ~expand:true ~padding:5) () in
3315 let _ = scrolled_window0#add output#coerce in
3317 GBin.frame ~label:"Insert Term"
3318 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
3319 let scrolled_window1 =
3320 GBin.scrolled_window ~border_width:5
3321 ~packing:frame#add () in
3323 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add ()
3324 ~isnotempty_callback:
3326 check_menu_item#misc#set_sensitive b ;
3327 searchPattern_menu_item#misc#set_sensitive b) in
3329 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3331 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
3333 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
3337 ~source:"<html><body bgColor=\"white\"></body></html>"
3338 ~width:400 ~height: 100
3343 method outputhtml = outputhtml
3344 method inputt = inputt
3345 method output = (output : GMathViewAux.single_selection_math_view)
3346 method notebook = notebook
3347 method show = window#show
3349 notebook#set_empty_page ;
3350 export_to_postscript_menu_item#misc#set_sensitive false ;
3351 check_term := (check_term_in_scratch scratch_window) ;
3353 (* signal handlers here *)
3354 ignore(output#connect#selection_changed
3356 choose_selection output elem ;
3357 !focus_and_proveit_set_sensitive true
3359 ignore (output#connect#click (show_in_show_window_callback output)) ;
3360 let settings_window = new settings_window output scrolled_window0
3361 export_to_postscript_menu_item (choose_selection output) in
3362 set_settings_window settings_window ;
3363 set_outputhtml outputhtml ;
3364 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
3365 Logger.log_callback :=
3366 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
3371 let initialize_everything () =
3372 let module U = Unix in
3373 let output = GMathViewAux.single_selection_math_view ~width:350 ~height:280 () in
3374 let notebook = new notebook in
3375 let rendering_window' = new rendering_window output notebook in
3376 set_rendering_window rendering_window' ;
3377 mml_of_cic_term_ref := mml_of_cic_term ;
3378 rendering_window'#show () ;
3385 Mqint.set_database Mqint.postgres_db ;
3386 Mqint.init postgresqlconnectionstring ;
3388 ignore (GtkMain.Main.init ()) ;
3389 initialize_everything () ;
3390 if !usedb then Mqint.close ();