[project @ 1998-04-07 16:40:08 by simonpj]
[ghc-hetmet.git] / ghc / compiler / rename / ParseIface.y
1 {
2 module ParseIface ( parseIface, IfaceStuff(..) ) where
3
4 #include "HsVersions.h"
5
6 import HsSyn            -- quite a bit of stuff
7 import RdrHsSyn         -- oodles of synonyms
8 import HsDecls          ( HsIdInfo(..), HsStrictnessInfo(..) )
9 import HsTypes          ( mkHsForAllTy )
10 import HsCore
11 import Literal
12 import BasicTypes       ( IfaceFlavour(..), Fixity(..), FixityDirection(..), NewOrData(..), Version(..) )
13 import HsPragmas        ( noDataPragmas, noClassPragmas )
14 import Kind             ( Kind, mkArrowKind, mkBoxedTypeKind, mkTypeKind )
15 import IdInfo           ( ArgUsageInfo, FBTypeInfo, ArityInfo, exactArity )
16 import PrimRep          ( decodePrimRep )
17 import Lex              
18
19 import RnMonad          ( ImportVersion, LocalVersion, ParsedIface(..), WhatsImported(..),
20                           RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..)
21                         ) 
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           ( SrcLoc )
26 import Maybes
27 import Outputable
28
29 }
30
31 %name       parseIface
32 %tokentype  { IfaceToken }
33 %monad      { IfM }{ thenIf }{ returnIf }
34 %lexer      { lexIface } { ITeof }
35
36 %token
37         INTERFACE           { ITinterface }
38         USAGES_PART         { ITusages }
39         VERSIONS_PART       { ITversions }
40         EXPORTS_PART        { ITexports }
41         INSTANCE_MODULES_PART { ITinstance_modules }
42         INSTANCES_PART      { ITinstances }
43         FIXITIES_PART       { ITfixities }
44         DECLARATIONS_PART   { ITdeclarations }
45         PRAGMAS_PART        { ITpragmas }
46         DATA                { ITdata }
47         TYPE                { ITtype }
48         NEWTYPE             { ITnewtype }
49         DERIVING            { ITderiving }
50         CLASS               { ITclass }
51         WHERE               { ITwhere }
52         INSTANCE            { ITinstance }
53         INFIXL              { ITinfixl }
54         INFIXR              { ITinfixr }
55         INFIX               { ITinfix }
56         FORALL              { ITforall }
57         BANG                { ITbang }
58         VBAR                { ITvbar }
59         DCOLON              { ITdcolon }
60         COMMA               { ITcomma }
61         DARROW              { ITdarrow }
62         DOTDOT              { ITdotdot }
63         EQUAL               { ITequal }
64         OCURLY              { ITocurly }
65         OBRACK              { ITobrack }
66         OPAREN              { IToparen }
67         RARROW              { ITrarrow }
68         CCURLY              { ITccurly }
69         CBRACK              { ITcbrack }
70         CPAREN              { ITcparen }
71         SEMI                { ITsemi }
72
73         VARID               { ITvarid    $$ }
74         CONID               { ITconid    $$ }
75         VARSYM              { ITvarsym   $$ }
76         CONSYM              { ITconsym   $$ }
77         QVARID              { ITqvarid   $$ }
78         QCONID              { ITqconid   $$ }
79         QVARSYM             { ITqvarsym  $$ }
80         QCONSYM             { ITqconsym  $$ }
81
82         STRICT_PART     { ITstrict $$ }
83         TYPE_PART       { ITtysig _ _ }
84         ARITY_PART      { ITarity }
85         UNFOLD_PART     { ITunfold $$ }
86         SPECIALISE      { ITspecialise }
87         BOTTOM          { ITbottom }
88         LAM             { ITlam }
89         BIGLAM          { ITbiglam }
90         CASE            { ITcase }
91         PRIM_CASE       { ITprim_case }
92         LET             { ITlet }
93         LETREC          { ITletrec }
94         IN              { ITin }
95         OF              { ITof }
96         COERCE          { ITcoerce }
97         ATSIGN          { ITatsign }
98         CCALL           { ITccall $$ }
99         SCC             { ITscc $$ }
100         INLINE_CALL     { ITinline }
101
102         CHAR            { ITchar $$ }
103         STRING          { ITstring $$ } 
104         INTEGER         { ITinteger  $$ }
105         DOUBLE          { ITdouble $$ }
106
107         INTEGER_LIT     { ITinteger_lit }
108         FLOAT_LIT       { ITfloat_lit }
109         RATIONAL_LIT    { ITrational_lit }
110         ADDR_LIT        { ITaddr_lit }
111         LIT_LIT         { ITlit_lit }
112         STRING_LIT      { ITstring_lit }
113
114         UNKNOWN         { ITunknown $$ }
115 %%
116
117 -- iface_stuff is the main production.
118 -- It recognises (a) a whole interface file
119 --               (b) a type (so that type sigs can be parsed lazily)
120 --               (c) the IdInfo part of a signature (same reason)
121
122 iface_stuff :: { IfaceStuff }
123 iface_stuff : iface             { PIface  $1 }
124             | type              { PType   $1 }
125             | id_info           { PIdInfo $1 }
126
127
128 iface           :: { ParsedIface }
129 iface           : INTERFACE CONID INTEGER checkVersion
130                   inst_modules_part 
131                   usages_part
132                   exports_part fixities_part
133                   instances_part
134                   decls_part
135                   { ParsedIface 
136                         $2                      -- Module name
137                         (fromInteger $3)        -- Module version
138                         $6                      -- Usages
139                         $7                      -- Exports
140                         $5                      -- Instance modules
141                         $8                      -- Fixities
142                         $10                     -- Decls
143                         $9                      -- Local instances
144                     }
145
146
147 usages_part         :: { [ImportVersion OccName] }
148 usages_part         :  USAGES_PART module_stuff_pairs           { $2 }
149                     |                                           { [] }
150
151 module_stuff_pairs  :: { [ImportVersion OccName] }
152 module_stuff_pairs  :                                           { [] }
153                     |  module_stuff_pair module_stuff_pairs     { $1 : $2 }
154
155 module_stuff_pair   ::  { ImportVersion OccName }
156 module_stuff_pair   :  mod_name opt_bang INTEGER DCOLON whats_imported SEMI
157                         { ($1, $2, fromInteger $3, $5) }
158
159 whats_imported      :: { WhatsImported OccName }
160 whats_imported      :                                           { Everything }
161                     | name_version_pair name_version_pairs      { Specifically ($1:$2) }
162
163 versions_part       :: { [LocalVersion OccName] }
164 versions_part       :  VERSIONS_PART name_version_pairs         { $2 }
165                     |                                           { [] }
166
167 name_version_pairs  ::  { [LocalVersion OccName] }
168 name_version_pairs  :                                           { [] }
169                     |  name_version_pair name_version_pairs     { $1 : $2 }
170
171 name_version_pair   ::  { LocalVersion OccName }
172 name_version_pair   :  entity_occ INTEGER                       { ($1, fromInteger $2)
173 --------------------------------------------------------------------------
174                                                                 }
175
176 exports_part    :: { [ExportItem] }
177 exports_part    :  EXPORTS_PART export_items                    { $2 }
178                 |                                               { [] }
179
180 export_items    :: { [ExportItem] }
181 export_items    :                                               { [] }
182                 |  opt_bang mod_name entities SEMI export_items { ($2,$1,$3) : $5 }
183
184 opt_bang        :: { IfaceFlavour }
185 opt_bang        :                                               { HiFile }
186                 | BANG                                          { HiBootFile }
187
188 entities        :: { [RdrAvailInfo] }
189 entities        :                                               { [] }
190                 |  entity entities                              { $1 : $2 }
191
192 entity          :: { RdrAvailInfo }
193 entity          :  entity_occ                           { if isTCOcc $1 
194                                                           then AvailTC $1 [$1]
195                                                           else Avail $1 }
196                 |  entity_occ stuff_inside              { AvailTC $1 ($1:$2) }
197                 |  entity_occ VBAR stuff_inside         { AvailTC $1 $3 }
198
199 stuff_inside    :: { [OccName] }
200 stuff_inside    :  OPAREN val_occs1 CPAREN              { $2
201 --------------------------------------------------------------------------
202                                                         }
203
204 inst_modules_part :: { [Module] }
205 inst_modules_part :                                             { [] }
206                   |  INSTANCE_MODULES_PART mod_list             { $2 }
207
208 mod_list        :: { [Module] }
209 mod_list        :                                               { [] }
210                 |  mod_name mod_list                            { $1 : $2
211 --------------------------------------------------------------------------
212                                                                   }
213
214 fixities_part   :: { [(OccName,Fixity)] }
215 fixities_part   :                                               { [] }
216                 |  FIXITIES_PART fixes                          { $2 }
217
218 fixes           :: { [(OccName,Fixity)] }
219 fixes           :                                               { []  }
220                 |  fix fixes                                    { $1 : $2 }
221
222 fix             :: { (OccName, Fixity) }
223 fix             :  INFIXL INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixL) }
224                 |  INFIXR INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixR) }
225                 |  INFIX  INTEGER val_occ SEMI { ($3, Fixity (fromInteger $2) InfixN)
226 --------------------------------------------------------------------------
227                                                                                       }
228
229 decls_part      :: { [(Version, RdrNameHsDecl)] }
230 decls_part      :                                       { [] }
231                 |       DECLARATIONS_PART topdecls      { $2 }
232
233 topdecls        :: { [(Version, RdrNameHsDecl)] }
234 topdecls        :                                       { [] }
235                 |  version topdecl topdecls             { ($1,$2) : $3 }
236
237 version         :: { Version }
238 version         :  INTEGER                              { fromInteger $1 }
239
240 topdecl         :: { RdrNameHsDecl }
241 topdecl         :  src_loc TYPE  tc_name tv_bndrs EQUAL type SEMI
242                         { TyD (TySynonym $3 $4 $6 $1) }
243                 |  src_loc DATA decl_context tc_name tv_bndrs constrs deriving SEMI
244                         { TyD (TyData DataType $3 $4 $5 $6 $7 noDataPragmas $1) }
245                 |  src_loc NEWTYPE decl_context tc_name tv_bndrs newtype_constr deriving SEMI
246                         { TyD (TyData NewType $3 $4 $5 $6 $7 noDataPragmas $1) }
247                 |  src_loc CLASS decl_context tc_name tv_bndrs csigs SEMI
248                         { ClD (mkClassDecl $3 $4 $5 $6 EmptyMonoBinds noClassPragmas $1) }
249                 |  src_loc var_name TYPE_PART
250                         {
251                          case $3 of
252                             ITtysig sig idinfo_part ->  -- Parse type and idinfo lazily
253                                 let info = 
254                                       case idinfo_part of
255                                         Nothing -> []
256                                         Just s  -> case parseIface s $1 of 
257                                                      Succeeded (PIdInfo id_info) -> id_info
258                                                      other ->  pprPanic "IdInfo parse failed"
259                                                                         (ppr $2)
260
261                                     tp = case parseIface sig $1 of
262                                             Succeeded (PType tp) -> tp
263                                             other -> pprPanic "Id type parse failed"
264                                                               (ppr $2)
265                                  in
266                                  SigD (IfaceSig $2 tp info $1) }
267
268 decl_context    :: { RdrNameContext }
269 decl_context    :                                       { [] }
270                 | OCURLY context_list1 CCURLY DARROW    { $2 }
271
272
273 csigs           :: { [RdrNameSig] }
274 csigs           :                               { [] }
275                 | WHERE OCURLY csigs1 CCURLY    { $3 }
276
277 csigs1          :: { [RdrNameSig] }
278 csigs1          : csig                          { [$1] }
279                 | csig SEMI csigs1              { $1 : $3 }
280
281 csig            :: { RdrNameSig }
282 csig            :  src_loc var_name DCOLON type { ClassOpSig $2 Nothing $4 $1 }
283                 |  src_loc var_name EQUAL DCOLON type   { ClassOpSig $2 
284                                                                 (Just (error "Un-filled-in default method"))
285                                                                 $5 $1 }
286 ----------------------------------------------------------------
287
288
289 constrs         :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
290                 :                               { [] }
291                 | EQUAL constrs1                { $2 }
292
293 constrs1        :: { [RdrNameConDecl] }
294 constrs1        :  constr               { [$1] }
295                 |  constr VBAR constrs1 { $1 : $3 }
296
297 constr          :: { RdrNameConDecl }
298 constr          :  src_loc data_name batypes                    { ConDecl $2 [] (VanillaCon $3) $1 }
299                 |  src_loc data_name OCURLY fields1 CCURLY      { ConDecl $2 [] (RecCon $4)     $1 }
300
301 newtype_constr  :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
302 newtype_constr  :                                       { [] }
303                 | src_loc EQUAL data_name atype         { [ConDecl $3 [] (NewCon $4) $1] }
304
305 deriving        :: { Maybe [RdrName] }
306                 :                                       { Nothing }
307                 | DERIVING OPAREN tc_names1 CPAREN      { Just $3 }
308
309 batypes         :: { [RdrNameBangType] }
310 batypes         :                                       { [] }
311                 |  batype batypes                       { $1 : $2 }
312
313 batype          :: { RdrNameBangType }
314 batype          :  atype                                { Unbanged $1 }
315                 |  BANG atype                           { Banged   $2 }
316
317 fields1         :: { [([RdrName], RdrNameBangType)] }
318 fields1         : field                                 { [$1] }
319                 | field COMMA fields1                   { $1 : $3 }
320
321 field           :: { ([RdrName], RdrNameBangType) }
322 field           :  var_names1 DCOLON type               { ($1, Unbanged $3) }
323                 |  var_names1 DCOLON BANG type          { ($1, Banged   $4) }
324 --------------------------------------------------------------------------
325
326 type            :: { RdrNameHsType }
327 type            : FORALL forall context DARROW type     { mkHsForAllTy $2 $3 $5 }
328                 |  btype RARROW type                    { MonoFunTy $1 $3 }
329                 |  btype                                { $1 }
330
331 forall          :: { [HsTyVar RdrName] }
332 forall          : OBRACK tv_bndrs CBRACK                { $2 }
333
334 context         :: { RdrNameContext }
335 context         :                                       { [] }
336                 | OCURLY context_list1 CCURLY           { $2 }
337
338 context_list1   :: { RdrNameContext }
339 context_list1   : class                                 { [$1] }
340                 | class COMMA context_list1             { $1 : $3 }
341
342 class           :: { (RdrName, [RdrNameHsType]) }
343 class           :  tc_name atypes                       { ($1, $2) }
344
345 types2          :: { [RdrNameHsType]                    {- Two or more -}  }    
346 types2          :  type COMMA type                      { [$1,$3] }
347                 |  type COMMA types2                    { $1 : $3 }
348
349 btype           :: { RdrNameHsType }
350 btype           :  atype                                { $1 }
351                 |  btype atype                          { MonoTyApp $1 $2 }
352
353 atype           :: { RdrNameHsType }
354 atype           :  tc_name                              { MonoTyVar $1 }
355                 |  tv_name                              { MonoTyVar $1 }
356                 |  OPAREN types2 CPAREN                 { MonoTupleTy dummyRdrTcName $2 }
357                 |  OBRACK type CBRACK                   { MonoListTy  dummyRdrTcName $2 }
358                 |  OCURLY tc_name atypes CCURLY         { MonoDictTy $2 $3 }
359                 |  OPAREN type CPAREN                   { $2 }
360
361 atypes          :: { [RdrNameHsType]    {-  Zero or more -} }
362 atypes          :                                       { [] }
363                 |  atype atypes                         { $1 : $2 }
364 ---------------------------------------------------------------------
365
366 mod_name        :: { Module }
367                 :  CONID                { $1 }
368
369 var_occ         :: { OccName }
370 var_occ         : VARID                 { VarOcc $1 }
371                 | VARSYM                { VarOcc $1 }
372                 | BANG                  { VarOcc SLIT("!") {-sigh, double-sigh-} }
373
374 tc_occ          :: { OccName }
375 tc_occ          :  CONID                { TCOcc $1 }
376                 |  CONSYM               { TCOcc $1 }
377                 |  OPAREN RARROW CPAREN { TCOcc SLIT("->") }
378
379 entity_occ      :: { OccName }
380 entity_occ      :  var_occ              { $1 }
381                 |  tc_occ               { $1 }
382                 |  RARROW               { TCOcc SLIT("->") {- Allow un-paren'd arrow -} }
383
384 val_occ         :: { OccName }
385 val_occ         :  var_occ              { $1 }
386                 |  CONID                { VarOcc $1 }
387                 |  CONSYM               { VarOcc $1 }
388
389 val_occs1       :: { [OccName] }
390                 :  val_occ              { [$1] }
391                 |  val_occ val_occs1    { $1 : $2 }
392
393
394 var_name        :: { RdrName }
395 var_name        :  var_occ              { Unqual $1 }
396
397 qvar_name       :: { RdrName }
398 qvar_name       :  var_name             { $1 }
399                 |  QVARID               { lexVarQual $1 }
400                 |  QVARSYM              { lexVarQual $1 }
401
402 var_names       :: { [RdrName] }
403 var_names       :                       { [] }
404                 | var_name var_names    { $1 : $2 }
405
406 var_names1      :: { [RdrName] }
407 var_names1      : var_name var_names    { $1 : $2 }
408
409 data_name       :: { RdrName }
410 data_name       :  CONID                { Unqual (VarOcc $1) }
411                 |  CONSYM               { Unqual (VarOcc $1) }
412
413 qdata_name      :: { RdrName }
414 qdata_name      : data_name             { $1 }
415                 |  QCONID               { lexVarQual $1 }
416                 |  QCONSYM              { lexVarQual $1 }
417                                 
418 qdata_names     :: { [RdrName] }
419 qdata_names     :                               { [] }
420                 | qdata_name qdata_names        { $1 : $2 }
421
422 tc_name         :: { RdrName }
423 tc_name         : tc_occ                        { Unqual $1 }
424                 | QCONID                        { lexTcQual $1 }
425                 | QCONSYM                       { lexTcQual $1 }
426
427 tc_names1       :: { [RdrName] }
428                 : tc_name                       { [$1] }
429                 | tc_name COMMA tc_names1       { $1 : $3 }
430
431 tv_name         :: { RdrName }
432 tv_name         :  VARID                { Unqual (TvOcc $1) }
433                 |  VARSYM               { Unqual (TvOcc $1) {- Allow t2 as a tyvar -} }
434
435 tv_names        :: { [RdrName] }
436                 :                       { [] }
437                 | tv_name tv_names      { $1 : $2 }
438
439 tv_bndr         :: { HsTyVar RdrName }
440 tv_bndr         :  tv_name DCOLON akind { IfaceTyVar $1 $3 }
441                 |  tv_name              { UserTyVar $1 }
442
443 tv_bndrs        :: { [HsTyVar RdrName] }
444                 :                       { [] }
445                 | tv_bndr tv_bndrs      { $1 : $2 }
446
447 kind            :: { Kind }
448                 : akind                 { $1 }
449                 | akind RARROW kind     { mkArrowKind $1 $3 }
450
451 akind           :: { Kind }
452                 : VARSYM                { if $1 == SLIT("*") then
453                                                 mkBoxedTypeKind
454                                           else if $1 == SLIT("**") then
455                                                 mkTypeKind
456                                           else panic "ParseInterface: akind"
457                                         }
458                 | OPAREN kind CPAREN    { $2 }
459 --------------------------------------------------------------------------
460
461
462 instances_part  :: { [RdrNameInstDecl] }
463 instances_part  :  INSTANCES_PART instdecls { $2 }
464                 |                           { [] }
465
466 instdecls       :: { [RdrNameInstDecl] }
467 instdecls       :                           { [] }
468                 |  instd instdecls          { $1 : $2 }
469
470 instd           :: { RdrNameInstDecl }
471 instd           :  src_loc INSTANCE type EQUAL var_name SEMI 
472                         { InstDecl $3
473                                    EmptyMonoBinds       {- No bindings -}
474                                    []                   {- No user pragmas -}
475                                    (Just $5)            {- Dfun id -}
476                                    $1
477                     }
478 --------------------------------------------------------------------------
479
480 id_info         :: { [HsIdInfo RdrName] }
481 id_info         :                                               { [] }
482                 | id_info_item id_info                          { $1 : $2 }
483
484 id_info_item    :: { HsIdInfo RdrName }
485 id_info_item    : ARITY_PART arity_info                 { HsArity $2 }
486                 | strict_info                           { HsStrictness $1 }
487                 | BOTTOM                                { HsStrictness HsBottom }
488                 | UNFOLD_PART core_expr                 { HsUnfold $1 $2 }
489                 | SPECIALISE spec_tvs
490                      atypes EQUAL core_expr             { HsSpecialise $2 $3 $5 }
491
492
493 spec_tvs        :: { [HsTyVar RdrName] }
494 spec_tvs        : OBRACK tv_bndrs CBRACK                { $2 }
495         
496
497 arity_info      :: { ArityInfo }
498 arity_info      : INTEGER                                       { exactArity (fromInteger $1) }
499
500 strict_info     :: { HsStrictnessInfo RdrName }
501 strict_info     : STRICT_PART qvar_name OCURLY qdata_names CCURLY       { HsStrictnessInfo $1 (Just ($2,$4)) }
502                 | STRICT_PART qvar_name                                 { HsStrictnessInfo $1 (Just ($2,[])) }
503                 | STRICT_PART                                           { HsStrictnessInfo $1 Nothing }
504
505 core_expr       :: { UfExpr RdrName }
506 core_expr       : qvar_name                                     { UfVar $1 }
507                 | qdata_name                                    { UfVar $1 }
508                 | core_lit                                      { UfLit $1 }
509                 | OPAREN core_expr CPAREN                       { $2 }
510                 | qdata_name OCURLY data_args CCURLY            { UfCon $1 $3 }
511
512                 | core_expr ATSIGN atype                        { UfApp $1 (UfTyArg $3) }
513                 | core_expr core_arg                            { UfApp $1 $2 }
514                 | LAM core_val_bndrs RARROW core_expr           { foldr UfLam $4 $2 }
515                 | BIGLAM core_tv_bndrs RARROW core_expr         { foldr UfLam $4 $2 }
516
517                 | CASE core_expr OF 
518                   OCURLY alg_alts core_default CCURLY           { UfCase $2 (UfAlgAlts  $5 $6) }
519                 | PRIM_CASE core_expr OF 
520                   OCURLY prim_alts core_default CCURLY          { UfCase $2 (UfPrimAlts $5 $6) }
521
522
523                 | LET OCURLY core_val_bndr EQUAL core_expr CCURLY
524                   IN core_expr                                  { UfLet (UfNonRec $3 $5) $8 }
525                 | LETREC OCURLY rec_binds CCURLY                
526                   IN core_expr                                  { UfLet (UfRec $3) $6 }
527
528                 | CCALL ccall_string 
529                         OBRACK atype atypes CBRACK core_args    { let
530                                                                         (is_casm, may_gc) = $1
531                                                                   in
532                                                                   UfPrim (UfCCallOp $2 is_casm may_gc $5 $4)
533                                                                          $7
534                                                                 }
535                 | INLINE_CALL core_expr                         {  UfNote UfInlineCall $2 }
536                 | COERCE atype core_expr                        {  UfNote (UfCoerce $2) $3 }
537                 | SCC core_expr                                 {  UfNote (UfSCC $1) $2 }
538
539 rec_binds       :: { [(UfBinder RdrName, UfExpr RdrName)] }
540                 :                                               { [] }
541                 | core_val_bndr EQUAL core_expr SEMI rec_binds  { ($1,$3) : $5 }
542
543 prim_alts       :: { [(Literal,UfExpr RdrName)] }
544                 :                                               { [] }
545                 | core_lit RARROW core_expr SEMI prim_alts      { ($1,$3) : $5 }
546
547 alg_alts        :: { [(RdrName, [RdrName], UfExpr RdrName)] }
548                 :                                               { [] }
549                 | qdata_name var_names RARROW 
550                         core_expr SEMI alg_alts                 { ($1,$2,$4) : $6 }
551
552 core_default    :: { UfDefault RdrName }
553                 :                                               { UfNoDefault }
554                 | var_name RARROW core_expr SEMI                { UfBindDefault $1 $3 }
555
556 core_arg        :: { UfArg RdrName }
557                 : qvar_name                                     { UfVarArg $1 }
558                 | qdata_name                                    { UfVarArg $1 }
559                 | core_lit                                      { UfLitArg $1 }
560
561 core_args       :: { [UfArg RdrName] }
562                 :                                               { [] }
563                 | core_arg core_args                            { $1 : $2 }
564
565 data_args       :: { [UfArg RdrName] }
566                 :                                               { [] }
567                 | ATSIGN atype data_args                        { UfTyArg $2 : $3 }
568                 | core_arg data_args                            { $1 : $2 }
569
570 core_lit        :: { Literal }
571 core_lit        : INTEGER                       { MachInt $1 True }
572                 | CHAR                          { MachChar $1 }
573                 | STRING                        { MachStr $1 }
574                 | STRING_LIT STRING             { NoRepStr $2 }
575                 | DOUBLE                        { MachDouble (toRational $1) }
576                 | FLOAT_LIT DOUBLE              { MachFloat (toRational $2) }
577
578                 | INTEGER_LIT INTEGER           { NoRepInteger  $2 (panic "NoRepInteger type") 
579                                                         -- The type checker will add the types
580                                                 }
581
582                 | RATIONAL_LIT INTEGER INTEGER  { NoRepRational ($2 % $3) 
583                                                                 (panic "NoRepRational type")
584                                                                         -- The type checker will add the type
585                                                 }
586
587                 | ADDR_LIT INTEGER              { MachAddr $2 }
588                 | LIT_LIT prim_rep STRING       { MachLitLit $3 (decodePrimRep $2) }
589
590 core_val_bndr   :: { UfBinder RdrName }
591 core_val_bndr   : var_name DCOLON atype                         { UfValBinder $1 $3 }
592
593 core_val_bndrs  :: { [UfBinder RdrName] }
594 core_val_bndrs  :                                               { [] }
595                 | core_val_bndr core_val_bndrs                  { $1 : $2 }
596
597 core_tv_bndr    :: { UfBinder RdrName }
598 core_tv_bndr    :  tv_name DCOLON akind                         { UfTyBinder $1 $3 }
599                 |  tv_name                                      { UfTyBinder $1 mkBoxedTypeKind }
600
601 core_tv_bndrs   :: { [UfBinder RdrName] }
602 core_tv_bndrs   :                                               { [] }
603                 | core_tv_bndr core_tv_bndrs                    { $1 : $2 }
604
605 ccall_string    :: { FAST_STRING }
606                 : STRING                                        { $1 }
607                 | VARID                                         { $1 }
608                 | CONID                                         { $1 }
609
610 prim_rep  :: { Char }
611           : VARID                                               { head (_UNPK_ $1) }
612           | CONID                                               { head (_UNPK_ $1) }
613
614 -------------------------------------------------------------------
615
616 src_loc :: { SrcLoc }
617 src_loc :                               {% getSrcLocIf }
618
619 checkVersion :: { () }
620            : {-empty-}                  {% checkVersion Nothing }
621            | INTEGER                    {% checkVersion (Just (fromInteger $1)) }
622
623 ------------------------------------------------------------------- 
624
625 --                      Haskell code 
626 {
627
628 data IfaceStuff = PIface        ParsedIface
629                 | PIdInfo       [HsIdInfo RdrName]
630                 | PType         RdrNameHsType
631
632 }