diff --git a/src/HIndent/Ast/Declaration/Annotation/Provenance.hs b/src/HIndent/Ast/Declaration/Annotation/Provenance.hs index 871cb1684..c53de42e5 100644 --- a/src/HIndent/Ast/Declaration/Annotation/Provenance.hs +++ b/src/HIndent/Ast/Declaration/Annotation/Provenance.hs @@ -3,15 +3,17 @@ module HIndent.Ast.Declaration.Annotation.Provenance , mkProvenance ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data Provenance - = Value (GHC.LIdP GHC.GhcPs) - | Type (GHC.LIdP GHC.GhcPs) + = Value (WithComments PrefixName) + | Type (WithComments PrefixName) | Module instance CommentExtraction Provenance where @@ -25,6 +27,8 @@ instance Pretty Provenance where pretty' Module = string "module" mkProvenance :: GHC.AnnProvenance GHC.GhcPs -> Provenance -mkProvenance (GHC.ValueAnnProvenance x) = Value x -mkProvenance (GHC.TypeAnnProvenance x) = Type x +mkProvenance (GHC.ValueAnnProvenance x) = + Value $ fromGenLocated $ fmap mkPrefixName x +mkProvenance (GHC.TypeAnnProvenance x) = + Type $ fromGenLocated $ fmap mkPrefixName x mkProvenance GHC.ModuleAnnProvenance = Module diff --git a/src/HIndent/Ast/Declaration/Annotation/Role.hs b/src/HIndent/Ast/Declaration/Annotation/Role.hs index 35221afd8..cc31a504c 100644 --- a/src/HIndent/Ast/Declaration/Annotation/Role.hs +++ b/src/HIndent/Ast/Declaration/Annotation/Role.hs @@ -5,6 +5,7 @@ module HIndent.Ast.Declaration.Annotation.Role , mkRoleAnnotation ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.Role import HIndent.Ast.WithComments @@ -14,7 +15,7 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data RoleAnnotation = RoleAnnotation - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , roles :: [WithComments (Maybe Role)] } @@ -28,6 +29,7 @@ instance Pretty RoleAnnotation where ++ fmap (`prettyWith` maybe (string "_") pretty) roles mkRoleAnnotation :: GHC.RoleAnnotDecl GHC.GhcPs -> RoleAnnotation -mkRoleAnnotation (GHC.RoleAnnotDecl _ name rs) = RoleAnnotation {..} +mkRoleAnnotation (GHC.RoleAnnotDecl _ nm rs) = RoleAnnotation {..} where + name = fromGenLocated $ fmap mkPrefixName nm roles = fmap (fmap (fmap mkRole) . fromGenLocated) rs diff --git a/src/HIndent/Ast/Declaration/Bind.hs b/src/HIndent/Ast/Declaration/Bind.hs index 3b3009ff6..c6dc77a86 100644 --- a/src/HIndent/Ast/Declaration/Bind.hs +++ b/src/HIndent/Ast/Declaration/Bind.hs @@ -7,6 +7,7 @@ module HIndent.Ast.Declaration.Bind ) where import HIndent.Ast.Name.Infix +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty @@ -46,9 +47,13 @@ instance Pretty Bind where string "pattern " case parameters of GHC.InfixCon l r -> - spaced [pretty l, pretty $ fmap mkInfixName name, pretty r] - GHC.PrefixCon _ [] -> pretty name - _ -> spaced [pretty name, pretty parameters] + spaced + [ pretty $ fmap mkPrefixName l + , pretty $ fmap mkInfixName name + , pretty $ fmap mkPrefixName r + ] + GHC.PrefixCon _ [] -> pretty $ fmap mkPrefixName name + _ -> spaced [pretty $ fmap mkPrefixName name, pretty parameters] spacePrefixed [pretty direction, pretty $ fmap PatInsidePatDecl definition] case direction of GHC.ExplicitBidirectional matches -> do diff --git a/src/HIndent/Ast/Declaration/Class/FunctionalDependency.hs b/src/HIndent/Ast/Declaration/Class/FunctionalDependency.hs index 0d253b92c..05fb385dc 100644 --- a/src/HIndent/Ast/Declaration/Class/FunctionalDependency.hs +++ b/src/HIndent/Ast/Declaration/Class/FunctionalDependency.hs @@ -5,15 +5,17 @@ module HIndent.Ast.Declaration.Class.FunctionalDependency , mkFunctionalDependency ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data FunctionalDependency = FunctionalDependency - { from :: [GHC.LIdP GHC.GhcPs] - , to :: [GHC.LIdP GHC.GhcPs] + { from :: [WithComments PrefixName] + , to :: [WithComments PrefixName] } instance CommentExtraction FunctionalDependency where @@ -24,4 +26,7 @@ instance Pretty FunctionalDependency where spaced $ fmap pretty from ++ [string "->"] ++ fmap pretty to mkFunctionalDependency :: GHC.FunDep GHC.GhcPs -> FunctionalDependency -mkFunctionalDependency (GHC.FunDep _ from to) = FunctionalDependency {..} +mkFunctionalDependency (GHC.FunDep _ f t) = FunctionalDependency {..} + where + from = fmap (fromGenLocated . fmap mkPrefixName) f + to = fmap (fromGenLocated . fmap mkPrefixName) t diff --git a/src/HIndent/Ast/Declaration/Class/NameAndTypeVariables.hs b/src/HIndent/Ast/Declaration/Class/NameAndTypeVariables.hs index 1486a263b..657615952 100644 --- a/src/HIndent/Ast/Declaration/Class/NameAndTypeVariables.hs +++ b/src/HIndent/Ast/Declaration/Class/NameAndTypeVariables.hs @@ -7,6 +7,7 @@ module HIndent.Ast.Declaration.Class.NameAndTypeVariables import qualified GHC.Types.Fixity as GHC import HIndent.Ast.Name.Infix +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.Type.Variable import HIndent.Ast.WithComments @@ -17,12 +18,12 @@ import HIndent.Pretty.NodeComments data NameAndTypeVariables = Prefix - { name :: GHC.LIdP GHC.GhcPs + { pName :: WithComments PrefixName -- Using `name` in both `Prefix` and `Infix` causes a type conflict. , typeVariables :: [WithComments TypeVariable] } | Infix { left :: WithComments TypeVariable - , name :: GHC.LIdP GHC.GhcPs + , iName :: WithComments InfixName , right :: WithComments TypeVariable , remains :: [WithComments TypeVariable] } @@ -32,16 +33,16 @@ instance CommentExtraction NameAndTypeVariables where nodeComments Infix {} = NodeComments [] [] [] instance Pretty NameAndTypeVariables where - pretty' Prefix {..} = spaced $ pretty name : fmap pretty typeVariables + pretty' Prefix {..} = spaced $ pretty pName : fmap pretty typeVariables pretty' Infix {..} = do - parens $ spaced [pretty left, pretty $ fmap mkInfixName name, pretty right] + parens $ spaced [pretty left, pretty iName, pretty right] spacePrefixed $ fmap pretty remains mkNameAndTypeVariables :: GHC.TyClDecl GHC.GhcPs -> Maybe NameAndTypeVariables mkNameAndTypeVariables GHC.ClassDecl {tcdFixity = GHC.Prefix, ..} = Just Prefix {..} where - name = tcdLName + pName = fromGenLocated $ fmap mkPrefixName tcdLName typeVariables = fmap mkTypeVariable . fromGenLocated <$> GHC.hsq_explicit tcdTyVars mkNameAndTypeVariables GHC.ClassDecl { tcdFixity = GHC.Infix @@ -50,7 +51,7 @@ mkNameAndTypeVariables GHC.ClassDecl { tcdFixity = GHC.Infix } = Just Infix {..} where left = mkTypeVariable <$> fromGenLocated h - name = tcdLName + iName = fromGenLocated $ fmap mkInfixName tcdLName right = mkTypeVariable <$> fromGenLocated t remains = fmap (fmap mkTypeVariable . fromGenLocated) xs mkNameAndTypeVariables _ = Nothing diff --git a/src/HIndent/Ast/Declaration/Data/GADT/Constructor.hs b/src/HIndent/Ast/Declaration/Data/GADT/Constructor.hs index 1f5df9ff1..4bddf8a4a 100644 --- a/src/HIndent/Ast/Declaration/Data/GADT/Constructor.hs +++ b/src/HIndent/Ast/Declaration/Data/GADT/Constructor.hs @@ -19,9 +19,10 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments #if MIN_VERSION_ghc_lib_parser(9, 6, 0) import qualified Data.List.NonEmpty as NE +import HIndent.Ast.Name.Prefix #endif data GADTConstructor = GADTConstructor - { names :: [WithComments (GHC.IdP GHC.GhcPs)] + { names :: [WithComments PrefixName] , bindings :: Maybe (WithComments [WithComments TypeVariable]) , context :: Maybe (WithComments Context) , signature :: ConstructorSignature @@ -79,10 +80,12 @@ mkGADTConstructor decl@GHC.ConDeclGADT {..} = Just $ GADTConstructor {..} context = fmap (fmap mkContext . fromGenLocated) con_mb_cxt mkGADTConstructor _ = Nothing -getNames :: GHC.ConDecl GHC.GhcPs -> Maybe [WithComments (GHC.IdP GHC.GhcPs)] +getNames :: GHC.ConDecl GHC.GhcPs -> Maybe [WithComments PrefixName] #if MIN_VERSION_ghc_lib_parser(9, 6, 0) -getNames GHC.ConDeclGADT {..} = Just $ NE.toList $ fmap fromGenLocated con_names +getNames GHC.ConDeclGADT {..} = + Just $ NE.toList $ fmap (fromGenLocated . fmap mkPrefixName) con_names #else -getNames GHC.ConDeclGADT {..} = Just $ fmap fromGenLocated con_names +getNames GHC.ConDeclGADT {..} = + Just $ fmap (fromGenLocated . fmap mkPrefixName) con_names #endif getNames _ = Nothing diff --git a/src/HIndent/Ast/Declaration/Data/Haskell98/Constructor/Body.hs b/src/HIndent/Ast/Declaration/Data/Haskell98/Constructor/Body.hs index 2a4f745e1..98cc26066 100644 --- a/src/HIndent/Ast/Declaration/Data/Haskell98/Constructor/Body.hs +++ b/src/HIndent/Ast/Declaration/Data/Haskell98/Constructor/Body.hs @@ -8,6 +8,7 @@ module HIndent.Ast.Declaration.Data.Haskell98.Constructor.Body import HIndent.Ast.Declaration.Data.Record.Field import HIndent.Ast.Name.Infix +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC @@ -17,16 +18,16 @@ import HIndent.Pretty.NodeComments data Haskell98ConstructorBody = Infix - { name :: GHC.LIdP GHC.GhcPs + { iName :: WithComments InfixName -- Using `name` in all constructors causes a type clash , left :: GHC.HsScaled GHC.GhcPs (GHC.LBangType GHC.GhcPs) , right :: GHC.HsScaled GHC.GhcPs (GHC.LBangType GHC.GhcPs) } | Prefix - { name :: GHC.LIdP GHC.GhcPs + { pName :: WithComments PrefixName , types :: [GHC.HsScaled GHC.GhcPs (GHC.LBangType GHC.GhcPs)] } | Record - { name :: GHC.LIdP GHC.GhcPs + { rName :: WithComments PrefixName , records :: WithComments [WithComments RecordField] } @@ -36,14 +37,13 @@ instance CommentExtraction Haskell98ConstructorBody where nodeComments Record {} = NodeComments [] [] [] instance Pretty Haskell98ConstructorBody where - pretty' Infix {..} = - spaced [pretty left, pretty $ fmap mkInfixName name, pretty right] - pretty' Prefix {..} = pretty name >> hor <-|> ver + pretty' Infix {..} = spaced [pretty left, pretty iName, pretty right] + pretty' Prefix {..} = pretty pName >> hor <-|> ver where hor = spacePrefixed $ fmap pretty types ver = indentedBlock $ newlinePrefixed $ fmap pretty types pretty' Record {..} = do - pretty name + pretty rName prettyWith records $ \r -> newline >> indentedBlock (vFields $ fmap pretty r) @@ -51,15 +51,17 @@ mkHaskell98ConstructorBody :: GHC.ConDecl GHC.GhcPs -> Maybe Haskell98ConstructorBody mkHaskell98ConstructorBody GHC.ConDeclH98 { con_args = GHC.InfixCon left right , .. - } = Just Infix {name = con_name, ..} + } = Just Infix {..} + where + iName = fromGenLocated $ fmap mkInfixName con_name mkHaskell98ConstructorBody GHC.ConDeclH98 {con_args = GHC.PrefixCon _ types, ..} = Just Prefix {..} where - name = con_name + pName = fromGenLocated $ fmap mkPrefixName con_name mkHaskell98ConstructorBody GHC.ConDeclH98 {con_args = GHC.RecCon rs, ..} = Just Record {..} where - name = con_name + rName = fromGenLocated $ fmap mkPrefixName con_name records = fromGenLocated $ fmap (fmap (fmap mkRecordField . fromGenLocated)) rs mkHaskell98ConstructorBody GHC.ConDeclGADT {} = Nothing diff --git a/src/HIndent/Ast/Declaration/Data/Header.hs b/src/HIndent/Ast/Declaration/Data/Header.hs index e964e5a9c..5c419f41f 100644 --- a/src/HIndent/Ast/Declaration/Data/Header.hs +++ b/src/HIndent/Ast/Declaration/Data/Header.hs @@ -8,6 +8,7 @@ module HIndent.Ast.Declaration.Data.Header import HIndent.Applicative import HIndent.Ast.Context import HIndent.Ast.Declaration.Data.NewOrData +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.Type.Variable import HIndent.Ast.WithComments @@ -18,7 +19,7 @@ import HIndent.Pretty.NodeComments data Header = Header { newOrData :: NewOrData - , name :: WithComments (GHC.IdP GHC.GhcPs) + , name :: WithComments PrefixName , context :: Maybe (WithComments Context) , typeVariables :: [WithComments TypeVariable] } @@ -39,7 +40,7 @@ mkHeader GHC.DataDecl {tcdDataDefn = defn@GHC.HsDataDefn {..}, ..} = where newOrData = mkNewOrData defn context = fmap (fmap mkContext . fromGenLocated) dd_ctxt - name = fromGenLocated tcdLName + name = fromGenLocated $ fmap mkPrefixName tcdLName typeVariables = fmap mkTypeVariable . fromGenLocated <$> GHC.hsq_explicit tcdTyVars mkHeader _ = Nothing diff --git a/src/HIndent/Ast/Declaration/Family/Data.hs b/src/HIndent/Ast/Declaration/Family/Data.hs index f93fdeccb..6f3585ef8 100644 --- a/src/HIndent/Ast/Declaration/Family/Data.hs +++ b/src/HIndent/Ast/Declaration/Family/Data.hs @@ -9,6 +9,7 @@ import Control.Monad import qualified GHC.Types.Basic as GHC import qualified GHC.Types.SrcLoc as GHC import HIndent.Applicative +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments hiding (fromEpAnn) import HIndent.Ast.Type import HIndent.Ast.Type.Variable @@ -20,7 +21,7 @@ import HIndent.Pretty.NodeComments data DataFamily = DataFamily { isTopLevel :: Bool - , name :: GHC.LIdP GHC.GhcPs + , name :: WithComments PrefixName , typeVariables :: [WithComments TypeVariable] , signature :: Maybe (WithComments Type) } @@ -46,7 +47,7 @@ mkDataFamily GHC.FamilyDecl {fdTyVars = GHC.HsQTvs {..}, ..} case fdTopLevel of GHC.TopLevel -> True GHC.NotTopLevel -> False - name = fdLName + name = fromGenLocated $ fmap mkPrefixName fdLName typeVariables = fmap (fmap mkTypeVariable . fromGenLocated) hsq_explicit signature = case GHC.unLoc fdResultSig of diff --git a/src/HIndent/Ast/Declaration/Family/Type.hs b/src/HIndent/Ast/Declaration/Family/Type.hs index 927f6e2fe..3fa289349 100644 --- a/src/HIndent/Ast/Declaration/Family/Type.hs +++ b/src/HIndent/Ast/Declaration/Family/Type.hs @@ -10,6 +10,7 @@ import qualified GHC.Types.Basic as GHC import HIndent.Applicative import HIndent.Ast.Declaration.Family.Type.Injectivity import HIndent.Ast.Declaration.Family.Type.ResultSignature +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments hiding (fromEpAnn) import HIndent.Ast.Type.Variable import HIndent.Ast.WithComments @@ -20,7 +21,7 @@ import HIndent.Pretty.NodeComments data TypeFamily = TypeFamily { isTopLevel :: Bool - , name :: GHC.LIdP GHC.GhcPs + , name :: WithComments PrefixName , typeVariables :: [WithComments TypeVariable] , signature :: WithComments ResultSignature , injectivity :: Maybe (WithComments Injectivity) @@ -50,7 +51,7 @@ mkTypeFamily GHC.FamilyDecl {fdTyVars = GHC.HsQTvs {..}, ..} case fdTopLevel of GHC.TopLevel -> True GHC.NotTopLevel -> False - name = fdLName + name = fromGenLocated $ fmap mkPrefixName fdLName typeVariables = fmap (fmap mkTypeVariable . fromGenLocated) hsq_explicit signature = mkResultSignature <$> fromGenLocated fdResultSig injectivity = fmap (fmap mkInjectivity . fromGenLocated) fdInjectivityAnn diff --git a/src/HIndent/Ast/Declaration/Family/Type/Injectivity.hs b/src/HIndent/Ast/Declaration/Family/Type/Injectivity.hs index b9c27a418..f628b1a42 100644 --- a/src/HIndent/Ast/Declaration/Family/Type/Injectivity.hs +++ b/src/HIndent/Ast/Declaration/Family/Type/Injectivity.hs @@ -5,15 +5,17 @@ module HIndent.Ast.Declaration.Family.Type.Injectivity , mkInjectivity ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data Injectivity = Injectivity - { from :: GHC.LIdP GHC.GhcPs - , to :: [GHC.LIdP GHC.GhcPs] + { from :: WithComments PrefixName + , to :: [WithComments PrefixName] } instance CommentExtraction Injectivity where @@ -23,4 +25,7 @@ instance Pretty Injectivity where pretty' Injectivity {..} = spaced $ pretty from : string "->" : fmap pretty to mkInjectivity :: GHC.InjectivityAnn GHC.GhcPs -> Injectivity -mkInjectivity (GHC.InjectivityAnn _ from to) = Injectivity {..} +mkInjectivity (GHC.InjectivityAnn _ f t) = Injectivity {..} + where + from = fromGenLocated $ fmap mkPrefixName f + to = fmap (fromGenLocated . fmap mkPrefixName) t diff --git a/src/HIndent/Ast/Declaration/Foreign.hs b/src/HIndent/Ast/Declaration/Foreign.hs index 118de5d86..513a90aef 100644 --- a/src/HIndent/Ast/Declaration/Foreign.hs +++ b/src/HIndent/Ast/Declaration/Foreign.hs @@ -12,7 +12,9 @@ import qualified GHC.Types.SourceText as GHC import qualified GHC.Types.SrcLoc as GHC import HIndent.Ast.Declaration.Foreign.CallingConvention import HIndent.Ast.Declaration.Foreign.Safety +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators @@ -25,13 +27,13 @@ data ForeignDeclaration { convention :: CallingConvention , safety :: Safety , srcIdent :: Maybe String - , dstIdent :: GHC.LIdP GHC.GhcPs + , dstIdent :: WithComments PrefixName , signature :: GHC.LHsSigType GHC.GhcPs } | ForeignExport { convention :: CallingConvention , srcIdent :: Maybe String - , dstIdent :: GHC.LIdP GHC.GhcPs + , dstIdent :: WithComments PrefixName , signature :: GHC.LHsSigType GHC.GhcPs } @@ -63,7 +65,7 @@ mkForeignDeclaration GHC.ForeignImport { fd_fi = (GHC.CImport (GHC.L _ src) (GHC case src of GHC.SourceText s -> Just $ GHC.unpackFS s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ src) (GHC.L _ (GHC.CExportStatic _ _ conv))) , .. @@ -74,7 +76,7 @@ mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ src) (GHC case src of GHC.SourceText s -> Just $ GHC.unpackFS s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty #elif MIN_VERSION_ghc_lib_parser(9, 6, 0) mkForeignDeclaration GHC.ForeignImport { fd_fi = (GHC.CImport (GHC.L _ src) (GHC.L _ conv) (GHC.L _ sfty) _ _) @@ -87,7 +89,7 @@ mkForeignDeclaration GHC.ForeignImport { fd_fi = (GHC.CImport (GHC.L _ src) (GHC case src of GHC.SourceText s -> Just s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ src) (GHC.L _ (GHC.CExportStatic _ _ conv))) , .. @@ -98,7 +100,7 @@ mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ src) (GHC case src of GHC.SourceText s -> Just s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty #else mkForeignDeclaration GHC.ForeignImport { fd_fi = (GHC.CImport (GHC.L _ conv) (GHC.L _ sfty) _ _ (GHC.L _ src)) @@ -111,7 +113,7 @@ mkForeignDeclaration GHC.ForeignImport { fd_fi = (GHC.CImport (GHC.L _ conv) (GH case src of GHC.SourceText s -> Just s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ (GHC.CExportStatic _ _ conv)) (GHC.L _ src)) , .. @@ -122,6 +124,6 @@ mkForeignDeclaration GHC.ForeignExport { fd_fe = (GHC.CExport (GHC.L _ (GHC.CExp case src of GHC.SourceText s -> Just s _ -> Nothing - dstIdent = fd_name + dstIdent = fromGenLocated $ fmap mkPrefixName fd_name signature = fd_sig_ty #endif diff --git a/src/HIndent/Ast/Declaration/Instance/Family/Data.hs b/src/HIndent/Ast/Declaration/Instance/Family/Data.hs index 913615239..3795c0678 100644 --- a/src/HIndent/Ast/Declaration/Instance/Family/Data.hs +++ b/src/HIndent/Ast/Declaration/Instance/Family/Data.hs @@ -8,7 +8,9 @@ module HIndent.Ast.Declaration.Instance.Family.Data import qualified GHC.Hs as GG import HIndent.Ast.Declaration.Data.Body import HIndent.Ast.Declaration.Data.NewOrData +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators @@ -16,7 +18,7 @@ import HIndent.Pretty.NodeComments data DataFamilyInstance = DataFamilyInstance { newOrData :: NewOrData - , name :: GHC.LIdP GHC.GhcPs + , name :: WithComments PrefixName , types :: GHC.HsTyPats GHC.GhcPs , body :: DataBody } @@ -35,6 +37,6 @@ mkDataFamilyInstance :: mkDataFamilyInstance GHC.FamEqn {..} = DataFamilyInstance {..} where newOrData = mkNewOrData feqn_rhs - name = feqn_tycon + name = fromGenLocated $ fmap mkPrefixName feqn_tycon types = feqn_pats body = mkDataBody feqn_rhs diff --git a/src/HIndent/Ast/Declaration/Instance/Family/Type.hs b/src/HIndent/Ast/Declaration/Instance/Family/Type.hs index ffec1651a..93b9e7dda 100644 --- a/src/HIndent/Ast/Declaration/Instance/Family/Type.hs +++ b/src/HIndent/Ast/Declaration/Instance/Family/Type.hs @@ -5,14 +5,16 @@ module HIndent.Ast.Declaration.Instance.Family.Type , mkTypeFamilyInstance ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data TypeFamilyInstance = TypeFamilyInstance - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , types :: GHC.HsTyPats GHC.GhcPs , bind :: GHC.LHsType GHC.GhcPs } @@ -30,7 +32,7 @@ mkTypeFamilyInstance :: GHC.InstDecl GHC.GhcPs -> Maybe TypeFamilyInstance mkTypeFamilyInstance GHC.TyFamInstD {GHC.tfid_inst = GHC.TyFamInstDecl {GHC.tfid_eqn = GHC.FamEqn {..}}} = Just $ TypeFamilyInstance {..} where - name = feqn_tycon + name = fromGenLocated $ fmap mkPrefixName feqn_tycon types = feqn_pats bind = feqn_rhs mkTypeFamilyInstance _ = Nothing diff --git a/src/HIndent/Ast/Declaration/Rule/Binder.hs b/src/HIndent/Ast/Declaration/Rule/Binder.hs index 581c0431e..33a6e57be 100644 --- a/src/HIndent/Ast/Declaration/Rule/Binder.hs +++ b/src/HIndent/Ast/Declaration/Rule/Binder.hs @@ -5,6 +5,7 @@ module HIndent.Ast.Declaration.Rule.Binder , mkRuleBinder ) where +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC @@ -13,7 +14,7 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data RuleBinder = RuleBinder - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , signature :: Maybe (WithComments (GHC.HsType GHC.GhcPs)) } @@ -26,6 +27,11 @@ instance Pretty RuleBinder where parens $ spaced [pretty name, string "::", pretty sig] mkRuleBinder :: GHC.RuleBndr GHC.GhcPs -> RuleBinder -mkRuleBinder (GHC.RuleBndr _ name) = RuleBinder {signature = Nothing, ..} -mkRuleBinder (GHC.RuleBndrSig _ name GHC.HsPS {..}) = - RuleBinder {signature = Just $ fromGenLocated hsps_body, ..} +mkRuleBinder (GHC.RuleBndr _ n) = RuleBinder {..} + where + signature = Nothing + name = fromGenLocated $ fmap mkPrefixName n +mkRuleBinder (GHC.RuleBndrSig _ n GHC.HsPS {..}) = RuleBinder {..} + where + signature = Just $ fromGenLocated hsps_body + name = fromGenLocated $ fmap mkPrefixName n diff --git a/src/HIndent/Ast/Declaration/Signature.hs b/src/HIndent/Ast/Declaration/Signature.hs index 960523cbb..1e2847213 100644 --- a/src/HIndent/Ast/Declaration/Signature.hs +++ b/src/HIndent/Ast/Declaration/Signature.hs @@ -14,6 +14,7 @@ import HIndent.Ast.Declaration.Signature.Fixity import HIndent.Ast.Declaration.Signature.Inline.Phase import HIndent.Ast.Declaration.Signature.Inline.Spec import HIndent.Ast.Name.Infix +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC @@ -26,38 +27,38 @@ import HIndent.Pretty.Types -- doesn't allow it. data Signature = Type - { names :: [GHC.LIdP GHC.GhcPs] + { names :: [WithComments PrefixName] , parameters :: GHC.LHsSigWcType GHC.GhcPs } | Pattern - { names :: [GHC.LIdP GHC.GhcPs] + { names :: [WithComments PrefixName] , signature :: GHC.LHsSigType GHC.GhcPs } | DefaultClassMethod - { names :: [GHC.LIdP GHC.GhcPs] + { names :: [WithComments PrefixName] , signature :: GHC.LHsSigType GHC.GhcPs } | ClassMethod - { names :: [GHC.LIdP GHC.GhcPs] + { names :: [WithComments PrefixName] , signature :: GHC.LHsSigType GHC.GhcPs } | Fixity - { names :: [GHC.LIdP GHC.GhcPs] + { opNames :: [WithComments InfixName] -- Using `names` causes a type conflict. , fixity :: Fixity } | Inline - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , spec :: InlineSpec , phase :: Maybe InlinePhase } | Specialise - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , sigs :: [GHC.LHsSigType GHC.GhcPs] } | SpecialiseInstance (GHC.LHsSigType GHC.GhcPs) | Minimal (WithComments BooleanFormula) - | Scc (GHC.LIdP GHC.GhcPs) - | Complete (GHC.XRec GHC.GhcPs [GHC.LIdP GHC.GhcPs]) + | Scc (WithComments PrefixName) + | Complete (WithComments [WithComments PrefixName]) instance CommentExtraction Signature where nodeComments Type {} = NodeComments [] [] [] @@ -121,8 +122,7 @@ instance Pretty Signature where indentedBlock $ indentedWithSpace 3 $ printCommentsAnd signature (pretty . HsSigTypeInsideDeclSig) - pretty' Fixity {..} = - spaced [pretty fixity, hCommaSep $ fmap (pretty . fmap mkInfixName) names] + pretty' Fixity {..} = spaced [pretty fixity, hCommaSep $ fmap pretty opNames] pretty' Inline {..} = do string "{-# " pretty spec @@ -148,28 +148,45 @@ instance Pretty Signature where pretty' (Complete names) = spaced [ string "{-# COMPLETE" - , printCommentsAnd names (hCommaSep . fmap pretty) + , prettyWith names (hCommaSep . fmap pretty) , string "#-}" ] mkSignature :: GHC.Sig GHC.GhcPs -> Signature -mkSignature (GHC.TypeSig _ names parameters) = Type {..} -mkSignature (GHC.PatSynSig _ names signature) = Pattern {..} -mkSignature (GHC.ClassOpSig _ True names signature) = DefaultClassMethod {..} -mkSignature (GHC.ClassOpSig _ False names signature) = ClassMethod {..} -mkSignature (GHC.FixSig _ (GHC.FixitySig _ names fixity)) = - Fixity {fixity = mkFixity fixity, ..} -mkSignature (GHC.InlineSig _ name GHC.InlinePragma {..}) = Inline {..} +mkSignature (GHC.TypeSig _ ns parameters) = Type {..} where + names = fmap (fromGenLocated . fmap mkPrefixName) ns +mkSignature (GHC.PatSynSig _ ns signature) = Pattern {..} + where + names = fmap (fromGenLocated . fmap mkPrefixName) ns +mkSignature (GHC.ClassOpSig _ True ns signature) = DefaultClassMethod {..} + where + names = fmap (fromGenLocated . fmap mkPrefixName) ns +mkSignature (GHC.ClassOpSig _ False ns signature) = ClassMethod {..} + where + names = fmap (fromGenLocated . fmap mkPrefixName) ns +mkSignature (GHC.FixSig _ (GHC.FixitySig _ ops fy)) = Fixity {..} + where + fixity = mkFixity fy + opNames = fmap (fromGenLocated . fmap mkInfixName) ops +mkSignature (GHC.InlineSig _ n GHC.InlinePragma {..}) = Inline {..} + where + name = fromGenLocated $ fmap mkPrefixName n spec = mkInlineSpec inl_inline phase = mkInlinePhase inl_act -mkSignature (GHC.SpecSig _ name sigs _) = Specialise {..} +mkSignature (GHC.SpecSig _ n sigs _) = Specialise {..} + where + name = fromGenLocated $ fmap mkPrefixName n #if MIN_VERSION_ghc_lib_parser(9, 6, 0) mkSignature (GHC.SpecInstSig _ sig) = SpecialiseInstance sig mkSignature (GHC.MinimalSig _ xs) = Minimal $ mkBooleanFormula <$> fromGenLocated xs -mkSignature (GHC.SCCFunSig _ name _) = Scc name -mkSignature (GHC.CompleteMatchSig _ names _) = Complete names +mkSignature (GHC.SCCFunSig _ n _) = Scc name + where + name = fromGenLocated $ fmap mkPrefixName n +mkSignature (GHC.CompleteMatchSig _ ns _) = Complete names + where + names = fromGenLocated $ fmap (fmap (fromGenLocated . fmap mkPrefixName)) ns #else mkSignature (GHC.SpecInstSig _ _ sig) = SpecialiseInstance sig mkSignature (GHC.MinimalSig _ _ xs) = diff --git a/src/HIndent/Ast/Declaration/Signature/BooleanFormula.hs b/src/HIndent/Ast/Declaration/Signature/BooleanFormula.hs index a0adc6964..7e680ba51 100644 --- a/src/HIndent/Ast/Declaration/Signature/BooleanFormula.hs +++ b/src/HIndent/Ast/Declaration/Signature/BooleanFormula.hs @@ -4,6 +4,7 @@ module HIndent.Ast.Declaration.Signature.BooleanFormula ) where import qualified GHC.Data.BooleanFormula as GHC +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC @@ -12,7 +13,7 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data BooleanFormula - = Var (GHC.LIdP GHC.GhcPs) + = Var (WithComments PrefixName) | And [WithComments BooleanFormula] | Or [WithComments BooleanFormula] | Parens (WithComments BooleanFormula) @@ -30,7 +31,7 @@ instance Pretty BooleanFormula where pretty' (Parens x) = parens $ pretty x mkBooleanFormula :: GHC.BooleanFormula (GHC.LIdP GHC.GhcPs) -> BooleanFormula -mkBooleanFormula (GHC.Var x) = Var x +mkBooleanFormula (GHC.Var x) = Var $ fromGenLocated $ fmap mkPrefixName x mkBooleanFormula (GHC.And xs) = And $ fmap (fmap mkBooleanFormula . fromGenLocated) xs mkBooleanFormula (GHC.Or xs) = diff --git a/src/HIndent/Ast/Declaration/Signature/StandaloneKind.hs b/src/HIndent/Ast/Declaration/Signature/StandaloneKind.hs index 9b420ea2c..3cda114ce 100644 --- a/src/HIndent/Ast/Declaration/Signature/StandaloneKind.hs +++ b/src/HIndent/Ast/Declaration/Signature/StandaloneKind.hs @@ -6,13 +6,15 @@ module HIndent.Ast.Declaration.Signature.StandaloneKind ) where import qualified GHC.Hs as GHC +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import {-# SOURCE #-} HIndent.Pretty import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data StandaloneKind = StandaloneKind - { name :: GHC.LIdP GHC.GhcPs + { name :: WithComments PrefixName , kind :: GHC.LHsSigType GHC.GhcPs } @@ -24,4 +26,6 @@ instance Pretty StandaloneKind where spaced [string "type", pretty name, string "::", pretty kind] mkStandaloneKind :: GHC.StandaloneKindSig GHC.GhcPs -> StandaloneKind -mkStandaloneKind (GHC.StandaloneKindSig _ name kind) = StandaloneKind {..} +mkStandaloneKind (GHC.StandaloneKindSig _ n kind) = StandaloneKind {..} + where + name = fromGenLocated $ fmap mkPrefixName n diff --git a/src/HIndent/Ast/Declaration/TypeSynonym/Lhs.hs b/src/HIndent/Ast/Declaration/TypeSynonym/Lhs.hs index bf2a7376f..79244dd56 100644 --- a/src/HIndent/Ast/Declaration/TypeSynonym/Lhs.hs +++ b/src/HIndent/Ast/Declaration/TypeSynonym/Lhs.hs @@ -7,6 +7,7 @@ module HIndent.Ast.Declaration.TypeSynonym.Lhs import qualified GHC.Types.Fixity as GHC import HIndent.Ast.Name.Infix +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.Type.Variable import HIndent.Ast.WithComments @@ -17,12 +18,12 @@ import HIndent.Pretty.NodeComments data TypeSynonymLhs = Prefix - { name :: GHC.LIdP GHC.GhcPs + { pName :: WithComments PrefixName -- Using `name` in both `Prefix` and `Infix` causes a type conflict. , typeVariables :: [WithComments TypeVariable] } | Infix { left :: WithComments TypeVariable - , name :: GHC.LIdP GHC.GhcPs + , iName :: WithComments InfixName , right :: WithComments TypeVariable } @@ -31,24 +32,20 @@ instance CommentExtraction TypeSynonymLhs where nodeComments Infix {} = NodeComments [] [] [] instance Pretty TypeSynonymLhs where - pretty' Prefix {..} = spaced $ pretty name : fmap pretty typeVariables - pretty' Infix {..} = - spaced [pretty left, pretty $ fmap mkInfixName name, pretty right] + pretty' Prefix {..} = spaced $ pretty pName : fmap pretty typeVariables + pretty' Infix {..} = spaced [pretty left, pretty iName, pretty right] mkTypeSynonymLhs :: GHC.TyClDecl GHC.GhcPs -> TypeSynonymLhs -mkTypeSynonymLhs GHC.SynDecl {tcdFixity = GHC.Prefix, ..} = - Prefix - { name = tcdLName - , typeVariables = - fmap mkTypeVariable . fromGenLocated <$> GHC.hsq_explicit tcdTyVars - } +mkTypeSynonymLhs GHC.SynDecl {tcdFixity = GHC.Prefix, ..} = Prefix {..} + where + pName = fromGenLocated $ fmap mkPrefixName tcdLName + typeVariables = + fmap mkTypeVariable . fromGenLocated <$> GHC.hsq_explicit tcdTyVars mkTypeSynonymLhs GHC.SynDecl {tcdFixity = GHC.Infix, ..} = case GHC.hsq_explicit tcdTyVars of - [l, r] -> - Infix - { left = mkTypeVariable <$> fromGenLocated l - , name = tcdLName - , right = mkTypeVariable <$> fromGenLocated r - } + [l, r] -> Infix {..} + where left = mkTypeVariable <$> fromGenLocated l + iName = fromGenLocated $ fmap mkInfixName tcdLName + right = mkTypeVariable <$> fromGenLocated r _ -> error "Unexpected number of type variables for infix type synonym." mkTypeSynonymLhs _ = error "Not a type synonym." diff --git a/src/HIndent/Ast/Declaration/Warning.hs b/src/HIndent/Ast/Declaration/Warning.hs index 979032340..899f67d6f 100644 --- a/src/HIndent/Ast/Declaration/Warning.hs +++ b/src/HIndent/Ast/Declaration/Warning.hs @@ -9,7 +9,9 @@ module HIndent.Ast.Declaration.Warning import qualified GHC.Types.SourceText as GHC import qualified GHC.Types.SrcLoc as GHC import HIndent.Ast.Declaration.Warning.Kind +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments +import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import qualified HIndent.GhcLibParserWrapper.GHC.Unit.Module.Warnings as GHC import {-# SOURCE #-} HIndent.Pretty @@ -17,7 +19,7 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data WarningDeclaration = WarningDeclaration - { names :: [GHC.LIdP GHC.GhcPs] + { names :: [WithComments PrefixName] , kind :: Kind , reasons :: [GHC.Located GHC.StringLiteral] } @@ -35,22 +37,26 @@ instance Pretty WarningDeclaration where mkWarningDeclaration :: GHC.WarnDecl GHC.GhcPs -> WarningDeclaration #if MIN_VERSION_ghc_lib_parser(9, 8, 1) -mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ rs)) = +mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) = WarningDeclaration {kind = Deprecated, ..} where + names = fmap (fromGenLocated . fmap mkPrefixName) ns reasons = fmap (fmap GHC.hsDocString) rs -mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ _ rs)) = +mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ _ rs)) = WarningDeclaration {kind = Warning, ..} where + names = fmap (fromGenLocated . fmap mkPrefixName) ns reasons = fmap (fmap GHC.hsDocString) rs #elif MIN_VERSION_ghc_lib_parser(9, 4, 1) -mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ rs)) = +mkWarningDeclaration (GHC.Warning _ ns (GHC.DeprecatedTxt _ rs)) = WarningDeclaration {kind = Deprecated, ..} where + names = fmap (fromGenLocated . fmap mkPrefixName) ns reasons = fmap (fmap GHC.hsDocString) rs -mkWarningDeclaration (GHC.Warning _ names (GHC.WarningTxt _ rs)) = +mkWarningDeclaration (GHC.Warning _ ns (GHC.WarningTxt _ rs)) = WarningDeclaration {kind = Warning, ..} where + names = fmap (fromGenLocated . fmap mkPrefixName) ns reasons = fmap (fmap GHC.hsDocString) rs #else mkWarningDeclaration (GHC.Warning _ names (GHC.DeprecatedTxt _ reasons)) = diff --git a/src/HIndent/Ast/Expression/Bracket.hs b/src/HIndent/Ast/Expression/Bracket.hs index 45b2fcba3..14f406911 100644 --- a/src/HIndent/Ast/Expression/Bracket.hs +++ b/src/HIndent/Ast/Expression/Bracket.hs @@ -6,6 +6,7 @@ module HIndent.Ast.Expression.Bracket ) where import HIndent.Ast.Declaration +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.WithComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC @@ -19,7 +20,7 @@ data Bracket | Pattern (GHC.LPat GHC.GhcPs) | Declaration [WithComments Declaration] | Type (GHC.LHsType GHC.GhcPs) - | Variable Bool (GHC.LIdP GHC.GhcPs) + | Variable Bool (WithComments PrefixName) instance CommentExtraction Bracket where nodeComments TypedExpression {} = NodeComments [] [] [] @@ -48,7 +49,7 @@ mkBracket (GHC.PatBr _ x) = Pattern x mkBracket (GHC.DecBrL _ x) = Declaration $ fmap (fmap mkDeclaration . fromGenLocated) x mkBracket (GHC.TypBr _ x) = Type x -mkBracket (GHC.VarBr _ b x) = Variable b x +mkBracket (GHC.VarBr _ b x) = Variable b $ fromGenLocated $ fmap mkPrefixName x mkBracket (GHC.DecBrG {}) = error "This AST node should never appear." #if !MIN_VERSION_ghc_lib_parser(9, 4, 1) mkBracket (GHC.TExpBr _ x) = TypedExpression x diff --git a/src/HIndent/Ast/Expression/Splice.hs b/src/HIndent/Ast/Expression/Splice.hs index a36a4266b..a9e15a46a 100644 --- a/src/HIndent/Ast/Expression/Splice.hs +++ b/src/HIndent/Ast/Expression/Splice.hs @@ -6,7 +6,7 @@ module HIndent.Ast.Expression.Splice ) where import qualified GHC.Data.FastString as GHC -import qualified GHC.Types.Name.Reader as GHC +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import {-# SOURCE #-} HIndent.Pretty @@ -19,7 +19,7 @@ data Splice = Typed (GHC.LHsExpr GHC.GhcPs) | UntypedDollar (GHC.LHsExpr GHC.GhcPs) | UntypedBare (GHC.LHsExpr GHC.GhcPs) - | QuasiQuote GHC.RdrName GHC.FastString + | QuasiQuote PrefixName GHC.FastString instance CommentExtraction Splice where nodeComments Typed {} = NodeComments [] [] [] @@ -47,12 +47,12 @@ instance Pretty Splice where #if MIN_VERSION_ghc_lib_parser(9, 6, 1) mkSplice :: GHC.HsUntypedSplice GHC.GhcPs -> Splice mkSplice (GHC.HsUntypedSpliceExpr _ x) = UntypedDollar x -mkSplice (GHC.HsQuasiQuote _ l (GHC.L _ r)) = QuasiQuote l r +mkSplice (GHC.HsQuasiQuote _ l (GHC.L _ r)) = QuasiQuote (mkPrefixName l) r #else mkSplice :: GHC.HsSplice GHC.GhcPs -> Splice mkSplice (GHC.HsTypedSplice _ _ _ body) = Typed body mkSplice (GHC.HsUntypedSplice _ GHC.DollarSplice _ body) = UntypedDollar body mkSplice (GHC.HsUntypedSplice _ GHC.BareSplice _ body) = UntypedBare body -mkSplice (GHC.HsQuasiQuote _ _ l _ r) = QuasiQuote l r +mkSplice (GHC.HsQuasiQuote _ _ l _ r) = QuasiQuote (mkPrefixName l) r mkSplice GHC.HsSpliced {} = error "This AST node should never appear." #endif diff --git a/src/HIndent/Ast/Type/Variable.hs b/src/HIndent/Ast/Type/Variable.hs index 1cd64744c..133aed4a0 100644 --- a/src/HIndent/Ast/Type/Variable.hs +++ b/src/HIndent/Ast/Type/Variable.hs @@ -6,6 +6,7 @@ module HIndent.Ast.Type.Variable ) where import qualified GHC.Hs as GHC +import HIndent.Ast.Name.Prefix import HIndent.Ast.NodeComments import HIndent.Ast.Type import HIndent.Ast.WithComments @@ -14,7 +15,7 @@ import HIndent.Pretty.Combinators import HIndent.Pretty.NodeComments data TypeVariable = TypeVariable - { name :: WithComments (GHC.IdP GHC.GhcPs) + { name :: WithComments PrefixName , kind :: Maybe (WithComments Type) } @@ -27,8 +28,11 @@ instance Pretty TypeVariable where pretty' TypeVariable {kind = Nothing, ..} = pretty name mkTypeVariable :: GHC.HsTyVarBndr a GHC.GhcPs -> TypeVariable -mkTypeVariable (GHC.UserTyVar _ _ n) = - TypeVariable {name = fromGenLocated n, kind = Nothing} -mkTypeVariable (GHC.KindedTyVar _ _ n k) = - TypeVariable - {name = fromGenLocated n, kind = Just $ mkType <$> fromGenLocated k} +mkTypeVariable (GHC.UserTyVar _ _ n) = TypeVariable {..} + where + name = fromGenLocated $ fmap mkPrefixName n + kind = Nothing +mkTypeVariable (GHC.KindedTyVar _ _ n k) = TypeVariable {..} + where + name = fromGenLocated $ fmap mkPrefixName n + kind = Just $ mkType <$> fromGenLocated k diff --git a/src/HIndent/Pretty.hs b/src/HIndent/Pretty.hs index 22c00702c..aeb9e8259 100644 --- a/src/HIndent/Pretty.hs +++ b/src/HIndent/Pretty.hs @@ -154,7 +154,7 @@ instance Pretty (GHC.HsExpr GHC.GhcPs) where prettyHsExpr :: GHC.HsExpr GHC.GhcPs -> Printer () prettyHsExpr (GHC.HsVar _ bind) = pretty $ fmap mkPrefixName bind -prettyHsExpr (GHC.HsUnboundVar _ x) = pretty x +prettyHsExpr (GHC.HsUnboundVar _ x) = pretty $ mkPrefixName x #if MIN_VERSION_ghc_lib_parser(9,6,1) prettyHsExpr (GHC.HsOverLabel _ _ l) = string "#" >> string (GHC.unpackFS l) #else @@ -308,9 +308,9 @@ prettyHsExpr (GHC.ExplicitList _ xs) = horizontal <-|> vertical vertical = vList $ fmap pretty xs prettyHsExpr (GHC.RecordCon _ name fields) = horizontal <-|> vertical where - horizontal = spaced [pretty name, pretty fields] + horizontal = spaced [pretty $ fmap mkPrefixName name, pretty fields] vertical = do - pretty name + pretty $ fmap mkPrefixName name (space >> pretty fields) <-|> (newline >> indentedBlock (pretty fields)) #if MIN_VERSION_ghc_lib_parser(9,8,1) prettyHsExpr (GHC.RecordUpd _ name fields) = hor <-|> ver @@ -709,8 +709,9 @@ prettyHsType GHC.HsQualTy {..} = hor <-|> ver ver = do pretty $ Context hst_ctxt lined [string " =>", indentedBlock $ pretty hst_body] -prettyHsType (GHC.HsTyVar _ GHC.NotPromoted x) = pretty x -prettyHsType (GHC.HsTyVar _ GHC.IsPromoted x) = string "'" >> pretty x +prettyHsType (GHC.HsTyVar _ GHC.NotPromoted x) = pretty $ fmap mkPrefixName x +prettyHsType (GHC.HsTyVar _ GHC.IsPromoted x) = + string "'" >> pretty (fmap mkPrefixName x) prettyHsType x@(GHC.HsAppTy _ l r) = hor <-|> ver where hor = spaced $ fmap pretty [l, r] @@ -817,7 +818,8 @@ instance Pretty (GHC.HsMatchContext GHC.GhcPs) where pretty' = prettyHsMatchContext prettyHsMatchContext :: GHC.HsMatchContext GHC.GhcPs -> Printer () -prettyHsMatchContext GHC.FunRhs {..} = pretty mc_strictness >> pretty mc_fun +prettyHsMatchContext GHC.FunRhs {..} = + pretty mc_strictness >> pretty (fmap mkPrefixName mc_fun) prettyHsMatchContext GHC.LambdaExpr = return () prettyHsMatchContext GHC.CaseAlt = return () prettyHsMatchContext GHC.IfAlt {} = notGeneratedByParser @@ -839,9 +841,6 @@ instance Pretty ParStmtBlockInsideVerticalList where pretty' (ParStmtBlockInsideVerticalList (GHC.ParStmtBlock _ xs _ _)) = vCommaSep $ fmap pretty xs -instance Pretty GHC.RdrName where - pretty' = pretty . mkPrefixName - instance Pretty (GHC.GRHS GHC.GhcPs @@ -942,10 +941,11 @@ instance Pretty PatInsidePatDecl where prettyPat :: GHC.Pat GHC.GhcPs -> Printer () prettyPat GHC.WildPat {} = string "_" -prettyPat (GHC.VarPat _ x) = pretty x +prettyPat (GHC.VarPat _ x) = pretty $ fmap mkPrefixName x prettyPat (GHC.LazyPat _ x) = string "~" >> pretty x #if MIN_VERSION_ghc_lib_parser(9,6,1) -prettyPat (GHC.AsPat _ a _ b) = pretty a >> string "@" >> pretty b +prettyPat (GHC.AsPat _ a _ b) = + pretty (fmap mkPrefixName a) >> string "@" >> pretty b #else prettyPat (GHC.AsPat _ a b) = pretty a >> string "@" >> pretty b #endif @@ -971,7 +971,8 @@ prettyPat GHC.ConPat {..} = GHC.PrefixCon _ as -> do pretty $ fmap mkPrefixName pat_con spacePrefixed $ fmap pretty as - GHC.RecCon rec -> (pretty pat_con >> space) |=> pretty (RecConPat rec) + GHC.RecCon rec -> + (pretty (fmap mkPrefixName pat_con) >> space) |=> pretty (RecConPat rec) GHC.InfixCon a b -> do pretty a unlessSpecialOp (GHC.unLoc pat_con) space @@ -982,7 +983,8 @@ prettyPat (GHC.ViewPat _ l r) = spaced [pretty l, string "->", pretty r] prettyPat (GHC.SplicePat _ x) = pretty $ mkSplice x prettyPat (GHC.LitPat _ x) = pretty x prettyPat (GHC.NPat _ x _ _) = pretty x -prettyPat (GHC.NPlusKPat _ n k _ _ _) = pretty n >> string "+" >> pretty k +prettyPat (GHC.NPlusKPat _ n k _ _ _) = + pretty (fmap mkPrefixName n) >> string "+" >> pretty k prettyPat (GHC.SigPat _ l r) = spaced [pretty l, string "::", pretty r] instance Pretty RecConPat where @@ -1087,10 +1089,10 @@ instance Pretty RecConField where #endif #if MIN_VERSION_ghc_lib_parser(9,4,1) instance Pretty (GHC.FieldOcc GHC.GhcPs) where - pretty' GHC.FieldOcc {..} = pretty foLabel + pretty' GHC.FieldOcc {..} = pretty $ fmap mkPrefixName foLabel #else instance Pretty (GHC.FieldOcc GHC.GhcPs) where - pretty' GHC.FieldOcc {..} = pretty rdrNameFieldOcc + pretty' GHC.FieldOcc {..} = pretty $ fmap mkPrefixName rdrNameFieldOcc #endif instance Pretty a => Pretty (GHC.HsScaled GHC.GhcPs a) where pretty' (GHC.HsScaled _ x) = pretty x @@ -1162,8 +1164,8 @@ instance Pretty (GHC.FieldLabelStrings GHC.GhcPs) where pretty' (GHC.FieldLabelStrings xs) = hDotSep $ fmap pretty xs instance Pretty (GHC.AmbiguousFieldOcc GHC.GhcPs) where - pretty' (GHC.Unambiguous _ name) = pretty name - pretty' (GHC.Ambiguous _ name) = pretty name + pretty' (GHC.Unambiguous _ name) = pretty $ fmap mkPrefixName name + pretty' (GHC.Ambiguous _ name) = pretty $ fmap mkPrefixName name instance Pretty (GHC.DerivClauseTys GHC.GhcPs) where pretty' (GHC.DctSingle _ ty) = parens $ pretty ty @@ -1269,7 +1271,7 @@ instance Pretty GHC.GhcPs (GHC.GenLocated GHC.SrcSpanAnnA (GHC.HsType GHC.GhcPs))) where pretty' GHC.FamEqn {..} = do - pretty feqn_tycon + pretty $ fmap mkPrefixName feqn_tycon spacePrefixed $ fmap pretty feqn_pats string " = " pretty feqn_rhs @@ -1280,7 +1282,10 @@ instance Pretty (GHC.FamEqn GHC.GhcPs (GHC.HsDataDefn GHC.GhcPs)) where #if MIN_VERSION_ghc_lib_parser(9, 6, 1) instance Pretty FamEqn' where pretty' FamEqn' {famEqn = GHC.FamEqn {..}, ..} = do - spaced $ string prefix : pretty feqn_tycon : fmap pretty feqn_pats + spaced + $ string prefix + : pretty (fmap mkPrefixName feqn_tycon) + : fmap pretty feqn_pats pretty (mkDataBody feqn_rhs) where prefix = @@ -1329,9 +1334,11 @@ instance Pretty (GHC.WithHsDocIdentifiers GHC.StringLiteral GHC.GhcPs) where #if MIN_VERSION_ghc_lib_parser(9,6,1) -- | 'Pretty' for 'LIEWrappedName (IdP GhcPs)' instance Pretty (GHC.IEWrappedName GHC.GhcPs) where - pretty' (GHC.IEName _ name) = pretty name - pretty' (GHC.IEPattern _ name) = spaced [string "pattern", pretty name] - pretty' (GHC.IEType _ name) = string "type " >> pretty name + pretty' (GHC.IEName _ name) = pretty $ fmap mkPrefixName name + pretty' (GHC.IEPattern _ name) = + spaced [string "pattern", pretty $ fmap mkPrefixName name] + pretty' (GHC.IEType _ name) = + string "type " >> pretty (fmap mkPrefixName name) #else -- | 'Pretty' for 'LIEWrappedName (IdP GhcPs)' instance Pretty (GHC.IEWrappedName GHC.RdrName) where @@ -1381,7 +1388,7 @@ instance Pretty Void (GHC.GenLocated GHC.SrcSpanAnnN GHC.RdrName) [GHC.RecordPatSynField GHC.GhcPs]) where - pretty' (GHC.PrefixCon _ xs) = spaced $ fmap pretty xs + pretty' (GHC.PrefixCon _ xs) = spaced $ fmap (pretty . fmap mkPrefixName) xs pretty' (GHC.RecCon rec) = hFields $ fmap pretty rec pretty' GHC.InfixCon {} = error diff --git a/src/HIndent/Pretty.hs-boot b/src/HIndent/Pretty.hs-boot index ea1ebd9a8..84d3adedf 100644 --- a/src/HIndent/Pretty.hs-boot +++ b/src/HIndent/Pretty.hs-boot @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} module HIndent.Pretty @@ -7,18 +7,18 @@ module HIndent.Pretty , printCommentsAnd ) where -import Data.Void -import qualified GHC.Types.Name as GHC -import qualified GHC.Types.Name.Reader as GHC -import qualified GHC.Types.SourceText as GHC -import qualified GHC.Types.SrcLoc as GHC -import qualified GHC.Unit as GHC +import Data.Void +import qualified GHC.Types.Name as GHC +import qualified GHC.Types.Name.Reader as GHC +import qualified GHC.Types.SourceText as GHC +import qualified GHC.Types.SrcLoc as GHC +import qualified GHC.Unit as GHC import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHC import qualified HIndent.GhcLibParserWrapper.GHC.Hs as GHc -import HIndent.Pretty.NodeComments -import HIndent.Pretty.SigBindFamily -import HIndent.Pretty.Types -import HIndent.Printer +import HIndent.Pretty.NodeComments +import HIndent.Pretty.SigBindFamily +import HIndent.Pretty.Types +import HIndent.Printer class CommentExtraction a => Pretty a @@ -42,8 +42,6 @@ instance Pretty GHC.GhcPs (GHC.GenLocated GHC.SrcSpanAnnA (GHC.HsType GHC.GhcPs))) -instance Pretty GHC.RdrName - instance Pretty SigBindFamily instance Pretty HsSigType'