Doc

org.typelevel.paiges.Doc$
See theDoc companion class
object Doc

Attributes

Companion
class
Source
Doc.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Doc.type

Members list

Type members

Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
Source
Mirror.scala

The name of the type

The name of the type

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def ansiControl(ns: Int*): Doc

Creates a zero-width Doc containing the given ANSI control sequences.

Creates a zero-width Doc containing the given ANSI control sequences.

Attributes

Source
Doc.scala
def cat(ds: Iterable[Doc]): Doc

Concatenate the given documents together.

Concatenate the given documents together.

cat(ds) is equivalent to ds.foldLeft(empty)(_ + _)

Attributes

Source
Doc.scala
def char(c: Char): Doc

Build a document from a single character.

Build a document from a single character.

Attributes

Source
Doc.scala
def defer(d: => Doc): Doc

Defer creation of a Doc until absolutely needed. This is useful in some recursive algorithms

Defer creation of a Doc until absolutely needed. This is useful in some recursive algorithms

Attributes

Source
Doc.scala
def equivAtWidths(widths: List[Int]): Equiv[Doc]

Require documents to be equivalent at all the given widths, as well as at their "wide" renderings.

Require documents to be equivalent at all the given widths, as well as at their "wide" renderings.

Attributes

Source
Doc.scala
def fill(sep: Doc, ds: Iterable[Doc]): Doc

Collapse a collection of documents into one document, delimited by a separator.

Collapse a collection of documents into one document, delimited by a separator.

This is equivalent to the following code, but is much more complex to avoid stack overflows and exponential time complexity


def fill(sep: Doc, ds: List[Doc]): Doc =
  ds match {
    case Nil => empty
    case x :: Nil => x.grouped
    case x :: y :: zs =>
      Union(
        x.flatten + (sep.flatten + fillSpec(sep, y.flatten :: zs)),
        x + (sep + fillSpec(sep, y :: zs)))
  }

For example:

import Doc.{ comma, line, text, fill } val ds = text("1") :: text("2") :: text("3") :: Nil val doc = fill(comma + line, ds)

doc.render(0) // produces "1,\n2,\n3" doc.render(6) // produces "1, 2,\n3" doc.render(10) // produces "1, 2, 3"

Attributes

Source
Doc.scala
def foldDocs(ds: Iterable[Doc])(fn: (Doc, Doc) => Doc): Doc

Combine documents, using the given associative function.

Combine documents, using the given associative function.

The function fn must be associative. That is, the expression fn(x, fn(y, z)) must be equivalent to fn(fn(x, y), z).

In practice this method builds documents from the right, so that the resulting concatenations are all right-associated.

Attributes

Source
Doc.scala
def hardLine: Doc

Puts a hard line that cannot be removed by grouped or flattening. This is useful for source code generation when you absolutely need a new line.

Puts a hard line that cannot be removed by grouped or flattening. This is useful for source code generation when you absolutely need a new line.

Attributes

See also

lineOr which is useful when you have a string that can replace newline, e.g. "; " or similar

Source
Doc.scala
def intercalate(sep: Doc, ds: Iterable[Doc]): Doc

Concatenate the given documents together, delimited by the given separator.

Concatenate the given documents together, delimited by the given separator.

For example, intercalate(comma, List(a, b, c)) is equivalent to a + comma + b + comma + b.

Attributes

Source
Doc.scala
def lineOr(doc: Doc): Doc

lineOr(d) renders as d if we can fit the rest or inserts a newline.

lineOr(d) renders as d if we can fit the rest or inserts a newline.

If it is not already flat, d will be flattened.

and example would be: stmt1 + lineOr(Doc.text("; ")) + stmt2 in a programming language that semicolons to separate statments, but does not require them on the end of a line

Attributes

Source
Doc.scala

Order documents by how they render at the given width.

Order documents by how they render at the given width.

Attributes

Source
Doc.scala
def paragraph(s: String): Doc

Split the given text into words (separated by whitespace), and then join those words with a space or newline.

Split the given text into words (separated by whitespace), and then join those words with a space or newline.

This produces text which will wrap naturally at line boundaries, producing a block of text.

paragraph is an alias for Doc.split(s), which uses its default arguments to split on whitespace and to rejoin the documents with Doc.lineOrSpace.

Attributes

Source
Doc.scala
def spaces(n: Int): Doc

Produce a document of exactly n spaces.

Produce a document of exactly n spaces.

If n < 1, and empty document is returned.

Attributes

Source
Doc.scala
def split(str: String, pat: Regex, sep: Doc): Doc

Convert a string to text, replacing instances of the given pattern with the corresponding separator.

Convert a string to text, replacing instances of the given pattern with the corresponding separator.

Like Doc.text, this method will also lift newlines into the Doc abstraction.

The default pattern to use is """\s+""".r and the default separator to use is Doc.lineOrSpace.

Attributes

Source
Doc.scala
def spread(ds: Iterable[Doc]): Doc

Concatenate the given documents together, delimited by spaces.

Concatenate the given documents together, delimited by spaces.

Attributes

Source
Doc.scala
def stack(ds: Iterable[Doc]): Doc

Concatenate the given documents together, delimited by newlines.

Concatenate the given documents together, delimited by newlines.

Attributes

Source
Doc.scala
def str[T](t: T): Doc

Convert an arbitrary value to a Doc, using toString.

Convert an arbitrary value to a Doc, using toString.

This method is equivalent to Doc.text(t.toString).

Attributes

Source
Doc.scala
def tabulate(kv: List[(String, Doc)]): Doc

A simple table which is the same as: tabulate("", ' ', "", kv)

A simple table which is the same as: tabulate("", ' ', "", kv)

or, no right separator and a space as the fill

Attributes

Source
Doc.scala
def tabulate(fill: Char, rightSep: String, rows: Iterable[(String, Doc)]): Doc

build a table with the strings left aligned and the Docs starting in the column after the longest string. The Docs on the right are rendered aligned after the rightSep

build a table with the strings left aligned and the Docs starting in the column after the longest string. The Docs on the right are rendered aligned after the rightSep

Value parameters

fill

the character used to fill the columns to make the values aligned (i.e. ' ' or '.')

rightSep

a string append left to the left of the value. Intended for use with bullets on values

rows

a List of key, value pairs to put in a table.

Attributes

Source
Doc.scala
def text(str: String): Doc

Convert a string to text.

Convert a string to text.

This method translates newlines into an appropriate document representation. The result may be much more complex than a single Text(_) node.

Attributes

Source
Doc.scala
def zeroWidth(s: String): Doc

Introduce some zero-width text.

Introduce some zero-width text.

WARNING: If this text ends up being seen by the viewer, it will make the formatting appear incorrect. This is an advanced feature -- prefer using styling where possible.

Attributes

Source
Doc.scala

Concrete fields

val comma: Doc

a literal comma, equivalent to char(',')

a literal comma, equivalent to char(',')

Attributes

Source
Doc.scala
val empty: Doc

Attributes

Source
Doc.scala
val line: Doc

when flattened a line becomes a space You might also @see lineBreak if you want a line that is flattened into empty

when flattened a line becomes a space You might also @see lineBreak if you want a line that is flattened into empty

Attributes

Source
Doc.scala
val lineBreak: Doc

A lineBreak is a line that is flattened into an empty Doc. This is generally useful in code following tokens that parse without the need for whitespace termination (consider ";" "," "=>" etc..)

A lineBreak is a line that is flattened into an empty Doc. This is generally useful in code following tokens that parse without the need for whitespace termination (consider ";" "," "=>" etc..)

when we call .grouped on lineBreak we get lineOrEmpty

Attributes

Source
Doc.scala

lineOrEmpty renders as empty if we can fit the rest or inserts a newline. Identical to lineBreak.grouped

lineOrEmpty renders as empty if we can fit the rest or inserts a newline. Identical to lineBreak.grouped

Attributes

Source
Doc.scala

lineOrSpace renders a space if we can fit the rest or inserts a newline. Identical to line.grouped

lineOrSpace renders a space if we can fit the rest or inserts a newline. Identical to line.grouped

Attributes

Source
Doc.scala
val space: Doc

Attributes

Source
Doc.scala