MCPcopy Create free account
hub / github.com/dolthub/doltgresql / doc

Method doc

postgres/parser/sem/tree/pretty.go:445–479  ·  view source on GitHub ↗
(p *PrettyCfg)

Source from the content-addressed store, hash-verified

443}
444
445func (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
481func (node *ParenExpr) doc(p *PrettyCfg) pretty.Doc {
482 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