When do nodes have None position? #97
-
When a tree has been parsed from a string, will they always have positions? Edit: I peeked at the construction of one node: Html and found that there is a case where position is None. But there are many nodes. I hope there's a straightforward answer to this. I'd also be able to pass on that option to my users, if it can be None in my usage, but I'd better be certain of it. To be clear, my usage is:
Can I expect all of these children to have Some positions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
Welcome @mightyiam! 👋 Taking a step back, this feels a lot like an XY Problem.
No, they will not. |
Beta Was this translation helpful? Give feedback.
Then an Abstract Syntax Tree (AST) based project isn't suitable.
Abstract syntax trees focus on the abstract structure rather than syntax detail.
Positions in most (likely all) AST based libraries are designed for debugging and source mapping, not editing.
Most of the major rust based markdown parsers are AST based including:
What you are describing @mightyiam sounds more like a Concrete Syntax Tree (CST), which preserves all detail about the text so it can be exactly reconstructed.
There are very fe…