1 (* Copyright (C) 2004-2005, 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://helm.cs.unibo.it/
29 module TA = GrafiteAst
32 let debug_print = if debug then prerr_endline else ignore
34 (** raised when one of the script margins (top or bottom) is reached *)
37 let safe_substring s i j =
38 try String.sub s i j with Invalid_argument _ -> assert false
40 let heading_nl_RE = Pcre.regexp "^\\s*\n\\s*"
41 let heading_nl_RE' = Pcre.regexp "^(\\s*\n\\s*)((.|\n)*)"
42 let only_dust_RE = Pcre.regexp "^(\\s|\n|%%[^\n]*\n)*$"
43 let multiline_RE = Pcre.regexp "^\n[^\n]+$"
44 let newline_RE = Pcre.regexp "\n"
47 if Pcre.pmatch ~rex:multiline_RE str then
48 "\n(** " ^ (Pcre.replace ~rex:newline_RE str) ^ " *)"
50 "\n(**\n" ^ str ^ "\n*)"
53 let s = Pcre.replace ~rex:heading_nl_RE s in
55 let nl_pos = String.index s '\n' in
59 (** creates a statement AST for the Goal tactic, e.g. "goal 7" *)
61 let module A = GrafiteAst in
62 let loc = DisambiguateTypes.dummy_floc in
63 A.Executable (loc, A.Tactical (loc,
64 A.Tactic (loc, A.Goal (loc, n)),
68 mathviewer:MatitaTypes.mathViewer;
69 urichooser: UriManager.uri list -> UriManager.uri list;
70 ask_confirmation: title:string -> message:string -> [`YES | `NO | `CANCEL];
71 develcreator: containing:string option -> unit;
72 mutable filenamedata: string option * MatitamakeLib.development option
75 let eval_with_engine guistuff status user_goal parsed_text st =
76 let module TAPp = GrafiteAstPp in
78 match guistuff.filenamedata with
80 | None,Some devel -> [MatitamakeLib.root_for_development devel ]
82 match MatitamakeLib.development_for_dir (Filename.dirname f) with
84 | Some devel -> [MatitamakeLib.root_for_development devel ]
86 let parsed_text_length = String.length parsed_text in
88 match st with TA.Executable (loc,ex) -> loc, ex | _ -> assert false in
89 let initial_space,parsed_text =
91 let pieces = Pcre.extract ~rex:heading_nl_RE' parsed_text in
92 pieces.(1), pieces.(2)
94 Not_found -> "", parsed_text in
95 (* we add the goal command if needed *)
96 let inital_space,new_status,new_status_and_text_list' =
97 match status.proof_status with
98 (* | Incomplete_proof { stack = stack }
99 when not (List.mem user_goal (Continuationals.head_goals stack)) ->
101 MatitaEngine.eval_ast ~include_paths:include_
102 ~do_heavy_checks:true status (goal_ast user_goal)
104 let initial_space = if initial_space = "" then "\n" else initial_space
108 initial_space ^ TAPp.pp_tactical (TA.Select (loc, [user_goal])) ] *)
109 | _ -> initial_space,status,[] in
111 MatitaEngine.eval_ast
112 ~include_paths:include_ ~do_heavy_checks:true new_status st
116 | TA.Command (_, TA.Alias _)
117 | TA.Command (_, TA.Include _)
118 | TA.Command (_, TA.Interpretation _) -> []
119 | _ -> MatitaSync.alias_diff ~from:status new_status
121 (* we remove the defined object since we consider them "automatic aliases" *)
123 TA.Comment (DisambiguateTypes.dummy_floc,
124 TA.Note (DisambiguateTypes.dummy_floc, ""))
126 let initial_space,status,new_status_and_text_list_rev =
127 let module DTE = DisambiguateTypes.Environment in
128 let module UM = UriManager in
130 fun (initial_space,status,acc) (k,((v,_) as value)) ->
133 let v = UM.strip_xpointer (UM.uri_of_string v) in
134 List.exists (fun (s,_) -> s = v) new_status.objects
135 with UM.IllFormedUri _ -> false
138 initial_space,status,acc
142 if initial_space = "" then "\n" else initial_space in
144 DisambiguatePp.pp_environment
145 (DisambiguateTypes.Environment.add k value
146 DisambiguateTypes.Environment.empty) in
148 MatitaSync.set_proof_aliases status [k,value]
150 "\n",new_status,((new_status, (new_text, dummy_st))::acc)
151 ) (initial_space,status,[]) new_aliases in
152 let parsed_text = initial_space ^ parsed_text in
154 List.rev new_status_and_text_list_rev @ new_status_and_text_list' @
155 [new_status, (parsed_text, st)]
157 res,parsed_text_length
159 let eval_with_engine guistuff status user_goal parsed_text st =
161 eval_with_engine guistuff status user_goal parsed_text st
163 | MatitaEngine.UnableToInclude what
164 | MatitaEngine.IncludedFileNotCompiled what as exc ->
165 let compile_needed_and_go_on d =
168 while Glib.Main.pending () do ignore(Glib.Main.iteration false); done
170 if not(MatitamakeLib.build_development_in_bg ~target refresh_cb d) then
173 eval_with_engine guistuff status user_goal parsed_text st
175 let do_nothing () = [], 0 in
176 let handle_with_devel d =
177 let name = MatitamakeLib.name_for_development d in
178 let title = "Unable to include " ^ what in
180 what ^ " is handled by development <b>" ^ name ^ "</b>.\n\n" ^
181 "<i>Should I compile it and Its dependencies?</i>"
183 (match guistuff.ask_confirmation ~title ~message with
184 | `YES -> compile_needed_and_go_on d
186 | `CANCEL -> do_nothing ())
188 let handle_without_devel filename =
189 let title = "Unable to include " ^ what in
191 what ^ " is <b>not</b> handled by a development.\n" ^
192 "All dependencies are automatically solved for a development.\n\n" ^
193 "<i>Do you want to set up a development?</i>"
195 (match guistuff.ask_confirmation ~title ~message with
199 guistuff.develcreator ~containing:(Some (Filename.dirname f))
200 | None -> guistuff.develcreator ~containing:None);
203 | `CANCEL -> do_nothing())
205 match guistuff.filenamedata with
206 | None,None -> handle_without_devel None
207 | None,Some d -> handle_with_devel d
209 match MatitamakeLib.development_for_dir (Filename.dirname f) with
210 | None -> handle_without_devel (Some f)
211 | Some d -> handle_with_devel d
214 let disambiguate_macro_term term status user_goal =
215 let module MD = MatitaDisambiguator in
216 let dbd = MatitaDb.instance () in
217 let metasenv = MatitaTypes.get_proof_metasenv status in
218 let context = MatitaTypes.get_proof_context status user_goal in
220 MD.disambiguate_term ~dbd ~context ~metasenv ~aliases:status.aliases
221 ~universe:(Some status.multi_aliases) term in
226 let eval_macro guistuff status user_goal unparsed_text parsed_text script mac =
227 let module TAPp = GrafiteAstPp in
228 let module MQ = MetadataQuery in
229 let module MDB = MatitaDb in
230 let module CTC = CicTypeChecker in
231 let module CU = CicUniv in
232 (* no idea why ocaml wants this *)
233 let advance ?statement () = script#advance ?statement () in
234 let parsed_text_length = String.length parsed_text in
235 let dbd = MatitaDb.instance () in
238 | TA.WMatch (loc, term) ->
239 let term = disambiguate_macro_term term status user_goal in
240 let l = MQ.match_term ~dbd term in
242 MatitaMisc.strip_suffix ~suffix:"."
243 (HExtlib.trim_blanks unparsed_text)
245 let entry = `Whelp (query_url, l) in
246 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
247 [], parsed_text_length
248 | TA.WInstance (loc, term) ->
249 let term = disambiguate_macro_term term status user_goal in
250 let l = MQ.instance ~dbd term in
251 let entry = `Whelp (TAPp.pp_macro_cic (TA.WInstance (loc, term)), l) in
252 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
253 [], parsed_text_length
254 | TA.WLocate (loc, s) ->
255 let l = MQ.locate ~dbd s in
256 let entry = `Whelp (TAPp.pp_macro_cic (TA.WLocate (loc, s)), l) in
257 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
258 [], parsed_text_length
259 | TA.WElim (loc, term) ->
260 let term = disambiguate_macro_term term status user_goal in
263 | Cic.MutInd (uri,n,_) -> UriManager.uri_of_uriref uri n None
264 | _ -> failwith "Not a MutInd"
266 let l = MQ.elim ~dbd uri in
267 let entry = `Whelp (TAPp.pp_macro_cic (TA.WElim (loc, term)), l) in
268 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
269 [], parsed_text_length
270 | TA.WHint (loc, term) ->
271 let term = disambiguate_macro_term term status user_goal in
272 let s = ((None,[0,[],term], Cic.Meta (0,[]) ,term),0) in
273 let l = List.map fst (MQ.experimental_hint ~dbd s) in
274 let entry = `Whelp (TAPp.pp_macro_cic (TA.WHint (loc, term)), l) in
275 guistuff.mathviewer#show_uri_list ~reuse:true ~entry l;
276 [], parsed_text_length
279 let proof = MatitaTypes.get_current_proof status in
280 let proof_status = proof, user_goal in
281 let l = List.map fst (MQ.experimental_hint ~dbd proof_status) in
282 let selected = guistuff.urichooser l in
284 | [] -> [], parsed_text_length
286 let suri = UriManager.string_of_uri uri in
288 TA.Executable (loc, (TA.Tactical (loc,
290 TA.Apply (loc, CicNotationPt.Uri (suri, None))),
293 let new_status = MatitaEngine.eval_ast status ast in
295 comment parsed_text ^
296 "\n" ^ TAPp.pp_statement ast
298 [ new_status , (extra_text, ast) ], parsed_text_length
301 "The result of the urichooser should be only 1 uri, not:\n";
303 fun u -> MatitaLog.error (UriManager.string_of_uri u ^ "\n")
306 | TA.Check (_,term) ->
307 let metasenv = MatitaTypes.get_proof_metasenv status in
308 let context = MatitaTypes.get_proof_context status user_goal in
310 MatitaDisambiguator.disambiguate_term ~dbd ~context ~metasenv
311 ~aliases:status.aliases ~universe:(Some status.multi_aliases) term
313 let _, metasenv , term, ugraph =
318 let ty,_ = CTC.type_of_aux' metasenv context term ugraph in
319 let t_and_ty = Cic.Cast (term,ty) in
320 guistuff.mathviewer#show_entry (`Cic (t_and_ty,metasenv));
321 [], parsed_text_length
324 let status = script#status.proof_status in
327 | _ -> script#retract ();go_back()
329 [], parsed_text_length, Some go_back
330 | TA.Redo (_, Some i) -> [], parsed_text_length,
331 Some (fun () -> for j = 1 to i do advance () done)
332 | TA.Redo (_, None) -> [], parsed_text_length,
333 Some (fun () -> advance ())
334 | TA.Undo (_, Some i) -> [], parsed_text_length,
335 Some (fun () -> for j = 1 to i do script#retract () done)
336 | TA.Undo (_, None) -> [], parsed_text_length,
337 Some (fun () -> script#retract ()) *)
339 | TA.Quit _ -> failwith "not implemented"
340 | TA.Print (_,kind) -> failwith "not implemented"
341 | TA.Search_pat (_, search_kind, str) -> failwith "not implemented"
342 | TA.Search_term (_, search_kind, term) -> failwith "not implemented"
344 let eval_executable guistuff status user_goal unparsed_text parsed_text script
347 let module TAPp = GrafiteAstPp in
348 let module MD = MatitaDisambiguator in
349 let module ML = MatitacleanLib in
350 let parsed_text_length = String.length parsed_text in
352 | TA.Command (loc, _) | TA.Tactical (loc, _, _) ->
354 (match MatitaMisc.baseuri_of_baseuri_decl (TA.Executable (loc,ex)) with
357 if not (MatitaMisc.is_empty u) then
359 guistuff.ask_confirmation
360 ~title:"Baseuri redefinition"
362 "Baseuri " ^ u ^ " already exists.\n" ^
363 "Do you want to redefine the corresponding "^
364 "part of the library?")
366 | `YES -> MatitacleanLib.clean_baseuris [u]
368 | `CANCEL -> raise MatitaTypes.Cancel);
370 guistuff status user_goal parsed_text (TA.Executable (loc, ex))
371 with MatitaTypes.Cancel -> [], 0)
372 | TA.Macro (_,mac) ->
373 eval_macro guistuff status user_goal unparsed_text parsed_text script mac
375 let rec eval_statement (buffer : GText.buffer) guistuff status user_goal
378 let st, unparsed_text =
381 if Pcre.pmatch ~rex:only_dust_RE text then raise Margin;
382 GrafiteParser.parse_statement (Ulexing.from_utf8_string text), text
383 | `Ast (st, text) -> st, text
385 let text_of_loc loc =
386 let parsed_text_length = snd (HExtlib.loc_of_floc loc) in
387 let parsed_text = safe_substring unparsed_text 0 parsed_text_length in
388 parsed_text, parsed_text_length
391 | GrafiteAst.Comment (loc, _) ->
392 let parsed_text, parsed_text_length = text_of_loc loc in
393 let remain_len = String.length unparsed_text - parsed_text_length in
394 let s = String.sub unparsed_text parsed_text_length remain_len in
397 eval_statement buffer guistuff status user_goal script
399 with HExtlib.Localized (floc, exn) ->
400 HExtlib.raise_localized_exception
401 ~offset:parsed_text_length floc exn
404 | (status, (text, ast)) :: tl ->
405 ((status, (parsed_text ^ text, ast))::tl), (parsed_text_length + len)
407 | GrafiteAst.Executable (loc, ex) ->
408 let parsed_text, parsed_text_length = text_of_loc loc in
409 eval_executable guistuff status user_goal unparsed_text parsed_text
412 let fresh_script_id =
416 class script ~(source_view: GSourceView.source_view)
417 ~(init: MatitaTypes.status)
418 ~(mathviewer: MatitaTypes.mathViewer)
424 let buffer = source_view#buffer in
425 let source_buffer = source_view#source_buffer in
427 val scriptId = fresh_script_id ()
430 mathviewer = mathviewer;
431 urichooser = urichooser;
432 ask_confirmation = ask_confirmation;
433 develcreator = develcreator;
434 filenamedata = (None, None)}
436 method private getFilename =
437 match guistuff.filenamedata with Some f,_ -> f | _ -> assert false
439 method filename = self#getFilename
441 method private ppFilename =
442 match guistuff.filenamedata with
444 | None,_ -> sprintf ".unnamed%d.ma" scriptId
447 ignore (GMain.Timeout.add ~ms:300000
448 ~callback:(fun _ -> self#_saveToBackupFile ();true));
449 ignore (buffer#connect#modified_changed
450 (fun _ -> set_star (Filename.basename self#ppFilename) buffer#modified))
452 val mutable statements = []; (** executed statements *)
453 val mutable history = [ init ];
454 (** list of states before having executed statements. Head element of this
455 * list is the current state, last element is the state at the beginning of
457 * Invariant: this list length is 1 + length of statements *)
459 (** goal as seen by the user (i.e. metano corresponding to current tab) *)
460 val mutable userGoal = ~-1
462 (** text mark and tag representing locked part of a script *)
464 buffer#create_mark ~name:"locked" ~left_gravity:true buffer#start_iter
465 val locked_tag = buffer#create_tag [`BACKGROUND "lightblue"; `EDITABLE false]
466 val error_tag = buffer#create_tag [`UNDERLINE `SINGLE; `FOREGROUND "red"]
468 method locked_mark = locked_mark
469 method locked_tag = locked_tag
470 method error_tag = error_tag
472 (* history can't be empty, the invariant above grant that it contains at
473 * least the init status *)
474 method status = match history with hd :: _ -> hd | _ -> assert false
476 method private _advance ?statement () =
478 let (entries, parsed_len) =
479 eval_statement buffer guistuff self#status userGoal self st
481 let (new_statuses, new_statements, new_asts) =
482 let statuses, statements = List.split entries in
483 let texts, asts = List.split statements in
484 statuses, texts, asts
486 history <- List.rev new_statuses @ history;
487 statements <- List.rev new_statements @ statements;
488 let start = buffer#get_iter_at_mark (`MARK locked_mark) in
489 let new_text = String.concat "" new_statements in
490 if statement <> None then
491 buffer#insert ~iter:start new_text
493 let s = match st with `Raw s | `Ast (_, s) -> s in
494 if new_text <> String.sub s 0 parsed_len then
496 let stop = start#copy#forward_chars parsed_len in
497 buffer#delete ~start ~stop;
498 buffer#insert ~iter:start new_text;
500 self#moveMark (String.length new_text);
502 (match List.rev new_asts with (* advance again on punctuation *)
503 | TA.Executable (_, TA.Tactical (_, tac, _)) :: _ ->
505 (buffer#get_iter_at_mark (`MARK locked_mark))#offset
507 let text = self#getFuture in
509 (match parse_statement baseoffset 0 buffer text with
510 | TA.Executable (loc, TA.Tactical (_, tac, None)) as st
511 when GrafiteAst.is_punctuation tac ->
512 let len = snd (CicNotationPt.loc_of_floc loc) in
513 aux (`Ast (st, String.sub text 0 len))
515 with CicNotationParser.Parse_error _ | End_of_file -> ())
519 let s = match statement with Some s -> s | None -> self#getFuture in
520 MatitaLog.debug ("evaluating: " ^ first_line s ^ " ...");
521 (try aux (`Raw s) with End_of_file -> raise Margin)
523 method private _retract offset status new_statements new_history =
524 let cur_status = match history with s::_ -> s | [] -> assert false in
525 MatitaSync.time_travel ~present:cur_status ~past:status;
526 statements <- new_statements;
527 history <- new_history;
528 self#moveMark (- offset)
530 method advance ?statement () =
532 self#_advance ?statement ();
535 | Margin -> self#notify
536 | exc -> self#notify; raise exc
540 let cmp,new_statements,new_history,status =
541 match statements,history with
542 stat::statements, _::(status::_ as history) ->
543 String.length stat, statements, history, status
544 | [],[_] -> raise Margin
545 | _,_ -> assert false
547 self#_retract cmp status new_statements new_history;
550 | Margin -> self#notify
551 | exc -> self#notify; raise exc
553 method private getFuture =
554 buffer#get_text ~start:(buffer#get_iter_at_mark (`MARK locked_mark))
555 ~stop:buffer#end_iter ()
558 (** @param rel_offset relative offset from current position of locked_mark *)
559 method private moveMark rel_offset =
560 let mark = `MARK locked_mark in
561 let old_insert = buffer#get_iter_at_mark `INSERT in
562 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
563 let current_mark_pos = buffer#get_iter_at_mark mark in
565 match rel_offset with
566 | 0 -> current_mark_pos
567 | n when n > 0 -> current_mark_pos#forward_chars n
568 | n (* when n < 0 *) -> current_mark_pos#backward_chars (abs n)
570 buffer#move_mark mark ~where:new_mark_pos;
571 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:new_mark_pos;
572 buffer#move_mark `INSERT old_insert;
573 let mark_position = buffer#get_iter_at_mark mark in
574 if source_view#move_mark_onscreen mark then
576 buffer#move_mark mark mark_position;
577 source_view#scroll_to_mark ~use_align:true ~xalign:1.0 ~yalign:0.1 mark;
579 while Glib.Main.pending () do ignore(Glib.Main.iteration false); done
581 method clean_dirty_lock =
582 let lock_mark_iter = buffer#get_iter_at_mark (`MARK locked_mark) in
583 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
584 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:lock_mark_iter
586 val mutable observers = []
588 method addObserver (o: MatitaTypes.status -> unit) =
589 observers <- o :: observers
591 method private notify =
592 let status = self#status in
593 List.iter (fun o -> o status) observers
595 method loadFromFile f =
596 buffer#set_text (HExtlib.input_file f);
598 buffer#set_modified false
600 method assignFileName file =
601 let abspath = MatitaMisc.absolute_path file in
602 let devel = MatitamakeLib.development_for_dir (Filename.dirname abspath) in
603 guistuff.filenamedata <- Some abspath, devel
605 method saveToFile () =
606 let oc = open_out self#getFilename in
607 output_string oc (buffer#get_text ~start:buffer#start_iter
608 ~stop:buffer#end_iter ());
610 buffer#set_modified false
612 method private _saveToBackupFile () =
613 if buffer#modified then
615 let f = self#ppFilename ^ "~" in
616 let oc = open_out f in
617 output_string oc (buffer#get_text ~start:buffer#start_iter
618 ~stop:buffer#end_iter ());
620 MatitaLog.debug ("backup " ^ f ^ " saved")
623 method private goto_top =
624 MatitaSync.time_travel ~present:self#status ~past:init
626 method private reset_buffer =
631 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
632 buffer#move_mark (`MARK locked_mark) ~where:buffer#start_iter
636 source_buffer#begin_not_undoable_action ();
637 buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter;
638 source_buffer#end_not_undoable_action ();
639 buffer#set_modified false
642 let template = HExtlib.input_file BuildTimeConf.script_template in
643 buffer#insert ~iter:(buffer#get_iter `START) template;
644 guistuff.filenamedata <-
645 (None,MatitamakeLib.development_for_dir (Unix.getcwd ()));
646 buffer#set_modified false;
647 set_star (Filename.basename self#ppFilename) false
649 method goto (pos: [`Top | `Bottom | `Cursor]) () =
650 let old_locked_mark =
652 (buffer#create_mark ~name:"old_locked_mark"
653 ~left_gravity:true (buffer#get_iter_at_mark (`MARK locked_mark))) in
654 let getpos _ = buffer#get_iter_at_mark (`MARK locked_mark) in
655 let getoldpos _ = buffer#get_iter_at_mark old_locked_mark in
656 let dispose_old_locked_mark () = buffer#delete_mark old_locked_mark in
659 dispose_old_locked_mark ();
667 let newpos = getpos () in
668 if (getoldpos ())#compare newpos < 0 then
670 buffer#move_mark old_locked_mark newpos;
675 dispose_old_locked_mark ();
678 | Margin -> dispose_old_locked_mark (); self#notify
679 | exc -> dispose_old_locked_mark (); self#notify; raise exc)
681 let locked_iter () = buffer#get_iter_at_mark (`NAME "locked") in
682 let cursor_iter () = buffer#get_iter_at_mark `INSERT in
685 (buffer#create_mark ~name:"initial_insert"
686 ~left_gravity:true (cursor_iter ())) in
687 let dispose_remember () = buffer#delete_mark remember in
688 let remember_iter () =
689 buffer#get_iter_at_mark (`NAME "initial_insert") in
690 let cmp () = (locked_iter ())#offset - (remember_iter ())#offset in
692 let forward_until_cursor () = (* go forward until locked > cursor *)
695 if cmp () < 0 && (getoldpos ())#compare (getpos ()) < 0
698 buffer#move_mark old_locked_mark (getpos ());
704 let rec back_until_cursor len = (* go backward until locked < cursor *)
706 statements, (status::_ as history) when len <= 0 ->
707 self#_retract (icmp - len) status statements history
708 | statement::tl1, _::tl2 ->
709 back_until_cursor (len - String.length statement) (tl1,tl2)
710 | _,_ -> assert false
714 if icmp < 0 then (* locked < cursor *)
715 (forward_until_cursor (); self#notify)
716 else if icmp > 0 then (* locked > cursor *)
717 (back_until_cursor icmp (statements,history); self#notify)
718 else (* cursor = locked *)
722 dispose_old_locked_mark ();
724 | Margin -> dispose_remember (); dispose_old_locked_mark (); self#notify
725 | exc -> dispose_remember (); dispose_old_locked_mark ();
726 self#notify; raise exc)
728 method onGoingProof () =
729 match self#status.proof_status with
730 | No_proof | Proof _ -> false
731 | Incomplete_proof _ -> true
732 | Intermediate _ -> assert false
734 (* method proofStatus = MatitaTypes.get_proof_status self#status *)
735 method proofMetasenv = MatitaTypes.get_proof_metasenv self#status
736 method proofContext = MatitaTypes.get_proof_context self#status userGoal
737 method proofConclusion = MatitaTypes.get_proof_conclusion self#status userGoal
738 method stack = MatitaTypes.get_stack self#status
739 method setGoal n = userGoal <- n
740 method goal = userGoal
743 let s = self#getFuture in
744 let rec is_there_and_executable s =
745 if Pcre.pmatch ~rex:only_dust_RE s then raise Margin;
746 let st = GrafiteParser.parse_statement (Ulexing.from_utf8_string s) in
748 | GrafiteAst.Comment (loc,_)->
749 let parsed_text_length = snd (HExtlib.loc_of_floc loc) in
750 let remain_len = String.length s - parsed_text_length in
751 let next = String.sub s parsed_text_length remain_len in
752 is_there_and_executable next
753 | GrafiteAst.Executable (loc, ex) -> false
756 is_there_and_executable s
758 | CicNotationParser.Parse_error _ -> false
759 | Margin | End_of_file -> true
763 MatitaLog.debug "script status:";
764 MatitaLog.debug ("history size: " ^ string_of_int (List.length history));
765 MatitaLog.debug (sprintf "%d statements:" (List.length statements));
766 List.iter MatitaLog.debug statements;
767 MatitaLog.debug ("Current file name: " ^
768 (match guistuff.filenamedata with
769 |None,_ -> "[ no name ]"
774 let _script = ref None
776 let script ~source_view ~init ~mathviewer ~urichooser ~develcreator ~ask_confirmation ~set_star ()
779 ~source_view ~init ~mathviewer ~ask_confirmation ~urichooser ~develcreator ~set_star ()
784 let current () = match !_script with None -> assert false | Some s -> s