2 #include "HsVersions.h"
3 module ParseType ( parseType ) where
7 import HsSyn -- quite a bit of stuff
8 import RdrHsSyn -- oodles of synonyms
9 import HsDecls ( HsIdInfo(..) )
10 import HsTypes ( mkHsForAllTy )
13 import HsPragmas ( noGenPragmas, noDataPragmas, noClassPragmas, noClassOpPragmas, noInstancePragmas )
14 import IdInfo ( exactArity, mkStrictnessInfo, mkBottomStrictnessInfo,
15 ArgUsageInfo, FBTypeInfo
17 import Kind ( Kind, mkArrowKind, mkTypeKind )
20 import RnMonad ( SYN_IE(ImportVersion), SYN_IE(LocalVersion), ParsedIface(..),
21 SYN_IE(RdrNamePragma), SYN_IE(ExportItem)
23 import Bag ( emptyBag, unitBag, snocBag )
24 import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
25 import Name ( OccName(..), isTCOcc, Provenance )
26 import SrcLoc ( mkIfaceSrcLoc )
27 import Util ( panic{-, pprPanic ToDo:rm-} )
28 import Pretty ( ppShow )
29 import PprStyle -- PprDebug for panic
30 import Maybes ( MaybeErr(..) )
32 ------------------------------------------------------------------
34 parseType :: [IfaceToken] -> MaybeErr RdrNameHsType (PprStyle -> Int -> Bool -> PrettyRep)
40 Failed err -> panic (ppShow 80 (err PprDebug))
47 %tokentype { IfaceToken }
48 %monad { IfM }{ thenIf }{ returnIf }
65 VARSYM { ITvarsym $$ }
66 CONSYM { ITconsym $$ }
67 QCONID { ITqconid $$ }
69 UNKNOWN { ITunknown $$ }
72 type :: { RdrNameHsType }
73 type : FORALL forall context DARROW type { mkHsForAllTy $2 $3 $5 }
76 forall : OBRACK tv_bndrs CBRACK { $2 }
78 context :: { RdrNameContext }
80 | OCURLY context_list1 CCURLY { $2 }
82 context_list1 :: { RdrNameContext }
83 context_list1 : class { [$1] }
84 | class COMMA context_list1 { $1 : $3 }
86 class :: { (RdrName, RdrNameHsType) }
87 class : qtc_name atype { ($1, $2) }
90 tautype :: { RdrNameHsType }
91 tautype : btype { $1 }
92 | btype RARROW tautype { MonoFunTy $1 $3 }
94 types2 :: { [RdrNameHsType] {- Two or more -} }
95 types2 : type COMMA type { [$1,$3] }
96 | type COMMA types2 { $1 : $3 }
98 btype :: { RdrNameHsType }
100 | btype atype { MonoTyApp $1 $2 }
102 atype :: { RdrNameHsType }
103 atype : qtc_name { MonoTyVar $1 }
104 | tv_name { MonoTyVar $1 }
105 | OPAREN types2 CPAREN { MonoTupleTy dummyRdrTcName $2 }
106 | OBRACK type CBRACK { MonoListTy dummyRdrTcName $2 }
107 | OCURLY qtc_name atype CCURLY { MonoDictTy $2 $3 }
108 | OPAREN type CPAREN { $2 }
110 atypes :: { [RdrNameHsType] {- Zero or more -} }
112 | atype atypes { $1 : $2
113 ---------------------------------------------------------------------
116 tv_bndr :: { HsTyVar RdrName }
117 tv_bndr : tv_name DCOLON akind { IfaceTyVar $1 $3 }
118 | tv_name { UserTyVar $1 }
120 tv_bndrs :: { [HsTyVar RdrName] }
122 | tv_bndr tv_bndrs { $1 : $2 }
126 | akind RARROW kind { mkArrowKind $1 $3 }
129 : VARSYM { mkTypeKind {- ToDo: check that it's "*" -} }
130 | OPAREN kind CPAREN { $2 }
132 tv_name :: { RdrName }
133 tv_name : VARID { Unqual (TvOcc $1) }
135 tv_names :: { [RdrName] }
137 | tv_name tv_names { $1 : $2 }
138 qtc_name :: { RdrName }
139 qtc_name : QCONID { tcQual $1 }