2 #include "HsVersions.h"
3 module ParseIface ( parseIface ) 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 BasicTypes ( IfaceFlavour(..), Fixity(..), FixityDirection(..), NewOrData(..), Version(..) )
14 import HsPragmas ( noDataPragmas, noClassPragmas )
15 import Kind ( Kind, mkArrowKind, mkBoxedTypeKind )
16 import IdInfo ( ArgUsageInfo, FBTypeInfo )
19 import RnMonad ( SYN_IE(ImportVersion), SYN_IE(LocalVersion), ParsedIface(..),
20 SYN_IE(RdrNamePragma), SYN_IE(ExportItem), SYN_IE(RdrAvailInfo), GenAvailInfo(..)
22 import Bag ( emptyBag, unitBag, snocBag )
23 import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
24 import Name ( OccName(..), isTCOcc, Provenance, SYN_IE(Module) )
25 import SrcLoc ( mkIfaceSrcLoc )
26 --import Util ( panic{-, pprPanic ToDo:rm-} )
27 import ParseType ( parseType )
28 import ParseUnfolding ( parseUnfolding )
34 %tokentype { IfaceToken }
35 %monad { IfM }{ thenIf }{ returnIf }
36 %lexer { lexIface } { ITeof }
39 INTERFACE { ITinterface }
40 USAGES_PART { ITusages }
41 VERSIONS_PART { ITversions }
42 EXPORTS_PART { ITexports }
43 INSTANCE_MODULES_PART { ITinstance_modules }
44 INSTANCES_PART { ITinstances }
45 FIXITIES_PART { ITfixities }
46 DECLARATIONS_PART { ITdeclarations }
47 PRAGMAS_PART { ITpragmas }
51 DERIVING { ITderiving }
54 INSTANCE { ITinstance }
77 VARSYM { ITvarsym $$ }
78 CONSYM { ITconsym $$ }
79 QVARID { ITqvarid $$ }
80 QCONID { ITqconid $$ }
81 QVARSYM { ITqvarsym $$ }
82 QCONSYM { ITqconsym $$ }
84 TYPE_PART { ITtysig _ _ }
85 ARITY_PART { ITarity }
86 STRICT_PART { ITstrict $$ }
87 UNFOLD_PART { ITunfold $$ }
92 PRIM_CASE { ITprim_case }
97 COERCE_IN { ITcoerce_in }
98 COERCE_OUT { ITcoerce_out }
104 STRING { ITstring $$ }
105 INTEGER { ITinteger $$ }
106 DOUBLE { ITdouble $$ }
108 INTEGER_LIT { ITinteger_lit }
109 FLOAT_LIT { ITfloat_lit }
110 RATIONAL_LIT { ITrational_lit }
111 ADDR_LIT { ITaddr_lit }
112 LIT_LIT { ITlit_lit }
113 STRING_LIT { ITstring_lit }
115 UNKNOWN { ITunknown $$ }
118 iface :: { ParsedIface }
119 iface : INTERFACE CONID INTEGER
122 exports_part fixities_part
127 (fromInteger $3) -- Module version
130 $4 -- Instance modules
133 $8 -- Local instances
137 usages_part :: { [ImportVersion OccName] }
138 usages_part : USAGES_PART module_stuff_pairs { $2 }
141 module_stuff_pairs :: { [ImportVersion OccName] }
142 module_stuff_pairs : { [] }
143 | module_stuff_pair module_stuff_pairs { $1 : $2 }
145 module_stuff_pair :: { ImportVersion OccName }
146 module_stuff_pair : mod_name opt_bang INTEGER DCOLON name_version_pairs SEMI
147 { ($1, $2, fromInteger $3, $5) }
149 versions_part :: { [LocalVersion OccName] }
150 versions_part : VERSIONS_PART name_version_pairs { $2 }
153 name_version_pairs :: { [LocalVersion OccName] }
154 name_version_pairs : { [] }
155 | name_version_pair name_version_pairs { $1 : $2 }
157 name_version_pair :: { LocalVersion OccName }
158 name_version_pair : entity_occ INTEGER { ($1, fromInteger $2)
159 --------------------------------------------------------------------------
162 exports_part :: { [ExportItem] }
163 exports_part : EXPORTS_PART export_items { $2 }
166 export_items :: { [ExportItem] }
167 export_items : { [] }
168 | opt_bang mod_name entities SEMI export_items { ($2,$1,$3) : $5 }
170 opt_bang :: { IfaceFlavour }
171 opt_bang : { HiFile }
172 | BANG { HiBootFile }
174 entities :: { [RdrAvailInfo] }
176 | entity entities { $1 : $2 }
178 entity :: { RdrAvailInfo }
179 entity : entity_occ { if isTCOcc $1
182 | entity_occ stuff_inside { AvailTC $1 ($1:$2) }
183 | entity_occ VBAR stuff_inside { AvailTC $1 $3 }
185 stuff_inside :: { [OccName] }
186 stuff_inside : OPAREN val_occs1 CPAREN { $2
187 --------------------------------------------------------------------------
190 inst_modules_part :: { [Module] }
191 inst_modules_part : { [] }
192 | INSTANCE_MODULES_PART mod_list { $2 }
194 mod_list :: { [Module] }
196 | mod_name mod_list { $1 : $2
197 --------------------------------------------------------------------------
200 fixities_part :: { [(OccName,Fixity)] }
201 fixities_part : { [] }
202 | FIXITIES_PART fixes { $2 }
204 fixes :: { [(OccName,Fixity)] }
206 | fix fixes { $1 : $2 }
208 fix :: { (OccName, Fixity) }
209 fix : INFIXL INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixL) }
210 | INFIXR INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixR) }
211 | INFIX INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixN)
212 --------------------------------------------------------------------------
215 decls_part :: { [(Version, RdrNameHsDecl)] }
217 | DECLARATIONS_PART topdecls { $2 }
219 topdecls :: { [(Version, RdrNameHsDecl)] }
221 | version topdecl topdecls { ($1,$2) : $3 }
223 version :: { Version }
224 version : INTEGER { fromInteger $1 }
226 topdecl :: { RdrNameHsDecl }
227 topdecl : TYPE tc_name tv_bndrs EQUAL type SEMI
228 { TyD (TySynonym $2 $3 $5 mkIfaceSrcLoc) }
229 | DATA decl_context tc_name tv_bndrs constrs deriving SEMI
230 { TyD (TyData DataType $2 $3 $4 $5 $6 noDataPragmas mkIfaceSrcLoc) }
231 | NEWTYPE decl_context tc_name tv_bndrs newtype_constr deriving SEMI
232 { TyD (TyData NewType $2 $3 $4 $5 $6 noDataPragmas mkIfaceSrcLoc) }
233 | CLASS decl_context tc_name tv_bndr csigs SEMI
234 { ClD (ClassDecl $2 $3 $4 $5 EmptyMonoBinds noClassPragmas mkIfaceSrcLoc) }
238 ITtysig sig idinfo_part ->
243 let { (Succeeded id_info) = parseUnfolding s } in id_info
244 (Succeeded tp) = parseType sig
246 SigD (IfaceSig $1 tp info mkIfaceSrcLoc) }
248 decl_context :: { RdrNameContext }
249 decl_context : { [] }
250 | OCURLY context_list1 CCURLY DARROW { $2 }
253 csigs :: { [RdrNameSig] }
255 | WHERE OCURLY csigs1 CCURLY { $3 }
257 csigs1 :: { [RdrNameSig] }
258 csigs1 : csig { [$1] }
259 | csig SEMI csigs1 { $1 : $3 }
261 csig :: { RdrNameSig }
262 csig : var_name DCOLON type { ClassOpSig $1 Nothing $3 mkIfaceSrcLoc }
263 | var_name EQUAL DCOLON type { ClassOpSig $1 (Just (error "Un-filled-in default method"))
265 ----------------------------------------------------------------
268 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
270 | EQUAL constrs1 { $2 }
272 constrs1 :: { [RdrNameConDecl] }
273 constrs1 : constr { [$1] }
274 | constr VBAR constrs1 { $1 : $3 }
276 constr :: { RdrNameConDecl }
277 constr : data_name batypes { ConDecl $1 [] (VanillaCon $2) mkIfaceSrcLoc }
278 | data_name OCURLY fields1 CCURLY { ConDecl $1 [] (RecCon $3) mkIfaceSrcLoc }
280 newtype_constr :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
281 newtype_constr : { [] }
282 | EQUAL data_name atype { [ConDecl $2 [] (NewCon $3) mkIfaceSrcLoc] }
284 deriving :: { Maybe [RdrName] }
286 | DERIVING OPAREN tc_names1 CPAREN { Just $3 }
288 batypes :: { [RdrNameBangType] }
290 | batype batypes { $1 : $2 }
292 batype :: { RdrNameBangType }
293 batype : atype { Unbanged $1 }
294 | BANG atype { Banged $2 }
296 fields1 :: { [([RdrName], RdrNameBangType)] }
297 fields1 : field { [$1] }
298 | field COMMA fields1 { $1 : $3 }
300 field :: { ([RdrName], RdrNameBangType) }
301 field : var_names1 DCOLON type { ($1, Unbanged $3) }
302 | var_names1 DCOLON BANG type { ($1, Banged $4)
303 --------------------------------------------------------------------------
306 forall :: { [HsTyVar RdrName] }
307 forall : OBRACK tv_bndrs CBRACK { $2 }
309 context :: { RdrNameContext }
311 | OCURLY context_list1 CCURLY { $2 }
313 context_list1 :: { RdrNameContext }
314 context_list1 : class { [$1] }
315 | class COMMA context_list1 { $1 : $3 }
317 class :: { (RdrName, RdrNameHsType) }
318 class : tc_name atype { ($1, $2) }
320 type :: { RdrNameHsType }
321 type : FORALL forall context DARROW type { mkHsForAllTy $2 $3 $5 }
322 | btype RARROW type { MonoFunTy $1 $3 }
325 types2 :: { [RdrNameHsType] {- Two or more -} }
326 types2 : type COMMA type { [$1,$3] }
327 | type COMMA types2 { $1 : $3 }
329 btype :: { RdrNameHsType }
331 | btype atype { MonoTyApp $1 $2 }
333 atype :: { RdrNameHsType }
334 atype : tc_name { MonoTyVar $1 }
335 | tv_name { MonoTyVar $1 }
336 | OPAREN types2 CPAREN { MonoTupleTy dummyRdrTcName $2 }
337 | OBRACK type CBRACK { MonoListTy dummyRdrTcName $2 }
338 | OCURLY tc_name atype CCURLY { MonoDictTy $2 $3 }
339 | OPAREN type CPAREN { $2 }
341 atypes :: { [RdrNameHsType] {- Zero or more -} }
343 | atype atypes { $1 : $2
344 ---------------------------------------------------------------------
347 mod_name :: { Module }
350 var_occ :: { OccName }
351 var_occ : VARID { VarOcc $1 }
352 | VARSYM { VarOcc $1 }
353 | BANG { VarOcc SLIT("!") {-sigh, double-sigh-} }
355 tc_occ :: { OccName }
356 tc_occ : CONID { TCOcc $1 }
357 | CONSYM { TCOcc $1 }
358 | OPAREN RARROW CPAREN { TCOcc SLIT("->") }
360 entity_occ :: { OccName }
361 entity_occ : var_occ { $1 }
363 | RARROW { TCOcc SLIT("->") {- Allow un-paren'd arrow -} }
365 val_occ :: { OccName }
366 val_occ : var_occ { $1 }
367 | CONID { VarOcc $1 }
368 | CONSYM { VarOcc $1 }
370 val_occs1 :: { [OccName] }
372 | val_occ val_occs1 { $1 : $2 }
375 qvar_name :: { RdrName }
376 : QVARID { lexVarQual $1 }
377 | QVARSYM { lexVarQual $1 }
379 var_name :: { RdrName }
380 var_name : var_occ { Unqual $1 }
382 var_names1 :: { [RdrName] }
383 var_names1 : var_name { [$1] }
384 | var_name var_names1 { $1 : $2 }
386 any_var_name :: {RdrName}
387 any_var_name : var_name { $1 }
390 qdata_name :: { RdrName }
391 qdata_name : QCONID { lexVarQual $1 }
392 | QCONSYM { lexVarQual $1 }
394 data_name :: { RdrName }
395 data_name : CONID { Unqual (VarOcc $1) }
396 | CONSYM { Unqual (VarOcc $1) }
399 tc_names1 :: { [RdrName] }
401 | tc_name COMMA tc_names1 { $1 : $3 }
403 tc_name :: { RdrName }
404 tc_name : tc_occ { Unqual $1 }
405 | QCONID { lexTcQual $1 }
407 tv_name :: { RdrName }
408 tv_name : VARID { Unqual (TvOcc $1) }
409 | VARSYM { Unqual (TvOcc $1) {- Allow t2 as a tyvar -} }
411 tv_names :: { [RdrName] }
413 | tv_name tv_names { $1 : $2 }
415 tv_bndr :: { HsTyVar RdrName }
416 tv_bndr : tv_name DCOLON akind { IfaceTyVar $1 $3 }
417 | tv_name { UserTyVar $1 }
419 tv_bndrs :: { [HsTyVar RdrName] }
421 | tv_bndr tv_bndrs { $1 : $2 }
425 | akind RARROW kind { mkArrowKind $1 $3 }
428 : VARSYM { mkBoxedTypeKind {- ToDo: check that it's "*" -} }
429 | OPAREN kind CPAREN { $2
430 --------------------------------------------------------------------------
434 instances_part :: { [RdrNameInstDecl] }
435 instances_part : INSTANCES_PART instdecls { $2 }
438 instdecls :: { [RdrNameInstDecl] }
440 | instd instdecls { $1 : $2 }
442 instd :: { RdrNameInstDecl }
443 instd : INSTANCE type EQUAL var_name SEMI
445 EmptyMonoBinds {- No bindings -}
446 [] {- No user pragmas -}
447 (Just $4) {- Dfun id -}
449 --------------------------------------------------------------------------