]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/tacticChaser.ml
- new generated query "unreferred" implemented at server side
[helm.git] / helm / ocaml / tactics / tacticChaser.ml
1 (* Copyright (C) 2000-2002, 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://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 18/02/2003                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 module I = MQueryInterpreter
37 module U = MQGUtil
38 module G = MQueryGenerator
39
40   (* search arguments on which Apply tactic doesn't fail *)
41 let matchConclusion mqi_handle ?(output_html = (fun _ -> ())) ~choose_must () ~status =
42  let ((_, metasenv, _, _), metano) = status in
43  let (_, ey ,ty) = List.find (function (m,_,_) -> m=metano) metasenv in
44   let list_of_must, only = CGMatchConclusion.get_constraints metasenv ey ty in
45   let must = choose_must list_of_must only in
46   let result =
47          I.execute mqi_handle 
48             (G.query_of_constraints
49         (Some U.universe_for_match_conclusion)
50         (must,[],[]) (Some only,None,None)) in 
51         let uris =
52          List.map
53                 (function uri,_ ->
54                         MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format' uri
55                 ) result in
56          let uris',exc =
57                 let rec filter_out =
58                  function
59                                 [] -> [],""
60                         | uri::tl ->
61                                  let tl',exc = filter_out tl in
62                                         try
63                                          if
64                                                 (try
65                                                  ignore
66                                                         (PrimitiveTactics.apply_tac
67                                                          ~term:(MQueryMisc.term_of_cic_textual_parser_uri
68                                                                 (MQueryMisc.cic_textual_parser_uri_of_string uri))
69                                                          ~status);
70                                                  true
71                                                 with ProofEngineTypes.Fail _ -> false)
72                                          then
73                                                 uri::tl',exc
74                                          else
75                                                 tl',exc
76                                         with
77            (ProofEngineTypes.Fail _) as e ->
78                                                  let exc' =
79                                                   "<h1 color=\"red\"> ^ Exception raised trying to apply " ^
80                                                          uri ^ ": " ^ Printexc.to_string e ^ " </h1>" ^ exc
81                                                  in
82                                                   tl',exc'
83                 in
84                  filter_out uris
85          in
86                 let html' =
87                  " <h1>Objects that can actually be applied: </h1> " ^
88                  String.concat "<br>" uris' ^ exc ^
89                  " <h1>Number of false matches: " ^
90                         string_of_int (List.length uris - List.length uris') ^ "</h1>" ^
91                  " <h1>Number of good matches: " ^
92                         string_of_int (List.length uris') ^ "</h1>"
93                 in
94                  output_html html' ;
95                  uris'
96 ;;
97