Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: scoped notation in an attribute
Chris Henson (Oct 23 2025 at 15:18):
In CSLib we have a command and attribute that creates notations. I would like to change these to be scoped the same as the declaration the attribute is applied to. On its own having scoped notation3 in a macro is fine, but will not work from within an attribute. Is there a way I can manually specify the namespace the notation should use?
Chris Henson (Oct 23 2025 at 21:10):
I had the thought that I could manually assemble the Lean.ParserDescr, but there are several downsides to this:
- for
notation3, this doesn't handle the generated delaborators - even if I add the definition, I'm not sure how that gets registered as notation
- a bit annoying for maintainability
What I feel I need is a way to pass to scoped (within an attribute/macro) what namespace it should be using.
Eric Wieser (Oct 27 2025 at 11:38):
Does this work?
syntax attrKind "reduction_notation" ident (str)? : command
macro_rules
| `($kind:attrKind reduction_notation $rs $sym) =>
`(
$kind:attrKind notation3 t:39 " ⭢" $sym:str t':39 => (ReductionSystem.Red $rs) t t'
$kind:attrKind notation3 t:39 " ↠" $sym:str t':39 => (ReductionSystem.MRed $rs) t t'
)
| `($kind:attrKind reduction_notation $rs) =>
`(
$kind:attrKind notation3 t:39 " ⭢ " t':39 => (ReductionSystem.Red $rs) t t'
$kind:attrKind notation3 t:39 " ↠ " t':39 => (ReductionSystem.MRed $rs) t t'
)
(found by looking at this line)
Chris Henson (Oct 27 2025 at 12:29):
Ah, that got me halfway there, thanks! Along with docs#Lean.Elab.Command.modifyScope, I was able to make it work from within an attribute in cslib#133.
Last updated: Dec 20 2025 at 21:32 UTC