Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: Examples on delaborating for whitespace/indentation
nrs (Jan 15 2025 at 23:03):
Am trying to make a delaborator that will print a top-level function as
someFunc
• arg1
• arg2
Does anyone have examples of delaborators or unexpanders that control whitespace and indentation?
Kyle Miller (Jan 15 2025 at 23:04):
Delaborators don't control whitespace or indentation.
Instead, you need to somehow encode whitespace handling in the syntax definition itself.
nrs (Jan 15 2025 at 23:06):
Hm I see. Any chance you could give me a vague idea of what it would mean to encode whitespace in Syntax
? Do you mean e.g. using tab/space/whitespace characters in the String
for e.g. Syntax.atom
?
Damiano Testa (Jan 15 2025 at 23:06):
Wasn't there an example of exactly this in the early days of lean 4?
Damiano Testa (Jan 15 2025 at 23:11):
Maybe "early days" was not really correct, but this discussion is what I had in mind.
Kyle Miller (Jan 15 2025 at 23:13):
How about you give your syntax definition as a #mwe?
Damiano Testa (Jan 15 2025 at 23:13):
Oh, you want the arguments to be displayed in that format, not entered like that!
nrs (Jan 15 2025 at 23:16):
@Kyle Miller concretely I'm trying to make this for an arbitrary recursor. as a special case I'm working with the Expr
from List.permutationsAux.rec
(just so happened to be the example that made me start on ideas for making verbose Expr
s easier to read)
def permutationsAux.rec {C : List α → List α → Sort v} (H0 : ∀ is, C [] is)
(H1 : ∀ t ts is, C ts (t :: is) → C is [] → C (t :: ts) is) : ∀ l₁ l₂, C l₁ l₂
| [], is => H0 is
| t :: ts, is =>
H1 t ts is (permutationsAux.rec H0 H1 ts (t :: is)) (permutationsAux.rec H0 H1 is [])
termination_by ts is => (length ts + length is, length ts)
decreasing_by all_goals (simp_wf; omega)
@Damiano Testa yeah, only pretty printing!
Kyle Miller (Jan 15 2025 at 23:28):
Maybe you could look at how match
syntax is defined and look in Delaborators/Builtins for the builtin match
delaborator.
nrs (Jan 15 2025 at 23:29):
will get started on that, thank you!
Kyle Miller (Jan 15 2025 at 23:30):
Note that since match
syntax is builtin, it's using a lower-level parser description than syntax
. For user-defined syntax, syntax
is nicer.
nrs (Jan 16 2025 at 18:52):
open Std Format
def myFormat : Format :=
.append (.text "theFunc")
(.append (.nest 2 line)
(.append (.text "arg, the First")
(.append (.nest 2 line)
(.text "seconarg"))))
#eval IO.println myFormat
nrs (Jan 16 2025 at 18:58):
more examples in the Wadler article mentioned at docs#Std.Format
Last updated: May 02 2025 at 03:31 UTC