]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaScript.ml
fix
[helm.git] / helm / matita / matitaScript.ml
index c35fb9307232975b1b8409005aea93bcc1810562..c8411d5cf4e0d5b40d45492bf6e5cfb627af02cd 100644 (file)
@@ -83,6 +83,9 @@ let eval_with_engine guistuff status user_goal parsed_text st =
         | None -> []
         | Some devel -> [MatitamakeLib.root_for_development devel ]
   in
+  let include_ =
+    include_ @ (Helm_registry.get_list Helm_registry.string "matita.includes")
+  in
   let parsed_text_length = String.length parsed_text in
   let loc, ex = 
     match st with TA.Executable (loc,ex) -> loc, ex | _ -> assert false in
@@ -98,7 +101,7 @@ let eval_with_engine guistuff status user_goal parsed_text st =
 (*     | Incomplete_proof { stack = stack }
       when not (List.mem user_goal (Continuationals.head_goals stack)) ->
         let status =
-          MatitaEngine.eval_ast ~include_paths:include_
+          MatitaEngine.eval_ast
             ~do_heavy_checks:true status (goal_ast user_goal)
         in
         let initial_space = if initial_space = "" then "\n" else initial_space
@@ -109,9 +112,10 @@ let eval_with_engine guistuff status user_goal parsed_text st =
       | _ -> initial_space,status,[] in
   let new_status = 
     GrafiteEngine.eval_ast
+      ~baseuri_of_script:(GrafiteParserMisc.baseuri_of_script ~include_paths:include_)
       ~disambiguate_tactic:GrafiteDisambiguate.disambiguate_tactic
       ~disambiguate_command:GrafiteDisambiguate.disambiguate_command
-      ~include_paths:include_ ~do_heavy_checks:true new_status st 
+      ~do_heavy_checks:true new_status st 
   in
   let new_aliases =
     match ex with
@@ -163,7 +167,7 @@ let eval_with_engine guistuff status user_goal parsed_text st =
   try
     eval_with_engine guistuff status user_goal parsed_text st
   with
-  | GrafiteEngine.UnableToInclude what 
+  | GrafiteParserMisc.UnableToInclude what 
   | GrafiteEngine.IncludedFileNotCompiled what as exc ->
       let compile_needed_and_go_on d =
         let target = what in
@@ -225,6 +229,10 @@ let disambiguate_macro_term term status user_goal =
   match interps with 
   | [_,_,x,_], _ -> x
   | _ -> assert false
+
+let pp_eager_statement_ast =
+  GrafiteAstPp.pp_statement ~term_pp:CicNotationPp.pp_term
+    ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
  
 let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
   let module TAPp = GrafiteAstPp in
@@ -235,6 +243,8 @@ let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
   (* no idea why ocaml wants this *)
   let parsed_text_length = String.length parsed_text in
   let dbd = LibraryDb.instance () in
+  (* XXX use a real CIC -> string pretty printer *)
+  let pp_macro = TAPp.pp_macro ~term_pp:CicPp.ppterm in
   match mac with
   (* WHELP's stuff *)
   | TA.WMatch (loc, term) -> 
@@ -250,12 +260,12 @@ let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
   | TA.WInstance (loc, term) ->
       let term = disambiguate_macro_term term status user_goal in
       let l = Whelp.instance ~dbd term in
-      let entry = `Whelp (TAPp.pp_macro_cic (TA.WInstance (loc, term)), l) in
+      let entry = `Whelp (pp_macro (TA.WInstance (loc, term)), l) in
       guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
       [], parsed_text_length
   | TA.WLocate (loc, s) -> 
       let l = Whelp.locate ~dbd s in
-      let entry = `Whelp (TAPp.pp_macro_cic (TA.WLocate (loc, s)), l) in
+      let entry = `Whelp (pp_macro (TA.WLocate (loc, s)), l) in
       guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
       [], parsed_text_length
   | TA.WElim (loc, term) ->
@@ -266,14 +276,14 @@ let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
         | _ -> failwith "Not a MutInd"
       in
       let l = Whelp.elim ~dbd uri in
-      let entry = `Whelp (TAPp.pp_macro_cic (TA.WElim (loc, term)), l) in
+      let entry = `Whelp (pp_macro (TA.WElim (loc, term)), l) in
       guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
       [], parsed_text_length
   | TA.WHint (loc, term) ->
       let term = disambiguate_macro_term term status user_goal in
       let s = ((None,[0,[],term], Cic.Meta (0,[]) ,term),0) in
       let l = List.map fst (MQ.experimental_hint ~dbd s) in
-      let entry = `Whelp (TAPp.pp_macro_cic (TA.WHint (loc, term)), l) in
+      let entry = `Whelp (pp_macro (TA.WHint (loc, term)), l) in
       guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
       [], parsed_text_length
   (* REAL macro *)
@@ -294,13 +304,12 @@ let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
           in
         let new_status =
          GrafiteEngine.eval_ast
+          ~baseuri_of_script:(fun _ -> assert false)
           ~disambiguate_tactic:GrafiteDisambiguate.disambiguate_tactic
           ~disambiguate_command:GrafiteDisambiguate.disambiguate_command
           status ast in
         let extra_text = 
-          comment parsed_text ^ 
-          "\n" ^ TAPp.pp_statement ast
-        in
+          comment parsed_text ^ "\n" ^ pp_eager_statement_ast ast in
         [ new_status , (extra_text, ast) ], parsed_text_length
       | _ -> 
           HLog.error 
@@ -356,7 +365,7 @@ let eval_executable guistuff status user_goal unparsed_text parsed_text script
   match ex with
   | TA.Command (loc, _) | TA.Tactical (loc, _, _) ->
       (try 
-        (match GrafiteMisc.baseuri_of_baseuri_decl (TA.Executable (loc,ex)) with
+        (match GrafiteParserMisc.baseuri_of_baseuri_decl (TA.Executable (loc,ex)) with
         | None -> ()
         | Some u -> 
             if not (GrafiteMisc.is_empty u) then
@@ -373,8 +382,8 @@ let eval_executable guistuff status user_goal unparsed_text parsed_text script
                    LibraryClean.clean_baseuris ~basedir [u]
               | `NO -> ()
               | `CANCEL -> raise MatitaTypes.Cancel);
-        eval_with_engine 
-          guistuff status user_goal parsed_text (TA.Executable (loc, ex))
+        eval_with_engine
+         guistuff status user_goal parsed_text (TA.Executable (loc, ex))
       with MatitaTypes.Cancel -> [], 0)
   | TA.Macro (_,mac) ->
       eval_macro guistuff status user_goal unparsed_text parsed_text script mac
@@ -425,7 +434,6 @@ let fresh_script_id =
   fun () -> incr i; !i
 
 class script  ~(source_view: GSourceView.source_view)
-              ~(init: GrafiteTypes.status) 
               ~(mathviewer: MatitaTypes.mathViewer) 
               ~set_star
               ~ask_confirmation
@@ -461,7 +469,7 @@ object (self)
       (fun _ -> set_star (Filename.basename self#ppFilename) buffer#modified))
 
   val mutable statements = [];    (** executed statements *)
-  val mutable history = [ init ];
+  val mutable history = [ MatitaSync.init () ];
     (** list of states before having executed statements. Head element of this
       * list is the current state, last element is the state at the beginning of
       * the script.
@@ -499,15 +507,14 @@ object (self)
       let start = buffer#get_iter_at_mark (`MARK locked_mark) in
       let new_text = String.concat "" new_statements in
       if statement <> None then
-       buffer#insert ~iter:start new_text
-      else
+        buffer#insert ~iter:start new_text
+      else begin
         let s = match st with `Raw s | `Ast (_, s) -> s in
-        if new_text <> String.sub s 0 parsed_len then
-        begin
-          let stop = start#copy#forward_chars parsed_len in
-          buffer#delete ~start ~stop;
+        if new_text <> String.sub s 0 parsed_len then begin
+          buffer#delete ~start ~stop:(start#copy#forward_chars parsed_len);
           buffer#insert ~iter:start new_text;
         end;
+      end;
       self#moveMark (String.length new_text);
       (*
       (match List.rev new_asts with (* advance again on punctuation *)
@@ -632,11 +639,20 @@ object (self)
       end
   
   method private goto_top =
+    let init = 
+      let rec last x = function 
+      | [] -> x
+      | hd::tl -> last hd tl
+      in
+      last self#status history
+    in
+    (* FIXME: this is not correct since there is no undo for 
+     * library_objects.set_default... *)
     MatitaSync.time_travel ~present:self#status ~past:init
 
   method private reset_buffer = 
     statements <- [];
-    history <- [ init ];
+    history <- [ MatitaSync.init () ];
     userGoal <- ~-1;
     self#notify;
     buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
@@ -647,7 +663,7 @@ object (self)
     source_buffer#begin_not_undoable_action ();
     buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter;
     source_buffer#end_not_undoable_action ();
-    buffer#set_modified false
+    buffer#set_modified false;
   
   method template () =
     let template = HExtlib.input_file BuildTimeConf.script_template in 
@@ -784,10 +800,10 @@ end
 
 let _script = ref None
 
-let script ~source_view ~init ~mathviewer ~urichooser ~develcreator ~ask_confirmation ~set_star ()
+let script ~source_view ~mathviewer ~urichooser ~develcreator ~ask_confirmation ~set_star ()
 =
   let s = new script 
-    ~source_view ~init ~mathviewer ~ask_confirmation ~urichooser ~develcreator ~set_star () 
+    ~source_view ~mathviewer ~ask_confirmation ~urichooser ~develcreator ~set_star () 
   in
   _script := Some s;
   s