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(..), HsStrictnessInfo )
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, mkBoxedTypeKind )
20 import RnMonad ( SYN_IE(ImportVersion), SYN_IE(LocalVersion), ParsedIface(..),
21 SYN_IE(RdrNamePragma), SYN_IE(ExportItem), GenAvailInfo
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-} )
29 import Outputable ( PprStyle(..) )
30 import Maybes ( MaybeErr(..) )
32 ------------------------------------------------------------------
34 parseType :: StringBuffer -> MaybeErr RdrNameHsType (PprStyle -> Doc)
40 Failed err -> panic (show (err PprDebug))
47 %tokentype { IfaceToken }
48 %monad { IfM }{ thenIf }{ returnIf }
49 %lexer { lexIface } { ITeof }
66 VARSYM { ITvarsym $$ }
67 CONSYM { ITconsym $$ }
68 QCONID { ITqconid $$ }
70 UNKNOWN { ITunknown $$ }
73 type :: { RdrNameHsType }
74 type : FORALL forall context DARROW type { mkHsForAllTy $2 $3 $5 }
75 | btype RARROW type { MonoFunTy $1 $3 }
78 forall : OBRACK tv_bndrs CBRACK { $2 }
80 context :: { RdrNameContext }
82 | OCURLY context_list1 CCURLY { $2 }
84 context_list1 :: { RdrNameContext }
85 context_list1 : class { [$1] }
86 | class COMMA context_list1 { $1 : $3 }
88 class :: { (RdrName, RdrNameHsType) }
89 class : tc_name atype { ($1, $2) }
92 types2 :: { [RdrNameHsType] {- Two or more -} }
93 types2 : type COMMA type { [$1,$3] }
94 | type COMMA types2 { $1 : $3 }
96 btype :: { RdrNameHsType }
98 | btype atype { MonoTyApp $1 $2 }
100 atype :: { RdrNameHsType }
101 atype : tc_name { MonoTyVar $1 }
102 | tv_name { MonoTyVar $1 }
103 | OPAREN types2 CPAREN { MonoTupleTy dummyRdrTcName $2 }
104 | OBRACK type CBRACK { MonoListTy dummyRdrTcName $2 }
105 | OCURLY tc_name atype CCURLY { MonoDictTy $2 $3 }
106 | OPAREN type CPAREN { $2 }
108 atypes :: { [RdrNameHsType] {- Zero or more -} }
110 | atype atypes { $1 : $2
111 ---------------------------------------------------------------------
114 tv_bndr :: { HsTyVar RdrName }
115 tv_bndr : tv_name DCOLON akind { IfaceTyVar $1 $3 }
116 | tv_name { UserTyVar $1 }
118 tv_bndrs :: { [HsTyVar RdrName] }
120 | tv_bndr tv_bndrs { $1 : $2 }
124 | akind RARROW kind { mkArrowKind $1 $3 }
127 : VARSYM { mkBoxedTypeKind {- ToDo: check that it's "*" -} }
128 | OPAREN kind CPAREN { $2 }
130 tv_name :: { RdrName }
131 tv_name : VARID { Unqual (TvOcc $1) }
132 | VARSYM { Unqual (TvOcc $1) {- Allow t2 as a tyvar -} }
134 tv_names :: { [RdrName] }
136 | tv_name tv_names { $1 : $2 }
138 tc_name :: { RdrName }
139 tc_name : QCONID { lexTcQual $1 }
140 | CONID { Unqual (TCOcc $1) }
141 | CONSYM { Unqual (TCOcc $1) }
142 | OPAREN RARROW CPAREN { Unqual (TCOcc SLIT("->")) }