chore: prepare to change first syntax

This commit is contained in:
Leonardo de Moura 2021-05-10 16:42:47 -07:00
parent 0e1f645b07
commit 7d39a0d56c
2 changed files with 18 additions and 2 deletions

View file

@ -227,6 +227,7 @@ 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 := rotateLeft) "rotateLeft" (num)? : tactic
syntax (name := rotateRight) "rotateRight" (num)? : tactic
macro "try " t:tacticSeq : tactic => `(first $t | skip)

View file

@ -622,10 +622,25 @@ def withCaseRef [Monad m] [MonadRef m] (arrow body : Syntax) (x : m α) : m α :
setGoals gs
| _ => throwUnsupportedSyntax
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
let tacs := stx[2].getSepArgs
-- syntax (name := firstNew) "firstNew " withPosition((colGe "|" tacticSeq)+) : tactic
@[builtinTactic «firstNew»] partial def evalFirstNew : Tactic := fun stx => do
let tacs := stx[1].getArgs
if tacs.isEmpty then throwUnsupportedSyntax
loop tacs 0
where
loop (tacs : Array Syntax) (i : Nat) :=
if i == tacs.size - 1 then
evalTactic tacs[i][1]
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