]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/tacticals.ml
Initial revision
[helm.git] / helm / gTopLevel / tacticals.ml
1 (* Copyright (C) 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 open CicReduction
27 open PrimitiveTactics
28 open ProofEngineTypes
29 open UriManager
30
31 (** DEBUGGING *)
32
33   (** perform debugging output? *)
34 let debug = false
35
36   (** debugging print *)
37 let warn s =
38   if debug then
39     prerr_endline ("TACTICALS WARNING: " ^ s)
40
41 (** AUX TACTIC{,AL}S *)
42
43   (**
44     naive implementation of ORELSE tactical, try a sequence of tactics in turn:
45     if one fails pass to the next one and so on, eventually raises (failure "no
46     tactics left")
47     TODO warning: not tail recursive due to "try .. with" boxing
48   *)
49 let rec try_tactics ~(tactics: (string * tactic) list) ~status =
50   warn "in Ring.try_tactics";
51   match tactics with
52   | (descr, tac)::tactics ->
53       warn ("Ring.try_tactics IS TRYING " ^ descr);
54       (try
55         let res = tac ~status in
56         warn ("Ring.try_tactics: " ^ descr ^ " succedeed!!!");
57         res
58        with
59         e ->
60          match e with
61             (Fail _)
62           | (CicTypeChecker.NotWellTyped _)
63           | (CicUnification.UnificationFailed) ->
64               warn (
65                 "Ring.try_tactics failed with exn: " ^
66                 Printexc.to_string e);
67               try_tactics ~tactics ~status
68         | _ -> raise e (* [e] must not be caught ; let's re-raise it *)
69       )
70   | [] -> raise (Fail "try_tactics: no tactics left")
71
72 let thens ~start ~continuations ~status =
73  let (proof,new_goals) = start ~status in
74   try
75    List.fold_left2
76     (fun (proof,goals) goal tactic ->
77       let (proof',new_goals') = tactic ~status:(proof,goal) in
78        (proof',goals@new_goals')
79     ) (proof,[]) new_goals continuations
80   with
81    Invalid_argument _ -> raise (Fail "thens: wrong number of new goals")
82
83 let then_ ~start ~continuation ~status =
84  let (proof,new_goals) = start ~status in
85   List.fold_left
86    (fun (proof,goals) goal ->
87      let (proof',new_goals') = continuation ~status:(proof,goal) in
88       (proof',goals@new_goals')
89    ) (proof,[]) new_goals