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

Method doc

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

Source from the content-addressed store, hash-verified

430}
431
432func (node *BinaryExpr) doc(p *PrettyCfg) pretty.Doc {
433 // All the binary operators are at least left-associative.
434 // So we can always simplify "(a OP b) OP c" to "a OP b OP c".
435 parenPrio := binaryOpPrio[node.Operator]
436 leftOperand := p.peelBinaryOperand(node.Left, true /*sameLevel*/, parenPrio)
437 // If the binary operator is also fully associative,
438 // we can also simplify "a OP (b OP c)" to "a OP b OP c".
439 opFullyAssoc := binaryOpFullyAssoc[node.Operator]
440 rightOperand := p.peelBinaryOperand(node.Right, opFullyAssoc, parenPrio)
441
442 opDoc := pretty.Text(node.Operator.String())
443 var res pretty.Doc
444 if !node.Operator.isPadded() {
445 res = pretty.JoinDoc(opDoc, p.Doc(leftOperand), p.Doc(rightOperand))
446 } else {
447 pred := func(e Expr, recurse func(e Expr)) bool {
448 if b, ok := e.(*BinaryExpr); ok && b.Operator == node.Operator {
449 leftSubOperand := p.peelBinaryOperand(b.Left, true /*sameLevel*/, parenPrio)
450 rightSubOperand := p.peelBinaryOperand(b.Right, opFullyAssoc, parenPrio)
451 recurse(leftSubOperand)
452 recurse(rightSubOperand)
453 return true
454 }
455 return false
456 }
457 formatOperand := func(e Expr) pretty.Doc {
458 return p.Doc(e)
459 }
460 operands := p.flattenOp(leftOperand, pred, formatOperand, nil)
461 operands = p.flattenOp(rightOperand, pred, formatOperand, operands)
462 res = pretty.JoinNestedRight(
463 opDoc, operands...)
464 }
465 return pretty.Group(res)
466}
467
468func (node *ParenExpr) doc(p *PrettyCfg) pretty.Doc {
469 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