MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / doc

Method doc

pkg/sql/sem/tree/pretty.go:473–507  ·  view source on GitHub ↗
(p *PrettyCfg)

Source from the content-addressed store, hash-verified

471}
472
473func (node *BinaryExpr) doc(p *PrettyCfg) pretty.Doc {
474 // All the binary operators are at least left-associative.
475 // So we can always simplify "(a OP b) OP c" to "a OP b OP c".
476 parenPrio := binaryOpPrio[node.Operator.Symbol]
477 leftOperand := p.peelBinaryOperand(node.Left, true /*sameLevel*/, parenPrio)
478 // If the binary operator is also fully associative,
479 // we can also simplify "a OP (b OP c)" to "a OP b OP c".
480 opFullyAssoc := binaryOpFullyAssoc[node.Operator.Symbol]
481 rightOperand := p.peelBinaryOperand(node.Right, opFullyAssoc, parenPrio)
482
483 opDoc := pretty.Text(node.Operator.String())
484 var res pretty.Doc
485 if !node.Operator.Symbol.IsPadded() {
486 res = pretty.JoinDoc(opDoc, p.Doc(leftOperand), p.Doc(rightOperand))
487 } else {
488 pred := func(e Expr, recurse func(e Expr)) bool {
489 if b, ok := e.(*BinaryExpr); ok && b.Operator == node.Operator {
490 leftSubOperand := p.peelBinaryOperand(b.Left, true /*sameLevel*/, parenPrio)
491 rightSubOperand := p.peelBinaryOperand(b.Right, opFullyAssoc, parenPrio)
492 recurse(leftSubOperand)
493 recurse(rightSubOperand)
494 return true
495 }
496 return false
497 }
498 formatOperand := func(e Expr) pretty.Doc {
499 return p.Doc(e)
500 }
501 operands := p.flattenOp(leftOperand, pred, formatOperand, nil)
502 operands = p.flattenOp(rightOperand, pred, formatOperand, operands)
503 res = pretty.JoinNestedRight(
504 opDoc, operands...)
505 }
506 return pretty.Group(res)
507}
508
509func (node *ParenExpr) doc(p *PrettyCfg) pretty.Doc {
510 return p.bracket("(", p.Doc(node.Expr), ")")

Callers

nothing calls this directly

Calls 9

TextFunction · 0.92
JoinDocFunction · 0.92
JoinNestedRightFunction · 0.92
GroupFunction · 0.92
peelBinaryOperandMethod · 0.80
IsPaddedMethod · 0.80
DocMethod · 0.80
flattenOpMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected