Skip to content

Commit ce18a34

Browse files
committed
feat: remove +premises from grind? output
1 parent 40e1e09 commit ce18a34

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Lean/Elab/Tactic/Grind/Main.lean

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ def setGrindParams (stx : TSyntax `tactic) (params : Array Syntax) : TSyntax `ta
201201
def getGrindParams (stx : TSyntax `tactic) : Array Syntax :=
202202
stx.raw[grindParamsPos][1].getSepArgs
203203

204+
/-- Filter out `+premises` from the config syntax -/
205+
def filterPremisesFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig) : MetaM (TSyntax ``Lean.Parser.Tactic.optConfig) := do
206+
let configItems := config.raw.getArgs
207+
let filteredItems := configItems.filter fun item =>
208+
-- The structure is: null node -> configItem node -> posConfigItem node
209+
-- We need to check if this is a +premises config item
210+
if let some configItem := item[0]? then
211+
if let some innerItem := configItem[0]? then
212+
if innerItem.getKind == ``Lean.Parser.Tactic.posConfigItem then
213+
if let some ident := innerItem[1]? then
214+
ident.getId != `premises
215+
else
216+
true
217+
else
218+
true
219+
else
220+
true
221+
else
222+
true
223+
return ⟨config.raw.setArgs filteredItems⟩
224+
204225
def mkGrindOnly
205226
(config : TSyntax ``Lean.Parser.Tactic.optConfig)
206227
(trace : Grind.Trace)
@@ -217,7 +238,8 @@ def mkGrindOnly
217238
else
218239
let param ← Grind.globalDeclToGrindParamSyntax declName kind minIndexable
219240
params := params.push param
220-
let result ← `(tactic| grind $config:optConfig only)
241+
let filteredConfig ← filterPremisesFromConfig config
242+
let result ← `(tactic| grind $filteredConfig:optConfig only)
221243
return setGrindParams result params
222244

223245
private def elabGrindConfig' (config : TSyntax ``Lean.Parser.Tactic.optConfig) (interactive : Bool) : TacticM Grind.Config := do
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Lean
2+
3+
set_premise_selector Lean.PremiseSelection.sineQuaNonSelector
4+
5+
-- Test that grind? +premises does NOT include +premises in its output
6+
/--
7+
info: Try this:
8+
[apply] grind only
9+
-/
10+
#guard_msgs in
11+
example {x y : Nat} (h : x = y) : y = x := by
12+
grind? +premises

0 commit comments

Comments
 (0)