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/
29 let debug_print = if debug then prerr_endline else ignore ;;
31 let disambiguate_command lexicon_status_ref status cmd =
32 let lexicon_status,metasenv,cmd =
33 GrafiteDisambiguate.disambiguate_command
36 Some (GrafiteTypes.get_string_option status "baseuri")
38 GrafiteTypes.Option_error _ -> None)
39 !lexicon_status_ref (GrafiteTypes.get_proof_metasenv status) cmd
41 lexicon_status_ref := lexicon_status;
42 GrafiteTypes.set_metasenv metasenv status,cmd
44 let disambiguate_tactic lexicon_status_ref status goal tac =
46 GrafiteDisambiguate.disambiguate_tactic
48 (GrafiteTypes.get_proof_context status goal)
49 (GrafiteTypes.get_proof_metasenv status)
52 GrafiteTypes.set_metasenv metasenv status,tac
54 let eval_ast ?do_heavy_checks ?clean_baseuri lexicon_status
57 let lexicon_status_ref = ref lexicon_status in
58 let new_grafite_status,new_objs =
59 GrafiteEngine.eval_ast
60 ~disambiguate_tactic:(disambiguate_tactic lexicon_status_ref)
61 ~disambiguate_command:(disambiguate_command lexicon_status_ref)
62 ?do_heavy_checks ?clean_baseuri grafite_status ast in
63 let new_lexicon_status =
64 LexiconSync.add_aliases_for_objs !lexicon_status_ref new_objs in
66 LexiconSync.alias_diff ~from:lexicon_status new_lexicon_status in
67 let _,intermediate_states =
68 let baseuri = GrafiteTypes.get_string_option new_grafite_status "baseuri" in
70 (fun (lexicon_status,acc) (k,((v,_) as value)) ->
73 UriManager.buri_of_uri (UriManager.uri_of_string v) = baseuri
75 UriManager.IllFormedUri _ -> false (* v is a description, not a URI *)
80 let new_lexicon_status =
81 LexiconEngine.set_proof_aliases lexicon_status [k,value]
84 ((new_grafite_status,new_lexicon_status),Some (k,value))::acc
85 ) (lexicon_status,[]) new_aliases
87 ((new_grafite_status,new_lexicon_status),None)::intermediate_states
89 let eval_from_stream ~first_statement_only ~include_paths ?(prompt=false)
90 ?do_heavy_checks ?clean_baseuri lexicon_status grafite_status str cb
92 let rec loop lexicon_status grafite_status statuses =
94 if first_statement_only then
95 fun _ _ _ -> raise End_of_file
99 if prompt then (print_string "matita> "; flush stdout);
101 let lexicon_status,ast =
102 GrafiteParser.parse_statement ~include_paths str lexicon_status
105 GrafiteParser.LNone _ ->
106 loop lexicon_status grafite_status
107 (((grafite_status,lexicon_status),None)::statuses)
108 | GrafiteParser.LSome ast ->
109 cb grafite_status ast;
111 eval_ast ?do_heavy_checks ?clean_baseuri lexicon_status
112 grafite_status ast in
113 let grafite_status,lexicon_status =
114 match new_statuses with
118 loop lexicon_status grafite_status (new_statuses @ statuses))
120 End_of_file -> statuses
122 loop lexicon_status grafite_status []
125 let eval_string ~first_statement_only ~include_paths ?do_heavy_checks
126 ?clean_baseuri lexicon_status status str
128 eval_from_stream ~first_statement_only ~include_paths ?do_heavy_checks
129 ?clean_baseuri lexicon_status status (Ulexing.from_utf8_string str)