]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaEngine.ml
40a80afddba86e6efe2b181c8a2154a9c0eef59b
[helm.git] / helm / matita / matitaEngine.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 let debug = false ;;
29 let debug_print = if debug then prerr_endline else ignore ;;
30
31 let disambiguate_command lexicon_status_ref status cmd =
32  let lexicon_status,metasenv,cmd =
33   GrafiteDisambiguate.disambiguate_command
34    ~baseuri:(
35      try
36       Some (GrafiteTypes.get_string_option status "baseuri")
37      with
38       GrafiteTypes.Option_error _ -> None)
39    !lexicon_status_ref (GrafiteTypes.get_proof_metasenv status) cmd
40  in
41   lexicon_status_ref := lexicon_status;
42   GrafiteTypes.set_metasenv metasenv status,cmd
43
44 let disambiguate_tactic lexicon_status_ref status goal tac =
45  let metasenv,tac =
46   GrafiteDisambiguate.disambiguate_tactic
47    lexicon_status_ref
48    (GrafiteTypes.get_proof_context status goal)
49    (GrafiteTypes.get_proof_metasenv status)
50    tac
51  in
52   GrafiteTypes.set_metasenv metasenv status,tac
53
54 let eval_ast ?do_heavy_checks ?clean_baseuri lexicon_status
55  status ast
56 =
57  let lexicon_status_ref = ref lexicon_status in
58  let 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 status ast
63  in
64   let lexicon_status =
65    LexiconSync.add_aliases_for_objs !lexicon_status_ref new_objs
66   in
67    lexicon_status,status
68
69 let eval_from_stream ~include_paths ?(prompt=false) ?do_heavy_checks
70  ?clean_baseuri lexicon_status status str cb 
71 =
72  let rec loop lexicon_status status =
73   if prompt then (print_string "matita> "; flush stdout);
74   try
75    let lexicon_status,ast = GrafiteParser.parse_statement ~include_paths str lexicon_status in
76     (match ast with
77         GrafiteParser.LNone _ -> loop lexicon_status status
78       | GrafiteParser.LSome ast ->
79          cb status ast;
80          let lexicon_status,status =
81           eval_ast ?do_heavy_checks ?clean_baseuri lexicon_status status ast
82          in
83           loop lexicon_status status)
84   with
85    End_of_file -> lexicon_status,status
86 in
87  loop lexicon_status status
88 ;;
89
90 let eval_string ~include_paths ?do_heavy_checks ?clean_baseuri lexicon_status
91  status str
92 =
93  eval_from_stream ~include_paths ?do_heavy_checks ?clean_baseuri lexicon_status
94   status (Ulexing.from_utf8_string str) (fun _ _ -> ())