Simplify/Optimize Decl:layoutPatternBindFinal

ghc92
Lennart Spitzner 2023-04-20 17:05:57 +00:00
parent 156b5cf407
commit 56e7d6b5b9
1 changed files with 24 additions and 47 deletions

View File

@ -412,6 +412,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
pure [(Nothing, [], e)] pure [(Nothing, [], e)]
Right grhss -> layoutGrhs `mapM` grhss Right grhss -> layoutGrhs `mapM` grhss
let multipleClauses = not $ null clauseDocs
runFilteredAlternative $ do runFilteredAlternative $ do
case clauseDocs of case clauseDocs of
@ -492,12 +494,11 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
_ -> return () -- no alternatives exclusively when `length clauseDocs /= 1` _ -> return () -- no alternatives exclusively when `length clauseDocs /= 1`
case mPatDoc of case mPatDoc of
Nothing -> return () Just patDoc | multipleClauses, indentPolicy == IndentPolicyFree ->
Just patDoc ->
-- multiple clauses added in-paragraph, each in a single line -- multiple clauses added in-paragraph, each in a single line
-- example: foo | bar = baz -- example: foo | bar = baz
-- | lll = asd -- | lll = asd
addAlternativeCond (indentPolicy == IndentPolicyFree) addAlternative
$ docLines $ docLines
$ [ docSeq $ [ docSeq
[ appSep $ docForceSingleline $ return patDoc [ appSep $ docForceSingleline $ return patDoc
@ -522,6 +523,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
] ]
] ]
++ wherePartMultiLine ++ wherePartMultiLine
_ -> return ()
-- multiple clauses, each in a separate, single line -- multiple clauses, each in a separate, single line
addAlternative addAlternative
$ docLines $ docLines
@ -559,20 +561,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
$ clauseDocs $ clauseDocs
<&> \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92 <&> \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92
docHandleComms grhsEpAnn $ docSeq docHandleComms grhsEpAnn $ docSeq
$ (case guardDocs of [ singleLineGuardsDoc guardDocs
[] -> []
[g] ->
[ docForceSingleline $ docSeq
[appSep $ docLit $ Text.pack "|", return g]
]
gs ->
[ docForceSingleline
$ docSeq
$ [appSep $ docLit $ Text.pack "|"]
++ List.intersperse docCommaSep (return <$> gs)
]
)
++ [ docSeparator
, docCols , docCols
ColOpPrefix ColOpPrefix
[ appSep $ return binderDoc [ appSep $ return binderDoc
@ -593,20 +582,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
$ map docSetBaseY $ map docSetBaseY
$ clauseDocs $ clauseDocs
>>= \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92 >>= \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92
(case guardDocs of [ docHandleComms grhsEpAnn $ singleLineGuardsDoc guardDocs
[] -> [docHandleComms grhsEpAnn docEmpty] , docCols
[g] ->
[ docHandleComms grhsEpAnn $ docForceSingleline
$ docSeq [appSep $ docLit $ Text.pack "|", return g]
]
gs ->
[ docHandleComms grhsEpAnn $ docForceSingleline
$ docSeq
$ [appSep $ docLit $ Text.pack "|"]
++ List.intersperse docCommaSep (return <$> gs)
]
)
++ [ docCols
ColOpPrefix ColOpPrefix
[ appSep $ return binderDoc [ appSep $ return binderDoc
, docAddBaseY BrIndentRegular , docAddBaseY BrIndentRegular