@@ -25,6 +25,7 @@ import Lean.Elab.Tactic.Basic
2525import Lean.Elab.Tactic.RenameInaccessibles
2626import Lean.Elab.Tactic.Grind.Filter
2727import Lean.Elab.Tactic.Grind.ShowState
28+ import Lean.Elab.Tactic.Grind.Config
2829import Lean.Elab.SetOption
2930namespace Lean.Elab.Tactic.Grind
3031
@@ -425,9 +426,30 @@ where
425426 liftGrindM <| resetAnchors
426427 replaceMainGoal [{ goal with mvarId }]
427428
429+ def isGrindConfigField? (stx : Syntax) : CoreM (Option Name) := do
430+ unless stx.isIdent do return none
431+ let id := stx.getId
432+ let env ← getEnv
433+ let info := getStructureInfo env ``Grind.Config
434+ unless info.fieldNames.contains id do return none
435+ return some id
436+
428437@[builtin_grind_tactic setOption] def elabSetOption : GrindTactic := fun stx => do
429- let options ← Elab.elabSetOption stx[1 ] stx[3 ]
430- withOptions (fun _ => options) do evalGrindTactic stx[5 ]
438+ if let some fieldName ← isGrindConfigField? stx[1 ] then
439+ let val := stx[3 ]
440+ let val ← match val.isNatLit? with
441+ | some num => pure <| DataValue.ofNat num
442+ | none => match val with
443+ | Syntax.atom _ "true" => pure <| DataValue.ofBool true
444+ | Syntax.atom _ "false" => pure <| DataValue.ofBool false
445+ | _ => throwErrorAt val "`grind` configuration option must be a Boolean or a numeral"
446+ let config := (← read).ctx.config
447+ let config ← setConfigField config fieldName val
448+ withReader (fun c => { c with ctx.config := config }) do
449+ evalGrindTactic stx[5 ]
450+ else
451+ let options ← Elab.elabSetOption stx[1 ] stx[3 ]
452+ withOptions (fun _ => options) do evalGrindTactic stx[5 ]
431453
432454@[builtin_grind_tactic mbtc] def elabMBTC : GrindTactic := fun _ => do
433455 liftGoalM do
0 commit comments