Refactor/Cleanup layoutPatternBindFinal
parent
af38c547e5
commit
df422ffa5f
|
@ -209,9 +209,15 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
$ return
|
$ return
|
||||||
<$> ws
|
<$> ws
|
||||||
]
|
]
|
||||||
|
let singleLineGuardsDoc guards = appSep $ case guards of
|
||||||
|
[] -> docEmpty
|
||||||
|
[g] -> docSeq [appSep $ docLit $ Text.pack "|", return g]
|
||||||
|
gs -> docSeq
|
||||||
|
$ [appSep $ docLit $ Text.pack "|"]
|
||||||
|
++ List.intersperse docCommaSep (return <$> gs)
|
||||||
docAlt
|
docAlt
|
||||||
$ -- one-line solution
|
$ -- one-line solution
|
||||||
[ docCols
|
[ docCols
|
||||||
(ColBindingLine alignmentToken)
|
(ColBindingLine alignmentToken)
|
||||||
[ docSeq (patPartInline ++ [guardPart])
|
[ docSeq (patPartInline ++ [guardPart])
|
||||||
, docSeq
|
, docSeq
|
||||||
|
@ -221,16 +227,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
||||||
, let
|
, let guardPart = singleLineGuardsDoc guards
|
||||||
guardPart = case guards of
|
|
||||||
[] -> docEmpty
|
|
||||||
[g] ->
|
|
||||||
docSeq [appSep $ docLit $ Text.pack "|", return g, docSeparator]
|
|
||||||
gs ->
|
|
||||||
docSeq
|
|
||||||
$ [appSep $ docLit $ Text.pack "|"]
|
|
||||||
++ List.intersperse docCommaSep (return <$> gs)
|
|
||||||
++ [docSeparator]
|
|
||||||
, wherePart <- case mWhereDocs of
|
, wherePart <- case mWhereDocs of
|
||||||
Nothing -> return @[] $ docEmpty
|
Nothing -> return @[] $ docEmpty
|
||||||
Just [w] -> return @[] $ docSeq
|
Just [w] -> return @[] $ docSeq
|
||||||
|
@ -251,16 +248,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
]
|
]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
||||||
, let
|
, let guardPart = singleLineGuardsDoc guards
|
||||||
guardPart = case guards of
|
|
||||||
[] -> docEmpty
|
|
||||||
[g] ->
|
|
||||||
docSeq [appSep $ docLit $ Text.pack "|", return g, docSeparator]
|
|
||||||
gs ->
|
|
||||||
docSeq
|
|
||||||
$ [appSep $ docLit $ Text.pack "|"]
|
|
||||||
++ List.intersperse docCommaSep (return <$> gs)
|
|
||||||
++ [docSeparator]
|
|
||||||
, Data.Maybe.isJust mWhereDocs
|
, Data.Maybe.isJust mWhereDocs
|
||||||
]
|
]
|
||||||
++ -- two-line solution + where in next line(s)
|
++ -- two-line solution + where in next line(s)
|
||||||
|
@ -271,23 +259,14 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
]
|
]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
||||||
, let
|
, let guardPart = singleLineGuardsDoc guards
|
||||||
guardPart = case guards of
|
|
||||||
[] -> docEmpty
|
|
||||||
[g] ->
|
|
||||||
docSeq [appSep $ docLit $ Text.pack "|", return g, docSeparator]
|
|
||||||
gs ->
|
|
||||||
docSeq
|
|
||||||
$ [appSep $ docLit $ Text.pack "|"]
|
|
||||||
++ List.intersperse docCommaSep (return <$> gs)
|
|
||||||
++ [docSeparator]
|
|
||||||
]
|
]
|
||||||
++ -- pattern and exactly one clause in single line, body as par;
|
++ -- pattern and exactly one clause in single line, body as par;
|
||||||
-- where in following lines
|
-- where in following lines
|
||||||
[ docLines
|
[ docLines
|
||||||
$ [ docCols
|
$ [ docCols
|
||||||
(ColBindingLine alignmentToken)
|
(ColBindingLine alignmentToken)
|
||||||
[ docSeq (patPartInline ++ [appSep guardPart])
|
[ docSeq (patPartInline ++ [guardPart])
|
||||||
, docSeq
|
, docSeq
|
||||||
[ appSep $ return binderDoc
|
[ appSep $ return binderDoc
|
||||||
, docForceParSpacing $ docAddBaseY BrIndentRegular $ return body
|
, docForceParSpacing $ docAddBaseY BrIndentRegular $ return body
|
||||||
|
@ -300,13 +279,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
-- ]
|
-- ]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
| [(guards, body, _bodyRaw)] <- [clauseDocs]
|
||||||
, let
|
, let guardPart = singleLineGuardsDoc guards
|
||||||
guardPart = case guards of
|
|
||||||
[] -> docEmpty
|
|
||||||
[g] -> docSeq [appSep $ docLit $ Text.pack "|", return g]
|
|
||||||
gs -> docSeq $ [appSep $ docLit $ Text.pack "|"] ++ List.intersperse
|
|
||||||
docCommaSep
|
|
||||||
(return <$> gs)
|
|
||||||
]
|
]
|
||||||
++ -- pattern and exactly one clause in single line, body in new line.
|
++ -- pattern and exactly one clause in single line, body in new line.
|
||||||
[ docLines
|
[ docLines
|
||||||
|
@ -317,19 +290,13 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs mWhereDocs =
|
||||||
]
|
]
|
||||||
++ wherePartMultiLine
|
++ wherePartMultiLine
|
||||||
| [(guards, body, _)] <- [clauseDocs]
|
| [(guards, body, _)] <- [clauseDocs]
|
||||||
, let
|
, let guardPart = singleLineGuardsDoc guards
|
||||||
guardPart = case guards of
|
|
||||||
[] -> docEmpty
|
|
||||||
[g] -> docSeq [appSep $ docLit $ Text.pack "|", return g]
|
|
||||||
gs -> docSeq $ [appSep $ docLit $ Text.pack "|"] ++ List.intersperse
|
|
||||||
docCommaSep
|
|
||||||
(return <$> gs)
|
|
||||||
]
|
]
|
||||||
++ -- conservative approach: everything starts on the left.
|
++ -- conservative approach: everything starts on the left.
|
||||||
[ docLines
|
[ docLines
|
||||||
$ [ patPartParWrap
|
$ [ patPartParWrap
|
||||||
|
$ docEnsureIndent BrIndentRegular
|
||||||
$ docLines
|
$ docLines
|
||||||
$ fmap (docEnsureIndent BrIndentRegular)
|
|
||||||
$ clauseDocs
|
$ clauseDocs
|
||||||
>>= \(guardDocs, bodyDoc, _) ->
|
>>= \(guardDocs, bodyDoc, _) ->
|
||||||
( case guardDocs of
|
( case guardDocs of
|
||||||
|
|
Loading…
Reference in New Issue