diff --git a/main.ml b/main.ml index 26c4894..5b6f1ad 100644 --- a/main.ml +++ b/main.ml @@ -165,9 +165,15 @@ let rec interactive (get_instr : unit -> instr) (sl : (interactive_state) list) end end | Tact t -> - (* on applique la tactique et on copie l'état actuel de la preuve pour un futur Undo - Comme OCaml évalue de la droite vers la gauche, on fait bien la copie avant de modifier les références dans la preuve *) - (cg, (apply_tactic (g, gs) t))::(clean_state (cg, (g, gs)))::sq |> interactive get_instr + (* on applique la tactique et on copie l'état actuel de la preuve pour un futur Undo *) + let previous_state = clean_state (cg, (g, gs)) in + let new_proof, status = apply_tactic (g, gs) t in + ( + if status then + (cg, new_proof)::previous_state::sq + else + previous_state::sq + ) |> interactive get_instr with Parser.Error -> print_error "Invalid input" ""; diff --git a/proof.ml b/proof.ml index 31d2b0e..ccf2905 100644 --- a/proof.ml +++ b/proof.ml @@ -210,17 +210,18 @@ let tact_left ((g, gs) : proof) : proof = Some (new_h, t_l, cs), gs | _ -> raise (TacticFailed "Not a disjunction") -let rec apply_tactic (p : proof) (t : tactic) : proof = + (* applies tactic to proof, returns (new_proof, true if p changed) *) +let rec apply_tactic (p : proof) (t : tactic) : proof * bool = match t with - TExact_term e -> tact_exact_term p e - | TExact_proof hyp -> tact_exact_proof p hyp - | TIntros -> tact_intros p - | TIntro -> tact_intro p - | TAssumption -> tact_assumption p - | TCut t -> tact_cut p t - | TApply h -> tact_apply p h - | TSplit -> tact_split p - | TRight -> tact_right p - | TLeft -> tact_left p - | TTry t -> try apply_tactic p t with TacticFailed _ -> p + TExact_term e -> tact_exact_term p e, true + | TExact_proof hyp -> tact_exact_proof p hyp, true + | TIntros -> tact_intros p, true + | TIntro -> tact_intro p, true + | TAssumption -> tact_assumption p, true + | TCut t -> tact_cut p t, true + | TApply h -> tact_apply p h, true + | TSplit -> tact_split p, true + | TRight -> tact_right p, true + | TLeft -> tact_left p, true + | TTry t -> try apply_tactic p t with TacticFailed _ -> p, false diff --git a/tests/8pus/bad/undo_try.8pus b/tests/8pus/bad/undo_try.8pus index 549111d..bbf032e 100644 --- a/tests/8pus/bad/undo_try.8pus +++ b/tests/8pus/bad/undo_try.8pus @@ -1,7 +1,7 @@ Goal A -> B -> A. intros. -try intro. +try try try intro. Undo. intro. exact H0. -Qed. \ No newline at end of file +Qed.