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

Method parseBinaryAndTernaryFromLhs

parser/pratt_parser.go:489–522  ·  view source on GitHub ↗

parseBinaryAndTernaryFromLhs parses the operators following lhs, which is lhsDepth deep, and leaves the depth of the resulting expression in lastParsedDepth.

(lhs ast.Expr, minPrec int, lhsDepth int)

Source from the content-addressed store, hash-verified

487// parseBinaryAndTernaryFromLhs parses the operators following lhs, which is lhsDepth deep, and
488// leaves the depth of the resulting expression in lastParsedDepth.
489func (p *prattParserWorker) parseBinaryAndTernaryFromLhs(lhs ast.Expr, minPrec int, lhsDepth int) ast.Expr {
490 depth := lhsDepth
491 for !p.recursionLimitExceeded && !p.isRecoveryLimitExceeded() {
492 tok := p.peekTok.kind
493 if tok == tokQuestion && minPrec <= 0 {
494 lhs = p.parseTernary(lhs, depth)
495 depth = p.lastParsedDepth
496 continue
497 }
498
499 opInfo := getBinaryOpInfo(tok)
500 if opInfo.kind == tokError || opInfo.precedence < minPrec {
501 break
502 }
503
504 if opInfo.name == operators.LogicalOr || opInfo.name == operators.LogicalAnd {
505 lhs = p.parseLogicalChain(lhs, opInfo, depth)
506 depth = p.lastParsedDepth
507 continue
508 }
509
510 opTok := p.nextToken()
511 opID := p.nextID(opTok)
512 rhs := p.parseBinaryAndTernary(opInfo.precedence + 1)
513 lhs = p.helper.newGlobalCall(opID, opInfo.name, lhs, rhs)
514 // lastParsedDepth is the depth of the rhs just parsed. The operator node
515 // sits one level above whichever operand is deeper: "x + a.b.c.d" reaches
516 // 4 through its rhs and "a.b.c.d + x" reaches 4 through its lhs.
517 depth = max(depth, p.lastParsedDepth) + 1
518 p.checkRecursion(depth)
519 }
520 p.lastParsedDepth = depth
521 return lhs
522}
523
524// parseTernary parses the branches of a conditional whose condition, lhs, is condDepth deep,
525// and leaves the depth of the conditional in lastParsedDepth.

Callers 2

parseBinaryAndTernaryMethod · 0.95
parsePrimaryMethod · 0.95

Calls 9

parseTernaryMethod · 0.95
parseLogicalChainMethod · 0.95
nextTokenMethod · 0.95
nextIDMethod · 0.95
parseBinaryAndTernaryMethod · 0.95
checkRecursionMethod · 0.95
getBinaryOpInfoFunction · 0.85
newGlobalCallMethod · 0.80

Tested by

no test coverage detected