- All Superinterfaces:
Docile
- All Known Implementing Classes:
Doc.Cat,Doc.Column,Doc.Empty,Doc.FlatAlt,Doc.HyperLinked,Doc.Line,Doc.Nest,Doc.Nesting,Doc.PageWidth,Doc.PlainText,Doc.SpecialSymbol,Doc.Styled,Doc.Union
public sealed interface Doc
extends Docile
permits Doc.HyperLinked, Doc.Nest, Doc.Union, Doc.FlatAlt, Doc.Styled, Doc.Empty, Doc.PlainText, Doc.SpecialSymbol, Doc.Line, Doc.Cat, Doc.Column, Doc.Nesting, Doc.PageWidth
This class reimplemented Haskell
PrettyPrint library's Doc module.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordConcatenation of two documentsstatic final recordA document that will react on the current cursor position.static final recordThe empty document; conceptually the unit of 'Cat'static final recordLay out the defaultDoc 'Doc', but when flattened (via 'group'), prefer the preferWhenFlatten.static final recordA clickable text line without '\n'.static final recordHard line breakstatic final recordDocument indented by a number of columnsstatic final recordA document that will react on the current nest level.static final recordA document that will react on the page width.static final recordA plain text line without '\n'.static final recordA special symbol that may get rendered in a special waystatic final recordStyled documentstatic final recordThe first lines of first document should be shorter than the first lines of the second one, so the layout algorithm can pick the one that fits best. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull Docalign lays out the document with the nesting level set to the current column.static @NotNull Docdefault @NotNull kala.collection.SeqLike<Doc>asSeq()static @NotNull Docstatic @NotNull DocbracedUnless(Doc doc, boolean falsification) static @NotNull Doccat tries laying out the documents separated with nothing, and if this does not fit the page, separates them with newlines.static @NotNull Docstatic @NotNull DocCreates a C-style indented block of statements.static @NotNull Doccolumn(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on which column it starts at.static @NotNull Docdefault @NotNull StringProduce unicode and 80-width outputdefault @NotNull StringProduce ASCII and infinite-width outputstatic @NotNull Docempty()The empty document; conceptually the unit of 'Cat'static @NotNull DocReturn conditionalempty()static @NotNull Docstatic @NotNull DocBy default, flatAlt renders as .static @NotNull DocflatAltBracedBlock(Doc defaultDoc, Doc flatDoc) Either `{ defaultDoc }` or `{\nflatDoc\n}`static @NotNull Dochang lays out the document with a nesting level set to the /current column/ plus .static @NotNull Docstatic @NotNull Docdefault booleanisEmpty()default booleanstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docline()Unconditionally line breakstatic @NotNull Docstatic @NotNull Docstatic @NotNull Doclays out the document with the current nesting level (indentation of the following lines) increased by .static @NotNull Docnesting(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on the current 'nest'-ing level.static @NotNull Docordinal(int n) static @NotNull DocpageWidth(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on the page width, if one has been specified.static @NotNull DocIndents by columns, and then indent the first line again by columns.static @NotNull Docstatic @NotNull DocPlain text documentdefault <Out,Config extends PrinterConfig>
Outdefault @NotNull Stringdefault @NotNull StringrenderToHtml(boolean withHeader) default @NotNull StringrenderToString(@NotNull StringPrinterConfig config) default @NotNull Stringdefault @NotNull StringrenderWithPageWidth(int pageWidth, boolean unicode) static @NotNull Docstatic @NotNull DocfillSep concatenates the documents horizontally with a space as long as it fits the page, then inserts a 'line' and continues doing that for all documents in .static @NotNull DocsepNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull DocsepNonEmpty(Doc @NotNull ... docs) static @NotNull Docstatic @NotNull DocstickySep concatenates all documents horizontally with a space, i.e.static @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docdefault @NotNull DoctoDoc()static @NotNull Docstatic @NotNull Docstatic @NotNull DocvcatNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull DocvcatNonEmpty(Doc @NotNull ... docs) static @NotNull DocvcommaList(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull Doc
-
Field Details
-
ONE_WS
-
ALT_WS
-
COMMA
-
-
Method Details
-
isNotEmpty
default boolean isNotEmpty() -
isEmpty
default boolean isEmpty() -
toDoc
-
asSeq
-
renderToString
-
renderToHtml
-
renderToHtml
-
renderToTeX
-
render
@NotNull default <Out,Config extends PrinterConfig> Out render(@NotNull @NotNull Printer<Out, Config> printer, @NotNull Config config) -
renderWithPageWidth
-
debugRender
Produce ASCII and infinite-width output -
commonRender
Produce unicode and 80-width output -
linkDef
-
linkRef
-
hyperLink
-
hyperLink
-
styled
-
styled
-
styled
-
styled
-
licit
-
spaced
-
wrap
-
bracedUnless
- Parameters:
falsification- when false, add braces
-
braced
-
flatAltBracedBlock
Either `{ defaultDoc }` or `{\nflatDoc\n}` -
angled
-
parened
-
emptyIf
Return conditionalempty()- Parameters:
cond- conditionotherwise- otherwise- Returns:
Doc.Emptywhencondis true, otherwiseotherwise
-
empty
The empty document; conceptually the unit of 'Cat'- Returns:
- empty document
-
flatAlt
@Contract("_, _ -> new") @NotNull static @NotNull Doc flatAlt(@NotNull @NotNull Doc defaultDoc, @NotNull @NotNull Doc preferWhenFlattened) By default, flatAlt renders as . However, when 'group'-ed, will be preferred, with as the fallback for the case when doesn't fit.- Parameters:
defaultDoc- default documentpreferWhenFlattened- document selected when flattened- Returns:
- alternative document
-
column
@Contract("_ -> new") @NotNull static @NotNull Doc column(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on which column it starts at.align(Doc)is implemented in terms ofcolumn.- Parameters:
docBuilder- document generator when current position provided- Returns:
- column action document
-
nesting
@Contract("_ -> new") @NotNull static @NotNull Doc nesting(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on the current 'nest'-ing level.align(Doc)is implemented in terms ofnesting.- Parameters:
docBuilder- document generator when current nest level provided- Returns:
- nest level action document
-
pageWidth
@Contract("_ -> new") @NotNull static @NotNull Doc pageWidth(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on the page width, if one has been specified.- Parameters:
docBuilder- document generator when page width provided- Returns:
- page width action document
-
nest
lays out the document with the current nesting level (indentation of the following lines) increased by . Negative values are allowed, and decrease the nesting level accordingly.- Parameters:
indent- indentation of the following linesdoc- the document to lay out- Returns:
- indented document
-
align
align lays out the document with the nesting level set to the current column. It is used for example to implementhang(int, Doc).As an example, we will put a document right above another one, regardless of the current nesting level. Without 'align'-ment, the second line is put simply below everything we've had so far,
If we add an 'align' to the mix, the @'vsep'@'s contents all start in the same column,
- Parameters:
doc- document to be aligned- Returns:
- aligned document
-
hang
@Contract("_, _ -> new") @NotNull static @NotNull Doc hang(int deltaNest, @NotNull @NotNull Doc doc) hang lays out the document with a nesting level set to the /current column/ plus . Negative values are allowed, and decrease the nesting level accordingly.This differs from
nest(int, Doc), which is based on the /current nesting level/ plusindent. When you're not sure, try the more efficient 'nest' first. In our example, this would yield- Parameters:
deltaNest- change of nesting level, relative to the start of the first linedoc- document to indent- Returns:
- hang-ed document
-
par
Indents by columns, and then indent the first line again by columns.- Parameters:
indent- the indented nesting leveldoc- document to indent- Returns:
- indented document
-
cblock
@Contract("_, _, _ -> new") @NotNull static @NotNull Doc cblock(@NotNull @NotNull Doc prefix, int indent, @NotNull @NotNull Doc block) Creates a C-style indented block of statements.prefix { [indent]block } -
ordinal
-
plain
Plain text document- Parameters:
text- text that may not contain '\n'- Returns:
- text document of the whole text
-
english
-
symbol
- Parameters:
text- '\n' not allowed!- Returns:
- special symbol
-
cat
@Contract("_ -> new") @NotNull static @NotNull Doc cat(@NotNull @NotNull kala.collection.SeqLike<Doc> docs) cat tries laying out the documents separated with nothing, and if this does not fit the page, separates them with newlines. This is what differentiates it from 'vcat', which always lays out its contents beneath each other.- Parameters:
docs- documents to concat- Returns:
- cat document
-
cat
- See Also:
-
vcat
-
vcat
-
vcatNonEmpty
-
vcatNonEmpty
-
stickySep
@Contract("_ -> new") @NotNull static @NotNull Doc stickySep(@NotNull @NotNull kala.collection.SeqLike<@NotNull Doc> docs) stickySep concatenates all documents horizontally with a space, i.e. it puts a space between all entries.stickySep does not introduce line breaks on its own, even when the page is too narrow:
- Parameters:
docs- documents to separate- Returns:
- separated documents
-
stickySep
-
sep
fillSep concatenates the documents horizontally with a space as long as it fits the page, then inserts a 'line' and continues doing that for all documents in . 'line' means that if 'group'-ed, the documents are separated with a 'space' instead of newlines. Usecat(kala.collection.SeqLike<org.aya.pretty.doc.Doc>)if you do not want a 'space'.Let's print some words to fill the line:
- Parameters:
docs- documents to separate- Returns:
- separated documents
-
sep
-
sepNonEmpty
-
sepNonEmpty
-
commaList
-
vcommaList
-
join
-
join
-
line
Unconditionally line break- Returns:
- hard line document
-