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
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 status ast
65 LexiconSync.add_aliases_for_objs !lexicon_status_ref new_objs
69 let eval_from_stream ~include_paths ?(prompt=false) ?do_heavy_checks
70 ?clean_baseuri lexicon_status status str cb
72 let rec loop lexicon_status status =
73 if prompt then (print_string "matita> "; flush stdout);
75 let lexicon_status,ast = GrafiteParser.parse_statement ~include_paths str lexicon_status in
77 GrafiteParser.LNone _ -> loop lexicon_status status
78 | GrafiteParser.LSome ast ->
80 let lexicon_status,status =
81 eval_ast ?do_heavy_checks ?clean_baseuri lexicon_status status ast
83 loop lexicon_status status)
85 End_of_file -> lexicon_status,status
87 loop lexicon_status status
90 let eval_string ~include_paths ?do_heavy_checks ?clean_baseuri lexicon_status
93 eval_from_stream ~include_paths ?do_heavy_checks ?clean_baseuri lexicon_status
94 status (Ulexing.from_utf8_string str) (fun _ _ -> ())