Zulip Chat Archive

Stream: lean4

Topic: Quotation for list of list of string


Adam Topaz (Jan 31 2024 at 18:16):

I'm trying to write an elaborator that takes takes some syntax which is a list, separated by ;, of lists of strings, separated by ,, but I'm having a hard time figuring out how to write the necessary quotation... Can someone point me in the right direction?

import Lean
open Lean

syntax "foo%" ((str,*) ";")* : term

open Lean Elab Term
elab_rules : term
  | `(foo%) => sorry
  | `(foo% $xs;) => sorry -- xs : TSyntax `str ???
  -- recursive step???

In the exapmle above, the single case gives me a string literal for xs, where I would have expected an array of string literals. And I don't even know how to start writing the recursive step which considers more than one list of string literals.

Kyle Miller (Jan 31 2024 at 18:21):

Maybe look at docs#Matrix.matrixNotation for inspiration? It's a little more complicated than what you need, since it's handling the case of 0 x n and m x 0 matrices.

Adam Topaz (Jan 31 2024 at 18:23):

Thanks Kyle! Yes I should have thought of that -- this is essentially exactly the same sort of parsing I'm trying to do

Kyle Miller (Jan 31 2024 at 18:24):

Then again, here you go:

syntax "foo%" sepBy((str,*),";") : term

open Lean Elab Term

elab_rules : term
  | `(foo% $[$[$xss],*];*) => sorry -- xss : Array (Array (TSyntax `str))

Kyle Miller (Jan 31 2024 at 18:24):

(Untested beyond not seeing any errors!)

Adam Topaz (Jan 31 2024 at 18:24):

Amazing! Thanks! I always seem to have a hard time remembering where to put the [,] and $ :)

Patrick Massot (Jan 31 2024 at 18:56):

Adam, you're not alone...

Adam Topaz (Jan 31 2024 at 18:57):

We really need some cheatsheet with very many examples of this sort!

Johan Commelin (Jan 31 2024 at 19:10):

It somehow makes me think of Perl...

Adam Topaz (Jan 31 2024 at 19:10):

Is that a good or bad thing?

Patrick Massot (Feb 01 2024 at 02:57):

I think it's meant to make you think of racket.

Sebastian Ullrich (Feb 01 2024 at 07:29):

Rust, actually


Last updated: May 02 2025 at 03:31 UTC