Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove description argument from register_simp_attr #1566

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Lean/DocString.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ termination_by
consumeSpaces n it r => (it, 1)
saveLine it r => (it, 0)

private def removeLeadingSpaces (s : String) : String :=
def removeLeadingSpaces (s : String) : String :=
let n := findLeadingSpacesSize s
if n == 0 then s else removeNumLeadingSpaces n s

Expand Down Expand Up @@ -92,4 +92,9 @@ def getDocStringText [Monad m] [MonadError m] [MonadRef m] (stx : TSyntax `Lean.
| Syntax.atom _ val => return val.extract 0 (val.endPos - ⟨2⟩)
| _ => throwErrorAt stx "unexpected doc string{indentD stx.raw[1]}"

def TSyntax.getDocString (stx : TSyntax `Lean.Parser.Command.docComment) : String :=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't use getDocStringText because MacroM doesn't have MonadError.

match stx.raw[1] with
| Syntax.atom _ val => val.extract 0 (val.endPos - ⟨2⟩)
| _ => panic! s!"unexpected doc string\n{stx.raw[1]}"

end Lean
10 changes: 6 additions & 4 deletions src/Lean/Meta/Tactic/Simp/SimpTheorems.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Lean.Meta.DiscrTree
import Lean.Meta.AppBuilder
import Lean.Meta.Eqns
import Lean.Meta.Tactic.AuxLemma
import Lean.DocString
namespace Lean.Meta

/--
Expand Down Expand Up @@ -415,12 +416,13 @@ def SimpTheoremsArray.isErased (thmsArray : SimpTheoremsArray) (thmId : Name) :
def SimpTheoremsArray.isDeclToUnfold (thmsArray : SimpTheoremsArray) (declName : Name) : Bool :=
thmsArray.any fun thms => thms.isDeclToUnfold declName

macro (name := _root_.Lean.Parser.Command.registerSimpAttr) doc?:(docComment)?
"register_simp_attr" id:ident descr:str : command => do
macro (name := _root_.Lean.Parser.Command.registerSimpAttr) doc:docComment
"register_simp_attr" id:ident : command => do
let str := id.getId.toString
let idParser := mkIdentFrom id (`Parser.Attr ++ id.getId)
`($[$doc?]? initialize ext : SimpExtension ← registerSimpAttr $(quote id.getId) $descr $(quote id.getId)
$[$doc?]? syntax (name := $idParser:ident) $(quote str):str (Parser.Tactic.simpPre <|> Parser.Tactic.simpPost)? (prio)? : attr)
let descr := quote (removeLeadingSpaces doc.getDocString)
`($doc:docComment initialize ext : SimpExtension ← registerSimpAttr $(quote id.getId) $descr $(quote id.getId)
$doc:docComment syntax (name := $idParser:ident) $(quote str):str (Parser.Tactic.simpPre <|> Parser.Tactic.simpPost)? (prio)? : attr)

end Meta

Expand Down
2 changes: 1 addition & 1 deletion tests/lean/run/1374.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ register_builtin_option testb : Nat := {
}

/-- My new simp attribute -/
register_simp_attr mysimp "my simp attr"
register_simp_attr mysimp

/-- config elab -/
declare_config_elab elabSimpConfig' Lean.Meta.Simp.Config
4 changes: 2 additions & 2 deletions tests/pkg/user_attr/UserAttr/BlaAttr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ open Lean

initialize blaAttr : TagAttribute ← registerTagAttribute `bla "simple user defined attribute"

/-- My new simp attribute -/
register_simp_attr my_simp "my own simp attribute"
/-- My own new simp attribute. -/
register_simp_attr my_simp

syntax (name := foo) "foo" num "important"? : attr

Expand Down