Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: Parenthesizing custom syntax
Sergei Stepanenko (Oct 29 2025 at 12:32):
Hi all!
I think misunderstand something about parenthesizers for custom syntax.
Is there a canonical way parenthesize delaborator output based on the specified precedence? (Or doing it in the delaborator is simply wrong?)
E.g., in the example below, I try to invoke
let stx ← parenthesizeCategory `term_lang stx
expecting it to add parenthesis to syntax.
However, the final output doesn't contain parenthesis. Is it parenthesizeCategory not doing anything? Or parenthesis are removed by something in-between delaboration and printing?
Thank you in advance and sorry if it was already asked on Zulip. I found only examples for custom parsers.
MWE
Robin Arnez (Oct 29 2025 at 17:55):
You need to register a category parenthesizer:
open Parenthesizer in
@[category_parenthesizer term_lang]
def term_lang.parenthesizer : CategoryParenthesizer := fun prec => do
maybeParenthesize `term_lang false (fun stx => Unhygienic.run `(term_lang| ($(⟨stx⟩):term_lang))) prec <|
parenthesizeCategoryCore `term_lang prec
Sergei Stepanenko (Nov 17 2025 at 17:22):
Robin Arnez said:
You need to register a category parenthesizer:
open Parenthesizer in @[category_parenthesizer term_lang] def term_lang.parenthesizer : CategoryParenthesizer := fun prec => do maybeParenthesize `term_lang false (fun stx => Unhygienic.run `(term_lang| ($(⟨stx⟩):term_lang))) prec <| parenthesizeCategoryCore `term_lang prec
Thanks! Works perfectly!
Last updated: Dec 20 2025 at 21:32 UTC