diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index a3d8591..282e911 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -295,6 +295,47 @@ func = f f = id +############################################################################### +############################################################################### +############################################################################### +#group data type declarations +############################################################################### +############################################################################### +############################################################################### + +#test single record +data Foo = Bar { foo :: Baz } + +#test record multiple names +data Foo = Bar { foo, bar :: Baz } + +#test record multiple types +data Foo = Bar + { foo :: Baz + , bars :: Bizzz + } + +#test record multiple types and names +data Foo = Bar + { foo, biz :: Baz + , bar :: Bizzz + } + +#test record multiple types deriving +data Foo = Bar + { fooz :: Baz + , bar :: Bizzz + } + deriving Show + +#test record multiple types deriving +data Foo = Bar + { foo :: Baz + , bars :: Bizzz + } + deriving (Show, Eq, Monad, Functor, Traversable, Foldable) + + ############################################################################### ############################################################################### ############################################################################### diff --git a/src/Language/Haskell/Brittany/Internal/Backend.hs b/src/Language/Haskell/Brittany/Internal/Backend.hs index c121eaf..ea82e8e 100644 --- a/src/Language/Haskell/Brittany/Internal/Backend.hs +++ b/src/Language/Haskell/Brittany/Internal/Backend.hs @@ -434,6 +434,7 @@ alignColsLines bridocs = do -- colInfos `forM_` \colInfo -> do (BDCols ColBindStmt _) -> True (BDCols ColDoLet _) -> True (BDCols ColRecUpdate _) -> False + (BDCols ColRecDecl _) -> False (BDCols ColListComp _) -> False (BDCols ColList _) -> False (BDCols ColApp _) -> True diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs b/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs index ed6aaeb..c785270 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/DataDecl.hs @@ -173,7 +173,7 @@ createDetailsDoc consNameStr details = case details of [ docLit consNameStr , docSeparator , appSep $ docLit $ Text.pack "{" - , createNamesAndTypeDoc names t + , docSeq $ createNamesAndTypeDoc names t , docSeparator , docLit $ Text.pack "}" ] @@ -181,14 +181,13 @@ createDetailsDoc consNameStr details = case details of docAddBaseY BrIndentRegular $ docPar (docLit consNameStr) (docLines - [ docSeq - [ docLit $ Text.pack "{ " - , let L _ (ConDeclField names t _) = fstField + [ docCols ColRecDecl + $ docLit (Text.pack "{ ") + : let L _ (ConDeclField names t _) = fstField in createNamesAndTypeDoc names t - ] , docLines - $ (\(L _ (ConDeclField names t _)) -> - docSeq [docCommaSep, createNamesAndTypeDoc names t]) + $ (\(L _ (ConDeclField names t _)) -> + docCols ColRecDecl $ docCommaSep : createNamesAndTypeDoc names t) <$> fields , docLit $ Text.pack "}" ] @@ -213,15 +212,19 @@ createForallDoc (Just (HsQTvs _ bs _)) = do ] createNamesAndTypeDoc - :: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> ToBriDocM BriDocNumbered -createNamesAndTypeDoc names t = docSeq + :: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> [ToBriDocM BriDocNumbered] +createNamesAndTypeDoc names t = [ docSeq - $ List.intersperse docCommaSep - $ names - <&> \(L _ (FieldOcc fieldName _)) -> - docLit =<< lrdrNameToTextAnn fieldName - , docSeparator - , docLit $ Text.pack "::" - , docSeparator - , layoutType t + [ docSeq + $ List.intersperse docCommaSep + $ names + <&> \(L _ (FieldOcc fieldName _)) -> + docLit =<< lrdrNameToTextAnn fieldName + , docSeparator + ] + , docSeq + [ docLit $ Text.pack "::" + , docSeparator + , layoutType t + ] ] diff --git a/src/Language/Haskell/Brittany/Internal/Types.hs b/src/Language/Haskell/Brittany/Internal/Types.hs index 557f9b3..ed720d5 100644 --- a/src/Language/Haskell/Brittany/Internal/Types.hs +++ b/src/Language/Haskell/Brittany/Internal/Types.hs @@ -172,6 +172,7 @@ data ColSig | ColBindStmt | ColDoLet -- the non-indented variant | ColRecUpdate -- used for both RecCon and RecUpd. TODO: refactor to reflect? + | ColRecDecl | ColListComp | ColList | ColApp @@ -391,7 +392,7 @@ briDocForceSpine bd = briDocSeqSpine bd `seq` bd data VerticalSpacingPar = VerticalSpacingParNone -- no indented lines - | VerticalSpacingParSome Int -- indented lines, requiring this much + | VerticalSpacingParSome Int -- indented lines, requiring this much -- vertical space at most | VerticalSpacingParAlways Int -- indented lines, requiring this much -- vertical space at most, but should