diff --git a/src/Init/Notation.lean b/src/Init/Notation.lean index 9ef2f1d21f..dc7e90ccf1 100644 --- a/src/Init/Notation.lean +++ b/src/Init/Notation.lean @@ -256,7 +256,7 @@ syntax (name := injection) "injection " term (" with " (colGt (ident <|> "_"))+) syntax simpPre := "↓" syntax simpPost := "↑" syntax simpLemma := (simpPre <|> simpPost)? term -syntax (name := simp) "simp " ("[" simpLemma,* "]")? (colGt term)? (location)? : tactic +syntax (name := simp) "simp " (&"only ")? ("[" simpLemma,* "]")? (colGt term)? (location)? : tactic syntax (name := «have») "have " haveDecl : tactic syntax (name := «suffices») "suffices " sufficesDecl : tactic diff --git a/src/Lean/Elab/Tactic/Simp.lean b/src/Lean/Elab/Tactic/Simp.lean index 9264a43cac..dfb6cee88c 100644 --- a/src/Lean/Elab/Tactic/Simp.lean +++ b/src/Lean/Elab/Tactic/Simp.lean @@ -119,10 +119,15 @@ where return none /- - "simp " ("[" simpLemma,* "]")? (colGt term)? (location)? + "simp " ("only ")? ("[" simpLemma,* "]")? (colGt term)? (location)? -/ @[builtinTactic Lean.Parser.Tactic.simp] def evalSimp : Tactic := fun stx => do - let ctx ← elabSimpLemmas stx[2] { config := (← elabSimpConfig stx[3]), simpLemmas := (← getSimpLemmas), congrLemmas := (← getCongrLemmas) } + let simpOnly := !stx[1].isNone + let ctx ← elabSimpLemmas stx[2] { + config := (← elabSimpConfig stx[3]) + simpLemmas := if simpOnly then {} else (← getSimpLemmas) + congrLemmas := (← getCongrLemmas) + } let loc := expandOptLocation stx[4] match loc with | Location.target => simpTarget ctx diff --git a/tests/lean/run/simpOnly.lean b/tests/lean/run/simpOnly.lean new file mode 100644 index 0000000000..c39a6d7176 --- /dev/null +++ b/tests/lean/run/simpOnly.lean @@ -0,0 +1,13 @@ +theorem ex1 (n m : Nat) : 0 + (n, m).1 = n := by + simp only + rw [Nat.zero_add] + +theorem ex2 (n m : Nat) : 0 + (n, m).1 = n := by + simp + +theorem ex3 (n m : Nat) : 0 + (n, m).1 + 0 = n := by + simp only [Nat.add_zero] + rw [Nat.zero_add] + +theorem ex4 (n m : Nat) : 0 + (n, m).1 + 0 = n := by + simp