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://cs.unibo.it/helm/.
28 module Trivial_disambiguate:
30 exception Ambiguous_term of string Lazy.t
31 (** disambiguate an _unanmbiguous_ term using dummy callbacks which fail if a
32 * choice from the user is needed to disambiguate the term
33 * @raise Ambiguous_term for ambiguous term *)
34 val disambiguate_string:
36 ?context:Cic.context ->
37 ?metasenv:Cic.metasenv ->
38 ?initial_ugraph:CicUniv.universe_graph ->
39 ?aliases:DisambiguateTypes.environment ->(* previous interpretation status*)
41 ((DisambiguateTypes.domain_item * DisambiguateTypes.codomain_item) list *
42 Cic.metasenv * (* new metasenv *)
44 CicUniv.universe_graph) list (* disambiguated term *)
48 exception Ambiguous_term of string Lazy.t
52 let non p x = not (p x)
53 let interactive_user_uri_choice ~selection_mode ?ok
54 ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
55 List.filter (non UriManager.uri_is_var) uris
56 let interactive_interpretation_choice interp = raise Exit
57 let input_or_locate_uri ~(title:string) ?id = raise Exit
59 module Disambiguator = Disambiguate.Make (Callbacks)
60 let disambiguate_string ~dbd ?(context = []) ?(metasenv = []) ?initial_ugraph
61 ?(aliases = DisambiguateTypes.Environment.empty) term
64 CicNotationParser.parse_level2_ast (Ulexing.from_utf8_string term)
67 fst (Disambiguator.disambiguate_term ~dbd ~context ~metasenv ("",0,ast)
68 ?initial_ugraph ~aliases ~universe:None)
69 with Exit -> raise (Ambiguous_term (lazy term))
72 let configuration_file = ref "../../../matita/matita.conf.xml";;
74 let core_notation_script = "../../../matita/core_notation.moo";;
76 let get_from_user ~(dbd:HSql.dbd) =
78 match read_line () with
82 let term_string = String.concat "\n" (get ()) in
83 let env, metasenv, term, ugraph =
84 List.nth (Trivial_disambiguate.disambiguate_string dbd term_string) 0
86 term, metasenv, ugraph
89 let full = ref false;;
91 let retrieve_only = ref false;;
93 let demod_equalities = ref false;;
96 let module S = Saturation in
97 let set_ratio v = S.weight_age_ratio := v; S.weight_age_counter := v
98 and set_sel v = S.symbols_ratio := v; S.symbols_counter := v;
99 and set_conf f = configuration_file := f
102 | "lpo" -> Utils.compare_terms := Utils.lpo
103 | "kbo" -> Utils.compare_terms := Utils.kbo
104 | "nr-kbo" -> Utils.compare_terms := Utils.nonrec_kbo
105 | "ao" -> Utils.compare_terms := Utils.ao
106 | o -> raise (Arg.Bad ("Unknown term ordering: " ^ o))
107 and set_fullred b = S.use_fullred := b
108 and set_time_limit v = S.time_limit := float_of_int v
109 and set_width w = S.maxwidth := w
110 and set_depth d = S.maxdepth := d
111 and set_full () = full := true
112 and set_retrieve () = retrieve_only := true
113 and set_demod_equalities () = demod_equalities := true
116 "-full", Arg.Unit set_full, "Enable full mode";
117 "-f", Arg.Bool set_fullred,
118 "Enable/disable full-reduction strategy (default: enabled)";
120 "-r", Arg.Int set_ratio, "Weight-Age equality selection ratio (default: 4)";
122 "-s", Arg.Int set_sel,
123 "symbols-based selection ratio (relative to the weight ratio, default: 0)";
125 "-c", Arg.String set_conf, "Configuration file (for the db connection)";
127 "-o", Arg.String set_ordering,
128 "Term ordering. Possible values are:\n" ^
129 "\tkbo: Knuth-Bendix ordering\n" ^
130 "\tnr-kbo: Non-recursive variant of kbo (default)\n" ^
131 "\tlpo: Lexicographic path ordering";
133 "-l", Arg.Int set_time_limit, "Time limit in seconds (default: no limit)";
135 "-w", Arg.Int set_width,
136 Printf.sprintf "Maximal width (default: %d)" !Saturation.maxwidth;
138 "-d", Arg.Int set_depth,
139 Printf.sprintf "Maximal depth (default: %d)" !Saturation.maxdepth;
141 "-retrieve", Arg.Unit set_retrieve, "retrieve only";
142 "-demod-equalities", Arg.Unit set_demod_equalities, "demod equalities";
143 ] (fun a -> ()) "Usage:";
144 Helm_registry.load_from !configuration_file;
145 ignore (CicNotation2.load_notation [] core_notation_script);
146 ignore (CicNotation2.load_notation [] "../../../matita/library/legacy/coq.ma");
147 let dbd = HSql.quick_connect
148 ~host:(Helm_registry.get "db.host")
149 ~user:(Helm_registry.get "db.user")
150 ~database:(Helm_registry.get "db.database")
153 let term, metasenv, ugraph = get_from_user ~dbd in
154 if !retrieve_only then
155 Saturation.retrieve_and_print dbd term metasenv ugraph
156 else if !demod_equalities then
157 Saturation.main_demod_equalities dbd term metasenv ugraph
159 Saturation.main dbd !full term metasenv ugraph
165 (*with exn -> prerr_endline (Printexc.to_string exn)*)