{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
module Language.Haskell.Brittany.Internal.Layouters.Decl
( layoutDecl
, layoutSig
, layoutBind
, layoutLocalBinds
, layoutGuardLStmt
, layoutPatternBind
, layoutGrhs
, layoutPatternBindFinal
)
where
#include "prelude.inc"
import Language.Haskell.Brittany.Internal.Types
import Language.Haskell.Brittany.Internal.LayouterBasics
import Language.Haskell.Brittany.Internal.Config.Types
import Language.Haskell.Brittany.Internal.Layouters.Type
import qualified Language.Haskell.GHC.ExactPrint as ExactPrint
import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint
import Language.Haskell.Brittany.Internal.ExactPrintUtils
import Language.Haskell.Brittany.Internal.Utils
import GHC ( runGhc
, GenLocated(L)
, moduleNameString
, AnnKeywordId(..)
)
import SrcLoc ( SrcSpan, noSrcSpan, Located , getLoc, unLoc )
import qualified FastString
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
import GHC.Hs
import GHC.Hs.Extension (NoExtField (..))
#else
import HsSyn
import HsExtension (NoExt (..))
#endif
import Name
import BasicTypes ( InlinePragma(..)
, Activation(..)
, InlineSpec(..)
, RuleMatchInfo(..)
, LexicalFixity(..)
)
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.Layouters.DataDecl
import Bag ( mapBagM, bagToList, emptyBag )
import Data.Char (isUpper)
layoutDecl :: ToBriDoc HsDecl
layoutDecl :: ToBriDoc HsDecl
layoutDecl d :: Located (HsDecl GhcPs)
d@(L SrcSpan
loc HsDecl GhcPs
decl) = case HsDecl GhcPs
decl of
SigD XSigD GhcPs
_ Sig GhcPs
sig -> Located (HsDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall ast (w :: [*]) (s :: [*]) a.
Data ast =>
ast
-> MultiRWS '[Config, Anns] w s a -> MultiRWS '[Config, Anns] w s a
withTransformedAnns Located (HsDecl GhcPs)
d (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc Sig
layoutSig (SrcSpan -> Sig GhcPs -> GenLocated SrcSpan (Sig GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc Sig GhcPs
sig)
ValD XValD GhcPs
_ HsBind GhcPs
bind -> Located (HsDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall ast (w :: [*]) (s :: [*]) a.
Data ast =>
ast
-> MultiRWS '[Config, Anns] w s a -> MultiRWS '[Config, Anns] w s a
withTransformedAnns Located (HsDecl GhcPs)
d (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocC (HsBind GhcPs) (Either [BriDocNumbered] BriDocNumbered)
layoutBind (SrcSpan -> HsBind GhcPs -> GenLocated SrcSpan (HsBind GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc HsBind GhcPs
bind) MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
-> (Either [BriDocNumbered] BriDocNumbered
-> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left [BriDocNumbered]
ns -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
ns
Right BriDocNumbered
n -> BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
n
TyClD XTyClD GhcPs
_ TyClDecl GhcPs
tycl -> Located (HsDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall ast (w :: [*]) (s :: [*]) a.
Data ast =>
ast
-> MultiRWS '[Config, Anns] w s a -> MultiRWS '[Config, Anns] w s a
withTransformedAnns Located (HsDecl GhcPs)
d (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc TyClDecl
layoutTyCl (SrcSpan -> TyClDecl GhcPs -> GenLocated SrcSpan (TyClDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc TyClDecl GhcPs
tycl)
InstD XInstD GhcPs
_ (TyFamInstD XTyFamInstD GhcPs
_ TyFamInstDecl GhcPs
tfid) ->
Located (HsDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall ast (w :: [*]) (s :: [*]) a.
Data ast =>
ast
-> MultiRWS '[Config, Anns] w s a -> MultiRWS '[Config, Anns] w s a
withTransformedAnns Located (HsDecl GhcPs)
d (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Bool
-> Located (HsDecl GhcPs)
-> TyFamInstDecl GhcPs
-> ToBriDocM BriDocNumbered
forall a.
Data a =>
Bool
-> Located a -> TyFamInstDecl GhcPs -> ToBriDocM BriDocNumbered
layoutTyFamInstDecl Bool
False Located (HsDecl GhcPs)
d TyFamInstDecl GhcPs
tfid
InstD XInstD GhcPs
_ (ClsInstD XClsInstD GhcPs
_ ClsInstDecl GhcPs
inst) ->
Located (HsDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall ast (w :: [*]) (s :: [*]) a.
Data ast =>
ast
-> MultiRWS '[Config, Anns] w s a -> MultiRWS '[Config, Anns] w s a
withTransformedAnns Located (HsDecl GhcPs)
d (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDoc ClsInstDecl
layoutClsInst (SrcSpan
-> ClsInstDecl GhcPs -> GenLocated SrcSpan (ClsInstDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc ClsInstDecl GhcPs
inst)
HsDecl GhcPs
_ -> ToBriDoc HsDecl
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment Located (HsDecl GhcPs)
d
layoutSig :: ToBriDoc Sig
layoutSig :: ToBriDoc Sig
layoutSig lsig :: GenLocated SrcSpan (Sig GhcPs)
lsig@(L SrcSpan
_loc Sig GhcPs
sig) = case Sig GhcPs
sig of
TypeSig XTypeSig GhcPs
_ [Located (IdP GhcPs)]
names (HsWC XHsWC GhcPs (LHsSigType GhcPs)
_ (HsIB XHsIB GhcPs (LHsType GhcPs)
_ LHsType GhcPs
typ)) -> Maybe String
-> [Located RdrName] -> LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutNamesAndType Maybe String
forall a. Maybe a
Nothing [Located (IdP GhcPs)]
[Located RdrName]
names LHsType GhcPs
typ
InlineSig XInlineSig GhcPs
_ Located (IdP GhcPs)
name (InlinePragma SourceText
_ InlineSpec
spec Maybe Arity
_arity Activation
phaseAct RuleMatchInfo
conlike) ->
GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan (Sig GhcPs)
lsig (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 (IdP GhcPs)
Located RdrName
name
String
specStr <- GenLocated SrcSpan (Sig GhcPs)
-> InlineSpec
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
String
forall (m :: * -> *).
MonadMultiWriter [BrittanyError] m =>
GenLocated SrcSpan (Sig GhcPs) -> InlineSpec -> m String
specStringCompat GenLocated SrcSpan (Sig GhcPs)
lsig InlineSpec
spec
let phaseStr :: String
phaseStr = case Activation
phaseAct of
Activation
NeverActive -> String
""
Activation
AlwaysActive -> String
""
ActiveBefore SourceText
_ Arity
i -> String
"[~" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Arity -> String
forall a. Show a => a -> String
show Arity
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"] "
ActiveAfter SourceText
_ Arity
i -> String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Arity -> String
forall a. Show a => a -> String
show Arity
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"] "
let conlikeStr :: String
conlikeStr = case RuleMatchInfo
conlike of
RuleMatchInfo
FunLike -> String
""
RuleMatchInfo
ConLike -> String
"CONLIKE "
Text -> ToBriDocM BriDocNumbered
docLit
(Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack (String
"{-# " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
specStr String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
conlikeStr String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
phaseStr)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
nameStr
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
" #-}"
ClassOpSig XClassOpSig GhcPs
_ Bool
False [Located (IdP GhcPs)]
names (HsIB XHsIB GhcPs (LHsType GhcPs)
_ LHsType GhcPs
typ) -> Maybe String
-> [Located RdrName] -> LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutNamesAndType Maybe String
forall a. Maybe a
Nothing [Located (IdP GhcPs)]
[Located RdrName]
names LHsType GhcPs
typ
PatSynSig XPatSynSig GhcPs
_ [Located (IdP GhcPs)]
names (HsIB XHsIB GhcPs (LHsType GhcPs)
_ LHsType GhcPs
typ) -> Maybe String
-> [Located RdrName] -> LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutNamesAndType (String -> Maybe String
forall a. a -> Maybe a
Just String
"pattern") [Located (IdP GhcPs)]
[Located RdrName]
names LHsType GhcPs
typ
Sig GhcPs
_ -> ToBriDoc Sig
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment GenLocated SrcSpan (Sig GhcPs)
lsig
where
layoutNamesAndType :: Maybe String
-> [Located RdrName] -> LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutNamesAndType Maybe String
mKeyword [Located RdrName]
names LHsType GhcPs
typ = GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan (Sig GhcPs)
lsig (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
let keyDoc :: [ToBriDocM BriDocNumbered]
keyDoc = case Maybe String
mKeyword of
Just String
key -> [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (Text -> ToBriDocM BriDocNumbered)
-> Text
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
key]
Maybe String
Nothing -> []
[Text]
nameStrs <- [Located RdrName]
names [Located RdrName]
-> (Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn
let nameStr :: Text
nameStr = Text -> [Text] -> Text
Text.intercalate (String -> Text
Text.pack String
", ") ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ [Text]
nameStrs
ToBriDocM BriDocNumbered
typeDoc <- (LHsType GhcPs -> ToBriDocM BriDocNumbered)
-> LHsType 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 LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
typ
Bool
hasComments <- GenLocated SrcSpan (Sig GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow GenLocated SrcSpan (Sig GhcPs)
lsig
Bool
shouldBeHanging <- 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 -> Bool) -> ToBriDocM Bool
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 Bool))
-> Config
-> Identity (Last Bool)
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> CLayoutConfig Identity -> Identity (Last Bool)
forall (f :: * -> *). CLayoutConfig f -> f (Last Bool)
_lconfig_hangingTypeSignature
(Config -> Identity (Last Bool))
-> (Identity (Last Bool) -> Bool) -> Config -> Bool
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> Identity (Last Bool) -> Bool
forall a b. Coercible a b => Identity a -> b
confUnpack
if Bool
shouldBeHanging
then [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan (Sig GhcPs)
lsig (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]
keyDoc [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. Semigroup a => a -> a -> a
<> [Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr]
, 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
[ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColTyOpPrefix
[ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
":: "
, BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY (Arity -> BrIndent
BrIndentSpecial Arity
3) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
typeDoc
]
]
]
else Bool
-> ToBriDocM BriDocNumbered
-> String
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
layoutLhsAndType
Bool
hasComments
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan (Sig GhcPs)
lsig (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
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered]
keyDoc [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. Semigroup a => a -> a -> a
<> [Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr])
String
"::"
ToBriDocM BriDocNumbered
typeDoc
specStringCompat
:: MonadMultiWriter [BrittanyError] m => LSig GhcPs -> InlineSpec -> m String
specStringCompat :: GenLocated SrcSpan (Sig GhcPs) -> InlineSpec -> m String
specStringCompat GenLocated SrcSpan (Sig GhcPs)
ast = \case
InlineSpec
NoUserInline -> [BrittanyError] -> m ()
forall a (m :: * -> *). MonadMultiWriter a m => a -> m ()
mTell [String -> GenLocated SrcSpan (Sig GhcPs) -> BrittanyError
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> BrittanyError
ErrorUnknownNode String
"NoUserInline" GenLocated SrcSpan (Sig GhcPs)
ast] m () -> String -> m String
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> String
""
InlineSpec
Inline -> String -> m String
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"INLINE "
InlineSpec
Inlinable -> String -> m String
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"INLINABLE "
InlineSpec
NoInline -> String -> m String
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"NOINLINE "
layoutGuardLStmt :: ToBriDoc' (Stmt GhcPs (LHsExpr GhcPs))
layoutGuardLStmt :: ToBriDoc' (Stmt GhcPs (LHsExpr GhcPs))
layoutGuardLStmt lgstmt :: Located (Stmt GhcPs (LHsExpr GhcPs))
lgstmt@(L SrcSpan
_ Stmt GhcPs (LHsExpr GhcPs)
stmtLR) = Located (Stmt GhcPs (LHsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (Stmt GhcPs (LHsExpr GhcPs))
lgstmt (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case Stmt GhcPs (LHsExpr GhcPs)
stmtLR of
BodyStmt XBodyStmt GhcPs GhcPs (LHsExpr GhcPs)
_ LHsExpr GhcPs
body SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_ -> ToBriDoc HsExpr
layoutExpr LHsExpr GhcPs
body
BindStmt XBindStmt GhcPs GhcPs (LHsExpr GhcPs)
_ LPat GhcPs
lPat LHsExpr GhcPs
expr SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_ -> do
MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
patDoc <- (Located (Pat GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered))
-> Located (Pat GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered))
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper LPat GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
Located (Pat GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
layoutPat LPat GhcPs
Located (Pat GhcPs)
lPat
ToBriDocM BriDocNumbered
expDoc <- ToBriDoc HsExpr
-> LHsExpr 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 HsExpr
layoutExpr LHsExpr GhcPs
expr
ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColBindStmt
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Seq BriDocNumbered -> ToBriDocM BriDocNumbered
colsWrapPat (Seq BriDocNumbered -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
patDoc
, [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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"<-", ToBriDocM BriDocNumbered
expDoc]
]
Stmt GhcPs (LHsExpr GhcPs)
_ -> String -> ToBriDoc' (Stmt GhcPs (LHsExpr GhcPs))
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"" Located (Stmt GhcPs (LHsExpr GhcPs))
lgstmt
layoutBind
:: ToBriDocC
(HsBindLR GhcPs GhcPs)
(Either [BriDocNumbered] BriDocNumbered)
layoutBind :: ToBriDocC (HsBind GhcPs) (Either [BriDocNumbered] BriDocNumbered)
layoutBind lbind :: GenLocated SrcSpan (HsBind GhcPs)
lbind@(L SrcSpan
_ HsBind GhcPs
bind) = case HsBind GhcPs
bind of
FunBind XFunBind GhcPs GhcPs
_ Located (IdP GhcPs)
fId (MG XMG GhcPs (LHsExpr GhcPs)
_ lmatches :: Located [LMatch GhcPs (LHsExpr GhcPs)]
lmatches@(L SrcSpan
_ [LMatch GhcPs (LHsExpr GhcPs)]
matches) Origin
_) HsWrapper
_ [] -> do
Text
idStr <- 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
fId
BriDocNumbered
binderDoc <- Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"="
[BriDocNumbered]
funcPatDocs <-
GenLocated SrcSpan (HsBind GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan (HsBind GhcPs)
lbind
(MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ Located [LMatch GhcPs (LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located [LMatch GhcPs (LHsExpr GhcPs)]
lmatches
(MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ Maybe Text
-> BriDocNumbered
-> LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered
layoutPatternBind (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
idStr) BriDocNumbered
binderDoc
(LMatch GhcPs (LHsExpr GhcPs) -> ToBriDocM BriDocNumbered)
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [LMatch GhcPs (LHsExpr GhcPs)]
matches
Either [BriDocNumbered] BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [BriDocNumbered] BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered))
-> Either [BriDocNumbered] BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ [BriDocNumbered] -> Either [BriDocNumbered] BriDocNumbered
forall a b. a -> Either a b
Left ([BriDocNumbered] -> Either [BriDocNumbered] BriDocNumbered)
-> [BriDocNumbered] -> Either [BriDocNumbered] BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [BriDocNumbered]
funcPatDocs
PatBind XPatBind GhcPs GhcPs
_ LPat GhcPs
pat (GRHSs XCGRHSs GhcPs (LHsExpr GhcPs)
_ [LGRHS GhcPs (LHsExpr GhcPs)]
grhss LHsLocalBinds GhcPs
whereBinds) ([], []) -> do
BriDocNumbered
patDocs <- Seq BriDocNumbered -> ToBriDocM BriDocNumbered
colsWrapPat (Seq BriDocNumbered -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< LPat GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
layoutPat LPat GhcPs
pat
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs <- LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
layoutGrhs (LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs))
-> [LGRHS GhcPs (LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [LGRHS GhcPs (LHsExpr GhcPs)]
grhss
Maybe [BriDocNumbered]
mWhereDocs <- ToBriDocC (HsLocalBindsLR GhcPs GhcPs) (Maybe [BriDocNumbered])
layoutLocalBinds LHsLocalBinds GhcPs
whereBinds
let mWhereArg :: Maybe (AnnKey, [BriDocNumbered])
mWhereArg = Maybe [BriDocNumbered]
mWhereDocs Maybe [BriDocNumbered]
-> ([BriDocNumbered] -> (AnnKey, [BriDocNumbered]))
-> Maybe (AnnKey, [BriDocNumbered])
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \[BriDocNumbered]
d -> (GenLocated SrcSpan (HsBind GhcPs) -> AnnKey
forall a. Constraints a => a -> AnnKey
mkAnnKey GenLocated SrcSpan (HsBind GhcPs)
lbind, [BriDocNumbered]
d)
BriDocNumbered
binderDoc <- Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"="
Bool
hasComments <- GenLocated SrcSpan (HsBind GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow GenLocated SrcSpan (HsBind GhcPs)
lbind
(BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered
forall a b. b -> Either a b
Right (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpan (HsBind GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan (HsBind GhcPs)
lbind (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> Maybe (AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal Maybe Text
forall a. Maybe a
Nothing
BriDocNumbered
binderDoc
(BriDocNumbered -> Maybe BriDocNumbered
forall a. a -> Maybe a
Just BriDocNumbered
patDocs)
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
Maybe (AnnKey, [BriDocNumbered])
mWhereArg
Bool
hasComments
#if MIN_VERSION_ghc(8,8,0)
PatSynBind XPatSynBind GhcPs GhcPs
_ (PSB XPSB GhcPs GhcPs
_ Located (IdP GhcPs)
patID HsPatSynDetails (Located (IdP GhcPs))
lpat LPat GhcPs
rpat HsPatSynDir GhcPs
dir) -> do
#else
PatSynBind _ (PSB _ patID lpat rpat dir) -> do
#endif
(BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered
forall a b. b -> Either a b
Right (ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered))
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpan (HsBind GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan (HsBind GhcPs)
lbind (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> HsPatSynDir GhcPs
-> LPat GhcPs
-> ToBriDocM BriDocNumbered
layoutPatSynBind Located (IdP GhcPs)
patID
HsPatSynDetails (Located (IdP GhcPs))
lpat
HsPatSynDir GhcPs
dir
LPat GhcPs
rpat
HsBind GhcPs
_ -> BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered
forall a b. b -> Either a b
Right (BriDocNumbered -> Either [BriDocNumbered] BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String
-> GenLocated SrcSpan (HsBind GhcPs) -> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"" GenLocated SrcSpan (HsBind GhcPs)
lbind
layoutIPBind :: ToBriDoc IPBind
layoutIPBind :: ToBriDoc IPBind
layoutIPBind lipbind :: Located (IPBind GhcPs)
lipbind@(L SrcSpan
_ IPBind GhcPs
bind) = case IPBind GhcPs
bind of
XIPBind{} -> String -> ToBriDoc IPBind
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"XIPBind" Located (IPBind GhcPs)
lipbind
IPBind XCIPBind GhcPs
_ (Right IdP GhcPs
_) LHsExpr GhcPs
_ -> String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: IPBind Right"
IPBind XCIPBind GhcPs
_ (Left (L SrcSpan
_ (HsIPName FastString
name))) LHsExpr GhcPs
expr -> do
BriDocNumbered
ipName <- Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Char
'?' Char -> String -> String
forall a. a -> [a] -> [a]
: FastString -> String
FastString.unpackFS FastString
name
BriDocNumbered
binderDoc <- Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"="
BriDocNumbered
exprDoc <- ToBriDoc HsExpr
layoutExpr LHsExpr GhcPs
expr
Bool
hasComments <- Located (IPBind GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (IPBind GhcPs)
lipbind
Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> Maybe (AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal Maybe Text
forall a. Maybe a
Nothing BriDocNumbered
binderDoc (BriDocNumbered -> Maybe BriDocNumbered
forall a. a -> Maybe a
Just BriDocNumbered
ipName) [([], BriDocNumbered
exprDoc, LHsExpr GhcPs
expr)] Maybe (AnnKey, [BriDocNumbered])
forall a. Maybe a
Nothing Bool
hasComments
data BagBindOrSig = BagBind (LHsBindLR GhcPs GhcPs)
| BagSig (LSig GhcPs)
bindOrSigtoSrcSpan :: BagBindOrSig -> SrcSpan
bindOrSigtoSrcSpan :: BagBindOrSig -> SrcSpan
bindOrSigtoSrcSpan (BagBind (L SrcSpan
l HsBind GhcPs
_)) = SrcSpan
l
bindOrSigtoSrcSpan (BagSig (L SrcSpan
l Sig GhcPs
_)) = SrcSpan
l
layoutLocalBinds
:: ToBriDocC (HsLocalBindsLR GhcPs GhcPs) (Maybe [BriDocNumbered])
layoutLocalBinds :: ToBriDocC (HsLocalBindsLR GhcPs GhcPs) (Maybe [BriDocNumbered])
layoutLocalBinds lbinds :: LHsLocalBinds GhcPs
lbinds@(L SrcSpan
_ HsLocalBindsLR GhcPs GhcPs
binds) = case HsLocalBindsLR GhcPs GhcPs
binds of
HsValBinds XHsValBinds GhcPs GhcPs
_ (ValBinds XValBinds GhcPs GhcPs
_ LHsBindsLR GhcPs GhcPs
bindlrs [GenLocated SrcSpan (Sig GhcPs)]
sigs) -> do
let unordered :: [BagBindOrSig]
unordered =
[ GenLocated SrcSpan (HsBind GhcPs) -> BagBindOrSig
BagBind GenLocated SrcSpan (HsBind GhcPs)
b | GenLocated SrcSpan (HsBind GhcPs)
b <- LHsBindsLR GhcPs GhcPs -> [GenLocated SrcSpan (HsBind GhcPs)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Data.Foldable.toList LHsBindsLR GhcPs GhcPs
bindlrs ]
[BagBindOrSig] -> [BagBindOrSig] -> [BagBindOrSig]
forall a. [a] -> [a] -> [a]
++ [ GenLocated SrcSpan (Sig GhcPs) -> BagBindOrSig
BagSig GenLocated SrcSpan (Sig GhcPs)
s | GenLocated SrcSpan (Sig GhcPs)
s <- [GenLocated SrcSpan (Sig GhcPs)]
sigs ]
ordered :: [BagBindOrSig]
ordered = (BagBindOrSig -> BagBindOrSig -> Ordering)
-> [BagBindOrSig] -> [BagBindOrSig]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ((BagBindOrSig -> SrcSpan)
-> BagBindOrSig -> BagBindOrSig -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing BagBindOrSig -> SrcSpan
bindOrSigtoSrcSpan) [BagBindOrSig]
unordered
[BriDocNumbered]
docs <- LHsLocalBinds GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LHsLocalBinds GhcPs
lbinds (MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [[BriDocNumbered]] -> [BriDocNumbered]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([[BriDocNumbered]] -> [BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[[BriDocNumbered]]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BagBindOrSig]
ordered [BagBindOrSig]
-> (BagBindOrSig
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[[BriDocNumbered]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \case
BagBind GenLocated SrcSpan (HsBind GhcPs)
b -> ([BriDocNumbered] -> [BriDocNumbered])
-> (BriDocNumbered -> [BriDocNumbered])
-> Either [BriDocNumbered] BriDocNumbered
-> [BriDocNumbered]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [BriDocNumbered] -> [BriDocNumbered]
forall a. a -> a
id BriDocNumbered -> [BriDocNumbered]
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [BriDocNumbered] BriDocNumbered -> [BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDocC (HsBind GhcPs) (Either [BriDocNumbered] BriDocNumbered)
layoutBind GenLocated SrcSpan (HsBind GhcPs)
b
BagSig GenLocated SrcSpan (Sig GhcPs)
s -> BriDocNumbered -> [BriDocNumbered]
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> [BriDocNumbered])
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc Sig
layoutSig GenLocated SrcSpan (Sig GhcPs)
s
Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered])
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered]))
-> Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered])
forall a b. (a -> b) -> a -> b
$ [BriDocNumbered] -> Maybe [BriDocNumbered]
forall a. a -> Maybe a
Just ([BriDocNumbered] -> Maybe [BriDocNumbered])
-> [BriDocNumbered] -> Maybe [BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [BriDocNumbered]
docs
HsValBinds XHsValBinds GhcPs GhcPs
_ (XValBindsLR{}) -> String -> ToBriDocM (Maybe [BriDocNumbered])
forall a. HasCallStack => String -> a
error String
"brittany internal error: XValBindsLR"
XHsLocalBindsLR{} -> String -> ToBriDocM (Maybe [BriDocNumbered])
forall a. HasCallStack => String -> a
error String
"brittany internal error: XHsLocalBindsLR"
x :: HsLocalBindsLR GhcPs GhcPs
x@(HsIPBinds XHsIPBinds GhcPs GhcPs
_ XHsIPBinds{}) ->
[BriDocNumbered] -> Maybe [BriDocNumbered]
forall a. a -> Maybe a
Just ([BriDocNumbered] -> Maybe [BriDocNumbered])
-> (BriDocNumbered -> [BriDocNumbered])
-> BriDocNumbered
-> Maybe [BriDocNumbered]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BriDocNumbered -> [BriDocNumbered] -> [BriDocNumbered]
forall a. a -> [a] -> [a]
: []) (BriDocNumbered -> Maybe [BriDocNumbered])
-> ToBriDocM BriDocNumbered -> ToBriDocM (Maybe [BriDocNumbered])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> LHsLocalBinds GhcPs -> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"XHsIPBinds" (SrcSpan -> HsLocalBindsLR GhcPs GhcPs -> LHsLocalBinds GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
noSrcSpan HsLocalBindsLR GhcPs GhcPs
x)
HsIPBinds XHsIPBinds GhcPs GhcPs
_ (IPBinds XIPBinds GhcPs
_ [Located (IPBind GhcPs)]
bb) ->
[BriDocNumbered] -> Maybe [BriDocNumbered]
forall a. a -> Maybe a
Just ([BriDocNumbered] -> Maybe [BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> ToBriDocM (Maybe [BriDocNumbered])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc IPBind
-> [Located (IPBind GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ToBriDoc IPBind
layoutIPBind [Located (IPBind GhcPs)]
bb
EmptyLocalBinds{} -> Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered])
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered]))
-> Maybe [BriDocNumbered] -> ToBriDocM (Maybe [BriDocNumbered])
forall a b. (a -> b) -> a -> b
$ Maybe [BriDocNumbered]
forall a. Maybe a
Nothing
layoutGrhs
:: LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
layoutGrhs :: LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
layoutGrhs lgrhs :: LGRHS GhcPs (LHsExpr GhcPs)
lgrhs@(L SrcSpan
_ (GRHS XCGRHS GhcPs (LHsExpr GhcPs)
_ [Located (Stmt GhcPs (LHsExpr GhcPs))]
guards LHsExpr GhcPs
body)) = do
[BriDocNumbered]
guardDocs <- LGRHS GhcPs (LHsExpr GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LGRHS GhcPs (LHsExpr GhcPs)
lgrhs (MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ ToBriDoc' (Stmt GhcPs (LHsExpr GhcPs))
layoutStmt ToBriDoc' (Stmt GhcPs (LHsExpr GhcPs))
-> [Located (Stmt GhcPs (LHsExpr GhcPs))]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [Located (Stmt GhcPs (LHsExpr GhcPs))]
guards
BriDocNumbered
bodyDoc <- ToBriDoc HsExpr
layoutExpr LHsExpr GhcPs
body
([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
forall (m :: * -> *) a. Monad m => a -> m a
return ([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
body)
layoutGrhs (L SrcSpan
_ (XGRHS{})) = String
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
forall a. HasCallStack => String -> a
error String
"brittany internal error: XGRHS"
layoutPatternBind
:: Maybe Text
-> BriDocNumbered
-> LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered
layoutPatternBind :: Maybe Text
-> BriDocNumbered
-> LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered
layoutPatternBind Maybe Text
funId BriDocNumbered
binderDoc lmatch :: LMatch GhcPs (LHsExpr GhcPs)
lmatch@(L SrcSpan
_ Match GhcPs (LHsExpr GhcPs)
match) = do
let pats :: [LPat GhcPs]
pats = Match GhcPs (LHsExpr GhcPs) -> [LPat GhcPs]
forall p body. Match p body -> [LPat p]
m_pats Match GhcPs (LHsExpr GhcPs)
match
let (GRHSs XCGRHSs GhcPs (LHsExpr GhcPs)
_ [LGRHS GhcPs (LHsExpr GhcPs)]
grhss LHsLocalBinds GhcPs
whereBinds) = Match GhcPs (LHsExpr GhcPs) -> GRHSs GhcPs (LHsExpr GhcPs)
forall p body. Match p body -> GRHSs p body
m_grhss Match GhcPs (LHsExpr GhcPs)
match
[ToBriDocM BriDocNumbered]
patDocs <- [LPat GhcPs]
[Located (Pat GhcPs)]
pats [Located (Pat GhcPs)]
-> (Located (Pat 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` \Located (Pat GhcPs)
p -> (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
$ Seq BriDocNumbered -> ToBriDocM BriDocNumbered
colsWrapPat (Seq BriDocNumbered -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< LPat GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
layoutPat LPat GhcPs
Located (Pat GhcPs)
p
let isInfix :: Bool
isInfix = Match GhcPs (LHsExpr GhcPs) -> Bool
forall id body. Match id body -> Bool
isInfixMatch Match GhcPs (LHsExpr GhcPs)
match
Maybe Text
mIdStr <- case Match GhcPs (LHsExpr GhcPs)
match of
Match XCMatch GhcPs (LHsExpr GhcPs)
_ (FunRhs Located (NameOrRdrName (IdP GhcPs))
matchId LexicalFixity
_ SrcStrictness
_) [LPat GhcPs]
_ GRHSs GhcPs (LHsExpr GhcPs)
_ -> Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f 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 (NameOrRdrName (IdP GhcPs))
Located RdrName
matchId
Match GhcPs (LHsExpr GhcPs)
_ -> Maybe Text
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Maybe Text)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Text
forall a. Maybe a
Nothing
let mIdStr' :: Maybe Text
mIdStr' = Match GhcPs (LHsExpr GhcPs) -> Text -> Text
fixPatternBindIdentifier Match GhcPs (LHsExpr GhcPs)
match (Text -> Text) -> Maybe Text -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
mIdStr
BriDocNumbered
patDoc <- LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior LMatch GhcPs (LHsExpr GhcPs)
lmatch (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case (Maybe Text
mIdStr', [ToBriDocM BriDocNumbered]
patDocs) of
(Just Text
idStr, ToBriDocM BriDocNumbered
p1:ToBriDocM BriDocNumbered
p2:[ToBriDocM BriDocNumbered]
pr) | Bool
isInfix -> if [ToBriDocM BriDocNumbered] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ToBriDocM BriDocNumbered]
pr
then
ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColPatternsFuncInfix
[ 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
p1
, 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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text
idStr
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
p2
]
else
ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColPatternsFuncInfix
( [ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColPatterns
[ ToBriDocM BriDocNumbered
docParenL
, 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
p1
, 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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text
idStr
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
p2
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
docParenR
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
spacifyDocs ([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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ToBriDocM BriDocNumbered]
pr)
)
(Just Text
idStr, []) -> Text -> ToBriDocM BriDocNumbered
docLit Text
idStr
(Just Text
idStr, [ToBriDocM BriDocNumbered]
ps) ->
ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColPatternsFuncPrefix
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text
idStr)
ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
: ([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
spacifyDocs ([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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ToBriDocM BriDocNumbered]
ps)
(Maybe Text
Nothing, [ToBriDocM BriDocNumbered]
ps) ->
ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColPatterns
([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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ToBriDocM BriDocNumbered]
ps)
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs <- LMatch GhcPs (LHsExpr GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest LMatch GhcPs (LHsExpr GhcPs)
lmatch (MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
forall a b. (a -> b) -> a -> b
$ LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
layoutGrhs (LGRHS GhcPs (LHsExpr GhcPs)
-> ToBriDocM ([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs))
-> [LGRHS GhcPs (LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
`mapM` [LGRHS GhcPs (LHsExpr GhcPs)]
grhss
Maybe [BriDocNumbered]
mWhereDocs <- ToBriDocC (HsLocalBindsLR GhcPs GhcPs) (Maybe [BriDocNumbered])
layoutLocalBinds LHsLocalBinds GhcPs
whereBinds
let mWhereArg :: Maybe (AnnKey, [BriDocNumbered])
mWhereArg = Maybe [BriDocNumbered]
mWhereDocs Maybe [BriDocNumbered]
-> ([BriDocNumbered] -> (AnnKey, [BriDocNumbered]))
-> Maybe (AnnKey, [BriDocNumbered])
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \[BriDocNumbered]
d -> (LMatch GhcPs (LHsExpr GhcPs) -> AnnKey
forall a. Constraints a => a -> AnnKey
mkAnnKey LMatch GhcPs (LHsExpr GhcPs)
lmatch, [BriDocNumbered]
d)
let alignmentToken :: Maybe Text
alignmentToken = if [Located (Pat GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LPat GhcPs]
[Located (Pat GhcPs)]
pats then Maybe Text
forall a. Maybe a
Nothing else Maybe Text
funId
Bool
hasComments <- LMatch GhcPs (LHsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow LMatch GhcPs (LHsExpr GhcPs)
lmatch
Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> Maybe (AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal Maybe Text
alignmentToken
BriDocNumbered
binderDoc
(BriDocNumbered -> Maybe BriDocNumbered
forall a. a -> Maybe a
Just BriDocNumbered
patDoc)
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
Maybe (AnnKey, [BriDocNumbered])
mWhereArg
Bool
hasComments
fixPatternBindIdentifier
:: Match GhcPs (LHsExpr GhcPs) -> Text -> Text
fixPatternBindIdentifier :: Match GhcPs (LHsExpr GhcPs) -> Text -> Text
fixPatternBindIdentifier Match GhcPs (LHsExpr GhcPs)
match Text
idStr = HsMatchContext RdrName -> Text
go (HsMatchContext RdrName -> Text) -> HsMatchContext RdrName -> Text
forall a b. (a -> b) -> a -> b
$ Match GhcPs (LHsExpr GhcPs)
-> HsMatchContext (NameOrRdrName (IdP GhcPs))
forall p body.
Match p body -> HsMatchContext (NameOrRdrName (IdP p))
m_ctxt Match GhcPs (LHsExpr GhcPs)
match
where
go :: HsMatchContext RdrName -> Text
go = \case
(FunRhs Located RdrName
_ LexicalFixity
_ SrcStrictness
SrcLazy ) -> Char -> Text -> Text
Text.cons Char
'~' Text
idStr
(FunRhs Located RdrName
_ LexicalFixity
_ SrcStrictness
SrcStrict ) -> Char -> Text -> Text
Text.cons Char
'!' Text
idStr
(FunRhs Located RdrName
_ LexicalFixity
_ SrcStrictness
NoSrcStrict) -> Text
idStr
(StmtCtxt HsStmtContext RdrName
ctx1 ) -> HsStmtContext RdrName -> Text
goInner HsStmtContext RdrName
ctx1
HsMatchContext RdrName
_ -> Text
idStr
goInner :: HsStmtContext RdrName -> Text
goInner = \case
(PatGuard HsMatchContext RdrName
ctx1) -> HsMatchContext RdrName -> Text
go HsMatchContext RdrName
ctx1
(ParStmtCtxt HsStmtContext RdrName
ctx1) -> HsStmtContext RdrName -> Text
goInner HsStmtContext RdrName
ctx1
(TransStmtCtxt HsStmtContext RdrName
ctx1) -> HsStmtContext RdrName -> Text
goInner HsStmtContext RdrName
ctx1
HsStmtContext RdrName
_ -> Text
idStr
layoutPatternBindFinal
:: Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> Maybe (ExactPrint.AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal :: Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> Maybe (AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal Maybe Text
alignmentToken BriDocNumbered
binderDoc Maybe BriDocNumbered
mPatDoc [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs Maybe (AnnKey, [BriDocNumbered])
mWhereDocs Bool
hasComments = do
let patPartInline :: [ToBriDocM BriDocNumbered]
patPartInline = case Maybe BriDocNumbered
mPatDoc of
Maybe BriDocNumbered
Nothing -> []
Just BriDocNumbered
patDoc -> [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 -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
patDoc]
patPartParWrap :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
patPartParWrap = case Maybe BriDocNumbered
mPatDoc of
Maybe BriDocNumbered
Nothing -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a. a -> a
id
Just BriDocNumbered
patDoc -> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
patDoc)
BrIndent
whereIndent <- do
Bool
shouldSpecial <- 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 -> Bool) -> ToBriDocM Bool
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 Bool))
-> Config
-> Identity (Last Bool)
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> CLayoutConfig Identity -> Identity (Last Bool)
forall (f :: * -> *). CLayoutConfig f -> f (Last Bool)
_lconfig_indentWhereSpecial
(Config -> Identity (Last Bool))
-> (Identity (Last Bool) -> Bool) -> Config -> Bool
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> Identity (Last Bool) -> Bool
forall a b. Coercible a b => Identity a -> b
confUnpack
Arity
regularIndentAmount <- 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 -> Arity)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Arity
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 Arity))
-> Config
-> Identity (Last Arity)
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> CLayoutConfig Identity -> Identity (Last Arity)
forall (f :: * -> *). CLayoutConfig f -> f (Last Arity)
_lconfig_indentAmount
(Config -> Identity (Last Arity))
-> (Identity (Last Arity) -> Arity) -> Config -> Arity
forall a b c. (a -> b) -> (b -> c) -> a -> c
.> Identity (Last Arity) -> Arity
forall a b. Coercible a b => Identity a -> b
confUnpack
BrIndent
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
BrIndent
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BrIndent
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
BrIndent)
-> BrIndent
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
BrIndent
forall a b. (a -> b) -> a -> b
$ if Bool
shouldSpecial
then Arity -> BrIndent
BrIndentSpecial (Arity -> Arity -> Arity
forall a. Ord a => a -> a -> a
max Arity
1 (Arity
regularIndentAmount Arity -> Arity -> Arity
forall a. Integral a => a -> a -> a
`div` Arity
2))
else BrIndent
BrIndentRegular
[ToBriDocM BriDocNumbered]
wherePartMultiLine :: [ToBriDocM BriDocNumbered] <- case Maybe (AnnKey, [BriDocNumbered])
mWhereDocs of
Maybe (AnnKey, [BriDocNumbered])
Nothing -> [ToBriDocM BriDocNumbered]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[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
$ []
Just (AnnKey
annKeyWhere, [BriDocNumbered
w]) -> (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 (ToBriDocM BriDocNumbered -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ToBriDocM BriDocNumbered -> [ToBriDocM BriDocNumbered])
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> BriDocNumbered
-> [ToBriDocM BriDocNumbered]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
docAlt
[ 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
docSeq
[ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"where"
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
w
]
, AnnKey
-> AnnKeywordId
-> Bool
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docMoveToKWDP AnnKey
annKeyWhere AnnKeywordId
AnnWhere Bool
False
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docEnsureIndent BrIndent
whereIndent
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"where"
, BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docEnsureIndent BrIndent
whereIndent
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> 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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
w
]
]
Just (AnnKey
annKeyWhere, [BriDocNumbered]
ws) ->
(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 (ToBriDocM BriDocNumbered -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ToBriDocM BriDocNumbered -> [ToBriDocM BriDocNumbered])
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> BriDocNumbered
-> [ToBriDocM BriDocNumbered]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
$ AnnKey
-> AnnKeywordId
-> Bool
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docMoveToKWDP AnnKey
annKeyWhere AnnKeywordId
AnnWhere Bool
False
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docEnsureIndent BrIndent
whereIndent
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"where"
, BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docEnsureIndent BrIndent
whereIndent
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> 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
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return
(BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
ws
]
let singleLineGuardsDoc :: [BriDocNumbered] -> ToBriDocM BriDocNumbered
singleLineGuardsDoc [BriDocNumbered]
guards = ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case [BriDocNumbered]
guards of
[] -> ToBriDocM BriDocNumbered
docEmpty
[BriDocNumbered
g] -> [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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|", ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g]
[BriDocNumbered]
gs -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|"]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ (ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> BriDocNumbered
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
gs)
)
wherePart :: Maybe (ToBriDocM BriDocNumbered)
wherePart = case Maybe (AnnKey, [BriDocNumbered])
mWhereDocs of
Maybe (AnnKey, [BriDocNumbered])
Nothing -> ToBriDocM BriDocNumbered -> Maybe (ToBriDocM BriDocNumbered)
forall a. a -> Maybe a
Just ToBriDocM BriDocNumbered
docEmpty
Just (AnnKey
_, [BriDocNumbered
w]) -> 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
[ ToBriDocM BriDocNumbered
docSeparator
, 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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"where"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel (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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
w
]
Maybe (AnnKey, [BriDocNumbered])
_ -> Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
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
CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
case [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs of
[([BriDocNumbered]
guards, BriDocNumbered
body, LHsExpr GhcPs
_bodyRaw)] -> do
let guardPart :: ToBriDocM BriDocNumbered
guardPart = [BriDocNumbered] -> ToBriDocM BriDocNumbered
singleLineGuardsDoc [BriDocNumbered]
guards
Maybe (ToBriDocM BriDocNumbered)
-> (ToBriDocM BriDocNumbered -> CollectAltM ()) -> CollectAltM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (ToBriDocM BriDocNumbered)
wherePart ((ToBriDocM BriDocNumbered -> CollectAltM ()) -> CollectAltM ())
-> (ToBriDocM BriDocNumbered -> CollectAltM ()) -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ \ToBriDocM BriDocNumbered
wherePart' ->
Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond (Bool -> Bool
not Bool
hasComments) (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
(Maybe Text -> ColSig
ColBindingLine Maybe Text
alignmentToken)
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered]
patPartInline [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
guardPart])
, [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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
body
, ToBriDocM BriDocNumbered
wherePart'
]
]
Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond (Maybe (AnnKey, [BriDocNumbered]) -> Bool
forall a. Maybe a -> Bool
Data.Maybe.isJust Maybe (AnnKey, [BriDocNumbered])
mWhereDocs)
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
(Maybe Text -> ColSig
ColBindingLine Maybe Text
alignmentToken)
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered]
patPartInline [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
guardPart])
, [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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing (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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
body
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
docForceSingleline
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered]
patPartInline [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
guardPart, BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc])
, 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
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
body
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
(Maybe Text -> ColSig
ColBindingLine Maybe Text
alignmentToken)
[ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered]
patPartInline [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
guardPart])
, [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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing (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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
body
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
docSeq ([ToBriDocM BriDocNumbered]
patPartInline [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
guardPart, BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc])
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docNonBottomSpacing
(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
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
body
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
_ -> () -> CollectAltM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
case Maybe BriDocNumbered
mPatDoc of
Maybe BriDocNumbered
Nothing -> () -> CollectAltM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just BriDocNumbered
patDoc ->
Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond (IndentPolicy
indentPolicy IndentPolicy -> IndentPolicy -> Bool
forall a. Eq a => a -> a -> Bool
== IndentPolicy
IndentPolicyFree)
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
docSeq
[ 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 -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
patDoc
, 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
$ [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> (([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
_) -> do
let guardPart :: ToBriDocM BriDocNumbered
guardPart = [BriDocNumbered] -> ToBriDocM BriDocNumbered
singleLineGuardsDoc [BriDocNumbered]
guardDocs
ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColGuardedBody
[ ToBriDocM BriDocNumbered
guardPart
, [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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
bodyDoc
]
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ 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
patPartParWrap
(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)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> [a] -> [b]
map ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> (([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
_) -> do
let guardPart :: ToBriDocM BriDocNumbered
guardPart = [BriDocNumbered] -> ToBriDocM BriDocNumbered
singleLineGuardsDoc [BriDocNumbered]
guardDocs
ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColGuardedBody
[ ToBriDocM BriDocNumbered
guardPart
, [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
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
bodyDoc
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ 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
patPartParWrap
(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)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> [a] -> [b]
map ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> (([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
_) ->
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ( case [BriDocNumbered]
guardDocs of
[] -> []
[BriDocNumbered
g] ->
[ 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|", BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g]
]
[BriDocNumbered]
gs ->
[ 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|"]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep (BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
gs)
]
)
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ToBriDocM BriDocNumbered
docSeparator
, ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColOpPrefix
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, 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
docForceParSpacing
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
bodyDoc
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ 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
patPartParWrap
(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)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> [a] -> [b]
map ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> (([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
_) ->
( case [BriDocNumbered]
guardDocs of
[] -> []
[BriDocNumbered
g] ->
[ 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|", BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g]
]
[BriDocNumbered]
gs ->
[ 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|"]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep (BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
gs)
]
)
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColOpPrefix
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, 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
docForceParSpacing
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
bodyDoc
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
(ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
$ [ 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
patPartParWrap
(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)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> [a] -> [b]
map ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY
([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
clauseDocs
[([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)]
-> (([BriDocNumbered], BriDocNumbered, LHsExpr GhcPs)
-> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([BriDocNumbered]
guardDocs, BriDocNumbered
bodyDoc, LHsExpr GhcPs
_) ->
( case [BriDocNumbered]
guardDocs of
[] -> []
[BriDocNumbered
g] ->
[[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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|", BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g]]
(BriDocNumbered
g1:[BriDocNumbered]
gr) ->
( [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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"|", BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g1]
ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
: ( [BriDocNumbered]
gr
[BriDocNumbered]
-> (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \BriDocNumbered
g ->
[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 -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
",", BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
g]
)
)
)
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColOpPrefix
[ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
binderDoc
, BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
bodyDoc
]
]
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
wherePartMultiLine
layoutPatSynBind
:: Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> HsPatSynDir GhcPs
-> LPat GhcPs
-> ToBriDocM BriDocNumbered
layoutPatSynBind :: Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> HsPatSynDir GhcPs
-> LPat GhcPs
-> ToBriDocM BriDocNumbered
layoutPatSynBind Located (IdP GhcPs)
name HsPatSynDetails (Located (IdP GhcPs))
patSynDetails HsPatSynDir GhcPs
patDir LPat GhcPs
rpat = do
let patDoc :: ToBriDocM BriDocNumbered
patDoc = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"pattern"
binderDoc :: ToBriDocM BriDocNumbered
binderDoc = case HsPatSynDir GhcPs
patDir of
HsPatSynDir GhcPs
ImplicitBidirectional -> Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"="
HsPatSynDir GhcPs
_ -> Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"<-"
body :: ToBriDocM BriDocNumbered
body = Seq BriDocNumbered -> ToBriDocM BriDocNumbered
colsWrapPat (Seq BriDocNumbered -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< LPat GhcPs
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Seq BriDocNumbered)
layoutPat LPat GhcPs
rpat
whereDoc :: ToBriDocM BriDocNumbered
whereDoc = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"where"
Maybe [ToBriDocM BriDocNumbered]
mWhereDocs <- HsPatSynDir GhcPs -> ToBriDocM (Maybe [ToBriDocM BriDocNumbered])
layoutPatSynWhere HsPatSynDir GhcPs
patDir
ToBriDocM BriDocNumbered
headDoc <- (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
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$
[ ToBriDocM BriDocNumbered
patDoc
, ToBriDocM BriDocNumbered
docSeparator
, Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> ToBriDocM BriDocNumbered
layoutLPatSyn Located (IdP GhcPs)
name HsPatSynDetails (Located (IdP GhcPs))
patSynDetails
, ToBriDocM BriDocNumbered
docSeparator
, ToBriDocM BriDocNumbered
binderDoc
]
CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
docSeq
( [ToBriDocM BriDocNumbered
headDoc, ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
body]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ case Maybe [ToBriDocM BriDocNumbered]
mWhereDocs of
Just [ToBriDocM BriDocNumbered]
ds -> [ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar ToBriDocM BriDocNumbered
whereDoc ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered]
ds)]
Maybe [ToBriDocM BriDocNumbered]
Nothing -> []
)
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
headDoc
(case Maybe [ToBriDocM BriDocNumbered]
mWhereDocs of
Maybe [ToBriDocM BriDocNumbered]
Nothing -> ToBriDocM BriDocNumbered
body
Just [ToBriDocM BriDocNumbered]
ds -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
body, ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
whereDoc] ] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
ds)
)
layoutLPatSyn
:: Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> ToBriDocM BriDocNumbered
layoutLPatSyn :: Located (IdP GhcPs)
-> HsPatSynDetails (Located (IdP GhcPs))
-> ToBriDocM BriDocNumbered
layoutLPatSyn Located (IdP GhcPs)
name (PrefixCon [Located (IdP GhcPs)]
vars) = do
Text
docName <- 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
name
[Text]
names <- (Located RdrName
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text)
-> [Located RdrName]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM 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]
vars
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([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] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap 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
docName ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
: (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> [Text] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
names)
layoutLPatSyn Located (IdP GhcPs)
name (InfixCon Located (IdP GhcPs)
left Located (IdP GhcPs)
right) = do
Text
leftDoc <- 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
left
Text
docName <- 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
name
Text
rightDoc <- 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
right
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> ([Text] -> [ToBriDocM BriDocNumbered])
-> [Text]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> ToBriDocM BriDocNumbered)
-> [Text] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (Text -> ToBriDocM BriDocNumbered)
-> Text
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ToBriDocM BriDocNumbered
docLit) ([Text] -> ToBriDocM BriDocNumbered)
-> [Text] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [Text
leftDoc, Text
docName, Text
rightDoc]
layoutLPatSyn Located (IdP GhcPs)
name (RecCon [RecordPatSynField (Located (IdP GhcPs))]
recArgs) = do
Text
docName <- 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
name
[Text]
args <- (RecordPatSynField (Located RdrName)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text)
-> [RecordPatSynField (Located RdrName)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (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
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text)
-> (RecordPatSynField (Located RdrName) -> Located RdrName)
-> RecordPatSynField (Located RdrName)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RecordPatSynField (Located RdrName) -> Located RdrName
forall a. RecordPatSynField a -> a
recordPatSynSelectorId) [RecordPatSynField (Located (IdP GhcPs))]
[RecordPatSynField (Located RdrName)]
recArgs
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> ([Text] -> [ToBriDocM BriDocNumbered])
-> [Text]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> ToBriDocM BriDocNumbered)
-> [Text] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> ToBriDocM BriDocNumbered
docLit
([Text] -> ToBriDocM BriDocNumbered)
-> [Text] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [Text
docName, String -> Text
Text.pack String
" { " ]
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
intersperse (String -> Text
Text.pack String
", ") [Text]
args
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [String -> Text
Text.pack String
" }"]
layoutPatSynWhere :: HsPatSynDir GhcPs -> ToBriDocM (Maybe [ToBriDocM BriDocNumbered])
layoutPatSynWhere :: HsPatSynDir GhcPs -> ToBriDocM (Maybe [ToBriDocM BriDocNumbered])
layoutPatSynWhere HsPatSynDir GhcPs
hs = case HsPatSynDir GhcPs
hs of
ExplicitBidirectional (MG XMG GhcPs (LHsExpr GhcPs)
_ (L SrcSpan
_ [LMatch GhcPs (LHsExpr GhcPs)]
lbinds) Origin
_) -> do
BriDocNumbered
binderDoc <- Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"="
[ToBriDocM BriDocNumbered] -> Maybe [ToBriDocM BriDocNumbered]
forall a. a -> Maybe a
Just ([ToBriDocM BriDocNumbered] -> Maybe [ToBriDocM BriDocNumbered])
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[ToBriDocM BriDocNumbered]
-> ToBriDocM (Maybe [ToBriDocM BriDocNumbered])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LMatch GhcPs (LHsExpr GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[ToBriDocM BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((LMatch GhcPs (LHsExpr GhcPs) -> ToBriDocM BriDocNumbered)
-> LMatch GhcPs (LHsExpr 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 ((LMatch GhcPs (LHsExpr GhcPs) -> ToBriDocM BriDocNumbered)
-> LMatch GhcPs (LHsExpr GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered))
-> (LMatch GhcPs (LHsExpr GhcPs) -> ToBriDocM BriDocNumbered)
-> LMatch GhcPs (LHsExpr GhcPs)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ Maybe Text
-> BriDocNumbered
-> LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered
layoutPatternBind Maybe Text
forall a. Maybe a
Nothing BriDocNumbered
binderDoc) [LMatch GhcPs (LHsExpr GhcPs)]
lbinds
HsPatSynDir GhcPs
_ -> Maybe [ToBriDocM BriDocNumbered]
-> ToBriDocM (Maybe [ToBriDocM BriDocNumbered])
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [ToBriDocM BriDocNumbered]
forall a. Maybe a
Nothing
layoutTyCl :: ToBriDoc TyClDecl
layoutTyCl :: ToBriDoc TyClDecl
layoutTyCl ltycl :: GenLocated SrcSpan (TyClDecl GhcPs)
ltycl@(L SrcSpan
_loc TyClDecl GhcPs
tycl) = case TyClDecl GhcPs
tycl of
SynDecl XSynDecl GhcPs
_ Located (IdP GhcPs)
name LHsQTyVars GhcPs
vars LexicalFixity
fixity LHsType GhcPs
typ -> do
let isInfix :: Bool
isInfix = case LexicalFixity
fixity of
LexicalFixity
Prefix -> Bool
False
LexicalFixity
Infix -> Bool
True
let wrapNodeRest :: ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
wrapNodeRest = GenLocated SrcSpan (TyClDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan (TyClDecl GhcPs)
ltycl
GenLocated SrcSpan (TyClDecl GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior GenLocated SrcSpan (TyClDecl GhcPs)
ltycl
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Bool
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> Located (IdP GhcPs)
-> [LHsTyVarBndr GhcPs]
-> LHsType GhcPs
-> ToBriDocM BriDocNumbered
layoutSynDecl Bool
isInfix ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
wrapNodeRest Located (IdP GhcPs)
name (LHsQTyVars GhcPs -> [LHsTyVarBndr GhcPs]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr pass]
hsq_explicit LHsQTyVars GhcPs
vars) LHsType GhcPs
typ
DataDecl XDataDecl GhcPs
_ext Located (IdP GhcPs)
name LHsQTyVars GhcPs
tyVars LexicalFixity
_ HsDataDefn GhcPs
dataDefn ->
GenLocated SrcSpan (TyClDecl GhcPs)
-> Located RdrName
-> LHsQTyVars GhcPs
-> HsDataDefn GhcPs
-> ToBriDocM BriDocNumbered
layoutDataDecl GenLocated SrcSpan (TyClDecl GhcPs)
ltycl Located (IdP GhcPs)
Located RdrName
name LHsQTyVars GhcPs
tyVars HsDataDefn GhcPs
dataDefn
TyClDecl GhcPs
_ -> ToBriDoc TyClDecl
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment GenLocated SrcSpan (TyClDecl GhcPs)
ltycl
layoutSynDecl
:: Bool
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> Located (IdP GhcPs)
-> [LHsTyVarBndr GhcPs]
-> LHsType GhcPs
-> ToBriDocM BriDocNumbered
layoutSynDecl :: Bool
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> Located (IdP GhcPs)
-> [LHsTyVarBndr GhcPs]
-> LHsType GhcPs
-> ToBriDocM BriDocNumbered
layoutSynDecl Bool
isInfix ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
wrapNodeRest Located (IdP GhcPs)
name [LHsTyVarBndr GhcPs]
vars LHsType GhcPs
typ = 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 (IdP GhcPs)
Located RdrName
name
let
lhs :: ToBriDocM BriDocNumbered
lhs = ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (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
wrapNodeRest (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ if Bool
isInfix
then do
let (LHsTyVarBndr GhcPs
a : LHsTyVarBndr GhcPs
b : [LHsTyVarBndr GhcPs]
rest) = [LHsTyVarBndr GhcPs]
vars
Bool
hasOwnParens <- LHsTyVarBndr GhcPs -> AnnKeywordId -> ToBriDocM Bool
forall ast.
Data ast =>
Located ast -> AnnKeywordId -> ToBriDocM Bool
hasAnnKeywordComment LHsTyVarBndr GhcPs
a AnnKeywordId
AnnOpenP
let needsParens :: Bool
needsParens = Bool -> Bool
not ([LHsTyVarBndr GhcPs] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LHsTyVarBndr GhcPs]
rest) Bool -> Bool -> Bool
|| Bool
hasOwnParens
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"type"
, ToBriDocM BriDocNumbered
docSeparator
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ToBriDocM BriDocNumbered
docParenL | Bool
needsParens ]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr Bool
False LHsTyVarBndr GhcPs
a
, ToBriDocM BriDocNumbered
docSeparator
, Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr
, ToBriDocM BriDocNumbered
docSeparator
, Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr Bool
False LHsTyVarBndr GhcPs
b
]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ToBriDocM BriDocNumbered
docParenR | Bool
needsParens ]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ToBriDoc HsTyVarBndr
-> [LHsTyVarBndr GhcPs] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr Bool
True) [LHsTyVarBndr GhcPs]
rest
else
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"type"
, ToBriDocM BriDocNumbered
docSeparator
, Located RdrName
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (IdP GhcPs)
Located RdrName
name (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] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ToBriDoc HsTyVarBndr
-> [LHsTyVarBndr GhcPs] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr Bool
True) [LHsTyVarBndr GhcPs]
vars
ToBriDocM BriDocNumbered
sharedLhs <- (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(ToBriDocM BriDocNumbered)
forall (m :: * -> *) x y. Monad m => (x -> m y) -> x -> m (m y)
docSharedWrapper ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a. a -> a
id ToBriDocM BriDocNumbered
lhs
ToBriDocM BriDocNumbered
typeDoc <- (LHsType GhcPs -> ToBriDocM BriDocNumbered)
-> LHsType 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 LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
typ
Bool
hasComments <- LHsType GhcPs -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsConnected LHsType GhcPs
typ
Bool
-> ToBriDocM BriDocNumbered
-> String
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
layoutLhsAndType Bool
hasComments ToBriDocM BriDocNumbered
sharedLhs String
"=" ToBriDocM BriDocNumbered
typeDoc
layoutTyVarBndr :: Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr :: Bool -> ToBriDoc HsTyVarBndr
layoutTyVarBndr Bool
needsSep lbndr :: LHsTyVarBndr GhcPs
lbndr@(L SrcSpan
_ HsTyVarBndr GhcPs
bndr) = do
LHsTyVarBndr GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior LHsTyVarBndr GhcPs
lbndr (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case HsTyVarBndr GhcPs
bndr of
XTyVarBndr{} -> String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: XTyVarBndr"
UserTyVar XUserTyVar GhcPs
_ Located (IdP GhcPs)
name -> 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 (IdP GhcPs)
Located RdrName
name
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered
docSeparator | Bool
needsSep] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [Text -> ToBriDocM BriDocNumbered
docLit Text
nameStr]
KindedTyVar XKindedTyVar GhcPs
_ Located (IdP GhcPs)
name LHsType GhcPs
kind -> 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 (IdP GhcPs)
Located RdrName
name
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ ToBriDocM BriDocNumbered
docSeparator | Bool
needsSep ]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"("
, 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 -> ToBriDocM BriDocNumbered)
-> (Text -> ToBriDocM BriDocNumbered)
-> Text
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"::"
, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
kind
, Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
")"
]
layoutTyFamInstDecl
:: Data.Data.Data a
=> Bool
-> Located a
-> TyFamInstDecl GhcPs
-> ToBriDocM BriDocNumbered
layoutTyFamInstDecl :: Bool
-> Located a -> TyFamInstDecl GhcPs -> ToBriDocM BriDocNumbered
layoutTyFamInstDecl Bool
inClass Located a
outerNode TyFamInstDecl GhcPs
tfid = do
let
#if MIN_VERSION_ghc(8,8,0)
FamEqn XCFamEqn GhcPs (LHsType GhcPs)
_ Located (IdP GhcPs)
name Maybe [LHsTyVarBndr GhcPs]
bndrsMay HsTyPats GhcPs
pats LexicalFixity
_fixity LHsType GhcPs
typ = HsImplicitBndrs GhcPs (FamEqn GhcPs (LHsType GhcPs))
-> FamEqn GhcPs (LHsType GhcPs)
forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body (HsImplicitBndrs GhcPs (FamEqn GhcPs (LHsType GhcPs))
-> FamEqn GhcPs (LHsType GhcPs))
-> HsImplicitBndrs GhcPs (FamEqn GhcPs (LHsType GhcPs))
-> FamEqn GhcPs (LHsType GhcPs)
forall a b. (a -> b) -> a -> b
$ TyFamInstDecl GhcPs
-> HsImplicitBndrs GhcPs (FamEqn GhcPs (LHsType GhcPs))
forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn TyFamInstDecl GhcPs
tfid
innerNode :: Located a
innerNode = Located a
outerNode
#else
FamEqn _ name pats _fixity typ = hsib_body $ tfid_eqn tfid
bndrsMay = Nothing
innerNode = outerNode
#endif
Located a -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior Located a
outerNode (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 (IdP GhcPs)
Located RdrName
name
Bool
needsParens <- Located a -> AnnKeywordId -> ToBriDocM Bool
forall a (m :: * -> *).
(Data a, MonadMultiReader Anns m) =>
Located a -> AnnKeywordId -> m Bool
hasAnnKeyword Located a
outerNode AnnKeywordId
AnnOpenP
let
instanceDoc :: ToBriDocM BriDocNumbered
instanceDoc = if Bool
inClass
then Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"type"
else [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (Text -> ToBriDocM BriDocNumbered)
-> Text
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"type", Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"instance"]
makeForallDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
makeForallDoc :: [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
makeForallDoc [LHsTyVarBndr GhcPs]
bndrs = do
[(Text, Maybe (ToBriDocM BriDocNumbered))]
bndrDocs <- [LHsTyVarBndr GhcPs]
-> ToBriDocM [(Text, Maybe (ToBriDocM BriDocNumbered))]
layoutTyVarBndrs [LHsTyVarBndr GhcPs]
bndrs
[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
( [Text -> ToBriDocM BriDocNumbered
docLit (String -> Text
Text.pack String
"forall")]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [(Text, Maybe (ToBriDocM BriDocNumbered))]
-> [ToBriDocM BriDocNumbered]
processTyVarBndrsSingleline [(Text, Maybe (ToBriDocM BriDocNumbered))]
bndrDocs
)
lhs :: ToBriDocM BriDocNumbered
lhs =
Located a -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located a
innerNode
(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
docSeq
([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
instanceDoc]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ [LHsTyVarBndr GhcPs] -> ToBriDocM BriDocNumbered
makeForallDoc [LHsTyVarBndr GhcPs]
foralls | Just [LHsTyVarBndr GhcPs]
foralls <- [Maybe [LHsTyVarBndr GhcPs]
bndrsMay] ]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ToBriDocM BriDocNumbered
docParenL | Bool
needsParens ]
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located RdrName
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (IdP GhcPs)
Located RdrName
name (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] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
intersperse ToBriDocM BriDocNumbered
docSeparator (HsTyPats GhcPs -> [ToBriDocM BriDocNumbered]
layoutHsTyPats HsTyPats GhcPs
pats)
[ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ ToBriDocM BriDocNumbered
docParenR | Bool
needsParens ]
Bool
hasComments <- Bool -> Bool -> Bool
(||)
(Bool -> Bool -> Bool)
-> ToBriDocM Bool
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Located a -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyRegularCommentsConnected Located a
outerNode
MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Bool -> Bool)
-> ToBriDocM Bool -> ToBriDocM Bool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Located a -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyRegularCommentsRest Located a
innerNode
ToBriDocM BriDocNumbered
typeDoc <- (LHsType GhcPs -> ToBriDocM BriDocNumbered)
-> LHsType 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 LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
typ
Bool
-> ToBriDocM BriDocNumbered
-> String
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
layoutLhsAndType Bool
hasComments ToBriDocM BriDocNumbered
lhs String
"=" ToBriDocM BriDocNumbered
typeDoc
#if MIN_VERSION_ghc(8,8,0)
layoutHsTyPats :: [HsArg (LHsType GhcPs) (LHsKind GhcPs)] -> [ToBriDocM BriDocNumbered]
layoutHsTyPats :: HsTyPats GhcPs -> [ToBriDocM BriDocNumbered]
layoutHsTyPats HsTyPats GhcPs
pats = HsTyPats GhcPs
pats HsTyPats GhcPs
-> (HsArg (LHsType GhcPs) (LHsType GhcPs)
-> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
HsValArg LHsType GhcPs
tm -> LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
tm
HsTypeArg SrcSpan
_l LHsType GhcPs
ty -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"@", LHsType GhcPs -> ToBriDocM BriDocNumbered
layoutType LHsType GhcPs
ty]
HsArgPar SrcSpan
_l -> String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: HsArgPar{}"
#else
layoutHsTyPats :: [LHsType GhcPs] -> [ToBriDocM BriDocNumbered]
layoutHsTyPats pats = layoutType <$> pats
#endif
layoutClsInst :: ToBriDoc ClsInstDecl
layoutClsInst :: ToBriDoc ClsInstDecl
layoutClsInst lcid :: GenLocated SrcSpan (ClsInstDecl GhcPs)
lcid@(L SrcSpan
_ ClsInstDecl GhcPs
cid) = [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
[ ToBriDocM BriDocNumbered
layoutInstanceHead
, 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
docSetIndentLevel
(ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM (Located BriDocNumbered)] -> ToBriDocM BriDocNumbered
docSortedLines
([ToBriDocM (Located BriDocNumbered)] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM (Located BriDocNumbered)] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM (Located BriDocNumbered))
-> [GenLocated SrcSpan (Sig GhcPs)]
-> [ToBriDocM (Located BriDocNumbered)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateSig (ClsInstDecl GhcPs -> [GenLocated SrcSpan (Sig GhcPs)]
forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs ClsInstDecl GhcPs
cid)
[ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
forall a. [a] -> [a] -> [a]
++ (GenLocated SrcSpan (HsBind GhcPs)
-> ToBriDocM (Located BriDocNumbered))
-> [GenLocated SrcSpan (HsBind GhcPs)]
-> [ToBriDocM (Located BriDocNumbered)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenLocated SrcSpan (HsBind GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateBind (LHsBindsLR GhcPs GhcPs -> [GenLocated SrcSpan (HsBind GhcPs)]
forall a. Bag a -> [a]
bagToList (LHsBindsLR GhcPs GhcPs -> [GenLocated SrcSpan (HsBind GhcPs)])
-> LHsBindsLR GhcPs GhcPs -> [GenLocated SrcSpan (HsBind GhcPs)]
forall a b. (a -> b) -> a -> b
$ ClsInstDecl GhcPs -> LHsBindsLR GhcPs GhcPs
forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds ClsInstDecl GhcPs
cid)
[ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
forall a. [a] -> [a] -> [a]
++ (Located (TyFamInstDecl GhcPs)
-> ToBriDocM (Located BriDocNumbered))
-> [Located (TyFamInstDecl GhcPs)]
-> [ToBriDocM (Located BriDocNumbered)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Located (TyFamInstDecl GhcPs) -> ToBriDocM (Located BriDocNumbered)
layoutAndLocateTyFamInsts (ClsInstDecl GhcPs -> [Located (TyFamInstDecl GhcPs)]
forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts ClsInstDecl GhcPs
cid)
[ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
-> [ToBriDocM (Located BriDocNumbered)]
forall a. [a] -> [a] -> [a]
++ (Located (DataFamInstDecl GhcPs)
-> ToBriDocM (Located BriDocNumbered))
-> [Located (DataFamInstDecl GhcPs)]
-> [ToBriDocM (Located BriDocNumbered)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Located (DataFamInstDecl GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateDataFamInsts (ClsInstDecl GhcPs -> [Located (DataFamInstDecl GhcPs)]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcPs
cid)
]
where
layoutInstanceHead :: ToBriDocM BriDocNumbered
#if MIN_VERSION_ghc(8,10,1) /* ghc-8.10.1 */
layoutInstanceHead :: ToBriDocM BriDocNumbered
layoutInstanceHead =
ToBriDoc HsDecl
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment
ToBriDoc HsDecl -> ToBriDoc HsDecl
forall a b. (a -> b) -> a -> b
$ XInstD GhcPs -> InstDecl GhcPs -> HsDecl GhcPs
forall p. XInstD p -> InstDecl p -> HsDecl p
InstD NoExtField
XInstD GhcPs
NoExtField
(InstDecl GhcPs -> HsDecl GhcPs)
-> (ClsInstDecl GhcPs -> InstDecl GhcPs)
-> ClsInstDecl GhcPs
-> HsDecl GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XClsInstD GhcPs -> ClsInstDecl GhcPs -> InstDecl GhcPs
forall pass. XClsInstD pass -> ClsInstDecl pass -> InstDecl pass
ClsInstD NoExtField
XClsInstD GhcPs
NoExtField
(ClsInstDecl GhcPs -> InstDecl GhcPs)
-> (ClsInstDecl GhcPs -> ClsInstDecl GhcPs)
-> ClsInstDecl GhcPs
-> InstDecl GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClsInstDecl GhcPs -> ClsInstDecl GhcPs
forall p. ClsInstDecl p -> ClsInstDecl p
removeChildren
(ClsInstDecl GhcPs -> HsDecl GhcPs)
-> GenLocated SrcSpan (ClsInstDecl GhcPs) -> Located (HsDecl GhcPs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenLocated SrcSpan (ClsInstDecl GhcPs)
lcid
#else
layoutInstanceHead =
briDocByExactNoComment
$ InstD NoExt
. ClsInstD NoExt
. removeChildren
<$> lcid
#endif
removeChildren :: ClsInstDecl p -> ClsInstDecl p
removeChildren :: ClsInstDecl p -> ClsInstDecl p
removeChildren ClsInstDecl p
c = ClsInstDecl p
c
{ cid_binds :: LHsBinds p
cid_binds = LHsBinds p
forall a. Bag a
emptyBag
, cid_sigs :: [LSig p]
cid_sigs = []
, cid_tyfam_insts :: [LTyFamInstDecl p]
cid_tyfam_insts = []
, cid_datafam_insts :: [LDataFamInstDecl p]
cid_datafam_insts = []
}
docSortedLines
:: [ToBriDocM (Located BriDocNumbered)] -> ToBriDocM BriDocNumbered
docSortedLines :: [ToBriDocM (Located BriDocNumbered)] -> ToBriDocM BriDocNumbered
docSortedLines [ToBriDocM (Located BriDocNumbered)]
l =
BriDocFInt -> ToBriDocM BriDocNumbered
forall (m :: * -> *).
MonadMultiState NodeAllocIndex m =>
BriDocFInt -> m BriDocNumbered
allocateNode (BriDocFInt -> ToBriDocM BriDocNumbered)
-> ([Located BriDocNumbered] -> BriDocFInt)
-> [Located BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [BriDocNumbered] -> BriDocFInt
forall (f :: * -> *). [f (BriDocF f)] -> BriDocF f
BDFLines ([BriDocNumbered] -> BriDocFInt)
-> ([Located BriDocNumbered] -> [BriDocNumbered])
-> [Located BriDocNumbered]
-> BriDocFInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located BriDocNumbered -> BriDocNumbered)
-> [Located BriDocNumbered] -> [BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Located BriDocNumbered -> BriDocNumbered
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc ([Located BriDocNumbered] -> [BriDocNumbered])
-> ([Located BriDocNumbered] -> [Located BriDocNumbered])
-> [Located BriDocNumbered]
-> [BriDocNumbered]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located BriDocNumbered -> SrcSpan)
-> [Located BriDocNumbered] -> [Located BriDocNumbered]
forall b a. Ord b => (a -> b) -> [a] -> [a]
List.sortOn Located BriDocNumbered -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc ([Located BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[Located BriDocNumbered]
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [ToBriDocM (Located BriDocNumbered)]
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
[Located BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ToBriDocM (Located BriDocNumbered)]
l
layoutAndLocateSig :: ToBriDocC (Sig GhcPs) (Located BriDocNumbered)
layoutAndLocateSig :: GenLocated SrcSpan (Sig GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateSig lsig :: GenLocated SrcSpan (Sig GhcPs)
lsig@(L SrcSpan
loc Sig GhcPs
_) = SrcSpan -> BriDocNumbered -> Located BriDocNumbered
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (BriDocNumbered -> Located BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM (Located BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc Sig
layoutSig GenLocated SrcSpan (Sig GhcPs)
lsig
layoutAndLocateBind :: ToBriDocC (HsBind GhcPs) (Located BriDocNumbered)
layoutAndLocateBind :: GenLocated SrcSpan (HsBind GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateBind lbind :: GenLocated SrcSpan (HsBind GhcPs)
lbind@(L SrcSpan
loc HsBind GhcPs
_) =
SrcSpan -> BriDocNumbered -> Located BriDocNumbered
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (BriDocNumbered -> Located BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM (Located BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Either [BriDocNumbered] BriDocNumbered -> ToBriDocM BriDocNumbered
joinBinds (Either [BriDocNumbered] BriDocNumbered
-> ToBriDocM BriDocNumbered)
-> MultiRWST
'[Config, Anns]
'[[BrittanyError], Seq String]
'[NodeAllocIndex]
Identity
(Either [BriDocNumbered] BriDocNumbered)
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ToBriDocC (HsBind GhcPs) (Either [BriDocNumbered] BriDocNumbered)
layoutBind GenLocated SrcSpan (HsBind GhcPs)
lbind)
joinBinds
:: Either [BriDocNumbered] BriDocNumbered -> ToBriDocM BriDocNumbered
joinBinds :: Either [BriDocNumbered] BriDocNumbered -> ToBriDocM BriDocNumbered
joinBinds = \case
Left [BriDocNumbered]
ns -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return (BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [BriDocNumbered]
ns
Right BriDocNumbered
n -> BriDocNumbered -> ToBriDocM BriDocNumbered
forall (m :: * -> *) a. Monad m => a -> m a
return BriDocNumbered
n
layoutAndLocateTyFamInsts
:: ToBriDocC (TyFamInstDecl GhcPs) (Located BriDocNumbered)
layoutAndLocateTyFamInsts :: Located (TyFamInstDecl GhcPs) -> ToBriDocM (Located BriDocNumbered)
layoutAndLocateTyFamInsts ltfid :: Located (TyFamInstDecl GhcPs)
ltfid@(L SrcSpan
loc TyFamInstDecl GhcPs
tfid) =
SrcSpan -> BriDocNumbered -> Located BriDocNumbered
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (BriDocNumbered -> Located BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM (Located BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool
-> Located (TyFamInstDecl GhcPs)
-> TyFamInstDecl GhcPs
-> ToBriDocM BriDocNumbered
forall a.
Data a =>
Bool
-> Located a -> TyFamInstDecl GhcPs -> ToBriDocM BriDocNumbered
layoutTyFamInstDecl Bool
True Located (TyFamInstDecl GhcPs)
ltfid TyFamInstDecl GhcPs
tfid
layoutAndLocateDataFamInsts
:: ToBriDocC (DataFamInstDecl GhcPs) (Located BriDocNumbered)
layoutAndLocateDataFamInsts :: Located (DataFamInstDecl GhcPs)
-> ToBriDocM (Located BriDocNumbered)
layoutAndLocateDataFamInsts ldfid :: Located (DataFamInstDecl GhcPs)
ldfid@(L SrcSpan
loc DataFamInstDecl GhcPs
_) =
SrcSpan -> BriDocNumbered -> Located BriDocNumbered
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (BriDocNumbered -> Located BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM (Located BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc DataFamInstDecl
layoutDataFamInstDecl Located (DataFamInstDecl GhcPs)
ldfid
layoutDataFamInstDecl :: ToBriDoc DataFamInstDecl
layoutDataFamInstDecl :: ToBriDoc DataFamInstDecl
layoutDataFamInstDecl Located (DataFamInstDecl GhcPs)
ldfid =
(BriDocFInt -> BriDocFInt) -> BriDocNumbered -> BriDocNumbered
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BriDocFInt -> BriDocFInt
forall (f :: * -> *). BriDocF f -> BriDocF f
stripWhitespace (BriDocNumbered -> BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc DataFamInstDecl
forall ast. Annotate ast => Located ast -> ToBriDocM BriDocNumbered
briDocByExactNoComment Located (DataFamInstDecl GhcPs)
ldfid
stripWhitespace :: BriDocF f -> BriDocF f
stripWhitespace :: BriDocF f -> BriDocF f
stripWhitespace (BDFExternal AnnKey
ann Set AnnKey
anns Bool
b Text
t) =
AnnKey -> Set AnnKey -> Bool -> Text -> BriDocF f
forall (f :: * -> *).
AnnKey -> Set AnnKey -> Bool -> Text -> BriDocF f
BDFExternal AnnKey
ann Set AnnKey
anns Bool
b (Text -> BriDocF f) -> Text -> BriDocF f
forall a b. (a -> b) -> a -> b
$ Text -> Text
stripWhitespace' Text
t
stripWhitespace BriDocF f
b = BriDocF f
b
stripWhitespace' :: Text -> Text
stripWhitespace' :: Text -> Text
stripWhitespace' Text
t =
Text -> [Text] -> Text
Text.intercalate (String -> Text
Text.pack String
"\n") ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
go ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Arity -> [Text] -> [Text]
forall a. Arity -> [a] -> [a]
List.drop Arity
1 ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
Text.lines Text
t
where
go :: [Text] -> [Text]
go [] = []
go (Text
line1 : [Text]
lineR) = case Text -> Text
Text.stripStart Text
line1 of
Text
st | Text -> Bool
isTypeOrData Text
st -> Text
st Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
lineR
| Bool
otherwise -> Text
st Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text] -> [Text]
go [Text]
lineR
isTypeOrData :: Text -> Bool
isTypeOrData Text
t' =
(String -> Text
Text.pack String
"type" Text -> Text -> Bool
`Text.isPrefixOf` Text
t')
Bool -> Bool -> Bool
|| (String -> Text
Text.pack String
"newtype" Text -> Text -> Bool
`Text.isPrefixOf` Text
t')
Bool -> Bool -> Bool
|| (String -> Text
Text.pack String
"data" Text -> Text -> Bool
`Text.isPrefixOf` Text
t')
layoutLhsAndType
:: Bool
-> ToBriDocM BriDocNumbered
-> String
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
layoutLhsAndType :: Bool
-> ToBriDocM BriDocNumbered
-> String
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
layoutLhsAndType Bool
hasComments ToBriDocM BriDocNumbered
lhs String
sep ToBriDocM BriDocNumbered
typeDoc = do
CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond (Bool -> Bool
not Bool
hasComments) (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
[ToBriDocM BriDocNumbered
lhs, ToBriDocM BriDocNumbered
docSeparator, String -> ToBriDocM BriDocNumbered
docLitS String
sep, ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
typeDoc]
ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
lhs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols
ColSig
ColTyOpPrefix
[ 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
sep
, BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY (Arity -> BrIndent
BrIndentSpecial (String -> Arity
forall (t :: * -> *) a. Foldable t => t a -> Arity
length String
sep Arity -> Arity -> Arity
forall a. Num a => a -> a -> a
+ Arity
1)) ToBriDocM BriDocNumbered
typeDoc
]