- let output_status,goals = step output_status goallist in
- S.set_goals output_status goals
- with
- (Fail _) as e ->
- warn (lazy ("Tacticals.do_tactic failed after nth time with exception: " ^ Printexc.to_string e)) ;
- S.apply_tactic S.id_tac status
- in
- S.mk_tactic (do_tactic ~n ~tactic)
-
-
-
-(* This applies tactic and catches its possible failure *)
-let try_tactic ~tactic =
- let rec try_tactic ~tactic status =
- warn (lazy "in Tacticals.try_tactic");
- try
- S.apply_tactic tactic status
- with
- (Fail _) as e ->
- warn (lazy ( "Tacticals.try_tactic failed with exn: " ^ Printexc.to_string e));
- S.apply_tactic S.id_tac status
- in
- S.mk_tactic (try_tactic ~tactic)
-
-(* This tries tactics until one of them doesn't _solve_ the goal *)
-(* TODO: si puo' unificare le 2(due) chiamate ricorsive? *)
-let solve_tactics ~tactics =
- let rec solve_tactics ~(tactics: (string * tactic) list) status =
- warn (lazy "in Tacticals.solve_tactics");
- match tactics with
- | (descr, currenttactic)::moretactics ->
- warn (lazy ("Tacticals.solve_tactics is trying " ^ descr));
- (try
- let output_status = S.apply_tactic currenttactic status in
- let goallist = S.goals output_status in
- match goallist with
- [] -> warn (lazy ("Tacticals.solve_tactics: " ^ descr ^
- " solved the goal!!!"));
-(* questo significa che non ci sono piu' goal, o che current_tactic non ne
- ha aperti di nuovi? (la 2a!) #####
- nel secondo caso basta per dire che solve_tactics has solved the goal? (si!) *)
- output_status
- | _ -> warn (lazy ("Tacticals.solve_tactics: try the next tactic"));
- solve_tactics ~tactics:(moretactics) status
- with
- (Fail _) as e ->
- warn (lazy ("Tacticals.solve_tactics: current tactic failed with exn: " ^
- Printexc.to_string e));
- solve_tactics ~tactics status
- )
- | [] -> raise (Fail (lazy "solve_tactics cannot solve the goal"));
- S.apply_tactic S.id_tac status
- in
- S.mk_tactic (solve_tactics ~tactics)
+ S.set_goals output_status goals
+ in
+ S.mk_tactic (then_ ~start ~continuation) *)
+
+ let seq ~tactics =
+ S.mk_tactic
+ (fun istatus ->
+ fold_eval istatus
+ (HExtlib.list_concat ~sep:[ C.Semicolon ]
+ (List.map (fun t -> [ C.Tactical (C.Tactic t) ]) tactics)))
+
+(* let rec seq ~tactics =
+ match tactics with
+ | [] -> assert false
+ | [tac] -> tac
+ | hd :: tl -> then_ ~start:hd ~continuation:(seq ~tactics:tl) *)
+
+ (* TODO: x debug: i due tatticali seguenti non contano quante volte hanno
+ * applicato la tattica *)
+
+ let rec step f output_status opened closed =
+ match opened with
+ | [] -> output_status, [], closed
+ | head :: tail ->
+ let status = S.focus head output_status in
+ let output_status' = f status in
+ let opened', closed' = S.goals output_status' in
+ let output_status'', opened'', closed'' =
+ step f output_status' tail []
+ in
+ output_status'', opened' @ opened'', closed' @ closed''
+
+ (* This keep on appling tactic until it fails. When <tactic> generates more
+ * than one goal, you have a tree of application on the tactic, repeat_tactic
+ * works in depth on this tree *)
+ let repeat_tactic ~tactic =
+ let rec repeat_tactic ~tactic status =
+ info (lazy "in repeat_tactic");
+ try
+(* let rec step output_status opened closed =
+ match opened with
+ | [] -> output_status, [], closed
+ | head :: tail ->
+ let status = S.focus head output_status in
+ let output_status' = repeat_tactic ~tactic status in
+ let opened', closed' = S.goals output_status' in
+ let output_status'', opened'', closed'' =
+ step output_status' tail []
+ in
+ output_status'', opened' @ opened'', closed' @ closed''
+ in *)
+ let output_status = S.apply_tactic tactic status in
+ let opened, closed = S.goals output_status in
+ let output_status, opened', closed' =
+ step (repeat_tactic ~tactic) output_status opened closed
+ in
+ S.set_goals (opened', closed') output_status
+ with
+ (ProofEngineTypes.Fail _) as e ->
+ info (lazy
+ ("Tacticals.repeat_tactic failed after nth time with exception: "
+ ^ Printexc.to_string e));
+ S.apply_tactic S.id_tactic status
+ in
+ S.mk_tactic (repeat_tactic ~tactic)
+
+ (* This tries to apply tactic n times *)
+ let do_tactic ~n ~tactic =
+ let rec do_tactic ~n ~tactic status =
+ if n = 0 then
+ S.apply_tactic S.id_tactic status
+ else
+ try
+ let output_status = S.apply_tactic tactic status in
+ let opened, closed = S.goals output_status in
+(* let rec step output_status goallist =
+ match goallist with
+ [] -> output_status, []
+ | head::tail ->
+ let status = S.focus head output_status in
+ let output_status' = do_tactic ~n:(n-1) ~tactic status in
+ let goallist' = S.goals output_status' in
+ let (output_status'', goallist'') = step output_status' tail in
+ output_status'', goallist'@goallist''
+ in *)
+ let output_status, opened', closed' =
+ step (do_tactic ~n:(n-1) ~tactic) output_status opened closed
+ in
+ S.set_goals (opened', closed') output_status
+ with
+ (ProofEngineTypes.Fail _) as e ->
+ info (lazy
+ ("Tacticals.do_tactic failed after nth time with exception: "
+ ^ Printexc.to_string e)) ;
+ S.apply_tactic S.id_tactic status
+ in
+ S.mk_tactic (do_tactic ~n ~tactic)
+
+ (* This applies tactic and catches its possible failure *)
+ let try_tactic ~tactic =
+ let rec try_tactic ~tactic status =
+ info (lazy "in Tacticals.try_tactic");
+ try
+ S.apply_tactic tactic status
+ with
+ (ProofEngineTypes.Fail _) as e ->
+ info (lazy (
+ "Tacticals.try_tactic failed with exn: " ^ Printexc.to_string e));
+ S.apply_tactic S.id_tactic status
+ in
+ S.mk_tactic (try_tactic ~tactic)
+
+ (* This tries tactics until one of them doesn't _solve_ the goal *)
+ (* TODO: si puo' unificare le 2(due) chiamate ricorsive? *)
+ let solve_tactics ~tactics =
+ let rec solve_tactics ~(tactics: (string * tactic) list) status =
+ info (lazy "in Tacticals.solve_tactics");
+ match tactics with
+ | (descr, currenttactic)::moretactics ->
+ info (lazy ("Tacticals.solve_tactics is trying " ^ descr));
+ (try
+ let output_status = S.apply_tactic currenttactic status in
+ let opened, closed = S.goals output_status in
+ match opened with
+ | [] -> info (lazy ("Tacticals.solve_tactics: " ^ descr ^
+ " solved the goal!!!"));
+ (* questo significa che non ci sono piu' goal, o che current_tactic non ne ha
+ * aperti di nuovi? (la 2a!) ##### nel secondo caso basta per dire che
+ * solve_tactics has solved the goal? (si!) *)
+ output_status
+ | _ -> info (lazy ("Tacticals.solve_tactics: try the next tactic"));
+ solve_tactics ~tactics:(moretactics) status
+ with
+ (ProofEngineTypes.Fail _) as e ->
+ info (lazy (
+ "Tacticals.solve_tactics: current tactic failed with exn: "
+ ^ Printexc.to_string e));
+ solve_tactics ~tactics status
+ )
+ | [] ->
+ raise (ProofEngineTypes.Fail
+ (lazy "solve_tactics cannot solve the goal"))
+ in
+ S.mk_tactic (solve_tactics ~tactics)
+
+ let cont_proxy cont = S.mk_tactic (C.eval cont)
+
+ let tactic t = cont_proxy (C.Tactical (C.Tactic t))
+ let skip = cont_proxy (C.Tactical C.Skip)
+ let dot = cont_proxy C.Dot
+ let semicolon = cont_proxy C.Semicolon
+ let branch = cont_proxy C.Branch
+ let shift = cont_proxy C.Shift
+ let pos i = cont_proxy (C.Pos i)
+ let merge = cont_proxy C.Merge
+ let focus goals = cont_proxy (C.Focus goals)
+ let unfocus = cont_proxy C.Unfocus