]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/gTopLevel/gTopLevel.ml
* Many improvements
[helm.git] / helm / gTopLevel / gTopLevel.ml
index eeda38e492d4a49bc0d93c7dba9c6add00897f3d..4f8a29d76cbd70cbe99a545a4bd9e7bec5a17233 100644 (file)
@@ -100,8 +100,9 @@ let mml_args =
   "media-type", "'text/html'" ;
   "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
   "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
-  "naturalLanguage", "'no'" ;
+  "naturalLanguage", "'yes'" ;
   "annotations", "'no'" ;
+  "explodeall", "'true()'" ;
   "topurl", "'http://phd.cs.unibo.it/helm'" ;
   "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
 ;;
@@ -120,6 +121,7 @@ let sequent_args =
   "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
   "naturalLanguage", "'no'" ;
   "annotations", "'no'" ;
+  "explodeall", "'true()'" ;
   "topurl", "'http://phd.cs.unibo.it/helm'" ;
   "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
 ;;
@@ -141,14 +143,21 @@ let applyStylesheets input styles args =
   input styles
 ;;
 
-let mml_of_cic_object annobj ids_to_inner_sorts =
+let mml_of_cic_object annobj ids_to_inner_sorts ids_to_inner_types =
  let xml =
   Cic2Xml.print_object
    (UriManager.uri_of_string "cic:/dummy.con") ids_to_inner_sorts annobj 
  in
-  let input =
-   Xml2Gdome.document_of_xml domImpl xml 
-  in
+ let xmlinnertypes =
+  Cic2Xml.print_inner_types
+   (UriManager.uri_of_string "cic:/dummy.con") ids_to_inner_sorts
+   ids_to_inner_types
+ in
+  let input = Xml2Gdome.document_of_xml domImpl xml in
+(*CSC: We save the innertypes to disk so that we can retrieve them in the  *)
+(*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
+(*CSC: local.                                                              *)
+   Xml.pp xmlinnertypes (Some "/public/sacerdot/innertypes") ;
    let output = applyStylesheets input mml_styles mml_args in
     output
 ;;
@@ -162,33 +171,35 @@ let refresh_proof (output : GMathView.math_view) =
      None -> assert false
    | Some (metasenv,bo,ty) -> Cic.CurrentProof ("unnamed", metasenv, bo, ty)
  in
- let (acic, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts) =
+ let
+  (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_inner_types)
+ =
   Cic2acic.acic_object_of_cic_object currentproof
  in
-  let mml = mml_of_cic_object acic ids_to_inner_sorts in
+  let mml = mml_of_cic_object acic ids_to_inner_sorts ids_to_inner_types in
    output#load_tree mml ;
    current_cic_infos := Some (ids_to_terms,ids_to_father_ids)
 ;;
 
 let refresh_sequent (proofw : GMathView.math_view) =
- let metasenv =
-  match !ProofEngine.proof with
-     None -> assert false
-   | Some (metasenv,_,_) -> metasenv
- in
- let currentsequent =
-  match !ProofEngine.goal with
-     None -> assert false
-   | Some (_,sequent) -> sequent
- in
-  let sequent_gdome = SequentPp.XmlPp.print_sequent metasenv currentsequent in
-   let sequent_doc =
-    Xml2Gdome.document_of_xml domImpl sequent_gdome
-   in
-    let sequent_mml =
-     applyStylesheets sequent_doc sequent_styles sequent_args
-    in
-     proofw#load_tree ~dom:sequent_mml
+ match !ProofEngine.goal with
+    None -> proofw#unload
+  | Some (_,currentsequent) ->
+     let metasenv =
+      match !ProofEngine.proof with
+         None -> assert false
+       | Some (metasenv,_,_) -> metasenv
+     in
+      let sequent_gdome =
+       SequentPp.XmlPp.print_sequent metasenv currentsequent
+      in
+       let sequent_doc =
+        Xml2Gdome.document_of_xml domImpl sequent_gdome
+       in
+        let sequent_mml =
+         applyStylesheets sequent_doc sequent_styles sequent_args
+        in
+         proofw#load_tree ~dom:sequent_mml
 (*
 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
  ~name:"/public/sacerdot/guruguru1" ~indent:true ()) ;
@@ -197,10 +208,44 @@ ignore(domImpl#saveDocumentToFile ~doc:sequent_mml
 *)
 ;;
 
-let exact rendering_window () =
+let output_html outputhtml msg =
+ htmlheader_and_content := !htmlheader_and_content ^ msg ;
+ outputhtml#source (!htmlheader_and_content ^ htmlfooter)
+;;
+
+(***********************)
+(*       TACTICS       *)
+(***********************)
+
+let call_tactic tactic rendering_window () =
+ let proofw = (rendering_window#proofw : GMathView.math_view) in
+ let output = (rendering_window#output : GMathView.math_view) in
+ let output = (rendering_window#output : GMathView.math_view) in
+ let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
+ let savedproof = !ProofEngine.proof in
+ let savedgoal  = !ProofEngine.goal in
+  begin
+   try
+    tactic () ;
+    refresh_sequent proofw ;
+    refresh_proof output
+   with
+    e ->
+     output_html outputhtml
+      ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
+     ProofEngine.proof := savedproof ;
+     ProofEngine.goal := savedgoal ;
+  end
+;;
+
+let call_tactic_with_input tactic rendering_window () =
  let proofw = (rendering_window#proofw : GMathView.math_view) in
  let output = (rendering_window#output : GMathView.math_view) in
+ let output = (rendering_window#output : GMathView.math_view) in
+ let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
  let inputt = (rendering_window#inputt : GEdit.text) in
+ let savedproof = !ProofEngine.proof in
+ let savedgoal  = !ProofEngine.goal in
 (*CSC: Gran cut&paste da sotto... *)
   let inputlen = inputt#length in
   let input = inputt#get_chars 0 inputlen ^ "\n" in
@@ -215,43 +260,38 @@ let exact rendering_window () =
    in
     try
      while true do
-      (* Execute the actions *)
       match
        CicTextualParserContext.main context CicTextualLexer.token lexbuf
       with
          None -> ()
        | Some expr ->
-          try
-           ProofEngine.exact expr ;
-           proofw#unload ;
-           refresh_proof output
-          with
-           e ->
-            print_endline ("? " ^ CicPp.ppterm expr) ; flush stdout ;
-            raise e
+          tactic expr ;
+          refresh_sequent proofw ;
+          refresh_proof output
      done
     with
        CicTextualParser0.Eof ->
         inputt#delete_text 0 inputlen
      | e ->
-        print_endline ("Error: " ^ Printexc.to_string e) ; flush stdout
+prerr_endline ("? " ^ Printexc.to_string e) ; flush stderr ;
+        output_html outputhtml
+         ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>");
+        ProofEngine.proof := savedproof ;
+        ProofEngine.goal := savedgoal
 ;;
 
-let intros rendering_window () =
- let proofw = (rendering_window#proofw : GMathView.math_view) in
- let output = (rendering_window#output : GMathView.math_view) in
-  begin
-   try
-    ProofEngine.intros () ;
-   with
-    e ->
-     print_endline "? Intros " ;
-     raise e
-  end ;
-  refresh_sequent proofw ;
-  refresh_proof output
+let intros rendering_window = call_tactic ProofEngine.intros rendering_window;;
+let exact rendering_window =
+ call_tactic_with_input ProofEngine.exact rendering_window
+;;
+let apply rendering_window =
+ call_tactic_with_input ProofEngine.apply rendering_window
 ;;
 
+(**********************)
+(*   END OF TACTICS   *)
+(**********************)
+
 exception OpenConjecturesStillThere;;
 exception WrongProof;;
 
@@ -263,10 +303,15 @@ let save rendering_window () =
       begin
        (*CSC: Wrong: [] is just plainly wrong *)
        let proof = Cic.Definition ("unnamed",bo,ty,[]) in
-        let (acic, ids_to_terms, ids_to_father_ids, ids_to_inner_sorts) =
+        let
+         (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
+          ids_to_inner_types)
+        =
          Cic2acic.acic_object_of_cic_object proof
         in
-         let mml = mml_of_cic_object acic ids_to_inner_sorts in
+         let mml =
+          mml_of_cic_object acic ids_to_inner_sorts ids_to_inner_types
+         in
           (rendering_window#output : GMathView.math_view)#load_tree mml ;
           current_cic_infos := Some (ids_to_terms,ids_to_father_ids)
       end
@@ -305,11 +350,6 @@ let proveit rendering_window () =
  | None -> assert false (* "ERROR: No selection!!!" *)
 ;;
 
-let output_html outputhtml msg =
- htmlheader_and_content := !htmlheader_and_content ^ msg ;
- outputhtml#source (!htmlheader_and_content ^ htmlfooter)
-;;
-
 let state rendering_window () =
  let inputt = (rendering_window#inputt : GEdit.text) in
  let oldinputt = (rendering_window#oldinputt : GEdit.text) in
@@ -544,6 +584,9 @@ class rendering_window output proofw (label : GMisc.label) =
  let introsb =
   GButton.button ~label:"Intros"
    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
+ let applyb =
+  GButton.button ~label:"Apply"
+   ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
  let outputhtml =
   GHtml.xmhtml
    ~source:"<html><body bgColor=\"white\"></body></html>"
@@ -574,6 +617,7 @@ object(self)
   ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
   ignore(stateb#connect#clicked (state self)) ;
   ignore(exactb#connect#clicked (exact self)) ;
+  ignore(applyb#connect#clicked (apply self)) ;
   ignore(introsb#connect#clicked (intros self)) ;
   Logger.log_callback :=
    (Logger.log_to_html ~print_and_flush:(output_html outputhtml))