package pp
Pretty-printer library based on the Wadler's paper "A Prettier Printer".
- Alphabetic
- By Inheritance
- pp
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
final
case class
AlignDoc
(inner: Doc) extends Doc with Product with Serializable
Align document: aligns the document on the current column.
-
final
case class
ColumnDoc
(f: (Int) ⇒ Doc) extends Doc with Product with Serializable
Column document: creates a document depending on the current column.
-
final
case class
ConsDoc
(first: Doc, second: Doc) extends Doc with Product with Serializable
Cons document: Concatenation of two documents.
- sealed trait CountUnit extends AnyRef
-
sealed
trait
Doc
extends AnyRef
A document that can then be laid out.
-
final
case class
LineDoc
(repl: Doc) extends Doc with Product with Serializable
Line document: renders as a new line except if discarded by a group.
-
final
case class
NestDoc
(indent: Int, inner: Doc) extends Doc with Product with Serializable
Nest document: new lines are indented by the given indentation.
-
class
PrettyRenderer
extends (Doc) ⇒ SimpleDoc
A pretty printer, that tries to make the document fit in the page width
-
final
case class
SLine
(indent: Int, next: SimpleDoc) extends SimpleDoc with Product with Serializable
A new line document with the indentation level to print right after.
A new line document with the indentation level to print right after. If the next document is empty, the indentation is not printed.
-
final
case class
SText
(text: String, next: SimpleDoc) extends SimpleDoc with Product with Serializable
A text document.
A text document. Should never contain new lines
-
sealed
trait
SimpleDoc
extends AnyRef
A simple document is the normalized form of a document.
A simple document is the normalized form of a document.
This is what is produced by the renderers depending on their rendering algorithm.
-
final
case class
TextDoc
(text: String) extends Doc with Product with Serializable
Text document: shall not contain any new lines.
-
class
TruncateRenderer
extends (Doc) ⇒ SimpleDoc
A renderer that truncates the result (once rendered by the inner renderer) with the given limit.
A renderer that truncates the result (once rendered by the inner renderer) with the given limit. It makes the assumption that the following invariants are respected:
- a gnieh.pp.SText contains either only spaces or only a word
- indentation characters are all modeled with the indentation in gnieh.pp.SLine
-
final
case class
UnionDoc
(long: Doc, short: Doc) extends Doc with Product with Serializable
Union document: two variations of the same document.
Union document: two variations of the same document. Note: The
long-document's first lines must be longer that theshort-document's ones.
Value Members
-
def
align(doc: Doc): Doc
Renders the document with nesting level set to the current column
Renders the document with nesting level set to the current column
- Annotations
- @inline()
-
implicit
def
c2doc(c: Char): Doc
- Annotations
- @inline()
-
def
cat(docs: TraversableLike[Doc, _]): Doc
Renders a document that trie to append the documents in the collection horizontally, otherwise append them vertically
Renders a document that trie to append the documents in the collection horizontally, otherwise append them vertically
- Annotations
- @inline()
-
def
char(c: Char): Doc
Creates a document from the given character
-
implicit
def
d2doc(d: Double): Doc
- Annotations
- @inline()
-
def
double(d: Double): Doc
Creates a document from the given double
Creates a document from the given double
- Annotations
- @inline()
-
val
empty: Doc
Renders as an empty string
-
implicit
def
f2doc(f: Float): Doc
- Annotations
- @inline()
-
def
fill(until: Int)(doc: Doc): Doc
Renders the document as usual, and then fills until
widthwith spaces if necessaryRenders the document as usual, and then fills until
widthwith spaces if necessary- Annotations
- @inline()
-
def
fillCat(docs: TraversableLike[Doc, _]): Doc
Renders a document that appends all document in the collection horizontally, separated by a
softbreakRenders a document that appends all document in the collection horizontally, separated by a
softbreak- Annotations
- @inline()
-
def
fillSep(docs: TraversableLike[Doc, _]): Doc
Renders a document in which all documents in the collection are appended vertically, separated by a
softlineRenders a document in which all documents in the collection are appended vertically, separated by a
softline- Annotations
- @inline()
-
def
float(f: Float): Doc
Creates a document from the given float
Creates a document from the given float
- Annotations
- @inline()
-
def
group(doc: Doc): Doc
Discards all line breaks in the given document if the result fits in the page, otherwise, renders without any changes
Discards all line breaks in the given document if the result fits in the page, otherwise, renders without any changes
- Annotations
- @inline()
-
def
hang(indent: Int)(doc: Doc): Doc
Renders the document with nesting level set to the current column plus
indentRenders the document with nesting level set to the current column plus
indent- Annotations
- @inline()
-
def
hcat(docs: TraversableLike[Doc, _]): Doc
Renders a document that appends the document in the collection horizontally
Renders a document that appends the document in the collection horizontally
- Annotations
- @inline()
-
def
hsep(docs: TraversableLike[Doc, _]): Doc
Renders a document in which all documents in the collection are appended horizontally, separated by a
spaceRenders a document in which all documents in the collection are appended horizontally, separated by a
space- Annotations
- @inline()
-
implicit
def
i2doc(i: Int): Doc
- Annotations
- @inline()
-
def
indent(i: Int)(doc: Doc): Doc
Renders the document with prepending n spaces to the current column
Renders the document with prepending n spaces to the current column
- Annotations
- @inline()
-
def
int(i: Int): Doc
Creates a document from the given integer
Creates a document from the given integer
- Annotations
- @inline()
-
implicit
def
l2doc(l: Long): Doc
- Annotations
- @inline()
-
val
line: Doc
Renders as a new line unless it is discarded by a group, in which case behaves like
space -
def
lineOr(replacement: ⇒ Doc): Doc
Behaves like a new line unless it is discarded by a group, in which case, behaves like the replacement document
Behaves like a new line unless it is discarded by a group, in which case, behaves like the replacement document
- Annotations
- @inline()
-
val
linebreak: Doc
Renders as a new line unless it is discarded by a group, in which case behaves like
empty -
def
long(l: Long): Doc
Creates a document from the given long
Creates a document from the given long
- Annotations
- @inline()
-
def
nest(indent: Int)(inner: Doc): Doc
Indents the document
Indents the document
- Annotations
- @inline()
- implicit def opt2doc[T](o: Option[T])(implicit ev: (T) ⇒ Doc): Doc
-
implicit
def
s2doc(s: String): Doc
- Annotations
- @inline()
-
def
sep(docs: TraversableLike[Doc, _]): Doc
Renders a document that tries to append the documents in the collection horizontally separated by a
spaceif it fits, otherwise append them verticallyRenders a document that tries to append the documents in the collection horizontally separated by a
spaceif it fits, otherwise append them vertically- Annotations
- @inline()
-
val
softbreak: Doc
Behaves like
emptyif the result fits in the page, otherwise behaves likeline -
val
softline: Doc
Behaves like
spaceif the result fits in the page, otherwise behaves likeline -
val
space: Doc
Renders as a space
-
def
string(s: String): Doc
Concatenates all characters, using
linefor new lines andtextfor other blocks -
def
text(s: String): Doc
Renders the text as is.
Renders the text as is. If it contains new lines,
stringshould be used. -
def
unnest(indent: Int)(inner: Doc): Doc
Deindent the document
Deindent the document
- Annotations
- @inline()
-
def
vcat(docs: TraversableLike[Doc, _]): Doc
Renders a document that appends all documents in the collection vertically, separated by a
linebreakRenders a document that appends all documents in the collection vertically, separated by a
linebreak- Annotations
- @inline()
-
def
vsep(docs: TraversableLike[Doc, _]): Doc
Renders a document in which all documents in the collection are appended vertically, separated by a
lineRenders a document in which all documents in the collection are appended vertically, separated by a
line- Annotations
- @inline()
-
def
width(f: (Int) ⇒ Doc)(doc: Doc): Doc
Renders a document followed by some other document computed depending on the current width
Renders a document followed by some other document computed depending on the current width
- Annotations
- @inline()
-
def
words(s: String): List[Doc]
Splits the string into words and create a document for each word
-
object
Characters
extends CountUnit with Product with Serializable
Truncates after the count in non space characters
-
object
CompactRenderer
extends (Doc) ⇒ SimpleDoc
This printer is not really pretty (but should be faster than pretty printers!): it does not insert any indentation and discards all groups, just renders everything as compact as possible
-
object
EmptyDoc
extends Doc with Product with Serializable
Empty document.
-
object
Lines
extends CountUnit with Product with Serializable
Truncates after the count in lines
-
object
SEmpty
extends SimpleDoc with Product with Serializable
An empty document.
-
object
Words
extends CountUnit with Product with Serializable
Truncates after the count in words
Gnieh Tekstlib
Gnieh Tekstlib is a library grouping standard classes and packages allowing people to work with texts and documents.
Package Structure
gnieh.diffdiff manipulation,gnieh.hyphenhyphenation for text in any language,gnieh.stringstrings manipulation for text processing,gnieh.mustachelightweight mustache template engine,gnieh.pppretty printing related classes,gnieh.regexregular expressions manipulation.