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