Simplify/Optimize Decl:layoutPatternBindFinal
parent
156b5cf407
commit
56e7d6b5b9
|
@ -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
|
||||||
|
@ -558,29 +560,16 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
|
||||||
$ map docSetBaseY
|
$ map docSetBaseY
|
||||||
$ clauseDocs
|
$ clauseDocs
|
||||||
<&> \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92
|
<&> \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92
|
||||||
docHandleComms grhsEpAnn $ docSeq
|
docHandleComms grhsEpAnn $ docSeq
|
||||||
$ (case guardDocs of
|
[ singleLineGuardsDoc guardDocs
|
||||||
[] -> []
|
, docCols
|
||||||
[g] ->
|
ColOpPrefix
|
||||||
[ docForceSingleline $ docSeq
|
[ appSep $ return binderDoc
|
||||||
[appSep $ docLit $ Text.pack "|", return g]
|
, docAddBaseY BrIndentRegular
|
||||||
]
|
$ docForceParSpacing
|
||||||
gs ->
|
$ return bodyDoc
|
||||||
[ docForceSingleline
|
]
|
||||||
$ docSeq
|
]
|
||||||
$ [appSep $ docLit $ Text.pack "|"]
|
|
||||||
++ List.intersperse docCommaSep (return <$> gs)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
++ [ docSeparator
|
|
||||||
, docCols
|
|
||||||
ColOpPrefix
|
|
||||||
[ appSep $ return binderDoc
|
|
||||||
, docAddBaseY BrIndentRegular
|
|
||||||
$ docForceParSpacing
|
|
||||||
$ return bodyDoc
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
-- multiple clauses, each with the guard(s) in a single line, body
|
-- multiple clauses, each with the guard(s) in a single line, body
|
||||||
|
@ -593,27 +582,15 @@ 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] ->
|
ColOpPrefix
|
||||||
[ docHandleComms grhsEpAnn $ docForceSingleline
|
[ appSep $ return binderDoc
|
||||||
$ docSeq [appSep $ docLit $ Text.pack "|", return g]
|
, docAddBaseY BrIndentRegular
|
||||||
]
|
$ docForceParSpacing
|
||||||
gs ->
|
$ return bodyDoc
|
||||||
[ docHandleComms grhsEpAnn $ docForceSingleline
|
]
|
||||||
$ docSeq
|
]
|
||||||
$ [appSep $ docLit $ Text.pack "|"]
|
|
||||||
++ List.intersperse docCommaSep (return <$> gs)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
++ [ docCols
|
|
||||||
ColOpPrefix
|
|
||||||
[ appSep $ return binderDoc
|
|
||||||
, docAddBaseY BrIndentRegular
|
|
||||||
$ docForceParSpacing
|
|
||||||
$ return bodyDoc
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
-- conservative approach: everything starts on the left.
|
-- conservative approach: everything starts on the left.
|
||||||
|
|
Loading…
Reference in New Issue