From e9a2de7a85593c0c89fda522df4362efb1f06f13 Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Sat, 25 Nov 2017 20:50:17 -0500 Subject: [PATCH] Filter binders with docSetBaseAndIndent. --- src-literatetests/tests-context-free.blt | 27 +++++---- .../Brittany/Internal/Layouters/Expr.hs | 56 ++++++++++--------- .../Brittany/Internal/Layouters/Stmt.hs | 28 ++++++---- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src-literatetests/tests-context-free.blt b/src-literatetests/tests-context-free.blt index f5ab85c..34f314b 100644 --- a/src-literatetests/tests-context-free.blt +++ b/src-literatetests/tests-context-free.blt @@ -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,18 +1057,20 @@ 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 - | Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO - -> max - (defLen - 0.2) -- TODO - (defLen * 0.8) - | otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO + let + foo = if + | Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO + -> max + (defLen - 0.2) -- TODO + (defLen * 0.8) + | otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO return True #test issue 49 @@ -1109,7 +1114,7 @@ foo = ## from the input; i cannot really express this yet with the current ## test-suite. ## #test ayaz -## +## ## myManageHook = ## composeOne [isFullscreen -?> doFullFloat, isDialog -?> doFloat, transience] ## <+> composeAll diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs index c3f4429..38f3808 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Expr.hs @@ -539,33 +539,39 @@ 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 - [ appSep $ docLit $ Text.pack "let" - , appSep $ docForceSingleline $ return bindDoc - , appSep $ docLit $ Text.pack "in" - , docForceSingleline $ expDoc1 - ] - , docLines - [ docSeq - [ appSep $ docLit $ Text.pack "let" - , docSetBaseAndIndent $ return bindDoc - ] + Just [bindDoc] -> docAltFilter + [ ( indentPolicy /= IndentPolicyLeft , docSeq - [ appSep $ docLit $ Text.pack "in " - , docSetBaseY $ expDoc1 + [ appSep $ docLit $ Text.pack "let" + , appSep $ docForceSingleline $ return bindDoc + , appSep $ docLit $ Text.pack "in" + , docForceSingleline $ expDoc1 ] - ] - , docLines - [ docAddBaseY BrIndentRegular - $ docPar - (appSep $ docLit $ Text.pack "let") - (docSetBaseAndIndent $ return bindDoc) - , docAddBaseY BrIndentRegular - $ docPar - (appSep $ docLit $ Text.pack "in") - (docSetBaseY $ expDoc1) - ] + ) + , ( indentPolicy /= IndentPolicyLeft + , docLines + [ docSeq + [ appSep $ docLit $ Text.pack "let" + , docSetBaseAndIndent $ return bindDoc + ] + , docSeq + [ appSep $ docLit $ Text.pack "in " + , docSetBaseY $ expDoc1 + ] + ] + ) + , ( True + , docLines + [ docAddBaseY BrIndentRegular + $ docPar + (appSep $ docLit $ Text.pack "let") + (docSetBaseAndIndent $ return bindDoc) + , docAddBaseY BrIndentRegular + $ docPar + (appSep $ docLit $ Text.pack "in") + (docSetBaseY $ expDoc1) + ] + ) ] Just bindDocs@(_:_) -> docAltFilter --either diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Stmt.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Stmt.hs index e1cf215..5bd33d3 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Stmt.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Stmt.hs @@ -50,19 +50,23 @@ layoutStmt lstmt@(L _ stmt) = do ] LetStmt binds -> layoutLocalBinds binds >>= \case Nothing -> docLit $ Text.pack "let" -- i just tested - -- it, and it is - -- indeed allowed. - -- heh. + -- it, and it is + -- indeed allowed. + -- heh. Just [] -> docLit $ Text.pack "let" -- this probably never happens - Just [bindDoc] -> docAlt - [ docCols - ColDoLet - [ appSep $ docLit $ Text.pack "let" - , docSetBaseAndIndent $ return bindDoc - ] - , docAddBaseY BrIndentRegular $ docPar - (docLit $ Text.pack "let") - (docSetBaseAndIndent $ return bindDoc) + 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