gnodet opened a new pull request, #20936:
URL: https://github.com/apache/camel/pull/20936
This commit implements support for the ternary operator (`condition ?
trueValue : falseValue`)
in Apache Camel's Simple language, providing a more familiar syntax
alongside the existing
iif function.
## Key Changes:
- Added new token types (ternaryOperator, ternaryColon) to TokenType enum
- Created TernaryOperatorType enum to represent the ternary operator
- Implemented TernaryExpression AST node with support for:
* Condition evaluation with proper boolean type conversion
* True and false value branches
* Quote handling for literal values
* Code generation for csimple
- Updated SimpleTokenizer to recognize `?` and `:` operators with proper
spacing requirements
- Extended SimplePredicateParser and SimpleExpressionParser to:
* Parse ternary operator syntax
* Prepare ternary expressions in the AST
* Handle nested ternary operators
- Added comprehensive test suite covering:
* Basic ternary operations
* Nested ternary operators
* Integration with existing Simple language features
* Null value handling
* Type coercion
* Backward compatibility with iif function and elvis operator
The implementation maintains full backward compatibility with existing
Simple language
features including the iif function and the elvis operator (?:).
## Examples:
- Basic: `${header.foo > 10 ? 'high' : 'low'}`
- Nested: `${header.x > 10 ? (header.y > 5 ? 'A' : 'B') : 'C'}`
- With functions: `${header.foo > 0 ? ${body} : 'default'}`
JIRA: https://issues.apache.org/jira/browse/CAMEL-22873
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]