Merge pull request #105 from eborden/datadecl

Make record declarations respect alignment
remotes/eborden/origin/datadecl
Lennart Spitzner 2018-02-09 16:37:33 +01:00 committed by GitHub
commit a0aaffaae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 18 deletions

View File

@ -295,6 +295,47 @@ func = f
f = id 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)
############################################################################### ###############################################################################
############################################################################### ###############################################################################
############################################################################### ###############################################################################

View File

@ -434,6 +434,7 @@ alignColsLines bridocs = do -- colInfos `forM_` \colInfo -> do
(BDCols ColBindStmt _) -> True (BDCols ColBindStmt _) -> True
(BDCols ColDoLet _) -> True (BDCols ColDoLet _) -> True
(BDCols ColRecUpdate _) -> False (BDCols ColRecUpdate _) -> False
(BDCols ColRecDecl _) -> False
(BDCols ColListComp _) -> False (BDCols ColListComp _) -> False
(BDCols ColList _) -> False (BDCols ColList _) -> False
(BDCols ColApp _) -> True (BDCols ColApp _) -> True

View File

@ -173,7 +173,7 @@ createDetailsDoc consNameStr details = case details of
[ docLit consNameStr [ docLit consNameStr
, docSeparator , docSeparator
, appSep $ docLit $ Text.pack "{" , appSep $ docLit $ Text.pack "{"
, createNamesAndTypeDoc names t , docSeq $ createNamesAndTypeDoc names t
, docSeparator , docSeparator
, docLit $ Text.pack "}" , docLit $ Text.pack "}"
] ]
@ -181,14 +181,13 @@ createDetailsDoc consNameStr details = case details of
docAddBaseY BrIndentRegular $ docPar docAddBaseY BrIndentRegular $ docPar
(docLit consNameStr) (docLit consNameStr)
(docLines (docLines
[ docSeq [ docCols ColRecDecl
[ docLit $ Text.pack "{ " $ docLit (Text.pack "{ ")
, let L _ (ConDeclField names t _) = fstField : let L _ (ConDeclField names t _) = fstField
in createNamesAndTypeDoc names t in createNamesAndTypeDoc names t
]
, docLines , docLines
$ (\(L _ (ConDeclField names t _)) -> $ (\(L _ (ConDeclField names t _)) ->
docSeq [docCommaSep, createNamesAndTypeDoc names t]) docCols ColRecDecl $ docCommaSep : createNamesAndTypeDoc names t)
<$> fields <$> fields
, docLit $ Text.pack "}" , docLit $ Text.pack "}"
] ]
@ -213,15 +212,19 @@ createForallDoc (Just (HsQTvs _ bs _)) = do
] ]
createNamesAndTypeDoc createNamesAndTypeDoc
:: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> ToBriDocM BriDocNumbered :: [GenLocated t (FieldOcc u)] -> Located (HsType RdrName) -> [ToBriDocM BriDocNumbered]
createNamesAndTypeDoc names t = docSeq createNamesAndTypeDoc names t =
[ docSeq
[ docSeq [ docSeq
$ List.intersperse docCommaSep $ List.intersperse docCommaSep
$ names $ names
<&> \(L _ (FieldOcc fieldName _)) -> <&> \(L _ (FieldOcc fieldName _)) ->
docLit =<< lrdrNameToTextAnn fieldName docLit =<< lrdrNameToTextAnn fieldName
, docSeparator , docSeparator
, docLit $ Text.pack "::" ]
, docSeq
[ docLit $ Text.pack "::"
, docSeparator , docSeparator
, layoutType t , layoutType t
] ]
]

View File

@ -172,6 +172,7 @@ data ColSig
| ColBindStmt | ColBindStmt
| ColDoLet -- the non-indented variant | ColDoLet -- the non-indented variant
| ColRecUpdate -- used for both RecCon and RecUpd. TODO: refactor to reflect? | ColRecUpdate -- used for both RecCon and RecUpd. TODO: refactor to reflect?
| ColRecDecl
| ColListComp | ColListComp
| ColList | ColList
| ColApp | ColApp