fead: add evalInjection

This commit is contained in:
Leonardo de Moura 2020-03-08 11:31:43 -07:00
parent cbf7a661df
commit adce6df1a1
2 changed files with 33 additions and 0 deletions

View file

@ -9,3 +9,4 @@ import Init.Lean.Elab.Tactic.Basic
import Init.Lean.Elab.Tactic.ElabTerm
import Init.Lean.Elab.Tactic.Induction
import Init.Lean.Elab.Tactic.Generalize
import Init.Lean.Elab.Tactic.Injection

View file

@ -0,0 +1,32 @@
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Meta.Tactic.Injection
import Init.Lean.Elab.Tactic.ElabTerm
namespace Lean
namespace Elab
namespace Tactic
-- optional (" with " >> many1 ident')
private def getInjectionNewIds (stx : Syntax) : List Name :=
if stx.isNone then []
else (stx.getArg 1).getArgs.toList.map Syntax.getId
@[builtinTactic «injection»] def evalInjection : Tactic :=
fun stx => do
-- parser! nonReservedSymbol "injection " >> termParser >> withIds
fvarId ← elabAsFVar (stx.getArg 1);
let ids := getInjectionNewIds (stx.getArg 2);
liftMetaTactic stx $ fun mvarId => do
r ← Meta.injection mvarId fvarId ids (!ids.isEmpty);
match r with
| Meta.InjectionResult.solved => pure []
| Meta.InjectionResult.subgoal mvarId _ _ => pure [mvarId]
end Tactic
end Elab
end Lean