2 module ParseIface ( parseIface, IfaceStuff(..) ) where
4 #include "HsVersions.h"
6 import HsSyn -- quite a bit of stuff
7 import RdrHsSyn -- oodles of synonyms
8 import HsTypes ( mkHsForAllTy, mkHsUsForAllTy )
10 import Const ( Literal(..), mkMachInt_safe )
11 import BasicTypes ( Fixity(..), FixityDirection(..),
12 NewOrData(..), Version
14 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
15 import HsPragmas ( noDataPragmas, noClassPragmas )
16 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind, UsageAnn(..) )
17 import IdInfo ( ArityInfo, exactArity, CprInfo(..), InlinePragInfo(..) )
20 import RnMonad ( ImportVersion, LocalVersion, ParsedIface(..), WhatsImported(..),
21 RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..), WhetherHasOrphans
23 import Bag ( emptyBag, unitBag, snocBag )
24 import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
25 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual )
26 import Name ( OccName, Provenance )
27 import OccName ( mkSysOccFS,
28 tcName, varName, ipName, dataName, clsName, tvName, uvName,
31 import Module ( ModuleName, mkSysModuleFS )
32 import PrelMods ( mkTupNameStr, mkUbxTupNameStr )
33 import PrelInfo ( mkTupConRdrName, mkUbxTupConRdrName )
34 import SrcLoc ( SrcLoc )
39 import FastString ( tailFS )
48 %monad { P }{ thenP }{ returnP }
49 %lexer { lexer } { ITeof }
52 'case' { ITcase } -- Haskell keywords
55 'default' { ITdefault }
56 'deriving' { ITderiving }
65 'instance' { ITinstance }
68 'newtype' { ITnewtype }
74 'qualified' { ITqualified }
77 'forall' { ITforall } -- GHC extension keywords
78 'foreign' { ITforeign }
81 'dynamic' { ITdynamic }
85 '__interface' { ITinterface } -- interface keywords
86 '__export' { IT__export }
87 '__forall' { IT__forall }
88 '__depends' { ITdepends }
89 '__letrec' { ITletrec }
90 '__coerce' { ITcoerce }
91 '__inline_call'{ ITinlineCall }
92 '__inline_me' { ITinlineMe }
93 '__DEFAULT' { ITdefaultbranch }
95 '__integer' { ITinteger_lit }
96 '__float' { ITfloat_lit }
97 '__rational' { ITrational_lit }
98 '__addr' { ITaddr_lit }
99 '__litlit' { ITlit_lit }
100 '__string' { ITstring_lit }
101 '__ccall' { ITccall $$ }
103 '__sccC' { ITsccAllCafs }
106 '__fuall' { ITfuall }
109 '__P' { ITspecialise }
111 '__U' { ITunfold $$ }
112 '__S' { ITstrict $$ }
114 '__D' { ITdeprecated }
115 '__M' { ITcprinfo $$ }
117 '..' { ITdotdot } -- reserved symbols
130 '/\\' { ITbiglam } -- GHC-extension symbols
132 '{' { ITocurly } -- special symbols
143 VARID { ITvarid $$ } -- identifiers
145 VARSYM { ITvarsym $$ }
146 CONSYM { ITconsym $$ }
147 QVARID { ITqvarid $$ }
148 QCONID { ITqconid $$ }
149 QVARSYM { ITqvarsym $$ }
150 QCONSYM { ITqconsym $$ }
152 IPVARID { ITipvarid $$ } -- GHC extension
154 PRAGMA { ITpragma $$ }
157 STRING { ITstring $$ }
158 INTEGER { ITinteger $$ }
159 RATIONAL { ITrational $$ }
160 CLITLIT { ITlitlit $$ }
162 UNKNOWN { ITunknown $$ }
165 -- iface_stuff is the main production.
166 -- It recognises (a) a whole interface file
167 -- (b) a type (so that type sigs can be parsed lazily)
168 -- (c) the IdInfo part of a signature (same reason)
170 iface_stuff :: { IfaceStuff }
171 iface_stuff : iface { let (nm, iff) = $1 in PIface nm iff }
173 | id_info { PIdInfo $1 }
174 | '__R' rules { PRules $2 }
175 | '__D' deprecs { PDeprecs $2 }
178 iface :: { (ModuleName, ParsedIface) }
179 iface : '__interface' mod_fs INTEGER orphans checkVersion 'where'
185 { ( $2 -- Module name
187 pi_mod = fromInteger $3, -- Module version
189 pi_exports = $7, -- Exports
190 pi_usages = $8, -- Usages
191 pi_insts = $9, -- Local instances
192 pi_decls = $10, -- Decls
193 pi_rules = fst $11, -- Rules
194 pi_deprecs = snd $11 -- Deprecations
197 --------------------------------------------------------------------------
199 import_part :: { [ImportVersion OccName] }
201 | import_part import_decl { $2 : $1 }
203 import_decl :: { ImportVersion OccName }
204 import_decl : 'import' mod_fs INTEGER orphans whats_imported ';'
205 { (mkSysModuleFS $2, fromInteger $3, $4, $5) }
206 -- import Foo 3 :: a 1 b 3 c 7 ; means import a,b,c from Foo
207 -- import Foo 3 ; means import all of Foo
208 -- import Foo 3 ! :: ...stuff... ; the ! means that Foo contains orphans
210 orphans :: { WhetherHasOrphans }
214 whats_imported :: { WhatsImported OccName }
215 whats_imported : { Everything }
216 | '::' name_version_pairs { Specifically $2 }
218 name_version_pairs :: { [LocalVersion OccName] }
219 name_version_pairs : { [] }
220 | name_version_pair name_version_pairs { $1 : $2 }
222 name_version_pair :: { LocalVersion OccName }
223 name_version_pair : var_occ INTEGER { ($1, fromInteger $2) }
224 | tc_occ INTEGER { ($1, fromInteger $2) }
227 --------------------------------------------------------------------------
229 exports_part :: { [ExportItem] }
230 exports_part : { [] }
231 | exports_part '__export'
232 mod_fs entities ';' { (mkSysModuleFS $3, $4) : $1 }
234 entities :: { [RdrAvailInfo] }
236 | entity entities { $1 : $2 }
238 entity :: { RdrAvailInfo }
239 entity : tc_occ { AvailTC $1 [$1] }
240 | var_occ { Avail $1 }
241 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
242 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
244 stuff_inside :: { [OccName] }
245 stuff_inside : '{' val_occs '}' { $2 }
247 val_occ :: { OccName }
251 val_occs :: { [OccName] }
253 | val_occ val_occs { $1 : $2 }
256 --------------------------------------------------------------------------
258 fixity :: { FixityDirection }
259 fixity : 'infixl' { InfixL }
260 | 'infixr' { InfixR }
264 mb_fix : {-nothing-} { 9 }
265 | INTEGER { (fromInteger $1) }
267 -----------------------------------------------------------------------------
269 csigs :: { [RdrNameSig] }
271 | 'where' '{' csigs1 '}' { $3 }
273 csigs1 :: { [RdrNameSig] }
274 csigs1 : csig { [$1] }
275 | csig ';' csigs1 { $1 : $3 }
277 csig :: { RdrNameSig }
278 csig : src_loc var_name '::' type { mkClassOpSig False $2 $4 $1 }
279 | src_loc var_name '=' '::' type { mkClassOpSig True $2 $5 $1 }
281 --------------------------------------------------------------------------
283 instance_decl_part :: { [RdrNameInstDecl] }
284 instance_decl_part : {- empty -} { [] }
285 | instance_decl_part inst_decl { $2 : $1 }
287 inst_decl :: { RdrNameInstDecl }
288 inst_decl : src_loc 'instance' type '=' var_name ';'
290 EmptyMonoBinds {- No bindings -}
291 [] {- No user pragmas -}
296 --------------------------------------------------------------------------
298 decls_part :: { [(Version, RdrNameHsDecl)] }
301 | decls_part version decl ';' { ($2,$3):$1 }
303 decl :: { RdrNameHsDecl }
304 decl : src_loc var_name '::' type maybe_idinfo
305 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
306 | src_loc 'type' tc_name tv_bndrs '=' type
307 { TyClD (TySynonym $3 $4 $6 $1) }
308 | src_loc 'data' decl_context tc_name tv_bndrs constrs
309 { TyClD (TyData DataType $3 $4 $5 $6 Nothing noDataPragmas $1) }
310 | src_loc 'newtype' decl_context tc_name tv_bndrs newtype_constr
311 { TyClD (TyData NewType $3 $4 $5 $6 Nothing noDataPragmas $1) }
312 | src_loc 'class' decl_context tc_name tv_bndrs fds csigs
313 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds
315 | src_loc fixity mb_fix var_or_data_name
316 { FixD (FixitySig $4 (Fixity $3 $2) $1) }
318 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
319 maybe_idinfo : {- empty -} { \_ -> [] }
320 | pragma { \x -> case $1 of
321 POk _ (PIdInfo id_info) -> id_info
323 pprPanic "IdInfo parse failed"
327 pragma :: { ParseResult IfaceStuff }
328 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
334 -----------------------------------------------------------------------------
336 rules_and_deprecs :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
337 rules_and_deprecs : {- empty -} { ([], []) }
338 | rules_and_deprecs rule_or_deprec
340 append2 (xs1,ys1) (xs2,ys2) =
341 (xs1 `app` xs2, ys1 `app` ys2)
342 xs `app` [] = xs -- performance paranoia
343 xs `app` ys = xs ++ ys
347 rule_or_deprec :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
348 rule_or_deprec : pragma { case $1 of
349 POk _ (PRules rules) -> (rules,[])
350 POk _ (PDeprecs deprecs) -> ([],deprecs)
351 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
354 -----------------------------------------------------------------------------
356 rules :: { [RdrNameRuleDecl] }
358 | rule ';' rules { $1:$3 }
360 rule :: { RdrNameRuleDecl }
361 rule : src_loc STRING rule_forall qvar_name
362 core_args '=' core_expr { IfaceRuleDecl $4 (UfRuleBody $2 $3 $5 $7) $1 }
364 rule_forall :: { [UfBinder RdrName] }
365 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
367 -----------------------------------------------------------------------------
369 deprecs :: { [RdrNameDeprecation] }
370 deprecs : {- empty -} { [] }
371 | deprecs deprec ';' { $2 : $1 }
373 deprec :: { RdrNameDeprecation }
374 deprec : STRING { Deprecation (IEModuleContents undefined) $1 }
375 | deprec_name STRING { Deprecation $1 $2 }
377 -- SUP: TEMPORARY HACK
378 deprec_name :: { RdrNameIE }
379 : var_name { IEVar $1 }
380 | data_name { IEThingAbs $1 }
382 -----------------------------------------------------------------------------
384 version :: { Version }
385 version : INTEGER { fromInteger $1 }
387 decl_context :: { RdrNameContext }
388 decl_context : { [] }
389 | '{' context_list1 '}' '=>' { $2 }
391 ----------------------------------------------------------------------------
393 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
395 | '=' constrs1 { $2 }
397 constrs1 :: { [RdrNameConDecl] }
398 constrs1 : constr { [$1] }
399 | constr '|' constrs1 { $1 : $3 }
401 constr :: { RdrNameConDecl }
402 constr : src_loc ex_stuff data_name batypes { mkConDecl $3 $2 (VanillaCon $4) $1 }
403 | src_loc ex_stuff data_name '{' fields1 '}' { mkConDecl $3 $2 (RecCon $5) $1 }
404 -- We use "data_fs" so as to include ()
406 newtype_constr :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
407 newtype_constr : { [] }
408 | src_loc '=' ex_stuff data_name atype { [mkConDecl $4 $3 (NewCon $5 Nothing) $1] }
409 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
410 { [mkConDecl $4 $3 (NewCon $8 (Just $6)) $1] }
412 ex_stuff :: { ([HsTyVar RdrName], RdrNameContext) }
413 ex_stuff : { ([],[]) }
414 | '__forall' forall context '=>' { ($2,$3) }
416 batypes :: { [RdrNameBangType] }
418 | batype batypes { $1 : $2 }
420 batype :: { RdrNameBangType }
421 batype : atype { Unbanged $1 }
422 | '!' atype { Banged $2 }
423 | '!' '!' atype { Unpacked $3 }
425 fields1 :: { [([RdrName], RdrNameBangType)] }
426 fields1 : field { [$1] }
427 | field ',' fields1 { $1 : $3 }
429 field :: { ([RdrName], RdrNameBangType) }
430 field : var_names1 '::' type { ($1, Unbanged $3) }
431 | var_names1 '::' '!' type { ($1, Banged $4) }
432 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
433 --------------------------------------------------------------------------
435 type :: { RdrNameHsType }
436 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
437 | '__forall' forall context '=>' type
438 { mkHsForAllTy (Just $2) $3 $5 }
439 | btype '->' type { MonoFunTy $1 $3 }
442 fuall :: { [RdrName] }
443 fuall : '[' uv_bndrs ']' { $2 }
445 forall :: { [HsTyVar RdrName] }
446 forall : '[' tv_bndrs ']' { $2 }
448 context :: { RdrNameContext }
450 | '{' context_list1 '}' { $2 }
452 context_list1 :: { RdrNameContext }
453 context_list1 : class { [$1] }
454 | class ',' context_list1 { $1 : $3 }
456 class :: { HsPred RdrName }
457 class : qcls_name atypes { (HsPClass $1 $2) }
458 | ipvar_name '::' type { (HsPIParam $1 $3) }
460 types0 :: { [RdrNameHsType] {- Zero or more -} }
461 types0 : {- empty -} { [ ] }
465 types2 :: { [RdrNameHsType] {- Two or more -} }
466 types2 : type ',' type { [$1,$3] }
467 | type ',' types2 { $1 : $3 }
469 btype :: { RdrNameHsType }
471 | btype atype { MonoTyApp $1 $2 }
472 | '__u' usage atype { MonoUsgTy $2 $3 }
474 usage :: { MonoUsageAnn RdrName }
475 usage : '-' { MonoUsOnce }
477 | uv_name { MonoUsVar $1 }
479 atype :: { RdrNameHsType }
480 atype : qtc_name { MonoTyVar $1 }
481 | tv_name { MonoTyVar $1 }
482 | '(' types2 ')' { MonoTupleTy $2 True{-boxed-} }
483 | '(#' types0 '#)' { MonoTupleTy $2 False{-unboxed-} }
484 | '[' type ']' { MonoListTy $2 }
485 | '{' qcls_name atypes '}' { MonoDictTy $2 $3 }
486 | '{' ipvar_name '::' type '}' { MonoIParamTy $2 $4 }
487 | '(' type ')' { $2 }
489 -- This one is dealt with via qtc_name
490 -- | '(' ')' { MonoTupleTy [] True }
492 atypes :: { [RdrNameHsType] {- Zero or more -} }
494 | atype atypes { $1 : $2 }
495 ---------------------------------------------------------------------
496 mod_fs :: { EncodedFS }
499 mod_name :: { ModuleName }
500 : mod_fs { mkSysModuleFS $1 }
503 ---------------------------------------------------
504 var_fs :: { EncodedFS }
507 | 'as' { SLIT("as") }
508 | 'qualified' { SLIT("qualified") }
509 | 'hiding' { SLIT("hiding") }
510 | 'forall' { SLIT("forall") }
511 | 'foreign' { SLIT("foreign") }
512 | 'export' { SLIT("export") }
513 | 'label' { SLIT("label") }
514 | 'dynamic' { SLIT("dynamic") }
515 | 'unsafe' { SLIT("unsafe") }
516 | 'with' { SLIT("with") }
518 qvar_fs :: { (EncodedFS, EncodedFS) }
522 var_occ :: { OccName }
523 : var_fs { mkSysOccFS varName $1 }
525 var_name :: { RdrName }
526 var_name : var_occ { mkRdrUnqual $1 }
528 qvar_name :: { RdrName }
529 qvar_name : var_name { $1 }
530 | qvar_fs { mkSysQual varName $1 }
532 ipvar_name :: { RdrName }
533 : IPVARID { mkSysUnqual ipName (tailFS $1) }
535 var_names :: { [RdrName] }
537 | var_name var_names { $1 : $2 }
539 var_names1 :: { [RdrName] }
540 var_names1 : var_name var_names { $1 : $2 }
542 ---------------------------------------------------
543 -- For some bizarre reason,
544 -- (,,,) is dealt with by the parser
545 -- Foo.(,,,) is dealt with by the lexer
548 data_fs :: { EncodedFS }
552 qdata_fs :: { (EncodedFS, EncodedFS) }
556 data_occ :: { OccName }
557 : data_fs { mkSysOccFS dataName $1 }
559 data_name :: { RdrName }
560 : data_occ { mkRdrUnqual $1 }
562 qdata_name :: { RdrName }
563 qdata_name : data_name { $1 }
564 | qdata_fs { mkSysQual dataName $1 }
566 qdata_names :: { [RdrName] }
568 | qdata_name qdata_names { $1 : $2 }
570 var_or_data_name :: { RdrName }
574 ---------------------------------------------------
575 tc_fs :: { EncodedFS }
578 tc_occ :: { OccName }
579 : tc_fs { mkSysOccFS tcName $1 }
581 tc_name :: { RdrName }
582 : tc_occ { mkRdrUnqual $1 }
584 qtc_name :: { RdrName }
586 | qdata_fs { mkSysQual tcName $1 }
588 ---------------------------------------------------
589 cls_name :: { RdrName }
590 : data_fs { mkSysUnqual clsName $1 }
592 qcls_name :: { RdrName }
594 | qdata_fs { mkSysQual clsName $1 }
596 ---------------------------------------------------
597 uv_name :: { RdrName }
598 : VARID { mkSysUnqual uvName $1 }
600 uv_bndr :: { RdrName }
603 uv_bndrs :: { [RdrName] }
605 | uv_bndr uv_bndrs { $1 : $2 }
607 ---------------------------------------------------
608 tv_name :: { RdrName }
609 : VARID { mkSysUnqual tvName $1 }
610 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
612 tv_bndr :: { HsTyVar RdrName }
613 : tv_name '::' akind { IfaceTyVar $1 $3 }
614 | tv_name { IfaceTyVar $1 boxedTypeKind }
616 tv_bndrs :: { [HsTyVar RdrName] }
618 | tv_bndr tv_bndrs { $1 : $2 }
620 ---------------------------------------------------
621 fds :: { [([RdrName], [RdrName])] }
623 | '|' fds1 { reverse $2 }
625 fds1 :: { [([RdrName], [RdrName])] }
626 : fds1 ',' fd { $3 : $1 }
629 fd :: { ([RdrName], [RdrName]) }
630 : varids0 '->' varids0 { (reverse $1, reverse $3) }
632 varids0 :: { [RdrName] }
634 | varids0 tv_name { $2 : $1 }
636 ---------------------------------------------------
639 | akind '->' kind { mkArrowKind $1 $3 }
642 : VARSYM { if $1 == SLIT("*") then
644 else if $1 == SLIT("?") then
646 else panic "ParseInterface: akind"
648 | '(' kind ')' { $2 }
650 --------------------------------------------------------------------------
652 id_info :: { [HsIdInfo RdrName] }
654 | id_info_item id_info { $1 : $2 }
656 id_info_item :: { HsIdInfo RdrName }
657 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
658 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
659 | '__M' { HsCprInfo $1 }
660 | '__S' { HsStrictness (HsStrictnessInfo $1) }
661 | '__C' { HsNoCafRefs }
662 | '__P' qvar_name { HsWorker $2 }
664 inline_prag :: { InlinePragInfo }
665 : {- empty -} { NoInlinePragInfo }
666 | '[' INTEGER ']' { IMustNotBeINLINEd True (Just (fromInteger $2)) } -- INLINE n
667 | '[' '!' INTEGER ']' { IMustNotBeINLINEd False (Just (fromInteger $3)) } -- NOINLINE n
669 -------------------------------------------------------
670 core_expr :: { UfExpr RdrName }
671 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
672 | 'case' core_expr 'of' var_name
673 '{' core_alts '}' { UfCase $2 $4 $6 }
675 | 'let' '{' core_val_bndr '=' core_expr
676 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
677 | '__letrec' '{' rec_binds '}'
678 'in' core_expr { UfLet (UfRec $3) $6 }
680 | con_or_primop '{' core_args '}' { UfCon $1 $3 }
681 | '__litlit' STRING atype { UfCon (UfLitLitCon $2 $3) [] }
683 | '__inline_me' core_expr { UfNote UfInlineMe $2 }
684 | '__inline_call' core_expr { UfNote UfInlineCall $2 }
685 | '__coerce' atype core_expr { UfNote (UfCoerce $2) $3 }
686 | scc core_expr { UfNote (UfSCC $1) $2 }
689 fexpr :: { UfExpr RdrName }
690 fexpr : fexpr core_arg { UfApp $1 $2 }
693 core_arg :: { UfExpr RdrName }
694 : '@' atype { UfType $2 }
697 core_args :: { [UfExpr RdrName] }
699 | core_arg core_args { $1 : $2 }
701 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
702 core_aexpr : qvar_name { UfVar $1 }
704 | qdata_name { UfVar $1 }
705 -- This one means that e.g. "True" will parse as
706 -- (UfVar True_Id) rather than (UfCon True_Con []).
707 -- No big deal; it'll be inlined in a jiffy. I tried
708 -- parsing it to (Con con []) directly, but got bitten
709 -- when a real constructor Id showed up in an interface
710 -- file. As usual, a hack bites you in the end.
711 -- If you want to get a UfCon, then use the
712 -- curly-bracket notation (True {}).
714 | core_lit { UfCon (UfLitCon $1) [] }
715 | '(' core_expr ')' { $2 }
716 | '(' comma_exprs2 ')' { UfTuple (mkTupConRdrName (length $2)) $2 }
717 | '(#' comma_exprs0 '#)' { UfTuple (mkUbxTupConRdrName (length $2)) $2 }
719 -- This one is dealt with by qdata_name: see above comments
720 -- | '(' ')' { UfTuple (mkTupConRdrName 0) [] }
722 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
723 comma_exprs0 : {- empty -} { [ ] }
724 | core_expr { [ $1 ] }
725 | comma_exprs2 { $1 }
727 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
728 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
729 | core_expr ',' comma_exprs2 { $1 : $3 }
731 con_or_primop :: { UfCon RdrName }
732 con_or_primop : qdata_name { UfDataCon $1 }
733 | qvar_name { UfPrimOp $1 }
734 | '__ccall' ccall_string { let
735 (is_dyn, is_casm, may_gc) = $1
737 UfCCallOp $2 is_dyn is_casm may_gc
740 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
742 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
744 core_alts :: { [UfAlt RdrName] }
746 | core_alt ';' core_alts { $1 : $3 }
748 core_alt :: { UfAlt RdrName }
749 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
751 core_pat :: { (UfCon RdrName, [RdrName]) }
752 core_pat : core_lit { (UfLitCon $1, []) }
753 | '__litlit' STRING atype { (UfLitLitCon $2 $3, []) }
754 | qdata_name core_pat_names { (UfDataCon $1, $2) }
755 | '(' comma_var_names1 ')' { (UfDataCon (mkTupConRdrName (length $2)), $2) }
756 | '(#' comma_var_names1 '#)' { (UfDataCon (mkUbxTupConRdrName (length $2)), $2) }
757 | '__DEFAULT' { (UfDefault, []) }
758 | '(' core_pat ')' { $2 }
760 core_pat_names :: { [RdrName] }
761 core_pat_names : { [] }
762 | core_pat_name core_pat_names { $1 : $2 }
764 -- Tyvar names and variable names live in different name spaces
765 -- so they need to be signalled separately. But we don't record
766 -- types or kinds in a pattern; we work that out from the type
767 -- of the case scrutinee
768 core_pat_name :: { RdrName }
769 core_pat_name : var_name { $1 }
772 comma_var_names1 :: { [RdrName] } -- One or more
773 comma_var_names1 : var_name { [$1] }
774 | var_name ',' comma_var_names1 { $1 : $3 }
776 core_lit :: { Literal }
777 core_lit : integer { mkMachInt_safe $1 }
778 | CHAR { MachChar $1 }
779 | STRING { MachStr $1 }
780 | '__string' STRING { NoRepStr $2 (panic "NoRepStr type") }
781 | rational { MachDouble $1 }
782 | '__float' rational { MachFloat $2 }
784 | '__integer' integer { NoRepInteger $2 (panic "NoRepInteger type")
785 -- The type checker will add the types
788 | '__rational' integer integer { NoRepRational ($2 % $3)
789 (panic "NoRepRational type")
790 -- The type checker will add the type
793 | '__addr' integer { MachAddr $2 }
795 integer :: { Integer }
797 | '-' INTEGER { (-$2) }
799 rational :: { Rational }
801 | '-' RATIONAL { (-$2) }
803 core_bndr :: { UfBinder RdrName }
804 core_bndr : core_val_bndr { $1 }
805 | core_tv_bndr { $1 }
807 core_bndrs :: { [UfBinder RdrName] }
809 | core_bndr core_bndrs { $1 : $2 }
811 core_val_bndr :: { UfBinder RdrName }
812 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
814 core_tv_bndr :: { UfBinder RdrName }
815 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
816 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
818 ccall_string :: { FAST_STRING }
824 ------------------------------------------------------------------------
825 scc :: { CostCentre }
826 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
827 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
828 { NormalCC { cc_name = $3, cc_mod = $4,
829 cc_is_dupd = $5, cc_is_caf = $6 } }
831 cc_name :: { EncodedFS }
835 cc_dup :: { IsDupdCC }
836 cc_dup : { OriginalCC }
839 cc_caf :: { IsCafCC }
843 -------------------------------------------------------------------
845 src_loc :: { SrcLoc }
846 src_loc : {% getSrcLocP }
848 checkVersion :: { () }
849 : {-empty-} {% checkVersion Nothing }
850 | INTEGER {% checkVersion (Just (fromInteger $1)) }
852 -------------------------------------------------------------------
857 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
859 data IfaceStuff = PIface EncodedFS{-.hi module name-} ParsedIface
860 | PIdInfo [HsIdInfo RdrName]
861 | PType RdrNameHsType
862 | PRules [RdrNameRuleDecl]
863 | PDeprecs [RdrNameDeprecation]
865 mkConDecl name (ex_tvs, ex_ctxt) details loc = ConDecl name ex_tvs ex_ctxt details loc