diff options
author | romes <rodrigo.m.mesquita@gmail.com> | 2022-05-14 12:12:19 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-07-03 14:11:31 -0400 |
commit | 3a8970ac0c69335a1d229f9c9a71e6e333e99bfb (patch) | |
tree | 28a786d6e3bbc40b068cc7fe10433a9a8037b1d6 /compiler/Language | |
parent | 9e79f6d09c9fbd81150a45d307f753141453c945 (diff) | |
download | haskell-3a8970ac0c69335a1d229f9c9a71e6e333e99bfb.tar.gz |
TTG: Move HsModule to L.H.S
Move the definition of HsModule defined in GHC.Hs to
Language.Haskell.Syntax with an added TTG parameter and corresponding
extension fields.
This is progress towards having the haskell-syntax package, as described
in #21592
Diffstat (limited to 'compiler/Language')
-rw-r--r-- | compiler/Language/Haskell/Syntax.hs | 51 | ||||
-rw-r--r-- | compiler/Language/Haskell/Syntax.hs-boot | 9 | ||||
-rw-r--r-- | compiler/Language/Haskell/Syntax/Extension.hs | 6 |
3 files changed, 65 insertions, 1 deletions
diff --git a/compiler/Language/Haskell/Syntax.hs b/compiler/Language/Haskell/Syntax.hs index 79012495ef..143b682405 100644 --- a/compiler/Language/Haskell/Syntax.hs +++ b/compiler/Language/Haskell/Syntax.hs @@ -24,6 +24,7 @@ module Language.Haskell.Syntax ( module Language.Haskell.Syntax.Pat, module Language.Haskell.Syntax.Type, module Language.Haskell.Syntax.Extension, + ModuleName(..), HsModule(..) ) where import Language.Haskell.Syntax.Decls @@ -34,6 +35,12 @@ import Language.Haskell.Syntax.Extension import Language.Haskell.Syntax.Pat import Language.Haskell.Syntax.Type +import GHC.Data.FastString +import GHC.Data.Maybe (Maybe) +import GHC.Prelude (Show) +import GHC.Parser.Annotation +import GHC.Hs.ImpExp (LIE, LImportDecl) + {- Note [Language.Haskell.Syntax.* Hierarchy] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -55,5 +62,47 @@ For more details, see https://gitlab.haskell.org/ghc/ghc/-/wikis/implementing-trees-that-grow -} +-- | A ModuleName is essentially a simple string, e.g. @Data.List@. +newtype ModuleName = ModuleName FastString deriving Show + +-- | Haskell Module +-- +-- All we actually declare here is the top-level structure for a module. +data HsModule p + = -- | 'GHC.Parser.Annotation.AnnKeywordId's + -- + -- - 'GHC.Parser.Annotation.AnnModule','GHC.Parser.Annotation.AnnWhere' + -- + -- - 'GHC.Parser.Annotation.AnnOpen','GHC.Parser.Annotation.AnnSemi', + -- 'GHC.Parser.Annotation.AnnClose' for explicit braces and semi around + -- hsmodImports,hsmodDecls if this style is used. + + -- For details on above see Note [exact print annotations] in GHC.Parser.Annotation + HsModule { + hsmodExt :: XModule p, + -- ^ HsModule extension point + hsmodName :: Maybe (LocatedA ModuleName), + -- ^ @Nothing@: \"module X where\" is omitted (in which case the next + -- field is Nothing too) + hsmodExports :: Maybe (LocatedL [LIE p]), + -- ^ Export list + -- + -- - @Nothing@: export list omitted, so export everything + -- + -- - @Just []@: export /nothing/ + -- + -- - @Just [...]@: as you would expect... + -- + -- + -- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnOpen' + -- ,'GHC.Parser.Annotation.AnnClose' --- TODO Add TTG parameter to 'HsModule' and move here. + -- For details on above see Note [exact print annotations] in GHC.Parser.Annotation + hsmodImports :: [LImportDecl p], + -- ^ We snaffle interesting stuff out of the imported interfaces early + -- on, adding that info to TyDecls/etc; so this list is often empty, + -- downstream. + hsmodDecls :: [LHsDecl p] + -- ^ Type, class, value, and interface signature decls + } + | XModule (XXModule p) diff --git a/compiler/Language/Haskell/Syntax.hs-boot b/compiler/Language/Haskell/Syntax.hs-boot new file mode 100644 index 0000000000..72ddcaa0e4 --- /dev/null +++ b/compiler/Language/Haskell/Syntax.hs-boot @@ -0,0 +1,9 @@ +{-# LANGUAGE StandaloneDeriving #-} +module Language.Haskell.Syntax where + +import GHC.Prelude (Show) +import GHC.Data.FastString + +newtype ModuleName = ModuleName FastString + +instance Show ModuleName diff --git a/compiler/Language/Haskell/Syntax/Extension.hs b/compiler/Language/Haskell/Syntax/Extension.hs index 47b693a9bd..f63ca09b30 100644 --- a/compiler/Language/Haskell/Syntax/Extension.hs +++ b/compiler/Language/Haskell/Syntax/Extension.hs @@ -397,6 +397,12 @@ type family XCInjectivityAnn x type family XXInjectivityAnn x -- ===================================================================== +-- Type families for the HsModule extension points + +type family XModule x +type family XXModule x + +-- ===================================================================== -- Type families for the HsExpr extension points type family XVar x |