[project @ 1999-01-15 15:57:33 by simonm]
[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 Const            ( Literal(..), mkMachInt_safe )
12 import BasicTypes       ( IfaceFlavour(..), Fixity(..), FixityDirection(..), 
13                           NewOrData(..), Version
14                         )
15 import HsPragmas        ( noDataPragmas, noClassPragmas )
16 import Type             ( Kind, mkArrowKind, boxedTypeKind, openTypeKind )
17 import IdInfo           ( ArityInfo, exactArity )
18 import Lex              
19
20 import RnEnv            ( ifaceUnqualTC, ifaceUnqualVar, ifaceUnqualTv, ifaceQualVar, ifaceQualTC )
21 import RnMonad          ( ImportVersion, LocalVersion, ParsedIface(..), WhatsImported(..),
22                           RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..)
23                         ) 
24 import Bag              ( emptyBag, unitBag, snocBag )
25 import FiniteMap        ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
26 import Name             ( OccName, isTCOcc, Provenance, Module,
27                           varOcc, tcOcc, mkModuleFS
28                         )
29 import PrelMods         ( mkTupNameStr, mkUbxTupNameStr )
30 import PrelInfo         ( mkTupConRdrName, mkUbxTupConRdrName )
31 import SrcLoc           ( SrcLoc )
32 import Maybes
33 import Outputable
34
35 import GlaExts
36
37 #if __HASKELL1__ > 4
38 import Ratio ( (%) )
39 #endif
40 }
41
42 %name       parseIface
43 %tokentype  { IfaceToken }
44 %monad      { IfM }{ thenIf }{ returnIf }
45 %lexer      { lexIface } { ITeof }
46
47 %token
48  'case'         { ITcase }                      -- Haskell keywords
49  'class'        { ITclass } 
50  'data'         { ITdata } 
51  'default'      { ITdefault }
52  'deriving'     { ITderiving }
53  'do'           { ITdo }
54  'else'         { ITelse }
55  'if'           { ITif }
56  'import'       { ITimport }
57  'in'           { ITin }
58  'infix'        { ITinfix }
59  'infixl'       { ITinfixl }
60  'infixr'       { ITinfixr }
61  'instance'     { ITinstance }
62  'let'          { ITlet }
63  'module'       { ITmodule }
64  'newtype'      { ITnewtype }
65  'of'           { ITof }
66  'then'         { ITthen }
67  'type'         { ITtype }
68  'where'        { ITwhere }
69  'as'           { ITas }
70  'qualified'    { ITqualified }
71  'hiding'       { IThiding }
72
73  '__interface'  { ITinterface }                 -- GHC-extension keywords
74  '__export'     { ITexport }
75  '__instimport' { ITinstimport }
76  '__forall'     { ITforall }
77  '__letrec'     { ITletrec }
78  '__coerce'     { ITcoerce }
79  '__inline'     { ITinline }
80  '__DEFAULT'    { ITdefaultbranch }
81  '__bot'        { ITbottom }
82  '__integer'    { ITinteger_lit }
83  '__float'      { ITfloat_lit }
84  '__rational'   { ITrational_lit }
85  '__addr'       { ITaddr_lit }
86  '__litlit'     { ITlit_lit }
87  '__string'     { ITstring_lit }
88  '__ccall'      { ITccall $$ }
89  '__scc'        { ITscc $$ }
90  '__a'          { ITtypeapp }
91
92  '__A'          { ITarity }
93  '__P'          { ITspecialise }
94  '__C'          { ITnocaf }
95  '__U'          { ITunfold $$ }
96  '__S'          { ITstrict $$ }
97
98  '..'           { ITdotdot }                    -- reserved symbols
99  '::'           { ITdcolon }
100  '='            { ITequal }
101  '\\'           { ITlam }
102  '|'            { ITvbar }
103  '<-'           { ITlarrow }
104  '->'           { ITrarrow }
105  '@'            { ITat }
106  '~'            { ITtilde }
107  '=>'           { ITdarrow }
108  '-'            { ITminus }
109  '!'            { ITbang }
110
111  '/\\'          { ITbiglam }                    -- GHC-extension symbols
112
113  '{'            { ITocurly }                    -- special symbols
114  '}'            { ITccurly }
115  '['            { ITobrack }
116  ']'            { ITcbrack }
117  '('            { IToparen }
118  ')'            { ITcparen }
119  '(#'           { IToubxparen }
120  '#)'           { ITcubxparen }
121  ';'            { ITsemi }
122  ','            { ITcomma }
123
124  VARID          { ITvarid    $$ }               -- identifiers
125  CONID          { ITconid    $$ }
126  VARSYM         { ITvarsym   $$ }
127  CONSYM         { ITconsym   $$ }
128  QVARID         { ITqvarid   $$ }
129  QCONID         { ITqconid   $$ }
130  QVARSYM        { ITqvarsym  $$ }
131  QCONSYM        { ITqconsym  $$ }
132
133  PRAGMA         { ITpragma   $$ }
134
135  CHAR           { ITchar     $$ }
136  STRING         { ITstring   $$ }
137  INTEGER        { ITinteger  $$ }
138  RATIONAL       { ITrational $$ }
139
140  UNKNOWN        { ITunknown  $$ }
141 %%
142
143 -- iface_stuff is the main production.
144 -- It recognises (a) a whole interface file
145 --               (b) a type (so that type sigs can be parsed lazily)
146 --               (c) the IdInfo part of a signature (same reason)
147
148 iface_stuff :: { IfaceStuff }
149 iface_stuff : iface             { PIface  $1 }
150             | type              { PType   $1 }
151             | id_info           { PIdInfo $1 }
152
153
154 iface           :: { ParsedIface }
155 iface           : '__interface' mod_name INTEGER checkVersion 'where'
156                   import_part
157                   instance_import_part
158                   exports_part
159                   instance_decl_part
160                   decls_part
161                   { ParsedIface 
162                         $2                      -- Module name
163                         (fromInteger $3)        -- Module version
164                         (reverse $6)            -- Usages
165                         (reverse $8)            -- Exports
166                         (reverse $7)            -- Instance import modules
167                         (reverse $10)           -- Decls
168                         (reverse $9)            -- Local instances
169                   }
170
171 --------------------------------------------------------------------------
172
173 import_part :: { [ImportVersion OccName] }
174 import_part :                                             { [] }
175             |  import_part import_decl                    { $2 : $1 }
176             
177 import_decl :: { ImportVersion OccName }
178 import_decl : 'import' mod_name opt_bang INTEGER '::' whats_imported ';'
179                         { ($2, $3, fromInteger $4, $6) }
180
181 whats_imported      :: { WhatsImported OccName }
182 whats_imported      :                                           { Everything }
183                     | name_version_pair name_version_pairs      { Specifically ($1:$2) }
184
185 name_version_pairs  ::  { [LocalVersion OccName] }
186 name_version_pairs  :                                           { [] }
187                     |  name_version_pair name_version_pairs     { $1 : $2 }
188
189 name_version_pair   ::  { LocalVersion OccName }
190 name_version_pair   :  entity_occ INTEGER                       { ($1, fromInteger $2) }
191
192 instance_import_part :: { [Module] }
193 instance_import_part :                                          {   []    }
194                      | instance_import_part '__instimport' mod_name ';'
195                                                                 { $3 : $1 }
196
197 --------------------------------------------------------------------------
198
199 exports_part    :: { [ExportItem] }
200 exports_part    :                                       { [] }
201                 | exports_part '__export' opt_bang mod_name entities ';'
202                                                 { ($4,$3,$5) : $1 }
203
204 opt_bang        :: { IfaceFlavour }
205 opt_bang        :                                               { HiFile }
206                 | '!'                                           { HiBootFile }
207
208 entities        :: { [RdrAvailInfo] }
209 entities        :                                               { [] }
210                 |  entity entities                              { $1 : $2 }
211
212 entity          :: { RdrAvailInfo }
213 entity          :  entity_occ                           { if isTCOcc $1 
214                                                           then AvailTC $1 [$1]
215                                                           else Avail $1 }
216                 |  entity_occ stuff_inside              { AvailTC $1 ($1:$2) }
217                 |  entity_occ '|' stuff_inside          { AvailTC $1 $3 }
218
219 stuff_inside    :: { [OccName] }
220 stuff_inside    :  '{' val_occs '}'                     { $2 }
221
222 --------------------------------------------------------------------------
223
224 fixity      :: { FixityDirection }
225 fixity      : 'infixl'                                  { InfixL }
226             | 'infixr'                                  { InfixR }
227             | 'infix'                                   { InfixN }
228    
229 mb_fix      :: { Int }
230 mb_fix      : {-nothing-}                               { 9 }
231             | INTEGER                                   { (fromInteger $1) }
232
233 -----------------------------------------------------------------------------
234
235 csigs           :: { [RdrNameSig] }
236 csigs           :                               { [] }
237                 | 'where' '{' csigs1 '}'        { $3 }
238
239 csigs1          :: { [RdrNameSig] }
240 csigs1          : csig                          { [$1] }
241                 | csig ';' csigs1               { $1 : $3 }
242
243 csig            :: { RdrNameSig }
244 csig            :  src_loc var_name '::' type { ClassOpSig $2 Nothing $4 $1 }
245                 |  src_loc var_name '=' '::' type       
246                         { ClassOpSig $2 
247                             (Just (error "Un-filled-in default method"))
248                             $5 $1 }
249
250 --------------------------------------------------------------------------
251
252 instance_decl_part :: { [RdrNameInstDecl] }
253 instance_decl_part : {- empty -}                       { [] }
254                    | instance_decl_part inst_decl      { $2 : $1 }
255
256 inst_decl       :: { RdrNameInstDecl }
257 inst_decl       :  src_loc 'instance' type '=' var_name ';'
258                         { InstDecl $3
259                                    EmptyMonoBinds       {- No bindings -}
260                                    []                   {- No user pragmas -}
261                                    (Just $5)            {- Dfun id -}
262                                    $1
263                         }
264
265 --------------------------------------------------------------------------
266
267 decls_part :: { [(Version, RdrNameHsDecl)] }
268 decls_part 
269         :  {- empty -}                          { [] }
270         |  decls_part version decl ';'          { ($2,$3):$1 }
271
272 decl    :: { RdrNameHsDecl }
273 decl    : src_loc var_name '::' type maybe_idinfo
274                          { SigD (IfaceSig $2 $4 ($5 $2) $1) }
275         | src_loc 'type' tc_name tv_bndrs '=' type                     
276                         { TyClD (TySynonym $3 $4 $6 $1) }
277         | src_loc 'data' decl_context data_fs tv_bndrs constrs         
278                         { TyClD (TyData DataType $3 (ifaceUnqualTC $4) $5 $6 Nothing noDataPragmas $1) }
279         | src_loc 'newtype' decl_context tc_name tv_bndrs newtype_constr
280                         { TyClD (TyData NewType $3 $4 $5 $6 Nothing noDataPragmas $1) }
281         | src_loc 'class' decl_context tc_name tv_bndrs csigs
282                         { TyClD (mkClassDecl $3 $4 $5 $6 EmptyMonoBinds 
283                                         noClassPragmas $1) }
284         | src_loc fixity mb_fix val_occ
285                         { FixD (FixitySig (Unqual $4) (Fixity $3 $2) $1) }
286
287 maybe_idinfo  :: { RdrName -> [HsIdInfo RdrName] }
288 maybe_idinfo  : {- empty -}     { \_ -> [] }
289               | src_loc PRAGMA  { \x -> 
290                                    case parseIface $2 $1 of
291                                      Succeeded (PIdInfo id_info) -> id_info
292                                      Failed err -> pprPanic "IdInfo parse failed" 
293                                                             (vcat [ppr x, err])
294                                 }
295
296 -----------------------------------------------------------------------------
297
298 version         :: { Version }
299 version         :  INTEGER                              { fromInteger $1 }
300
301 decl_context    :: { RdrNameContext }
302 decl_context    :                                       { [] }
303                 | '{' context_list1 '}' '=>'    { $2 }
304
305 ----------------------------------------------------------------
306
307 constrs         :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
308                 :                       { [] }
309                 | '=' constrs1          { $2 }
310
311 constrs1        :: { [RdrNameConDecl] }
312 constrs1        :  constr               { [$1] }
313                 |  constr '|' constrs1  { $1 : $3 }
314
315 constr          :: { RdrNameConDecl }
316 constr          :  src_loc ex_stuff data_fs batypes             { mkConDecl (ifaceUnqualVar $3) $2 (VanillaCon $4) $1 }
317                 |  src_loc ex_stuff data_fs '{' fields1 '}'     { mkConDecl (ifaceUnqualVar $3) $2 (RecCon $5)     $1 }
318                 -- We use "data_fs" so as to include ()
319
320 newtype_constr  :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
321 newtype_constr  :                                       { [] }
322                 | src_loc '=' ex_stuff data_name atype  { [mkConDecl $4 $3 (NewCon $5 Nothing) $1] }
323                 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
324                                                         { [mkConDecl $4 $3 (NewCon $8 (Just $6)) $1] }
325
326 ex_stuff :: { ([HsTyVar RdrName], RdrNameContext) }
327 ex_stuff        :                                       { ([],[]) }
328                 | '__forall' forall context '=>'            { ($2,$3) }
329
330 batypes         :: { [RdrNameBangType] }
331 batypes         :                                       { [] }
332                 |  batype batypes                       { $1 : $2 }
333
334 batype          :: { RdrNameBangType }
335 batype          :  atype                                { Unbanged $1 }
336                 |  '!' atype                            { Banged   $2 }
337
338 fields1         :: { [([RdrName], RdrNameBangType)] }
339 fields1         : field                                 { [$1] }
340                 | field ',' fields1                     { $1 : $3 }
341
342 field           :: { ([RdrName], RdrNameBangType) }
343 field           :  var_names1 '::' type         { ($1, Unbanged $3) }
344                 |  var_names1 '::' '!' type     { ($1, Banged   $4) }
345 --------------------------------------------------------------------------
346
347 type            :: { RdrNameHsType }
348 type            : '__forall' forall context '=>' type   
349                                                 { mkHsForAllTy $2 $3 $5 }
350                 | btype '->' type               { MonoFunTy $1 $3 }
351                 | btype                         { $1 }
352
353 forall          :: { [HsTyVar RdrName] }
354 forall          : '[' tv_bndrs ']'                      { $2 }
355
356 context         :: { RdrNameContext }
357 context         :                                       { [] }
358                 | '{' context_list1 '}'                 { $2 }
359
360 context_list1   :: { RdrNameContext }
361 context_list1   : class                                 { [$1] }
362                 | class ',' context_list1               { $1 : $3 }
363
364 class           :: { (RdrName, [RdrNameHsType]) }
365 class           :  qtc_name atypes                      { ($1, $2) }
366
367 types2          :: { [RdrNameHsType]                    {- Two or more -}  }    
368 types2          :  type ',' type                        { [$1,$3] }
369                 |  type ',' types2                      { $1 : $3 }
370
371 btype           :: { RdrNameHsType }
372 btype           :  atype                                { $1 }
373                 |  btype atype                          { MonoTyApp $1 $2 }
374
375 atype           :: { RdrNameHsType }
376 atype           :  qtc_name                             { MonoTyVar $1 }
377                 |  tv_name                              { MonoTyVar $1 }
378                 |  '(' ')'                              { MonoTupleTy [] True }
379                 |  '(' types2 ')'                       { MonoTupleTy $2 True{-boxed-} }
380                 |  '(#' type '#)'                       { MonoTupleTy [$2] False{-unboxed-} }
381                 |  '(#' types2 '#)'                     { MonoTupleTy $2 False{-unboxed-} }
382                 |  '[' type ']'                         { MonoListTy  $2 }
383                 |  '{' qtc_name atypes '}'              { MonoDictTy $2 $3 }
384                 |  '(' type ')'                         { $2 }
385
386 atypes          :: { [RdrNameHsType]    {-  Zero or more -} }
387 atypes          :                                       { [] }
388                 |  atype atypes                         { $1 : $2 }
389 ---------------------------------------------------------------------
390
391 mod_name        :: { Module }
392                 :  CONID                { mkModuleFS $1 }
393
394 var_fs          :: { FAST_STRING }
395                 : VARID                 { $1 }
396                 | VARSYM                { $1 }
397                 | '-'                   { SLIT("-") }
398                 | '!'                   { SLIT("!") }
399
400 data_fs         :: { FAST_STRING }
401                 :  CONID                { $1 }
402                 |  CONSYM               { $1 }
403                 |  '->'                 { SLIT("->") }
404                 |  '(' ')'              { SLIT("()") }
405                 |  '(' commas ')'       { snd (mkTupNameStr $2) }
406                 |  '[' ']'              { SLIT("[]") }
407
408 commas          :: { Int }
409                 : ','                   { 2 }
410                 | commas ','            { $1 + 1 }
411
412 val_occ         :: { OccName }
413                 :  var_fs               { varOcc $1 }
414                 |  data_fs              { varOcc $1 }
415
416 val_occs        :: { [OccName] }
417                 :  val_occ              { [$1] }
418                 |  val_occ val_occs     { $1 : $2 }
419
420 entity_occ      :: { OccName }
421                 :  var_fs               { varOcc $1 }
422                 |  data_fs              { tcOcc $1 }
423
424 var_name        :: { RdrName }
425 var_name        :  var_fs               { ifaceUnqualVar $1 }
426
427 qvar_name       :: { RdrName }
428 qvar_name       :  var_name             { $1 }
429                 |  QVARID               { ifaceQualVar $1 }
430                 |  QVARSYM              { ifaceQualVar $1 }
431
432 var_names       :: { [RdrName] }
433 var_names       :                       { [] }
434                 | var_name var_names    { $1 : $2 }
435
436 var_names1      :: { [RdrName] }
437 var_names1      : var_name var_names    { $1 : $2 }
438
439 data_name       :: { RdrName }
440                 :  CONID                { ifaceUnqualVar $1 }
441                 |  CONSYM               { ifaceUnqualVar $1 }
442                 |  '(' commas ')'       { ifaceUnqualVar (snd (mkTupNameStr $2)) }
443                 |  '[' ']'              { ifaceUnqualVar SLIT("[]") }
444
445 qdata_name      :: { RdrName }
446 qdata_name      :  data_name            { $1 }
447                 |  QCONID               { ifaceQualVar $1 }
448                 |  QCONSYM              { ifaceQualVar $1 }
449                                 
450 qdata_names     :: { [RdrName] }
451 qdata_names     :                               { [] }
452                 | qdata_name qdata_names        { $1 : $2 }
453
454 tc_name         :: { RdrName }
455 tc_name         :  CONID                { ifaceUnqualTC $1 }
456                 |  CONSYM               { ifaceUnqualTC $1 }
457                 |  '(' '->' ')'         { ifaceUnqualTC SLIT("->") }
458                 |  '(' commas ')'       { ifaceUnqualTC (snd (mkTupNameStr $2)) }
459                 |  '[' ']'              { ifaceUnqualTC SLIT("[]") }
460
461 qtc_name        :: { RdrName }
462 qtc_name        : tc_name               { $1 }
463                 | QCONID                { ifaceQualTC $1 }
464                 | QCONSYM               { ifaceQualTC $1 }
465
466 tv_name         :: { RdrName }
467 tv_name         :  VARID                { ifaceUnqualTv $1 }
468                 |  VARSYM               { ifaceUnqualTv $1 {- Allow t2 as a tyvar -} }
469
470 tv_bndr         :: { HsTyVar RdrName }
471 tv_bndr         :  tv_name '::' akind   { IfaceTyVar $1 $3 }
472                 |  tv_name              { IfaceTyVar $1 boxedTypeKind }
473
474 tv_bndrs        :: { [HsTyVar RdrName] }
475                 :                       { [] }
476                 | tv_bndr tv_bndrs      { $1 : $2 }
477
478 kind            :: { Kind }
479                 : akind                 { $1 }
480                 | akind '->' kind       { mkArrowKind $1 $3 }
481
482 akind           :: { Kind }
483                 : VARSYM                { if $1 == SLIT("*") then
484                                                 boxedTypeKind
485                                           else if $1 == SLIT("?") then
486                                                 openTypeKind
487                                           else panic "ParseInterface: akind"
488                                         }
489                 | '(' kind ')'  { $2 }
490
491 --------------------------------------------------------------------------
492
493 id_info         :: { [HsIdInfo RdrName] }
494 id_info         :                               { [] }
495                 | id_info_item id_info          { $1 : $2 }
496
497 id_info_item    :: { HsIdInfo RdrName }
498 id_info_item    : '__A' arity_info              { HsArity $2 }
499                 | strict_info                   { HsStrictness $1 }
500                 | '__U' core_expr               { HsUnfold $1 (Just $2) }
501                 | '__U'                         { HsUnfold $1 Nothing }
502                 | '__P' spec_tvs
503                      atypes '=' core_expr       { HsSpecialise $2 $3 $5 }
504                 | '__C'                         { HsNoCafRefs }
505
506
507 spec_tvs        :: { [HsTyVar RdrName] }
508 spec_tvs        : '[' tv_bndrs ']'              { $2 }
509         
510
511 arity_info      :: { ArityInfo }
512 arity_info      : INTEGER                       { exactArity (fromInteger $1) }
513
514 strict_info     :: { HsStrictnessInfo RdrName }
515 strict_info     : '__S' qvar_name '{' qdata_names '}'   
516                                         { HsStrictnessInfo $1 (Just ($2,$4)) }
517                 | '__S' qvar_name       { HsStrictnessInfo $1 (Just ($2,[])) }
518                 | '__S'                 { HsStrictnessInfo $1 Nothing }
519
520 -------------------------------------------------------
521 core_expr       :: { UfExpr RdrName }
522 core_expr       : '\\' core_bndrs '->' core_expr        { foldr UfLam $4 $2 }
523                 | 'case' core_expr 'of' var_name
524                   '{' core_alts '}'                     { UfCase $2 $4 $6 }
525
526                 | 'let' '{' core_val_bndr '=' core_expr
527                       '}' 'in' core_expr                { UfLet (UfNonRec $3 $5) $8 }
528                 | '__letrec' '{' rec_binds '}'          
529                   'in' core_expr                        { UfLet (UfRec $3) $6 }
530
531                 | con_or_primop '{' core_args '}'       { UfCon $1 $3 }
532                 | '__litlit' STRING atype               { UfCon (UfLitLitCon $2 $3) [] }
533
534                 | '__inline' core_expr               { UfNote UfInlineCall $2 }
535                 | '__coerce' atype core_expr         { UfNote (UfCoerce $2) $3 }
536                 | '__scc' core_expr                  { UfNote (UfSCC $1) $2  }
537                 | fexpr                              { $1 }
538
539 fexpr   :: { UfExpr RdrName }
540 fexpr   : fexpr core_arg                                { UfApp $1 $2 }
541         | core_aexpr                                    { $1 }
542
543 core_arg        :: { UfExpr RdrName }
544                 : '__a' atype                                  { UfType $2 }
545                 | core_aexpr                                    { $1 }
546
547 core_args       :: { [UfExpr RdrName] }
548                 :                                               { [] }
549                 | core_arg core_args                            { $1 : $2 }
550
551 core_aexpr      :: { UfExpr RdrName }              -- Atomic expressions
552 core_aexpr      : qvar_name                                     { UfVar $1 }
553
554                 | qdata_name                                    { UfVar $1 }
555                         -- This one means that e.g. "True" will parse as 
556                         -- (UfVar True_Id) rather than (UfCon True_Con []).
557                         -- No big deal; it'll be inlined in a jiffy.  I tried 
558                         -- parsing it to (Con con []) directly, but got bitten 
559                         -- when a real constructor Id showed up in an interface
560                         -- file.  As usual, a hack bites you in the end.
561                         -- If you want to get a UfCon, then use the
562                         -- curly-bracket notation (True {}).
563
564                 | core_lit               { UfCon (UfLitCon $1) [] }
565                 | '(' core_expr ')'      { $2 }
566                 | '('  ')'               { UfTuple (mkTupConRdrName 0) [] }
567                 | '(' comma_exprs2 ')'   { UfTuple (mkTupConRdrName (length $2)) $2 }
568                 | '(#' core_expr '#)'    { UfTuple (mkUbxTupConRdrName 1) [$2] }
569                 | '(#' comma_exprs2 '#)' { UfTuple (mkUbxTupConRdrName (length $2)) $2 }
570
571 comma_exprs2    :: { [UfExpr RdrName] } -- Two or more
572 comma_exprs2    : core_expr ',' core_expr                       { [$1,$3] }
573                 | core_expr ',' comma_exprs2                    { $1 : $3 }
574
575 con_or_primop   :: { UfCon RdrName }
576 con_or_primop   : qdata_name                    { UfDataCon $1 }
577                 | qvar_name                     { UfPrimOp $1 }
578                 | '__ccall' ccall_string      { let
579                                                 (is_dyn, is_casm, may_gc) = $1
580                                                 in
581                                                 UfCCallOp $2 is_dyn is_casm may_gc
582                                                 }
583
584 rec_binds       :: { [(UfBinder RdrName, UfExpr RdrName)] }
585                 :                                               { [] }
586                 | core_val_bndr '=' core_expr ';' rec_binds     { ($1,$3) : $5 }
587
588 core_alts       :: { [UfAlt RdrName] }
589                 : core_alt                                      { [$1] }
590                 | core_alt ';' core_alts                        { $1 : $3 }
591
592 core_alt        :: { UfAlt RdrName }
593 core_alt        : core_pat '->' core_expr       { (fst $1, snd $1, $3) }
594
595 core_pat        :: { (UfCon RdrName, [RdrName]) }
596 core_pat        : core_lit                      { (UfLitCon  $1, []) }
597                 | '__litlit' STRING atype       { (UfLitLitCon $2 $3, []) }
598                 | qdata_name var_names          { (UfDataCon $1, $2) }
599                 | '(' comma_var_names ')'       { (UfDataCon (mkTupConRdrName (length $2)), $2) }
600                 | '(#' comma_var_names1 '#)'    { (UfDataCon (mkUbxTupConRdrName (length $2)), $2) }
601                 | '__DEFAULT'                   { (UfDefault, []) }
602                 | '(' core_pat ')'              { $2 }
603
604
605 comma_var_names :: { [RdrName] }        -- Zero, or two or more
606 comma_var_names :                                               { [] }
607                 | var_name ',' comma_var_names1         { $1 : $3 }
608
609 comma_var_names1 :: { [RdrName] }       -- One or more
610 comma_var_names1 : var_name                                     { [$1] }
611                  | var_name ',' comma_var_names1                { $1 : $3 }
612
613 core_lit        :: { Literal }
614 core_lit        : INTEGER                       { mkMachInt_safe $1 }
615                 | CHAR                          { MachChar $1 }
616                 | STRING                        { MachStr $1 }
617                 | '__string' STRING             { NoRepStr $2 (panic "NoRepStr type") }
618                 | RATIONAL                      { MachDouble $1 }
619                 | '__float' RATIONAL            { MachFloat $2 }
620
621                 | '__integer' INTEGER           { NoRepInteger  $2 (panic "NoRepInteger type") 
622                                                         -- The type checker will add the types
623                                                 }
624
625                 | '__rational' INTEGER INTEGER  { NoRepRational ($2 % $3) 
626                                                    (panic "NoRepRational type")
627                                                         -- The type checker will add the type
628                                                 }
629
630                 | '__addr' INTEGER              { MachAddr $2 }
631
632 core_bndr       :: { UfBinder RdrName }
633 core_bndr       : core_val_bndr                                 { $1 }
634                 | core_tv_bndr                                  { $1 }
635
636 core_bndrs      :: { [UfBinder RdrName] }
637 core_bndrs      :                                               { [] }
638                 | core_bndr core_bndrs                          { $1 : $2 }
639
640 core_val_bndr   :: { UfBinder RdrName }
641 core_val_bndr   : var_name '::' atype                           { UfValBinder $1 $3 }
642
643 core_tv_bndr    :: { UfBinder RdrName }
644 core_tv_bndr    :  '__a' tv_name '::' akind             { UfTyBinder $2 $4 }
645                 |  '__a' tv_name                        { UfTyBinder $2 boxedTypeKind }
646
647 ccall_string    :: { FAST_STRING }
648                 : STRING                                        { $1 }
649                 | VARID                                         { $1 }
650                 | CONID                                         { $1 }
651
652 -------------------------------------------------------------------
653
654 src_loc :: { SrcLoc }
655 src_loc :                               {% getSrcLocIf }
656
657 checkVersion :: { () }
658            : {-empty-}                  {% checkVersion Nothing }
659            | INTEGER                    {% checkVersion (Just (fromInteger $1)) }
660
661 ------------------------------------------------------------------- 
662
663 --                      Haskell code 
664 {
665
666 data IfaceStuff = PIface        ParsedIface
667                 | PIdInfo       [HsIdInfo RdrName]
668                 | PType         RdrNameHsType
669
670 mkConDecl name (ex_tvs, ex_ctxt) details loc = ConDecl name ex_tvs ex_ctxt details loc
671 }