-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eager expression node #548
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… into eager-expression-node
boulter
reviewed
Dec 7, 2020
JinjavaInterpreter interpreter | ||
) { | ||
if ( | ||
interpreter.getConfig().getExecutionMode().isPreserveRawTags() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to a create a variable for interpreter.getConfig()
to shorten up these lines.
@@ -0,0 +1,3 @@ | |||
{{ '{{ foo }}' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd inline all of these test files for readability.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #532
This PR adds in the functionality that is necessary to interpret an expression node when doing eager execution. The expression node needs to get treated similarly to a
PrintTag
, and it has nearly the same logic, save for the possibility for nested interpretation. Because of this, several static methods from the EagerTagDecorator are used to partially or fully evaluate the expression within the node.It uses the chunk resolver in a child context to evaluate the expression in chunks. For more detail on how the chunk resolver works, see #525. If the interpretation is run in
protectedMode
, then if any values on the context are updated, a SetTag is pre-pended to the output to preserve the state of the context. In other words, performing the sort of speculative execution done when unsure which branch of an IfTag to execute, the values should be preserved on the context. Quick example:When executing these expressions, since the value of
list
gets updated viaappend()
andprotectedMode
would betrue
, then the desired output would be something like:The IfTag functionality has not been PR'd yet, but it helps demonstrate the purpose of
protectedMode
. (Again, this functionality is similar to pre-pending a SetTag after interpreting certain tags as well.Somewhat similar to the set tag pre-pending, if an expression node references a macro function which must be deferred such as
{{ some_macro(deferred) }}
, then the macro function's image must be pre-pended as well as described in #547.We use
chunkResolver.getDeferredWords().isEmpty()
to determine if the expression was able to be completely evaluated. If there are any deferred words, then we know that the expression node must be "reconstructed", and the partially evaluated result gets wrapped in double curly braces. If there are no words, however, then the logic continues similarly to theDefaultExpressionStrategy
, although we must keep in mind that the output may need to be wrapped in a raw tag if nested interpretation is disabled. Ex:{{ 'this is an expression' + '{{ foo }}' }}
would need to be output as:{% raw %}this is an expression {{ foo }}{% endraw %}
to prevent evaluation on a second rendering pass if the execution mode specifiesisPreserveRawTags() == true
.cc @boulter @Joeoh @gobimcp feel free to bring up any questions or comments you may have about this alternate strategy for processing expression nodes (see #544 for how I added the strategy pattern into the expression node logic, allowing for different approaches to the logic for an
ExpressionNode
)