]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaDisambiguator.ml
87215fba177db6ea4cc9ed50e6b7ab8249b499c5
[helm.git] / helm / matita / matitaDisambiguator.ml
1 (* Copyright (C) 2004, 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 class parserr () =
27   object
28     method parseTerm (stream: char Stream.t) =
29       CicTextualParser2.parse_term stream
30
31       (* TODO Zack: implements methods below *)
32     method parseTactic (_: char Stream.t) : DisambiguateTypes.tactic =
33       MatitaTypes.not_implemented "parserr.parseTactic"
34     method parseTactical (_: char Stream.t) : DisambiguateTypes.tactical =
35       MatitaTypes.not_implemented "parserr.parseTactical"
36     method parseCommand (_: char Stream.t) : DisambiguateTypes.command =
37       MatitaTypes.not_implemented "parserr.parseCommand"
38     method parseScript (_: char Stream.t) : DisambiguateTypes.script =
39       MatitaTypes.not_implemented "parserr.parseScript"
40   end
41
42 class disambiguator
43   ~parserr ~mqiconn ~(chooseUris: MatitaTypes.choose_uris_callback)
44   ~(chooseInterp: MatitaTypes.choose_interp_callback) ()
45   =
46   let disambiguate_term =
47     let module Callbacks =
48       struct
49         let interactive_user_uri_choice
50           ~selection_mode ?ok ?(enable_button_for_non_vars = true) ~title ~msg
51           ~id uris
52         =
53           chooseUris ~selection_mode ~title ~msg
54             ~nonvars_button:enable_button_for_non_vars uris
55
56         let interactive_interpretation_choice = chooseInterp
57         let input_or_locate_uri ~(title:string) =
58           (* TODO Zack: I try to avoid using this callback. I therefore assume
59            * that the presence of an identifier that can't be resolved via
60            * "locate" query is a syntax error *)
61           MatitaTypes.not_implemented
62             "MatitaDisambiguator: input_or_locate_uri callback"
63       end
64     in
65     let module Disambiguator = Disambiguate.Make (Callbacks) in
66     Disambiguator.disambiguate_term
67   in
68   object (self)
69     val mutable parserr: parserr = parserr
70     method parserr = parserr
71     method setParserr p = parserr <- p
72
73     val mutable _env = DisambiguateTypes.Environment.empty
74     method env = _env
75     method setEnv e = _env <- e
76
77     method disambiguateTermAst ?(context = []) ?(metasenv = []) ?env termAst =
78       let (save_state, env) =
79         match env with
80         | Some env -> (false, env)
81         | None -> (true, _env)
82       in
83       match disambiguate_term mqiconn context metasenv termAst ~aliases:env with
84       | [ (env, metasenv, term) as x ] ->
85           if save_state then self#setEnv env;
86           x
87       | _ -> assert false
88
89     method disambiguateTerm ?context ?metasenv ?env stream =
90       self#disambiguateTermAst ?context ?metasenv ?env
91         (parserr#parseTerm stream)
92   end
93