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,21 +308,22 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs ha
++ (List.intersperse docCommaSep ++ (List.intersperse docCommaSep
(docForceSingleline . return <$> gs) (docForceSingleline . return <$> gs)
) )
wherePart = case mWhereDocs of
Nothing -> Just docEmpty
Just [w] -> Just $ docSeq
[ docSeparator
, appSep $ docLit $ Text.pack "where"
, docSetIndentLevel $ docForceSingleline $ return w
]
_ -> Nothing
indentPolicy <- mAsk indentPolicy <- mAsk
<&> _conf_layout <&> _conf_layout
.> _lconfig_indentPolicy .> _lconfig_indentPolicy
.> confUnpack .> confUnpack
runFilteredAlternative $ do runFilteredAlternative $ do
let wherePart = case mWhereDocs of
Nothing -> Just docEmpty
Just [w] -> Just $ docSeq
[ docSeparator
, appSep $ docLit $ Text.pack "where"
, docSetIndentLevel $ docForceSingleline $ return w
]
_ -> Nothing
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,21 +118,22 @@ 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
case ieDs of runFilteredAlternative $
[] -> runFilteredAlternative $ do case ieDs of
addAlternativeCond (not hasComments) $ [] -> do
docLit $ Text.pack "()" addAlternativeCond (not hasComments) $
addAlternativeCond hasComments $ docLit $ Text.pack "()"
docPar (docSeq [docParenLSep, docWrapNodeRest llies docEmpty]) addAlternativeCond hasComments $
docParenR docPar (docSeq [docParenLSep, docWrapNodeRest llies docEmpty])
(ieDsH:ieDsT) -> runFilteredAlternative $ do docParenR
addAlternativeCond (not hasComments && enableSingleline) (ieDsH:ieDsT) -> do
$ docSeq addAlternativeCond (not hasComments && enableSingleline)
$ [docLit (Text.pack "(")] $ docSeq
++ (docForceSingleline <$> ieDs) $ [docLit (Text.pack "(")]
++ [docParenR] ++ (docForceSingleline <$> ieDs)
addAlternative ++ [docParenR]
$ docPar (docSetBaseY $ docSeq [docParenLSep, ieDsH]) addAlternative
$ docLines $ docPar (docSetBaseY $ docSeq [docParenLSep, ieDsH])
$ ieDsT $ docLines
++ [docParenR] $ ieDsT
++ [docParenR]