接口 Doc

所有超级接口:
Docile
所有已知实现类:
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

This class reimplemented Haskell PrettyPrint library's Doc module.
  • 嵌套类概要

    嵌套类
    修饰符和类型
    接口
    说明
    static final record 
    Concatenation of two documents
    static final record 
    A document that will react on the current cursor position.
    static final record 
    The empty document; conceptually the unit of 'Cat'
    static final record 
    Lay out the defaultDoc 'Doc', but when flattened (via 'group'), prefer the preferWhenFlatten.
    static final record 
    A clickable text line without '\n'.
    static final record 
    Hard line break
    static final record 
    Document indented by a number of columns
    static final record 
    A document that will react on the current nest level.
    static final record 
    A document that will react on the page width.
    static final record 
    A plain text line without '\n'.
    static final record 
    A special symbol that may get rendered in a special way
    static final record 
    Styled document
    static final record 
    The 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.
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final @NotNull Doc
     
    static final @NotNull Doc
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static @NotNull Doc
    align(@NotNull Doc doc)
    align lays out the document with the nesting level set to the current column.
    static @NotNull Doc
    angled(Doc doc)
     
    default @NotNull kala.collection.SeqLike<Doc>
     
    static @NotNull Doc
    braced(Doc doc)
     
    static @NotNull Doc
    cat(@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.
    static @NotNull Doc
    cat(Doc @NotNull ... docs)
     
    static @NotNull Doc
    column(@NotNull IntFunction<Doc> docBuilder)
    Layout a document depending on which column it starts at.
    static @NotNull Doc
    commaList(@NotNull kala.collection.SeqLike<Doc> docs)
     
    default @NotNull String
    Produce unicode and 80-width output
    default @NotNull String
    Produce ASCII and infinite-width output
    static @NotNull Doc
    The empty document; conceptually the unit of 'Cat'
    static @NotNull Doc
    emptyIf(boolean cond, Supplier<@NotNull Doc> otherwise)
    Return conditional empty()
    static @NotNull Doc
     
    static @NotNull Doc
    flatAlt(@NotNull Doc defaultDoc, @NotNull Doc preferWhenFlattened)
    By default, flatAlt renders as .
    static @NotNull Doc
    hang(int deltaNest, @NotNull Doc doc)
    hang lays out the document with a nesting level set to the /current column/ plus .
    static @NotNull Doc
    hyperLink(@NotNull String plain, @NotNull LinkId link)
     
    static @NotNull Doc
    hyperLink(@NotNull Doc doc, @NotNull LinkId link)
     
    static @NotNull Doc
    join(@NotNull Doc delim, @NotNull kala.collection.SeqLike<@NotNull Doc> docs)
     
    static @NotNull Doc
    join(@NotNull Doc delim, Doc @NotNull ... docs)
     
    static @NotNull Doc
    licit(boolean explicit, Doc doc)
     
    static @NotNull Doc
    Unconditionally line break
    static @NotNull Doc
    linkDef(@NotNull Doc doc, int hashCode)
     
    static @NotNull Doc
    linkRef(@NotNull Doc doc, int hashCode)
     
    static @NotNull Doc
    nest(int indent, @NotNull Doc doc)
    lays out the document with the current nesting level (indentation of the following lines) increased by .
    static @NotNull Doc
    nesting(@NotNull IntFunction<Doc> docBuilder)
    Layout a document depending on the current 'nest'-ing level.
    static @NotNull Doc
    ordinal(int n)
     
    static @NotNull Doc
    pageWidth(@NotNull IntFunction<Doc> docBuilder)
    Layout a document depending on the page width, if one has been specified.
    static @NotNull Doc
    par(int indent, @NotNull Doc doc)
    Indents by columns, and then indent the first line again by columns.
    static @NotNull Doc
    parened(Doc doc)
     
    static @NotNull Doc
    plain(String text)
    Plain text document
    default <Out, Config extends PrinterConfig>
    Out
    render(@NotNull Printer<Out,Config> printer, Config config)
     
    default @NotNull String
     
    default @NotNull String
    renderToHtml(boolean withHeader)
     
    default @NotNull String
     
    default @NotNull String
     
    default @NotNull String
    renderWithPageWidth(int pageWidth, boolean unicode)
     
    static @NotNull Doc
    sep(@NotNull kala.collection.SeqLike<Doc> docs)
     
    static @NotNull Doc
    sep(Doc @NotNull ... docs)
    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 .
    static @NotNull Doc
    sepNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs)
     
    static @NotNull Doc
    sepNonEmpty(Doc @NotNull ... docs)
     
    static @NotNull Doc
    stickySep(@NotNull kala.collection.SeqLike<@NotNull Doc> docs)
    stickySep concatenates all documents horizontally with a space, i.e. it puts a space between all entries.
    static @NotNull Doc
    stickySep(Doc @NotNull ... docs)
     
    static @NotNull Doc
    styled(@NotNull Style style, @NotNull String plain)
     
    static @NotNull Doc
    styled(@NotNull Style style, @NotNull Doc doc)
     
    static @NotNull Doc
    styled(@NotNull Styles builder, @NotNull String plain)
     
    static @NotNull Doc
    styled(@NotNull Styles builder, @NotNull Doc doc)
     
    static @NotNull Doc
    symbol(String text)
     
    default @NotNull Doc
     
    static @NotNull Doc
    vcat(@NotNull kala.collection.SeqLike<@NotNull Doc> docs)
     
    static @NotNull Doc
    vcat(Doc @NotNull ... docs)
     
    static @NotNull Doc
    vcatNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs)
     
    static @NotNull Doc
    vcatNonEmpty(Doc @NotNull ... docs)
     
    static @NotNull Doc
    wrap(String leftSymbol, String rightSymbol, Doc doc)
     
  • 字段详细资料

    • ONE_WS

      @NotNull static final @NotNull Doc ONE_WS
    • ALT_WS

      @NotNull static final @NotNull Doc ALT_WS
  • 方法详细资料

    • toDoc

      @NotNull default @NotNull Doc toDoc()
      指定者:
      toDoc 在接口中 Docile
    • asSeq

      @NotNull default @NotNull kala.collection.SeqLike<Doc> asSeq()
    • renderToString

      @NotNull default @NotNull String renderToString(@NotNull @NotNull StringPrinterConfig config)
    • renderToHtml

      @NotNull default @NotNull String renderToHtml()
    • renderToHtml

      @NotNull default @NotNull String renderToHtml(boolean withHeader)
    • renderToTeX

      @NotNull default @NotNull String renderToTeX()
    • render

      @NotNull default <Out, Config extends PrinterConfig> Out render(@NotNull @NotNull Printer<Out,Config> printer, @NotNull Config config)
    • renderWithPageWidth

      @NotNull default @NotNull String renderWithPageWidth(int pageWidth, boolean unicode)
    • debugRender

      @NotNull default @NotNull String debugRender()
      Produce ASCII and infinite-width output
    • commonRender

      @NotNull default @NotNull String commonRender()
      Produce unicode and 80-width output
    • linkDef

      @NotNull static @NotNull Doc linkDef(@NotNull @NotNull Doc doc, int hashCode)
    • linkRef

      @NotNull static @NotNull Doc linkRef(@NotNull @NotNull Doc doc, int hashCode)
    • hyperLink

      @NotNull static @NotNull Doc hyperLink(@NotNull @NotNull Doc doc, @NotNull @NotNull LinkId link)
    • hyperLink

      @NotNull static @NotNull Doc hyperLink(@NotNull @NotNull String plain, @NotNull @NotNull LinkId link)
    • styled

      @NotNull static @NotNull Doc styled(@NotNull @NotNull Style style, @NotNull @NotNull Doc doc)
    • styled

      @NotNull static @NotNull Doc styled(@NotNull @NotNull Style style, @NotNull @NotNull String plain)
    • styled

      @NotNull static @NotNull Doc styled(@NotNull @NotNull Styles builder, @NotNull @NotNull Doc doc)
    • styled

      @NotNull static @NotNull Doc styled(@NotNull @NotNull Styles builder, @NotNull @NotNull String plain)
    • licit

      @NotNull static @NotNull Doc licit(boolean explicit, Doc doc)
    • wrap

      @NotNull static @NotNull Doc wrap(String leftSymbol, String rightSymbol, Doc doc)
    • braced

      @NotNull static @NotNull Doc braced(Doc doc)
    • angled

      @NotNull static @NotNull Doc angled(Doc doc)
    • parened

      @NotNull static @NotNull Doc parened(Doc doc)
    • emptyIf

      @NotNull static @NotNull Doc emptyIf(boolean cond, Supplier<@NotNull Doc> otherwise)
      Return conditional empty()
      参数:
      cond - condition
      otherwise - otherwise
      返回:
      Doc.Empty when cond is true, otherwise otherwise
    • empty

      @NotNull static @NotNull Doc empty()
      The empty document; conceptually the unit of 'Cat'
      返回:
      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.
      参数:
      defaultDoc - default document
      preferWhenFlattened - document selected when flattened
      返回:
      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 of column.
      参数:
      docBuilder - document generator when current position provided
      返回:
      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 of nesting.
      参数:
      docBuilder - document generator when current nest level provided
      返回:
      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.
      参数:
      docBuilder - document generator when page width provided
      返回:
      page width action document
    • nest

      @Contract("_, _ -> new") @NotNull static @NotNull Doc nest(int indent, @NotNull @NotNull Doc doc)
      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.
      参数:
      indent - indentation of the following lines
      doc - the document to lay out
      返回:
      indented document
    • align

      @Contract("_ -> new") @NotNull static @NotNull Doc align(@NotNull @NotNull Doc doc)
      align lays out the document with the nesting level set to the current column. It is used for example to implement hang(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,

      参数:
      doc - document to be aligned
      返回:
      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/ plus indent. When you're not sure, try the more efficient 'nest' first. In our example, this would yield

      参数:
      deltaNest - change of nesting level, relative to the start of the first line
      doc - document to indent
      返回:
      hang-ed document
    • par

      @Contract("_, _ -> new") @NotNull static @NotNull Doc par(int indent, @NotNull @NotNull Doc doc)
      Indents by columns, and then indent the first line again by columns.
      参数:
      indent - the indented nesting level
      doc - document to indent
      返回:
      indented document
    • ordinal

      @Contract("_ -> new") @NotNull static @NotNull Doc ordinal(int n)
    • plain

      @Contract("_ -> new") @NotNull static @NotNull Doc plain(String text)
      Plain text document
      参数:
      text - text that may not contain '\n'
      返回:
      text document of the whole text
    • english

      @Contract("_ -> new") @NotNull static @NotNull Doc english(String text)
    • symbol

      @Contract("_ -> new") @NotNull static @NotNull Doc symbol(String text)
      参数:
      text - '\n' not allowed!
      返回:
      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.
      参数:
      docs - documents to concat
      返回:
      cat document
    • cat

      @Contract("_ -> new") @NotNull static @NotNull Doc cat(Doc @NotNull ... docs)
      另请参阅:
    • vcat

      @Contract("_ -> new") @NotNull static @NotNull Doc vcat(Doc @NotNull ... docs)
    • vcat

      @Contract("_ -> new") @NotNull static @NotNull Doc vcat(@NotNull @NotNull kala.collection.SeqLike<@NotNull Doc> docs)
    • vcatNonEmpty

      @Contract("_ -> new") @NotNull static @NotNull Doc vcatNonEmpty(Doc @NotNull ... docs)
    • vcatNonEmpty

      @Contract("_ -> new") @NotNull static @NotNull Doc vcatNonEmpty(@NotNull @NotNull kala.collection.SeqLike<Doc> docs)
    • 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:

      参数:
      docs - documents to separate
      返回:
      separated documents
    • stickySep

      @Contract("_ -> new") @NotNull static @NotNull Doc stickySep(Doc @NotNull ... docs)
    • sep

      @Contract("_ -> new") @NotNull static @NotNull Doc sep(Doc @NotNull ... docs)
      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. Use cat(kala.collection.SeqLike<org.aya.pretty.doc.Doc>) if you do not want a 'space'.

      Let's print some words to fill the line:

      参数:
      docs - documents to separate
      返回:
      separated documents
    • sep

      @Contract("_ -> new") @NotNull static @NotNull Doc sep(@NotNull @NotNull kala.collection.SeqLike<Doc> docs)
    • sepNonEmpty

      @Contract("_ -> new") @NotNull static @NotNull Doc sepNonEmpty(Doc @NotNull ... docs)
    • sepNonEmpty

      @Contract("_ -> new") @NotNull static @NotNull Doc sepNonEmpty(@NotNull @NotNull kala.collection.SeqLike<Doc> docs)
    • commaList

      @Contract("_ -> new") @NotNull static @NotNull Doc commaList(@NotNull @NotNull kala.collection.SeqLike<Doc> docs)
    • join

      @Contract("_, _ -> new") @NotNull static @NotNull Doc join(@NotNull @NotNull Doc delim, Doc @NotNull ... docs)
    • join

      @Contract("_, _ -> new") @NotNull static @NotNull Doc join(@NotNull @NotNull Doc delim, @NotNull @NotNull kala.collection.SeqLike<@NotNull Doc> docs)
    • line

      @Contract("-> new") @NotNull static @NotNull Doc line()
      Unconditionally line break
      返回:
      hard line document