{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ViewPatterns #-}

module Language.Haskell.Brittany.Internal.Layouters.Expr
  ( layoutExpr
  , litBriDoc
  , overLitValBriDoc
  )
where



#include "prelude.inc"

import           Language.Haskell.Brittany.Internal.Types
import           Language.Haskell.Brittany.Internal.LayouterBasics
import           Language.Haskell.Brittany.Internal.Config.Types

import qualified Language.Haskell.GHC.ExactPrint.Types as ExactPrint.Types

import           GHC ( runGhc, GenLocated(L), SrcSpan, moduleNameString, AnnKeywordId(..), RdrName(..) )
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
import           GHC.Hs
#else
import           HsSyn
#endif
import           Name
import qualified FastString
import           BasicTypes

import           Language.Haskell.Brittany.Internal.Utils
import           Language.Haskell.Brittany.Internal.Layouters.Pattern
import           Language.Haskell.Brittany.Internal.Layouters.Decl
import           Language.Haskell.Brittany.Internal.Layouters.Stmt
import           Language.Haskell.Brittany.Internal.Layouters.Type



layoutExpr :: ToBriDoc HsExpr
layoutExpr :: ToBriDoc HsExpr
layoutExpr lexpr :: Located (HsExpr GhcPs)
lexpr@(L SrcSpan
_ HsExpr GhcPs
expr) = do
  IndentPolicy
indentPolicy <- MultiRWST
  '[Config, Anns]
  '[[BrittanyError], Seq String]
  '[NodeAllocIndex]
  Identity
  Config
forall a (m :: * -> *). MonadMultiReader a m => m a
mAsk
    MultiRWST
  '[Config, Anns]
  '[[BrittanyError], Seq String]
  '[NodeAllocIndex]
  Identity
  Config
-> (Config -> IndentPolicy)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     IndentPolicy
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Config -> CLayoutConfig Identity
forall (f :: * -> *). CConfig f -> CLayoutConfig f
_conf_layout
    (Config -> CLayoutConfig Identity)
-> (CLayoutConfig Identity -> Identity (Last IndentPolicy))
-> Config
-> Identity (Last IndentPolicy)
forall a b c. (a -> b) -> (b -> c) -> a -> c
.>  CLayoutConfig Identity -> Identity (Last IndentPolicy)
forall (f :: * -> *). CLayoutConfig f -> f (Last IndentPolicy)
_lconfig_indentPolicy
    (Config -> Identity (Last IndentPolicy))
-> (Identity (Last IndentPolicy) -> IndentPolicy)
-> Config
-> IndentPolicy
forall a b c. (a -> b) -> (b -> c) -> a -> c
.>  Identity (Last IndentPolicy) -> IndentPolicy
forall a b. Coercible a b => Identity a -> b
confUnpack
  let allowFreeIndent :: Bool
allowFreeIndent = IndentPolicy
indentPolicy IndentPolicy -> IndentPolicy -> Bool
forall a. Eq a => a -> a -> Bool
== IndentPolicy
IndentPolicyFree
  Located (HsExpr GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (HsExpr GhcPs)
lexpr (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case HsExpr GhcPs
expr of
    HsVar XVar GhcPs
_ Located (IdP GhcPs)
vname -> do
      Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     Text
-> ToBriDocM BriDocNumbered
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Located RdrName
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     Text
forall (m :: * -> *).
(MonadMultiReader Config m, MonadMultiReader Anns m) =>
Located RdrName -> m Text
lrdrNameToTextAnn Located (IdP GhcPs)
Located RdrName
vname
    HsUnboundVar XUnboundVar GhcPs
_ UnboundVar
var -> case UnboundVar
var of
      OutOfScope OccName
oname GlobalRdrEnv
_ -> 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
$ OccName -> String
occNameString OccName
oname
      TrueExprHole OccName
oname -> 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
$ OccName -> String
occNameString OccName
oname
    HsRecFld{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsRecFld" Located (HsExpr GhcPs)
lexpr
    HsOverLabel XOverLabel GhcPs
_ext Maybe (IdP GhcPs)
_reboundFromLabel FastString
name ->
      let label :: String
label = FastString -> String
FastString.unpackFS FastString
name
      in Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> (String -> Text) -> String -> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack (String -> ToBriDocM BriDocNumbered)
-> String -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Char
'#' Char -> String -> String
forall a. a -> [a] -> [a]
: String
label
    HsIPVar XIPVar GhcPs
_ext (HsIPName FastString
name) ->
      let label :: String
label = FastString -> String
FastString.unpackFS FastString
name
      in Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> (String -> Text) -> String -> ToBriDocM BriDocNumbered
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack (String -> ToBriDocM BriDocNumbered)
-> String -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Char
'?' Char -> String -> String
forall a. a -> [a] -> [a]
: String
label
    HsOverLit XOverLitE GhcPs
_ HsOverLit GhcPs
olit -> do
      BriDocFInt -> ToBriDocM BriDocNumbered
forall (m :: * -> *).
MonadMultiState NodeAllocIndex m =>
BriDocFInt -> m BriDocNumbered
allocateNode (BriDocFInt -> ToBriDocM BriDocNumbered)
-> BriDocFInt -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ OverLitVal -> BriDocFInt
overLitValBriDoc (OverLitVal -> BriDocFInt) -> OverLitVal -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ HsOverLit GhcPs -> OverLitVal
forall p. HsOverLit p -> OverLitVal
ol_val HsOverLit GhcPs
olit
    HsLit XLitE GhcPs
_ HsLit GhcPs
lit -> do
      BriDocFInt -> ToBriDocM BriDocNumbered
forall (m :: * -> *).
MonadMultiState NodeAllocIndex m =>
BriDocFInt -> m BriDocNumbered
allocateNode (BriDocFInt -> ToBriDocM BriDocNumbered)
-> BriDocFInt -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ HsLit GhcPs -> BriDocFInt
litBriDoc HsLit GhcPs
lit
    HsLam XLam GhcPs
_ (MG XMG GhcPs (Located (HsExpr GhcPs))
_ (L SrcSpan
_ [lmatch :: LMatch GhcPs (Located (HsExpr GhcPs))
lmatch@(L SrcSpan
_ Match GhcPs (Located (HsExpr GhcPs))
match)]) Origin
_)
      |  [LPat GhcPs]
pats                  <- Match GhcPs (Located (HsExpr GhcPs)) -> [LPat GhcPs]
forall p body. Match p body -> [LPat p]
m_pats Match GhcPs (Located (HsExpr GhcPs))
match
      ,  GRHSs XCGRHSs GhcPs (Located (HsExpr GhcPs))
_ [LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs] LHsLocalBinds GhcPs
llocals <- Match GhcPs (Located (HsExpr GhcPs))
-> GRHSs GhcPs (Located (HsExpr GhcPs))
forall p body. Match p body -> GRHSs p body
m_grhss Match GhcPs (Located (HsExpr GhcPs))
match
      ,  L SrcSpan
_ EmptyLocalBinds {} <- LHsLocalBinds GhcPs
llocals
      ,  L SrcSpan
_ (GRHS XCGRHS GhcPs (Located (HsExpr GhcPs))
_ [] Located (HsExpr GhcPs)
body)     <- LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs
      -> do
      [ToBriDocM BriDocNumbered]
patDocs <- [Bool] -> [Located (Pat GhcPs)] -> [(Bool, Located (Pat GhcPs))]
forall a b. [a] -> [b] -> [(a, b)]
zip (Bool
True Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: Bool -> [Bool]
forall a. a -> [a]
repeat Bool
False) [LPat GhcPs]
[Located (Pat GhcPs)]
pats [(Bool, Located (Pat GhcPs))]
-> ((Bool, 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` \(Bool
isFirst, 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
$ do
          -- this code could be as simple as `colsWrapPat =<< layoutPat p`
          -- if it was not for the following two cases:
          -- \ !x -> x
          -- \ ~x -> x
          -- These make it necessary to special-case an additional separator.
          -- (TODO: we create a BDCols here, but then make it ineffective
          -- by wrapping it in docSeq below. We _could_ add alignments for
          -- stuff like lists-of-lambdas. Nothing terribly important..)
          let shouldPrefixSeparator :: Bool
shouldPrefixSeparator = case Located (Pat GhcPs)
p of
                (Located (Pat GhcPs) -> Located (SrcSpanLess (Located (Pat GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
ghcDL -> L SrcSpan
_ LazyPat{}) -> Bool
isFirst
                (Located (Pat GhcPs) -> Located (SrcSpanLess (Located (Pat GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
ghcDL -> L SrcSpan
_ BangPat{}) -> Bool
isFirst
                Located (Pat GhcPs)
_               -> Bool
False
          Seq BriDocNumbered
patDocSeq <- LPat GhcPs -> ToBriDocM (Seq BriDocNumbered)
layoutPat LPat GhcPs
Located (Pat GhcPs)
p
          Seq BriDocNumbered
fixed <- case Seq BriDocNumbered -> ViewL BriDocNumbered
forall a. Seq a -> ViewL a
Seq.viewl Seq BriDocNumbered
patDocSeq of
            BriDocNumbered
p1 Seq.:< Seq BriDocNumbered
pr | Bool
shouldPrefixSeparator -> do
              BriDocNumbered
p1' <- [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
docSeparator, BriDocNumbered -> ToBriDocM BriDocNumbered
forall (f :: * -> *) a. Applicative f => a -> f a
pure BriDocNumbered
p1]
              Seq BriDocNumbered -> ToBriDocM (Seq BriDocNumbered)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (BriDocNumbered
p1' BriDocNumbered -> Seq BriDocNumbered -> Seq BriDocNumbered
forall a. a -> Seq a -> Seq a
Seq.<| Seq BriDocNumbered
pr)
            ViewL BriDocNumbered
_ -> Seq BriDocNumbered -> ToBriDocM (Seq BriDocNumbered)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Seq BriDocNumbered
patDocSeq
          Seq BriDocNumbered -> ToBriDocM BriDocNumbered
colsWrapPat Seq BriDocNumbered
fixed
      ToBriDocM BriDocNumbered
bodyDoc <- BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (ToBriDocM BriDocNumbered)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
body
      let funcPatternPartLine :: ToBriDocM BriDocNumbered
funcPatternPartLine =
            ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColCasePattern
              ([ToBriDocM BriDocNumbered]
patDocs [ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\ToBriDocM BriDocNumbered
p -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
p, ToBriDocM BriDocNumbered
docSeparator]))
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ -- single line
          [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
"\\"
          , LMatch GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LMatch GhcPs (Located (HsExpr GhcPs))
lmatch (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
funcPatternPartLine
          , 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
"->"
          , LGRHS GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
bodyDoc
          ]
          -- double line
        , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
          ([ToBriDocM BriDocNumbered] -> 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
"\\"
            , LMatch GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LMatch GhcPs (Located (HsExpr GhcPs))
lmatch (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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
funcPatternPartLine
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"->"
            ])
          (LGRHS GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
bodyDoc)
          -- wrapped par spacing
        , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
        (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
"\\"
          , LMatch GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LMatch GhcPs (Located (HsExpr GhcPs))
lmatch (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
funcPatternPartLine
          , 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
"->"
          , LGRHS GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
bodyDoc
          ]
          -- conservative
        , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
          ([ToBriDocM BriDocNumbered] -> 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
"\\"
            , LMatch GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LMatch GhcPs (Located (HsExpr GhcPs))
lmatch (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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
funcPatternPartLine
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"->"
            ])
          (LGRHS GhcPs (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LGRHS GhcPs (Located (HsExpr GhcPs))
lgrhs (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docNonBottomSpacing ToBriDocM BriDocNumbered
bodyDoc)
        ]
    HsLam{} ->
      String -> ToBriDoc HsExpr
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"HsLam too complex" Located (HsExpr GhcPs)
lexpr
    HsLamCase XLamCase GhcPs
_ XMatchGroup{} ->
      String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: HsLamCase XMatchGroup"
    HsLamCase XLamCase GhcPs
_ (MG XMG GhcPs (Located (HsExpr GhcPs))
_ (L SrcSpan
_ []) Origin
_) -> do
      ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing (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
$
        (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"\\case {}")
    HsLamCase XLamCase GhcPs
_ (MG XMG GhcPs (Located (HsExpr GhcPs))
_ lmatches :: GenLocated SrcSpan [LMatch GhcPs (Located (HsExpr GhcPs))]
lmatches@(L SrcSpan
_ [LMatch GhcPs (Located (HsExpr GhcPs))]
matches) 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
"->"
      [BriDocNumbered]
funcPatDocs <- GenLocated SrcSpan [LMatch GhcPs (Located (HsExpr 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 [LMatch GhcPs (Located (HsExpr 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 (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered
layoutPatternBind Maybe Text
forall a. Maybe a
Nothing BriDocNumbered
binderDoc (LMatch GhcPs (Located (HsExpr GhcPs)) -> ToBriDocM BriDocNumbered)
-> [LMatch GhcPs (Located (HsExpr 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 (Located (HsExpr GhcPs))]
matches
      ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
        (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"\\case")
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
funcPatDocs)
    HsApp XApp GhcPs
_ exp1 :: Located (HsExpr GhcPs)
exp1@(L SrcSpan
_ HsApp{}) Located (HsExpr GhcPs)
exp2 -> do
      let gather :: [LHsExpr GhcPs] -> LHsExpr GhcPs -> (LHsExpr GhcPs, [LHsExpr GhcPs])
          gather :: [Located (HsExpr GhcPs)]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs), [Located (HsExpr GhcPs)])
gather [Located (HsExpr GhcPs)]
list = \case
            L SrcSpan
_ (HsApp XApp GhcPs
_ Located (HsExpr GhcPs)
l Located (HsExpr GhcPs)
r) -> [Located (HsExpr GhcPs)]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs), [Located (HsExpr GhcPs)])
gather (Located (HsExpr GhcPs)
rLocated (HsExpr GhcPs)
-> [Located (HsExpr GhcPs)] -> [Located (HsExpr GhcPs)]
forall a. a -> [a] -> [a]
:[Located (HsExpr GhcPs)]
list) Located (HsExpr GhcPs)
l
            Located (HsExpr GhcPs)
x               -> (Located (HsExpr GhcPs)
x, [Located (HsExpr GhcPs)]
list)
      let (Located (HsExpr GhcPs)
headE, [Located (HsExpr GhcPs)]
paramEs) = [Located (HsExpr GhcPs)]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs), [Located (HsExpr GhcPs)])
gather [Located (HsExpr GhcPs)
exp2] Located (HsExpr GhcPs)
exp1
      let colsOrSequence :: [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
colsOrSequence = case Located (HsExpr GhcPs)
headE of
            L SrcSpan
_ (HsVar XVar GhcPs
_ (L SrcSpan
_ (Unqual occname))) ->
              ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols (Text -> ColSig
ColApp (Text -> ColSig) -> Text -> ColSig
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ OccName -> String
occNameString OccName
occname)
            Located (HsExpr GhcPs)
_ -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
      ToBriDocM BriDocNumbered
headDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
headE
      [ToBriDocM BriDocNumbered]
paramDocs <- ToBriDoc HsExpr
-> Located (HsExpr 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 (Located (HsExpr GhcPs)
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (ToBriDocM BriDocNumbered))
-> [Located (HsExpr 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` [Located (HsExpr GhcPs)]
paramEs
      Bool
hasComments <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsConnected Located (HsExpr GhcPs)
exp2
      CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
        -- foo x y
        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
colsOrSequence
          ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
headDoc)
          ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
: [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
spacifyDocs (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]
paramDocs)
        -- foo x
        --     y
        Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond Bool
allowFreeIndent
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
          [ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
headDoc)
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
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 (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ToBriDocM BriDocNumbered]
paramDocs
          ]
        -- foo
        --   x
        --   y
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
headDoc)
            ( 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]
paramDocs
            )
        -- ( multi
        --   line
        --   function
        -- )
        --   x
        --   y
        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
            ( 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]
paramDocs
            )
    HsApp XApp GhcPs
_ Located (HsExpr GhcPs)
exp1 Located (HsExpr GhcPs)
exp2 -> do
      -- TODO: if expDoc1 is some literal, we may want to create a docCols here.
      ToBriDocM BriDocNumbered
expDoc1 <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
exp1
      ToBriDocM BriDocNumbered
expDoc2 <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
exp2
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ -- func arg
          [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
expDoc1, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
expDoc2]
        , -- func argline1
          --   arglines
          -- e.g.
          -- func Abc
          --   { member1 = True
          --   , member2 = 13
          --   }
          ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing -- this is most likely superfluous because
                           -- this is a sequence of a one-line and a par-space
                           -- anyways, so it is _always_ par-spaced.
        (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
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
expDoc1
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
expDoc2
          ]
        , -- func
          --   arg
          ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
expDoc1)
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docNonBottomSpacing ToBriDocM BriDocNumbered
expDoc2)
        , -- fu
          --   nc
          --   ar
          --     gument
          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
expDoc1
          ToBriDocM BriDocNumbered
expDoc2
        ]
#if MIN_VERSION_ghc(8,8,0)   /* ghc-8.8 */
    HsAppType XAppTypeE GhcPs
_ Located (HsExpr GhcPs)
_ XHsWildCardBndrs{} ->
      String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: HsAppType XHsWildCardBndrs"
    HsAppType XAppTypeE GhcPs
_ Located (HsExpr GhcPs)
exp1 (HsWC XHsWC (NoGhcTc GhcPs) (LHsType (NoGhcTc GhcPs))
_ LHsType (NoGhcTc GhcPs)
ty1) -> do
#else
    HsAppType XHsWildCardBndrs{} _ ->
      error "brittany internal error: HsAppType XHsWildCardBndrs"
    HsAppType (HsWC _ ty1) exp1 -> do
#endif
      ToBriDocM BriDocNumbered
t <- (Located (HsType GhcPs) -> ToBriDocM BriDocNumbered)
-> Located (HsType 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 Located (HsType GhcPs) -> ToBriDocM BriDocNumbered
layoutType Located (HsType GhcPs)
LHsType (NoGhcTc GhcPs)
ty1
      ToBriDocM BriDocNumbered
e <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
exp1
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
            [ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e
            , ToBriDocM BriDocNumbered
docSeparator
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"@"
            , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
t
            ]
        , ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
            ToBriDocM BriDocNumbered
e
            ([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
"@", ToBriDocM BriDocNumbered
t ])
        ]
    OpApp XOpApp GhcPs
_ expLeft :: Located (HsExpr GhcPs)
expLeft@(L SrcSpan
_ OpApp{}) Located (HsExpr GhcPs)
expOp Located (HsExpr GhcPs)
expRight -> do
      let gather :: [(LHsExpr GhcPs, LHsExpr GhcPs)] -> LHsExpr GhcPs -> (LHsExpr GhcPs, [(LHsExpr GhcPs, LHsExpr GhcPs)])
          gather :: [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs),
    [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))])
gather [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
opExprList = \case
            (L SrcSpan
_ (OpApp XOpApp GhcPs
_ Located (HsExpr GhcPs)
l1 Located (HsExpr GhcPs)
op1 Located (HsExpr GhcPs)
r1)) -> [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs),
    [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))])
gather ((Located (HsExpr GhcPs)
op1, Located (HsExpr GhcPs)
r1)(Located (HsExpr GhcPs), Located (HsExpr GhcPs))
-> [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
-> [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
forall a. a -> [a] -> [a]
: [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
opExprList) Located (HsExpr GhcPs)
l1
            Located (HsExpr GhcPs)
final -> (Located (HsExpr GhcPs)
final, [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
opExprList)
          (Located (HsExpr GhcPs)
leftOperand, [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
appList) = [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
-> Located (HsExpr GhcPs)
-> (Located (HsExpr GhcPs),
    [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))])
gather [] Located (HsExpr GhcPs)
expLeft
      ToBriDocM BriDocNumbered
leftOperandDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
leftOperand
      [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
appListDocs <- [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
appList [(Located (HsExpr GhcPs), Located (HsExpr GhcPs))]
-> ((Located (HsExpr GhcPs), Located (HsExpr GhcPs))
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \(Located (HsExpr GhcPs)
x,Located (HsExpr GhcPs)
y) -> [ (ToBriDocM BriDocNumbered
xD, ToBriDocM BriDocNumbered
yD)
                                              | ToBriDocM BriDocNumbered
xD <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
x
                                              , ToBriDocM BriDocNumbered
yD <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
y
                                              ]
      ToBriDocM BriDocNumbered
opLastDoc   <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
expOp
      ToBriDocM BriDocNumbered
expLastDoc  <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
expRight
      Bool
allowSinglelinePar <- do
        Bool
hasComLeft <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsConnected Located (HsExpr GhcPs)
expLeft
        Bool
hasComOp   <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsConnected Located (HsExpr GhcPs)
expOp
        Bool -> ToBriDocM Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> ToBriDocM Bool) -> Bool -> ToBriDocM Bool
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
hasComLeft Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
hasComOp
      let allowPar :: Bool
allowPar = case (Located (HsExpr GhcPs)
expOp, Located (HsExpr GhcPs)
expRight) of
            (L SrcSpan
_ (HsVar XVar GhcPs
_ (L SrcSpan
_ (Unqual occname))), Located (HsExpr GhcPs)
_)
              | OccName -> String
occNameString OccName
occname String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"$" -> Bool
True
            (Located (HsExpr GhcPs)
_, L SrcSpan
_ (HsApp XApp GhcPs
_ Located (HsExpr GhcPs)
_ (L SrcSpan
_ HsVar{}))) -> Bool
False
            (Located (HsExpr GhcPs), Located (HsExpr GhcPs))
_ -> Bool
True
      CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
        -- > one + two + three
        -- or
        -- > one + two + case x of
        -- >   _ -> three
        Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond Bool
allowSinglelinePar
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
leftOperandDoc
          , [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
          ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
appListDocs [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
-> ((ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
    -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(ToBriDocM BriDocNumbered
od, ToBriDocM BriDocNumbered
ed) -> [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
od
              , 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
ed
              ]
          , 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
opLastDoc
          , (if Bool
allowPar then ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing else ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline)
              ToBriDocM BriDocNumbered
expLastDoc
          ]
        -- this case rather leads to some unfortunate layouting than to anything
        -- useful; disabling for now. (it interfers with cols stuff.)
        -- addAlternative
        --   $ docSetBaseY
        --   $ docPar
        --     leftOperandDoc
        --     ( docLines
        --      $ (appListDocs <&> \(od, ed) -> docCols ColOpPrefix [appSep od, docSetBaseY ed])
        --       ++ [docCols ColOpPrefix [appSep opLastDoc, docSetBaseY expLastDoc]]
        --     )
        -- > one
        -- >   + two
        -- >   + three
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$
          ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
            ToBriDocM BriDocNumbered
leftOperandDoc
            ( [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
            ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ([(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
appListDocs [(ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)]
-> ((ToBriDocM BriDocNumbered, ToBriDocM BriDocNumbered)
    -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(ToBriDocM BriDocNumbered
od, ToBriDocM BriDocNumbered
ed) -> ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColOpPrefix [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
od, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
ed])
              [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
opLastDoc, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
expLastDoc]]
            )
    OpApp XOpApp GhcPs
_ Located (HsExpr GhcPs)
expLeft Located (HsExpr GhcPs)
expOp Located (HsExpr GhcPs)
expRight -> do
      ToBriDocM BriDocNumbered
expDocLeft  <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
expLeft
      ToBriDocM BriDocNumbered
expDocOp    <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
expOp
      ToBriDocM BriDocNumbered
expDocRight <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
expRight
      let allowPar :: Bool
allowPar = case (Located (HsExpr GhcPs)
expOp, Located (HsExpr GhcPs)
expRight) of
            (L SrcSpan
_ (HsVar XVar GhcPs
_ (L SrcSpan
_ (Unqual occname))), Located (HsExpr GhcPs)
_)
              | OccName -> String
occNameString OccName
occname String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"$" -> Bool
True
            (Located (HsExpr GhcPs)
_, L SrcSpan
_ (HsApp XApp GhcPs
_ Located (HsExpr GhcPs)
_ (L SrcSpan
_ HsVar{}))) -> Bool
False
            (Located (HsExpr GhcPs), Located (HsExpr GhcPs))
_ -> Bool
True
      let leftIsDoBlock :: Bool
leftIsDoBlock = case Located (HsExpr GhcPs)
expLeft of
            L SrcSpan
_ HsDo{} -> Bool
True
            Located (HsExpr GhcPs)
_          -> Bool
False
      CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
        -- one-line
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
expDocLeft
          , 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
expDocOp
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
expDocRight
          ]
        -- -- line + freely indented block for right expression
        -- addAlternative
        --   $ docSeq
        --   [ appSep $ docForceSingleline expDocLeft
        --   , appSep $ docForceSingleline expDocOp
        --   , docSetBaseY $ docAddBaseY BrIndentRegular expDocRight
        --   ]
        -- two-line
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
          let
            expDocOpAndRight :: ToBriDocM BriDocNumbered
expDocOpAndRight = 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
ColOpPrefix [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
expDocOp, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
expDocRight]
          if Bool
leftIsDoBlock
            then [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered
expDocLeft, ToBriDocM BriDocNumbered
expDocOpAndRight]
            else 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
expDocLeft ToBriDocM BriDocNumbered
expDocOpAndRight
              -- TODO: in both cases, we don't force expDocLeft to be
              -- single-line, which has certain.. interesting consequences.
              -- At least, the "two-line" label is not entirely
              -- accurate.
        -- one-line + par
        Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond Bool
allowPar
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
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
expDocLeft
          , 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
expDocOp
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
expDocRight
          ]
        -- more lines
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
          let expDocOpAndRight :: ToBriDocM BriDocNumbered
expDocOpAndRight =
                ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColOpPrefix [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
expDocOp, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
expDocRight]
          if Bool
leftIsDoBlock
            then [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered
expDocLeft, ToBriDocM BriDocNumbered
expDocOpAndRight]
            else 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
expDocLeft ToBriDocM BriDocNumbered
expDocOpAndRight
    NegApp XNegApp GhcPs
_ Located (HsExpr GhcPs)
op SyntaxExpr GhcPs
_ -> do
      ToBriDocM BriDocNumbered
opDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
op
      [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
"-"
             , ToBriDocM BriDocNumbered
opDoc
             ]
    HsPar XPar GhcPs
_ Located (HsExpr GhcPs)
innerExp -> do
      ToBriDocM BriDocNumbered
innerExpDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 (Located (HsExpr GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (HsExpr GhcPs)
lexpr (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDoc HsExpr -> ToBriDoc HsExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ToBriDoc HsExpr
layoutExpr) Located (HsExpr GhcPs)
innerExp
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ [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
"("
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
innerExpDoc
          , 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
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
ColOpPrefix
            [ 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 (Int -> BrIndent
BrIndentSpecial Int
2) ToBriDocM BriDocNumbered
innerExpDoc
            ]
          , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
")"
          ]
        ]
    SectionL XSectionL GhcPs
_ Located (HsExpr GhcPs)
left Located (HsExpr GhcPs)
op -> do -- TODO: add to testsuite
      ToBriDocM BriDocNumbered
leftDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
left
      ToBriDocM BriDocNumbered
opDoc   <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
op
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
leftDoc, ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
opDoc]
    SectionR XSectionR GhcPs
_ Located (HsExpr GhcPs)
op Located (HsExpr GhcPs)
right -> do -- TODO: add to testsuite
      ToBriDocM BriDocNumbered
opDoc    <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
op
      ToBriDocM BriDocNumbered
rightDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
right
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
opDoc, ToBriDocM BriDocNumbered
docSeparator, ToBriDocM BriDocNumbered
rightDoc]
    ExplicitTuple XExplicitTuple GhcPs
_ [LHsTupArg GhcPs]
args Boxity
boxity -> do
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
      let argExprs :: [(LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))]
argExprs = [LHsTupArg GhcPs]
args [LHsTupArg GhcPs]
-> (LHsTupArg GhcPs
    -> (LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs))))
-> [(LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \LHsTupArg GhcPs
arg -> case LHsTupArg GhcPs
arg of
            (L SrcSpan
_ (Present XPresent GhcPs
_ Located (HsExpr GhcPs)
e)) -> (LHsTupArg GhcPs
arg, Located (HsExpr GhcPs) -> Maybe (Located (HsExpr GhcPs))
forall a. a -> Maybe a
Just Located (HsExpr GhcPs)
e);
            (L SrcSpan
_ (Missing XMissing GhcPs
NoExtField)) -> (LHsTupArg GhcPs
arg, Maybe (Located (HsExpr GhcPs))
forall a. Maybe a
Nothing)
            (L SrcSpan
_ XTupArg{}) -> String -> (LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
forall a. HasCallStack => String -> a
error String
"brittany internal error: XTupArg"
#else
      let argExprs = args <&> \arg -> case arg of
            (L _ (Present _ e)) -> (arg, Just e);
            (L _ (Missing NoExt)) -> (arg, Nothing)
            (L _ XTupArg{}) -> error "brittany internal error: XTupArg"
#endif
      [ToBriDocM BriDocNumbered]
argDocs <- [(LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))]
-> ((LHsTupArg GhcPs, Maybe (Located (HsExpr 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 [(LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))]
argExprs
        (((LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
  -> MultiRWST
       '[Config, Anns]
       '[[BrittanyError], Seq String]
       '[NodeAllocIndex]
       Identity
       (ToBriDocM BriDocNumbered))
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      [ToBriDocM BriDocNumbered])
-> ((LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ ((LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
 -> ToBriDocM BriDocNumbered)
-> (LHsTupArg GhcPs, Maybe (Located (HsExpr 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
        (((LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
  -> ToBriDocM BriDocNumbered)
 -> (LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (ToBriDocM BriDocNumbered))
-> ((LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
    -> ToBriDocM BriDocNumbered)
-> (LHsTupArg GhcPs, Maybe (Located (HsExpr GhcPs)))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (ToBriDocM BriDocNumbered)
forall a b. (a -> b) -> a -> b
$ \(LHsTupArg GhcPs
arg, Maybe (Located (HsExpr GhcPs))
exprM) -> LHsTupArg GhcPs
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode LHsTupArg GhcPs
arg (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDoc HsExpr
-> Maybe (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ToBriDocM BriDocNumbered
docEmpty ToBriDoc HsExpr
layoutExpr Maybe (Located (HsExpr GhcPs))
exprM
      Bool
hasComments <- [ToBriDocM Bool] -> ToBriDocM Bool
forall (m :: * -> *). Monad m => [m Bool] -> m Bool
orM
        ( Located (HsExpr GhcPs)
-> AnnKeywordId -> AnnKeywordId -> ToBriDocM Bool
forall ast.
Data ast =>
Located ast -> AnnKeywordId -> AnnKeywordId -> ToBriDocM Bool
hasCommentsBetween Located (HsExpr GhcPs)
lexpr  AnnKeywordId
AnnOpenP AnnKeywordId
AnnCloseP
        ToBriDocM Bool -> [ToBriDocM Bool] -> [ToBriDocM Bool]
forall a. a -> [a] -> [a]
: (LHsTupArg GhcPs -> ToBriDocM Bool)
-> [LHsTupArg GhcPs] -> [ToBriDocM Bool]
forall a b. (a -> b) -> [a] -> [b]
map LHsTupArg GhcPs -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow [LHsTupArg GhcPs]
args
        )
      let (ToBriDocM BriDocNumbered
openLit, ToBriDocM BriDocNumbered
closeLit) = case Boxity
boxity of
            Boxity
Boxed   -> (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"(", Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
")")
            Boxity
Unboxed -> (ToBriDocM BriDocNumbered
docParenHashLSep, ToBriDocM BriDocNumbered
docParenHashRSep)
      case [ToBriDocM BriDocNumbered]
-> FirstLastView (ToBriDocM BriDocNumbered)
forall a. [a] -> FirstLastView a
splitFirstLast [ToBriDocM BriDocNumbered]
argDocs of
        FirstLastView (ToBriDocM BriDocNumbered)
FirstLastEmpty -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
          [ ToBriDocM BriDocNumbered
openLit
          , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenP) ToBriDocM BriDocNumbered
closeLit
          ]
        FirstLastSingleton ToBriDocM BriDocNumbered
e -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
          [ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColTuple
            [ ToBriDocM BriDocNumbered
openLit
            , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenP) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e
            , ToBriDocM BriDocNumbered
closeLit
            ]
          , 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
docSeq
              [ ToBriDocM BriDocNumbered
openLit
              , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenP) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e
              ]
            , ToBriDocM BriDocNumbered
closeLit
            ]
          ]
        FirstLast ToBriDocM BriDocNumbered
e1 [ToBriDocM BriDocNumbered]
ems ToBriDocM BriDocNumbered
eN -> 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
$  ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColTuple
            ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$  [[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
openLit, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e1]]
            [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ ([ToBriDocM BriDocNumbered]
ems [ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ToBriDocM BriDocNumbered
e -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
docCommaSep, ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e])
            [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [[ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
docCommaSep, Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenP) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
eN), ToBriDocM BriDocNumbered
closeLit]]
          ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$
            let
              start :: ToBriDocM BriDocNumbered
start = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColTuples
                        [ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
openLit, ToBriDocM BriDocNumbered
e1]
              linesM :: [ToBriDocM BriDocNumbered]
linesM = [ToBriDocM BriDocNumbered]
ems [ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ToBriDocM BriDocNumbered
d ->
                      ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColTuples [ToBriDocM BriDocNumbered
docCommaSep, ToBriDocM BriDocNumbered
d]
              lineN :: ToBriDocM BriDocNumbered
lineN = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColTuples [ToBriDocM BriDocNumbered
docCommaSep, Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenP) ToBriDocM BriDocNumbered
eN]
              end :: ToBriDocM BriDocNumbered
end   = ToBriDocM BriDocNumbered
closeLit
            in 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
$ [ToBriDocM BriDocNumbered
start] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
linesM [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
lineN, ToBriDocM BriDocNumbered
end]
    HsCase XCase GhcPs
_ Located (HsExpr GhcPs)
_ XMatchGroup{} ->
      String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: HsCase XMatchGroup"
    HsCase XCase GhcPs
_ Located (HsExpr GhcPs)
cExp (MG XMG GhcPs (Located (HsExpr GhcPs))
_ (L SrcSpan
_ []) Origin
_) -> do
      ToBriDocM BriDocNumbered
cExpDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
cExp
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ 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 -> 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
"case"
            , 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
cExpDoc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"of {}"
            ]
        , ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
            ( BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"case") ToBriDocM BriDocNumbered
cExpDoc
            )
            (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"of {}")
        ]
    HsCase XCase GhcPs
_ Located (HsExpr GhcPs)
cExp (MG XMG GhcPs (Located (HsExpr GhcPs))
_ lmatches :: GenLocated SrcSpan [LMatch GhcPs (Located (HsExpr GhcPs))]
lmatches@(L SrcSpan
_ [LMatch GhcPs (Located (HsExpr GhcPs))]
matches) Origin
_) -> do
      ToBriDocM BriDocNumbered
cExpDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
cExp
      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 [LMatch GhcPs (Located (HsExpr 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 [LMatch GhcPs (Located (HsExpr 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 (Located (HsExpr GhcPs))
-> ToBriDocM BriDocNumbered
layoutPatternBind Maybe Text
forall a. Maybe a
Nothing BriDocNumbered
binderDoc (LMatch GhcPs (Located (HsExpr GhcPs)) -> ToBriDocM BriDocNumbered)
-> [LMatch GhcPs (Located (HsExpr 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 (Located (HsExpr GhcPs))]
matches
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
        [ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
          ( [ToBriDocM BriDocNumbered] -> 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
"case"
            , 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
cExpDoc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"of"
            ])
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
funcPatDocs)
        , ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
            ( BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"case") ToBriDocM BriDocNumbered
cExpDoc
            )
            ( BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"of")
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
funcPatDocs)
            )
        ]
    HsIf XIf GhcPs
_ Maybe (SyntaxExpr GhcPs)
_ Located (HsExpr GhcPs)
ifExpr Located (HsExpr GhcPs)
thenExpr Located (HsExpr GhcPs)
elseExpr -> do
      ToBriDocM BriDocNumbered
ifExprDoc   <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
ifExpr
      ToBriDocM BriDocNumbered
thenExprDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
thenExpr
      ToBriDocM BriDocNumbered
elseExprDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
elseExpr
      Bool
hasComments <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (HsExpr GhcPs)
lexpr
      let maySpecialIndent :: BrIndent
maySpecialIndent =
            case IndentPolicy
indentPolicy of
              IndentPolicy
IndentPolicyLeft -> BrIndent
BrIndentRegular
              IndentPolicy
IndentPolicyMultiple -> BrIndent
BrIndentRegular
              IndentPolicy
IndentPolicyFree -> Int -> BrIndent
BrIndentSpecial Int
3
      -- TODO: some of the alternatives (especially last and last-but-one)
      -- overlap.
      ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetIndentLevel (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
        -- if _ then _ else _
        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 -> 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
"if"
          , 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
ifExprDoc
          , 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
"then"
          , 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
thenExprDoc
          , 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
"else"
          , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
elseExprDoc
          ]
        -- either
        --   if expr
        --   then foo
        --     bar
        --   else foo
        --     bar
        -- or
        --   if expr
        --   then
        --     stuff
        --   else
        --     stuff
        -- note that this has par-spacing
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
              ( [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
                [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing (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
"if"
                , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnIf) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
ifExprDoc
                ])
              ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
                [ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnThen)
                (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
docAlt
                  [ [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
"then", ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
thenExprDoc]
                  , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"then") ToBriDocM BriDocNumbered
thenExprDoc
                  ]
                , 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
docNonBottomSpacing (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
                  [ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [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
"else", ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
elseExprDoc]
                  , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"else") ToBriDocM BriDocNumbered
elseExprDoc
                  ]
                ])
        -- either
        --   if multi
        --      line
        --      condition
        --   then foo
        --     bar
        --   else foo
        --     bar
        -- or
        --   if multi
        --      line
        --      condition
        --   then
        --     stuff
        --   else
        --     stuff
        -- note that this does _not_ have par-spacing
        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
              ( BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
maySpecialIndent
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
                [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing (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
"if"
                , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnIf) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
ifExprDoc
                ])
              ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
                [ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnThen)
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
                  [ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [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
"then", ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
thenExprDoc]
                  , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"then") ToBriDocM BriDocNumbered
thenExprDoc
                  ]
                , 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
docAlt
                  [ [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
"else", ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceParSpacing ToBriDocM BriDocNumbered
elseExprDoc]
                  , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"else") ToBriDocM BriDocNumbered
elseExprDoc
                  ]
                ])
        ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
          (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ 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
            [ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
maySpecialIndent
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
              [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing (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
"if"
              , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnIf) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
ifExprDoc
              ]
            , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnThen)
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"then") ToBriDocM BriDocNumbered
thenExprDoc
            , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"else") ToBriDocM BriDocNumbered
elseExprDoc
            ]
    HsMultiIf XMultiIf GhcPs
_ [LGRHS GhcPs (Located (HsExpr GhcPs))]
cases -> do
      [([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs))]
clauseDocs  <- [LGRHS GhcPs (Located (HsExpr GhcPs))]
cases [LGRHS GhcPs (Located (HsExpr GhcPs))]
-> (LGRHS GhcPs (Located (HsExpr GhcPs))
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         ([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs)))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` LGRHS GhcPs (Located (HsExpr GhcPs))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     ([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs))
layoutGrhs
      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 <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (HsExpr GhcPs)
lexpr
      ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
        (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"if")
        (Maybe Text
-> BriDocNumbered
-> Maybe BriDocNumbered
-> [([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs))]
-> Maybe (AnnKey, [BriDocNumbered])
-> Bool
-> ToBriDocM BriDocNumbered
layoutPatternBindFinal Maybe Text
forall a. Maybe a
Nothing BriDocNumbered
binderDoc Maybe BriDocNumbered
forall a. Maybe a
Nothing [([BriDocNumbered], BriDocNumbered, Located (HsExpr GhcPs))]
clauseDocs Maybe (AnnKey, [BriDocNumbered])
forall a. Maybe a
Nothing Bool
hasComments)
    HsLet XLet GhcPs
_ LHsLocalBinds GhcPs
binds Located (HsExpr GhcPs)
exp1 -> do
      ToBriDocM BriDocNumbered
expDoc1     <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
exp1
      -- We jump through some ugly hoops here to ensure proper sharing.
      Bool
hasComments <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (HsExpr GhcPs)
lexpr
      Maybe [ToBriDocM BriDocNumbered]
mBindDocs   <- (Maybe [BriDocNumbered] -> Maybe [ToBriDocM BriDocNumbered])
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe [BriDocNumbered])
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe [ToBriDocM BriDocNumbered])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> Maybe [BriDocNumbered] -> Maybe [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [BriDocNumbered] -> [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)) (MultiRWST
   '[Config, Anns]
   '[[BrittanyError], Seq String]
   '[NodeAllocIndex]
   Identity
   (Maybe [BriDocNumbered])
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (Maybe [ToBriDocM BriDocNumbered]))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe [BriDocNumbered])
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe [ToBriDocM BriDocNumbered])
forall a b. (a -> b) -> a -> b
$ ToBriDocC (HsLocalBindsLR GhcPs GhcPs) (Maybe [BriDocNumbered])
layoutLocalBinds LHsLocalBinds GhcPs
binds
      let
        ifIndentFreeElse :: a -> a -> a
        ifIndentFreeElse :: a -> a -> a
ifIndentFreeElse a
x a
y =
          case IndentPolicy
indentPolicy of
            IndentPolicy
IndentPolicyLeft -> a
y
            IndentPolicy
IndentPolicyMultiple -> a
y
            IndentPolicy
IndentPolicyFree -> a
x
      -- this `docSetBaseAndIndent` might seem out of place (especially the
      -- Indent part; setBase is necessary due to the use of docLines below),
      -- but is here due to ghc-exactprint's DP handling of "let" in
      -- particular.
      -- Just pushing another indentation level is a straightforward approach
      -- to making brittany idempotent, even though the result is non-optimal
      -- if "let" is moved horizontally as part of the transformation, as the
      -- comments before the first let item are moved horizontally with it.
      ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case Maybe [ToBriDocM BriDocNumbered]
mBindDocs of
        Just [ToBriDocM BriDocNumbered
bindDoc] -> 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 -> 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
"let"
            , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnLet)
              (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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
bindDoc
            , 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
"in"
            , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
expDoc1
            ]
          ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
            [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnLet)
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
                [ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
                    [ 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
"let"
                    , (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall a. a -> a -> a
ifIndentFreeElse ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline
                    (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
bindDoc
                    ]
                , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
                  (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"let")
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent ToBriDocM BriDocNumbered
bindDoc)
                ]
            , [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
                [ [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 -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ String -> String -> String
forall a. a -> a -> a
ifIndentFreeElse String
"in " String
"in"
                    , (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall a. a -> a -> a
ifIndentFreeElse ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
expDoc1
                    ]
                , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
                  (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"in")
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
expDoc1)
                ]
            ]
        Just bindDocs :: [ToBriDocM BriDocNumbered]
bindDocs@(ToBriDocM BriDocNumbered
_:[ToBriDocM BriDocNumbered]
_) -> CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
          --either
          --  let
          --    a = b
          --    c = d
          --  in foo
          --    bar
          --    baz
          --or
          --  let
          --    a = b
          --    c = d
          --  in
          --    fooooooooooooooooooo
          let noHangingBinds :: [ToBriDocM BriDocNumbered]
noHangingBinds =
                [ 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
docAddBaseY BrIndent
BrIndentRegular
                (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
                  (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"let")
                  (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered]
bindDocs)
                , [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
"in "
                  , 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
expDoc1
                  ]
                ]
          ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ case IndentPolicy
indentPolicy of
            IndentPolicy
IndentPolicyLeft     -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered]
noHangingBinds
            IndentPolicy
IndentPolicyMultiple -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered]
noHangingBinds
            IndentPolicy
IndentPolicyFree     -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
              [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnLet)
              (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
"let"
                , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines [ToBriDocM BriDocNumbered]
bindDocs
                ]
              , [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
"in "
                , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY ToBriDocM BriDocNumbered
expDoc1
                ]
              ]
          ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
            (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docLines
            [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnLet)
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
              (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"let")
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
bindDocs)
            , BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
              (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"in")
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
expDoc1)
            ]
        Maybe [ToBriDocM BriDocNumbered]
_ -> [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
"let in", ToBriDocM BriDocNumbered
expDoc1]
      -- docSeq [appSep $ docLit "let in", expDoc1]
    HsDo XDo GhcPs
_ HsStmtContext Name
stmtCtx (L SrcSpan
_ [GuardLStmt GhcPs]
stmts) -> case HsStmtContext Name
stmtCtx of
      HsStmtContext Name
DoExpr -> do
        [ToBriDocM BriDocNumbered]
stmtDocs <- (GuardLStmt GhcPs -> ToBriDocM BriDocNumbered)
-> GuardLStmt 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 GuardLStmt GhcPs -> ToBriDocM BriDocNumbered
layoutStmt (GuardLStmt GhcPs
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (ToBriDocM BriDocNumbered))
-> [GuardLStmt 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` [GuardLStmt GhcPs]
stmts
        ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
              (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"do")
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
stmtDocs)
      HsStmtContext Name
MDoExpr -> do
        [ToBriDocM BriDocNumbered]
stmtDocs <- (GuardLStmt GhcPs -> ToBriDocM BriDocNumbered)
-> GuardLStmt 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 GuardLStmt GhcPs -> ToBriDocM BriDocNumbered
layoutStmt (GuardLStmt GhcPs
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (ToBriDocM BriDocNumbered))
-> [GuardLStmt 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` [GuardLStmt GhcPs]
stmts
        ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
          (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
              (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"mdo")
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseAndIndent (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]
stmtDocs)
      HsStmtContext Name
x | case HsStmtContext Name
x of { HsStmtContext Name
ListComp -> Bool
True
                    ; HsStmtContext Name
MonadComp -> Bool
True
                    ; HsStmtContext Name
_ -> Bool
False } -> do
        [ToBriDocM BriDocNumbered]
stmtDocs    <- (GuardLStmt GhcPs -> ToBriDocM BriDocNumbered)
-> GuardLStmt 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 GuardLStmt GhcPs -> ToBriDocM BriDocNumbered
layoutStmt (GuardLStmt GhcPs
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (ToBriDocM BriDocNumbered))
-> [GuardLStmt 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` [GuardLStmt GhcPs]
stmts
        Bool
hasComments <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (HsExpr GhcPs)
lexpr
        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
            [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing
            (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
"["
            , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS)
            (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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline
            (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a. [a] -> a
List.last [ToBriDocM BriDocNumbered]
stmtDocs
            , 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
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
            ([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ 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] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a]
List.init [ToBriDocM BriDocNumbered]
stmtDocs
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
" ]"
            ]
          ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$
            let
              start :: ToBriDocM BriDocNumbered
start = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColListComp
                        [ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing
                        (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
docSetBaseY
                        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS)
                        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a. [a] -> a
List.last [ToBriDocM BriDocNumbered]
stmtDocs
                        ]
              (ToBriDocM BriDocNumbered
s1:[ToBriDocM BriDocNumbered]
sM) = [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a]
List.init [ToBriDocM BriDocNumbered]
stmtDocs
              line1 :: ToBriDocM BriDocNumbered
line1 = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColListComp
                        [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
s1]
              lineM :: [ToBriDocM BriDocNumbered]
lineM = [ToBriDocM BriDocNumbered]
sM [ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ToBriDocM BriDocNumbered
d ->
                      ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColListComp [ToBriDocM BriDocNumbered
docCommaSep, ToBriDocM BriDocNumbered
d]
              end :: ToBriDocM BriDocNumbered
end   = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"]"
            in 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
$ [ToBriDocM BriDocNumbered
start, ToBriDocM BriDocNumbered
line1] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
lineM [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
end]
      HsStmtContext Name
_ -> do
        -- TODO
        String -> ToBriDoc HsExpr
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"HsDo{} unknown stmtCtx" Located (HsExpr GhcPs)
lexpr
    ExplicitList XExplicitList GhcPs
_ Maybe (SyntaxExpr GhcPs)
_ elems :: [Located (HsExpr GhcPs)]
elems@(Located (HsExpr GhcPs)
_:[Located (HsExpr GhcPs)]
_) -> do
      [ToBriDocM BriDocNumbered]
elemDocs    <- [Located (HsExpr GhcPs)]
elems [Located (HsExpr GhcPs)]
-> (Located (HsExpr GhcPs)
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [ToBriDocM BriDocNumbered]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` ToBriDoc HsExpr
-> Located (HsExpr 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
      Bool
hasComments <- Located (HsExpr GhcPs) -> ToBriDocM Bool
forall ast. Data ast => Located ast -> ToBriDocM Bool
hasAnyCommentsBelow Located (HsExpr GhcPs)
lexpr
      case [ToBriDocM BriDocNumbered]
-> FirstLastView (ToBriDocM BriDocNumbered)
forall a. [a] -> FirstLastView a
splitFirstLast [ToBriDocM BriDocNumbered]
elemDocs of
        FirstLastView (ToBriDocM BriDocNumbered)
FirstLastEmpty -> [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
"["
          , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS) (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
"]"
          ]
        FirstLastSingleton ToBriDocM BriDocNumbered
e -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docAlt
          [ [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
"["
            , Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e
            , 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
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
docSeq
              [ Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"["
              , ToBriDocM BriDocNumbered
docSeparator
              , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetBaseY (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS) ToBriDocM BriDocNumbered
e
              ]
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"]"
            ]
          ]
        FirstLast ToBriDocM BriDocNumbered
e1 [ToBriDocM BriDocNumbered]
ems ToBriDocM BriDocNumbered
eN -> 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] -> 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)
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ToBriDocM BriDocNumbered
e1ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
:[ToBriDocM BriDocNumbered]
ems [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS) ToBriDocM BriDocNumbered
eN]))
            [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 -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$
            let
              start :: ToBriDocM BriDocNumbered
start = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColList
                        [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
e1]
              linesM :: [ToBriDocM BriDocNumbered]
linesM = [ToBriDocM BriDocNumbered]
ems [ToBriDocM BriDocNumbered]
-> (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \ToBriDocM BriDocNumbered
d ->
                      ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColList [ToBriDocM BriDocNumbered
docCommaSep, ToBriDocM BriDocNumbered
d]
              lineN :: ToBriDocM BriDocNumbered
lineN = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColList [ToBriDocM BriDocNumbered
docCommaSep, Located (HsExpr GhcPs)
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW Located (HsExpr GhcPs)
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenS) ToBriDocM BriDocNumbered
eN]
              end :: ToBriDocM BriDocNumbered
end   = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"]"
            in 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
$ [ToBriDocM BriDocNumbered
start] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
linesM [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
lineN] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
end]
    ExplicitList XExplicitList GhcPs
_ Maybe (SyntaxExpr GhcPs)
_ [] ->
      Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"[]"
    RecordCon XRecordCon GhcPs
_ Located (IdP GhcPs)
lname HsRecordBinds GhcPs
fields ->
      case HsRecordBinds GhcPs
fields of
        HsRecFields [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs Maybe (Located Int)
Nothing -> do
          let nameDoc :: ToBriDocM BriDocNumbered
nameDoc = Located RdrName
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (IdP GhcPs)
Located RdrName
lname (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
$ Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located (IdP GhcPs)
Located RdrName
lname
          [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
  Maybe (ToBriDocM BriDocNumbered))]
rFs <- [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs
            [LHsRecField GhcPs (Located (HsExpr GhcPs))]
-> (LHsRecField GhcPs (Located (HsExpr GhcPs))
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
          Maybe (ToBriDocM BriDocNumbered)))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
       Maybe (ToBriDocM BriDocNumbered))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \lfield :: LHsRecField GhcPs (Located (HsExpr GhcPs))
lfield@(L SrcSpan
_ (HsRecField (L SrcSpan
_ FieldOcc GhcPs
fieldOcc) Located (HsExpr GhcPs)
rFExpr Bool
pun)) -> do
              let FieldOcc XCFieldOcc GhcPs
_ Located RdrName
lnameF = FieldOcc GhcPs
fieldOcc
              Maybe (ToBriDocM BriDocNumbered)
rFExpDoc <- if Bool
pun
                then Maybe (ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
                else 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)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
rFExpr
              (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
 Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
      Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return ((LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
  Maybe (ToBriDocM BriDocNumbered))
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
       Maybe (ToBriDocM BriDocNumbered)))
-> (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
    Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
      Maybe (ToBriDocM BriDocNumbered))
forall a b. (a -> b) -> a -> b
$ (LHsRecField GhcPs (Located (HsExpr GhcPs))
lfield, Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located RdrName
lnameF, Maybe (ToBriDocM BriDocNumbered)
rFExpDoc)
          Bool
-> IndentPolicy
-> Located (HsExpr GhcPs)
-> ToBriDocM BriDocNumbered
-> [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
forall lExpr name.
(Data lExpr, Data name) =>
Bool
-> IndentPolicy
-> GenLocated SrcSpan lExpr
-> ToBriDocM BriDocNumbered
-> [(GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
recordExpression Bool
False IndentPolicy
indentPolicy Located (HsExpr GhcPs)
lexpr ToBriDocM BriDocNumbered
nameDoc [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
  Maybe (ToBriDocM BriDocNumbered))]
rFs
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
        HsRecFields [] (Just (L SrcSpan
_ Int
0)) -> do
#else
        HsRecFields [] (Just 0) -> do
#endif
          let t :: Text
t = Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located (IdP GhcPs)
Located RdrName
lname
          Located RdrName
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (IdP GhcPs)
Located RdrName
lname (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
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
" { .. }"
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
        HsRecFields fs :: [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs@(LHsRecField GhcPs (Located (HsExpr GhcPs))
_:[LHsRecField GhcPs (Located (HsExpr GhcPs))]
_) (Just (L SrcSpan
_ Int
dotdoti)) | Int
dotdoti Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [LHsRecField GhcPs (Located (HsExpr GhcPs))] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs -> do
#else
        HsRecFields fs@(_:_) (Just dotdoti) | dotdoti == length fs -> do
#endif
          let nameDoc :: ToBriDocM BriDocNumbered
nameDoc = Located RdrName
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode Located (IdP GhcPs)
Located RdrName
lname (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
$ Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located (IdP GhcPs)
Located RdrName
lname
          [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
  Maybe (ToBriDocM BriDocNumbered))]
fieldDocs <- [LHsRecField GhcPs (Located (HsExpr GhcPs))]
fs [LHsRecField GhcPs (Located (HsExpr GhcPs))]
-> (LHsRecField GhcPs (Located (HsExpr GhcPs))
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
          Maybe (ToBriDocM BriDocNumbered)))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
       Maybe (ToBriDocM BriDocNumbered))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \fieldl :: LHsRecField GhcPs (Located (HsExpr GhcPs))
fieldl@(L SrcSpan
_ (HsRecField (L SrcSpan
_ FieldOcc GhcPs
fieldOcc) Located (HsExpr GhcPs)
fExpr Bool
pun)) -> do
            let FieldOcc XCFieldOcc GhcPs
_ Located RdrName
lnameF = FieldOcc GhcPs
fieldOcc
            Maybe (ToBriDocM BriDocNumbered)
fExpDoc <- if Bool
pun
              then Maybe (ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
              else 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)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
fExpr
            (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
 Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
      Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return (LHsRecField GhcPs (Located (HsExpr GhcPs))
fieldl, Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located RdrName
lnameF, Maybe (ToBriDocM BriDocNumbered)
fExpDoc)
          Bool
-> IndentPolicy
-> Located (HsExpr GhcPs)
-> ToBriDocM BriDocNumbered
-> [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
forall lExpr name.
(Data lExpr, Data name) =>
Bool
-> IndentPolicy
-> GenLocated SrcSpan lExpr
-> ToBriDocM BriDocNumbered
-> [(GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
recordExpression Bool
True IndentPolicy
indentPolicy Located (HsExpr GhcPs)
lexpr ToBriDocM BriDocNumbered
nameDoc [(LHsRecField GhcPs (Located (HsExpr GhcPs)), Text,
  Maybe (ToBriDocM BriDocNumbered))]
fieldDocs
        HsRecordBinds GhcPs
_ -> String -> ToBriDoc HsExpr
forall ast.
Data ast =>
String -> GenLocated SrcSpan ast -> ToBriDocM BriDocNumbered
unknownNodeError String
"RecordCon with puns" Located (HsExpr GhcPs)
lexpr
    RecordUpd XRecordUpd GhcPs
_ Located (HsExpr GhcPs)
rExpr [LHsRecUpdField GhcPs]
fields -> do
      ToBriDocM BriDocNumbered
rExprDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
rExpr
      [(LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))]
rFs <- [LHsRecUpdField GhcPs]
fields
        [LHsRecUpdField GhcPs]
-> (LHsRecUpdField GhcPs
    -> MultiRWST
         '[Config, Anns]
         '[[BrittanyError], Seq String]
         '[NodeAllocIndex]
         Identity
         (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered)))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     [(LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
`forM` \lfield :: LHsRecUpdField GhcPs
lfield@(L SrcSpan
_ (HsRecField (L SrcSpan
_ AmbiguousFieldOcc GhcPs
ambName) Located (HsExpr GhcPs)
rFExpr Bool
pun)) -> do
          Maybe (ToBriDocM BriDocNumbered)
rFExpDoc <- if Bool
pun
            then Maybe (ToBriDocM BriDocNumbered)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (ToBriDocM BriDocNumbered)
forall a. Maybe a
Nothing
            else 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)
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (Maybe (ToBriDocM BriDocNumbered))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
rFExpr
          (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
forall (m :: * -> *) a. Monad m => a -> m a
return ((LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
 -> MultiRWST
      '[Config, Anns]
      '[[BrittanyError], Seq String]
      '[NodeAllocIndex]
      Identity
      (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered)))
-> (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
-> MultiRWST
     '[Config, Anns]
     '[[BrittanyError], Seq String]
     '[NodeAllocIndex]
     Identity
     (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
forall a b. (a -> b) -> a -> b
$ case AmbiguousFieldOcc GhcPs
ambName of
            Unambiguous XUnambiguous GhcPs
_ Located RdrName
n -> (LHsRecUpdField GhcPs
lfield, Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located RdrName
n, Maybe (ToBriDocM BriDocNumbered)
rFExpDoc)
            Ambiguous   XAmbiguous GhcPs
_ Located RdrName
n -> (LHsRecUpdField GhcPs
lfield, Located RdrName -> Text
forall l. GenLocated l RdrName -> Text
lrdrNameToText Located RdrName
n, Maybe (ToBriDocM BriDocNumbered)
rFExpDoc)
            XAmbiguousFieldOcc{} ->
              String
-> (LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))
forall a. HasCallStack => String -> a
error String
"brittany internal error: XAmbiguousFieldOcc"
      Bool
-> IndentPolicy
-> Located (HsExpr GhcPs)
-> ToBriDocM BriDocNumbered
-> [(LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
forall lExpr name.
(Data lExpr, Data name) =>
Bool
-> IndentPolicy
-> GenLocated SrcSpan lExpr
-> ToBriDocM BriDocNumbered
-> [(GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
recordExpression Bool
False IndentPolicy
indentPolicy Located (HsExpr GhcPs)
lexpr ToBriDocM BriDocNumbered
rExprDoc [(LHsRecUpdField GhcPs, Text, Maybe (ToBriDocM BriDocNumbered))]
rFs
#if MIN_VERSION_ghc(8,8,0)   /* ghc-8.6 */
    ExprWithTySig XExprWithTySig GhcPs
_ Located (HsExpr GhcPs)
_ (HsWC XHsWC (NoGhcTc GhcPs) (LHsSigType (NoGhcTc GhcPs))
_ XHsImplicitBndrs{}) ->
      String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: ExprWithTySig HsWC XHsImplicitBndrs"
    ExprWithTySig XExprWithTySig GhcPs
_ Located (HsExpr GhcPs)
_ XHsWildCardBndrs{} ->
      String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: ExprWithTySig XHsWildCardBndrs"
    ExprWithTySig XExprWithTySig GhcPs
_ Located (HsExpr GhcPs)
exp1 (HsWC XHsWC (NoGhcTc GhcPs) (LHsSigType (NoGhcTc GhcPs))
_ (HsIB XHsIB (NoGhcTc GhcPs) (LHsType (NoGhcTc GhcPs))
_ LHsType (NoGhcTc GhcPs)
typ1)) -> do
#else
    ExprWithTySig (HsWC _ XHsImplicitBndrs{}) _ ->
      error "brittany internal error: ExprWithTySig HsWC XHsImplicitBndrs"
    ExprWithTySig XHsWildCardBndrs{} _ ->
      error "brittany internal error: ExprWithTySig XHsWildCardBndrs"
    ExprWithTySig (HsWC _ (HsIB _ typ1)) exp1 -> do
#endif
      ToBriDocM BriDocNumbered
expDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
exp1
      ToBriDocM BriDocNumbered
typDoc <- (Located (HsType GhcPs) -> ToBriDocM BriDocNumbered)
-> Located (HsType 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 Located (HsType GhcPs) -> ToBriDocM BriDocNumbered
layoutType Located (HsType GhcPs)
LHsType (NoGhcTc GhcPs)
typ1
      [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
        [ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep ToBriDocM BriDocNumbered
expDoc
        , 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
typDoc
        ]
    ArithSeq XArithSeq GhcPs
_ Maybe (SyntaxExpr GhcPs)
Nothing ArithSeqInfo GhcPs
info ->
      case ArithSeqInfo GhcPs
info of
        From Located (HsExpr GhcPs)
e1 -> do
          ToBriDocM BriDocNumbered
e1Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e1
          [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
"["
            , 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
e1Doc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"..]"
            ]
        FromThen Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 -> do
          ToBriDocM BriDocNumbered
e1Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e1
          ToBriDocM BriDocNumbered
e2Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e2
          [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
"["
            , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e1Doc
            , 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e2Doc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"..]"
            ]
        FromTo Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
eN -> do
          ToBriDocM BriDocNumbered
e1Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e1
          ToBriDocM BriDocNumbered
eNDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
eN
          [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
"["
            , 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
e1Doc
            , 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
eNDoc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"]"
            ]
        FromThenTo Located (HsExpr GhcPs)
e1 Located (HsExpr GhcPs)
e2 Located (HsExpr GhcPs)
eN -> do
          ToBriDocM BriDocNumbered
e1Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e1
          ToBriDocM BriDocNumbered
e2Doc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
e2
          ToBriDocM BriDocNumbered
eNDoc <- ToBriDoc HsExpr
-> Located (HsExpr 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 Located (HsExpr GhcPs)
eN
          [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
"["
            , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e1Doc
            , 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
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
e2Doc
            , 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
eNDoc
            , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"]"
            ]
    ArithSeq{} ->
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"ArithSeq" Located (HsExpr GhcPs)
lexpr
    HsSCC{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsSCC{}" Located (HsExpr GhcPs)
lexpr
    HsCoreAnn{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsCoreAnn{}" Located (HsExpr GhcPs)
lexpr
    HsBracket{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsBracket{}" Located (HsExpr GhcPs)
lexpr
    HsRnBracketOut{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsRnBracketOut{}" Located (HsExpr GhcPs)
lexpr
    HsTcBracketOut{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsTcBracketOut{}" Located (HsExpr GhcPs)
lexpr
    HsSpliceE XSpliceE GhcPs
_ (HsQuasiQuote XQuasiQuote GhcPs
_ IdP GhcPs
_ IdP GhcPs
quoter SrcSpan
_loc FastString
content) -> do
      BriDocFInt -> ToBriDocM BriDocNumbered
forall (m :: * -> *).
MonadMultiState NodeAllocIndex m =>
BriDocFInt -> m BriDocNumbered
allocateNode (BriDocFInt -> ToBriDocM BriDocNumbered)
-> BriDocFInt -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFPlain
        (String -> Text
Text.pack
          (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$  String
"["
          String -> String -> String
forall a. [a] -> [a] -> [a]
++ RdrName -> String
forall a. Outputable a => a -> String
showOutputable IdP GhcPs
RdrName
quoter
          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|"
          String -> String -> String
forall a. [a] -> [a] -> [a]
++ FastString -> String
forall a. Outputable a => a -> String
showOutputable FastString
content
          String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|]")
    HsSpliceE{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsSpliceE{}" Located (HsExpr GhcPs)
lexpr
    HsProc{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsProc{}" Located (HsExpr GhcPs)
lexpr
    HsStatic{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsStatic{}" Located (HsExpr GhcPs)
lexpr
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
#else
    HsArrApp{} -> do
      -- TODO
      briDocByExactInlineOnly "HsArrApp{}" lexpr
    HsArrForm{} -> do
      -- TODO
      briDocByExactInlineOnly "HsArrForm{}" lexpr
#endif
    HsTick{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsTick{}" Located (HsExpr GhcPs)
lexpr
    HsBinTick{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsBinTick{}" Located (HsExpr GhcPs)
lexpr
    HsTickPragma{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsTickPragma{}" Located (HsExpr GhcPs)
lexpr
#if MIN_VERSION_ghc(8,10,1)   /* ghc-8.10.1 */
#else
    EWildPat{} -> do
      docLit $ Text.pack "_"
    EAsPat _ asName asExpr -> do
      docSeq
        [ docLit $ lrdrNameToText asName <> Text.pack "@"
        , layoutExpr asExpr
        ]
    EViewPat{} -> do
      -- TODO
      briDocByExactInlineOnly "EViewPat{}" lexpr
    ELazyPat{} -> do
      -- TODO
      briDocByExactInlineOnly "ELazyPat{}" lexpr
#endif
    HsWrap{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsWrap{}" Located (HsExpr GhcPs)
lexpr
    HsConLikeOut{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"HsWrap{}" Located (HsExpr GhcPs)
lexpr
    ExplicitSum{} -> do
      -- TODO
      String -> ToBriDoc HsExpr
forall ast.
(Annotate ast, Data ast) =>
String -> Located ast -> ToBriDocM BriDocNumbered
briDocByExactInlineOnly String
"ExplicitSum{}" Located (HsExpr GhcPs)
lexpr
    XExpr{} -> String -> ToBriDocM BriDocNumbered
forall a. HasCallStack => String -> a
error String
"brittany internal error: XExpr"

recordExpression
  :: (Data.Data.Data lExpr, Data.Data.Data name)
  => Bool
  -> IndentPolicy
  -> GenLocated SrcSpan lExpr
  -> ToBriDocM BriDocNumbered
  -> [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
  -> ToBriDocM BriDocNumbered
recordExpression :: Bool
-> IndentPolicy
-> GenLocated SrcSpan lExpr
-> ToBriDocM BriDocNumbered
-> [(GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))]
-> ToBriDocM BriDocNumbered
recordExpression Bool
False IndentPolicy
_ GenLocated SrcSpan lExpr
lexpr ToBriDocM BriDocNumbered
nameDoc [] =
  [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
    [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
nameDoc, Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"{"]
    , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"}"
    ]
recordExpression Bool
True IndentPolicy
_ GenLocated SrcSpan lExpr
lexpr ToBriDocM BriDocNumbered
nameDoc [] =
  [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq -- this case might still be incomplete, and is probably not used
         -- atm anyway.
    [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ToBriDocM BriDocNumbered
nameDoc, Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"{"]
    , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
" .. }"
    ]
recordExpression Bool
dotdot IndentPolicy
indentPolicy GenLocated SrcSpan lExpr
lexpr ToBriDocM BriDocNumbered
nameDoc rFs :: [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
rFs@((GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))
rF1:[(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
rFr) = do
  let (GenLocated SrcSpan name
rF1f, Text
rF1n, Maybe (ToBriDocM BriDocNumbered)
rF1e) = (GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))
rF1
  CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
    -- container { fieldA = blub, fieldB = blub }
    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
      (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
      [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing (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
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
nameDoc
      , 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
docSeq ([ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. a -> [a] -> [a]
List.intersperse ToBriDocM BriDocNumbered
docCommaSep
              ([ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered])
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a b. (a -> b) -> a -> b
$ [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
rFs [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
-> ((GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))
    -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
                (GenLocated SrcSpan name
lfield, Text
fieldStr, Just ToBriDocM BriDocNumbered
fieldDoc) ->
                  GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan name
lfield (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq
                        [ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
appSep (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
fieldStr
                        , 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
fieldDoc
                        ]
                (GenLocated SrcSpan name
lfield, Text
fieldStr, Maybe (ToBriDocM BriDocNumbered)
Nothing) ->
                  GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan name
lfield (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ Text -> ToBriDocM BriDocNumbered
docLit Text
fieldStr
      , if Bool
dotdot
          then [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docSeq [ ToBriDocM BriDocNumbered
docCommaSep, Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"..", ToBriDocM BriDocNumbered
docSeparator]
          else ToBriDocM BriDocNumbered
docSeparator
      , Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"}"
      ]
    -- hanging single-line fields
    -- container { fieldA = blub
    --           , fieldB = blub
    --           }
    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
docSeq
      [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing (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
appSep ToBriDocM BriDocNumbered
nameDoc
      , 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
$ let
          line1 :: ToBriDocM BriDocNumbered
line1 = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
            [ 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
"{"
            , GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior GenLocated SrcSpan name
rF1f (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
rF1n
            , case Maybe (ToBriDocM BriDocNumbered)
rF1e of
                Just ToBriDocM BriDocNumbered
x -> GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan name
rF1f (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
"="
                                , ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docForceSingleline ToBriDocM BriDocNumbered
x
                                ]
                Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
            ]
          lineR :: [ToBriDocM BriDocNumbered]
lineR = [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
rFr [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
-> ((GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))
    -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(GenLocated SrcSpan name
lfield, Text
fText, Maybe (ToBriDocM BriDocNumbered)
fDoc) -> GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan name
lfield (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
            [ ToBriDocM BriDocNumbered
docCommaSep
            , 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
fText
            , case Maybe (ToBriDocM BriDocNumbered)
fDoc of
                Just ToBriDocM BriDocNumbered
x ->  [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
x
                                  ]
                Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
            ]
          dotdotLine :: ToBriDocM BriDocNumbered
dotdotLine = if Bool
dotdot
            then ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
                   [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) ToBriDocM BriDocNumbered
docCommaSep
                   , GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnDotdot)
                     (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
".."
                   ]
            else GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) ToBriDocM BriDocNumbered
docEmpty
          lineN :: ToBriDocM BriDocNumbered
lineN = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"}"
          in [ToBriDocM BriDocNumbered
line1] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
lineR [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
dotdotLine, ToBriDocM BriDocNumbered
lineN]
      ]
    -- non-hanging with expressions placed to the right of the names
    -- container
    -- { fieldA = blub
    -- , fieldB = potentially
    --     multiline
    -- }
    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative
      (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docSetParSpacing
      (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
      (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar
          (GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr Maybe AnnKeywordId
forall a. Maybe a
Nothing ToBriDocM BriDocNumbered
nameDoc)
          (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
$ let
            line1 :: ToBriDocM BriDocNumbered
line1 = ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
              [ 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
"{"
              , GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodePrior GenLocated SrcSpan name
rF1f (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
rF1n
              , GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNodeRest GenLocated SrcSpan name
rF1f (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ case Maybe (ToBriDocM BriDocNumbered)
rF1e of
                  Just ToBriDocM BriDocNumbered
x -> CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
                    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
$ do
                      [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
docSetBaseY ToBriDocM BriDocNumbered
x]
                    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
                      [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
docForceParSpacing ToBriDocM BriDocNumbered
x]
                    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
                      BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"=") ToBriDocM BriDocNumbered
x
                  Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
              ]
            lineR :: [ToBriDocM BriDocNumbered]
lineR = [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
rFr [(GenLocated SrcSpan name, Text, Maybe (ToBriDocM BriDocNumbered))]
-> ((GenLocated SrcSpan name, Text,
     Maybe (ToBriDocM BriDocNumbered))
    -> ToBriDocM BriDocNumbered)
-> [ToBriDocM BriDocNumbered]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(GenLocated SrcSpan name
lfield, Text
fText, Maybe (ToBriDocM BriDocNumbered)
fDoc) -> GenLocated SrcSpan name
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a ast. (DocWrapable a, Data ast) => Located ast -> a -> a
docWrapNode GenLocated SrcSpan name
lfield
              (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
              [ ToBriDocM BriDocNumbered
docCommaSep
              , 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
fText
              , case Maybe (ToBriDocM BriDocNumbered)
fDoc of
                  Just ToBriDocM BriDocNumbered
x -> CollectAltM () -> ToBriDocM BriDocNumbered
runFilteredAlternative (CollectAltM () -> ToBriDocM BriDocNumbered)
-> CollectAltM () -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ do
                    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
$ do
                      [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
docSetBaseY ToBriDocM BriDocNumbered
x]
                    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
                      [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
docForceParSpacing ToBriDocM BriDocNumbered
x
                             ]
                    ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternative (ToBriDocM BriDocNumbered -> CollectAltM ())
-> ToBriDocM BriDocNumbered -> CollectAltM ()
forall a b. (a -> b) -> a -> b
$ do
                      BrIndent -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAddBaseY BrIndent
BrIndentRegular
                        (ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docPar (Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"=") ToBriDocM BriDocNumbered
x
                  Maybe (ToBriDocM BriDocNumbered)
Nothing -> ToBriDocM BriDocNumbered
docEmpty
              ]
            dotdotLine :: ToBriDocM BriDocNumbered
dotdotLine = if Bool
dotdot
              then ColSig -> [ToBriDocM BriDocNumbered] -> ToBriDocM BriDocNumbered
docCols ColSig
ColRec
                     [ GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) ToBriDocM BriDocNumbered
docCommaSep
                     , GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnDotdot)
                       (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
".."
                     ]
              else GenLocated SrcSpan lExpr
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
forall ast.
Data ast =>
Located ast
-> Maybe AnnKeywordId
-> ToBriDocM BriDocNumbered
-> ToBriDocM BriDocNumbered
docNodeAnnKW GenLocated SrcSpan lExpr
lexpr (AnnKeywordId -> Maybe AnnKeywordId
forall a. a -> Maybe a
Just AnnKeywordId
AnnOpenC) ToBriDocM BriDocNumbered
docEmpty
            lineN :: ToBriDocM BriDocNumbered
lineN = Text -> ToBriDocM BriDocNumbered
docLit (Text -> ToBriDocM BriDocNumbered)
-> Text -> ToBriDocM BriDocNumbered
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
"}"
            in [ToBriDocM BriDocNumbered
line1] [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered]
lineR [ToBriDocM BriDocNumbered]
-> [ToBriDocM BriDocNumbered] -> [ToBriDocM BriDocNumbered]
forall a. [a] -> [a] -> [a]
++ [ToBriDocM BriDocNumbered
dotdotLine, ToBriDocM BriDocNumbered
lineN]
          )

litBriDoc :: HsLit GhcPs -> BriDocFInt
litBriDoc :: HsLit GhcPs -> BriDocFInt
litBriDoc = \case
  HsChar       (SourceText t) Char
_c                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ ['\'', c, '\'']
  HsCharPrim   (SourceText t) Char
_c                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ ['\'', c, '\'']
  HsString     (SourceText t) FastString
_fastString                -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ FastString.unpackFS fastString
  HsStringPrim (SourceText t) ByteString
_byteString                -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ Data.ByteString.Char8.unpack byteString
  HsInt        XHsInt GhcPs
_              (IL (SourceText String
t) Bool
_ Integer
_)    -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsIntPrim    (SourceText t) Integer
_i                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsWordPrim   (SourceText t) Integer
_i                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsInt64Prim  (SourceText t) Integer
_i                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsWord64Prim (SourceText t) Integer
_i                         -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsInteger (SourceText t) Integer
_i                      Type
_type -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t -- BDFLit $ Text.pack $ show i
  HsRat     XHsRat GhcPs
_              (FL (SourceText String
t) Bool
_ Rational
_) Type
_type -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  HsFloatPrim  XHsFloatPrim GhcPs
_ (FL (SourceText String
t) Bool
_ Rational
_)                 -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  HsDoublePrim XHsDoublePrim GhcPs
_ (FL (SourceText String
t) Bool
_ Rational
_)                 -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  HsLit GhcPs
_ -> String -> BriDocFInt
forall a. HasCallStack => String -> a
error String
"litBriDoc: literal with no SourceText"

overLitValBriDoc :: OverLitVal -> BriDocFInt
overLitValBriDoc :: OverLitVal -> BriDocFInt
overLitValBriDoc = \case
  HsIntegral   (IL (SourceText String
t) Bool
_ Integer
_) -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  HsFractional (FL (SourceText String
t) Bool
_ Rational
_) -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  HsIsString (SourceText String
t) FastString
_ -> Text -> BriDocFInt
forall (f :: * -> *). Text -> BriDocF f
BDFLit (Text -> BriDocFInt) -> Text -> BriDocFInt
forall a b. (a -> b) -> a -> b
$ String -> Text
Text.pack String
t
  OverLitVal
_ -> String -> BriDocFInt
forall a. HasCallStack => String -> a
error String
"overLitValBriDoc: literal with no SourceText"