davsclaus opened a new pull request, #26824:
URL: https://github.com/apache/camel/pull/26824
Every language a Camel user comes from has `!`, and it is one of the forms a
local model writes unprompted (three separate benchmark series). Simple had
none, so it had to be written as `${body.isEmpty()} == false`.
```java
simple("!${body.isEmpty()}")
simple("!${body.isEmpty()} && ${header.foo} == 'bar'")
simple("${body} == null || !${body.isEmpty()}")
simple("${body != null && !${body.isEmpty()}}") // operators inside ${ },
CAMEL-24921
```
### Why log messages are safe
This was the main worry, and the language already answers it: **an
expression never tokenizes an operator at all.**
| expression | before and after |
|---|---|
| `Hello ${body}! how are you` | `Hello World! how are you` |
| `!aaa! is a weird text` | `!aaa! is a weird text` |
| `Alert: !${body}` | `Alert: !World` |
| `Order ${body}!!!` | `Order World!!!` |
Even `${body} != 'x'` evaluates to the literal text `World != 'x'` in an
expression. So the tokenizer offers the `!` operator only to a predicate
parser, which is the one that enables it — a `SimpleTokenizer` is created per
parser, so there is no shared state.
Inside a predicate the `!` is a token only when a function follows it
**directly** (`!${`) and what precedes it is nothing, a space or an opening
parenthesis. A quoted `!` is untouched, as the tokenizer takes a quoted string
as one unit: `${body} == 'Hello!'` and `${body} contains '!'` still work.
### The eleven operators that start with a !
`!=`, `!=~`, `!is`, `!contains`, `!~~`, `!regex`, `!in`, `!range`,
`!startsWith`, `!endsWith`, `!equals` are all matched **before** the bare `!`,
which is the last entry in the token table. The test asserts five of them still
work.
### How it differs from ++ and --
Those are postfix and take the node on their left. `!` is written in front
of what it negates, so the node takes the one that follows it, and
`LogicalExpression` accepts a negated function as an operand (a `++` unary is
numeric and is not accepted). A value that is not a boolean says so rather than
guessing:
```
Cannot negate ${body} as it is not true or false but: Hello
```
### Not supported, deliberately
`${!body.isEmpty()}` — a `!` inside a function name — reports `Unknown
function: !body.isEmpty() (did you mean ${body.isEmpty()}?)`, and `${body !=
null && !body.isEmpty()}` still needs `body.isEmpty() == false`. Those go
through the function parser rather than the predicate grammar; CAMEL-24983
gives them a message that says what to write.
### Testing
New `SimpleNotOperatorTest` (5 tests): negation, grouping with `&&`/`||` on
both sides and through `${ }`, the negated operators, and that `!` in text is
not an operator. **The full camel-core suite passes: 7494 tests, 0 failures.**
Docs updated in `simple-operators.adoc`.
Note: if this lands, the message added by CAMEL-24983 (#26822) needs
rewording, since `!` does now negate a function in the `!${...}` form.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj
--
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]