MCPcopy Create free account
hub / github.com/cel-expr/cel-go / isAmbiguousUnaryOperand

Function isAmbiguousUnaryOperand

parser/unparser.go:556–570  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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`.
556func 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

Callers 1

visitCallUnaryMethod · 0.85

Calls 4

KindMethod · 0.65
FunctionNameMethod · 0.65
AsCallMethod · 0.65
AsLiteralMethod · 0.65

Tested by

no test coverage detected