{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE KindSignatures #-}
module Language.Haskell.Brittany.Internal.Layouters.DataDecl
( layoutDataDecl
)
where
#include "prelude.inc"
import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.LayouterBasics
import Language.Haskell.Brittany.Internal.Config.Types
import RdrName ( RdrName(..) )
import GHC ( Located, runGhc, GenLocated(L), moduleNameString )
import qualified GHC
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
#else
import HsSyn
#endif
import Name
import BasicTypes
import Language.Haskell.GHC.ExactPrint.Types ( mkAnnKey )
import Language.Haskell.Brittany.Internal.Layouters.Type
import {-# SOURCE #-} Language.Haskell.Brittany.Internal.Layouters.Expr
import {-# SOURCE #-} Language.Haskell.Brittany.Internal.Layouters.Stmt
import Language.Haskell.Brittany.Internal.Layouters.Pattern
import Language.Haskell.Brittany.Internal.Utils
import Bag ( mapBagM )
layoutDataDecl
:: Located (TyClDecl GhcPs)
-> Located RdrName
-> LHsQTyVars GhcPs
-> HsDataDefn GhcPs
-> ToBriDocM BriDocNumbered
layoutDataDecl :: Located (TyClDecl GhcPs)
-> Located RdrName
-> LHsQTyVars GhcPs
-> HsDataDefn GhcPs
-> ToBriDocM BriDocNumbered
layoutDataDecl Located (TyClDecl GhcPs)
_ Located RdrName
_ (XLHsQTyVars XXLHsQTyVars GhcPs
ext) HsDataDefn GhcPs
_ = NoExtCon -> ToBriDocM BriDocNumbered
forall a. NoExtCon -> a
absurdExt NoExtCon
XXLHsQTyVars GhcPs
ext
layoutDataDecl Located (TyClDecl GhcPs)
ltycl Located RdrName
name (HsQTvs XHsQTvs GhcPs
_ [LHsTyVarBndr GhcPs]
bndrs) HsDataDefn GhcPs
defn = case HsDataDefn GhcPs
defn of
HsDataDefn XCHsDataDefn GhcPs
_ext NewOrData
NewType (L SrcSpan
_ []) Maybe (Located CType)
_ctype Maybe (LHsKind GhcPs)
Nothing [LConDecl GhcPs
cons] HsDeriving GhcPs
mDerivs -> case LConDecl GhcPs
cons of
(L SrcSpan
_ (ConDeclH98 XConDeclH98 GhcPs
_ext Located (IdP GhcPs)
consName (L SrcSpan
_ Bool
False) [LHsTyVarBndr GhcPs]
_qvars (Just (L SrcSpan
_ [])) HsConDeclDetails GhcPs
details Maybe LHsDocString
_conDoc)) ->
Located (TyClDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (TyClDecl GhcPs)
ltycl (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
Text
nameStr <- Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located RdrName
name
Text
consNameStr <- Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located (IdP GhcPs)
Located RdrName
consName
ToBriDocM BriDocNumbered
tyVarLine <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc [LHsTyVarBndr GhcPs]
bndrs
ToBriDocM BriDocNumbered
rhsDoc <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ Text -> HsConDeclDetails GhcPs -> ToBriDocM BriDocNumbered
createDetailsDoc Text
consNameStr HsConDeclDetails GhcPs
details
HsDeriving GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
createDerivingPar HsDeriving GhcPs
mDerivs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"newtype"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
tyVarLine
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"="
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered
rhsDoc
]
LConDecl GhcPs
_ -> Located (TyClDecl GhcPs) -> ToBriDocM BriDocNumbered
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment Located (TyClDecl GhcPs)
ltycl
HsDataDefn XCHsDataDefn GhcPs
_ext NewOrData
DataType (L SrcSpan
_ HsContext GhcPs
lhsContext) Maybe (Located CType)
_ctype Maybe (LHsKind GhcPs)
Nothing [] HsDeriving GhcPs
mDerivs ->
Located (TyClDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (TyClDecl GhcPs)
ltycl (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
ToBriDocM BriDocNumbered
lhsContextDoc <- (HsContext GhcPs -> ToBriDocM BriDocNumbered)
-> HsContext GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper HsContext GhcPs -> ToBriDocM BriDocNumbered
createContextDoc HsContext GhcPs
lhsContext
Text
nameStr <- Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located RdrName
name
ToBriDocM BriDocNumbered
tyVarLine <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc [LHsTyVarBndr GhcPs]
bndrs
HsDeriving GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
createDerivingPar HsDeriving GhcPs
mDerivs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"data"
, ToBriDocM BriDocNumbered
lhsContextDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
tyVarLine
]
HsDataDefn XCHsDataDefn GhcPs
_ext NewOrData
DataType (L SrcSpan
_ HsContext GhcPs
lhsContext) Maybe (Located CType)
_ctype Maybe (LHsKind GhcPs)
Nothing [LConDecl GhcPs
cons] HsDeriving GhcPs
mDerivs ->
case LConDecl GhcPs
cons of
(L SrcSpan
_ (ConDeclH98 XConDeclH98 GhcPs
_ext Located (IdP GhcPs)
consName (L SrcSpan
_ Bool
_hasExt) [LHsTyVarBndr GhcPs]
qvars Maybe (GenLocated SrcSpan (HsContext GhcPs))
mRhsContext HsConDeclDetails GhcPs
details Maybe LHsDocString
_conDoc)) ->
Located (TyClDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (TyClDecl GhcPs)
ltycl (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
ToBriDocM BriDocNumbered
lhsContextDoc <- (HsContext GhcPs -> ToBriDocM BriDocNumbered)
-> HsContext GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper HsContext GhcPs -> ToBriDocM BriDocNumbered
createContextDoc HsContext GhcPs
lhsContext
Text
nameStr <- Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located RdrName
name
Text
consNameStr <- Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located (IdP GhcPs)
Located RdrName
consName
ToBriDocM BriDocNumbered
tyVarLine <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc [LHsTyVarBndr GhcPs]
bndrs
Maybe (ToBriDocM BriDocNumbered)
forallDocMay <- case [LHsTyVarBndr GhcPs] -> Maybe (ToBriDocM BriDocNumbered)
createForallDoc [LHsTyVarBndr GhcPs]
qvars of
Maybe (ToBriDocM BriDocNumbered)
Nothing -> Maybe (ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
Just ToBriDocM BriDocNumbered
x -> ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a. a -> Maybe a
Just (ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> BriDocNumbered
-> Maybe (ToBriDocM BriDocNumbered)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BriDocNumbered -> ToBriDocM BriDocNumbered
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDocM BriDocNumbered
x
Maybe (ToBriDocM BriDocNumbered)
rhsContextDocMay <- case Maybe (GenLocated SrcSpan (HsContext GhcPs))
mRhsContext of
Maybe (GenLocated SrcSpan (HsContext GhcPs))
Nothing -> Maybe (ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
Just (L SrcSpan
_ HsContext GhcPs
ctxt) -> ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a. a -> Maybe a
Just (ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> BriDocNumbered
-> Maybe (ToBriDocM BriDocNumbered)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BriDocNumbered -> ToBriDocM BriDocNumbered
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsContext GhcPs -> ToBriDocM BriDocNumbered
createContextDoc HsContext GhcPs
ctxt
ToBriDocM BriDocNumbered
rhsDoc <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ Text -> HsConDeclDetails GhcPs -> ToBriDocM BriDocNumbered
createDetailsDoc Text
consNameStr HsConDeclDetails GhcPs
details
ToBriDocM BriDocNumbered
consDoc <- (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> ToBriDocM BriDocNumbered
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docNonBottomSpacing
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case (Maybe (ToBriDocM BriDocNumbered)
forallDocMay, Maybe (ToBriDocM BriDocNumbered)
rhsContextDocMay) of
(Just ToBriDocM BriDocNumbered
forallDoc, Just ToBriDocM BriDocNumbered
rhsContextDoc) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"=", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
forallDoc]
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"."
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered
rhsContextDoc, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
rhsDoc]
]
]
(Just ToBriDocM BriDocNumbered
forallDoc, Maybe (ToBriDocM BriDocNumbered)
Nothing) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"=", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
forallDoc]
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
".", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
rhsDoc]
]
(Maybe (ToBriDocM BriDocNumbered)
Nothing, Just ToBriDocM BriDocNumbered
rhsContextDoc) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"="
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered
rhsContextDoc, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
rhsDoc]
]
(Maybe (ToBriDocM BriDocNumbered)
Nothing, Maybe (ToBriDocM BriDocNumbered)
Nothing) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"=", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
rhsDoc]
HsDeriving GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
createDerivingPar HsDeriving GhcPs
mDerivs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
[
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ Located (TyClDecl GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (TyClDecl GhcPs)
ltycl (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnData)
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"data"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
lhsContextDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
tyVarLine
, ToBriDocM BriDocNumbered
docSeparator
]
, String -> ToBriDocM BriDocNumbered
docLitS String
"="
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ case Maybe (ToBriDocM BriDocNumbered)
forallDocMay of
Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
Just ToBriDocM BriDocNumbered
forallDoc -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
forallDoc
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"."
, ToBriDocM BriDocNumbered
docSeparator
]
, ToBriDocM BriDocNumbered
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> Maybe (ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ToBriDocM BriDocNumbered
docEmpty ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline Maybe (ToBriDocM BriDocNumbered)
rhsContextDocMay
, ToBriDocM BriDocNumbered
rhsDoc
]
]
,
BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
( Located (TyClDecl GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (TyClDecl GhcPs)
ltycl (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnData)
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"data"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
lhsContextDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered
tyVarLine
]
)
( [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"="
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ case Maybe (ToBriDocM BriDocNumbered)
forallDocMay of
Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
Just ToBriDocM BriDocNumbered
forallDoc -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
forallDoc
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"."
, ToBriDocM BriDocNumbered
docSeparator
]
, ToBriDocM BriDocNumbered
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> Maybe (ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ToBriDocM BriDocNumbered
docEmpty ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline Maybe (ToBriDocM BriDocNumbered)
rhsContextDocMay
, ToBriDocM BriDocNumbered
rhsDoc
]
]
)
,
BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
( Located (TyClDecl GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (TyClDecl GhcPs)
ltycl (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnData)
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"data"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
lhsContextDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered
tyVarLine
]
)
ToBriDocM BriDocNumbered
consDoc
,
BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
(String -> ToBriDocM BriDocNumbered
docLitS String
"data")
( [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ ToBriDocM BriDocNumbered
lhsContextDoc
, Located (TyClDecl GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (TyClDecl GhcPs)
ltycl (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
GHC.AnnData)
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered
tyVarLine
]
, ToBriDocM BriDocNumbered
consDoc
]
)
]
LConDecl GhcPs
_ -> Located (TyClDecl GhcPs) -> ToBriDocM BriDocNumbered
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment Located (TyClDecl GhcPs)
ltycl
HsDataDefn GhcPs
_ -> Located (TyClDecl GhcPs) -> ToBriDocM BriDocNumbered
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment Located (TyClDecl GhcPs)
ltycl
createContextDoc :: HsContext GhcPs -> ToBriDocM BriDocNumbered
createContextDoc :: HsContext GhcPs -> ToBriDocM BriDocNumbered
createContextDoc [] = ToBriDocM BriDocNumbered
docEmpty
createContextDoc [LHsKind GhcPs
t] =
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDoc HsType
layoutType LHsKind GhcPs
t, ToBriDocM BriDocNumbered
docSeparator, String -> ToBriDocM BriDocNumbered
docLitS String
"=>", ToBriDocM BriDocNumbered
docSeparator]
createContextDoc (LHsKind GhcPs
t1 : HsContext GhcPs
tR) = do
ToBriDocM BriDocNumbered
t1Doc <- ToBriDoc HsType
-> LHsKind GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper ToBriDoc HsType
layoutType LHsKind GhcPs
t1
[ToBriDocM BriDocNumbered]
tRDocs <- HsContext GhcPs
tR HsContext GhcPs
-> (LHsKind GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[ToBriDocM BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` ToBriDoc HsType
-> LHsKind GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper ToBriDoc HsType
layoutType
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"("
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
(ToBriDocM BriDocNumbered
t1Doc ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
: [ToBriDocM BriDocNumbered]
tRDocs)
, String -> ToBriDocM BriDocNumbered
docLitS String
") =>"
, ToBriDocM BriDocNumbered
docSeparator
]
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [[ToBriDocM BriDocNumbered]] -> [ToBriDocM BriDocNumbered]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join
[ [[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"(", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
t1Doc]]
, [ToBriDocM BriDocNumbered]
tRDocs
[ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ToBriDocM BriDocNumbered
tRDoc -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
",", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
tRDoc]
, [String -> ToBriDocM BriDocNumbered
docLitS String
") =>", ToBriDocM BriDocNumbered
docSeparator]
]
]
createBndrDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc [LHsTyVarBndr GhcPs]
bs = do
[(Text, Maybe (ToBriDocM BriDocNumbered))]
tyVarDocs <- [LHsTyVarBndr GhcPs]
bs [LHsTyVarBndr GhcPs]
-> (LHsTyVarBndr GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered)))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[(Text, Maybe (ToBriDocM BriDocNumbered))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \case
(L SrcSpan
_ (UserTyVar XUserTyVar GhcPs
_ext Located (IdP GhcPs)
vname)) -> (Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return ((Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered)))
-> (Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered))
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located (IdP GhcPs)
Located RdrName
vname, Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing)
(L SrcSpan
_ (KindedTyVar XKindedTyVar GhcPs
_ext Located (IdP GhcPs)
lrdrName LHsKind GhcPs
kind)) -> do
ToBriDocM BriDocNumbered
d <- ToBriDoc HsType
-> LHsKind GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper ToBriDoc HsType
layoutType LHsKind GhcPs
kind
(Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return ((Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered)))
-> (Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered))
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located (IdP GhcPs)
Located RdrName
lrdrName, ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a. a -> Maybe a
Just (ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
d)
(L SrcSpan
_ (XTyVarBndr XXTyVarBndr GhcPs
ext)) -> NoExtCon
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Text, Maybe (ToBriDocM BriDocNumbered))
forall a. NoExtCon -> a
absurdExt NoExtCon
XXTyVarBndr GhcPs
ext
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docSeparator
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [(Text, Maybe (ToBriDocM BriDocNumbered))]
tyVarDocs
[(Text, Maybe (ToBriDocM BriDocNumbered))]
-> ((Text, Maybe (ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(Text
vname, Maybe (ToBriDocM BriDocNumbered)
mKind) -> case Maybe (ToBriDocM BriDocNumbered)
mKind of
Maybe (ToBriDocM BriDocNumbered)
Nothing -> Text -> ToBriDocM BriDocNumbered
docLit Text
vname
Just ToBriDocM BriDocNumbered
kind -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"("
, Text -> ToBriDocM BriDocNumbered
docLit Text
vname
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"::"
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered
kind
, String -> ToBriDocM BriDocNumbered
docLitS String
")"
]
createDerivingPar
:: HsDeriving GhcPs -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
createDerivingPar :: HsDeriving GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
createDerivingPar HsDeriving GhcPs
derivs ToBriDocM BriDocNumbered
mainDoc = do
case HsDeriving GhcPs
derivs of
(L SrcSpan
_ []) -> ToBriDocM BriDocNumbered
mainDoc
(L SrcSpan
_ [LHsDerivingClause GhcPs]
types) ->
ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar ToBriDocM BriDocNumbered
mainDoc
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docEnsureIndent BrIndent
BrIndentRegular
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ HsDeriving GhcPs
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode HsDeriving GhcPs
derivs
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ LHsDerivingClause GhcPs -> ToBriDocM BriDocNumbered
derivingClauseDoc
(LHsDerivingClause GhcPs -> ToBriDocM BriDocNumbered)
-> [LHsDerivingClause GhcPs] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsDerivingClause GhcPs]
types
derivingClauseDoc :: LHsDerivingClause GhcPs -> ToBriDocM BriDocNumbered
derivingClauseDoc :: LHsDerivingClause GhcPs -> ToBriDocM BriDocNumbered
derivingClauseDoc (L SrcSpan
_ (XHsDerivingClause XXHsDerivingClause GhcPs
ext)) = NoExtCon -> ToBriDocM BriDocNumbered
forall a. NoExtCon -> a
absurdExt NoExtCon
XXHsDerivingClause GhcPs
ext
derivingClauseDoc (L SrcSpan
_ (HsDerivingClause XCHsDerivingClause GhcPs
_ext Maybe (LDerivStrategy GhcPs)
mStrategy Located [LHsSigType GhcPs]
types)) = case Located [LHsSigType GhcPs]
types of
(L SrcSpan
_ []) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq []
(L SrcSpan
_ [LHsSigType GhcPs]
ts) ->
let
tsLength :: Int
tsLength = [LHsSigType GhcPs] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsSigType GhcPs]
ts
whenMoreThan1Type :: String -> ToBriDocM BriDocNumbered
whenMoreThan1Type String
val =
if Int
tsLength Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 then String -> ToBriDocM BriDocNumbered
docLitS String
val else String -> ToBriDocM BriDocNumbered
docLitS String
""
(ToBriDocM BriDocNumbered
lhsStrategy, ToBriDocM BriDocNumbered
rhsStrategy) = (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
-> (LDerivStrategy GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered))
-> Maybe (LDerivStrategy GhcPs)
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ToBriDocM BriDocNumbered
docEmpty, ToBriDocM BriDocNumbered
docEmpty) LDerivStrategy GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
strategyLeftRight Maybe (LDerivStrategy GhcPs)
mStrategy
in
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDocM BriDocNumbered
docDeriving
, Located [LHsSigType GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior Located [LHsSigType GhcPs]
types (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
lhsStrategy
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
whenMoreThan1Type String
"("
, Located [LHsSigType GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest Located [LHsSigType GhcPs]
types
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [LHsSigType GhcPs]
ts [LHsSigType GhcPs]
-> (LHsSigType GhcPs -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
HsIB XHsIB GhcPs (LHsKind GhcPs)
_ LHsKind GhcPs
t -> ToBriDoc HsType
layoutType LHsKind GhcPs
t
XHsImplicitBndrs XXHsImplicitBndrs GhcPs (LHsKind GhcPs)
x -> NoExtCon -> ToBriDocM BriDocNumbered
forall a. NoExtCon -> a
absurdExt NoExtCon
XXHsImplicitBndrs GhcPs (LHsKind GhcPs)
x
, String -> ToBriDocM BriDocNumbered
whenMoreThan1Type String
")"
, ToBriDocM BriDocNumbered
rhsStrategy
]
where
strategyLeftRight :: LDerivStrategy GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
strategyLeftRight = \case
(L SrcSpan
_ DerivStrategy GhcPs
StockStrategy ) -> (String -> ToBriDocM BriDocNumbered
docLitS String
" stock", ToBriDocM BriDocNumbered
docEmpty)
(L SrcSpan
_ DerivStrategy GhcPs
AnyclassStrategy ) -> (String -> ToBriDocM BriDocNumbered
docLitS String
" anyclass", ToBriDocM BriDocNumbered
docEmpty)
(L SrcSpan
_ DerivStrategy GhcPs
NewtypeStrategy ) -> (String -> ToBriDocM BriDocNumbered
docLitS String
" newtype", ToBriDocM BriDocNumbered
docEmpty)
lVia :: LDerivStrategy GhcPs
lVia@(L SrcSpan
_ (ViaStrategy XViaStrategy GhcPs
viaTypes) ) ->
( ToBriDocM BriDocNumbered
docEmpty
, case XViaStrategy GhcPs
viaTypes of
HsIB _ext t -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ LDerivStrategy GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LDerivStrategy GhcPs
lVia (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
" via"
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDoc HsType
layoutType LHsKind GhcPs
t
]
XHsImplicitBndrs ext -> NoExtCon -> ToBriDocM BriDocNumbered
forall a. NoExtCon -> a
absurdExt NoExtCon
XXHsImplicitBndrs GhcPs (LHsKind GhcPs)
ext
)
docDeriving :: ToBriDocM BriDocNumbered
docDeriving :: ToBriDocM BriDocNumbered
docDeriving = String -> ToBriDocM BriDocNumbered
docLitS String
"deriving"
createDetailsDoc
:: Text -> HsConDeclDetails GhcPs -> (ToBriDocM BriDocNumbered)
createDetailsDoc :: Text -> HsConDeclDetails GhcPs -> ToBriDocM BriDocNumbered
createDetailsDoc Text
consNameStr HsConDeclDetails GhcPs
details = case HsConDeclDetails GhcPs
details of
PrefixCon HsContext GhcPs
args -> do
IndentPolicy
indentPolicy <- MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Config
forall a (m :: * -> *). MonadMultiReader a m => m a
mAsk MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Config
-> (Config -> IndentPolicy)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
IndentPolicy
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Config -> CLayoutConfig Identity
forall (f :: * -> *). CConfig f -> CLayoutConfig f
_conf_layout (Config -> CLayoutConfig Identity)
-> (CLayoutConfig Identity -> Identity (Last IndentPolicy))
-> Config
-> Identity (Last IndentPolicy)
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> CLayoutConfig Identity -> Identity (Last IndentPolicy)
forall (f :: * -> *). CLayoutConfig f -> f (Last IndentPolicy)
_lconfig_indentPolicy (Config -> Identity (Last IndentPolicy))
-> (Identity (Last IndentPolicy) -> IndentPolicy)
-> Config
-> IndentPolicy
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> Identity (Last IndentPolicy) -> IndentPolicy
forall a b. Coercible a b => Identity a -> b
confUnpack
let
singleLine :: ToBriDocM BriDocNumbered
singleLine = [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docSeparator
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ HsContext GhcPs
args HsContext GhcPs -> ToBriDoc HsType -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> ToBriDoc HsType
layoutType
]
leftIndented :: ToBriDocM BriDocNumbered
leftIndented = ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr)
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc HsType
layoutType ToBriDoc HsType -> HsContext GhcPs -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsContext GhcPs
args
multiAppended :: ToBriDocM BriDocNumbered
multiAppended = [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc HsType
layoutType ToBriDoc HsType -> HsContext GhcPs -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsContext GhcPs
args
]
multiIndented :: ToBriDocM BriDocNumbered
multiIndented = ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
(Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr)
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc HsType
layoutType ToBriDoc HsType -> HsContext GhcPs -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HsContext GhcPs
args)
case IndentPolicy
indentPolicy of
IndentPolicy
IndentPolicyLeft -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt [ToBriDocM BriDocNumbered
singleLine, ToBriDocM BriDocNumbered
leftIndented]
IndentPolicy
IndentPolicyMultiple -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt [ToBriDocM BriDocNumbered
singleLine, ToBriDocM BriDocNumbered
multiAppended, ToBriDocM BriDocNumbered
leftIndented]
IndentPolicy
IndentPolicyFree ->
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt [ToBriDocM BriDocNumbered
singleLine, ToBriDocM BriDocNumbered
multiAppended, ToBriDocM BriDocNumbered
multiIndented, ToBriDocM BriDocNumbered
leftIndented]
RecCon (L SrcSpan
_ []) -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr, ToBriDocM BriDocNumbered
docSeparator, Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"{}"]
RecCon lRec :: GenLocated SrcSpan [LConDeclField GhcPs]
lRec@(L SrcSpan
_ fields :: [LConDeclField GhcPs]
fields@(LConDeclField GhcPs
_:[LConDeclField GhcPs]
_)) -> do
let ((ToBriDocM BriDocNumbered
fName1, ToBriDocM BriDocNumbered
fType1) : [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
fDocR) = [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
mkFieldDocs [LConDeclField GhcPs]
fields
let allowSingleline :: Bool
allowSingleline = Bool
False
BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative
(CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond Bool
allowSingleline (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr
, ToBriDocM BriDocNumbered
docSeparator
, GenLocated SrcSpan [LConDeclField GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior GenLocated SrcSpan [LConDeclField GhcPs]
lRec (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> ToBriDocM BriDocNumbered
docLitS String
"{"
, ToBriDocM BriDocNumbered
docSeparator
, GenLocated SrcSpan [LConDeclField GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan [LConDeclField GhcPs]
lRec
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [[ToBriDocM BriDocNumbered]] -> [ToBriDocM BriDocNumbered]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join
([[ToBriDocM BriDocNumbered]] -> [ToBriDocM BriDocNumbered])
-> [[ToBriDocM BriDocNumbered]] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered
fName1, ToBriDocM BriDocNumbered
docSeparator, String -> ToBriDocM BriDocNumbered
docLitS String
"::", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
fType1]
[ToBriDocM BriDocNumbered]
-> [[ToBriDocM BriDocNumbered]] -> [[ToBriDocM BriDocNumbered]]
forall a. a -> [a] -> [a]
: [ [ String -> ToBriDocM BriDocNumbered
docLitS String
","
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered
fName
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"::"
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered
fType
]
| (ToBriDocM BriDocNumbered
fName, ToBriDocM BriDocNumbered
fType) <- [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
fDocR
]
, ToBriDocM BriDocNumbered
docSeparator
, String -> ToBriDocM BriDocNumbered
docLitS String
"}"
]
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
(Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr)
(GenLocated SrcSpan [LConDeclField GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior GenLocated SrcSpan [LConDeclField GhcPs]
lRec (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docNonBottomSpacingS (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
[ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRecDecl
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (String -> ToBriDocM BriDocNumbered
docLitS String
"{")
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
fName1
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"::", ToBriDocM BriDocNumbered
docSeparator]
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
fType1
]
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
"{"
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
ToBriDocM BriDocNumbered
fName1
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"::", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
fType1])
]
]
, GenLocated SrcSpan [LConDeclField GhcPs]
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan [LConDeclField GhcPs]
lRec (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
fDocR [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
-> ((ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(ToBriDocM BriDocNumbered
fName, ToBriDocM BriDocNumbered
fType) ->
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
[ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRecDecl
[ ToBriDocM BriDocNumbered
docCommaSep
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
fName
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"::", ToBriDocM BriDocNumbered
docSeparator]
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
fType
]
, [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ String -> ToBriDocM BriDocNumbered
docLitS String
","
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
ToBriDocM BriDocNumbered
fName
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [String -> ToBriDocM BriDocNumbered
docLitS String
"::", ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
fType])
]
]
, String -> ToBriDocM BriDocNumbered
docLitS String
"}"
]
)
InfixCon LHsKind GhcPs
arg1 LHsKind GhcPs
arg2 -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ ToBriDoc HsType
layoutType LHsKind GhcPs
arg1
, ToBriDocM BriDocNumbered
docSeparator
, Text -> ToBriDocM BriDocNumbered
docLit Text
consNameStr
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDoc HsType
layoutType LHsKind GhcPs
arg2
]
where
mkFieldDocs
:: [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
mkFieldDocs :: [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
mkFieldDocs = (LConDeclField GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered))
-> [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((LConDeclField GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered))
-> [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)])
-> (LConDeclField GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered))
-> [LConDeclField GhcPs]
-> [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
forall a b. (a -> b) -> a -> b
$ \LConDeclField GhcPs
lField -> case LConDeclField GhcPs
lField of
L SrcSpan
_ (ConDeclField XConDeclField GhcPs
_ext [LFieldOcc GhcPs]
names LHsKind GhcPs
t Maybe LHsDocString
_) -> LConDeclField GhcPs
-> [LFieldOcc GhcPs]
-> LHsKind GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
forall ast t.
Data ast =>
Located ast
-> [GenLocated t (FieldOcc GhcPs)]
-> LHsKind GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
createNamesAndTypeDoc LConDeclField GhcPs
lField [LFieldOcc GhcPs]
names LHsKind GhcPs
t
L SrcSpan
_ (XConDeclField XXConDeclField GhcPs
x) -> NoExtCon -> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
forall a. NoExtCon -> a
absurdExt NoExtCon
XXConDeclField GhcPs
x
createForallDoc :: [LHsTyVarBndr GhcPs] -> Maybe (ToBriDocM BriDocNumbered)
createForallDoc :: [LHsTyVarBndr GhcPs] -> Maybe (ToBriDocM BriDocNumbered)
createForallDoc [] = Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
createForallDoc [LHsTyVarBndr GhcPs]
lhsTyVarBndrs = ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a. a -> Maybe a
Just (ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered))
-> ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[String -> ToBriDocM BriDocNumbered
docLitS String
"forall ", [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
createBndrDoc [LHsTyVarBndr GhcPs]
lhsTyVarBndrs]
createNamesAndTypeDoc
:: Data.Data.Data ast
=> Located ast
-> [GenLocated t (FieldOcc GhcPs)]
-> Located (HsType GhcPs)
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
createNamesAndTypeDoc :: Located ast
-> [GenLocated t (FieldOcc GhcPs)]
-> LHsKind GhcPs
-> (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
createNamesAndTypeDoc Located ast
lField [GenLocated t (FieldOcc GhcPs)]
names LHsKind GhcPs
t =
( Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located ast
lField Maybe AnnKeywordId
forall a. Maybe a
Nothing (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located ast -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior Located ast
lField (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [GenLocated t (FieldOcc GhcPs)]
names
[GenLocated t (FieldOcc GhcPs)]
-> (GenLocated t (FieldOcc GhcPs) -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
L t
_ (XFieldOcc XXFieldOcc GhcPs
x) -> NoExtCon -> ToBriDocM BriDocNumbered
forall a. NoExtCon -> a
absurdExt NoExtCon
XXFieldOcc GhcPs
x
L t
_ (FieldOcc XCFieldOcc GhcPs
_ Located RdrName
fieldName) ->
Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located RdrName
fieldName
]
, Located ast -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest Located ast
lField (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc HsType
layoutType LHsKind GhcPs
t
)