Filter binders with docSetBaseAndIndent.

pull/66/head
Evan Rutledge Borden 2017-11-25 20:50:17 -05:00 committed by Lennart Spitzner
parent de0851f975
commit e9a2de7a85
3 changed files with 63 additions and 48 deletions

View File

@ -532,7 +532,8 @@ func = do
#test let
func = do
let x = 13
let
x = 13
stmt x
@ -1021,7 +1022,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
| not hasComments
, [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
, wherePart <- case mWhereDocs of
Nothing -> return @[] $ docEmpty
Just [w] -> return @[] $ docSeq
@ -1042,7 +1044,8 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
, Data.Maybe.isJust mWhereDocs
]
++ -- two-line solution + where in next line(s)
@ -1054,13 +1057,15 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
]
++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs]
, let guardPart = singleLineGuardsDoc guards
, let
guardPart = singleLineGuardsDoc guards
]
#test comment-testcase-17
{-# LANGUAGE MultiWayIf #-}
func = do
let foo = if
let
foo = if
| Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO
-> max
(defLen - 0.2) -- TODO

View File

@ -539,13 +539,16 @@ layoutExpr lexpr@(L _ expr) = do
-- if "let" is moved horizontally as part of the transformation, as the
-- comments before the first let item are moved horizontally with it.
docSetIndentLevel $ case mBindDocs of
Just [bindDoc] -> docAlt
[ docSeq
Just [bindDoc] -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft
, docSeq
[ appSep $ docLit $ Text.pack "let"
, appSep $ docForceSingleline $ return bindDoc
, appSep $ docLit $ Text.pack "in"
, docForceSingleline $ expDoc1
]
)
, ( indentPolicy /= IndentPolicyLeft
, docLines
[ docSeq
[ appSep $ docLit $ Text.pack "let"
@ -556,6 +559,8 @@ layoutExpr lexpr@(L _ expr) = do
, docSetBaseY $ expDoc1
]
]
)
, ( True
, docLines
[ docAddBaseY BrIndentRegular
$ docPar
@ -566,6 +571,7 @@ layoutExpr lexpr@(L _ expr) = do
(appSep $ docLit $ Text.pack "in")
(docSetBaseY $ expDoc1)
]
)
]
Just bindDocs@(_:_) -> docAltFilter
--either

View File

@ -54,15 +54,19 @@ layoutStmt lstmt@(L _ stmt) = do
-- indeed allowed.
-- heh.
Just [] -> docLit $ Text.pack "let" -- this probably never happens
Just [bindDoc] -> docAlt
[ docCols
Just [bindDoc] -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft
, docCols
ColDoLet
[ appSep $ docLit $ Text.pack "let"
, docSetBaseAndIndent $ return bindDoc
]
)
, ( True
, docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "let")
(docSetBaseAndIndent $ return bindDoc)
)
]
Just bindDocs -> docAltFilter
[ ( indentPolicy /= IndentPolicyLeft