doc

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package doc is a small Wadler/Prettier-style document algebra: you build an immutable layout tree out of Text, Concat, Group, Indent, and the line primitives, then Render it at a target width. A Group lays its contents out on one line when they fit and breaks them across lines when they don't, so callers describe structure and let the renderer own wrapping.

Documents are immutable values: every constructor returns a fresh Doc and none of them retain or mutate their arguments, so a Doc is safe to share and reuse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(d Doc, width Width) string

Render lays d out as text, breaking groups that would otherwise exceed width columns.

Types

type Doc

type Doc struct {
	// contains filtered or unexported fields
}

Doc is an immutable layout document. The zero value renders as empty text. Fields are ordered so the garbage collector's pointer-scan prefix is as short as possible.

func Concat

func Concat(docs ...Doc) Doc

Concat is the documents rendered one after another with nothing between them.

func Group

func Group(d Doc) Doc

Group renders d flat (every Line a space, every Softline empty) when it fits the remaining width, and broken (every line primitive a newline) when it doesn't. A Hardline anywhere inside forces the broken layout.

func Hardline

func Hardline() Doc

Hardline always renders as a newline and forces every enclosing Group to break.

func Indent

func Indent(d Doc) Doc

Indent renders d one indentation step deeper, which only shows up on the lines that follow a break inside d.

func Line

func Line() Doc

Line renders as a single space when its group is flat and as a newline when the group is broken.

func Softline

func Softline() Doc

Softline renders as nothing when its group is flat and as a newline when the group is broken.

func Text

func Text(s Literal) Doc

Text is a document that renders literally as s, on a single line.

type Literal added in v0.1.0

type Literal string

Literal is the verbatim text a Text document renders as.

type Width added in v0.1.0

type Width int

Width is the column budget a rendered line must fit within.

Jump to

Keyboard shortcuts

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