prettier

package module
v0.0.0-...-661cc75 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 2 Imported by: 3

README

prettier

A Go implementation of the pretty-printing algorithm described in A prettier printer (Wadler 2003)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Space = Text(" ")

Functions

func Prettier

func Prettier(writer io.StringWriter, doc Doc, maxLineWidth int, indent string)

Prettier writes the given document to the specified string writer, indented using the given indentation, and trying to fit the content so that the maximum line width is not exceeded

Types

type Concat

type Concat []Doc

Concat combines multiple documents

func (Concat) Flatten

func (c Concat) Flatten() Doc

type Dedent

type Dedent struct {
	Doc Doc
}

Dedent decreases the level of indentation for the nested document

func (Dedent) Flatten

func (d Dedent) Flatten() Doc

type Doc

type Doc interface {
	Flatten() Doc
	// contains filtered or unexported methods
}

func Join

func Join(sep Doc, docs ...Doc) Doc

Join returns a document where the given documents are separated with the specified separator document

func Wrap

func Wrap(left, doc, right, line Doc) Doc

func WrapBraces

func WrapBraces(doc, line Doc) Doc

func WrapBrackets

func WrapBrackets(doc, line Doc) Doc

func WrapParentheses

func WrapParentheses(doc, line Doc) Doc

type Group

type Group struct {
	Doc Doc
}

Group marks a document to be flattened if it does not fit on one line

func (Group) Flatten

func (g Group) Flatten() Doc

type HardLine

type HardLine struct{}

HardLine is a line break. When flattened it is not replaced

func (HardLine) Flatten

func (l HardLine) Flatten() Doc

type Indent

type Indent struct {
	Doc Doc
}

Indent increases the level of indentation for the nested document

func (Indent) Flatten

func (i Indent) Flatten() Doc

type Line

type Line struct{}

Line is a line break. When flattened it is replaced with a space

func (Line) Flatten

func (l Line) Flatten() Doc

type SoftLine

type SoftLine struct{}

SoftLine is a line break. When flattened it is replaced with nothing

func (SoftLine) Flatten

func (l SoftLine) Flatten() Doc

type Text

type Text string

Text is text which does not contain newline characters

func (Text) Flatten

func (t Text) Flatten() Doc

Jump to

Keyboard shortcuts

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