    {-# LANGUAGE FlexibleInstances    #-}
    {-# LANGUAGE LambdaCase           #-}
    {-# LANGUAGE OverloadedStrings    #-}
    {-# LANGUAGE ScopedTypeVariables  #-}
    {-# LANGUAGE TypeApplications     #-}
    {-# OPTIONS_GHC -fno-warn-orphans #-}
    {-|
    Module      : HsLua.Module.DocLayout
    Copyright   : © 2020-2024 Albert Krewinkel
    License     : MIT
    Maintainer  : Albert Krewinkel <albert+hslua@zeitkraut.de>

    Provides a Lua module which wraps @'Text.DocLayout'@. The @'Doc'@
    type is specialized to @'Text'@.

    This module defines orphan instances for @Doc Text@.
    -}
    module HsLua.Module.DocLayout (
      -- * Module
        documentedModule
      , pushModule
      , preloadModule
      , description
      , fields
      , functions

      -- * Doc constructors and combinators
      , after_break
      , before_non_blank
      , blankline
      , blanklines
      , braces
      , brackets
      , cblock
      , chomp
      , concat
      , cr
      , double_quotes
      , empty
      , flush
      , hang
      , inside
      , lblock
      , literal
      , nest
      , nestle
      , nowrap
      , parens
      , prefixed
      , quotes
      , rblock
      , space
      , vfill

      -- * Rendering
      , render

      -- * Document Querying
      , is_empty
      , height
      , min_offset
      , offset
      , real_length
      , update_column

      -- * Styling
      , bold
      , italic
      , underlined
      , strikeout
      , fg
      , bg

      -- * Marshaling
      , peekDoc
      , pushDoc
      )
    where

    import Prelude hiding (concat)
    import Data.List (intersperse)
    import Data.Text (Text)
    import HsLua as Lua hiding (concat)
    import Text.DocLayout (Doc, (<+>), ($$), ($+$))

    import qualified Data.Text as T
    import qualified Data.Text.Lazy as TL
    import qualified Text.DocLayout as Doc

    --
    -- Module
    --

    -- | Textual description of the "doclayout" module.
    description :: Text
    description :: Text
    description = Text
    "Plain-text document layouting."

    -- | Self-documenting module.
    documentedModule :: LuaError e => Module e
    documentedModule :: forall e. LuaError e => Module e
    documentedModule = Module
      { moduleName :: Name
    moduleName = Name
    "doclayout"
      , moduleFields :: [Field e]
    moduleFields = [Field e]
    forall e. LuaError e => [Field e]
    fields
      , moduleDescription :: Text
    moduleDescription = Text
    description
      , moduleFunctions :: [DocumentedFunction e]
    moduleFunctions = [DocumentedFunction e]
    forall e. LuaError e => [DocumentedFunction e]
    functions
      , moduleOperations :: [(Operation, DocumentedFunction e)]
    moduleOperations = []
      , moduleTypeInitializers :: [LuaE e Name]
    moduleTypeInitializers = [DocumentedTypeWithList e (Doc Text) Void -> LuaE e Name
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> LuaE e Name
    initType DocumentedTypeWithList e (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc]
      }

    --
    -- Fields
    --

    -- | Exposed fields.
    fields :: forall e. LuaError e => [Field e]
    fields :: forall e. LuaError e => [Field e]
    fields =
      [ Field e
    forall e. LuaError e => Field e
    blankline
      , Field e
    forall e. LuaError e => Field e
    cr
      , Field e
    forall e. LuaError e => Field e
    empty
      , Field e
    forall e. LuaError e => Field e
    space
      ]

    -- | Wrapped and documented 'Doc.blankline' value.
    blankline :: forall e. LuaError e => Field e
    blankline :: forall e. LuaError e => Field e
    blankline = Field
      { fieldName :: Text
    fieldName = Text
    "blankline"
      , fieldDescription :: Text
    fieldDescription = Text
    "Inserts a blank line unless one exists already."
      , fieldType :: TypeSpec
    fieldType = forall e fn a itemtype. UDTypeWithList e fn a itemtype -> TypeSpec
    udTypeSpec @e UDTypeWithList e (DocumentedFunction e) (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc
      , fieldPushValue :: LuaE e ()
    fieldPushValue = Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc Doc Text
    forall a. Doc a
    Doc.blankline
      }

    -- | Wrapped and documented 'Doc.cr' value.
    cr :: forall e. LuaError e => Field e
    cr :: forall e. LuaError e => Field e
    cr = Field
      { fieldName :: Text
    fieldName = Text
    "cr"
      , fieldDescription :: Text
    fieldDescription = Text
    "A carriage return. Does nothing if we're at " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                           Text
    "the beginning of a line; " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                           Text
    "otherwise inserts a newline."
      , fieldType :: TypeSpec
    fieldType = forall e fn a itemtype. UDTypeWithList e fn a itemtype -> TypeSpec
    udTypeSpec @e UDTypeWithList e (DocumentedFunction e) (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc
      , fieldPushValue :: LuaE e ()
    fieldPushValue = Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc Doc Text
    forall a. Doc a
    Doc.cr
      }

    -- | Wrapped and documented 'Doc.empty' value.
    empty :: forall e. LuaError e => Field e
    empty :: forall e. LuaError e => Field e
    empty = Field
      { fieldName :: Text
    fieldName = Text
    "empty"
      , fieldDescription :: Text
    fieldDescription = Text
    "The empty document."
      , fieldType :: TypeSpec
    fieldType = forall e fn a itemtype. UDTypeWithList e fn a itemtype -> TypeSpec
    udTypeSpec @e UDTypeWithList e (DocumentedFunction e) (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc
      , fieldPushValue :: LuaE e ()
    fieldPushValue = Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc Doc Text
    forall a. Doc a
    Doc.empty
      }

    -- | Wrapped and documented 'Doc.space' value.
    space :: forall e. LuaError e => Field e
    space :: forall e. LuaError e => Field e
    space = Field
      { fieldName :: Text
    fieldName = Text
    "space"
      , fieldDescription :: Text
    fieldDescription = Text
    "A breaking (reflowable) space."
      , fieldType :: TypeSpec
    fieldType = forall e fn a itemtype. UDTypeWithList e fn a itemtype -> TypeSpec
    udTypeSpec @e UDTypeWithList e (DocumentedFunction e) (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc
      , fieldPushValue :: LuaE e ()
    fieldPushValue = Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc Doc Text
    forall a. Doc a
    Doc.space
      }

    --
    -- Functions
    --

    -- | Exposed module functions.
    functions :: LuaError e => [DocumentedFunction e]
    functions :: forall e. LuaError e => [DocumentedFunction e]
    functions =
      [ -- Constructors
        DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    after_break
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    before_non_blank
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    blanklines
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    braces
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    brackets
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    cblock
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    chomp
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    concat
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    double_quotes
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    flush
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    hang
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    inside
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    lblock
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    literal
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nest
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nestle
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nowrap
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    parens
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    prefixed
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    quotes
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    rblock
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    vfill
        -- rendering
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    render
        -- querying
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    is_empty
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    height
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    min_offset
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    offset
      , DocumentedFunction e
    forall e. DocumentedFunction e
    real_length
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    update_column
        -- styling
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    bold
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    italic
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    underlined
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    strikeout
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    fg
      , DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    bg
      ]

    typeDoc :: LuaError e => DocumentedType e (Doc Text)
    typeDoc :: forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc = Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) (Doc Text)]
    -> DocumentedType e (Doc Text)
    forall e a.
    LuaError e =>
    Name
    -> [(Operation, DocumentedFunction e)]
    -> [Member e (DocumentedFunction e) a]
    -> DocumentedType e a
    deftype Name
    "Doc"
          [ Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Add    (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    forall {e}.
    LuaError e =>
    (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    binaryOp Doc Text -> Doc Text -> Doc Text
    forall a. Doc a -> Doc a -> Doc a
    (<+>)
            Text
    "Concatenated docs, with breakable space between them."
          , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Concat (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    forall {e}.
    LuaError e =>
    (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    binaryOp Doc Text -> Doc Text -> Doc Text
    forall a. Semigroup a => a -> a -> a
    (<>) Text
    "Concatenation of the input docs"
          , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Div    (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    forall {e}.
    LuaError e =>
    (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    binaryOp Doc Text -> Doc Text -> Doc Text
    forall a. Doc a -> Doc a -> Doc a
    ($$) Text
    "Puts a above b"
          , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Eq     (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> Doc Text -> LuaE e Bool)
    -> HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e Bool)
    forall a e. a -> HsFnPrecursor e a
    lambda
            ### liftPure2 (==)
            HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e Bool)
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Doc Text -> LuaE e Bool)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "a"
            HsFnPrecursor e (Doc Text -> LuaE e Bool)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Bool)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "b"
            HsFnPrecursor e (LuaE e Bool)
    -> FunctionResults e Bool -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Bool
    forall e. Text -> FunctionResults e Bool
    boolResult Text
    "whether the two Docs are equal"
          , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Idiv   (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    forall {e}.
    LuaError e =>
    (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    binaryOp Doc Text -> Doc Text -> Doc Text
    forall a. Doc a -> Doc a -> Doc a
    ($+$) Text
    "Puts a above b"
          , Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall e.
    Operation
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    operation Operation
    Tostring (DocumentedFunction e -> (Operation, DocumentedFunction e))
    -> DocumentedFunction e -> (Operation, DocumentedFunction e)
    forall a b. (a -> b) -> a -> b
    $ (Doc Text -> LuaE e Text)
    -> HsFnPrecursor e (Doc Text -> LuaE e Text)
    forall a e. a -> HsFnPrecursor e a
    lambda
            ### liftPure (Doc.render Nothing)
            HsFnPrecursor e (Doc Text -> LuaE e Text)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Text)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
            HsFnPrecursor e (LuaE e Text)
    -> FunctionResults e Text -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Text
    forall e. Text -> FunctionResults e Text
    textResult Text
    "Rendered Doc without reflowing."
          ]
          [ DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    before_non_blank
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    braces
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    brackets
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    cblock
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    chomp
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    double_quotes
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    is_empty
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    flush
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    hang
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    height
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    inside
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    lblock
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    min_offset
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nest
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nestle
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    nowrap
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    offset
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    parens
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    prefixed
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    quotes
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    rblock
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    render
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    update_column
          , DocumentedFunction e -> Member e (DocumentedFunction e) (Doc Text)
    forall e a.
    DocumentedFunction e -> Member e (DocumentedFunction e) a
    method DocumentedFunction e
    forall e. LuaError e => DocumentedFunction e
    vfill
          ]
      where
        binaryOp :: (Doc Text -> Doc Text -> Doc Text) -> Text -> DocumentedFunction e
    binaryOp Doc Text -> Doc Text -> Doc Text
    op Text
    descr = (Doc Text -> Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e (Doc Text))
    forall a e. a -> HsFnPrecursor e a
    lambda
          ### liftPure2 op
          HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "a"
          HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "b"
          HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    descr

    -- | Render a @'Doc'@. The text is reflowed on breakable spaces
    -- to match the given line length. Text is not reflowed if the
    -- line length parameter is omitted or nil.
    render :: LuaError e => DocumentedFunction e
    render :: forall e. LuaError e => DocumentedFunction e
    render = Name
    -> (Doc Text -> Maybe Int -> Maybe Bool -> LuaE e Text)
    -> HsFnPrecursor
         e (Doc Text -> Maybe Int -> Maybe Bool -> LuaE e Text)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "render"
      ### (\doc mbcolwidth useAnsi ->
              if useAnsi == Just True
              then pure $ TL.toStrict $ Doc.renderANSI mbcolwidth doc
              else pure $ Doc.renderPlain mbcolwidth doc)
      HsFnPrecursor
      e (Doc Text -> Maybe Int -> Maybe Bool -> LuaE e Text)
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Maybe Int -> Maybe Bool -> LuaE e Text)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Maybe Int -> Maybe Bool -> LuaE e Text)
    -> Parameter e (Maybe Int)
    -> HsFnPrecursor e (Maybe Bool -> LuaE e Text)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e Int -> Parameter e (Maybe Int)
    forall e a. Parameter e a -> Parameter e (Maybe a)
    opt (Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "colwidth" (Text -> Parameter e Int) -> Text -> Parameter e Int
    forall a b. (a -> b) -> a -> b
    $
               Text
    "Maximum number of characters per line.\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
               Text
    "A value of `nil`, the default, means that the text " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
               Text
    "is not reflown.")
      HsFnPrecursor e (Maybe Bool -> LuaE e Text)
    -> Parameter e (Maybe Bool) -> HsFnPrecursor e (LuaE e Text)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e Bool -> Parameter e (Maybe Bool)
    forall e a. Parameter e a -> Parameter e (Maybe a)
    opt (Peeker e Bool -> TypeSpec -> Text -> Text -> Parameter e Bool
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter Peeker e Bool
    forall {e}. StackIndex -> Peek e Bool
    peekRenderStyle TypeSpec
    "string" Text
    "style" (Text -> Parameter e Bool) -> Text -> Parameter e Bool
    forall a b. (a -> b) -> a -> b
    $
               Text
    "Whether to generate plain text or ANSI terminal output.\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
               Text
    "Must be either `'plain'` or `'ansi'`.\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
               Text
    "Defaults to `'plain'`.")
      HsFnPrecursor e (LuaE e Text)
    -> FunctionResults e Text -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Pusher e Text -> TypeSpec -> Text -> FunctionResults e Text
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e Text
    forall e. Pusher e Text
    pushText TypeSpec
    "string" Text
    "rendered doc"
      #? T.unlines
         [ "Render a [[Doc]]. The text is reflowed on breakable spaces to"
         , "match the given line length. Text is not reflowed if the line"
         , "line length parameter is omitted or nil."
         ]
     where
       peekRenderStyle :: StackIndex -> Peek e Bool
    peekRenderStyle StackIndex
    idx = Peeker e ByteString
    forall e. Peeker e ByteString
    peekByteString StackIndex
    idx Peek e ByteString -> (ByteString -> Peek e Bool) -> Peek e Bool
    forall a b. Peek e a -> (a -> Peek e b) -> Peek e b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
         ByteString
    "ansi"  -> Bool -> Peek e Bool
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Bool
    True
         ByteString
    "ANSI"  -> Bool -> Peek e Bool
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Bool
    True
         ByteString
    "plain" -> Bool -> Peek e Bool
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Bool
    False
         ByteString
    style   -> ByteString -> Peek e Bool
    forall a e. ByteString -> Peek e a
    failPeek (ByteString -> Peek e Bool) -> ByteString -> Peek e Bool
    forall a b. (a -> b) -> a -> b
    $ ByteString
    "Unknown rendering style: " ByteString -> ByteString -> ByteString
    forall a. Semigroup a => a -> a -> a
    <> ByteString
    style

    --
    -- Querying
    --

    -- | @True@ iff the document is empty.
    is_empty :: LuaError e => DocumentedFunction e
    is_empty :: forall e. LuaError e => DocumentedFunction e
    is_empty = Name
    -> (Doc Text -> LuaE e Bool)
    -> HsFnPrecursor e (Doc Text -> LuaE e Bool)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "is_empty"
      ### liftPure Doc.isEmpty
      HsFnPrecursor e (Doc Text -> LuaE e Bool)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Bool)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e Bool)
    -> FunctionResults e Bool -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Bool
    forall e. Text -> FunctionResults e Bool
    boolResult Text
    "`true` iff `doc` is the empty document, `false` otherwise."
      #? "Checks whether a doc is empty."

    -- | Returns the width of a @'Doc'@.
    offset :: LuaError e => DocumentedFunction e
    offset :: forall e. LuaError e => DocumentedFunction e
    offset = Name
    -> (Doc Text -> LuaE e Int)
    -> HsFnPrecursor e (Doc Text -> LuaE e Int)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "offset"
      ### liftPure Doc.offset
      HsFnPrecursor e (Doc Text -> LuaE e Int)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e Int)
    -> FunctionResults e Int -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Int
    forall a e. (Integral a, Show a) => Text -> FunctionResults e a
    integralResult Text
    "doc width"
      #? "Returns the width of a [[Doc]] as number of characters."

    -- | Returns the minimal width of a @'Doc'@ when reflowed at
    -- breakable spaces.
    min_offset :: LuaError e => DocumentedFunction e
    min_offset :: forall e. LuaError e => DocumentedFunction e
    min_offset = Name
    -> (Doc Text -> LuaE e Int)
    -> HsFnPrecursor e (Doc Text -> LuaE e Int)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "min_offset"
      ### liftPure Doc.minOffset
      HsFnPrecursor e (Doc Text -> LuaE e Int)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e Int)
    -> FunctionResults e Int -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Int
    forall a e. (Integral a, Show a) => Text -> FunctionResults e a
    integralResult Text
    "minimal possible width"
      #? ("Returns the minimal width of a [[Doc]] when reflowed at " <>
          "breakable spaces.")

    -- | Returns the column that would be occupied by the last laid
    -- out character.
    update_column :: LuaError e => DocumentedFunction e
    update_column :: forall e. LuaError e => DocumentedFunction e
    update_column = Name
    -> (Doc Text -> Int -> LuaE e Int)
    -> HsFnPrecursor e (Doc Text -> Int -> LuaE e Int)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "update_column"
      ### liftPure2 Doc.updateColumn
      HsFnPrecursor e (Doc Text -> Int -> LuaE e Int)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (Int -> LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> LuaE e Int)
    -> Parameter e Int -> HsFnPrecursor e (LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "i" Text
    "start column"
      HsFnPrecursor e (LuaE e Int)
    -> FunctionResults e Int -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Int
    forall a e. (Integral a, Show a) => Text -> FunctionResults e a
    integralResult Text
    "column number"
      #? ("Returns the column that would be occupied by the last " <>
          "laid out character.")

    -- | Returns the height of a block or other Doc.
    height :: LuaError e => DocumentedFunction e
    height :: forall e. LuaError e => DocumentedFunction e
    height = Name
    -> (Doc Text -> LuaE e Int)
    -> HsFnPrecursor e (Doc Text -> LuaE e Int)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "height"
      ### liftPure Doc.height
      HsFnPrecursor e (Doc Text -> LuaE e Int)
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e Int)
    -> FunctionResults e Int -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Int
    forall a e. (Integral a, Show a) => Text -> FunctionResults e a
    integralResult Text
    "doc height"
      #? "Returns the height of a block or other Doc."

    -- | Returns the real length of a string in a monospace font: 0
    -- for a combining character, 1, for a regular character, 2 for
    -- an East Asian wide character.
    real_length :: DocumentedFunction e
    real_length :: forall e. DocumentedFunction e
    real_length = Name
    -> (Text -> LuaE e Int) -> HsFnPrecursor e (Text -> LuaE e Int)
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "real_length"
      ### liftPure Doc.realLength
      HsFnPrecursor e (Text -> LuaE e Int)
    -> Parameter e Text -> HsFnPrecursor e (LuaE e Int)
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Text
    forall e. Text -> Text -> Parameter e Text
    textParam Text
    "str" Text
    "UTF-8 string to measure"
      HsFnPrecursor e (LuaE e Int)
    -> FunctionResults e Int -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e Int
    forall a e. (Integral a, Show a) => Text -> FunctionResults e a
    integralResult Text
    "text length"
      #? ("Returns the real length of a string in a monospace font: " <>
          "0 for a combining character, 1 for a regular character, " <>
          "2 for an East Asian wide character.")

    --
    -- Constructors
    --

    -- | Creates a @'Doc'@ which is conditionally included only if it
    -- comes at the beginning of a line.
    after_break :: LuaError e => DocumentedFunction e
    after_break :: forall e. LuaError e => DocumentedFunction e
    after_break = Name
    -> (Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "after_break"
      ### liftPure Doc.afterBreak
      HsFnPrecursor e (Text -> LuaE e (Doc Text))
    -> Parameter e Text -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Text
    forall e. Text -> Text -> Parameter e Text
    textParam Text
    "text" Text
    "content to include when placed after a break"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "new doc"
      #? ("Creates a [[Doc]] which is conditionally included only if it " <>
          "comes at the beginning of a line.\n\n" <>
          "An example where this is useful is for escaping line-initial " <>
          "`.` in roff man.")

    -- | Conditionally includes the given @'Doc'@ unless it is
    -- followed by a blank space.
    before_non_blank :: LuaError e => DocumentedFunction e
    before_non_blank :: forall e. LuaError e => DocumentedFunction e
    before_non_blank = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "before_non_blank"
      ### liftPure Doc.beforeNonBlank
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "conditional doc"
      #? ("Conditionally includes the given `doc` unless it is " <>
          "followed by a blank space.")

    -- | Insert blank lines unless they exist already.
    blanklines :: LuaError e => DocumentedFunction e
    blanklines :: forall e. LuaError e => DocumentedFunction e
    blanklines = Name
    -> (Int -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Int -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "blanklines"
      ### liftPure Doc.blanklines
      HsFnPrecursor e (Int -> LuaE e (Doc Text))
    -> Parameter e Int -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "n" Text
    "number of blank lines"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "conditional blank lines"
      #? "Inserts blank lines unless they exist already."

    -- | Puts a @'Doc'@ in curly braces.
    braces :: LuaError e => DocumentedFunction e
    braces :: forall e. LuaError e => DocumentedFunction e
    braces = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "braces"
      ### liftPure Doc.braces
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "`doc` enclosed by {}."
      #? "Puts the `doc` in curly braces."

    -- | Puts a @'Doc'@ in square brackets.
    brackets :: LuaError e => DocumentedFunction e
    brackets :: forall e. LuaError e => DocumentedFunction e
    brackets = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "brackets"
      ### liftPure Doc.brackets
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "doc enclosed by []."
      #? "Puts the `doc` in square brackets"

    -- | Like @'lblock'@ but aligned centered.
    cblock :: LuaError e => DocumentedFunction e
    cblock :: forall e. LuaError e => DocumentedFunction e
    cblock = Name
    -> (Doc Text -> Int -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "cblock"
      ### liftPure2 (flip Doc.cblock)
      HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Int -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> LuaE e (Doc Text))
    -> Parameter e Int -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "width" Text
    "block width in chars"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult (Text
    "doc, aligned centered in a block with max " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                     Text
    "`width` chars per line.")
      #? ("Creates a block with the given width and content, " <>
          "aligned centered.")

    -- | Chomps trailing blank space off of a @'Doc'@.
    chomp :: LuaError e => DocumentedFunction e
    chomp :: forall e. LuaError e => DocumentedFunction e
    chomp = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "chomp"
      ### liftPure Doc.chomp
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "`doc` without trailing blanks"
      #? "Chomps trailing blank space off of the `doc`."

    -- | Concatenates a list of @'Doc'@s.
    concat :: LuaError e => DocumentedFunction e
    concat :: forall e. LuaError e => DocumentedFunction e
    concat = Name
    -> ([Doc Text] -> Maybe (Doc Text) -> LuaE e (Doc Text))
    -> HsFnPrecursor
         e ([Doc Text] -> Maybe (Doc Text) -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "concat"
      ### liftPure2 (\docs optSep -> mconcat $
                      maybe docs (`intersperse` docs) optSep)
      HsFnPrecursor
      e ([Doc Text] -> Maybe (Doc Text) -> LuaE e (Doc Text))
    -> Parameter e [Doc Text]
    -> HsFnPrecursor e (Maybe (Doc Text) -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Peeker e [Doc Text]
    -> TypeSpec -> Text -> Text -> Parameter e [Doc Text]
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter (Peeker e (Doc Text) -> Peeker e [Doc Text]
    forall a e. LuaError e => Peeker e a -> Peeker e [a]
    peekList Peeker e (Doc Text)
    forall e. LuaError e => Peeker e (Doc Text)
    peekDoc) TypeSpec
    "`{Doc,...}`" Text
    "docs" Text
    "list of Docs"
      HsFnPrecursor e (Maybe (Doc Text) -> LuaE e (Doc Text))
    -> Parameter e (Maybe (Doc Text))
    -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e (Doc Text) -> Parameter e (Maybe (Doc Text))
    forall e a. Parameter e a -> Parameter e (Maybe a)
    opt (Peeker e (Doc Text)
    -> TypeSpec -> Text -> Text -> Parameter e (Doc Text)
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter Peeker e (Doc Text)
    forall e. LuaError e => Peeker e (Doc Text)
    peekDoc TypeSpec
    "Doc" Text
    "sep" Text
    "separator (default: none)")
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "concatenated doc"
      #? "Concatenates a list of `Doc`s."

    -- | Wraps a @'Doc'@ in double quotes
    double_quotes :: LuaError e => DocumentedFunction e
    double_quotes :: forall e. LuaError e => DocumentedFunction e
    double_quotes = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "double_quotes"
      ### liftPure Doc.doubleQuotes
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "`doc` enclosed by `\"` chars"
      #? "Wraps a `Doc` in double quotes."

    -- | Makes a @'Doc'@ flush against the left margin.
    flush :: LuaError e => DocumentedFunction e
    flush :: forall e. LuaError e => DocumentedFunction e
    flush = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "flush"
      ### liftPure Doc.flush
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "flushed `doc`"
      #? "Makes a `Doc` flush against the left margin."

    -- | Creates a hanging indent.
    hang :: LuaError e => DocumentedFunction e
    hang :: forall e. LuaError e => DocumentedFunction e
    hang = Name
    -> (Doc Text -> Int -> Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor
         e (Doc Text -> Int -> Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "hang"
      ### liftPure3 (\doc ind start -> Doc.hang ind start doc)
      HsFnPrecursor e (Doc Text -> Int -> Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Int -> Doc Text -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> Doc Text -> LuaE e (Doc Text))
    -> Parameter e Int
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "ind" Text
    "indentation width"
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "start"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult (Text
    "`doc` prefixed by `start` on the first line, " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                     Text
    "subsequent lines indented by `ind` spaces.")
      #? "Creates a hanging indent."

    -- | Encloses a @'Doc'@ inside a start and end @'Doc'@.
    inside :: LuaError e => DocumentedFunction e
    inside :: forall e. LuaError e => DocumentedFunction e
    inside = Name
    -> (Doc Text -> Doc Text -> Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor
         e (Doc Text -> Doc Text -> Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "inside"
      ### liftPure3 (\contents start end -> Doc.inside start end contents)
      HsFnPrecursor
      e (Doc Text -> Doc Text -> Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "contents"
      HsFnPrecursor e (Doc Text -> Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "start"
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "end"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "enclosed contents"
      #? "Encloses a [[Doc]] inside a start and end [[Doc]]."

    -- | Creates a block with the given width and content, aligned to
    -- the left.
    lblock :: LuaError e => DocumentedFunction e
    lblock :: forall e. LuaError e => DocumentedFunction e
    lblock = Name
    -> (Doc Text -> Int -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "lblock"
      ### liftPure2 (flip Doc.lblock)
      HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Int -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> LuaE e (Doc Text))
    -> Parameter e Int -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "width" Text
    "block width in chars"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "doc put into block with max `width` chars per line."
      #? ("Creates a block with the given width and content, " <>
          "aligned to the left.")

    -- | Creates a @'Doc'@ from a string.
    literal :: LuaError e => DocumentedFunction e
    literal :: forall e. LuaError e => DocumentedFunction e
    literal = Name
    -> (Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "literal"
      ### liftPure Doc.literal
      HsFnPrecursor e (Text -> LuaE e (Doc Text))
    -> Parameter e Text -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Text
    forall e. Text -> Text -> Parameter e Text
    textParam Text
    "text" Text
    "literal value"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "doc contatining just the literal string"
      #? "Creates a `Doc` from a string."

    -- | Indents a @'Doc'@ by the specified number of spaces.
    nest :: LuaError e => DocumentedFunction e
    nest :: forall e. LuaError e => DocumentedFunction e
    nest = Name
    -> (Doc Text -> Int -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "nest"
      ### liftPure2 (flip Doc.nest)
      HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Int -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> LuaE e (Doc Text))
    -> Parameter e Int -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "ind" Text
    "indentation size"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "`doc` indented by `ind` spaces"
      #? "Indents a `Doc` by the specified number of spaces."

    -- | Removes leading blank lines from a @'Doc'@.
    nestle :: LuaError e => DocumentedFunction e
    nestle :: forall e. LuaError e => DocumentedFunction e
    nestle = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "nestle"
      ### liftPure Doc.nestle
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "`doc` with leading blanks removed"
      #? "Removes leading blank lines from a `Doc`."

    -- | Makes a @'Doc'@ non-reflowable.
    nowrap :: LuaError e => DocumentedFunction e
    nowrap :: forall e. LuaError e => DocumentedFunction e
    nowrap = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "nowrap"
      ### liftPure Doc.nowrap
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "same as input, but non-reflowable"
      #? "Makes a `Doc` non-reflowable."

    -- | Puts a @'Doc'@ in parentheses.
    parens :: LuaError e => DocumentedFunction e
    parens :: forall e. LuaError e => DocumentedFunction e
    parens = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "parens"
      ### liftPure Doc.parens
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "doc enclosed by ()."
      #? "Puts the `doc` in parentheses."

    -- | Uses the specified string as a prefix for every line of the
    -- inside document (except the first, if not at the beginning of
    -- the line).
    prefixed :: LuaError e => DocumentedFunction e
    prefixed :: forall e. LuaError e => DocumentedFunction e
    prefixed = Name
    -> (Doc Text -> String -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> String -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "prefixed"
      ### liftPure2 (flip Doc.prefixed)
      HsFnPrecursor e (Doc Text -> String -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (String -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (String -> LuaE e (Doc Text))
    -> Parameter e String -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e String
    forall e. Text -> Text -> Parameter e String
    stringParam Text
    "prefix" Text
    "prefix for each line"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "prefixed `doc`"
      #? ("Uses the specified string as a prefix for every line of " <>
          "the inside document (except the first, if not at the " <>
          "beginning of the line).")

    -- | Wraps a @'Doc'@ in single quotes.
    quotes :: LuaError e => DocumentedFunction e
    quotes :: forall e. LuaError e => DocumentedFunction e
    quotes = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "quotes"
      ### liftPure Doc.quotes
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "doc enclosed in `'`."
      #? "Wraps a `Doc` in single quotes."

    -- | Like @'rblock'@ but aligned to the right.
    rblock :: LuaError e => DocumentedFunction e
    rblock :: forall e. LuaError e => DocumentedFunction e
    rblock = Name
    -> (Doc Text -> Int -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "rblock"
      ### liftPure2 (flip Doc.rblock)
      HsFnPrecursor e (Doc Text -> Int -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Int -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Int -> LuaE e (Doc Text))
    -> Parameter e Int -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Int
    forall a e. (Read a, Integral a) => Text -> Text -> Parameter e a
    integralParam Text
    "width" Text
    "block width in chars"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult (Text
    "doc, right aligned in a block with max " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                     Text
    "`width` chars per line.")
      #? ("Creates a block with the given width and content, " <>
          "aligned to the right.")

    -- | An expandable border that, when placed next to a box,
    -- expands to the height of the box.  Strings cycle through the
    -- list provided.
    vfill :: LuaError e => DocumentedFunction e
    vfill :: forall e. LuaError e => DocumentedFunction e
    vfill = Name
    -> (Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "vfill"
      ### liftPure Doc.vfill
      HsFnPrecursor e (Text -> LuaE e (Doc Text))
    -> Parameter e Text -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Text -> Parameter e Text
    forall e. Text -> Text -> Parameter e Text
    textParam Text
    "border" Text
    "vertically expanded characters"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "automatically expanding border Doc"
      #? ("An expandable border that, when placed next to a box, " <>
          "expands to the height of the box.  Strings cycle through the " <>
          "list provided.")

    --
    -- Styling
    --

    bold :: LuaError e => DocumentedFunction e
    bold :: forall e. LuaError e => DocumentedFunction e
    bold = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "bold"
      ### liftPure Doc.bold
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "bolded Doc"
      #? "Puts a [[Doc]] in boldface."

    italic :: LuaError e => DocumentedFunction e
    italic :: forall e. LuaError e => DocumentedFunction e
    italic = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "italic"
      ### liftPure Doc.italic
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "styled Doc"
      #? "Puts a [[Doc]] in italics."

    underlined :: LuaError e => DocumentedFunction e
    underlined :: forall e. LuaError e => DocumentedFunction e
    underlined = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "underlined"
      ### liftPure Doc.underlined
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "styled Doc"
      #? "Underlines a [[Doc]]."

    strikeout :: LuaError e => DocumentedFunction e
    strikeout :: forall e. LuaError e => DocumentedFunction e
    strikeout = Name
    -> (Doc Text -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "strikeout"
      ### liftPure Doc.strikeout
      HsFnPrecursor e (Doc Text -> LuaE e (Doc Text))
    -> Parameter e (Doc Text) -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "styled Doc"
      #? "Puts a line through the [[Doc]]."

    fg :: LuaError e => DocumentedFunction e
    fg :: forall e. LuaError e => DocumentedFunction e
    fg = Name
    -> (Doc Text -> Color -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Color -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "fg"
      ### liftPure2 (flip Doc.fg)
      HsFnPrecursor e (Doc Text -> Color -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Color -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Color -> LuaE e (Doc Text))
    -> Parameter e Color -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e Color
    forall e. Parameter e Color
    colorParam
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "styled Doc"
      #? "Set the foreground color."

    bg :: LuaError e => DocumentedFunction e
    bg :: forall e. LuaError e => DocumentedFunction e
    bg = Name
    -> (Doc Text -> Color -> LuaE e (Doc Text))
    -> HsFnPrecursor e (Doc Text -> Color -> LuaE e (Doc Text))
    forall a e. Name -> a -> HsFnPrecursor e a
    defun Name
    "bg"
      ### liftPure2 (flip Doc.bg)
      HsFnPrecursor e (Doc Text -> Color -> LuaE e (Doc Text))
    -> Parameter e (Doc Text)
    -> HsFnPrecursor e (Color -> LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Text -> Parameter e (Doc Text)
    forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    "doc"
      HsFnPrecursor e (Color -> LuaE e (Doc Text))
    -> Parameter e Color -> HsFnPrecursor e (LuaE e (Doc Text))
    forall e a b.
    HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
    <#> Parameter e Color
    forall e. Parameter e Color
    colorParam
      HsFnPrecursor e (LuaE e (Doc Text))
    -> FunctionResults e (Doc Text) -> DocumentedFunction e
    forall e a.
    HsFnPrecursor e (LuaE e a)
    -> FunctionResults e a -> DocumentedFunction e
    =#> Text -> FunctionResults e (Doc Text)
    forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult Text
    "styled Doc"
      #? "Set the background color."

    --
    -- Marshaling
    --

    -- | Retrieve a @Doc Text@ value from the Lua stack. Strings are
    -- converted to plain @'Doc'@ values.
    peekDoc :: LuaError e => Peeker e (Doc Text)
    peekDoc :: forall e. LuaError e => Peeker e (Doc Text)
    peekDoc StackIndex
    idx = LuaE e Type -> Peek e Type
    forall e a. LuaE e a -> Peek e a
    liftLua (StackIndex -> LuaE e Type
    forall e. StackIndex -> LuaE e Type
    Lua.ltype StackIndex
    idx) Peek e Type -> (Type -> Peek e (Doc Text)) -> Peek e (Doc Text)
    forall a b. Peek e a -> (a -> Peek e b) -> Peek e b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
      Type
    Lua.TypeString   -> let stringToDoc :: Text -> Doc Text
    stringToDoc Text
    s = if Text -> Bool
    T.null Text
    s
                                              then Doc Text
    forall a. Doc a
    Doc.empty
                                              else Text -> Doc Text
    forall a. HasChars a => a -> Doc a
    Doc.literal Text
    s
                          in Text -> Doc Text
    stringToDoc (Text -> Doc Text) -> Peek e Text -> Peek e (Doc Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Peeker e Text
    forall e. Peeker e Text
    Lua.peekText StackIndex
    idx
      Type
    Lua.TypeNumber   -> Text -> Doc Text
    forall a. HasChars a => a -> Doc a
    Doc.literal (Text -> Doc Text) -> Peek e Text -> Peek e (Doc Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Peeker e Text
    forall e. Peeker e Text
    Lua.peekText StackIndex
    idx
      Type
    _                -> DocumentedTypeWithList e (Doc Text) Void -> Peeker e (Doc Text)
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> Peeker e a
    peekUD DocumentedTypeWithList e (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc StackIndex
    idx

    -- | Push a @Doc Text@ value to the Lua stack.
    pushDoc :: LuaError e => Pusher e (Doc Text)
    pushDoc :: forall e. LuaError e => Pusher e (Doc Text)
    pushDoc = DocumentedTypeWithList e (Doc Text) Void -> Doc Text -> LuaE e ()
    forall e a itemtype.
    LuaError e =>
    DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
    pushUD DocumentedTypeWithList e (Doc Text) Void
    forall e. LuaError e => DocumentedType e (Doc Text)
    typeDoc

    instance Peekable (Doc Text) where
      safepeek :: forall e. LuaError e => Peeker e (Doc Text)
    safepeek = Peeker e (Doc Text)
    forall e. LuaError e => Peeker e (Doc Text)
    peekDoc

    instance Pushable (Doc Text) where
      push :: forall e. LuaError e => Pusher e (Doc Text)
    push = Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc

    --
    -- Parameters
    --

    -- | @Doc@ typed function parameter.
    docParam :: LuaError e => Text -> Parameter e (Doc Text)
    docParam :: forall e. LuaError e => Text -> Parameter e (Doc Text)
    docParam Text
    name = Peeker e (Doc Text)
    -> TypeSpec -> Text -> Text -> Parameter e (Doc Text)
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter Peeker e (Doc Text)
    forall e. LuaError e => Peeker e (Doc Text)
    peekDoc TypeSpec
    "Doc" Text
    name Text
    "document"

    -- | @Color@ function parameter
    colorParam :: Parameter e Doc.Color
    colorParam :: forall e. Parameter e Color
    colorParam = Peeker e Color -> TypeSpec -> Text -> Text -> Parameter e Color
    forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
    parameter Peeker e Color
    forall {e}. StackIndex -> Peek e Color
    peekColor TypeSpec
    "string" Text
    "color"
      (Text
    "One of 'black', 'red', 'green', 'yellow', 'blue', 'magenta' " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
       Text
    "'cyan', or 'white'.")
      where
        peekColor :: StackIndex -> Peek e Color
    peekColor StackIndex
    idx = Peeker e ByteString
    forall e. Peeker e ByteString
    peekByteString StackIndex
    idx Peek e ByteString -> (ByteString -> Peek e Color) -> Peek e Color
    forall a b. Peek e a -> (a -> Peek e b) -> Peek e b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \case
          ByteString
    "black"   -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.black
          ByteString
    "red"     -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.red
          ByteString
    "green"   -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.green
          ByteString
    "yellow"  -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.yellow
          ByteString
    "blue"    -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.blue
          ByteString
    "magenta" -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.magenta
          ByteString
    "cyan"    -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.cyan
          ByteString
    "white"   -> Color -> Peek e Color
    forall a. a -> Peek e a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure Color
    Doc.white
          ByteString
    color -> ByteString -> Peek e Color
    forall a e. ByteString -> Peek e a
    failPeek (ByteString -> Peek e Color) -> ByteString -> Peek e Color
    forall a b. (a -> b) -> a -> b
    $ ByteString
    "Unknown color: " ByteString -> ByteString -> ByteString
    forall a. Semigroup a => a -> a -> a
    <> ByteString
    color

    --
    -- Results
    --

    -- | Function result of type @'Doc'@.
    docResult :: LuaError e
              => Text -- ^ Description
              -> FunctionResults e (Doc Text)
    docResult :: forall e. LuaError e => Text -> FunctionResults e (Doc Text)
    docResult = Pusher e (Doc Text)
    -> TypeSpec -> Text -> FunctionResults e (Doc Text)
    forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
    functionResult Pusher e (Doc Text)
    forall e. LuaError e => Pusher e (Doc Text)
    pushDoc TypeSpec
    "Doc"