fix: fixes #452
The new syntax is similar to `matchAlts` and uses `colGe`. The first `|` is not optional anymore.
This commit is contained in:
parent
0a57cbd7d3
commit
b52edf1259
6 changed files with 23 additions and 25 deletions
|
|
@ -226,11 +226,10 @@ syntax (name := generalize) "generalize " atomic(ident " : ")? term:51 " = " ide
|
|||
syntax (name := paren) "(" tacticSeq ")" : tactic
|
||||
syntax (name := withReducible) "withReducible " tacticSeq : tactic
|
||||
syntax (name := withReducibleAndInstances) "withReducibleAndInstances " tacticSeq : tactic
|
||||
syntax (name := first) "first " "|"? sepBy1(tacticSeq, "|") : tactic
|
||||
syntax (name := firstNew) "firstNew " withPosition((group(colGe "|" tacticSeq))+) : tactic
|
||||
syntax (name := first) "first " withPosition((group(colGe "|" tacticSeq))+) : tactic
|
||||
syntax (name := rotateLeft) "rotateLeft" (num)? : tactic
|
||||
syntax (name := rotateRight) "rotateRight" (num)? : tactic
|
||||
macro "try " t:tacticSeq : tactic => `(first $t | skip)
|
||||
macro "try " t:tacticSeq : tactic => `(first | $t | skip)
|
||||
macro:1 x:tactic " <;> " y:tactic:0 : tactic => `(tactic| focus ($x:tactic; allGoals $y:tactic))
|
||||
|
||||
macro "rfl" : tactic => `(exact rfl)
|
||||
|
|
@ -309,7 +308,7 @@ syntax (name := existsIntro) "exists " term : tactic
|
|||
|
||||
syntax "repeat " tacticSeq : tactic
|
||||
macro_rules
|
||||
| `(tactic| repeat $seq) => `(tactic| first ($seq); repeat $seq | skip)
|
||||
| `(tactic| repeat $seq) => `(tactic| first | ($seq); repeat $seq | skip)
|
||||
|
||||
syntax "trivial" : tactic
|
||||
|
||||
|
|
|
|||
|
|
@ -177,9 +177,9 @@ macro_rules
|
|||
@ $ctor:ident $ctorArgs*)
|
||||
|
||||
/-
|
||||
Similar to `first`, but succeeds only if one the given tactics solves the curretn goal.
|
||||
Similar to `first`, but succeeds only if one the given tactics solves the current goal.
|
||||
-/
|
||||
syntax "solve " "|"? sepBy1(tacticSeq, "|") : tactic
|
||||
syntax (name := solve) "solve " withPosition((group(colGe "|" tacticSeq))+) : tactic
|
||||
|
||||
macro_rules
|
||||
| `(tactic| solve $[|]? $ts:tacticSeq|*) => `(tactic| focus first $[($ts); done]|*)
|
||||
| `(tactic| solve $[| $ts]* ) => `(tactic| focus first $[| ($ts); done]*)
|
||||
|
|
|
|||
|
|
@ -622,8 +622,7 @@ def withCaseRef [Monad m] [MonadRef m] (arrow body : Syntax) (x : m α) : m α :
|
|||
setGoals gs
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
-- syntax (name := firstNew) "firstNew " withPosition((colGe "|" tacticSeq)+) : tactic
|
||||
@[builtinTactic «firstNew»] partial def evalFirstNew : Tactic := fun stx => do
|
||||
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
|
||||
let tacs := stx[1].getArgs
|
||||
if tacs.isEmpty then throwUnsupportedSyntax
|
||||
loop tacs 0
|
||||
|
|
@ -634,20 +633,6 @@ where
|
|||
else
|
||||
evalTactic tacs[i][1] <|> loop tacs (i+1)
|
||||
|
||||
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
|
||||
if stx.getNumArgs == 2 then
|
||||
evalFirstNew stx
|
||||
else
|
||||
let tacs := stx[2].getSepArgs
|
||||
if tacs.isEmpty then throwUnsupportedSyntax
|
||||
loop tacs 0
|
||||
where
|
||||
loop (tacs : Array Syntax) (i : Nat) :=
|
||||
if i == tacs.size - 1 then
|
||||
evalTactic tacs[i]
|
||||
else
|
||||
evalTactic tacs[i] <|> loop tacs (i+1)
|
||||
|
||||
builtin_initialize registerTraceClass `Elab.tactic
|
||||
|
||||
end Lean.Elab.Tactic
|
||||
|
|
|
|||
14
tests/lean/run/452.lean
Normal file
14
tests/lean/run/452.lean
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
example (h : x ∨ y) : y ∨ x := by
|
||||
cases h with
|
||||
| inl hx => first
|
||||
| apply Or.inr; assumption
|
||||
| apply Or.inl; assumption
|
||||
| inr hy => exact Or.inl hy
|
||||
|
||||
|
||||
example (h : x ∨ y) : y ∨ x := by
|
||||
cases h with
|
||||
| inl hx => first
|
||||
| apply Or.inl; assumption
|
||||
| apply Or.inr; assumption
|
||||
| inr hy => exact Or.inl hy
|
||||
|
|
@ -42,7 +42,7 @@ open Lean.Parser.Tactic in
|
|||
macro "rwd " x:term : tactic => `(rw [$x:term]; done)
|
||||
|
||||
theorem ex (a b c : α) (h₁ : a = b) (h₂ : a = c) : b = a ∧ c = a := by
|
||||
apply And.intro <;> first rwd h₁ | rwd h₂
|
||||
apply And.intro <;> first | rwd h₁ | rwd h₂
|
||||
|
||||
theorem idEq (a : α) : id a = a :=
|
||||
rfl
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ elab "#check2" b:term : command => do
|
|||
#check2 10
|
||||
|
||||
elab "try" t:tactic : tactic => do
|
||||
let t' ← `(tactic| first $t | skip);
|
||||
let t' ← `(tactic| first | $t | skip);
|
||||
Lean.Elab.Tactic.evalTactic t'
|
||||
|
||||
theorem tst (x y z : Nat) : y = z → x = x → x = y → x = z :=
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue