Skip to content

JMESPath let expression with operator in variable binding#691

Open
BartelNieuwenhuyse wants to merge 2 commits intodanielaparker:masterfrom
BartelNieuwenhuyse:bugfix/jmespath_let-expression-with-operator
Open

JMESPath let expression with operator in variable binding#691
BartelNieuwenhuyse wants to merge 2 commits intodanielaparker:masterfrom
BartelNieuwenhuyse:bugfix/jmespath_let-expression-with-operator

Conversation

@BartelNieuwenhuyse
Copy link
Copy Markdown

Fix for issue #690

JMESPath expressions with an operator in the expression part of a variable binding (expression between 'let $var=' and 'in') are not parsed correctly.
given:
{"foo": false, "bar": true}
search expression:
let $var = foo || bar in $var
expected:
yields result true
actual:
gives error during evaluation: assertion 'stack.size() == 1' failed

I've added an implicit lparen '(' when encountering the '=' of the let expression, such that the operator stack can be rewind when hitting the ',' or 'in' of the let-expression.

I've stored the name of the variable in a variable token when encountering the '=', rather than storing it in the expression_context. And use this variable token to mark the start of the binding expression, rather than storing the end_index in the expression_context. I'm not sure if after this change, expression_context has any other use as it seems to be an empty class now.

When hitting the ',' or 'in' of the let-expression the variable token and the tokens of the expression, including the operator stack up until the implicit lparen '(' are moved into the variable_expression, which on evaluation will evaluate the tokens, store the result in the context and return the original document at the start of the let expression.

Moved this logic to push_token, rather than (duplicating it) in the compile function

@danielaparker
Copy link
Copy Markdown
Owner

I figured this was coming :-) I'll review it when I have a chance. But I think the approach is basically right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants