Compare commits

..

1 Commits

Author SHA1 Message Date
Lennart Spitzner cf426f2040 Retain comments after lambdacase and at record fields 2023-05-20 16:09:01 +02:00
4 changed files with 33 additions and 77 deletions

View File

@ -1015,39 +1015,3 @@ catchFunc = do
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) )
`catch` catcher `catch` catcher
#test comment after lambdacase
func = \case
-- zzz
False -> 0
True -> 1
#test comment for recordfield
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
)
#test multiline-block-comment in do-block
func = do
abc
{- some long
block comment -}
x <- readLine
print x

View File

@ -641,36 +641,29 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses (wrapBinds, mWhe
$ docLines $ docLines
$ map docSetBaseY $ map docSetBaseY
$ clauseDocs $ clauseDocs
>>= \(grhsEpAnn, guardDocs, bodyDoc) -> case guardDocs of >>= \(grhsEpAnn, guardDocs, bodyDoc) -> -- TODO92
[] -> (case guardDocs of
[ docHandleComms grhsEpAnn [] -> [docHandleComms grhsEpAnn docEmpty]
$ docCols [g] ->
ColOpPrefix [ docHandleComms grhsEpAnn
[ appSep $ return binderDoc $ docSeq [appSep
, docAddBaseY BrIndentRegular $ return bodyDoc $ docLit $ Text.pack "|", return g]
] ]
] (g1 : gr) ->
[g] -> ( ( docHandleComms grhsEpAnn
[ docHandleComms grhsEpAnn $ docSeq [appSep $ docLit $ Text.pack "|", return g1]
$ docSeq [appSep $ docLit $ Text.pack "|", return g] )
, docSeq : (gr <&> \g ->
[ appSep $ return binderDoc docSeq [appSep $ docLit $ Text.pack ",", return g]
, docAddBaseY BrIndentRegular $ return bodyDoc )
] )
] )
(g1 : gr) -> ++ [ docCols
( [ docHandleComms grhsEpAnn ColOpPrefix
$ docSeq [appSep $ docLit $ Text.pack "|", return g1] [ appSep $ return binderDoc
] , docAddBaseY BrIndentRegular $ return bodyDoc
++ (gr <&> \g -> ]
docSeq [appSep $ docLit $ Text.pack ",", return g] ]
)
++ [ docSeq
[ appSep $ return binderDoc
, docAddBaseY BrIndentRegular $ return bodyDoc
]
]
)
] ]
++ wherePartMultiLine ++ wherePartMultiLine

View File

@ -109,13 +109,15 @@ transformSimplifyColumns = Uniplate.rewrite $ \case
-> Just -> Just
$ BDLines [BDCols sig1 (List.init cols ++ [line]), BDCols sig2 cols2] $ BDLines [BDCols sig1 (List.init cols ++ [line]), BDCols sig2 cols2]
BDCols sig1 cols BDCols sig1 cols
| BDPar _ line (BDLines lines) <- List.last cols | BDPar ind line (BDLines lines) <- List.last cols
, all (\case , BDCols sig2 cols2 <- List.last lines
BDCols sig2 _ -> sig1 == sig2 , sig1 == sig2
_ -> False -> Just $ BDLines
) [ BDCols sig1
lines $ List.init cols
-> Just $ BDLines $ BDCols sig1 (List.init cols ++ [line]) : lines ++ [BDPar ind line (BDLines $ List.init lines)]
, BDCols sig2 cols2
]
BDLines [x] -> Just $ x BDLines [x] -> Just $ x
BDLines [] -> Just $ BDEmpty BDLines [] -> Just $ BDEmpty
BDSeq{} -> Nothing BDSeq{} -> Nothing

View File

@ -25,7 +25,6 @@ where
import Language.Haskell.Brittany.Internal.Prelude import Language.Haskell.Brittany.Internal.Prelude
import qualified Data.Maybe
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Data.Text.Lazy.Builder as Text.Builder import qualified Data.Text.Lazy.Builder as Text.Builder
import qualified GHC.OldList as List import qualified GHC.OldList as List
@ -158,9 +157,7 @@ layoutWriteComment absolute isBlock dp commentLines s = do -- TODO92 we don't mo
PlannedNewline l -> PlannedNewline l ->
if l <= y then PlannedSameline 1 else PlannedNewline (l - y) if l <= y then PlannedSameline 1 else PlannedNewline (l - y)
PlannedDelta l i -> PlannedDelta l i ->
if l <= y && Data.Maybe.isNothing (_lstate_markerForDelta state) if l <= y then PlannedSameline 1 else PlannedDelta (l - y) i
then PlannedSameline 1
else PlannedDelta (l - y) i
else case _lstate_plannedSpace state of else case _lstate_plannedSpace state of
PlannedNone -> PlannedDelta 1 (_lstate_curY state) PlannedNone -> PlannedDelta 1 (_lstate_curY state)
PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i) PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i)