[chore][pkg/stanza] Upgrade expr module to latest #24648
Merged
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.
Fixes #24575
This upgrade involves a workaround for a grammar conflict introduced in this PR.
pkg/stanza
previously added a custom function to the syntax calledenv()
, which allows users to fetch values from OS environment variables.The latest version of the
expr
module introduced its own keywordenv
, but the meaning and usage were different. Still, the overlap was enough to cause failures in the compilation and rendering of expressions.The new syntax was introduced as a Membership Operator, which means that the proper way to use it is with square brackets,
env[]
. This resulted in our customenv()
syntax being flagged as invalid.More importantly, the meaning of the new
env[]
is not the same. While we useenv()
to lookup values from the OS environment,env[]
is meant to pull values from an in-memory map. This map allows for customizations of the syntax, such as those that allow users to reference "body" or "attributes" within an expression, but it does not contain OS environment variables. Therefore, accessing it with the new syntax is of limited value to users.The solution used here is a Patch option which allows us to inspect and modify elements of the grammar as an expression is being compiled. Fortunately,
env()
is understood to be a function call, whileenv[]
is otherwise. This makes it possible to detect usage of our custom syntax and rename the function internally without any impact to the user.The PR also standardizes all uses of
expr.Compile
withinpkg/stanza
to ensure they are using the new patch option.