]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matita.ml
rebuilt against ocaml 3.08.3
[helm.git] / helm / matita / matita.ml
index b62587e1d229a389d88c7fc64e7006e35554f3b5..3052e975e5cab70b78f8a86f7137bba1cda31738 100644 (file)
@@ -41,10 +41,11 @@ let _ =
   ignore (GMain.Main.init ())
 
 let gui = MatitaGui.instance ()
+let disambiguator = MatitaDisambiguator.instance ()
 let _ = (* set disambiguator callbacks *)
-  let disambiguator = MatitaDisambiguator.instance () in
   disambiguator#setChooseUris (interactive_user_uri_choice ~gui);
   disambiguator#setChooseInterp (interactive_interp_choice ~gui)
+
 let _ = (* environment trust *)
   CicEnvironment.set_trust
     (let trust = Helm_registry.get_bool "matita.environment_trust" in
@@ -52,15 +53,8 @@ let _ = (* environment trust *)
 
 let currentProof = MatitaProof.instance ()
 
-
-let sequent_viewer = MatitaMathView.sequent_viewer ~show:true ()
-let sequents_viewer =
-  let set_goal goal =
-    if not (currentProof#onGoing ()) then assert false;
-    currentProof#proof#set_goal goal
-  in
-  MatitaMathView.sequents_viewer ~notebook:gui#main#sequentsNotebook
-    ~sequent_viewer ~set_goal ()
+let sequent_viewer = MatitaMathView.sequent_viewer_instance ()
+let sequents_viewer = MatitaMathView.sequents_viewer_instance ()
 let _ = (* attach observers to proof status *)
   let browser_observer _ _ = MatitaMathView.refresh_all_browsers () in
   let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
@@ -86,60 +80,45 @@ let _ = (* attach observers to proof status *)
 let interpreter =
   let mathViewer = MatitaMathView.mathViewer () in
   MatitaInterpreter.interpreter ~console:gui#console ~mathViewer ()
+let script = MatitaScript.script ~interpreter
 let _ =
   let href_callback uri =
-    let term = CicAst.Uri (UriManager.string_of_uri uri, None) in
+    let term = CicAst.Uri (uri, None) in
     ignore (interpreter#evalAst (TacticAst.Command (TacticAst.Check term)))
   in
   sequent_viewer#set_href_callback (Some href_callback)
 
-(** {2 Script window handling} *)
-
-let script_forward _ =
-  let buf = gui#script#scriptTextView#buffer in
-  let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
-  let (success, hide) =
-    interpreter#evalPhrase
-      (buf#get_text ~start:locked_iter ~stop:buf#end_iter ())
+let console_callback s =
+  let module A = TacticAst in
+  let rec strip_locations = function
+    | A.LocatedTactical (loc, tac) -> strip_locations tac
+    | tac -> tac
   in
-  if success then
-    gui#lockScript (locked_iter#offset + interpreter#endOffset)
-
-let script_jump _ =
-  let buf = gui#script#scriptTextView#buffer in
-  let locked_iter = buf#get_iter_at_mark (`NAME "locked") in
-  let cursor_iter = buf#get_iter_at_mark (`NAME "insert") in
-  let raw_text = buf#get_text ~start:locked_iter ~stop:cursor_iter () in
-  let len = String.length raw_text in
-  let rec parse offset =
-    if offset < len then begin
-      let (success, hide) =
-        interpreter#evalPhrase (String.sub raw_text offset (len - offset))
-      in
-      if success then begin
-        let new_offset = interpreter#endOffset + offset in
-        gui#lockScript (new_offset + locked_iter#offset);
-        parse new_offset
-      end else
-        raise Exit
-    end
+  let needed_by_script ast =
+    match strip_locations ast with
+    | A.Tactic _
+    | A.Command
+      (A.Inductive _ | A.Theorem _ | A.Coercion _ | A.Qed _ | A.Proof) ->
+        true
+    | _ -> false
   in
-  try
-    parse 0
-  with Exit -> ()
-
-let script_back _ = not_implemented "script_back"
-
-let load_script fname =
-  gui#script#scriptTextView#buffer#set_text (input_file fname);
-  gui#script#scriptWin#show ();
-  gui#main#showScriptMenuItem#set_active true
+  let ast = disambiguator#parserr#parseTactical (Stream.of_string s) in
+  debug_print (sprintf "evaluating '%s'" s);
+  if needed_by_script ast then
+    script#advance s
+  else
+    interpreter#evalAst ast
+
+let console_callback s =
+  match gui#console#wrap_exn (fun () -> console_callback s) with
+  | None -> (false, false)
+  | Some outcome -> outcome
 
 (** {2 GUI callbacks} *)
 
 let _ =
   gui#setQuitCallback currentProof#quit;
-  gui#setPhraseCallback interpreter#evalPhrase;
+  gui#setPhraseCallback console_callback;
   gui#main#debugMenu#misc#hide ();
   ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
     gui#console#clear ();
@@ -147,19 +126,20 @@ let _ =
   ignore (gui#main#openMenuItem#connect#activate (fun _ ->
     match gui#chooseFile () with
     | None -> ()
-    | Some f when is_proof_script f -> load_script f
+    | Some f when is_proof_script f ->
+        ignore (gui#console#wrap_exn (fun () -> script#loadFrom f))
     | Some f ->
         gui#console#echo_error (sprintf
           "Don't know what to do with file: %s\nUnrecognized file format."
           f)));
   ignore (gui#main#newCicBrowserMenuItem#connect#activate (fun _ ->
     ignore (MatitaMathView.cicBrowser ())));
-  connect_button gui#script#scriptWinForwardButton script_forward;
-  connect_button gui#script#scriptWinBackButton script_back;
-  connect_button gui#script#scriptWinJumpButton script_jump;
   let module A = TacticAst in
   let hole = CicAst.UserInput in
-  let tac ast _ = ignore (interpreter#evalAst (A.Tactic ast)) in
+  let tac ast _ =
+    let ast = A.Tactic ast in
+    ignore (script#advance (TacticAstPp.pp_tactical ast))
+  in
   let tac_w_term ast _ =
 (*     gui#console#clear (); *)
     gui#console#show ~msg:(TacticAstPp.pp_tactic ast) ();
@@ -212,11 +192,7 @@ let _ =
   (** </DEBUGGING> *)
 
 let _ =
-(*
-  (try
-    load_script Sys.argv.(1)
-  with Invalid_argument _ -> ());
-*)
+  (try script#loadFrom Sys.argv.(1) with Invalid_argument _ -> ());
   if Filename.basename Sys.argv.(0) = "cicbrowser" then begin (* cicbrowser *)
     Helm_registry.set "matita.mode" "cicbrowser";
     let browser = MatitaMathView.cicBrowser () in