marianoguerra/shrubbery/doc does not have a README file

    Doc

    pub(all) enum Doc {
    Str(String)
    Nl
    Seq(Array[Doc])
    Nest(Int, Doc)
    Align(Doc)
    Or(Doc, Doc)
    }

    A description of ALL the ways a piece of output may be laid out.

    Deliberately small: five constructors, and Or is ordered — the single-line reading first, the multi-line one second. That ordering is what the renderer relies on, and it is why this is not a general pretty-printing document type.

    The value is a DAG rather than a tree: the two branches of an Or share their sub-documents, and a tree view of a nested document can be exponentially larger than the graph. Nothing here copies, so building one costs what it looks like it costs.

    Doc::to_sexpr

    fn Doc::to_sexpr(self : Doc) -> String

    The document as an S-expression, in the shape the reference prints.

    For comparing a document against the reference's own, which is the only way to tell a layout disagreement (the renderer chose differently) from a construction disagreement (the documents were never the same).

    Doc::write_sexpr

    fn Doc::write_sexpr(self : Doc, buf : StringBuilder) -> Unit

    empty

    let empty : Doc

    join

    fn join(docs : Array[Doc], sep : Doc) -> Doc

    docs, with sep between each pair.

    render

    fn render(doc : Doc, buf : StringBuilder, width? : Int?, column? : Int, indent? : Int) -> Int

    Lay a document out at width and write it.

    Greedy, and a single left-to-right pass. At each Or it measures the single-line branch — and keeps measuring past it, until either a line break arrives (it fits) or the width is exceeded (it does not) — and takes that branch if it fits. Measuring past the branch is what stops a form from being printed on one line only to push what follows it over the edge.

    width of None means "never measure": always take the first branch, which produces the single-line reading of the whole document. Answers with the column the output ends at, which is what a caller embedding this in something larger needs in order to keep laying out.

    render_string

    fn render_string(doc : Doc, width? : Int?, column? : Int, indent? : Int) -> String

    seq

    fn seq(docs : Array[Doc]) -> Doc

    Everything in order.

    Source Files