diff --git a/src-literatetests/14-extensions.blt b/src-literatetests/14-extensions.blt index 896d105..a1c930b 100644 --- a/src-literatetests/14-extensions.blt +++ b/src-literatetests/14-extensions.blt @@ -66,3 +66,17 @@ foo = do b <- g a return (a, b) +############################################################################### +## ExplicitNamespaces + PatternSynonyms +#test explicitnamespaces_patternsynonyms export +{-# LANGUAGE ExplicitNamespaces #-} +{-# LANGUAGE PatternSynonyms #-} +module Test (type (++), (++), pattern Foo) where + +#test explicitnamespaces_patternsynonyms import +{-# LANGUAGE ExplicitNamespaces #-} +{-# LANGUAGE PatternSynonyms #-} +import Test ( type (++) + , (++) + , pattern Foo + ) diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs index 4e5af9f..378de6e 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs @@ -39,46 +39,51 @@ prepareName = id layoutIE :: ToBriDoc IE layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of - IEVar _ -> ien - IEThingAbs _ -> ien - IEThingAll _ -> docSeq [ien, docLit $ Text.pack "(..)"] - IEThingWith _ (IEWildcard _) _ _ -> docSeq [ien, docLit $ Text.pack "(..)"] + IEVar x -> layoutWrapped x + IEThingAbs x -> layoutWrapped x + IEThingAll _ -> docSeq [ienDoc, docLit $ Text.pack "(..)"] + IEThingWith _ (IEWildcard _) _ _ -> + docSeq [ienDoc, docLit $ Text.pack "(..)"] IEThingWith _ _ ns _ -> do hasComments <- hasAnyCommentsBelow lie runFilteredAlternative $ do addAlternativeCond (not hasComments) $ docSeq - $ [ien, docLit $ Text.pack "("] + $ [ienDoc, docLit $ Text.pack "("] ++ intersperse docCommaSep (map nameDoc ns) ++ [docParenR] - addAlternative - $ docAddBaseY BrIndentRegular - $ docPar ien (layoutItems (splitFirstLast ns)) + addAlternative $ docAddBaseY BrIndentRegular $ docPar + ienDoc + (layoutItems (splitFirstLast ns)) where nameDoc = (docLit =<<) . lrdrNameToTextAnn . prepareName layoutItem n = docSeq [docCommaSep, docWrapNode n $ nameDoc n] - layoutItems FirstLastEmpty = - docSetBaseY $ - docLines [docSeq [docParenLSep, docWrapNodeRest lie docEmpty] - ,docParenR - ] - layoutItems (FirstLastSingleton n) = - docSetBaseY $ docLines - [docSeq [docParenLSep, docWrapNodeRest lie $ nameDoc n], docParenR] - layoutItems (FirstLast n1 nMs nN) = - docSetBaseY $ docLines $ - [docSeq [docParenLSep, docWrapNode n1 $ nameDoc n1]] - ++ map layoutItem nMs - ++ [ docSeq [docCommaSep, docWrapNodeRest lie $ nameDoc nN] - , docParenR - ] + layoutItems FirstLastEmpty = docSetBaseY $ docLines + [docSeq [docParenLSep, docWrapNodeRest lie docEmpty], docParenR] + layoutItems (FirstLastSingleton n) = docSetBaseY $ docLines + [docSeq [docParenLSep, docWrapNodeRest lie $ nameDoc n], docParenR] + layoutItems (FirstLast n1 nMs nN) = + docSetBaseY + $ docLines + $ [docSeq [docParenLSep, docWrapNode n1 $ nameDoc n1]] + ++ map layoutItem nMs + ++ [docSeq [docCommaSep, docWrapNodeRest lie $ nameDoc nN], docParenR] IEModuleContents n -> docSeq [ docLit $ Text.pack "module" , docSeparator , docLit . Text.pack . moduleNameString $ unLoc n ] _ -> docEmpty - where ien = docLit =<< lrdrNameToTextAnn (ieName <$> lie) + where + ienDoc = docLit =<< lrdrNameToTextAnn (ieName <$> lie) + layoutWrapped = \case + L _ (IEName n) -> docLit =<< lrdrNameToTextAnn n + L _ (IEPattern n) -> do + name <- lrdrNameToTextAnn n + docLit $ Text.pack "pattern " <> name + L _ (IEType n) -> do + name <- lrdrNameToTextAnn n + docLit $ Text.pack "type " <> name -- Helper function to deal with Located lists of LIEs. -- In particular this will also associate documentation