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)
| 487 | // parseBinaryAndTernaryFromLhs parses the operators following lhs, which is lhsDepth deep, and |
| 488 | // leaves the depth of the resulting expression in lastParsedDepth. |
| 489 | func (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. |
no test coverage detected