Documentation
¶
Overview ¶
Package printer implements the document renderer the SQL formatter prints through: a small Wadler-style engine, the model behind Prettier and ruff (via Biome's printer). Callers emit a stream of tokens — literal text, break opportunities, and markers that open and close groups and indented regions — and Print lays each group out on a single line when its flat width fits, breaking it otherwise. The package knows nothing about SQL or the AST; the ast package's TrackedBuffer embeds a Buffer and layers node formatting and comment emission on top.
Index ¶
- type Buffer
- func (t *Buffer) Breaker()
- func (t *Buffer) EndGroup()
- func (t *Buffer) EndIndent()
- func (t *Buffer) Group()
- func (t *Buffer) Hardline()
- func (t *Buffer) Indent()
- func (t *Buffer) Line()
- func (t *Buffer) Print(width int) string
- func (t *Buffer) Softline()
- func (t *Buffer) String() string
- func (t *Buffer) Write(p []byte) (int, error)
- func (t *Buffer) WriteRune(r rune) (int, error)
- func (t *Buffer) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer accumulates the document token stream.
func (*Buffer) Breaker ¶
func (t *Buffer) Breaker()
Breaker renders nothing but forces every enclosing group to break, so the next break opportunity becomes a real line break.
func (*Buffer) Group ¶
func (t *Buffer) Group()
Group opens a region the renderer tries to lay out on a single line, breaking it only when its flat form does not fit. Must be paired with EndGroup.
func (*Buffer) Hardline ¶
func (t *Buffer) Hardline()
Hardline always renders a line break and forces every enclosing group to break.
func (*Buffer) Indent ¶
func (t *Buffer) Indent()
Indent opens a region printed one indentation level deeper when line breaks occur inside it. Must be paired with EndIndent.
func (*Buffer) Line ¶
func (t *Buffer) Line()
Line marks a break opportunity between two tokens: a space when the surrounding group fits on one line, a line break when it does not.
func (*Buffer) Print ¶
Print renders the token stream. A negative width renders everything on one line; otherwise each group is rendered flat only when it fits in the space remaining on its line — and a group holding a hardline or breaker never fits, whatever the width, so forced breaks survive even an unlimited line length.
func (*Buffer) Softline ¶
func (t *Buffer) Softline()
Softline marks a break opportunity that disappears entirely when the surrounding group fits on one line.