Skip to content

JMESPath short circuit or and operator#698

Merged
danielaparker merged 3 commits intodanielaparker:jmespath_binary_opfrom
BartelNieuwenhuyse:feature/jmespath_short-circuit-or-and-operator
Apr 21, 2026
Merged

JMESPath short circuit or and operator#698
danielaparker merged 3 commits intodanielaparker:jmespath_binary_opfrom
BartelNieuwenhuyse:feature/jmespath_short-circuit-or-and-operator

Conversation

@BartelNieuwenhuyse
Copy link
Copy Markdown

Code change to short circuit the logical and && and or || operators:

  • lhs && rhs: if lhs is false, return it without evaluating rhs
  • lhs || rhs: if lhs is true, return it without evaluating rhs

For this change, I made an operator_base as base class for the unary (not !) and binary (comparators ==, <, etc.) operators and a new logical (and && and or ||) operator. operator_base has a single interface: operator_base::evaluate takes a reference val and a vector of expressions, which contains 1 expression for the unary and 2 expressions [lhs, rhs] for the binary and logical operators.

To hold this vector, I introduced the operator_expression which references an operator_base and is the owner of a vector of expressions. When evaluating, operator_expression::evaluate forwards the value it gets plus the expressions it owns to the operator_base.

The compilation happens as follows:

  • tokens are compiled and placed on the output_stack
  • when an operator is encountered, it collects its left hand side tokens by sweeping back over the output_stack and collecting everything belonging to its left hand side. It is then placed on the operator_stack
  • when it is popped from the operator_stack, it again sweeps over the output_stack to collect everything belonging to its right hand side. And then placed on the output_stack.

@danielaparker danielaparker changed the base branch from master to jmespath_binary_op April 21, 2026 22:35
@danielaparker danielaparker merged commit e837e0f into danielaparker:jmespath_binary_op Apr 21, 2026
37 checks passed
@danielaparker
Copy link
Copy Markdown
Owner

Nice! I've merged this PR into the branch jmespath_binary_op where I'll have the opportunity to study it more carefully and make sure there's sufficient test coverage for the different possibilities on the left and right sides.

@BartelNieuwenhuyse
Copy link
Copy Markdown
Author

Thank you!

@BartelNieuwenhuyse BartelNieuwenhuyse deleted the feature/jmespath_short-circuit-or-and-operator branch May 8, 2026 17:33
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