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/
31 module TA = GrafiteAst
34 let debug_print = if debug then prerr_endline else ignore
36 (** raised when one of the script margins (top or bottom) is reached *)
38 exception NoUnfinishedProof
39 exception ActionCancelled of string
41 let safe_substring s i j =
42 try String.sub s i j with Invalid_argument _ -> assert false
44 let heading_nl_RE = Pcre.regexp "^\\s*\n\\s*"
45 let heading_nl_RE' = Pcre.regexp "^(\\s*\n\\s*)"
46 let only_dust_RE = Pcre.regexp "^(\\s|\n|%%[^\n]*\n)*$"
47 let multiline_RE = Pcre.regexp "^\n[^\n]+$"
48 let newline_RE = Pcre.regexp "\n"
49 let comment_RE = Pcre.regexp "\\(\\*(.|\n)*\\*\\)\n?" ~flags:[`UNGREEDY]
52 if Pcre.pmatch ~rex:multiline_RE str then
53 "\n(** " ^ (Pcre.replace ~rex:newline_RE str) ^ " *)"
55 "\n(**\n" ^ str ^ "\n*)"
57 let strip_comments str =
58 Pcre.qreplace ~templ:"\n" ~pat:"\n\n" (Pcre.qreplace ~rex:comment_RE str)
62 let s = Pcre.replace ~rex:heading_nl_RE s in
64 let nl_pos = String.index s '\n' in
69 mathviewer:MatitaTypes.mathViewer;
70 urichooser: UriManager.uri list -> UriManager.uri list;
71 ask_confirmation: title:string -> message:string -> [`YES | `NO | `CANCEL];
74 let eval_with_engine include_paths guistuff grafite_status user_goal
75 skipped_txt nonskipped_txt st
77 let parsed_text_length =
78 String.length skipped_txt + String.length nonskipped_txt
80 let text = skipped_txt ^ nonskipped_txt in
81 let prefix_len = MatitaGtkMisc.utf8_string_length skipped_txt in
82 let enriched_history_fragment =
83 MatitaEngine.eval_ast ~do_heavy_checks:(Helm_registry.get_bool
84 "matita.do_heavy_checks")
85 grafite_status (text,prefix_len,st)
87 let enriched_history_fragment = List.rev enriched_history_fragment in
91 (fun (acc, to_prepend) (status,alias) ->
93 | None -> (status,to_prepend ^ nonskipped_txt)::acc,""
95 let newtxt = LexiconAstPp.pp_alias value in
96 (status,to_prepend ^ newtxt ^ "\n")::acc, "")
97 ([],skipped_txt) enriched_history_fragment
99 res,"",parsed_text_length
102 (* this function calls the parser in a way that it does not perform inclusions,
103 * so that we can ensure the inclusion is performed after the included file
104 * is compiled (if needed). matitac does not need that, since it compiles files
105 * in the good order, here files may be compiled on demand. *)
106 let wrap_with_make include_paths (f : #LexiconEngine.status GrafiteParser.statement) x =
108 f ~never_include:true ~include_paths x
110 | GrafiteParser.NoInclusionPerformed mafilename ->
111 let root, buri, _, tgt =
112 try Librarian.baseuri_of_script ~include_paths mafilename
113 with Librarian.NoRootFor _ ->
114 HLog.error ("The included file '"^mafilename^"' has no root file,");
115 HLog.error "please create it.";
116 raise (Failure ("No root file for "^mafilename))
118 let b = MatitacLib.Make.make root [tgt] in
120 try f ~include_paths x with LexiconEngine.IncludedFileNotCompiled _ ->
122 (Failure ("Including: "^tgt^
123 "\nNothing to do... did you run matitadep?"))
124 else raise (Failure ("Compiling: " ^ tgt))
127 let pp_eager_statement_ast =
128 GrafiteAstPp.pp_statement ~term_pp:NotationPp.pp_term
129 ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
131 let eval_nmacro include_paths (buffer : GText.buffer) guistuff grafite_status user_goal unparsed_text parsed_text script mac =
132 let parsed_text_length = String.length parsed_text in
134 | TA.Screenshot (_,name) ->
135 let status = script#grafite_status in
136 let _,_,menv,subst,_ = status#obj in
137 let name = Filename.dirname (script#filename) ^ "/" ^ name in
139 let selected = Continuationals.Stack.head_goals status#stack in
140 List.filter (fun x,_ -> List.mem x selected) menv
142 guistuff.mathviewer#screenshot status sequents menv subst name;
143 [status, parsed_text], "", parsed_text_length
145 let status = script#grafite_status in
146 let _,_,menv,subst,_ = status#obj in
148 try let _,(_,ctx,_) = List.hd menv in ctx
149 with Failure "hd" -> []
151 let m, s, status, t =
152 GrafiteDisambiguate.disambiguate_nterm
153 None status ctx menv subst (parsed_text,parsed_text_length,
154 NotationPt.Cast (t,NotationPt.Implicit `JustOne))
155 (* XXX use the metasenv, if possible *)
157 guistuff.mathviewer#show_entry (`NCic (t,ctx,m,s));
158 [status, parsed_text], "", parsed_text_length
159 | TA.NIntroGuess _loc ->
160 let names_ref = ref [] in
162 NTactics.intros_tac ~names_ref [] script#grafite_status
164 let rex = Pcre.regexp ~flags:[`MULTILINE] "\\A([\\n\\t\\r ]*).*\\Z" in
165 let nl = Pcre.replace ~rex ~templ:"$1" parsed_text in
166 [s, nl ^ "#" ^ String.concat " " !names_ref ^ ";"], "", parsed_text_length
167 | TA.NAutoInteractive (_loc, (None,a)) ->
168 let trace_ref = ref [] in
171 ~params:(None,a) ~trace_ref script#grafite_status
174 try List.assoc "depth" a
177 let trace = "/"^(if int_of_string depth > 1 then depth else "")^"/ by " in
179 match !trace_ref with
183 (HExtlib.filter_map (function
184 | NotationPt.NRef r -> Some (NCicPp.r2s true r)
188 let rex = Pcre.regexp ~flags:[`MULTILINE] "\\A([\\n\\t\\r ]*).*\\Z" in
189 let nl = Pcre.replace ~rex ~templ:"$1" parsed_text in
190 [s, nl ^ trace ^ thms ^ ";"], "", parsed_text_length
191 | TA.NAutoInteractive (_, (Some _,_)) -> assert false
193 let rec eval_executable include_paths (buffer : GText.buffer) guistuff
194 grafite_status user_goal unparsed_text skipped_txt nonskipped_txt
198 ignore (buffer#move_mark (`NAME "beginning_of_statement")
199 ~where:((buffer#get_iter_at_mark (`NAME "locked"))#forward_chars
200 (Glib.Utf8.length skipped_txt))) ;
201 eval_with_engine include_paths
202 guistuff grafite_status user_goal skipped_txt nonskipped_txt
203 (TA.Executable (loc, ex))
205 MatitaTypes.Cancel -> [], "", 0
206 | GrafiteEngine.NMacro (_loc,macro) ->
207 eval_nmacro include_paths buffer guistuff grafite_status
208 user_goal unparsed_text (skipped_txt ^ nonskipped_txt) script macro
211 and eval_statement include_paths (buffer : GText.buffer) guistuff
212 grafite_status user_goal script statement
214 let (grafite_status,st), unparsed_text =
217 if Pcre.pmatch ~rex:only_dust_RE text then raise Margin;
219 wrap_with_make include_paths
220 (GrafiteParser.parse_statement (Ulexing.from_utf8_string text))
224 | `Ast (st, text) -> (grafite_status, st), text
226 let text_of_loc floc =
227 let nonskipped_txt,_ = MatitaGtkMisc.utf8_parsed_text unparsed_text floc in
228 let start, stop = HExtlib.loc_of_floc floc in
229 let floc = HExtlib.floc_of_loc (0, start) in
230 let skipped_txt,_ = MatitaGtkMisc.utf8_parsed_text unparsed_text floc in
231 let floc = HExtlib.floc_of_loc (0, stop) in
232 let txt,len = MatitaGtkMisc.utf8_parsed_text unparsed_text floc in
233 txt,nonskipped_txt,skipped_txt,len
236 | GrafiteParser.LNone loc ->
237 let parsed_text, _, _, parsed_text_length = text_of_loc loc in
238 [grafite_status,parsed_text],"",
240 | GrafiteParser.LSome (GrafiteAst.Executable (loc, ex)) ->
241 let _, nonskipped, skipped, parsed_text_length = text_of_loc loc in
242 eval_executable include_paths buffer guistuff
243 grafite_status user_goal unparsed_text skipped nonskipped script ex loc
244 | GrafiteParser.LSome (GrafiteAst.Comment (loc, GrafiteAst.Code (_, ex)))
245 when Helm_registry.get_bool "matita.execcomments" ->
246 let _, nonskipped, skipped, parsed_text_length = text_of_loc loc in
247 eval_executable include_paths buffer guistuff
248 grafite_status user_goal unparsed_text skipped nonskipped script ex loc
249 | GrafiteParser.LSome (GrafiteAst.Comment (loc, _)) ->
250 let parsed_text, _, _, parsed_text_length = text_of_loc loc in
251 let remain_len = String.length unparsed_text - parsed_text_length in
252 let s = String.sub unparsed_text parsed_text_length remain_len in
255 eval_statement include_paths buffer guistuff
256 grafite_status user_goal script (`Raw s)
258 HExtlib.Localized (floc, exn) ->
259 HExtlib.raise_localized_exception
260 ~offset:(MatitaGtkMisc.utf8_string_length parsed_text) floc exn
261 | MultiPassDisambiguator.DisambiguationError (offset,errorll) ->
263 (MultiPassDisambiguator.DisambiguationError
264 (offset+parsed_text_length, errorll))
266 assert (text=""); (* no macros inside comments, please! *)
268 | (statuses,text)::tl ->
269 (statuses,parsed_text ^ text)::tl,"",parsed_text_length + len
272 let fresh_script_id =
276 class script ~(source_view: GSourceView2.source_view)
277 ~(mathviewer: MatitaTypes.mathViewer)
282 let buffer = source_view#buffer in
283 let source_buffer = source_view#source_buffer in
284 let initial_statuses current baseuri =
285 let empty_lstatus = new LexiconEngine.status in
288 LexiconSync.time_travel ~present:current ~past:empty_lstatus;
289 GrafiteSync.time_travel ~present:current ();
290 (* CSC: there is a known bug in invalidation; temporary fix here *)
291 NCicEnvironment.invalidate ()
294 CicNotation2.load_notation ~include_paths:[] empty_lstatus
295 BuildTimeConf.core_notation_script
297 let grafite_status = GrafiteSync.init lexicon_status baseuri in
300 let read_include_paths file =
302 let root, _buri, _fname, _tgt =
303 Librarian.baseuri_of_script ~include_paths:[] file
306 Str.split (Str.regexp " ")
307 (List.assoc "include_paths" (Librarian.load_root_file (root^"/root")))
309 List.iter (HLog.debug) rc; rc
310 with Librarian.NoRootFor _ | Not_found -> []
312 let default_buri = "cic:/matita/tests" in
313 let default_fname = ".unnamed.ma" in
315 val mutable include_paths_ = []
317 val scriptId = fresh_script_id ()
320 mathviewer = mathviewer;
321 urichooser = urichooser;
322 ask_confirmation = ask_confirmation;
325 val mutable filename_ = (None : string option)
327 method has_name = filename_ <> None
329 method include_paths =
331 Helm_registry.get_list Helm_registry.string "matita.includes"
333 method private curdir =
335 let root, _buri, _fname, _tgt =
336 Librarian.baseuri_of_script ~include_paths:self#include_paths
340 with Librarian.NoRootFor _ -> Sys.getcwd ()
342 method buri_of_current_file =
344 | None -> default_buri
347 let _root, buri, _fname, _tgt =
348 Librarian.baseuri_of_script ~include_paths:self#include_paths f
351 with Librarian.NoRootFor _ -> default_buri
353 method filename = match filename_ with None -> default_fname | Some f -> f
356 ignore (GMain.Timeout.add ~ms:300000
357 ~callback:(fun _ -> self#_saveToBackupFile ();true));
358 ignore (buffer#connect#modified_changed
359 (fun _ -> set_star buffer#modified))
361 val mutable statements = [] (** executed statements *)
363 val mutable history = [ initial_statuses None default_buri ]
364 (** list of states before having executed statements. Head element of this
365 * list is the current state, last element is the state at the beginning of
367 * Invariant: this list length is 1 + length of statements *)
369 (** goal as seen by the user (i.e. metano corresponding to current tab) *)
370 val mutable userGoal = (None : int option)
372 (** text mark and tag representing locked part of a script *)
374 buffer#create_mark ~name:"locked" ~left_gravity:true buffer#start_iter
375 val beginning_of_statement_mark =
376 buffer#create_mark ~name:"beginning_of_statement"
377 ~left_gravity:true buffer#start_iter
378 val locked_tag = buffer#create_tag [`BACKGROUND "lightblue"; `EDITABLE false]
379 val error_tag = buffer#create_tag [`UNDERLINE `SINGLE; `FOREGROUND "red"]
381 method locked_mark = locked_mark
382 method locked_tag = locked_tag
383 method error_tag = error_tag
385 (* history can't be empty, the invariant above grant that it contains at
386 * least the init grafite_status *)
387 method grafite_status = match history with s::_ -> s | _ -> assert false
389 method private _advance ?statement () =
390 let s = match statement with Some s -> s | None -> self#getFuture in
391 if self#bos then LibraryClean.clean_baseuris [self#buri_of_current_file];
392 HLog.debug ("evaluating: " ^ first_line s ^ " ...");
393 let time1 = Unix.gettimeofday () in
394 let entries, newtext, parsed_len =
396 eval_statement self#include_paths buffer guistuff
397 self#grafite_status userGoal self (`Raw s)
398 with End_of_file -> raise Margin
400 let time2 = Unix.gettimeofday () in
401 HLog.debug ("... done in " ^ string_of_float (time2 -. time1) ^ "s");
402 let new_statuses, new_statements =
403 let statuses, texts = List.split entries in
406 history <- new_statuses @ history;
407 statements <- new_statements @ statements;
408 let start = buffer#get_iter_at_mark (`MARK locked_mark) in
409 let new_text = String.concat "" (List.rev new_statements) in
410 if statement <> None then
411 buffer#insert ~iter:start new_text
413 let parsed_text = String.sub s 0 parsed_len in
414 if new_text <> parsed_text then begin
415 let stop = start#copy#forward_chars (Glib.Utf8.length parsed_text) in
416 buffer#delete ~start ~stop;
417 buffer#insert ~iter:start new_text;
420 self#moveMark (Glib.Utf8.length new_text);
421 buffer#insert ~iter:(buffer#get_iter_at_mark (`MARK locked_mark)) newtext;
422 (* here we need to set the Goal in case we are going to cursor (or to
423 bottom) and we will face a macro *)
426 method private _retract offset grafite_status new_statements
429 let cur_grafite_status =
430 match history with s::_ -> s | [] -> assert false
432 LexiconSync.time_travel ~present:cur_grafite_status ~past:grafite_status;
433 GrafiteSync.time_travel ~present:cur_grafite_status ~past:grafite_status ();
434 statements <- new_statements;
435 history <- new_history;
436 self#moveMark (- offset)
438 method advance ?statement () =
440 self#_advance ?statement ();
443 | Margin -> self#notify
444 | Not_found -> assert false
445 | Invalid_argument "Array.make" -> HLog.error "The script is too big!\n"
446 | exc -> self#notify; raise exc
450 let cmp,new_statements,new_history,grafite_status =
451 match statements,history with
452 stat::statements, _::(status::_ as history) ->
453 assert (Glib.Utf8.validate stat);
454 Glib.Utf8.length stat, statements, history, status
455 | [],[_] -> raise Margin
456 | _,_ -> assert false
458 self#_retract cmp grafite_status new_statements
462 | Margin -> self#notify
463 | Invalid_argument "Array.make" -> HLog.error "The script is too big!\n"
464 | exc -> self#notify; raise exc
466 method private getFuture =
467 let lock = buffer#get_iter_at_mark (`MARK locked_mark) in
468 let text = buffer#get_text ~start:lock ~stop:buffer#end_iter () in
471 method expandAllVirtuals =
472 let lock = buffer#get_iter_at_mark (`MARK locked_mark) in
473 let text = buffer#get_text ~start:lock ~stop:buffer#end_iter () in
474 buffer#delete ~start:lock ~stop:buffer#end_iter;
475 let text = Pcre.replace ~pat:":=" ~templ:"\\def" text in
476 let text = Pcre.replace ~pat:"->" ~templ:"\\to" text in
477 let text = Pcre.replace ~pat:"=>" ~templ:"\\Rightarrow" text in
479 Pcre.substitute_substrings
481 let pristine = Pcre.get_substring str 0 in
483 if pristine.[0] = ' ' then
484 String.sub pristine 1 (String.length pristine -1)
488 if input.[String.length input-1] = ' ' then
489 String.sub input 0 (String.length input -1)
493 if input = "\\forall" ||
494 input = "\\lambda" ||
495 input = "\\exists" then "","" else " ", " "
498 before ^ Glib.Utf8.from_unichar
499 (snd (Virtuals.symbol_of_virtual input)) ^ after
500 with Virtuals.Not_a_virtual -> pristine)
501 ~pat:" ?\\\\[a-zA-Z]+ ?" text
503 buffer#insert ~iter:lock text
505 (** @param rel_offset relative offset from current position of locked_mark *)
506 method private moveMark rel_offset =
507 let mark = `MARK locked_mark in
508 let old_insert = buffer#get_iter_at_mark `INSERT in
509 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
510 let current_mark_pos = buffer#get_iter_at_mark mark in
512 match rel_offset with
513 | 0 -> current_mark_pos
514 | n when n > 0 -> current_mark_pos#forward_chars n
515 | n (* when n < 0 *) -> current_mark_pos#backward_chars (abs n)
517 buffer#move_mark mark ~where:new_mark_pos;
518 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:new_mark_pos;
519 buffer#move_mark `INSERT old_insert;
520 let mark_position = buffer#get_iter_at_mark mark in
521 if source_view#move_mark_onscreen mark then
523 buffer#move_mark mark mark_position;
524 source_view#scroll_to_mark ~use_align:true ~xalign:1.0 ~yalign:0.1 mark;
526 while Glib.Main.pending () do ignore(Glib.Main.iteration false); done
528 method clean_dirty_lock =
529 let lock_mark_iter = buffer#get_iter_at_mark (`MARK locked_mark) in
530 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
531 buffer#apply_tag locked_tag ~start:buffer#start_iter ~stop:lock_mark_iter
533 val mutable observers = []
535 method addObserver (o: GrafiteTypes.status -> unit) =
536 observers <- o :: observers
538 method private notify =
539 let grafite_status = self#grafite_status in
540 List.iter (fun o -> o grafite_status) observers
542 method loadFromString s =
545 buffer#set_modified true
547 method loadFromFile f =
548 buffer#set_text (HExtlib.input_file f);
550 buffer#set_modified false
552 method assignFileName file =
555 | Some f -> Some (Librarian.absolutize f)
560 (match file with Some file -> read_include_paths file | None -> []);
562 Sys.chdir self#curdir;
563 HLog.debug ("Moving to " ^ Sys.getcwd ())
565 method saveToFile () =
566 if self#has_name then
567 let oc = open_out self#filename in
568 output_string oc (buffer#get_text ~start:buffer#start_iter
569 ~stop:buffer#end_iter ());
572 buffer#set_modified false
574 HLog.error "Can't save, no filename selected"
576 method private _saveToBackupFile () =
577 if buffer#modified then
579 let f = self#filename in
580 let oc = open_out f in
581 output_string oc (buffer#get_text ~start:buffer#start_iter
582 ~stop:buffer#end_iter ());
584 HLog.debug ("backup " ^ f ^ " saved")
587 method private reset_buffer =
589 history <- [ initial_statuses (Some self#grafite_status) self#buri_of_current_file ];
592 buffer#remove_tag locked_tag ~start:buffer#start_iter ~stop:buffer#end_iter;
593 buffer#move_mark (`MARK locked_mark) ~where:buffer#start_iter
597 source_buffer#begin_not_undoable_action ();
598 buffer#delete ~start:buffer#start_iter ~stop:buffer#end_iter;
599 source_buffer#end_not_undoable_action ();
600 buffer#set_modified false;
603 let template = HExtlib.input_file BuildTimeConf.script_template in
604 buffer#insert ~iter:(buffer#get_iter `START) template;
605 buffer#set_modified false;
608 method goto (pos: [`Top | `Bottom | `Cursor]) () =
610 let old_locked_mark =
612 (buffer#create_mark ~name:"old_locked_mark"
613 ~left_gravity:true (buffer#get_iter_at_mark (`MARK locked_mark))) in
614 let getpos _ = buffer#get_iter_at_mark (`MARK locked_mark) in
615 let getoldpos _ = buffer#get_iter_at_mark old_locked_mark in
616 let dispose_old_locked_mark () = buffer#delete_mark old_locked_mark in
619 dispose_old_locked_mark ();
626 let newpos = getpos () in
627 if (getoldpos ())#compare newpos < 0 then
629 buffer#move_mark old_locked_mark newpos;
634 dispose_old_locked_mark ();
637 | Margin -> dispose_old_locked_mark (); self#notify
638 | exc -> dispose_old_locked_mark (); self#notify; raise exc)
640 let locked_iter () = buffer#get_iter_at_mark (`NAME "locked") in
641 let cursor_iter () = buffer#get_iter_at_mark `INSERT in
644 (buffer#create_mark ~name:"initial_insert"
645 ~left_gravity:true (cursor_iter ())) in
646 let dispose_remember () = buffer#delete_mark remember in
647 let remember_iter () =
648 buffer#get_iter_at_mark (`NAME "initial_insert") in
649 let cmp () = (locked_iter ())#offset - (remember_iter ())#offset in
651 let forward_until_cursor () = (* go forward until locked > cursor *)
654 if cmp () < 0 && (getoldpos ())#compare (getpos ()) < 0
657 buffer#move_mark old_locked_mark (getpos ());
663 let rec back_until_cursor len = (* go backward until locked < cursor *)
665 statements, ((grafite_status)::_ as history)
667 self#_retract (icmp - len) grafite_status statements
669 | statement::tl1, _::tl2 ->
670 back_until_cursor (len - MatitaGtkMisc.utf8_string_length statement) (tl1,tl2)
671 | _,_ -> assert false
675 if icmp < 0 then (* locked < cursor *)
676 (forward_until_cursor (); self#notify)
677 else if icmp > 0 then (* locked > cursor *)
678 (back_until_cursor icmp (statements,history); self#notify)
679 else (* cursor = locked *)
683 dispose_old_locked_mark ();
685 | Margin -> dispose_remember (); dispose_old_locked_mark (); self#notify
686 | exc -> dispose_remember (); dispose_old_locked_mark ();
687 self#notify; raise exc)
688 with Invalid_argument "Array.make" ->
689 HLog.error "The script is too big!\n"
691 method stack = (assert false : Continuationals.Stack.t) (* MATITA 1.0 GrafiteTypes.get_stack
692 self#grafite_status *)
693 method setGoal n = userGoal <- n
694 method goal = userGoal
702 let rec is_there_only_comments lexicon_status s =
703 if Pcre.pmatch ~rex:only_dust_RE s then raise Margin;
704 let lexicon_status,st =
705 GrafiteParser.parse_statement (Ulexing.from_utf8_string s)
706 ~include_paths:self#include_paths lexicon_status
709 | GrafiteParser.LSome (GrafiteAst.Comment (loc,_)) ->
710 let _,parsed_text_length = MatitaGtkMisc.utf8_parsed_text s loc in
711 (* CSC: why +1 in the following lines ???? *)
712 let parsed_text_length = parsed_text_length + 1 in
713 let remain_len = String.length s - parsed_text_length in
714 let next = String.sub s parsed_text_length remain_len in
715 is_there_only_comments lexicon_status next
716 | GrafiteParser.LNone _
717 | GrafiteParser.LSome (GrafiteAst.Executable _) -> false
719 try is_there_only_comments self#grafite_status self#getFuture
721 | LexiconEngine.IncludedFileNotCompiled _
722 | HExtlib.Localized _
723 | CicNotationParser.Parse_error _ -> false
724 | Margin | End_of_file -> true
725 | Invalid_argument "Array.make" -> false
729 HLog.debug "script status:";
730 HLog.debug ("history size: " ^ string_of_int (List.length history));
731 HLog.debug (sprintf "%d statements:" (List.length statements));
732 List.iter HLog.debug statements;
733 HLog.debug ("Current file name: " ^ self#filename);
736 let _script = ref None
738 let script ~source_view ~mathviewer ~urichooser ~ask_confirmation ~set_star ()
741 ~source_view ~mathviewer ~ask_confirmation ~urichooser ~set_star ()
746 let current () = match !_script with None -> assert false | Some s -> s