[RFC] parser: lineno_end, linepos[_end] and fault tolerance#2173
[RFC] parser: lineno_end, linepos[_end] and fault tolerance#2173InsanePrawn wants to merge 19 commits into
Conversation
|
Thanks for putting work into this. Just setting expectations here, I'm not willing to modify the parser this much right now. It will probably be a year or more before I get Jinja in a place where I am willing, and at that point the parser may be very different. Even after that, I don't think building a fault tolerant parser will be a goal. |
|
Hi, thanks for the fast response!
Alright, that's good to know!
FWIW, I made the "fault tolerant" mode explicitly optional and only intended it for collecting error diagnostics, nobody should expect to be able to render or do anything else terribly meaningful from such a parse. Rendering should also error out on hitting those nodes iirc. As you can see in the diff, it wasn't terribly difficult and imo not too messy to get basic tolerance for a bunch of common cases like empty There's still a bunch of cases where the parser (intentionally) barfs up a big "parser failed here" error node and nothing beyond that. |
This PR is a "dirty" WIP branch of mine that adds two things:
parser_tolerate_faultsenvironment flag to add exceptions as new ExprIssue and ParserIssue subclasses into the AST rather than throwing it, where possible.At this point, I'm mostly seeking feedback on whether the project would be interested in getting these changes as clean MRs, architectural critiques, etc.
I do have a somewhat working LSP prototype based on this, that correctly displays inlined exception nodes as diagnostics and I'm building autocompletions, type inferencing and -checking on top using jedi or similar.
TODO if upstream is interested in this:
should fail without the change.
.. versionchanged::entries in any relevant code docs.