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

Method parseTernary

parser/pratt_parser.go:526–541  ·  view source on GitHub ↗

parseTernary parses the branches of a conditional whose condition, lhs, is condDepth deep, and leaves the depth of the conditional in lastParsedDepth.

(lhs ast.Expr, condDepth int)

Source from the content-addressed store, hash-verified

524// parseTernary parses the branches of a conditional whose condition, lhs, is condDepth deep,
525// and leaves the depth of the conditional in lastParsedDepth.
526func (p *prattParserWorker) parseTernary(lhs ast.Expr, condDepth int) ast.Expr {
527 qTok := p.nextToken()
528 opID := p.nextID(qTok)
529 trueExpr := p.parseBinaryAndTernary(1)
530 depth := max(condDepth, p.lastParsedDepth)
531 if !p.expect(tokColon, "expected ':' in conditional expression") {
532 p.lastParsedDepth = condDepth
533 return lhs
534 }
535 falseExpr := p.parseExpr()
536 // The conditional node sits one level above the deepest of its operands.
537 depth = max(depth, p.lastParsedDepth) + 1
538 p.lastParsedDepth = depth
539 p.checkRecursion(depth)
540 return p.helper.newGlobalCall(opID, operators.Conditional, lhs, trueExpr, falseExpr)
541}
542
543// parseLogicalChain parses a run of '&&' or '||' operators following lhs, which is lhsDepth
544// deep, and leaves the depth of the resulting expression in lastParsedDepth. Logical operators

Callers 1

Calls 7

nextTokenMethod · 0.95
nextIDMethod · 0.95
parseBinaryAndTernaryMethod · 0.95
expectMethod · 0.95
parseExprMethod · 0.95
checkRecursionMethod · 0.95
newGlobalCallMethod · 0.80

Tested by

no test coverage detected