Zulip Chat Archive
Stream: lean4
Topic: Custom parser
Björn Fischer (Sep 21 2022 at 09:54):
Hi guys,
I'm trying to write a parser for alphanumerical names similar to @Sebastian Ullrich 's text parser. I copied it for the most part part, but I'm getting an error when I use it in my syntax.
def name : Parser := withAntiquot (mkAntiquot "name" `LX.text) {
fn := fun c s =>
let startPos := s.pos;
let s := takeWhile1Fn (fun c => c.isAlphanum) "Invalid name" c s;
mkNodeToken `LX.text startPos c s
}
syntax "pql!" name (labelmatcher)? : term
The error is
don't know how to generate formatter for non-definition '{ info :=
{ collectTokens := id, collectKinds := id, firstTokens := FirstTokens.unknown },
fn := fun c s =>
let startPos := s.pos;
let s := takeWhile1Fn (fun c => Char.isAlphanum c) "Invalid name" c s;
mkNodeToken `LX.text startPos c s }'
The stringLit parser works fine
syntax "pql!" strLit (labelmatcher)? : term
What does the error mean?
Björn Fischer (Sep 21 2022 at 10:03):
I'm on leanprover/lean4:v4.0.0-m4
Sebastian Ullrich (Sep 21 2022 at 10:34):
The full definition of the parser is at https://github.com/leanprover/lean4/blob/3e83e28e8f7a81931ef4d6c77b797a60fcfdf5a3/tests/playground/webserver/Webserver.lean#L100-L108, though other parts of that file would need to be updated for current Lean versions
Last updated: Dec 20 2023 at 11:08 UTC