From 0795a398060d37090e51ced5adf1457610443bf0 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Thu, 19 Sep 2019 00:48:45 +0200 Subject: [PATCH] Fix infix matches with more than 2 args, fixes #219 --- src-literatetests/10-tests.blt | 9 +++++++ .../Brittany/Internal/Layouters/Decl.hs | 24 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index 7516fd4..1b152f5 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -330,6 +330,15 @@ x *** y = x #test symbol prefix (***) x y = x +#test infix more args simple +(f >=> g) k = f k >>= g + +#test infix more args alignment +(Left a <$$> Left dd) e f = True +(Left a <$$> Right d ) e f = True +(Right a <$$> Left d ) e f = False +(Right a <$$> Right dd) e f = True + ############################################################################### ############################################################################### diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs index 67e9000..6d9a1f5 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs @@ -341,11 +341,25 @@ layoutPatternBind funId binderDoc lmatch@(L _ match) = do _ -> pure Nothing let mIdStr' = fixPatternBindIdentifier match <$> mIdStr patDoc <- docWrapNodePrior lmatch $ case (mIdStr', patDocs) of - (Just idStr, p1 : pr) | isInfix -> docCols - ColPatternsFuncInfix - ( [appSep $ docForceSingleline p1, appSep $ docLit idStr] - ++ (spacifyDocs $ docForceSingleline <$> pr) - ) + (Just idStr, p1:p2:pr) | isInfix -> if null pr + then + docCols ColPatternsFuncInfix + [ appSep $ docForceSingleline p1 + , appSep $ docLit $ idStr + , docForceSingleline p2 + ] + else + docCols ColPatternsFuncInfix + ( [docCols ColPatterns + [ docParenL + , appSep $ docForceSingleline p1 + , appSep $ docLit $ idStr + , docForceSingleline p2 + , appSep $ docParenR + ] + ] + ++ (spacifyDocs $ docForceSingleline <$> pr) + ) (Just idStr, []) -> docLit idStr (Just idStr, ps) -> docCols ColPatternsFuncPrefix