diff --git a/data/15-regressions.blt b/data/15-regressions.blt index f101136..4c43e3d 100644 --- a/data/15-regressions.blt +++ b/data/15-regressions.blt @@ -1027,3 +1027,19 @@ func = myRecord { field = -- comment if some condition then option one else option two , otherfield = "text" } + +#test multiline guards within parenthesis +duGswidunBlxaq drux = DeeX.Vufcqqafi + (tiErihambSunxo drux) + (if + | geIqzscmBhiwo drux + -> Bmuh "Hpiioqa a yabufx ynyuq" + | liWaov drux + -> Bmuh "Ookhup ubqocf merr ukm ynyuq iitiop" + | tiErihambSunxo drux && bdp (alJukIkuh drux) + -> Bmuh "Jpgic dfaz dieb fs wreup hsv of ynyuq dio njr subdet" + | ukFinwuicUgIcclcep drux + -> Bmuh "Egwiqae-ka-molenqe codns dif'y ns csjyhth sisoyy" + | otherwise + -> Likiotq + ) diff --git a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Decl.hs b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Decl.hs index 0132c4d..da2bcb9 100644 --- a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Decl.hs +++ b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Decl.hs @@ -641,29 +641,36 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe $ docLines $ map docSetBaseY $ clauseDocs - >>= \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92 - (case guardDocs of - [] -> [docHandleComms grhsEpAnn docEmpty] - [g] -> - [ docHandleComms grhsEpAnn - $ docSeq [appSep - $ docLit $ Text.pack "|", return g] - ] - (g1 : gr) -> - ( ( docHandleComms grhsEpAnn - $ docSeq [appSep $ docLit $ Text.pack "|", return g1] - ) - : (gr <&> \g -> - docSeq [appSep $ docLit $ Text.pack ",", return g] - ) - ) - ) - ++ [ docCols - ColOpPrefix - [ appSep $ return binderDoc - , docAddBaseY BrIndentRegular $ return bodyDoc - ] - ] + >>= \(grhsEpAnn, guardDocs, bodyDoc) -> case guardDocs of + [] -> + [ docHandleComms grhsEpAnn + $ docCols + ColOpPrefix + [ appSep $ return binderDoc + , docAddBaseY BrIndentRegular $ return bodyDoc + ] + ] + [g] -> + [ docHandleComms grhsEpAnn + $ docSeq [appSep $ docLit $ Text.pack "|", return g] + , docSeq + [ appSep $ return binderDoc + , docAddBaseY BrIndentRegular $ return bodyDoc + ] + ] + (g1 : gr) -> + ( [ docHandleComms grhsEpAnn + $ docSeq [appSep $ docLit $ Text.pack "|", return g1] + ] + ++ (gr <&> \g -> + docSeq [appSep $ docLit $ Text.pack ",", return g] + ) + ++ [ docSeq + [ appSep $ return binderDoc + , docAddBaseY BrIndentRegular $ return bodyDoc + ] + ] + ) ] ++ wherePartMultiLine diff --git a/source/library/Language/Haskell/Brittany/Internal/Transformations/T4_Columns.hs b/source/library/Language/Haskell/Brittany/Internal/Transformations/T4_Columns.hs index 21ac49f..6aaf79a 100644 --- a/source/library/Language/Haskell/Brittany/Internal/Transformations/T4_Columns.hs +++ b/source/library/Language/Haskell/Brittany/Internal/Transformations/T4_Columns.hs @@ -109,15 +109,13 @@ transformSimplifyColumns = Uniplate.rewrite $ \case -> Just $ BDLines [BDCols sig1 (List.init cols ++ [line]), BDCols sig2 cols2] BDCols sig1 cols - | BDPar ind line (BDLines lines) <- List.last cols - , BDCols sig2 cols2 <- List.last lines - , sig1 == sig2 - -> Just $ BDLines - [ BDCols sig1 - $ List.init cols - ++ [BDPar ind line (BDLines $ List.init lines)] - , BDCols sig2 cols2 - ] + | BDPar _ line (BDLines lines) <- List.last cols + , all (\case + BDCols sig2 _ -> sig1 == sig2 + _ -> False + ) + lines + -> Just $ BDLines $ BDCols sig1 (List.init cols ++ [line]) : lines BDLines [x] -> Just $ x BDLines [] -> Just $ BDEmpty BDSeq{} -> Nothing