Indicates whether the operand of a unary operator must be wrapped in parentheses in order for the unparsed expression to parse back to an equivalent AST. The CEL grammar parses a run of leading '!' or '-' tokens as a single unary expression and drops the operators when their count is even, and it a
(expr ast.Expr)
| 554 | // `!(!a)` would unparse to `!!a` which parses back to `a`, or produces output which does not parse |
| 555 | // at all, e.g. `-(!a)` would unparse to `-!a`. |
| 556 | func isAmbiguousUnaryOperand(expr ast.Expr) bool { |
| 557 | switch expr.Kind() { |
| 558 | case ast.CallKind: |
| 559 | fun := expr.AsCall().FunctionName() |
| 560 | return fun == operators.LogicalNot || fun == operators.Negate |
| 561 | case ast.LiteralKind: |
| 562 | switch lit := expr.AsLiteral().(type) { |
| 563 | case types.Int: |
| 564 | return lit < 0 |
| 565 | case types.Double: |
| 566 | return math.Signbit(float64(lit)) |
| 567 | } |
| 568 | } |
| 569 | return false |
| 570 | } |
| 571 | |
| 572 | // Indicates whether it is a complex operation compared to another. |
| 573 | // expr is *not* considered complex if it is not a call expression or has |
no test coverage detected