feat: proper support for nullKind at evalTactic
@Kha When we write command macros, we can easily expand a command into multiple ones by using `mkNullNode [cmd_1, ... cmd_n]`. Before this commit, a tactic macro that expands into a sequence of tactics had to produce `mkNullNode [tac_1, "; ", ..., "; ", tac_n]`. I forgot the ";" a few times, and it produces very counterintuitive behavior. This commit is the last step for fixing this issue. The previous commits add the `withResultOf p f` combinator that allows us to implement variants of the `unboxSingleton` trick. Now, ``` `(tactic| t) ``` Produces just `t` as before, but ``` `(tactic| t_1; t_2) ``` produces ``` Syntax.node `Tactic.seq [[t_1, "; ", t_2]] ``` instead of ``` Syntax.node `null [t_1, "; ", t_2] ```
This commit is contained in:
parent
605057b62c
commit
cf85080e7a
2 changed files with 3 additions and 7 deletions
|
|
@ -152,9 +152,8 @@ partial def evalTactic : Syntax → TacticM Unit
|
|||
| stx => withRef stx $ withIncRecDepth $ withFreshMacroScope $ match stx with
|
||||
| Syntax.node k args =>
|
||||
if k == nullKind then
|
||||
-- list of tactics separated by `;` => evaluate in order
|
||||
-- Syntax quotations can return multiple ones
|
||||
stx.forSepArgsM evalTactic
|
||||
-- Macro writers create a sequence of tactics `t₁ ... tₙ` using `mkNullNode #[t₁, ..., tₙ]`
|
||||
stx.getArgs.forM evalTactic
|
||||
else do
|
||||
trace `Elab.step fun _ => stx;
|
||||
env ← getEnv;
|
||||
|
|
|
|||
|
|
@ -44,15 +44,12 @@ private def mkAuxiliaryMatchTerm (parentTag : Name) (matchTac : Syntax) : MacroM
|
|||
(matchTerm, s) ← (mkAuxiliaryMatchTermAux parentTag matchTac).run {};
|
||||
pure (matchTerm, s.cases)
|
||||
|
||||
def mkTacticSeq (ref : Syntax) (tacs : Array Syntax) : Syntax :=
|
||||
mkSepStx tacs (mkAtomFrom ref "; ")
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.match] def evalMatch : Tactic :=
|
||||
fun stx => do
|
||||
tag ← getMainTag;
|
||||
(matchTerm, cases) ← liftMacroM $ mkAuxiliaryMatchTerm tag stx;
|
||||
refineMatchTerm ← `(tactic| refine $matchTerm);
|
||||
let stxNew := mkTacticSeq stx (#[refineMatchTerm] ++ cases);
|
||||
let stxNew := mkNullNode (#[refineMatchTerm] ++ cases);
|
||||
withMacroExpansion stx stxNew $ evalTactic stxNew
|
||||
|
||||
end Tactic
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue