-
Notifications
You must be signed in to change notification settings - Fork 87
/
SeqFocus.lean
41 lines (37 loc) · 1.35 KB
/
SeqFocus.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/-
Copyright (c) 2022 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Lean.Elab.ElabRules
open Lean Elab Meta Tactic
namespace Batteries.Tactic
/-- Assuming there are `n` goals, `map_tacs [t1; t2; ...; tn]` applies each `ti` to the respective
goal and leaves the resulting subgoals. -/
elab "map_tacs " "[" ts:sepBy(tactic, "; ") "]" : tactic => do
let goals ← getUnsolvedGoals
let tacs := ts.getElems
let length := tacs.size
if length < goals.length then
throwError "not enough tactics"
else if length > goals.length then
throwError "too many tactics"
let mut goalsNew := #[]
for tac in tacs, goal in goals do
if ← goal.isAssigned then continue
setGoals [goal]
try
evalTactic tac
goalsNew := goalsNew ++ (← getUnsolvedGoals)
catch ex =>
if (← read).recover then
logException ex
goalsNew := goalsNew.push goal
else
throw ex
setGoals goalsNew.toList
/-- `t <;> [t1; t2; ...; tn]` focuses on the first goal and applies `t`, which should result in `n`
subgoals. It then applies each `ti` to the corresponding goal and collects the resulting
subgoals. -/
macro:1 (name := seq_focus) t:tactic " <;> " "[" ts:sepBy(tactic, "; ") "]" : tactic =>
`(tactic| focus ( $t:tactic; map_tacs [$ts;*]) )