HsSyn.lhs 3.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
%
\section{Haskell abstract syntax definition}

This module glues together the pieces of the Haskell abstract syntax,
which is declared in the various \tr{Hs*} modules.  This module,
therefore, is almost nothing but re-exporting.

\begin{code}
#include "HsVersions.h"

module HsSyn (

	-- NB: don't reexport HsCore or HsPragmas;
	-- this module tells about "real Haskell"

18 19 20 21 22 23 24 25 26
	EXP_MODULE(HsSyn) ,
	EXP_MODULE(HsBinds) ,
	EXP_MODULE(HsDecls) ,
	EXP_MODULE(HsExpr) ,
	EXP_MODULE(HsImpExp) ,
	EXP_MODULE(HsLit) ,
	EXP_MODULE(HsMatches) ,
	EXP_MODULE(HsPat) ,
	EXP_MODULE(HsTypes)
27 28
     ) where

29
IMP_Ubiq()
30 31 32 33 34 35 36 37 38 39 40

-- friends:
import HsBinds
import HsDecls
import HsExpr
import HsImpExp
import HsLit
import HsMatches
import HsPat
import HsTypes
import HsPragmas	( ClassPragmas, ClassOpPragmas,
41
			  DataPragmas, GenPragmas, InstancePragmas )
42 43
-- others:
import FiniteMap	( FiniteMap )
44
import Outputable	( ifPprShowAll, ifnotPprForUser, interpp'SP, Outputable(..) )
45
import Pretty
46
import SrcLoc		( SrcLoc )
47 48 49 50 51 52 53 54 55 56 57
\end{code}

@Fake@ is a placeholder type; for when tyvars and uvars aren't used.
\begin{code}
data Fake = Fake
instance Eq Fake
instance Outputable Fake
\end{code}

All we actually declare here is the top-level structure for a module.
\begin{code}
58 59
type Version = Int

60 61
data HsModule tyvar uvar name pat
  = HsModule
62 63
	Module			-- module name
	(Maybe Version)		-- source interface version number
64 65 66
	(Maybe [IE name])	-- export list; Nothing => export everything
				-- Just [] => export *nothing* (???)
				-- Just [...] => as you would expect...
67
	[ImportDecl name]	-- We snaffle interesting stuff out of the
68 69 70 71 72
				-- imported interfaces early on, adding that
				-- info to TyDecls/etc; so this list is
				-- often empty, downstream.
	[FixityDecl name]
	[TyDecl name]
73
	[SpecDataSig name]		-- user pragmas that modify TyDecls
74 75
	[ClassDecl tyvar uvar name pat]
	[InstDecl  tyvar uvar name pat]
76
	[SpecInstSig name] 		-- user pragmas that modify InstDecls
77
	[DefaultDecl name]
78 79
	(HsBinds tyvar uvar name pat)	-- the main stuff, includes source sigs
	[Sig name]			-- interface sigs
80 81 82 83 84 85 86 87
	SrcLoc
\end{code}

\begin{code}
instance (NamedThing name, Outputable name, Outputable pat,
	  Eq tyvar, Outputable tyvar, Eq uvar, Outputable uvar)
	=> Outputable (HsModule tyvar uvar name pat) where

88
    ppr sty (HsModule name iface_version exports imports fixities
89 90 91 92
		      typedecls typesigs classdecls instdecls instsigs
		      defdecls binds sigs src_loc)
      = ppAboves [
	    ifPprShowAll sty (ppr sty src_loc),
93
	    ifnotPprForUser sty (pp_iface_version iface_version),
94 95 96 97 98 99 100
	    case exports of
	      Nothing -> ppCat [ppPStr SLIT("module"), ppPStr name, ppPStr SLIT("where")]
	      Just es -> ppAboves [
			    ppCat [ppPStr SLIT("module"), ppPStr name, ppLparen],
			    ppNest 8 (interpp'SP sty es),
			    ppNest 4 (ppPStr SLIT(") where"))
			  ],
101 102 103 104
	    pp_nonnull imports,
	    pp_nonnull fixities,
	    pp_nonnull typedecls,
	    pp_nonnull typesigs,
105
	    pp_nonnull classdecls,
106 107
	    pp_nonnull instdecls,
	    pp_nonnull instsigs,
108
	    pp_nonnull defdecls,
109 110
	    ppr sty binds,
	    pp_nonnull sigs
111 112 113 114
	]
      where
	pp_nonnull [] = ppNil
	pp_nonnull xs = ppAboves (map (ppr sty) xs)
115 116 117

	pp_iface_version Nothing  = ppNil
	pp_iface_version (Just n) = ppCat [ppStr "{-# INTERFACE", ppInt n, ppStr "#-}"]
118
\end{code}