The Backpack patch.
[ghc.git] / compiler / backpack / BkpSyn.hs
1 -- | This is the syntax for bkp files which are parsed in 'ghc --backpack'
2 -- mode. This syntax is used purely for testing purposes.
3
4 module BkpSyn (
5 -- * Backpack abstract syntax
6 HsUnitId(..),
7 LHsUnitId,
8 HsModuleSubst,
9 LHsModuleSubst,
10 HsModuleId(..),
11 LHsModuleId,
12 HsComponentId(..),
13 LHsUnit, HsUnit(..),
14 LHsUnitDecl, HsUnitDecl(..),
15 HsDeclType(..),
16 IncludeDecl(..),
17 LRenaming, Renaming(..),
18 ) where
19
20 import HsSyn
21 import RdrName
22 import SrcLoc
23 import Outputable
24 import Module
25 import PackageConfig
26
27 {-
28 ************************************************************************
29 * *
30 User syntax
31 * *
32 ************************************************************************
33 -}
34
35 data HsComponentId = HsComponentId {
36 hsPackageName :: PackageName,
37 hsComponentId :: ComponentId
38 }
39
40 instance Outputable HsComponentId where
41 ppr (HsComponentId _pn cid) = ppr cid -- todo debug with pn
42
43 data HsUnitId n = HsUnitId (Located n) [LHsModuleSubst n]
44 type LHsUnitId n = Located (HsUnitId n)
45
46 type HsModuleSubst n = (Located ModuleName, LHsModuleId n)
47 type LHsModuleSubst n = Located (HsModuleSubst n)
48
49 data HsModuleId n = HsModuleVar (Located ModuleName)
50 | HsModuleId (LHsUnitId n) (Located ModuleName)
51 type LHsModuleId n = Located (HsModuleId n)
52
53 -- | Top level @unit@ declaration in a Backpack file.
54 data HsUnit n = HsUnit {
55 hsunitName :: Located n,
56 hsunitBody :: [LHsUnitDecl n]
57 }
58 type LHsUnit n = Located (HsUnit n)
59
60 -- | A declaration in a package, e.g. a module or signature definition,
61 -- or an include.
62 data HsDeclType = ModuleD | SignatureD
63 data HsUnitDecl n
64 = DeclD HsDeclType (Located ModuleName) (Maybe (Located (HsModule RdrName)))
65 | IncludeD (IncludeDecl n)
66 type LHsUnitDecl n = Located (HsUnitDecl n)
67
68 -- | An include of another unit
69 data IncludeDecl n = IncludeDecl {
70 idUnitId :: LHsUnitId n,
71 idModRenaming :: Maybe [ LRenaming ]
72 }
73
74 -- | Rename a module from one name to another. The identity renaming
75 -- means that the module should be brought into scope.
76 data Renaming = Renaming { renameFrom :: ModuleName, renameTo :: ModuleName }
77 type LRenaming = Located Renaming