printer

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 2 Imported by: 0

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

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) EndGroup

func (t *Buffer) EndGroup()

func (*Buffer) EndIndent

func (t *Buffer) EndIndent()

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

func (t *Buffer) Print(width int) string

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.

func (*Buffer) String

func (t *Buffer) String() string

String renders the buffer on a single line.

func (*Buffer) Write

func (t *Buffer) Write(p []byte) (int, error)

Write implements io.Writer so callers can use fmt.Fprintf.

func (*Buffer) WriteRune

func (t *Buffer) WriteRune(r rune) (int, error)

func (*Buffer) WriteString

func (t *Buffer) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL