sealed abstract class Doc extends Product with Serializable
implementation of Wadler's classic "A Prettier Printer"
http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
- Alphabetic
- By Inheritance
- Doc
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
&(that: Doc): Doc
Append the given Doc to this one, separated by a space.
-
def
&:(that: String): Doc
Append the given String to this Doc, separated by a space.
Append the given String to this Doc, separated by a space.
The expression
str &: dis equivalent toDoc.text(str) & d. -
def
*(n: Int): Doc
Synonym for .repeat.
Synonym for .repeat. If n > 0 repeat the doc n times, else return empty
-
def
+(that: Doc): Doc
Append the given Doc to this one.
-
def
+:(str: String): Doc
Prepend the given String to this Doc.
Prepend the given String to this Doc.
The expression
str +: dis equivalent toDoc.text(str) + d. -
def
/(that: Doc): Doc
Append the given Doc to this one, separated by a newline.
-
def
/:(str: String): Doc
Prepend the given String to this Doc, separated by a newline.
Prepend the given String to this Doc, separated by a newline.
The expression
str /: dis equivalent toDoc.text(str) / d. -
def
:&(that: String): Doc
Append the given String to this Doc, separated by a space.
Append the given String to this Doc, separated by a space.
The expression
d :& stris equivalent tod & Doc.text(str). -
def
:+(str: String): Doc
Append the given String to this Doc.
Append the given String to this Doc.
The expression
d :+ stris equivalent tod + Doc.text(str). -
def
:/(str: String): Doc
Append the given String to this Doc, separated by a newline.
Append the given String to this Doc, separated by a newline.
The expression
d :/ stris equivalent tod / Doc.text(str). -
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
aligned: Doc
aligned sets the nesting to the column position before we render the current doc.
aligned sets the nesting to the column position before we render the current doc. This is useful if you have:
Doc.text("foo") + (Doc.text("bar").line(Doc.text("baz"))).align
which will render as:
foobar baz
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
bracketBy(left: Doc, right: Doc, indent: Int = 2): Doc
Bookend this Doc between the given Docs.
Bookend this Doc between the given Docs.
If the documents (when flattened) all fit on one line, then newlines will be collapsed, spaces will be added, and the document will render on one line. If you do not want a space, see tightBracketBy
Otherwise, newlines will be used on either side of this document, and the requested level of indentation will be added as well.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatten: Option[Doc]
Convert this Doc to a single-line representation.
Convert this Doc to a single-line representation.
All newlines are replaced with spaces (and optional indentation is ignored). The resulting Doc will never render any newlines, no matter what width is used.
-
def
flattenOption: Option[Doc]
This method is similar to flatten, but returns None if no flattening was needed (i.e.
This method is similar to flatten, but returns None if no flattening was needed (i.e. if no newlines or unions were present).
As with flatten, the resulting Doc (if any) will never render any newlines, no matter what width is used.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
grouped: Doc
Treat this Doc as a group that can be compressed.
Treat this Doc as a group that can be compressed.
The effect of this is to replace newlines with spaces, if there is enough room. Otherwise, the Doc will be rendered as-is.
-
lazy val
hashCode: Int
Compute a hash code for this Doc.
Compute a hash code for this Doc.
- Definition Classes
- Doc → AnyRef → Any
-
def
isEmpty: Boolean
Returns true if all renders return the empty string
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
line(str: String): Doc
Append the given String to this one, separated by a newline.
-
def
line(that: Doc): Doc
Append the given Doc to this one, separated by a newline.
-
def
lineOrSpace(that: String): Doc
Append the given String to this Doc, using a space (if there is enough room), or a newline otherwise.
-
def
lineOrSpace(that: Doc): Doc
Append the given Doc to this one, using a space (if there is enough room), or a newline otherwise.
-
def
maxWidth: Int
Returns the largest width which may affect how this Doc renders.
Returns the largest width which may affect how this Doc renders. All widths larger than this amount are guaranteed to render the same.
Note that this does not guarantee that all widths below this value are distinct, just that they may be distinct. This value is an upper-bound on widths that produce distinct renderings, but not a least upper-bound.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nested(amount: Int): Doc
Nest appends spaces to any newlines occurring within this Doc.
Nest appends spaces to any newlines occurring within this Doc.
The effect of this is cumulative. For example, the expression
x.nested(1).nested(2)is equivalent tox.nested(3). -
def
nonEmpty: Boolean
d.nonEmpty == !d.isEmpty
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
productIterator: Iterator[Any]
- Definition Classes
- Product
-
def
productPrefix: String
- Definition Classes
- Product
-
def
render(width: Int): String
Render this Doc as a String, limiting line lengths to
widthor shorter when possible.Render this Doc as a String, limiting line lengths to
widthor shorter when possible.Note that this method does not guarantee there are no lines longer than
width-- it just attempts to keep lines within this length when possible. -
def
renderStream(width: Int): Stream[String]
Render this Doc as a stream of strings, treating
widthin the same way asrenderdoes.Render this Doc as a stream of strings, treating
widthin the same way asrenderdoes.The expression
d.renderStream(w).mkStringis equivalent tod.render(w). -
def
renderStreamTrim(width: Int): Stream[String]
Render this Doc as a stream of strings, treating
widthin the same way asrenderdoes.Render this Doc as a stream of strings, treating
widthin the same way asrenderdoes.The expression
d.renderStream(w).mkStringis equivalent tod.render(w).Lines consisting of only indentation are represented by the empty string.
-
def
renderTrim(width: Int): String
Render this Doc as a String, limiting line lengths to
widthor shorter when possible.Render this Doc as a String, limiting line lengths to
widthor shorter when possible.Note that this method does not guarantee there are no lines longer than
width-- it just attempts to keep lines within this length when possible.Lines consisting of only indentation are represented by the empty string.
-
def
renderWideStream: Stream[String]
Render this Doc as a stream of strings, using the widest possible variant.
Render this Doc as a stream of strings, using the widest possible variant. This is the same as render(Int.MaxValue) except it is more efficient.
-
def
repeat(count: Int): Doc
If n > 0, repeat the Doc that many times, else return empty
-
def
representation(forceUnions: Boolean = false): Doc
Produce a verbose string representation of this Doc.
Produce a verbose string representation of this Doc.
Unlike
render, this method will reveal the internal tree structure of the Doc (i.e. how concatenation and union nodes are constructed), as well as the contents of every text node.By default, only the left side of union nodes is displayed. If
forceUnions = trueis passed, then both sides of the union are rendered (making this potentially-expensive method even more expensive). -
def
space(that: String): Doc
Append the given String to this Doc, separated by a space.
-
def
space(that: Doc): Doc
Append the given Doc to this one, separated by a space.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tightBracketBy(left: Doc, right: Doc, indent: Int = 2): Doc
Bookend this Doc between the given Docs.
Bookend this Doc between the given Docs.
If the documents (when flattened) all fit on one line, then newlines will be collapsed, without a space and the document will render on one line. If you want the newline to collapse to a space, see bracketBy.
Otherwise, newlines will be used on either side of this document, and the requested level of indentation will be added as well.
-
def
toString(): String
Return a very terse string for this Doc.
Return a very terse string for this Doc.
To get a full representation of the document's internal structure, see
verboseString.- Definition Classes
- Doc → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
writeTo(width: Int, pw: PrintWriter): Unit
Render this Doc at the given
width, and write it to the given PrintWriter.Render this Doc at the given
width, and write it to the given PrintWriter.The expression
x.writeTo(w, pw)is equivalent topw.print(x.render(w)), but will usually be much more efficient.This method does not close
pwor have any side-effects other than the actual writing. -
def
writeToTrim(width: Int, pw: PrintWriter): Unit
Render this Doc at the given
width, and write it to the given PrintWriter.Render this Doc at the given
width, and write it to the given PrintWriter.The expression
x.writeTo(w, pw)is equivalent topw.print(x.render(w)), but will usually be much more efficient.This method does not close
pwor have any side-effects other than the actual writing.Lines consisting only of indentation are represented by the empty string.