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 , docLit
, docAlt , docAlt
, CollectAltM , CollectAltM
, addAlternativeCondM
, addAlternativeCond , addAlternativeCond
, addAlternative , addAlternative
, runFilteredAlternative , runFilteredAlternative
@ -426,10 +425,6 @@ docAlt l = allocateNode . BDFAlt =<< sequence l
newtype CollectAltM a = CollectAltM (Writer.Writer [ToBriDocM BriDocNumbered] a) newtype CollectAltM a = CollectAltM (Writer.Writer [ToBriDocM BriDocNumbered] a)
deriving (Functor, Applicative, Monad) deriving (Functor, Applicative, Monad)
addAlternativeCondM :: Bool -> CollectAltM (ToBriDocM BriDocNumbered) -> CollectAltM ()
addAlternativeCondM cond doc =
addAlternativeCond cond =<< doc
addAlternativeCond :: Bool -> ToBriDocM BriDocNumbered -> CollectAltM () addAlternativeCond :: Bool -> ToBriDocM BriDocNumbered -> CollectAltM ()
addAlternativeCond cond doc = addAlternativeCond cond doc =
when cond (addAlternative doc) when cond (addAlternative doc)

View File

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

View File

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