1 (* Copyright (C) 2004-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/
26 exception IncludedFileNotCompiled of string (* file name *)
27 exception MetadataNotFound of string (* file name *)
30 aliases: DisambiguateTypes.environment; (** disambiguation aliases *)
31 multi_aliases: DisambiguateTypes.multiple_environment;
32 lexicon_content_rev: LexiconMarshal.lexicon;
33 notation_ids: CicNotation.notation_id list; (** in-scope notation ids *)
34 metadata: LibraryNoDb.metadata list;
37 let add_lexicon_content cmds status =
38 let content = status.lexicon_content_rev in
41 (fun cmd acc -> cmd :: (List.filter ((<>) cmd) acc))
44 (* prerr_endline ("new lexicon content: " ^ String.concat " " (List.map
45 LexiconAstPp.pp_command content')); *)
46 { status with lexicon_content_rev = content' }
48 let add_metadata new_metadata status =
49 if Helm_registry.get_bool "db.nodb" then
50 let metadata = status.metadata in
55 | LibraryNoDb.Dependency buri ->
56 if List.exists (LibraryNoDb.eq_metadata m) metadata
62 { status with metadata = metadata' }
66 let set_proof_aliases status new_aliases =
67 let commands_of_aliases =
69 (fun alias -> LexiconAst.Alias (HExtlib.dummy_floc, alias))
74 | LexiconAst.Ident_alias (_, suri) ->
75 let buri = UriManager.buri_of_uri (UriManager.uri_of_string suri) in
76 Some (LibraryNoDb.Dependency buri)
80 List.fold_left (fun acc (d,c) -> DisambiguateTypes.Environment.add d c acc)
81 status.aliases new_aliases in
83 List.fold_left (fun acc (d,c) -> DisambiguateTypes.Environment.cons d c acc)
84 status.multi_aliases new_aliases in
86 { status with multi_aliases = multi_aliases ; aliases = aliases}
88 if new_aliases = [] then
92 DisambiguatePp.aliases_of_domain_and_codomain_items_list new_aliases
94 let status = add_lexicon_content (commands_of_aliases aliases) new_status in
95 let status = add_metadata (deps_of_aliases aliases) status in
98 let rec eval_command status cmd =
99 let notation_ids' = CicNotation.process_notation cmd in
101 { status with notation_ids = notation_ids' @ status.notation_ids } in
102 let basedir = Helm_registry.get "matita.basedir" in
104 | LexiconAst.Include (loc, baseuri) ->
105 let lexiconpath = LibraryMisc.lexicon_file_of_baseuri ~basedir ~baseuri in
106 if not (Sys.file_exists lexiconpath) then
107 raise (IncludedFileNotCompiled lexiconpath);
108 let lexicon = LexiconMarshal.load_lexicon lexiconpath in
109 let status = List.fold_left eval_command status lexicon in
110 if Helm_registry.get_bool "db.nodb" then
111 let metadatapath = LibraryMisc.metadata_file_of_baseuri ~basedir ~baseuri in
112 if not (Sys.file_exists metadatapath) then
113 raise (MetadataNotFound metadatapath)
115 add_metadata (LibraryNoDb.load_metadata ~fname:metadatapath) status
118 | LexiconAst.Alias (loc, spec) ->
120 (*CSC: Warning: this code should be factorized with the corresponding
121 code in DisambiguatePp *)
123 | LexiconAst.Ident_alias (id,uri) ->
124 [DisambiguateTypes.Id id,
125 (uri,(fun _ _ _-> CicUtil.term_of_uri(UriManager.uri_of_string uri)))]
126 | LexiconAst.Symbol_alias (symb, instance, desc) ->
127 [DisambiguateTypes.Symbol (symb,instance),
128 DisambiguateChoices.lookup_symbol_by_dsc symb desc]
129 | LexiconAst.Number_alias (instance,desc) ->
130 [DisambiguateTypes.Num instance,
131 DisambiguateChoices.lookup_num_by_dsc desc]
133 set_proof_aliases status diff
134 | LexiconAst.Interpretation (_, dsc, (symbol, _), cic_appl_pattern) as stm ->
135 let status = add_lexicon_content [stm] status in
138 (fun uri -> LibraryNoDb.Dependency (UriManager.buri_of_uri uri))
139 (CicNotationUtil.find_appl_pattern_uris cic_appl_pattern)
142 [DisambiguateTypes.Symbol (symbol, 0),
143 DisambiguateChoices.lookup_symbol_by_dsc symbol dsc]
145 let status = set_proof_aliases status diff in
146 let status = add_metadata uris status in
148 | LexiconAst.Notation _ as stm -> add_lexicon_content [stm] status