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