Skip to content

tanishiking/prettier

Repository files navigation

prettier

test

Overview

prettier is an implementation of Wadler's "A Prettier Printer".

Install

$ go get -u github.com/tanishiking/prettier

Usage

import (
    "fmt"

    p "github.com/tanishiking/prettier"
)
j
func main() {
    sep := p.Concat([]p.Doc{p.Text(","), p.LineOrSpace()})
    ds := []p.Doc{
        p.Text("foo"),
        p.Text("bar"),
        p.Text("baz"),
        p.Text("hello"),
        p.Text("world"),
    }
    doc := p.TightBracketBy(
        p.Text("["),
        p.Text("]"),
        p.Intercalate(sep, ds),
        uint(2),
    )

    fmt.Println(p.Pretty(40, doc))
    // [foo, bar, baz, hello, world]

    fmt.Println(p.Pretty(20, doc))
    // [
    //   foo, bar, baz,
    //   hello, world
    // ]

    fmt.Println(p.Pretty(10, doc))
    // [
    //   foo,
    //   bar,
    //   baz,
    //   hello,
    //   world
    // ]
}

License

MIT License