Zulip Chat Archive
Stream: lean4
Topic: Curiosity about syntax positions
Damiano Testa (Aug 05 2024 at 09:13):
This question is mostly out of curiosity.
When Lean parses a file it creates Syntax
objects for the various commands that the file contains.
- Do the syntax ranges for the parsed commands cover the entire file (or the file until
#exit
)? - Is it true that the ranges of two syntax objects are either disjoint or nested?
- Is it always the case that "comments"/whitespace are appended to the end of some Syntax leaf, or can they be somewhere else?
Thanks!
Mario Carneiro (Aug 05 2024 at 11:18):
- it includes
#exit
, but not any commands following it, and also the header is parsed separately - Syntax objects are created synthetically too, so it's not always so simple. For syntax from the parser, yes this should be the case.
- Yes, at least in theory; if you concatenate the atoms, leading/trailing whitespace, and the ident's
rawVal
you should reconstitute the exact contents of the original file.
Damiano Testa (Aug 05 2024 at 11:20):
Ok, great, thank you for the confirmation!
Damiano Testa (Aug 05 2024 at 11:22):
Even though I did not say so, I had in mind of only .original syntax: I had asked about creating "artificial" syntax nodes with specified ranges (and you and Eric showed me how to do it). Same goes for the header.
Last updated: May 02 2025 at 03:31 UTC