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 <natile@cs.unibo.it> *)
34 (******************************************************************************)
37 (* CSC: quick fix: a function from [uri#xpointer(path)] to [uri#path] *)
38 let wrong_xpointer_format_from_wrong_xpointer_format' uri =
40 let index_sharp = String.index uri '#' in
41 let index_rest = index_sharp + 10 in
42 let baseuri = String.sub uri 0 index_sharp in
43 let rest = String.sub uri index_rest (String.length uri - index_rest - 1) in
48 (* GLOBAL CONSTANTS *)
50 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
51 let xlinkns = Gdome.domString "http://www.w3.org/1999/xlink";;
55 " <body bgColor=\"white\">"
63 let prooffile = "/public/sacerdot/currentproof";;
64 let prooffiletype = "/public/sacerdot/currentprooftype";;
67 let prooffile = "/public/sacerdot/currentproof";;
68 let prooffiletype = "/public/sacerdot/currentprooftype";;
72 let prooffile = "/public/natile/currentproof";;
73 let prooffiletype = "/public/natile/currentprooftype";;
77 let prooffile = "//miohelm/tmp/currentproof";;
78 let prooffiletype = "/home/tassi/miohelm/tmp/currentprooftype";;
82 let prooffile = "/home/galata/miohelm/currentproof";;
83 let prooffiletype = "/home/galata/miohelm/currentprooftype";;
86 (*CSC: the getter should handle the innertypes, not the FS *)
88 let innertypesfile = "/public/sacerdot/innertypes";;
89 let constanttypefile = "/public/sacerdot/constanttype";;
92 let innertypesfile = "/public/sacerdot/innertypes";;
93 let constanttypefile = "/public/sacerdot/constanttype";;
97 let innertypesfile = "/public/natile/innertypes";;
98 let constanttypefile = "/public/natile/constanttype";;
102 let innertypesfile = "/home/tassi/miohelm/tmp/innertypes";;
103 let constanttypefile = "/home/tassi/miohelm/tmp/constanttype";;
107 let innertypesfile = "/home/galata/miohelm/innertypes";;
108 let constanttypefile = "/home/galata/miohelm/constanttype";;
111 let empty_id_to_uris = ([],function _ -> None);;
114 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
116 let htmlheader_and_content = ref htmlheader;;
118 let current_cic_infos = ref None;;
119 let current_goal_infos = ref None;;
120 let current_scratch_infos = ref None;;
122 let id_to_uris = ref empty_id_to_uris;;
124 let check_term = ref (fun _ _ _ -> assert false);;
125 let mml_of_cic_term_ref = ref (fun _ _ -> assert false);;
127 exception RenderingWindowsNotInitialized;;
129 let set_rendering_window,rendering_window =
130 let rendering_window_ref = ref None in
131 (function rw -> rendering_window_ref := Some rw),
133 match !rendering_window_ref with
134 None -> raise RenderingWindowsNotInitialized
139 exception SettingsWindowsNotInitialized;;
141 let set_settings_window,settings_window =
142 let settings_window_ref = ref None in
143 (function rw -> settings_window_ref := Some rw),
145 match !settings_window_ref with
146 None -> raise SettingsWindowsNotInitialized
151 exception OutputHtmlNotInitialized;;
153 let set_outputhtml,outputhtml =
154 let outputhtml_ref = ref None in
155 (function rw -> outputhtml_ref := Some rw),
157 match !outputhtml_ref with
158 None -> raise OutputHtmlNotInitialized
159 | Some outputhtml -> outputhtml
163 exception QedSetSensitiveNotInitialized;;
164 let qed_set_sensitive =
165 ref (function _ -> raise QedSetSensitiveNotInitialized)
168 exception SaveSetSensitiveNotInitialized;;
169 let save_set_sensitive =
170 ref (function _ -> raise SaveSetSensitiveNotInitialized)
173 (* COMMAND LINE OPTIONS *)
179 "-nodb", Arg.Clear usedb, "disable use of MathQL DB"
182 Arg.parse argspec ignore ""
184 (* A WIDGET TO ENTER CIC TERMS *)
186 class term_editor ?packing ?width ?height ?isnotempty_callback () =
187 let input = GEdit.text ~editable:true ?width ?height ?packing () in
189 match isnotempty_callback with
192 ignore(input#connect#changed (function () -> callback (input#length > 0)))
195 method coerce = input#coerce
197 input#delete_text 0 input#length
198 (* CSC: txt is now a string, but should be of type Cic.term *)
199 method set_term txt =
201 ignore ((input#insert_text txt) ~pos:0)
202 (* CSC: this method should disappear *)
203 method get_as_string =
204 input#get_chars 0 input#length
205 method get_term ~context ~metasenv =
206 let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
207 CicTextualParserContext.main ~context ~metasenv CicTextualLexer.token lexbuf
213 exception IllFormedUri of string;;
215 let cic_textual_parser_uri_of_string uri' =
218 if String.sub uri' (String.length uri' - 4) 4 = ".con" then
219 CicTextualParser0.ConUri (UriManager.uri_of_string uri')
221 if String.sub uri' (String.length uri' - 4) 4 = ".var" then
222 CicTextualParser0.VarUri (UriManager.uri_of_string uri')
226 let uri'',typeno = CicTextualLexer.indtyuri_of_uri uri' in
227 CicTextualParser0.IndTyUri (uri'',typeno)
230 (* Constructor of an Inductive Type *)
231 let uri'',typeno,consno =
232 CicTextualLexer.indconuri_of_uri uri'
234 CicTextualParser0.IndConUri (uri'',typeno,consno)
237 _ -> raise (IllFormedUri uri')
240 let term_of_cic_textual_parser_uri uri =
241 let module C = Cic in
242 let module CTP = CicTextualParser0 in
244 CTP.ConUri uri -> C.Const (uri,[])
245 | CTP.VarUri uri -> C.Var (uri,[])
246 | CTP.IndTyUri (uri,tyno) -> C.MutInd (uri,tyno,[])
247 | CTP.IndConUri (uri,tyno,consno) -> C.MutConstruct (uri,tyno,consno,[])
250 let string_of_cic_textual_parser_uri uri =
251 let module C = Cic in
252 let module CTP = CicTextualParser0 in
255 CTP.ConUri uri -> UriManager.string_of_uri uri
256 | CTP.VarUri uri -> UriManager.string_of_uri uri
257 | CTP.IndTyUri (uri,tyno) ->
258 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1)
259 | CTP.IndConUri (uri,tyno,consno) ->
260 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (tyno + 1) ^ "/" ^
263 (* 4 = String.length "cic:" *)
264 String.sub uri' 4 (String.length uri' - 4)
267 let output_html outputhtml msg =
268 htmlheader_and_content := !htmlheader_and_content ^ msg ;
269 outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
270 outputhtml#set_topline (-1)
273 (* UTILITY FUNCTIONS TO DISAMBIGUATE AN URI *)
277 let check_window outputhtml uris =
280 ~width:800 ~modal:true ~title:"Check" ~border_width:2 () in
282 GPack.notebook ~scrollable:true ~packing:window#add () in
287 let scrolled_window =
288 GBin.scrolled_window ~border_width:10
290 (notebook#append_page ~tab_label:((GMisc.label ~text:uri ())#coerce))
296 ~packing:scrolled_window#add ~width:400 ~height:280 () in
299 term_of_cic_textual_parser_uri (cic_textual_parser_uri_of_string uri)
301 (Cic.Cast (term, CicTypeChecker.type_of_aux' [] [] term))
304 let mml = !mml_of_cic_term_ref 111 expr in
305 prerr_endline ("### " ^ CicPp.ppterm expr) ;
306 mmlwidget#load_tree ~dom:mml
309 output_html outputhtml
310 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
315 (notebook#connect#switch_page
316 (function i -> Lazy.force (List.nth render_terms i)))
322 interactive_user_uri_choice ~selection_mode ?(ok="Ok") ~title ~msg uris
324 let choices = ref [] in
325 let chosen = ref false in
327 GWindow.dialog ~modal:true ~title ~width:600 () in
329 GMisc.label ~text:msg
330 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
331 let scrolled_window =
332 GBin.scrolled_window ~border_width:10
333 ~packing:(window#vbox#pack ~expand:true ~fill:true ~padding:5) () in
335 let expected_height = 18 * List.length uris in
336 let height = if expected_height > 400 then 400 else expected_height in
337 GList.clist ~columns:1 ~packing:scrolled_window#add
338 ~height ~selection_mode () in
339 let _ = List.map (function x -> clist#append [x]) uris in
341 GPack.hbox ~border_width:0
342 ~packing:(window#vbox#pack ~expand:false ~fill:false ~padding:5) () in
344 GMisc.label ~text:"None of the above. Try this one:"
345 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
347 GEdit.entry ~editable:true
348 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
350 GPack.hbox ~border_width:0 ~packing:window#action_area#add () in
352 GButton.button ~label:ok
353 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
354 let _ = okb#misc#set_sensitive false in
356 GButton.button ~label:"Check"
357 ~packing:(hbox#pack ~padding:5) () in
358 let _ = checkb#misc#set_sensitive false in
360 GButton.button ~label:"Abort"
361 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
363 let check_callback () =
364 assert (List.length !choices > 0) ;
365 check_window (outputhtml ()) !choices
367 ignore (window#connect#destroy GMain.Main.quit) ;
368 ignore (cancelb#connect#clicked window#destroy) ;
370 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
371 ignore (checkb#connect#clicked check_callback) ;
373 (clist#connect#select_row
374 (fun ~row ~column ~event ->
375 checkb#misc#set_sensitive true ;
376 okb#misc#set_sensitive true ;
377 choices := (List.nth uris row)::!choices)) ;
379 (clist#connect#unselect_row
380 (fun ~row ~column ~event ->
382 List.filter (function uri -> uri != (List.nth uris row)) !choices)) ;
384 (manual_input#connect#changed
386 if manual_input#text = "" then
389 checkb#misc#set_sensitive false ;
390 okb#misc#set_sensitive false ;
391 clist#misc#set_sensitive true
395 choices := [manual_input#text] ;
396 clist#unselect_all () ;
397 checkb#misc#set_sensitive true ;
398 okb#misc#set_sensitive true ;
399 clist#misc#set_sensitive false
401 window#set_position `CENTER ;
404 if !chosen && List.length !choices > 0 then
410 let interactive_interpretation_choice interpretations =
411 let chosen = ref None in
414 ~modal:true ~title:"Ambiguous well-typed input." ~border_width:2 () in
415 let vbox = GPack.vbox ~packing:window#add () in
419 ("Ambiguous input since there are many well-typed interpretations." ^
420 " Please, choose one of them.")
421 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
423 GPack.notebook ~scrollable:true
424 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
427 (function interpretation ->
429 let expected_height = 18 * List.length interpretation in
430 let height = if expected_height > 400 then 400 else expected_height in
431 GList.clist ~columns:2 ~packing:notebook#append_page ~height
432 ~titles:["id" ; "URI"] ()
436 (function (id,uri) ->
437 let n = clist#append [id;uri] in
438 clist#set_row ~selectable:false n
441 clist#columns_autosize ()
444 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
446 GButton.button ~label:"Ok"
447 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
449 GButton.button ~label:"Abort"
450 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
452 ignore (window#connect#destroy GMain.Main.quit) ;
453 ignore (cancelb#connect#clicked window#destroy) ;
456 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
457 window#set_position `CENTER ;
461 None -> raise NoChoice
468 (* CSC: IMPERATIVE AND NOT VERY CLEAN, TO GET THE LAST ISSUED QUERY *)
470 let query = ref "" in
471 MQueryGenerator.set_confirm_query
472 (function q -> query := MQueryUtil.text_of_query q ; true) ;
473 function result -> !query ^ " <h1>Result:</h1> " ^ MQueryUtil.text_of_result result "<br>"
476 let domImpl = Gdome.domImplementation ();;
478 let parseStyle name =
480 domImpl#createDocumentFromURI
482 ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
484 ~uri:("styles/" ^ name) ()
486 Gdome_xslt.processStylesheet style
489 let d_c = parseStyle "drop_coercions.xsl";;
490 let tc1 = parseStyle "objtheorycontent.xsl";;
491 let hc2 = parseStyle "content_to_html.xsl";;
492 let l = parseStyle "link.xsl";;
494 let c1 = parseStyle "rootcontent.xsl";;
495 let g = parseStyle "genmmlid.xsl";;
496 let c2 = parseStyle "annotatedpres.xsl";;
499 let getterURL = Configuration.getter_url;;
500 let processorURL = Configuration.processor_url;;
502 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
503 let mml_args ~explode_all =
504 ("explodeall",(if explode_all then "true()" else "false()"))::
505 ["processorURL", "'" ^ processorURL ^ "'" ;
506 "getterURL", "'" ^ getterURL ^ "'" ;
507 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
508 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
509 "UNICODEvsSYMBOL", "'symbol'" ;
510 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
511 "encoding", "'iso-8859-1'" ;
512 "media-type", "'text/html'" ;
513 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
514 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
515 "naturalLanguage", "'yes'" ;
516 "annotations", "'no'" ;
517 "URLs_or_URIs", "'URIs'" ;
518 "topurl", "'http://phd.cs.unibo.it/helm'" ;
519 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
522 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
524 ["processorURL", "'" ^ processorURL ^ "'" ;
525 "getterURL", "'" ^ getterURL ^ "'" ;
526 "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
527 "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
528 "UNICODEvsSYMBOL", "'symbol'" ;
529 "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
530 "encoding", "'iso-8859-1'" ;
531 "media-type", "'text/html'" ;
532 "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
533 "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
534 "naturalLanguage", "'no'" ;
535 "annotations", "'no'" ;
536 "explodeall", "true()" ;
537 "URLs_or_URIs", "'URIs'" ;
538 "topurl", "'http://phd.cs.unibo.it/helm'" ;
539 "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
542 let parse_file filename =
543 let inch = open_in filename in
544 let rec read_lines () =
546 let line = input_line inch in
554 let applyStylesheets input styles args =
555 List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
560 mml_of_cic_object ~explode_all uri annobj ids_to_inner_sorts ids_to_inner_types
562 (*CSC: ????????????????? *)
564 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:true
568 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
569 ~ask_dtd_to_the_getter:true
573 None -> Xml2Gdome.document_of_xml domImpl xml
575 Xml.pp xml (Some constanttypefile) ;
576 Xml2Gdome.document_of_xml domImpl bodyxml'
578 (*CSC: We save the innertypes to disk so that we can retrieve them in the *)
579 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
581 Xml.pp xmlinnertypes (Some innertypesfile) ;
582 let output = applyStylesheets input mml_styles (mml_args ~explode_all) in
587 save_object_to_disk uri annobj ids_to_inner_sorts ids_to_inner_types pathname
590 let struri = UriManager.string_of_uri uri in
591 let idx = (String.rindex struri '/') + 1 in
592 String.sub struri idx (String.length struri - idx)
594 let path = pathname ^ "/" ^ name in
596 Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
600 Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
601 ~ask_dtd_to_the_getter:false
604 let innertypesuri = UriManager.innertypesuri_of_uri uri in
605 Xml.pp ~quiet:true xmlinnertypes (Some (path ^ ".types.xml")) ;
606 Getter.register innertypesuri
607 (Configuration.annotations_url ^
608 Str.replace_first (Str.regexp "^cic:") ""
609 (UriManager.string_of_uri innertypesuri) ^ ".xml"
611 (* constant type / variable / mutual inductive types definition *)
612 Xml.pp ~quiet:true xml (Some (path ^ ".xml")) ;
614 (Configuration.annotations_url ^
615 Str.replace_first (Str.regexp "^cic:") ""
616 (UriManager.string_of_uri uri) ^ ".xml"
623 match UriManager.bodyuri_of_uri uri with
625 | Some bodyuri -> bodyuri
627 Xml.pp ~quiet:true bodyxml' (Some (path ^ ".body.xml")) ;
628 Getter.register bodyuri
629 (Configuration.annotations_url ^
630 Str.replace_first (Str.regexp "^cic:") ""
631 (UriManager.string_of_uri bodyuri) ^ ".xml"
638 exception RefreshSequentException of exn;;
639 exception RefreshProofException of exn;;
641 let refresh_proof (output : GMathView.math_view) =
643 let uri,currentproof =
644 match !ProofEngine.proof with
646 | Some (uri,metasenv,bo,ty) ->
647 !qed_set_sensitive (List.length metasenv = 0) ;
648 (*CSC: Wrong: [] is just plainly wrong *)
649 uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty, []))
652 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
653 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
655 Cic2acic.acic_object_of_cic_object currentproof
658 mml_of_cic_object ~explode_all:true uri acic ids_to_inner_sorts
661 output#load_tree mml ;
663 Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
666 match !ProofEngine.proof with
668 | Some (uri,metasenv,bo,ty) ->
669 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty,[]))) ; flush stderr ;
670 raise (RefreshProofException e)
673 let refresh_sequent ?(empty_notebook=true) notebook =
675 match !ProofEngine.goal with
677 if empty_notebook then
679 notebook#remove_all_pages ~skip_switch_page_event:false ;
680 notebook#set_empty_page
683 notebook#proofw#unload
686 match !ProofEngine.proof with
688 | Some (_,metasenv,_,_) -> metasenv
690 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
691 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
692 SequentPp.XmlPp.print_sequent metasenv currentsequent
694 let regenerate_notebook () =
695 let skip_switch_page_event =
697 (m,_,_)::_ when m = metano -> false
700 notebook#remove_all_pages ~skip_switch_page_event ;
701 List.iter (function (m,_,_) -> notebook#add_page m) metasenv ;
703 if empty_notebook then
705 regenerate_notebook () ;
706 notebook#set_current_page ~may_skip_switch_page_event:false metano
710 let sequent_doc = Xml2Gdome.document_of_xml domImpl sequent_gdome in
712 applyStylesheets sequent_doc sequent_styles sequent_args
714 notebook#set_current_page ~may_skip_switch_page_event:true metano;
715 notebook#proofw#load_tree ~dom:sequent_mml
717 current_goal_infos :=
718 Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
722 match !ProofEngine.goal with
727 match !ProofEngine.proof with
729 | Some (_,metasenv,_,_) -> metasenv
732 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
733 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
734 raise (RefreshSequentException e)
735 with Not_found -> prerr_endline ("Offending sequent " ^ string_of_int metano ^ " unkown."); raise (RefreshSequentException e)
739 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
740 ~name:"/home/galata/miohelm/guruguru1" ~indent:true ()) ;
743 let mml_of_cic_term metano term =
745 match !ProofEngine.proof with
747 | Some (_,metasenv,_,_) -> metasenv
750 match !ProofEngine.goal with
753 let (_,canonical_context,_) =
754 List.find (function (m,_,_) -> m=metano) metasenv
758 let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
759 SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
762 Xml2Gdome.document_of_xml domImpl sequent_gdome
765 applyStylesheets sequent_doc sequent_styles sequent_args ;
767 current_scratch_infos :=
768 Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
772 exception OpenConjecturesStillThere;;
773 exception WrongProof;;
775 let pathname_of_annuri uristring =
776 Configuration.annotations_dir ^
777 Str.replace_first (Str.regexp "^cic:") "" uristring
780 let make_dirs dirpath =
781 ignore (Unix.system ("mkdir -p " ^ dirpath))
784 let save_obj uri obj =
786 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
787 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
789 Cic2acic.acic_object_of_cic_object obj
791 (* let's save the theorem and register it to the getter *)
792 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
794 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
799 match !ProofEngine.proof with
801 | Some (uri,[],bo,ty) ->
803 CicReduction.are_convertible []
804 (CicTypeChecker.type_of_aux' [] [] bo) ty
807 (*CSC: Wrong: [] is just plainly wrong *)
808 let proof = Cic.Constant (UriManager.name_of_uri uri,Some bo,ty,[]) in
810 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
811 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
813 Cic2acic.acic_object_of_cic_object proof
816 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
819 ((rendering_window ())#output : GMathView.math_view)#load_tree mml ;
820 !qed_set_sensitive false ;
821 (* let's save the theorem and register it to the getter *)
822 let pathname = pathname_of_annuri (UriManager.buri_of_uri uri) in
824 save_object_to_disk uri acic ids_to_inner_sorts ids_to_inner_types
828 (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
833 | _ -> raise OpenConjecturesStillThere
837 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
838 match !ProofEngine.proof with
840 | Some (uri, metasenv, bo, ty) ->
842 (*CSC: Wrong: [] is just plainly wrong *)
843 Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty,[])
845 let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
846 Cic2acic.acic_object_of_cic_object currentproof
850 Cic2Xml.print_object uri ~ids_to_inner_sorts
851 ~ask_dtd_to_the_getter:true acurrentproof
853 xml,Some bodyxml -> xml,bodyxml
854 | _,None -> assert false
856 Xml.pp ~quiet:true xml (Some prooffiletype) ;
857 output_html outputhtml
858 ("<h1 color=\"Green\">Current proof type saved to " ^
859 prooffiletype ^ "</h1>") ;
860 Xml.pp ~quiet:true bodyxml (Some prooffile) ;
861 output_html outputhtml
862 ("<h1 color=\"Green\">Current proof body saved to " ^
866 (* Used to typecheck the loaded proofs *)
867 let typecheck_loaded_proof metasenv bo ty =
868 let module T = CicTypeChecker in
871 (fun metasenv ((_,context,ty) as conj) ->
872 ignore (T.type_of_aux' metasenv context ty) ;
875 ignore (T.type_of_aux' metasenv [] ty) ;
876 ignore (T.type_of_aux' metasenv [] bo)
880 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
881 let output = ((rendering_window ())#output : GMathView.math_view) in
882 let notebook = (rendering_window ())#notebook in
885 GToolbox.input_string ~title:"Load Unfinished Proof" ~text:"/dummy.con"
888 None -> raise NoChoice
890 let uri = UriManager.uri_of_string ("cic:" ^ uri0) in
891 match CicParser.obj_of_xml prooffiletype (Some prooffile) with
892 Cic.CurrentProof (_,metasenv,bo,ty,_) ->
893 typecheck_loaded_proof metasenv bo ty ;
895 Some (uri, metasenv, bo, ty) ;
899 | (metano,_,_)::_ -> Some metano
901 refresh_proof output ;
902 refresh_sequent notebook ;
903 output_html outputhtml
904 ("<h1 color=\"Green\">Current proof type loaded from " ^
905 prooffiletype ^ "</h1>") ;
906 output_html outputhtml
907 ("<h1 color=\"Green\">Current proof body loaded from " ^
908 prooffile ^ "</h1>") ;
909 !save_set_sensitive true
912 RefreshSequentException e ->
913 output_html outputhtml
914 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
915 "sequent: " ^ Printexc.to_string e ^ "</h1>")
916 | RefreshProofException e ->
917 output_html outputhtml
918 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
919 "proof: " ^ Printexc.to_string e ^ "</h1>")
921 output_html outputhtml
922 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
925 let edit_aliases () =
926 let chosen = ref false in
929 ~width:400 ~modal:true ~title:"Edit Aliases..." ~border_width:2 () in
931 GPack.vbox ~border_width:0 ~packing:window#add () in
932 let scrolled_window =
933 GBin.scrolled_window ~border_width:10
934 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
935 let input = GEdit.text ~editable:true ~width:400 ~height:100
936 ~packing:scrolled_window#add () in
938 GPack.hbox ~border_width:0
939 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
941 GButton.button ~label:"Ok"
942 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
944 GButton.button ~label:"Cancel"
945 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
946 ignore (window#connect#destroy GMain.Main.quit) ;
947 ignore (cancelb#connect#clicked window#destroy) ;
949 (okb#connect#clicked (function () -> chosen := true ; window#destroy ())) ;
950 let dom,resolve_id = !id_to_uris in
952 (input#insert_text ~pos:0
957 match resolve_id v with
962 (string_of_cic_textual_parser_uri uri)
968 let inputtext = input#get_chars 0 input#length in
970 let alfa = "[a-zA-Z_-]" in
971 let digit = "[0-9]" in
972 let ident = alfa ^ "\(" ^ alfa ^ "\|" ^ digit ^ "\)*" in
973 let blanks = "\( \|\t\|\n\)+" in
974 let nonblanks = "[^ \t\n]+" in
975 let uri = "/\(" ^ ident ^ "/\)*" ^ nonblanks in (* not very strict check *)
977 ("alias" ^ blanks ^ "\(" ^ ident ^ "\)" ^ blanks ^ "\(" ^ uri ^ "\)")
981 let n' = Str.search_forward regexpr inputtext n in
982 let id = Str.matched_group 2 inputtext in
984 cic_textual_parser_uri_of_string
985 ("cic:" ^ (Str.matched_group 5 inputtext))
987 let dom,resolve_id = aux (n' + 1) in
988 if List.mem id dom then
992 (function id' -> if id = id' then Some uri else resolve_id id')
994 Not_found -> empty_id_to_uris
998 id_to_uris := dom,resolve_id
1002 let module L = LogicalOperations in
1003 let module G = Gdome in
1004 let notebook = (rendering_window ())#notebook in
1005 let output = (rendering_window ())#output in
1006 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1007 match (rendering_window ())#output#get_selection with
1010 ((node : Gdome.element)#getAttributeNS
1011 (*CSC: OCAML DIVERGE
1012 ((element : G.element)#getAttributeNS
1014 ~namespaceURI:helmns
1015 ~localName:(G.domString "xref"))#to_string
1017 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1021 match !current_cic_infos with
1022 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1024 L.to_sequent id ids_to_terms ids_to_father_ids ;
1025 refresh_proof output ;
1026 refresh_sequent notebook
1027 | None -> assert false (* "ERROR: No current term!!!" *)
1029 RefreshSequentException e ->
1030 output_html outputhtml
1031 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1032 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1033 | RefreshProofException e ->
1034 output_html outputhtml
1035 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1036 "proof: " ^ Printexc.to_string e ^ "</h1>")
1038 output_html outputhtml
1039 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1041 | None -> assert false (* "ERROR: No selection!!!" *)
1045 let module L = LogicalOperations in
1046 let module G = Gdome in
1047 let notebook = (rendering_window ())#notebook in
1048 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1049 match (rendering_window ())#output#get_selection with
1052 ((node : Gdome.element)#getAttributeNS
1053 (*CSC: OCAML DIVERGE
1054 ((element : G.element)#getAttributeNS
1056 ~namespaceURI:helmns
1057 ~localName:(G.domString "xref"))#to_string
1059 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
1063 match !current_cic_infos with
1064 Some (ids_to_terms, ids_to_father_ids, _, _) ->
1066 L.focus id ids_to_terms ids_to_father_ids ;
1067 refresh_sequent notebook
1068 | None -> assert false (* "ERROR: No current term!!!" *)
1070 RefreshSequentException e ->
1071 output_html outputhtml
1072 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1073 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1074 | RefreshProofException e ->
1075 output_html outputhtml
1076 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1077 "proof: " ^ Printexc.to_string e ^ "</h1>")
1079 output_html outputhtml
1080 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1082 | None -> assert false (* "ERROR: No selection!!!" *)
1085 exception NoPrevGoal;;
1086 exception NoNextGoal;;
1088 let setgoal metano =
1089 let module L = LogicalOperations in
1090 let module G = Gdome in
1091 let notebook = (rendering_window ())#notebook in
1092 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1094 match !ProofEngine.proof with
1095 None -> assert false
1096 | Some (_,metasenv,_,_) -> metasenv
1099 refresh_sequent ~empty_notebook:false notebook
1101 RefreshSequentException e ->
1102 output_html outputhtml
1103 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1104 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1106 output_html outputhtml
1107 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1111 show_in_show_window_obj, show_in_show_window_uri, show_in_show_window_callback
1114 GWindow.window ~width:800 ~border_width:2 () in
1115 let scrolled_window =
1116 GBin.scrolled_window ~border_width:10 ~packing:window#add () in
1118 GMathView.math_view ~packing:scrolled_window#add ~width:600 ~height:400 () in
1119 let _ = window#event#connect#delete (fun _ -> window#misc#hide () ; true ) in
1120 let href = Gdome.domString "href" in
1121 let show_in_show_window_obj uri obj =
1122 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1125 (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
1126 ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
1128 Cic2acic.acic_object_of_cic_object obj
1131 mml_of_cic_object ~explode_all:false uri acic ids_to_inner_sorts
1134 window#set_title (UriManager.string_of_uri uri) ;
1135 window#misc#hide () ; window#show () ;
1136 mmlwidget#load_tree mml ;
1139 output_html outputhtml
1140 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1142 let show_in_show_window_uri uri =
1143 let obj = CicEnvironment.get_obj uri in
1144 show_in_show_window_obj uri obj
1146 let show_in_show_window_callback mmlwidget (n : Gdome.element) =
1147 if n#hasAttributeNS ~namespaceURI:xlinkns ~localName:href then
1149 (n#getAttributeNS ~namespaceURI:xlinkns ~localName:href)#to_string
1151 show_in_show_window_uri (UriManager.uri_of_string uri)
1153 if mmlwidget#get_action <> None then
1154 mmlwidget#action_toggle
1157 mmlwidget#connect#clicked (show_in_show_window_callback mmlwidget)
1159 show_in_show_window_obj, show_in_show_window_uri,
1160 show_in_show_window_callback
1163 exception NoObjectsLocated;;
1165 let user_uri_choice ~title ~msg uris =
1168 [] -> raise NoObjectsLocated
1172 interactive_user_uri_choice ~selection_mode:`SINGLE ~title ~msg uris
1177 String.sub uri 4 (String.length uri - 4)
1180 let locate_callback id =
1181 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1182 let result = MQueryGenerator.locate id in
1185 (function uri,_ -> wrong_xpointer_format_from_wrong_xpointer_format' uri)
1188 (" <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>")
1190 output_html outputhtml html ;
1191 user_uri_choice ~title:"Ambiguous input."
1193 ("Ambiguous input \"" ^ id ^
1194 "\". Please, choose one interpetation:")
1199 let inputt = ((rendering_window ())#inputt : term_editor) in
1200 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1203 GToolbox.input_string ~title:"Locate" "Enter an identifier to locate:"
1205 None -> raise NoChoice
1207 let uri = locate_callback input in
1211 output_html outputhtml
1212 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
1215 let input_or_locate_uri ~title =
1216 let uri = ref None in
1219 ~width:400 ~modal:true ~title ~border_width:2 () in
1220 let vbox = GPack.vbox ~packing:window#add () in
1222 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1224 GMisc.label ~text:"Enter a valid URI:" ~packing:(hbox1#pack ~padding:5) () in
1226 GEdit.entry ~editable:true
1227 ~packing:(hbox1#pack ~expand:true ~fill:true ~padding:5) () in
1229 GButton.button ~label:"Check"
1230 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1231 let _ = checkb#misc#set_sensitive false in
1233 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1235 GMisc.label ~text:"You can also enter an indentifier to locate:"
1236 ~packing:(hbox2#pack ~padding:5) () in
1238 GEdit.entry ~editable:true
1239 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1241 GButton.button ~label:"Locate"
1242 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1243 let _ = locateb#misc#set_sensitive false in
1245 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1247 GButton.button ~label:"Ok"
1248 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1249 let _ = okb#misc#set_sensitive false in
1251 GButton.button ~label:"Cancel"
1252 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) ()
1254 ignore (window#connect#destroy GMain.Main.quit) ;
1256 (cancelb#connect#clicked (function () -> uri := None ; window#destroy ())) ;
1257 let check_callback () =
1258 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1259 let uri = "cic:" ^ manual_input#text in
1261 ignore (Getter.resolve (UriManager.uri_of_string uri)) ;
1262 output_html outputhtml "<h1 color=\"Green\">OK</h1>" ;
1265 Getter.Unresolved ->
1266 output_html outputhtml
1267 ("<h1 color=\"Red\">URI " ^ uri ^
1268 " does not correspond to any object.</h1>") ;
1270 | UriManager.IllFormedUri _ ->
1271 output_html outputhtml
1272 ("<h1 color=\"Red\">URI " ^ uri ^ " is not well-formed.</h1>") ;
1275 output_html outputhtml
1276 ("<h1 color=\"Red\">" ^ Printexc.to_string e ^ "</h1>") ;
1280 (okb#connect#clicked
1282 if check_callback () then
1284 uri := Some manual_input#text ;
1288 ignore (checkb#connect#clicked (function () -> ignore (check_callback ()))) ;
1290 (manual_input#connect#changed
1292 if manual_input#text = "" then
1294 checkb#misc#set_sensitive false ;
1295 okb#misc#set_sensitive false
1299 checkb#misc#set_sensitive true ;
1300 okb#misc#set_sensitive true
1303 (locate_input#connect#changed
1304 (fun _ -> locateb#misc#set_sensitive (locate_input#text <> ""))) ;
1306 (locateb#connect#clicked
1308 let id = locate_input#text in
1309 manual_input#set_text (locate_callback id) ;
1310 locate_input#delete_text 0 (String.length id)
1313 GMain.Main.main () ;
1315 None -> raise NoChoice
1316 | Some uri -> UriManager.uri_of_string ("cic:" ^ uri)
1319 let locate_one_id id =
1320 let result = MQueryGenerator.locate id in
1324 wrong_xpointer_format_from_wrong_xpointer_format' uri
1326 let html= " <h1>Locate Query: </h1><pre>" ^ get_last_query result ^ "</pre>" in
1327 output_html (rendering_window ())#outputhtml html ;
1331 [UriManager.string_of_uri
1332 (input_or_locate_uri ~title:("URI matching \"" ^ id ^ "\" unknown."))]
1335 interactive_user_uri_choice
1336 ~selection_mode:`EXTENDED
1337 ~ok:"Try every selection."
1338 ~title:"Ambiguous input."
1340 ("Ambiguous input \"" ^ id ^
1341 "\". Please, choose one or more interpretations:")
1344 List.map cic_textual_parser_uri_of_string uris'
1347 exception ThereDoesNotExistAnyWellTypedInterpretationOfTheInput;;
1348 exception AmbiguousInput;;
1350 let disambiguate_input context metasenv dom mk_metasenv_and_expr =
1351 let known_ids,resolve_id = !id_to_uris in
1357 if List.mem he known_ids then filter tl else he::(filter tl)
1361 (* for each id in dom' we get the list of uris associated to it *)
1362 let list_of_uris = List.map locate_one_id dom' in
1363 (* and now we compute the list of all possible assignments from id to uris *)
1365 let rec aux ids list_of_uris =
1366 match ids,list_of_uris with
1367 [],[] -> [resolve_id]
1368 | id::idtl,uris::uristl ->
1369 let resolves = aux idtl uristl in
1375 function id' -> if id = id' then Some uri else f id'
1379 | _,_ -> assert false
1381 aux dom' list_of_uris
1383 let tests_no = List.length resolve_ids in
1384 if tests_no > 1 then
1385 output_html (outputhtml ())
1386 ("<h1>Disambiguation phase started: " ^
1387 string_of_int (List.length resolve_ids) ^ " cases will be tried.") ;
1388 (* now we select only the ones that generates well-typed terms *)
1394 let metasenv',expr = mk_metasenv_and_expr resolve in
1396 (*CSC: Bug here: we do not try to typecheck also the metasenv' *)
1398 (CicTypeChecker.type_of_aux' metasenv context expr) ;
1399 resolve::(filter tl)
1406 match resolve_ids' with
1407 [] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
1408 | [resolve_id] -> resolve_id
1412 (function resolve ->
1416 match resolve id with
1417 None -> assert false
1420 CicTextualParser0.ConUri uri
1421 | CicTextualParser0.VarUri uri ->
1422 UriManager.string_of_uri uri
1423 | CicTextualParser0.IndTyUri (uri,tyno) ->
1424 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1425 string_of_int (tyno+1) ^ ")"
1426 | CicTextualParser0.IndConUri (uri,tyno,consno) ->
1427 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
1428 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^ ")"
1432 let index = interactive_interpretation_choice choices in
1433 List.nth resolve_ids' index
1435 id_to_uris := known_ids @ dom', resolve_id' ;
1436 mk_metasenv_and_expr resolve_id'
1439 exception UriAlreadyInUse;;
1440 exception NotAUriToAConstant;;
1442 let new_inductive () =
1443 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1444 let output = ((rendering_window ())#output : GMathView.math_view) in
1445 let notebook = (rendering_window ())#notebook in
1447 let chosen = ref false in
1448 let inductive = ref true in
1449 let paramsno = ref 0 in
1450 let get_uri = ref (function _ -> assert false) in
1451 let get_base_uri = ref (function _ -> assert false) in
1452 let get_names = ref (function _ -> assert false) in
1453 let get_types_and_cons = ref (function _ -> assert false) in
1454 let get_name_context_context_and_subst = ref (function _ -> assert false) in
1457 ~width:600 ~modal:true ~position:`CENTER
1458 ~title:"New Block of Mutual (Co)Inductive Definitions"
1459 ~border_width:2 () in
1460 let vbox = GPack.vbox ~packing:window#add () in
1462 GPack.hbox ~border_width:0
1463 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1465 GMisc.label ~text:"Enter the URI for the new block:"
1466 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1468 GEdit.entry ~editable:true
1469 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1471 GPack.hbox ~border_width:0
1472 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1476 "Enter the number of left parameters in every arity and constructor type:"
1477 ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1478 let paramsno_entry =
1479 GEdit.entry ~editable:true ~text:"0"
1480 ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
1482 GPack.hbox ~border_width:0
1483 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1485 GMisc.label ~text:"Are the definitions inductive or coinductive?"
1486 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1488 GButton.radio_button ~label:"Inductive"
1489 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1491 GButton.radio_button ~label:"Coinductive"
1492 ~group:inductiveb#group
1493 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1495 GPack.hbox ~border_width:0
1496 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1498 GMisc.label ~text:"Enter the list of the names of the types:"
1499 ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1501 GEdit.entry ~editable:true
1502 ~packing:(hbox2#pack ~expand:true ~fill:true ~padding:5) () in
1504 GPack.hbox ~border_width:0
1505 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1507 GButton.button ~label:"> Next"
1508 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1509 let _ = okb#misc#set_sensitive true in
1511 GButton.button ~label:"Abort"
1512 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1513 ignore (window#connect#destroy GMain.Main.quit) ;
1514 ignore (cancelb#connect#clicked window#destroy) ;
1518 (okb#connect#clicked
1521 let uristr = "cic:" ^ uri_entry#text in
1522 let namesstr = names_entry#text in
1523 let paramsno' = int_of_string (paramsno_entry#text) in
1524 match Str.split (Str.regexp " +") namesstr with
1526 | (he::tl) as names ->
1527 let uri = UriManager.uri_of_string (uristr ^ "/" ^ he ^ ".ind") in
1530 ignore (Getter.resolve uri) ;
1531 raise UriAlreadyInUse
1533 Getter.Unresolved ->
1534 get_uri := (function () -> uri) ;
1535 get_names := (function () -> names) ;
1536 inductive := inductiveb#active ;
1537 paramsno := paramsno' ;
1542 output_html outputhtml
1543 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1551 GBin.frame ~label:name
1552 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
1553 let vbox = GPack.vbox ~packing:frame#add () in
1554 let hbox = GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false) () in
1556 GMisc.label ~text:("Enter its type:")
1557 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1558 let scrolled_window =
1559 GBin.scrolled_window ~border_width:5
1560 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1562 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1563 ~isnotempty_callback:
1565 (*non_empty_type := b ;*)
1566 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*)
1569 GPack.hbox ~border_width:0
1570 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1572 GMisc.label ~text:("Enter the list of its constructors:")
1573 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1574 let cons_names_entry =
1575 GEdit.entry ~editable:true
1576 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1577 (newinputt,cons_names_entry)
1580 vbox#remove hboxn#coerce ;
1582 GPack.hbox ~border_width:0
1583 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1585 GButton.button ~label:"> Next"
1586 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1588 GButton.button ~label:"Abort"
1589 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1590 ignore (cancelb#connect#clicked window#destroy) ;
1592 (okb#connect#clicked
1595 let names = !get_names () in
1596 let types_and_cons =
1598 (fun name (newinputt,cons_names_entry) ->
1599 let dom,mk_metasenv_and_expr =
1600 newinputt#get_term ~context:[] ~metasenv:[] in
1601 let consnamesstr = cons_names_entry#text in
1602 let cons_names = Str.split (Str.regexp " +") consnamesstr in
1604 disambiguate_input [] [] dom mk_metasenv_and_expr
1607 [] -> expr,cons_names
1608 | _ -> raise AmbiguousInput
1609 ) names type_widgets
1611 (* Let's see if so far the definition is well-typed *)
1612 let uri = !get_uri () in
1618 (fun name (ty,cons) ->
1621 (function consname -> consname, Cic.MutInd (uri,!i,[])) cons in
1622 let res = (name, !inductive, ty, cons') in
1625 ) names types_and_cons
1627 (*CSC: test momentaneamente disattivato. Debbo generare dei costruttori validi
1628 anche quando paramsno > 0 ;-((((
1629 CicTypeChecker.typecheck_mutual_inductive_defs uri
1630 (tys,params,paramsno) ;
1632 get_name_context_context_and_subst :=
1636 (fun (namecontext,context,subst) name (ty,_) ->
1638 (Some (Cic.Name name))::namecontext,
1639 (Some (Cic.Name name, Cic.Decl ty))::context,
1640 (Cic.MutInd (uri,!i,[]))::subst
1643 ) ([],[],[]) names types_and_cons) ;
1644 let types_and_cons' =
1646 (fun name (ty,cons) -> (name, !inductive, ty, phase3 name cons))
1647 names types_and_cons
1649 get_types_and_cons := (function () -> types_and_cons') ;
1654 output_html outputhtml
1655 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1658 and phase3 name cons =
1659 let get_cons_types = ref (function () -> assert false) in
1662 ~width:600 ~modal:true ~position:`CENTER
1663 ~title:(name ^ " Constructors")
1664 ~border_width:2 () in
1665 let vbox = GPack.vbox ~packing:window2#add () in
1666 let cons_type_widgets =
1668 (function consname ->
1670 GPack.hbox ~border_width:0
1671 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1673 GMisc.label ~text:("Enter the type of " ^ consname ^ ":")
1674 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1675 let scrolled_window =
1676 GBin.scrolled_window ~border_width:5
1677 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1679 new term_editor ~width:400 ~height:20 ~packing:scrolled_window#add ()
1680 ~isnotempty_callback:
1682 (* (*non_empty_type := b ;*)
1683 okb#misc#set_sensitive true) (*(b && uri_entry#text <> ""))*) *)())
1688 GPack.hbox ~border_width:0
1689 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1691 GButton.button ~label:"> Next"
1692 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1693 let _ = okb#misc#set_sensitive true in
1695 GButton.button ~label:"Abort"
1696 ~packing:(hboxn#pack ~expand:false ~fill:false ~padding:5) () in
1697 ignore (window2#connect#destroy GMain.Main.quit) ;
1698 ignore (cancelb#connect#clicked window2#destroy) ;
1700 (okb#connect#clicked
1704 let namecontext,context,subst= !get_name_context_context_and_subst () in
1708 let dom,mk_metasenv_and_expr =
1709 inputt#get_term ~context:namecontext ~metasenv:[]
1712 disambiguate_input context [] dom mk_metasenv_and_expr
1716 let undebrujined_expr =
1718 (fun expr t -> CicSubstitution.subst t expr) expr subst
1720 name, undebrujined_expr
1721 | _ -> raise AmbiguousInput
1722 ) cons cons_type_widgets
1724 get_cons_types := (function () -> cons_types) ;
1728 output_html outputhtml
1729 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1732 GMain.Main.main () ;
1733 let okb_pressed = !chosen in
1735 if (not okb_pressed) then
1738 assert false (* The control never reaches this point *)
1741 (!get_cons_types ())
1744 (* No more phases left or Abort pressed *)
1746 GMain.Main.main () ;
1750 let uri = !get_uri () in
1753 let tys = !get_types_and_cons () in
1754 let obj = Cic.InductiveDefinition tys params !paramsno in
1757 prerr_endline (CicPp.ppobj obj) ;
1758 CicTypeChecker.typecheck_mutual_inductive_defs uri
1759 (tys,params,!paramsno) ;
1762 prerr_endline "Offending mutual (co)inductive type declaration:" ;
1763 prerr_endline (CicPp.ppobj obj) ;
1765 (* We already know that obj is well-typed. We need to add it to the *)
1766 (* environment in order to compute the inner-types without having to *)
1767 (* debrujin it or having to modify lots of other functions to avoid *)
1768 (* asking the environment for the MUTINDs we are defining now. *)
1769 CicEnvironment.put_inductive_definition uri obj ;
1771 show_in_show_window_obj uri obj
1774 output_html outputhtml
1775 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1779 let inputt = ((rendering_window ())#inputt : term_editor) in
1780 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1781 let output = ((rendering_window ())#output : GMathView.math_view) in
1782 let notebook = (rendering_window ())#notebook in
1784 let chosen = ref false in
1785 let get_parsed = ref (function _ -> assert false) in
1786 let get_uri = ref (function _ -> assert false) in
1787 let non_empty_type = ref false in
1790 ~width:600 ~modal:true ~title:"New Proof or Definition"
1791 ~border_width:2 () in
1792 let vbox = GPack.vbox ~packing:window#add () in
1794 GPack.hbox ~border_width:0
1795 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1797 GMisc.label ~text:"Enter the URI for the new theorem or definition:"
1798 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1800 GEdit.entry ~editable:true
1801 ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5) () in
1803 GPack.hbox ~border_width:0
1804 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1806 GMisc.label ~text:"Enter the theorem or definition type:"
1807 ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1808 let scrolled_window =
1809 GBin.scrolled_window ~border_width:5
1810 ~packing:(vbox#pack ~expand:true ~padding:0) () in
1811 (* the content of the scrolled_window is moved below (see comment) *)
1813 GPack.hbox ~border_width:0
1814 ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1816 GButton.button ~label:"Ok"
1817 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1818 let _ = okb#misc#set_sensitive false in
1820 GButton.button ~label:"Cancel"
1821 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1822 (* moved here to have visibility of the ok button *)
1824 new term_editor ~width:400 ~height:100 ~packing:scrolled_window#add ()
1825 ~isnotempty_callback:
1827 non_empty_type := b ;
1828 okb#misc#set_sensitive (b && uri_entry#text <> ""))
1831 newinputt#set_term inputt#get_as_string ;
1834 uri_entry#connect#changed
1836 okb#misc#set_sensitive (!non_empty_type && uri_entry#text <> ""))
1838 ignore (window#connect#destroy GMain.Main.quit) ;
1839 ignore (cancelb#connect#clicked window#destroy) ;
1841 (okb#connect#clicked
1845 let parsed = newinputt#get_term [] [] in
1846 let uristr = "cic:" ^ uri_entry#text in
1847 let uri = UriManager.uri_of_string uristr in
1848 if String.sub uristr (String.length uristr - 4) 4 <> ".con" then
1849 raise NotAUriToAConstant
1853 ignore (Getter.resolve uri) ;
1854 raise UriAlreadyInUse
1856 Getter.Unresolved ->
1857 get_parsed := (function () -> parsed) ;
1858 get_uri := (function () -> uri) ;
1863 output_html outputhtml
1864 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1867 GMain.Main.main () ;
1870 let dom,mk_metasenv_and_expr = !get_parsed () in
1872 disambiguate_input [] [] dom mk_metasenv_and_expr
1874 let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
1875 ProofEngine.proof :=
1876 Some (!get_uri (), (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
1877 ProofEngine.goal := Some 1 ;
1878 refresh_sequent notebook ;
1879 refresh_proof output ;
1880 !save_set_sensitive true ;
1883 RefreshSequentException e ->
1884 output_html outputhtml
1885 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1886 "sequent: " ^ Printexc.to_string e ^ "</h1>")
1887 | RefreshProofException e ->
1888 output_html outputhtml
1889 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1890 "proof: " ^ Printexc.to_string e ^ "</h1>")
1892 output_html outputhtml
1893 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1896 let check_term_in_scratch scratch_window metasenv context expr =
1898 let ty = CicTypeChecker.type_of_aux' metasenv context expr in
1899 let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1900 prerr_endline ("### " ^ CicPp.ppterm expr ^ " ==> " ^ CicPp.ppterm ty) ;
1901 scratch_window#show () ;
1902 scratch_window#mmlwidget#load_tree ~dom:mml
1905 print_endline ("? " ^ CicPp.ppterm expr) ;
1909 let check scratch_window () =
1910 let inputt = ((rendering_window ())#inputt : term_editor) in
1911 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1913 match !ProofEngine.proof with
1915 | Some (_,metasenv,_,_) -> metasenv
1917 let context,names_context =
1919 match !ProofEngine.goal with
1922 let (_,canonical_context,_) =
1923 List.find (function (m,_,_) -> m=metano) metasenv
1930 Some (n,_) -> Some n
1935 let dom,mk_metasenv_and_expr = inputt#get_term names_context metasenv in
1936 let (metasenv',expr) =
1937 disambiguate_input context metasenv dom mk_metasenv_and_expr
1939 check_term_in_scratch scratch_window metasenv' context expr
1942 output_html outputhtml
1943 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1947 (***********************)
1949 (***********************)
1951 let call_tactic tactic () =
1952 let notebook = (rendering_window ())#notebook in
1953 let output = ((rendering_window ())#output : GMathView.math_view) in
1954 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1955 let savedproof = !ProofEngine.proof in
1956 let savedgoal = !ProofEngine.goal in
1960 refresh_sequent notebook ;
1961 refresh_proof output
1963 RefreshSequentException e ->
1964 output_html outputhtml
1965 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1966 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
1967 ProofEngine.proof := savedproof ;
1968 ProofEngine.goal := savedgoal ;
1969 refresh_sequent notebook
1970 | RefreshProofException e ->
1971 output_html outputhtml
1972 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1973 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
1974 ProofEngine.proof := savedproof ;
1975 ProofEngine.goal := savedgoal ;
1976 refresh_sequent notebook ;
1977 refresh_proof output
1979 output_html outputhtml
1980 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1981 ProofEngine.proof := savedproof ;
1982 ProofEngine.goal := savedgoal ;
1986 let call_tactic_with_input tactic () =
1987 let notebook = (rendering_window ())#notebook in
1988 let output = ((rendering_window ())#output : GMathView.math_view) in
1989 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
1990 let inputt = ((rendering_window ())#inputt : term_editor) in
1991 let savedproof = !ProofEngine.proof in
1992 let savedgoal = !ProofEngine.goal in
1993 let uri,metasenv,bo,ty =
1994 match !ProofEngine.proof with
1995 None -> assert false
1996 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
1998 let canonical_context =
1999 match !ProofEngine.goal with
2000 None -> assert false
2002 let (_,canonical_context,_) =
2003 List.find (function (m,_,_) -> m=metano) metasenv
2010 Some (n,_) -> Some n
2015 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv in
2016 let (metasenv',expr) =
2017 disambiguate_input canonical_context metasenv dom mk_metasenv_and_expr
2019 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
2021 refresh_sequent notebook ;
2022 refresh_proof output ;
2025 RefreshSequentException e ->
2026 output_html outputhtml
2027 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2028 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2029 ProofEngine.proof := savedproof ;
2030 ProofEngine.goal := savedgoal ;
2031 refresh_sequent notebook
2032 | RefreshProofException e ->
2033 output_html outputhtml
2034 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2035 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2036 ProofEngine.proof := savedproof ;
2037 ProofEngine.goal := savedgoal ;
2038 refresh_sequent notebook ;
2039 refresh_proof output
2041 output_html outputhtml
2042 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2043 ProofEngine.proof := savedproof ;
2044 ProofEngine.goal := savedgoal ;
2047 let call_tactic_with_goal_input tactic () =
2048 let module L = LogicalOperations in
2049 let module G = Gdome in
2050 let notebook = (rendering_window ())#notebook in
2051 let output = ((rendering_window ())#output : GMathView.math_view) in
2052 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2053 let savedproof = !ProofEngine.proof in
2054 let savedgoal = !ProofEngine.goal in
2055 match notebook#proofw#get_selection with
2058 ((node : Gdome.element)#getAttributeNS
2059 ~namespaceURI:helmns
2060 ~localName:(G.domString "xref"))#to_string
2062 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2066 match !current_goal_infos with
2067 Some (ids_to_terms, ids_to_father_ids,_) ->
2069 tactic (Hashtbl.find ids_to_terms id) ;
2070 refresh_sequent notebook ;
2071 refresh_proof output
2072 | None -> assert false (* "ERROR: No current term!!!" *)
2074 RefreshSequentException e ->
2075 output_html outputhtml
2076 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2077 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2078 ProofEngine.proof := savedproof ;
2079 ProofEngine.goal := savedgoal ;
2080 refresh_sequent notebook
2081 | RefreshProofException e ->
2082 output_html outputhtml
2083 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2084 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2085 ProofEngine.proof := savedproof ;
2086 ProofEngine.goal := savedgoal ;
2087 refresh_sequent notebook ;
2088 refresh_proof output
2090 output_html outputhtml
2091 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2092 ProofEngine.proof := savedproof ;
2093 ProofEngine.goal := savedgoal ;
2096 output_html outputhtml
2097 ("<h1 color=\"red\">No term selected</h1>")
2100 let call_tactic_with_input_and_goal_input tactic () =
2101 let module L = LogicalOperations in
2102 let module G = Gdome in
2103 let notebook = (rendering_window ())#notebook in
2104 let output = ((rendering_window ())#output : GMathView.math_view) in
2105 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2106 let inputt = ((rendering_window ())#inputt : term_editor) in
2107 let savedproof = !ProofEngine.proof in
2108 let savedgoal = !ProofEngine.goal in
2109 match notebook#proofw#get_selection with
2112 ((node : Gdome.element)#getAttributeNS
2113 ~namespaceURI:helmns
2114 ~localName:(G.domString "xref"))#to_string
2116 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2120 match !current_goal_infos with
2121 Some (ids_to_terms, ids_to_father_ids,_) ->
2123 let uri,metasenv,bo,ty =
2124 match !ProofEngine.proof with
2125 None -> assert false
2126 | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
2128 let canonical_context =
2129 match !ProofEngine.goal with
2130 None -> assert false
2132 let (_,canonical_context,_) =
2133 List.find (function (m,_,_) -> m=metano) metasenv
2135 canonical_context in
2139 Some (n,_) -> Some n
2143 let dom,mk_metasenv_and_expr = inputt#get_term context metasenv
2145 let (metasenv',expr) =
2146 disambiguate_input canonical_context metasenv dom
2147 mk_metasenv_and_expr
2149 ProofEngine.proof := Some (uri,metasenv',bo,ty) ;
2150 tactic ~goal_input:(Hashtbl.find ids_to_terms id)
2152 refresh_sequent notebook ;
2153 refresh_proof output ;
2155 | None -> assert false (* "ERROR: No current term!!!" *)
2157 RefreshSequentException e ->
2158 output_html outputhtml
2159 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2160 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2161 ProofEngine.proof := savedproof ;
2162 ProofEngine.goal := savedgoal ;
2163 refresh_sequent notebook
2164 | RefreshProofException e ->
2165 output_html outputhtml
2166 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2167 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2168 ProofEngine.proof := savedproof ;
2169 ProofEngine.goal := savedgoal ;
2170 refresh_sequent notebook ;
2171 refresh_proof output
2173 output_html outputhtml
2174 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2175 ProofEngine.proof := savedproof ;
2176 ProofEngine.goal := savedgoal ;
2179 output_html outputhtml
2180 ("<h1 color=\"red\">No term selected</h1>")
2183 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
2184 let module L = LogicalOperations in
2185 let module G = Gdome in
2186 let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
2187 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2188 let savedproof = !ProofEngine.proof in
2189 let savedgoal = !ProofEngine.goal in
2190 match mmlwidget#get_selection with
2193 ((node : Gdome.element)#getAttributeNS
2194 ~namespaceURI:helmns
2195 ~localName:(G.domString "xref"))#to_string
2197 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2201 match !current_scratch_infos with
2202 (* term is the whole goal in the scratch_area *)
2203 Some (term,ids_to_terms, ids_to_father_ids,_) ->
2205 let expr = tactic term (Hashtbl.find ids_to_terms id) in
2206 let mml = mml_of_cic_term 111 expr in
2207 scratch_window#show () ;
2208 scratch_window#mmlwidget#load_tree ~dom:mml
2209 | None -> assert false (* "ERROR: No current term!!!" *)
2212 output_html outputhtml
2213 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2216 output_html outputhtml
2217 ("<h1 color=\"red\">No term selected</h1>")
2220 let call_tactic_with_hypothesis_input tactic () =
2221 let module L = LogicalOperations in
2222 let module G = Gdome in
2223 let notebook = (rendering_window ())#notebook in
2224 let output = ((rendering_window ())#output : GMathView.math_view) in
2225 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2226 let savedproof = !ProofEngine.proof in
2227 let savedgoal = !ProofEngine.goal in
2228 match notebook#proofw#get_selection with
2231 ((node : Gdome.element)#getAttributeNS
2232 ~namespaceURI:helmns
2233 ~localName:(G.domString "xref"))#to_string
2235 if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
2239 match !current_goal_infos with
2240 Some (_,_,ids_to_hypotheses) ->
2242 tactic (Hashtbl.find ids_to_hypotheses id) ;
2243 refresh_sequent notebook ;
2244 refresh_proof output
2245 | None -> assert false (* "ERROR: No current term!!!" *)
2247 RefreshSequentException e ->
2248 output_html outputhtml
2249 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2250 "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
2251 ProofEngine.proof := savedproof ;
2252 ProofEngine.goal := savedgoal ;
2253 refresh_sequent notebook
2254 | RefreshProofException e ->
2255 output_html outputhtml
2256 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2257 "proof: " ^ Printexc.to_string e ^ "</h1>") ;
2258 ProofEngine.proof := savedproof ;
2259 ProofEngine.goal := savedgoal ;
2260 refresh_sequent notebook ;
2261 refresh_proof output
2263 output_html outputhtml
2264 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2265 ProofEngine.proof := savedproof ;
2266 ProofEngine.goal := savedgoal ;
2269 output_html outputhtml
2270 ("<h1 color=\"red\">No term selected</h1>")
2274 let intros = call_tactic ProofEngine.intros;;
2275 let exact = call_tactic_with_input ProofEngine.exact;;
2276 let apply = call_tactic_with_input ProofEngine.apply;;
2277 let elimsimplintros = call_tactic_with_input ProofEngine.elim_simpl_intros;;
2278 let elimtype = call_tactic_with_input ProofEngine.elim_type;;
2279 let whd = call_tactic_with_goal_input ProofEngine.whd;;
2280 let reduce = call_tactic_with_goal_input ProofEngine.reduce;;
2281 let simpl = call_tactic_with_goal_input ProofEngine.simpl;;
2282 let fold_whd = call_tactic_with_input ProofEngine.fold_whd;;
2283 let fold_reduce = call_tactic_with_input ProofEngine.fold_reduce;;
2284 let fold_simpl = call_tactic_with_input ProofEngine.fold_simpl;;
2285 let cut = call_tactic_with_input ProofEngine.cut;;
2286 let change = call_tactic_with_input_and_goal_input ProofEngine.change;;
2287 let letin = call_tactic_with_input ProofEngine.letin;;
2288 let ring = call_tactic ProofEngine.ring;;
2289 let clearbody = call_tactic_with_hypothesis_input ProofEngine.clearbody;;
2290 let clear = call_tactic_with_hypothesis_input ProofEngine.clear;;
2291 let fourier = call_tactic ProofEngine.fourier;;
2292 let rewritesimpl = call_tactic_with_input ProofEngine.rewrite_simpl;;
2293 let reflexivity = call_tactic ProofEngine.reflexivity;;
2294 let symmetry = call_tactic ProofEngine.symmetry;;
2295 let transitivity = call_tactic_with_input ProofEngine.transitivity;;
2296 let exists = call_tactic ProofEngine.exists;;
2297 let split = call_tactic ProofEngine.split;;
2298 let left = call_tactic ProofEngine.left;;
2299 let right = call_tactic ProofEngine.right;;
2300 let assumption = call_tactic ProofEngine.assumption;;
2301 let generalize = call_tactic_with_goal_input ProofEngine.generalize;;
2302 let absurd = call_tactic_with_input ProofEngine.absurd;;
2303 let contradiction = call_tactic ProofEngine.contradiction;;
2304 (* Galla: come dare alla tattica la lista di termini da decomporre?
2305 let decompose = call_tactic_with_input_and_goal_input ProofEngine.decompose;;
2308 let whd_in_scratch scratch_window =
2309 call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
2312 let reduce_in_scratch scratch_window =
2313 call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
2316 let simpl_in_scratch scratch_window =
2317 call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
2323 (**********************)
2324 (* END OF TACTICS *)
2325 (**********************)
2329 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2331 show_in_show_window_uri (input_or_locate_uri ~title:"Show")
2334 output_html outputhtml
2335 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2338 exception NotADefinition;;
2341 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2342 let output = ((rendering_window ())#output : GMathView.math_view) in
2343 let notebook = (rendering_window ())#notebook in
2345 let uri = input_or_locate_uri ~title:"Open" in
2346 CicTypeChecker.typecheck uri ;
2347 let metasenv,bo,ty =
2348 match CicEnvironment.get_cooked_obj uri with
2349 Cic.Constant (_,Some bo,ty,_) -> [],bo,ty
2350 | Cic.CurrentProof (_,metasenv,bo,ty,_) -> metasenv,bo,ty
2353 | Cic.InductiveDefinition _ -> raise NotADefinition
2355 ProofEngine.proof :=
2356 Some (uri, metasenv, bo, ty) ;
2357 ProofEngine.goal := None ;
2358 refresh_sequent notebook ;
2359 refresh_proof output
2361 RefreshSequentException e ->
2362 output_html outputhtml
2363 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2364 "sequent: " ^ Printexc.to_string e ^ "</h1>")
2365 | RefreshProofException e ->
2366 output_html outputhtml
2367 ("<h1 color=\"red\">Exception raised during the refresh of the " ^
2368 "proof: " ^ Printexc.to_string e ^ "</h1>")
2370 output_html outputhtml
2371 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2374 let show_query_results results =
2377 ~modal:false ~title:"Query results." ~border_width:2 () in
2378 let vbox = GPack.vbox ~packing:window#add () in
2380 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2383 ~text:"Click on a URI to show that object"
2384 ~packing:hbox#add () in
2385 let scrolled_window =
2386 GBin.scrolled_window ~border_width:10 ~height:400 ~width:600
2387 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2388 let clist = GList.clist ~columns:1 ~packing:scrolled_window#add () in
2391 (function (uri,_) ->
2395 clist#set_row ~selectable:false n
2398 clist#columns_autosize () ;
2400 (clist#connect#select_row
2401 (fun ~row ~column ~event ->
2402 let (uristr,_) = List.nth results row in
2404 cic_textual_parser_uri_of_string
2405 (wrong_xpointer_format_from_wrong_xpointer_format' uristr)
2407 CicTextualParser0.ConUri uri
2408 | CicTextualParser0.VarUri uri
2409 | CicTextualParser0.IndTyUri (uri,_)
2410 | CicTextualParser0.IndConUri (uri,_,_) ->
2411 show_in_show_window_uri uri
2418 refine_constraints (must_obj,must_rel,must_sort) (only_obj,only_rel,only_sort)
2420 let chosen = ref false in
2421 let use_only = ref false in
2424 ~modal:true ~title:"Constraints refinement." ~border_width:2 () in
2425 let vbox = GPack.vbox ~packing:window#add () in
2427 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2430 ~text: "\"Only\" constraints can be enforced or not."
2431 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2433 GButton.toggle_button ~label:"Enforce \"only\" constraints"
2434 ~active:false ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5)
2438 (onlyb#connect#toggled (function () -> use_only := onlyb#active)) ;
2440 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2443 ~text: "You can now specify the constraints on Rels."
2444 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2445 (* Rel constraints *)
2446 let expected_height = 25 * (List.length must_rel + 2) in
2447 let height = if expected_height > 400 then 400 else expected_height in
2448 let scrolled_window =
2449 GBin.scrolled_window ~border_width:10 ~height ~width:600
2450 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2451 let scrolled_vbox = GPack.vbox ~packing:scrolled_window#add_with_viewport () in
2452 let rel_constraints =
2454 (function (position,depth) ->
2457 ~packing:(scrolled_vbox#pack ~expand:false ~fill:false ~padding:5) () in
2461 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2463 None -> position, ref None
2465 let mutable_ref = ref (Some depth') in
2467 GButton.toggle_button ~label:(string_of_int depth')
2468 ~active:true ~packing:(hbox#pack ~expand:true ~fill:true ~padding:5)
2472 (depthb#connect#toggled
2474 let sel_depth = if depthb#active then Some depth' else None in
2475 mutable_ref := sel_depth
2477 position, mutable_ref
2480 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2482 GButton.button ~label:"Ok"
2483 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2485 GButton.button ~label:"Abort"
2486 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) ()
2488 ignore (window#connect#destroy GMain.Main.quit) ;
2489 ignore (cancelb#connect#clicked window#destroy) ;
2491 (okb#connect#clicked (function () -> chosen := true ; window#destroy ()));
2492 window#set_position `CENTER ;
2494 GMain.Main.main () ;
2496 let chosen_must_rel =
2499 (function (position,ref_depth) -> position,!ref_depth) rel_constraints
2501 (function (position,ref_depth) -> prerr_endline ("### " ^ position ^ " " ^ match !ref_depth with None -> "NULL" | Some d -> string_of_int d) ; position,!ref_depth) rel_constraints
2503 (must_obj,chosen_must_rel,must_sort),
2505 (*CSC: ???????????????????????? I assume that must and only are the same... *)
2506 only_obj,Some chosen_must_rel,only_sort
2514 let completeSearchPattern () =
2515 let inputt = ((rendering_window ())#inputt : term_editor) in
2516 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2518 let dom,mk_metasenv_and_expr = inputt#get_term ~context:[] ~metasenv:[] in
2519 let metasenv,expr = disambiguate_input [] [] dom mk_metasenv_and_expr in
2520 let must,only = MQueryLevels2.get_constraints expr in
2521 let must',only' = refine_constraints must only in
2522 let results = MQueryGenerator.searchPattern must' only' in
2523 show_query_results results
2526 output_html outputhtml
2527 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
2530 let choose_must list_of_must only =
2531 let chosen = ref None in
2532 let user_constraints = ref [] in
2535 ~modal:true ~title:"Query refinement." ~border_width:2 () in
2536 let vbox = GPack.vbox ~packing:window#add () in
2538 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2542 ("You can now specify the genericity of the query. " ^
2543 "The more generic the slower.")
2544 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2546 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2550 "Suggestion: start with faster queries before moving to more generic ones."
2551 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2553 GPack.notebook ~scrollable:true
2554 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2557 let last = List.length list_of_must in
2563 (if !page = 1 then "More generic" else
2564 if !page = last then "More precise" else " ") () in
2565 let expected_height = 25 * (List.length must + 2) in
2566 let height = if expected_height > 400 then 400 else expected_height in
2567 let scrolled_window =
2568 GBin.scrolled_window ~border_width:10 ~height ~width:600
2569 ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2571 GList.clist ~columns:2 ~packing:scrolled_window#add
2572 ~titles:["URI" ; "Position"] ()
2576 (function (uri,position) ->
2579 [uri; if position then "MainConclusion" else "Conclusion"]
2581 clist#set_row ~selectable:false n
2584 clist#columns_autosize ()
2587 let label = GMisc.label ~text:"User provided" () in
2589 GPack.vbox ~packing:(notebook#append_page ~tab_label:label#coerce) () in
2591 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2594 ~text:"Select the constraints that must be satisfied and press OK."
2595 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2596 let expected_height = 25 * (List.length only + 2) in
2597 let height = if expected_height > 400 then 400 else expected_height in
2598 let scrolled_window =
2599 GBin.scrolled_window ~border_width:10 ~height ~width:600
2600 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
2602 GList.clist ~columns:2 ~packing:scrolled_window#add
2603 ~selection_mode:`EXTENDED
2604 ~titles:["URI" ; "Position"] ()
2608 (function (uri,position) ->
2611 [uri; if position then "MainConclusion" else "Conclusion"]
2613 clist#set_row ~selectable:true n
2616 clist#columns_autosize () ;
2618 (clist#connect#select_row
2619 (fun ~row ~column ~event ->
2620 user_constraints := (List.nth only row)::!user_constraints)) ;
2622 (clist#connect#unselect_row
2623 (fun ~row ~column ~event ->
2626 (function uri -> uri != (List.nth only row)) !user_constraints)) ;
2629 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2631 GButton.button ~label:"Ok"
2632 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2634 GButton.button ~label:"Abort"
2635 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2637 ignore (window#connect#destroy GMain.Main.quit) ;
2638 ignore (cancelb#connect#clicked window#destroy) ;
2640 (okb#connect#clicked
2641 (function () -> chosen := Some notebook#current_page ; window#destroy ())) ;
2642 window#set_position `CENTER ;
2644 GMain.Main.main () ;
2646 None -> raise NoChoice
2648 if n = List.length list_of_must then
2649 (* user provided constraints *)
2652 List.nth list_of_must n
2655 let searchPattern () =
2656 let inputt = ((rendering_window ())#inputt : term_editor) in
2657 let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
2660 match !ProofEngine.proof with
2661 None -> assert false
2662 | Some (_,metasenv,_,_) -> metasenv
2664 match !ProofEngine.goal with
2667 let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
2668 let list_of_must,only = MQueryLevels.out_restr metasenv ey ty in
2669 let must = choose_must list_of_must only in
2670 let torigth_restriction (u,b) =
2673 "http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion"
2675 "http://www.cs.unibo.it/helm/schemas/schema-helm#InConclusion"
2679 let rigth_must = List.map torigth_restriction must in
2680 let rigth_only = Some (List.map torigth_restriction only) in
2682 MQueryGenerator.searchPattern
2683 (rigth_must,[],[]) (rigth_only,None,None) in
2687 wrong_xpointer_format_from_wrong_xpointer_format' uri
2690 " <h1>Backward Query: </h1>" ^
2691 " <pre>" ^ get_last_query result ^ "</pre>"
2693 output_html outputhtml html ;
2695 let rec filter_out =
2699 let tl',exc = filter_out tl in
2702 ProofEngine.can_apply
2703 (term_of_cic_textual_parser_uri
2704 (cic_textual_parser_uri_of_string uri))
2712 "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
2713 uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
2720 " <h1>Objects that can actually be applied: </h1> " ^
2721 String.concat "<br>" uris' ^ exc ^
2722 " <h1>Number of false matches: " ^
2723 string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
2724 " <h1>Number of good matches: " ^
2725 string_of_int (List.length uris') ^ "</h1>"
2727 output_html outputhtml html' ;
2729 user_uri_choice ~title:"Ambiguous input."
2731 "Many lemmas can be successfully applied. Please, choose one:"
2734 inputt#set_term uri' ;
2738 output_html outputhtml
2739 ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
2742 let choose_selection
2743 (mmlwidget : GMathView.math_view) (element : Gdome.element option)
2745 let module G = Gdome in
2746 let rec aux element =
2747 if element#hasAttributeNS
2748 ~namespaceURI:helmns
2749 ~localName:(G.domString "xref")
2751 mmlwidget#set_selection (Some element)
2753 match element#get_parentNode with
2754 None -> assert false
2755 (*CSC: OCAML DIVERGES!
2756 | Some p -> aux (new G.element_of_node p)
2758 | Some p -> aux (new Gdome.element_of_node p)
2762 | None -> mmlwidget#set_selection None
2765 (* STUFF TO BUILD THE GTK INTERFACE *)
2767 (* Stuff for the widget settings *)
2769 let export_to_postscript (output : GMathView.math_view) =
2770 let lastdir = ref (Unix.getcwd ()) in
2773 GToolbox.select_file ~title:"Export to PostScript"
2774 ~dir:lastdir ~filename:"screenshot.ps" ()
2778 output#export_to_postscript ~filename:filename ();
2781 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
2782 button_set_kerning button_set_transparency export_to_postscript_menu_item
2785 let is_set = button_t1#active in
2786 output#set_font_manager_type
2787 (if is_set then `font_manager_t1 else `font_manager_gtk) ;
2790 button_set_anti_aliasing#misc#set_sensitive true ;
2791 button_set_kerning#misc#set_sensitive true ;
2792 button_set_transparency#misc#set_sensitive true ;
2793 export_to_postscript_menu_item#misc#set_sensitive true ;
2797 button_set_anti_aliasing#misc#set_sensitive false ;
2798 button_set_kerning#misc#set_sensitive false ;
2799 button_set_transparency#misc#set_sensitive false ;
2800 export_to_postscript_menu_item#misc#set_sensitive false ;
2804 let set_anti_aliasing output button_set_anti_aliasing () =
2805 output#set_anti_aliasing button_set_anti_aliasing#active
2808 let set_kerning output button_set_kerning () =
2809 output#set_kerning button_set_kerning#active
2812 let set_transparency output button_set_transparency () =
2813 output#set_transparency button_set_transparency#active
2816 let changefont output font_size_spinb () =
2817 output#set_font_size font_size_spinb#value_as_int
2820 let set_log_verbosity output log_verbosity_spinb () =
2821 output#set_log_verbosity log_verbosity_spinb#value_as_int
2824 class settings_window (output : GMathView.math_view) sw
2825 export_to_postscript_menu_item selection_changed_callback
2827 let settings_window = GWindow.window ~title:"GtkMathView settings" () in
2829 GPack.vbox ~packing:settings_window#add () in
2832 ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2833 ~border_width:5 ~packing:vbox#add () in
2835 GButton.toggle_button ~label:"activate t1 fonts"
2836 ~packing:(table#attach ~left:0 ~top:0) () in
2837 let button_set_anti_aliasing =
2838 GButton.toggle_button ~label:"set_anti_aliasing"
2839 ~packing:(table#attach ~left:0 ~top:1) () in
2840 let button_set_kerning =
2841 GButton.toggle_button ~label:"set_kerning"
2842 ~packing:(table#attach ~left:1 ~top:1) () in
2843 let button_set_transparency =
2844 GButton.toggle_button ~label:"set_transparency"
2845 ~packing:(table#attach ~left:2 ~top:1) () in
2848 ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
2849 ~border_width:5 ~packing:vbox#add () in
2850 let font_size_label =
2851 GMisc.label ~text:"font size:"
2852 ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
2853 let font_size_spinb =
2855 GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
2858 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
2859 let log_verbosity_label =
2860 GMisc.label ~text:"log verbosity:"
2861 ~packing:(table#attach ~left:0 ~top:1) () in
2862 let log_verbosity_spinb =
2864 GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
2867 ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
2869 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2871 GButton.button ~label:"Close"
2872 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2874 method show = settings_window#show
2876 button_set_anti_aliasing#misc#set_sensitive false ;
2877 button_set_kerning#misc#set_sensitive false ;
2878 button_set_transparency#misc#set_sensitive false ;
2879 (* Signals connection *)
2880 ignore(button_t1#connect#clicked
2881 (activate_t1 output button_set_anti_aliasing button_set_kerning
2882 button_set_transparency export_to_postscript_menu_item button_t1)) ;
2883 ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
2884 ignore(button_set_anti_aliasing#connect#toggled
2885 (set_anti_aliasing output button_set_anti_aliasing));
2886 ignore(button_set_kerning#connect#toggled
2887 (set_kerning output button_set_kerning)) ;
2888 ignore(button_set_transparency#connect#toggled
2889 (set_transparency output button_set_transparency)) ;
2890 ignore(log_verbosity_spinb#connect#changed
2891 (set_log_verbosity output log_verbosity_spinb)) ;
2892 ignore(closeb#connect#clicked settings_window#misc#hide)
2895 (* Scratch window *)
2897 class scratch_window =
2899 GWindow.window ~title:"MathML viewer" ~border_width:2 () in
2901 GPack.vbox ~packing:window#add () in
2903 GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
2905 GButton.button ~label:"Whd"
2906 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2908 GButton.button ~label:"Reduce"
2909 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2911 GButton.button ~label:"Simpl"
2912 ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
2913 let scrolled_window =
2914 GBin.scrolled_window ~border_width:10
2915 ~packing:(vbox#pack ~expand:true ~padding:5) () in
2918 ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
2920 method mmlwidget = mmlwidget
2921 method show () = window#misc#hide () ; window#show ()
2923 ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
2924 ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
2925 ignore(whdb#connect#clicked (whd_in_scratch self)) ;
2926 ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
2927 ignore(simplb#connect#clicked (simpl_in_scratch self))
2931 let vbox1 = GPack.vbox () in
2933 val mutable proofw_ref = None
2934 val mutable compute_ref = None
2936 Lazy.force self#compute ;
2937 match proofw_ref with
2938 None -> assert false
2939 | Some proofw -> proofw
2940 method content = vbox1
2942 match compute_ref with
2943 None -> assert false
2944 | Some compute -> compute
2948 let scrolled_window1 =
2949 GBin.scrolled_window ~border_width:10
2950 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
2952 GMathView.math_view ~width:400 ~height:275
2953 ~packing:(scrolled_window1#add) () in
2954 let _ = proofw_ref <- Some proofw in
2956 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2958 GButton.button ~label:"Exact"
2959 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2961 GButton.button ~label:"Intros"
2962 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2964 GButton.button ~label:"Apply"
2965 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2966 let elimsimplintrosb =
2967 GButton.button ~label:"ElimSimplIntros"
2968 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2970 GButton.button ~label:"ElimType"
2971 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2973 GButton.button ~label:"Whd"
2974 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2976 GButton.button ~label:"Reduce"
2977 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2979 GButton.button ~label:"Simpl"
2980 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2982 GButton.button ~label:"Fold_whd"
2983 ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
2985 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
2987 GButton.button ~label:"Fold_reduce"
2988 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2990 GButton.button ~label:"Fold_simpl"
2991 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2993 GButton.button ~label:"Cut"
2994 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2996 GButton.button ~label:"Change"
2997 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
2999 GButton.button ~label:"Let ... In"
3000 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3002 GButton.button ~label:"Ring"
3003 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3005 GButton.button ~label:"ClearBody"
3006 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3008 GButton.button ~label:"Clear"
3009 ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
3011 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3013 GButton.button ~label:"Fourier"
3014 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3016 GButton.button ~label:"RewriteSimpl ->"
3017 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3019 GButton.button ~label:"Reflexivity"
3020 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3022 GButton.button ~label:"Symmetry"
3023 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3025 GButton.button ~label:"Transitivity"
3026 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3028 GButton.button ~label:"Exists"
3029 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3031 GButton.button ~label:"Split"
3032 ~packing:(hbox5#pack ~expand:false ~fill:false ~padding:5) () in
3034 GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
3036 GButton.button ~label:"Left"
3037 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3039 GButton.button ~label:"Right"
3040 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3042 GButton.button ~label:"Assumption"
3043 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3045 GButton.button ~label:"Generalize"
3046 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3048 GButton.button ~label:"Absurd"
3049 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3050 let contradictionb =
3051 GButton.button ~label:"Contradiction"
3052 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3053 let searchpatternb =
3054 GButton.button ~label:"SearchPattern_Apply"
3055 ~packing:(hbox6#pack ~expand:false ~fill:false ~padding:5) () in
3057 ignore(exactb#connect#clicked exact) ;
3058 ignore(applyb#connect#clicked apply) ;
3059 ignore(elimsimplintrosb#connect#clicked elimsimplintros) ;
3060 ignore(elimtypeb#connect#clicked elimtype) ;
3061 ignore(whdb#connect#clicked whd) ;
3062 ignore(reduceb#connect#clicked reduce) ;
3063 ignore(simplb#connect#clicked simpl) ;
3064 ignore(foldwhdb#connect#clicked fold_whd) ;
3065 ignore(foldreduceb#connect#clicked fold_reduce) ;
3066 ignore(foldsimplb#connect#clicked fold_simpl) ;
3067 ignore(cutb#connect#clicked cut) ;
3068 ignore(changeb#connect#clicked change) ;
3069 ignore(letinb#connect#clicked letin) ;
3070 ignore(ringb#connect#clicked ring) ;
3071 ignore(clearbodyb#connect#clicked clearbody) ;
3072 ignore(clearb#connect#clicked clear) ;
3073 ignore(fourierb#connect#clicked fourier) ;
3074 ignore(rewritesimplb#connect#clicked rewritesimpl) ;
3075 ignore(reflexivityb#connect#clicked reflexivity) ;
3076 ignore(symmetryb#connect#clicked symmetry) ;
3077 ignore(transitivityb#connect#clicked transitivity) ;
3078 ignore(existsb#connect#clicked exists) ;
3079 ignore(splitb#connect#clicked split) ;
3080 ignore(leftb#connect#clicked left) ;
3081 ignore(rightb#connect#clicked right) ;
3082 ignore(assumptionb#connect#clicked assumption) ;
3083 ignore(generalizeb#connect#clicked generalize) ;
3084 ignore(absurdb#connect#clicked absurd) ;
3085 ignore(contradictionb#connect#clicked contradiction) ;
3086 ignore(introsb#connect#clicked intros) ;
3087 ignore(searchpatternb#connect#clicked searchPattern) ;
3088 ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
3094 let vbox1 = GPack.vbox () in
3095 let scrolled_window1 =
3096 GBin.scrolled_window ~border_width:10
3097 ~packing:(vbox1#pack ~expand:true ~padding:5) () in
3099 GMathView.math_view ~width:400 ~height:275
3100 ~packing:(scrolled_window1#add) () in
3102 method proofw = (assert false : GMathView.math_view)
3103 method content = vbox1
3104 method compute = (assert false : unit)
3108 let empty_page = new empty_page;;
3112 val notebook = GPack.notebook ()
3114 val mutable skip_switch_page_event = false
3115 val mutable empty = true
3116 method notebook = notebook
3118 let new_page = new page () in
3120 pages := !pages @ [n,lazy (setgoal n),new_page] ;
3121 notebook#append_page
3122 ~tab_label:((GMisc.label ~text:("?" ^ string_of_int n) ())#coerce)
3123 new_page#content#coerce
3124 method remove_all_pages ~skip_switch_page_event:skip =
3126 notebook#remove_page 0 (* let's remove the empty page *)
3128 List.iter (function _ -> notebook#remove_page 0) !pages ;
3130 skip_switch_page_event <- skip
3131 method set_current_page ~may_skip_switch_page_event n =
3132 let (_,_,page) = List.find (function (m,_,_) -> m=n) !pages in
3133 let new_page = notebook#page_num page#content#coerce in
3134 if may_skip_switch_page_event && new_page <> notebook#current_page then
3135 skip_switch_page_event <- true ;
3136 notebook#goto_page new_page
3137 method set_empty_page =
3140 notebook#append_page
3141 ~tab_label:((GMisc.label ~text:"No proof in progress" ())#coerce)
3142 empty_page#content#coerce
3144 let (_,_,page) = List.nth !pages notebook#current_page in
3148 (notebook#connect#switch_page
3150 let skip = skip_switch_page_event in
3151 skip_switch_page_event <- false ;
3154 let (metano,setgoal,page) = List.nth !pages i in
3155 ProofEngine.goal := Some metano ;
3156 Lazy.force (page#compute) ;
3165 class rendering_window output (notebook : notebook) =
3166 let scratch_window = new scratch_window in
3168 GWindow.window ~title:"MathML viewer" ~border_width:0
3169 ~allow_shrink:false () in
3170 let vbox_for_menu = GPack.vbox ~packing:window#add () in
3172 let handle_box = GBin.handle_box ~border_width:2
3173 ~packing:(vbox_for_menu#pack ~padding:0) () in
3174 let menubar = GMenu.menu_bar ~packing:handle_box#add () in
3175 let factory0 = new GMenu.factory menubar in
3176 let accel_group = factory0#accel_group in
3178 let file_menu = factory0#add_submenu "File" in
3179 let factory1 = new GMenu.factory file_menu ~accel_group in
3180 let export_to_postscript_menu_item =
3183 factory1#add_item "New Block of (Co)Inductive Definitions..."
3184 ~key:GdkKeysyms._B ~callback:new_inductive
3187 factory1#add_item "New Proof or Definition..." ~key:GdkKeysyms._N
3190 let reopen_menu_item =
3191 factory1#add_item "Reopen a Finished Proof..." ~key:GdkKeysyms._R
3195 factory1#add_item "Qed" ~key:GdkKeysyms._E ~callback:qed in
3196 ignore (factory1#add_separator ()) ;
3198 (factory1#add_item "Load Unfinished Proof..." ~key:GdkKeysyms._L
3200 let save_menu_item =
3201 factory1#add_item "Save Unfinished Proof" ~key:GdkKeysyms._S ~callback:save
3204 (save_set_sensitive := function b -> save_menu_item#misc#set_sensitive b);
3205 ignore (!save_set_sensitive false);
3206 ignore (qed_set_sensitive:=function b -> qed_menu_item#misc#set_sensitive b);
3207 ignore (!qed_set_sensitive false);
3208 ignore (factory1#add_separator ()) ;
3209 let export_to_postscript_menu_item =
3210 factory1#add_item "Export to PostScript..."
3211 ~callback:(export_to_postscript output) in
3212 ignore (factory1#add_separator ()) ;
3214 (factory1#add_item "Exit" ~key:GdkKeysyms._Q ~callback:GMain.Main.quit) ;
3215 export_to_postscript_menu_item
3218 let edit_menu = factory0#add_submenu "Edit Current Proof" in
3219 let factory2 = new GMenu.factory edit_menu ~accel_group in
3220 let focus_and_proveit_set_sensitive = ref (function _ -> assert false) in
3221 let proveit_menu_item =
3222 factory2#add_item "Prove It" ~key:GdkKeysyms._I
3223 ~callback:(function () -> proveit ();!focus_and_proveit_set_sensitive false)
3225 let focus_menu_item =
3226 factory2#add_item "Focus" ~key:GdkKeysyms._F
3227 ~callback:(function () -> focus () ; !focus_and_proveit_set_sensitive false)
3230 focus_and_proveit_set_sensitive :=
3232 proveit_menu_item#misc#set_sensitive b ;
3233 focus_menu_item#misc#set_sensitive b
3235 let _ = !focus_and_proveit_set_sensitive false in
3236 (* edit term menu *)
3237 let edit_term_menu = factory0#add_submenu "Edit Term" in
3238 let factory5 = new GMenu.factory edit_term_menu ~accel_group in
3239 let check_menu_item =
3240 factory5#add_item "Check Term" ~key:GdkKeysyms._C
3241 ~callback:(check scratch_window) in
3242 let _ = check_menu_item#misc#set_sensitive false in
3244 let settings_menu = factory0#add_submenu "Search" in
3245 let factory4 = new GMenu.factory settings_menu ~accel_group in
3247 factory4#add_item "Locate..." ~key:GdkKeysyms._T
3249 let searchPattern_menu_item =
3250 factory4#add_item "SearchPattern..." ~key:GdkKeysyms._D
3251 ~callback:completeSearchPattern in
3252 let _ = searchPattern_menu_item#misc#set_sensitive false in
3253 let show_menu_item =
3254 factory4#add_item "Show..." ~key:GdkKeysyms._H ~callback:show
3257 let settings_menu = factory0#add_submenu "Settings" in
3258 let factory3 = new GMenu.factory settings_menu ~accel_group in
3260 factory3#add_item "Edit Aliases" ~key:GdkKeysyms._A
3261 ~callback:edit_aliases in
3262 let _ = factory3#add_separator () in
3264 factory3#add_item "MathML Widget Preferences..." ~key:GdkKeysyms._P
3265 ~callback:(function _ -> (settings_window ())#show ()) in
3267 let _ = window#add_accel_group accel_group in
3271 ~packing:(vbox_for_menu#pack ~expand:true ~fill:true ~padding:5) () in
3273 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3274 let scrolled_window0 =
3275 GBin.scrolled_window ~border_width:10
3276 ~packing:(vbox#pack ~expand:true ~padding:5) () in
3277 let _ = scrolled_window0#add output#coerce in
3279 GBin.frame ~label:"Insert Term"
3280 ~packing:(vbox#pack ~expand:true ~fill:true ~padding:5) () in
3281 let scrolled_window1 =
3282 GBin.scrolled_window ~border_width:5
3283 ~packing:frame#add () in
3285 new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add ()
3286 ~isnotempty_callback:
3288 check_menu_item#misc#set_sensitive b ;
3289 searchPattern_menu_item#misc#set_sensitive b) in
3291 GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
3293 vboxl#pack ~expand:true ~fill:true ~padding:5 notebook#notebook#coerce in
3295 GBin.frame ~shadow_type:`IN ~packing:(vboxl#pack ~expand:true ~padding:5) ()
3299 ~source:"<html><body bgColor=\"white\"></body></html>"
3300 ~width:400 ~height: 100
3305 method outputhtml = outputhtml
3306 method inputt = inputt
3307 method output = (output : GMathView.math_view)
3308 method notebook = notebook
3309 method show = window#show
3311 notebook#set_empty_page ;
3312 export_to_postscript_menu_item#misc#set_sensitive false ;
3313 check_term := (check_term_in_scratch scratch_window) ;
3315 (* signal handlers here *)
3316 ignore(output#connect#selection_changed
3318 choose_selection output elem ;
3319 !focus_and_proveit_set_sensitive true
3321 ignore (output#connect#clicked (show_in_show_window_callback output)) ;
3322 let settings_window = new settings_window output scrolled_window0
3323 export_to_postscript_menu_item (choose_selection output) in
3324 set_settings_window settings_window ;
3325 set_outputhtml outputhtml ;
3326 ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
3327 Logger.log_callback :=
3328 (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
3333 let initialize_everything () =
3334 let module U = Unix in
3335 let output = GMathView.math_view ~width:350 ~height:280 () in
3336 let notebook = new notebook in
3337 let rendering_window' = new rendering_window output notebook in
3338 set_rendering_window rendering_window' ;
3339 mml_of_cic_term_ref := mml_of_cic_term ;
3340 rendering_window'#show () ;
3347 Mqint.set_database Mqint.postgres_db ;
3348 (* Mqint.init "dbname=helm_mowgli" ; *)
3349 (* Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm" ; *)
3350 Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm";
3352 ignore (GtkMain.Main.init ()) ;
3353 initialize_everything () ;
3354 if !usedb then Mqint.close ();