(p *PrettyCfg)
| 443 | } |
| 444 | |
| 445 | func (node *BinaryExpr) doc(p *PrettyCfg) pretty.Doc { |
| 446 | // All the binary operators are at least left-associative. |
| 447 | // So we can always simplify "(a OP b) OP c" to "a OP b OP c". |
| 448 | parenPrio := binaryOpPrio[node.Operator] |
| 449 | leftOperand := p.peelBinaryOperand(node.Left, true /*sameLevel*/, parenPrio) |
| 450 | // If the binary operator is also fully associative, |
| 451 | // we can also simplify "a OP (b OP c)" to "a OP b OP c". |
| 452 | opFullyAssoc := binaryOpFullyAssoc[node.Operator] |
| 453 | rightOperand := p.peelBinaryOperand(node.Right, opFullyAssoc, parenPrio) |
| 454 | |
| 455 | opDoc := pretty.Text(node.Operator.String()) |
| 456 | var res pretty.Doc |
| 457 | if !node.Operator.isPadded() { |
| 458 | res = pretty.JoinDoc(opDoc, p.Doc(leftOperand), p.Doc(rightOperand)) |
| 459 | } else { |
| 460 | pred := func(e Expr, recurse func(e Expr)) bool { |
| 461 | if b, ok := e.(*BinaryExpr); ok && b.Operator == node.Operator { |
| 462 | leftSubOperand := p.peelBinaryOperand(b.Left, true /*sameLevel*/, parenPrio) |
| 463 | rightSubOperand := p.peelBinaryOperand(b.Right, opFullyAssoc, parenPrio) |
| 464 | recurse(leftSubOperand) |
| 465 | recurse(rightSubOperand) |
| 466 | return true |
| 467 | } |
| 468 | return false |
| 469 | } |
| 470 | formatOperand := func(e Expr) pretty.Doc { |
| 471 | return p.Doc(e) |
| 472 | } |
| 473 | operands := p.flattenOp(leftOperand, pred, formatOperand, nil) |
| 474 | operands = p.flattenOp(rightOperand, pred, formatOperand, operands) |
| 475 | res = pretty.JoinNestedRight( |
| 476 | opDoc, operands...) |
| 477 | } |
| 478 | return pretty.Group(res) |
| 479 | } |
| 480 | |
| 481 | func (node *ParenExpr) doc(p *PrettyCfg) pretty.Doc { |
| 482 | return p.bracket("(", p.Doc(node.Expr), ")") |
nothing calls this directly
no test coverage detected