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 )
47 %monad { P }{ thenP }{ returnP }
48 %lexer { lexer } { ITeof }
51 'case' { ITcase } -- Haskell keywords
54 'default' { ITdefault }
55 'deriving' { ITderiving }
64 'instance' { ITinstance }
67 'newtype' { ITnewtype }
73 'qualified' { ITqualified }
76 'forall' { ITforall } -- GHC extension keywords
77 'foreign' { ITforeign }
80 'dynamic' { ITdynamic }
84 '__interface' { ITinterface } -- interface keywords
85 '__export' { IT__export }
86 '__forall' { IT__forall }
87 '__depends' { ITdepends }
88 '__letrec' { ITletrec }
89 '__coerce' { ITcoerce }
90 '__inline_call'{ ITinlineCall }
91 '__inline_me' { ITinlineMe }
92 '__DEFAULT' { ITdefaultbranch }
94 '__integer' { ITinteger_lit }
95 '__float' { ITfloat_lit }
96 '__rational' { ITrational_lit }
97 '__addr' { ITaddr_lit }
98 '__litlit' { ITlit_lit }
99 '__string' { ITstring_lit }
100 '__ccall' { ITccall $$ }
102 '__sccC' { ITsccAllCafs }
105 '__fuall' { ITfuall }
108 '__P' { ITspecialise }
110 '__U' { ITunfold $$ }
111 '__S' { ITstrict $$ }
113 '__D' { ITdeprecated }
114 '__M' { ITcprinfo $$ }
116 '..' { ITdotdot } -- reserved symbols
129 '/\\' { ITbiglam } -- GHC-extension symbols
131 '{' { ITocurly } -- special symbols
142 VARID { ITvarid $$ } -- identifiers
144 VARSYM { ITvarsym $$ }
145 CONSYM { ITconsym $$ }
146 QVARID { ITqvarid $$ }
147 QCONID { ITqconid $$ }
148 QVARSYM { ITqvarsym $$ }
149 QCONSYM { ITqconsym $$ }
151 IPVARID { ITipvarid $$ } -- GHC extension
153 PRAGMA { ITpragma $$ }
156 STRING { ITstring $$ }
157 INTEGER { ITinteger $$ }
158 RATIONAL { ITrational $$ }
159 CLITLIT { ITlitlit $$ }
161 UNKNOWN { ITunknown $$ }
164 -- iface_stuff is the main production.
165 -- It recognises (a) a whole interface file
166 -- (b) a type (so that type sigs can be parsed lazily)
167 -- (c) the IdInfo part of a signature (same reason)
169 iface_stuff :: { IfaceStuff }
170 iface_stuff : iface { let (nm, iff) = $1 in PIface nm iff }
172 | id_info { PIdInfo $1 }
173 | '__R' rules { PRules $2 }
174 | '__D' deprecs { PDeprecs $2 }
177 iface :: { (ModuleName, ParsedIface) }
178 iface : '__interface' mod_fs INTEGER orphans checkVersion 'where'
184 { ( $2 -- Module name
186 pi_mod = fromInteger $3, -- Module version
188 pi_exports = $7, -- Exports
189 pi_usages = $8, -- Usages
190 pi_insts = $9, -- Local instances
191 pi_decls = $10, -- Decls
192 pi_rules = fst $11, -- Rules
193 pi_deprecs = snd $11 -- Deprecations
196 --------------------------------------------------------------------------
198 import_part :: { [ImportVersion OccName] }
200 | import_part import_decl { $2 : $1 }
202 import_decl :: { ImportVersion OccName }
203 import_decl : 'import' mod_fs INTEGER orphans whats_imported ';'
204 { (mkSysModuleFS $2, fromInteger $3, $4, $5) }
205 -- import Foo 3 :: a 1 b 3 c 7 ; means import a,b,c from Foo
206 -- import Foo 3 ; means import all of Foo
207 -- import Foo 3 ! :: ...stuff... ; the ! means that Foo contains orphans
209 orphans :: { WhetherHasOrphans }
213 whats_imported :: { WhatsImported OccName }
214 whats_imported : { Everything }
215 | '::' name_version_pairs { Specifically $2 }
217 name_version_pairs :: { [LocalVersion OccName] }
218 name_version_pairs : { [] }
219 | name_version_pair name_version_pairs { $1 : $2 }
221 name_version_pair :: { LocalVersion OccName }
222 name_version_pair : var_occ INTEGER { ($1, fromInteger $2) }
223 | tc_occ INTEGER { ($1, fromInteger $2) }
226 --------------------------------------------------------------------------
228 exports_part :: { [ExportItem] }
229 exports_part : { [] }
230 | exports_part '__export'
231 mod_fs entities ';' { (mkSysModuleFS $3, $4) : $1 }
233 entities :: { [RdrAvailInfo] }
235 | entity entities { $1 : $2 }
237 entity :: { RdrAvailInfo }
238 entity : tc_occ { AvailTC $1 [$1] }
239 | var_occ { Avail $1 }
240 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
241 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
243 stuff_inside :: { [OccName] }
244 stuff_inside : '{' val_occs '}' { $2 }
246 val_occ :: { OccName }
250 val_occs :: { [OccName] }
252 | val_occ val_occs { $1 : $2 }
255 --------------------------------------------------------------------------
257 fixity :: { FixityDirection }
258 fixity : 'infixl' { InfixL }
259 | 'infixr' { InfixR }
263 mb_fix : {-nothing-} { 9 }
264 | INTEGER { (fromInteger $1) }
266 -----------------------------------------------------------------------------
268 csigs :: { [RdrNameSig] }
270 | 'where' '{' csigs1 '}' { $3 }
272 csigs1 :: { [RdrNameSig] }
273 csigs1 : csig { [$1] }
274 | csig ';' csigs1 { $1 : $3 }
276 csig :: { RdrNameSig }
277 csig : src_loc var_name '::' type { mkClassOpSig False $2 $4 $1 }
278 | src_loc var_name '=' '::' type { mkClassOpSig True $2 $5 $1 }
280 --------------------------------------------------------------------------
282 instance_decl_part :: { [RdrNameInstDecl] }
283 instance_decl_part : {- empty -} { [] }
284 | instance_decl_part inst_decl { $2 : $1 }
286 inst_decl :: { RdrNameInstDecl }
287 inst_decl : src_loc 'instance' type '=' var_name ';'
289 EmptyMonoBinds {- No bindings -}
290 [] {- No user pragmas -}
295 --------------------------------------------------------------------------
297 decls_part :: { [(Version, RdrNameHsDecl)] }
300 | decls_part version decl ';' { ($2,$3):$1 }
302 decl :: { RdrNameHsDecl }
303 decl : src_loc var_name '::' type maybe_idinfo
304 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
305 | src_loc 'type' tc_name tv_bndrs '=' type
306 { TyClD (TySynonym $3 $4 $6 $1) }
307 | src_loc 'data' decl_context tc_name tv_bndrs constrs
308 { TyClD (TyData DataType $3 $4 $5 $6 Nothing noDataPragmas $1) }
309 | src_loc 'newtype' decl_context tc_name tv_bndrs newtype_constr
310 { TyClD (TyData NewType $3 $4 $5 $6 Nothing noDataPragmas $1) }
311 | src_loc 'class' decl_context tc_name tv_bndrs fds csigs
312 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds
314 | src_loc fixity mb_fix var_or_data_name
315 { FixD (FixitySig $4 (Fixity $3 $2) $1) }
317 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
318 maybe_idinfo : {- empty -} { \_ -> [] }
319 | pragma { \x -> case $1 of
320 POk _ (PIdInfo id_info) -> id_info
322 pprPanic "IdInfo parse failed"
326 pragma :: { ParseResult IfaceStuff }
327 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
333 -----------------------------------------------------------------------------
335 rules_and_deprecs :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
336 rules_and_deprecs : {- empty -} { ([], []) }
337 | rules_and_deprecs rule_or_deprec
339 append2 (xs1,ys1) (xs2,ys2) =
340 (xs1 `app` xs2, ys1 `app` ys2)
341 xs `app` [] = xs -- performance paranoia
342 xs `app` ys = xs ++ ys
346 rule_or_deprec :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
347 rule_or_deprec : pragma { case $1 of
348 POk _ (PRules rules) -> (rules,[])
349 POk _ (PDeprecs deprecs) -> ([],deprecs)
350 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
353 -----------------------------------------------------------------------------
355 rules :: { [RdrNameRuleDecl] }
357 | rule ';' rules { $1:$3 }
359 rule :: { RdrNameRuleDecl }
360 rule : src_loc STRING rule_forall qvar_name
361 core_args '=' core_expr { IfaceRuleDecl $4 (UfRuleBody $2 $3 $5 $7) $1 }
363 rule_forall :: { [UfBinder RdrName] }
364 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
366 -----------------------------------------------------------------------------
368 deprecs :: { [RdrNameDeprecation] }
369 deprecs : {- empty -} { [] }
370 | deprecs deprec ';' { $2 : $1 }
372 deprec :: { RdrNameDeprecation }
373 deprec : STRING { Deprecation (IEModuleContents undefined) $1 }
374 | deprec_name STRING { Deprecation $1 $2 }
376 -- SUP: TEMPORARY HACK
377 deprec_name :: { RdrNameIE }
378 : var_name { IEVar $1 }
379 | data_name { IEThingAbs $1 }
381 -----------------------------------------------------------------------------
383 version :: { Version }
384 version : INTEGER { fromInteger $1 }
386 decl_context :: { RdrNameContext }
387 decl_context : { [] }
388 | '{' context_list1 '}' '=>' { $2 }
390 ----------------------------------------------------------------------------
392 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
394 | '=' constrs1 { $2 }
396 constrs1 :: { [RdrNameConDecl] }
397 constrs1 : constr { [$1] }
398 | constr '|' constrs1 { $1 : $3 }
400 constr :: { RdrNameConDecl }
401 constr : src_loc ex_stuff data_name batypes { mkConDecl $3 $2 (VanillaCon $4) $1 }
402 | src_loc ex_stuff data_name '{' fields1 '}' { mkConDecl $3 $2 (RecCon $5) $1 }
403 -- We use "data_fs" so as to include ()
405 newtype_constr :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
406 newtype_constr : { [] }
407 | src_loc '=' ex_stuff data_name atype { [mkConDecl $4 $3 (NewCon $5 Nothing) $1] }
408 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
409 { [mkConDecl $4 $3 (NewCon $8 (Just $6)) $1] }
411 ex_stuff :: { ([HsTyVar RdrName], RdrNameContext) }
412 ex_stuff : { ([],[]) }
413 | '__forall' forall context '=>' { ($2,$3) }
415 batypes :: { [RdrNameBangType] }
417 | batype batypes { $1 : $2 }
419 batype :: { RdrNameBangType }
420 batype : atype { Unbanged $1 }
421 | '!' atype { Banged $2 }
422 | '!' '!' atype { Unpacked $3 }
424 fields1 :: { [([RdrName], RdrNameBangType)] }
425 fields1 : field { [$1] }
426 | field ',' fields1 { $1 : $3 }
428 field :: { ([RdrName], RdrNameBangType) }
429 field : var_names1 '::' type { ($1, Unbanged $3) }
430 | var_names1 '::' '!' type { ($1, Banged $4) }
431 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
432 --------------------------------------------------------------------------
434 type :: { RdrNameHsType }
435 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
436 | '__forall' forall context '=>' type
437 { mkHsForAllTy (Just $2) $3 $5 }
438 | btype '->' type { MonoFunTy $1 $3 }
441 fuall :: { [RdrName] }
442 fuall : '[' uv_bndrs ']' { $2 }
444 forall :: { [HsTyVar RdrName] }
445 forall : '[' tv_bndrs ']' { $2 }
447 context :: { RdrNameContext }
449 | '{' context_list1 '}' { $2 }
451 context_list1 :: { RdrNameContext }
452 context_list1 : class { [$1] }
453 | class ',' context_list1 { $1 : $3 }
455 class :: { HsPred RdrName }
456 class : qcls_name atypes { (HsPClass $1 $2) }
457 | IPVARID '::' type { (HsPIParam (mkSysUnqual ipName $1) $3) }
459 types0 :: { [RdrNameHsType] {- Zero or more -} }
460 types0 : {- empty -} { [ ] }
464 types2 :: { [RdrNameHsType] {- Two or more -} }
465 types2 : type ',' type { [$1,$3] }
466 | type ',' types2 { $1 : $3 }
468 btype :: { RdrNameHsType }
470 | btype atype { MonoTyApp $1 $2 }
471 | '__u' usage atype { MonoUsgTy $2 $3 }
473 usage :: { MonoUsageAnn RdrName }
474 usage : '-' { MonoUsOnce }
476 | uv_name { MonoUsVar $1 }
478 atype :: { RdrNameHsType }
479 atype : qtc_name { MonoTyVar $1 }
480 | tv_name { MonoTyVar $1 }
481 | '(' types2 ')' { MonoTupleTy $2 True{-boxed-} }
482 | '(#' types0 '#)' { MonoTupleTy $2 False{-unboxed-} }
483 | '[' type ']' { MonoListTy $2 }
484 | '{' qcls_name atypes '}' { MonoDictTy $2 $3 }
485 | '{' IPVARID '::' type '}' { MonoIParamTy (mkSysUnqual ipName $2) $4 }
486 | '(' type ')' { $2 }
488 -- This one is dealt with via qtc_name
489 -- | '(' ')' { MonoTupleTy [] True }
491 atypes :: { [RdrNameHsType] {- Zero or more -} }
493 | atype atypes { $1 : $2 }
494 ---------------------------------------------------------------------
495 mod_fs :: { EncodedFS }
498 mod_name :: { ModuleName }
499 : mod_fs { mkSysModuleFS $1 }
502 ---------------------------------------------------
503 var_fs :: { EncodedFS }
506 | 'as' { SLIT("as") }
507 | 'qualified' { SLIT("qualified") }
508 | 'hiding' { SLIT("hiding") }
509 | 'forall' { SLIT("forall") }
510 | 'foreign' { SLIT("foreign") }
511 | 'export' { SLIT("export") }
512 | 'label' { SLIT("label") }
513 | 'dynamic' { SLIT("dynamic") }
514 | 'unsafe' { SLIT("unsafe") }
515 | 'with' { SLIT("with") }
517 qvar_fs :: { (EncodedFS, EncodedFS) }
521 var_occ :: { OccName }
522 : var_fs { mkSysOccFS varName $1 }
524 var_name :: { RdrName }
525 var_name : var_occ { mkRdrUnqual $1 }
527 qvar_name :: { RdrName }
528 qvar_name : var_name { $1 }
529 | qvar_fs { mkSysQual varName $1 }
531 var_names :: { [RdrName] }
533 | var_name var_names { $1 : $2 }
535 var_names1 :: { [RdrName] }
536 var_names1 : var_name var_names { $1 : $2 }
538 ---------------------------------------------------
539 -- For some bizarre reason,
540 -- (,,,) is dealt with by the parser
541 -- Foo.(,,,) is dealt with by the lexer
544 data_fs :: { EncodedFS }
548 qdata_fs :: { (EncodedFS, EncodedFS) }
552 data_occ :: { OccName }
553 : data_fs { mkSysOccFS dataName $1 }
555 data_name :: { RdrName }
556 : data_occ { mkRdrUnqual $1 }
558 qdata_name :: { RdrName }
559 qdata_name : data_name { $1 }
560 | qdata_fs { mkSysQual dataName $1 }
562 qdata_names :: { [RdrName] }
564 | qdata_name qdata_names { $1 : $2 }
566 var_or_data_name :: { RdrName }
570 ---------------------------------------------------
571 tc_fs :: { EncodedFS }
574 tc_occ :: { OccName }
575 : tc_fs { mkSysOccFS tcName $1 }
577 tc_name :: { RdrName }
578 : tc_occ { mkRdrUnqual $1 }
580 qtc_name :: { RdrName }
582 | qdata_fs { mkSysQual tcName $1 }
584 ---------------------------------------------------
585 cls_name :: { RdrName }
586 : data_fs { mkSysUnqual clsName $1 }
588 qcls_name :: { RdrName }
590 | qdata_fs { mkSysQual clsName $1 }
592 ---------------------------------------------------
593 uv_name :: { RdrName }
594 : VARID { mkSysUnqual uvName $1 }
596 uv_bndr :: { RdrName }
599 uv_bndrs :: { [RdrName] }
601 | uv_bndr uv_bndrs { $1 : $2 }
603 ---------------------------------------------------
604 tv_name :: { RdrName }
605 : VARID { mkSysUnqual tvName $1 }
606 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
608 tv_bndr :: { HsTyVar RdrName }
609 : tv_name '::' akind { IfaceTyVar $1 $3 }
610 | tv_name { IfaceTyVar $1 boxedTypeKind }
612 tv_bndrs :: { [HsTyVar RdrName] }
614 | tv_bndr tv_bndrs { $1 : $2 }
616 ---------------------------------------------------
617 fds :: { [([RdrName], [RdrName])] }
619 | '|' fds1 { reverse $2 }
621 fds1 :: { [([RdrName], [RdrName])] }
622 : fds1 ',' fd { $3 : $1 }
625 fd :: { ([RdrName], [RdrName]) }
626 : varids0 '->' varids0 { (reverse $1, reverse $3) }
628 varids0 :: { [RdrName] }
630 | varids0 tv_name { $2 : $1 }
632 ---------------------------------------------------
635 | akind '->' kind { mkArrowKind $1 $3 }
638 : VARSYM { if $1 == SLIT("*") then
640 else if $1 == SLIT("?") then
642 else panic "ParseInterface: akind"
644 | '(' kind ')' { $2 }
646 --------------------------------------------------------------------------
648 id_info :: { [HsIdInfo RdrName] }
650 | id_info_item id_info { $1 : $2 }
652 id_info_item :: { HsIdInfo RdrName }
653 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
654 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
655 | '__M' { HsCprInfo $1 }
656 | '__S' { HsStrictness (HsStrictnessInfo $1) }
657 | '__C' { HsNoCafRefs }
658 | '__P' qvar_name { HsWorker $2 }
660 inline_prag :: { InlinePragInfo }
661 : {- empty -} { NoInlinePragInfo }
662 | '[' INTEGER ']' { IMustNotBeINLINEd True (Just (fromInteger $2)) } -- INLINE n
663 | '[' '!' INTEGER ']' { IMustNotBeINLINEd False (Just (fromInteger $3)) } -- NOINLINE n
665 -------------------------------------------------------
666 core_expr :: { UfExpr RdrName }
667 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
668 | 'case' core_expr 'of' var_name
669 '{' core_alts '}' { UfCase $2 $4 $6 }
671 | 'let' '{' core_val_bndr '=' core_expr
672 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
673 | '__letrec' '{' rec_binds '}'
674 'in' core_expr { UfLet (UfRec $3) $6 }
676 | con_or_primop '{' core_args '}' { UfCon $1 $3 }
677 | '__litlit' STRING atype { UfCon (UfLitLitCon $2 $3) [] }
679 | '__inline_me' core_expr { UfNote UfInlineMe $2 }
680 | '__inline_call' core_expr { UfNote UfInlineCall $2 }
681 | '__coerce' atype core_expr { UfNote (UfCoerce $2) $3 }
682 | scc core_expr { UfNote (UfSCC $1) $2 }
685 fexpr :: { UfExpr RdrName }
686 fexpr : fexpr core_arg { UfApp $1 $2 }
689 core_arg :: { UfExpr RdrName }
690 : '@' atype { UfType $2 }
693 core_args :: { [UfExpr RdrName] }
695 | core_arg core_args { $1 : $2 }
697 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
698 core_aexpr : qvar_name { UfVar $1 }
700 | qdata_name { UfVar $1 }
701 -- This one means that e.g. "True" will parse as
702 -- (UfVar True_Id) rather than (UfCon True_Con []).
703 -- No big deal; it'll be inlined in a jiffy. I tried
704 -- parsing it to (Con con []) directly, but got bitten
705 -- when a real constructor Id showed up in an interface
706 -- file. As usual, a hack bites you in the end.
707 -- If you want to get a UfCon, then use the
708 -- curly-bracket notation (True {}).
710 | core_lit { UfCon (UfLitCon $1) [] }
711 | '(' core_expr ')' { $2 }
712 | '(' comma_exprs2 ')' { UfTuple (mkTupConRdrName (length $2)) $2 }
713 | '(#' comma_exprs0 '#)' { UfTuple (mkUbxTupConRdrName (length $2)) $2 }
715 -- This one is dealt with by qdata_name: see above comments
716 -- | '(' ')' { UfTuple (mkTupConRdrName 0) [] }
718 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
719 comma_exprs0 : {- empty -} { [ ] }
720 | core_expr { [ $1 ] }
721 | comma_exprs2 { $1 }
723 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
724 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
725 | core_expr ',' comma_exprs2 { $1 : $3 }
727 con_or_primop :: { UfCon RdrName }
728 con_or_primop : qdata_name { UfDataCon $1 }
729 | qvar_name { UfPrimOp $1 }
730 | '__ccall' ccall_string { let
731 (is_dyn, is_casm, may_gc) = $1
733 UfCCallOp $2 is_dyn is_casm may_gc
736 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
738 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
740 core_alts :: { [UfAlt RdrName] }
742 | core_alt ';' core_alts { $1 : $3 }
744 core_alt :: { UfAlt RdrName }
745 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
747 core_pat :: { (UfCon RdrName, [RdrName]) }
748 core_pat : core_lit { (UfLitCon $1, []) }
749 | '__litlit' STRING atype { (UfLitLitCon $2 $3, []) }
750 | qdata_name core_pat_names { (UfDataCon $1, $2) }
751 | '(' comma_var_names1 ')' { (UfDataCon (mkTupConRdrName (length $2)), $2) }
752 | '(#' comma_var_names1 '#)' { (UfDataCon (mkUbxTupConRdrName (length $2)), $2) }
753 | '__DEFAULT' { (UfDefault, []) }
754 | '(' core_pat ')' { $2 }
756 core_pat_names :: { [RdrName] }
757 core_pat_names : { [] }
758 | core_pat_name core_pat_names { $1 : $2 }
760 -- Tyvar names and variable names live in different name spaces
761 -- so they need to be signalled separately. But we don't record
762 -- types or kinds in a pattern; we work that out from the type
763 -- of the case scrutinee
764 core_pat_name :: { RdrName }
765 core_pat_name : var_name { $1 }
768 comma_var_names1 :: { [RdrName] } -- One or more
769 comma_var_names1 : var_name { [$1] }
770 | var_name ',' comma_var_names1 { $1 : $3 }
772 core_lit :: { Literal }
773 core_lit : integer { mkMachInt_safe $1 }
774 | CHAR { MachChar $1 }
775 | STRING { MachStr $1 }
776 | '__string' STRING { NoRepStr $2 (panic "NoRepStr type") }
777 | rational { MachDouble $1 }
778 | '__float' rational { MachFloat $2 }
780 | '__integer' integer { NoRepInteger $2 (panic "NoRepInteger type")
781 -- The type checker will add the types
784 | '__rational' integer integer { NoRepRational ($2 % $3)
785 (panic "NoRepRational type")
786 -- The type checker will add the type
789 | '__addr' integer { MachAddr $2 }
791 integer :: { Integer }
793 | '-' INTEGER { (-$2) }
795 rational :: { Rational }
797 | '-' RATIONAL { (-$2) }
799 core_bndr :: { UfBinder RdrName }
800 core_bndr : core_val_bndr { $1 }
801 | core_tv_bndr { $1 }
803 core_bndrs :: { [UfBinder RdrName] }
805 | core_bndr core_bndrs { $1 : $2 }
807 core_val_bndr :: { UfBinder RdrName }
808 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
810 core_tv_bndr :: { UfBinder RdrName }
811 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
812 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
814 ccall_string :: { FAST_STRING }
820 ------------------------------------------------------------------------
821 scc :: { CostCentre }
822 : '__sccC' '{' mod_name STRING '}' { AllCafsCC $3 $4 }
823 | '__scc' '{' cc_name mod_name STRING cc_dup cc_caf '}'
824 { NormalCC { cc_name = $3, cc_mod = $4, cc_grp = $5,
825 cc_is_dupd = $6, cc_is_caf = $7 } }
827 cc_name :: { EncodedFS }
831 cc_dup :: { IsDupdCC }
832 cc_dup : { OriginalCC }
835 cc_caf :: { IsCafCC }
839 -------------------------------------------------------------------
841 src_loc :: { SrcLoc }
842 src_loc : {% getSrcLocP }
844 checkVersion :: { () }
845 : {-empty-} {% checkVersion Nothing }
846 | INTEGER {% checkVersion (Just (fromInteger $1)) }
848 -------------------------------------------------------------------
853 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
855 data IfaceStuff = PIface EncodedFS{-.hi module name-} ParsedIface
856 | PIdInfo [HsIdInfo RdrName]
857 | PType RdrNameHsType
858 | PRules [RdrNameRuleDecl]
859 | PDeprecs [RdrNameDeprecation]
861 mkConDecl name (ex_tvs, ex_ctxt) details loc = ConDecl name ex_tvs ex_ctxt details loc