Zulip Chat Archive
Stream: lean4
Topic: macro_rules with equation symbol
Ira Fesefeldt (May 24 2024 at 10:29):
I have a syntax category in which I would like to use equality symbols. For some reason, however, macro_rules
does not think I should use them. Instead I get the error unexpected token ']'; expected '='
. Why does this happen and how to solve this?
MWE:
declare_syntax_cat eq
syntax term " = " term : eq
syntax "[eq|" eq "]" : term
def my_eq {α : Type} (a b : α) : Prop := sorry
macro_rules
| `([eq| $a:term = $b:term]) => `(my_eq $a $b)
Eric Wieser (May 24 2024 at 11:05):
The issue is that the term
on the LHS is consuming the =
, because that already is valid as a term
Eric Wieser (May 24 2024 at 11:07):
(Separately, you probably want `(term| [eq| $a:term = $b:term])
to remind lean what category you are trying to match)
Ira Fesefeldt (May 24 2024 at 11:11):
Ah. I see. Thanks for the explanation!
Sebastian Ullrich (May 24 2024 at 12:37):
And the way to solve that is to increase the precedence, syntax term:51 " = " term:51 : eq
Sebastian Ullrich (May 24 2024 at 12:38):
@Eric Wieser term
is the default category
Last updated: May 02 2025 at 03:31 UTC