lean4-htt/src/Lean/Elab/Tactic/Split.lean
2022-02-23 16:00:42 -08:00

39 lines
1.4 KiB
Text

/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Split
import Lean.Elab.Tactic.Basic
import Lean.Elab.Tactic.Location
namespace Lean.Elab.Tactic
open Meta
@[builtinTactic Lean.Parser.Tactic.split] def evalSplit : Tactic := fun stx => do
unless stx[1].isNone do
throwError "'split' tactic, term to split is not supported yet"
let loc := expandOptLocation stx[2]
match loc with
| Location.targets hyps simplifyTarget =>
if (hyps.size > 0 && simplifyTarget) || hyps.size > 1 then
throwErrorAt stx[2] "'split' tactic failed, select a single target to split"
if simplifyTarget then
liftMetaTactic fun mvarId => do
let some mvarIds ← splitTarget? mvarId | Meta.throwTacticEx `split mvarId ""
return mvarIds
else
let fvarId ← getFVarId hyps[0]
liftMetaTactic fun mvarId => do
let some mvarIds ← splitLocalDecl? mvarId fvarId | Meta.throwTacticEx `split mvarId ""
return mvarIds
| Location.wildcard =>
liftMetaTactic fun mvarId => do
let fvarIds ← getNondepPropHyps mvarId
for fvarId in fvarIds do
if let some mvarIds ← splitLocalDecl? mvarId fvarId then
return mvarIds
let some mvarIds ← splitTarget? mvarId | Meta.throwTacticEx `split mvarId ""
return mvarIds
end Lean.Elab.Tactic