Compare commits
2 Commits
ChickenPro
...
master
Author | SHA1 | Date |
---|---|---|
|
e03ab8425b | |
|
420eac889e |
|
@ -1,4 +1,11 @@
|
|||
# brittany [](https://hackage.haskell.org/package/brittany) [](https://www.stackage.org/package/brittany) [](http://travis-ci.org/lspitzner/brittany)
|
||||
|
||||
:warning:
|
||||
This project is effectively unmaintained!
|
||||
I ([@tfausak](https://github.com/tfausak)) would recommend switching to another formatter.
|
||||
At time of writing (2022-11-11), I would suggest [Ormolu](https://github.com/tweag/ormolu).
|
||||
Or if you prefer some configuration, I would suggest [Fourmolu](https://github.com/fourmolu/fourmolu).
|
||||
|
||||
haskell source code formatter
|
||||
|
||||

|
||||
|
|
|
@ -1,50 +1 @@
|
|||
-- The spaces before commas are undesirable
|
||||
test :: Proxy '[ 'True ]
|
||||
test :: Proxy '[True]
|
||||
test :: Proxy '[ 'True , False ]
|
||||
test :: Proxy '[True , False]
|
||||
test :: Proxy '[True , 'False]
|
||||
test :: Proxy '[ 'True , 'False ]
|
||||
test :: Proxy '[ 'Just 'True , False ]
|
||||
test :: Proxy '[Just True , False]
|
||||
test :: Proxy '[('True)]
|
||||
test :: Proxy ('Just 'True)
|
||||
test :: Proxy ('True)
|
||||
|
||||
test = Proxy @'[ 'True ]
|
||||
test = Proxy @'[True]
|
||||
test = Proxy @'[ 'True , False ]
|
||||
test = Proxy @'[True , False]
|
||||
test = Proxy @'[True , 'False]
|
||||
test = Proxy @'[ 'True , 'False ]
|
||||
test = Proxy @'[ 'Just 'True , False ]
|
||||
test = Proxy @'[Just True , False]
|
||||
test = Proxy @'[('True)]
|
||||
test = Proxy @('Just 'True)
|
||||
test = Proxy @('True)
|
||||
|
||||
test
|
||||
:: Proxy '[-- comment
|
||||
'True ]
|
||||
test
|
||||
:: Proxy '[-- comment
|
||||
True]
|
||||
test
|
||||
:: Proxy '[{- comment -}
|
||||
'True ]
|
||||
test
|
||||
:: Proxy '[{- comment -}
|
||||
True]
|
||||
|
||||
test =
|
||||
Proxy @'[-- comment
|
||||
'True ]
|
||||
test =
|
||||
Proxy @'[-- comment
|
||||
True]
|
||||
test =
|
||||
Proxy @'[{- comment -}
|
||||
'True ]
|
||||
test =
|
||||
Proxy @'[{- comment -}
|
||||
True]
|
||||
test :: Proxy '[ 'True]
|
||||
|
|
|
@ -24,7 +24,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
|
|||
HsTyVar _ promoted name -> do
|
||||
t <- lrdrNameToTextAnnTypeEqualityIsSpecial name
|
||||
case promoted of
|
||||
IsPromoted -> docSeq [docTick, docWrapNode name $ docLit t]
|
||||
IsPromoted -> docSeq [docSeparator, docTick, docWrapNode name $ docLit t]
|
||||
NotPromoted -> docWrapNode name $ docLit t
|
||||
HsForAllTy _ hsf (L _ (HsQualTy _ (L _ cntxts) typ2)) -> do
|
||||
let bndrs = getBinders hsf
|
||||
|
@ -522,25 +522,14 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
|
|||
HsRecTy{} -> -- TODO
|
||||
briDocByExactInlineOnly "HsRecTy{}" ltype
|
||||
HsExplicitListTy _ _ typs -> do
|
||||
-- `'['Foo]` isn't valid because it parses as a character. So if the list
|
||||
-- starts with a promoted type var, we swap to `'[ 'Foo ]`.
|
||||
let
|
||||
sepIfHeadPromoted = case typs of
|
||||
(L _ t) : _ | startsWithTick t -> docSeparator
|
||||
_ -> docEmpty
|
||||
|
||||
-- When rendering on multiple lines, this causes commas to line up with the
|
||||
-- opening bracket. Unfortunately it also adds unnecessary space when
|
||||
-- rendering on a single line.
|
||||
let specialCommaSep = appSep $ docLit $ Text.pack " ,"
|
||||
|
||||
typDocs <- docSharedWrapper layoutType `mapM` typs
|
||||
hasComments <- hasAnyCommentsBelow ltype
|
||||
let specialCommaSep = appSep $ docLit $ Text.pack " ,"
|
||||
docAlt
|
||||
[ docSeq
|
||||
$ [docLit $ Text.pack "'[", sepIfHeadPromoted]
|
||||
$ [docLit $ Text.pack "'["]
|
||||
++ List.intersperse specialCommaSep (docForceSingleline <$> typDocs)
|
||||
++ [sepIfHeadPromoted, docLit $ Text.pack "]"]
|
||||
++ [docLit $ Text.pack "]"]
|
||||
, case splitFirstLast typDocs of
|
||||
FirstLastEmpty -> docSeq
|
||||
[ docLit $ Text.pack "'["
|
||||
|
@ -549,9 +538,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
|
|||
FirstLastSingleton e -> docAlt
|
||||
[ docSeq
|
||||
[ docLit $ Text.pack "'["
|
||||
, sepIfHeadPromoted
|
||||
, docNodeAnnKW ltype (Just AnnOpenS) $ docForceSingleline e
|
||||
, sepIfHeadPromoted
|
||||
, docLit $ Text.pack "]"
|
||||
]
|
||||
, docSetBaseY $ docLines
|
||||
|
@ -566,7 +553,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of
|
|||
FirstLast e1 ems eN -> runFilteredAlternative $ do
|
||||
addAlternativeCond (not hasComments)
|
||||
$ docSeq
|
||||
$ [docLit $ Text.pack "'[", sepIfHeadPromoted]
|
||||
$ [docLit $ Text.pack "'["]
|
||||
++ List.intersperse
|
||||
specialCommaSep
|
||||
(docForceSingleline
|
||||
|
@ -646,10 +633,3 @@ withoutSpecificity = fmap $ \case
|
|||
UserTyVar a _ c -> UserTyVar a () c
|
||||
KindedTyVar a _ c d -> KindedTyVar a () c d
|
||||
XTyVarBndr a -> XTyVarBndr a
|
||||
|
||||
-- | Determine if the type starts with a tick mark (single quote) when rendered.
|
||||
startsWithTick :: HsType pass -> Bool
|
||||
startsWithTick = \case
|
||||
HsTyVar _ IsPromoted _ -> True
|
||||
HsAppTy _ (L _ t) _ -> startsWithTick t
|
||||
_ -> False
|
||||
|
|
Loading…
Reference in New Issue