]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/grafite_parser/cicNotation2.ml
2ce3f012f761c43f326446d4dcf4d4d4a5f53e7a
[helm.git] / helm / ocaml / grafite_parser / cicNotation2.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 let load_notation fname =
27   let ic = open_in fname in
28   let lexbuf = Ulexing.from_utf8_channel ic in
29   try
30     while true do
31       match GrafiteParser.parse_statement lexbuf with
32       | GrafiteAst.Executable (_, GrafiteAst.Command (_, cmd)) ->
33          ignore (CicNotation.process_notation cmd)
34       | _ -> ()
35     done
36   with End_of_file -> close_in ic
37
38 let parse_environment str =
39  let stream = Ulexing.from_utf8_string str in
40  let environment = ref DisambiguateTypes.Environment.empty in
41  let multiple_environment = ref DisambiguateTypes.Environment.empty in
42   try
43     while true do
44      let alias =
45       match GrafiteParser.parse_statement stream with
46          GrafiteAst.Executable (_, GrafiteAst.Command (_, GrafiteAst.Alias (_,alias)))
47            -> alias
48        | _ -> assert false in
49      let key,value =
50       (*CSC: Warning: this code should be factorized with the corresponding
51              code in MatitaEngine *)
52       match alias with
53          GrafiteAst.Ident_alias (id,uri) ->
54           DisambiguateTypes.Id id,
55           (uri,(fun _ _ _-> CicUtil.term_of_uri (UriManager.uri_of_string uri)))
56        | GrafiteAst.Symbol_alias (symb,instance,desc) ->
57           DisambiguateTypes.Symbol (symb,instance),
58           DisambiguateChoices.lookup_symbol_by_dsc symb desc
59        | GrafiteAst.Number_alias (instance,desc) ->
60           DisambiguateTypes.Num instance,
61           DisambiguateChoices.lookup_num_by_dsc desc
62      in
63       environment := DisambiguateTypes.Environment.add key value !environment;
64       multiple_environment := DisambiguateTypes.Environment.cons key value !multiple_environment;
65     done;
66     assert false
67   with End_of_file ->
68    !environment, !multiple_environment
69