Review suggestions

pull/132/head
Sergey Vinokurov 2018-04-03 22:49:06 +01:00
parent 049f286e6f
commit 9bd3bfbe4c
No known key found for this signature in database
GPG Key ID: D6CD29530F98D6B8
3 changed files with 29 additions and 32 deletions

View File

@ -14,7 +14,6 @@ module Language.Haskell.Brittany.Internal.LayouterBasics
, docLit
, docAlt
, CollectAltM
, addAlternativeCondM
, addAlternativeCond
, addAlternative
, runFilteredAlternative
@ -426,10 +425,6 @@ docAlt l = allocateNode . BDFAlt =<< sequence l
newtype CollectAltM a = CollectAltM (Writer.Writer [ToBriDocM BriDocNumbered] a)
deriving (Functor, Applicative, Monad)
addAlternativeCondM :: Bool -> CollectAltM (ToBriDocM BriDocNumbered) -> CollectAltM ()
addAlternativeCondM cond doc =
addAlternativeCond cond =<< doc
addAlternativeCond :: Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond cond doc =
when cond (addAlternative doc)

View File

@ -308,14 +308,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs ha
++ (List.intersperse docCommaSep
(docForceSingleline . return <$> gs)
)
indentPolicy <- mAsk
<&> _conf_layout
.> _lconfig_indentPolicy
.> confUnpack
runFilteredAlternative $ do
let wherePart = case mWhereDocs of
wherePart = case mWhereDocs of
Nothing -> Just docEmpty
Just [w] -> Just $ docSeq
[ docSeparator
@ -323,6 +316,14 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs ha
, docSetIndentLevel $ docForceSingleline $ return w
]
_ -> Nothing
indentPolicy <- mAsk
<&> _conf_layout
.> _lconfig_indentPolicy
.> confUnpack
runFilteredAlternative $ do
case clauseDocs of
[(guards, body, _bodyRaw)] -> do
let guardPart = singleLineGuardsDoc guards
@ -385,7 +386,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs ha
]
++ wherePartMultiLine
_ -> return ()
_ -> return () -- no alternatives exclusively when `length clauseDocs /= 1`
case mPatDoc of
Nothing -> return ()

View File

@ -118,14 +118,15 @@ layoutLLIEs :: Bool -> Located [LIE RdrName] -> ToBriDocM BriDocNumbered
layoutLLIEs enableSingleline llies = do
ieDs <- layoutAnnAndSepLLIEs llies
hasComments <- hasAnyCommentsBelow llies
runFilteredAlternative $
case ieDs of
[] -> runFilteredAlternative $ do
[] -> do
addAlternativeCond (not hasComments) $
docLit $ Text.pack "()"
addAlternativeCond hasComments $
docPar (docSeq [docParenLSep, docWrapNodeRest llies docEmpty])
docParenR
(ieDsH:ieDsT) -> runFilteredAlternative $ do
(ieDsH:ieDsT) -> do
addAlternativeCond (not hasComments && enableSingleline)
$ docSeq
$ [docLit (Text.pack "(")]