lean4-htt/src/Lean/Elab/Tactic/Injection.lean
Sebastian Ullrich eb1e285e26 chore: style
2021-06-21 10:17:26 -07:00

30 lines
1.2 KiB
Text

/-
Copyright (c) 2020 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.Injection
import Lean.Elab.Tactic.ElabTerm
namespace Lean.Elab.Tactic
-- optional (" with " >> many1 ident')
private def getInjectionNewIds (stx : Syntax) : List Name :=
if stx.isNone then
[]
else
stx[1].getArgs.toList.map getNameOfIdent'
private def checkUnusedIds (mvarId : MVarId) (unusedIds : List Name) : MetaM Unit :=
unless unusedIds.isEmpty do
Meta.throwTacticEx `injection mvarId m!"too many identifiers provided, unused: {unusedIds}"
@[builtinTactic «injection»] def evalInjection : Tactic := fun stx => do
-- leading_parser nonReservedSymbol "injection " >> termParser >> withIds
let fvarId ← elabAsFVar stx[1]
let ids := getInjectionNewIds stx[2]
liftMetaTactic fun mvarId => do
match (← Meta.injection mvarId fvarId ids (!ids.isEmpty)) with
| Meta.InjectionResult.solved => checkUnusedIds mvarId ids; pure []
| Meta.InjectionResult.subgoal mvarId' _ unusedIds => checkUnusedIds mvarId unusedIds; pure [mvarId']
end Lean.Elab.Tactic