Zulip Chat Archive
Stream: lean4
Topic: Syntax atoms beginning with a single quote
František Silváši (Aug 23 2022 at 14:52):
Is there any way to make: notation "\'" x => x
work? i.e. use '
as the very first character of an atom; or do we always hit the codepath via Lean.Elab.Syntax.isValidAtom
which explicitly prohibits this.
Jakob von Raumer (Sep 02 2024 at 15:55):
Did you get any reply? In my case I don't even need the result to be atomic. Trying to parse single '
like this, but Lean still seems to want to parse a character literal:
def singleSingleQuote : Parser := rawCh '\'' (trailingWs := false)
@[combinator_formatter singleSingleQuote]
def singleSingleQuote.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous
@[combinator_parenthesizer singleSingleQuote]
def singleSingleQuote.parenthesizer := PrettyPrinter.Parenthesizer.visitToken
syntax singleSingleQuote noWs ident : kid
syntax "`[kid|" kid "]" : term
#eval `[kid|'foo]
François G. Dorais (Sep 03 2024 at 00:30):
I think this needs an RFC to Lean core.
Jakob von Raumer (Sep 03 2024 at 09:22):
cc @Sebastian Ullrich
Sebastian Ullrich (Sep 03 2024 at 11:43):
Do you need it at the beginning of a syntax category? The above category only has one production so it's not really necessary in that specific example
Jakob von Raumer (Sep 03 2024 at 12:20):
Ah, I guess I can avoid that
Jakob von Raumer (Sep 03 2024 at 12:24):
Works! Why does that make a difference?
Sebastian Ullrich (Sep 03 2024 at 14:36):
The production of the syntax category is chosen via parseToken. So it might also work if Parser.info is set up correctly for your custom parser.
Jakob von Raumer (Sep 03 2024 at 16:28):
Jakob von Raumer said:
Ah, I guess I can avoid that
Can avoid that in that syntax category, but to not have it at the start of any syntax category upwards from it is close to impossible. Will look at the Parser.info
Sebastian Ullrich (Sep 03 2024 at 16:46):
Not sure I understand that, if it's not at the beginning of the immediately surrounding category, how can it be at the beginning further up the stack?
Jakob von Raumer (Sep 03 2024 at 20:23):
Eh, my "solution" was to turn the category that's called kid
in the example above into a straight ParserDescr
instead of a syntax category, but that just shifts the problem.
Jakob von Raumer (Sep 04 2024 at 11:46):
The production of the syntax category is chosen via parseToken.
Did you really mean parseToken
? I can only find tat in the formatter :thinking:
Last updated: May 02 2025 at 03:31 UTC