Implement ChunkResolver by extending ExtendedParser #527
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@jboulter Because of your comment about the parser that exists in Jinjava, I decided to look into it as an alternative to the ChunkResolver PR that I opened #525.
It essentially does the same thing that the ChunkResolver does but in a more low-level (and probably faster) way.
Rather than introducing a new parser that works on top of the
interpreter.resolveELExpression()
, this approach instead extends the Jinjava parser itself by providing decorators for all the different types of AstNodes to allow for deferred values to be handled when they are evaluated.I created a new Exception type that passes through the Abstract Syntax Tree as it gets evaluated, and when one of the decorated nodes sees this exception, it partially evaluates its children (or whatever they are specifically for each type of AstNode).
This method for partially resolving expressions is more complex than the initial ChunkResolver PR because I had to implement custom overrides for all the different AstNodes.
This is a draft PR because idk if I want to go with this approach. It's a lot more complex than the ChunkResolver, and I haven't fully tested out all the code (I only have it tested against the tests that I wrote for the ChunkResolver PR). A pro to this approach is that I think it is faster than the other PR because the expression gets evaluated a single time, rather than being evaluated several times in sub-expressions.
I don't intend for anyone to read through this code, it's currently just a proof of concept, unless we decide to go with this approach.