1 (* Copyright (C) 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 let debug_print = if debug then prerr_endline else ignore ;;
33 let eval_macro_screenshot (status : GrafiteTypes.status) name =
34 assert false (* MATITA 1.0
35 let _,_,metasenv,subst,_ = status#obj in
36 let sequent = List.hd metasenv in
38 ApplyTransformation.nmml_of_cic_sequent
39 status metasenv subst sequent
41 let domImpl = Gdome.domImplementation () in
42 ignore(domImpl#saveDocumentToFile
43 ~name:(name^".xml") ~doc:mathml ());
44 ignore(Sys.command ("mathmlsvg --verbose=1 --font-size=20 --cut-filename=no " ^
45 Filename.quote (name^".xml")));
46 ignore(Sys.command ("convert " ^
47 Filename.quote (name^".svg") ^ " " ^
48 Filename.quote (name^".png")));
49 HLog.debug ("generated " ^ name ^ ".png");
54 let eval_ast ~include_paths ?do_heavy_checks status (text,prefix_len,ast) =
55 let baseuri = status#baseuri in
57 status#set_lstatus { status#lstatus with LexiconTypes.new_aliases = [] } in
59 GrafiteEngine.eval_ast ~include_paths ?do_heavy_checks status
60 (text,prefix_len,ast) in
61 let new_aliases = status#lstatus.LexiconTypes.new_aliases in
62 let _,intermediate_states =
64 (fun (status,acc) (k,value) ->
65 let v = GrafiteAst.description_of_alias value in
68 let NReference.Ref (uri,_) = NReference.reference_of_string v in
69 NUri.baseuri_of_uri uri = baseuri
71 NReference.IllFormedReference _ ->
72 false (* v is a description, not a URI *)
78 LexiconEngine.set_proof_aliases status ~implicit_aliases:false
79 GrafiteAst.WithPreferences [k,value]
81 status, (status ,Some (k,value))::acc
82 ) (status,[]) new_aliases
84 (status,None)::intermediate_states
87 exception TryingToAdd of string
88 exception EnrichedWithStatus of exn * GrafiteTypes.status
90 let eval_from_stream ~first_statement_only ~include_paths
91 ?do_heavy_checks ?(enforce_no_new_aliases=true)
92 ?(watch_statuses=fun _ -> ()) status str cb
94 let matita_debug = Helm_registry.get_bool "matita.debug" in
95 let rec loop status statuses =
97 if first_statement_only then fun _ statuses -> statuses
103 try Some (GrafiteParser.parse_statement status str)
104 with End_of_file -> None in
106 | None -> true, status, statuses
109 GrafiteParser.LNone _ ->
110 watch_statuses status ;
111 false, status, ((status,None)::statuses)
112 | GrafiteParser.LSome ast ->
115 eval_ast ~include_paths ?do_heavy_checks status ("",0,ast) in
116 if enforce_no_new_aliases then
122 let newtxt = GrafiteAstPp.pp_alias value in
123 raise (TryingToAdd newtxt)) new_statuses;
125 match new_statuses with
129 watch_statuses status ;
130 false, status, (new_statuses @ statuses))
131 with exn when not matita_debug ->
132 raise (EnrichedWithStatus (exn, status))
134 if stop then s else loop g s