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 Literal ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
11 import BasicTypes ( Fixity(..), FixityDirection(..),
12 NewOrData(..), Version
14 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
15 import CallConv ( cCallConv )
16 import HsPragmas ( noDataPragmas, noClassPragmas )
17 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind, UsageAnn(..) )
18 import IdInfo ( ArityInfo, exactArity, CprInfo(..), InlinePragInfo(..) )
19 import PrimOp ( CCall(..), CCallTarget(..) )
22 import RnMonad ( ImportVersion, LocalVersion, ParsedIface(..), WhatsImported(..),
23 RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..),
24 WhetherHasOrphans, IsBootInterface
26 import Bag ( emptyBag, unitBag, snocBag )
27 import FiniteMap ( emptyFM, unitFM, addToFM, plusFM, bagToFM, FiniteMap )
28 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual, mkRdrNameWkr )
29 import Name ( OccName, Provenance )
30 import OccName ( mkSysOccFS,
31 tcName, varName, ipName, dataName, clsName, tvName, uvName,
34 import Module ( ModuleName, mkSysModuleFS )
35 import PrelInfo ( mkTupConRdrName, mkUbxTupConRdrName )
36 import SrcLoc ( SrcLoc )
41 import FastString ( tailFS )
50 %monad { P }{ thenP }{ returnP }
51 %lexer { lexer } { ITeof }
55 'case' { ITcase } -- Haskell keywords
58 'default' { ITdefault }
59 'deriving' { ITderiving }
69 'instance' { ITinstance }
72 'newtype' { ITnewtype }
74 'qualified' { ITqualified }
78 --???? 'scc' { ITscc }
80 'forall' { ITforall } -- GHC extension keywords
81 'foreign' { ITforeign }
84 'dynamic' { ITdynamic }
87 'stdcall' { ITstdcallconv }
88 'ccall' { ITccallconv }
90 '__interface' { ITinterface } -- interface keywords
91 '__export' { IT__export }
92 '__depends' { ITdepends }
93 '__forall' { IT__forall }
94 '__letrec' { ITletrec }
95 '__coerce' { ITcoerce }
96 '__inline_me' { ITinlineMe }
97 '__inline_call'{ ITinlineCall }
98 '__DEFAULT' { ITdefaultbranch }
100 '__integer' { ITinteger_lit }
101 '__float' { ITfloat_lit }
102 '__word' { ITword_lit }
103 '__int64' { ITint64_lit }
104 '__word64' { ITword64_lit }
105 '__rational' { ITrational_lit }
106 '__addr' { ITaddr_lit }
107 '__litlit' { ITlit_lit }
108 '__string' { ITstring_lit }
109 '__ccall' { ITccall $$ }
111 '__sccC' { ITsccAllCafs }
114 '__fuall' { ITfuall }
117 '__P' { ITspecialise }
119 '__U' { ITunfold $$ }
120 '__S' { ITstrict $$ }
123 '__D' { ITdeprecated }
125 '..' { ITdotdot } -- reserved symbols
138 '/\\' { ITbiglam } -- GHC-extension symbols
140 '{' { ITocurly } -- special symbols
151 VARID { ITvarid $$ } -- identifiers
153 VARSYM { ITvarsym $$ }
154 CONSYM { ITconsym $$ }
155 QVARID { ITqvarid $$ }
156 QCONID { ITqconid $$ }
157 QVARSYM { ITqvarsym $$ }
158 QCONSYM { ITqconsym $$ }
160 IPVARID { ITipvarid $$ } -- GHC extension
162 PRAGMA { ITpragma $$ }
165 STRING { ITstring $$ }
166 INTEGER { ITinteger $$ }
167 RATIONAL { ITrational $$ }
168 CLITLIT { ITlitlit $$ }
170 UNKNOWN { ITunknown $$ }
173 -- iface_stuff is the main production.
174 -- It recognises (a) a whole interface file
175 -- (b) a type (so that type sigs can be parsed lazily)
176 -- (c) the IdInfo part of a signature (same reason)
178 iface_stuff :: { IfaceStuff }
179 iface_stuff : iface { let (nm, iff) = $1 in PIface nm iff }
181 | id_info { PIdInfo $1 }
182 | '__R' rules { PRules $2 }
183 | '__D' deprecs { PDeprecs $2 }
186 iface :: { (ModuleName, ParsedIface) }
187 iface : '__interface' mod_fs INTEGER orphans checkVersion 'where'
193 { ( $2 -- Module name
195 pi_mod = fromInteger $3, -- Module version
197 pi_exports = $7, -- Exports
198 pi_usages = $8, -- Usages
199 pi_insts = $9, -- Local instances
200 pi_decls = $10, -- Decls
201 pi_rules = fst $11, -- Rules
202 pi_deprecs = snd $11 -- Deprecations
205 --------------------------------------------------------------------------
207 import_part :: { [ImportVersion OccName] }
209 | import_part import_decl { $2 : $1 }
211 import_decl :: { ImportVersion OccName }
212 import_decl : 'import' mod_fs INTEGER orphans is_boot whats_imported ';'
213 { (mkSysModuleFS $2, fromInteger $3, $4, $5, $6) }
214 -- import Foo 3 :: a 1 b 3 c 7 ; means import a,b,c from Foo
215 -- import Foo 3 ; means import all of Foo
216 -- import Foo 3 ! @ :: ...stuff... ; the ! means that Foo contains orphans
217 -- and @ that Foo is a boot interface
219 orphans :: { WhetherHasOrphans }
223 is_boot :: { IsBootInterface }
227 whats_imported :: { WhatsImported OccName }
228 whats_imported : { Everything }
229 | '::' name_version_pairs { Specifically $2 }
231 name_version_pairs :: { [LocalVersion OccName] }
232 name_version_pairs : { [] }
233 | name_version_pair name_version_pairs { $1 : $2 }
235 name_version_pair :: { LocalVersion OccName }
236 name_version_pair : var_occ INTEGER { ($1, fromInteger $2) }
237 | tc_occ INTEGER { ($1, fromInteger $2) }
240 --------------------------------------------------------------------------
242 exports_part :: { [ExportItem] }
243 exports_part : { [] }
244 | exports_part '__export'
245 mod_fs entities ';' { (mkSysModuleFS $3, $4) : $1 }
247 entities :: { [RdrAvailInfo] }
249 | entity entities { $1 : $2 }
251 entity :: { RdrAvailInfo }
252 entity : tc_occ { AvailTC $1 [$1] }
253 | var_occ { Avail $1 }
254 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
255 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
257 stuff_inside :: { [OccName] }
258 stuff_inside : '{' val_occs '}' { $2 }
260 val_occ :: { OccName }
264 val_occs :: { [OccName] }
266 | val_occ val_occs { $1 : $2 }
269 --------------------------------------------------------------------------
271 fixity :: { FixityDirection }
272 fixity : 'infixl' { InfixL }
273 | 'infixr' { InfixR }
277 mb_fix : {-nothing-} { 9 }
278 | INTEGER { (fromInteger $1) }
280 -----------------------------------------------------------------------------
282 csigs :: { [RdrNameSig] }
284 | 'where' '{' csigs1 '}' { $3 }
286 csigs1 :: { [RdrNameSig] }
287 csigs1 : csig { [$1] }
288 | csig ';' csigs1 { $1 : $3 }
290 csig :: { RdrNameSig }
291 csig : src_loc var_name '::' type { mkClassOpSig False $2 $4 $1 }
292 | src_loc var_name '=' '::' type { mkClassOpSig True $2 $5 $1 }
294 --------------------------------------------------------------------------
296 instance_decl_part :: { [RdrNameInstDecl] }
297 instance_decl_part : {- empty -} { [] }
298 | instance_decl_part inst_decl { $2 : $1 }
300 inst_decl :: { RdrNameInstDecl }
301 inst_decl : src_loc 'instance' type '=' var_name ';'
303 EmptyMonoBinds {- No bindings -}
304 [] {- No user pragmas -}
309 --------------------------------------------------------------------------
311 decls_part :: { [(Version, RdrNameHsDecl)] }
314 | decls_part version decl ';' { ($2,$3):$1 }
316 decl :: { RdrNameHsDecl }
317 decl : src_loc var_name '::' type maybe_idinfo
318 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
319 | src_loc 'type' tc_name tv_bndrs '=' type
320 { TyClD (TySynonym $3 $4 $6 $1) }
321 | src_loc 'data' decl_context tc_name tv_bndrs constrs
322 { TyClD (TyData DataType $3 $4 $5 $6 Nothing noDataPragmas $1) }
323 | src_loc 'newtype' decl_context tc_name tv_bndrs newtype_constr
324 { TyClD (TyData NewType $3 $4 $5 $6 Nothing noDataPragmas $1) }
325 | src_loc 'class' decl_context tc_name tv_bndrs fds csigs
326 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds
328 | src_loc fixity mb_fix var_or_data_name
329 { FixD (FixitySig $4 (Fixity $3 $2) $1) }
331 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
332 maybe_idinfo : {- empty -} { \_ -> [] }
333 | pragma { \x -> case $1 of
334 POk _ (PIdInfo id_info) -> id_info
336 pprPanic "IdInfo parse failed"
340 pragma :: { ParseResult IfaceStuff }
341 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
347 -----------------------------------------------------------------------------
349 rules_and_deprecs :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
350 rules_and_deprecs : {- empty -} { ([], []) }
351 | rules_and_deprecs rule_or_deprec
353 append2 (xs1,ys1) (xs2,ys2) =
354 (xs1 `app` xs2, ys1 `app` ys2)
355 xs `app` [] = xs -- performance paranoia
356 xs `app` ys = xs ++ ys
360 rule_or_deprec :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
361 rule_or_deprec : pragma { case $1 of
362 POk _ (PRules rules) -> (rules,[])
363 POk _ (PDeprecs deprecs) -> ([],deprecs)
364 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
367 -----------------------------------------------------------------------------
369 rules :: { [RdrNameRuleDecl] }
371 | rule ';' rules { $1:$3 }
373 rule :: { RdrNameRuleDecl }
374 rule : src_loc STRING rule_forall qvar_name
375 core_args '=' core_expr { IfaceRuleDecl $4 (UfRuleBody $2 $3 $5 $7) $1 }
377 rule_forall :: { [UfBinder RdrName] }
378 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
380 -----------------------------------------------------------------------------
382 deprecs :: { [RdrNameDeprecation] }
383 deprecs : {- empty -} { [] }
384 | deprecs deprec ';' { $2 : $1 }
386 deprec :: { RdrNameDeprecation }
387 deprec : STRING { Deprecation (IEModuleContents undefined) $1 }
388 | deprec_name STRING { Deprecation $1 $2 }
390 -- SUP: TEMPORARY HACK
391 deprec_name :: { RdrNameIE }
392 : var_name { IEVar $1 }
393 | data_name { IEThingAbs $1 }
395 -----------------------------------------------------------------------------
397 version :: { Version }
398 version : INTEGER { fromInteger $1 }
400 decl_context :: { RdrNameContext }
401 decl_context : { [] }
402 | '{' context_list1 '}' '=>' { $2 }
404 ----------------------------------------------------------------------------
406 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
408 | '=' constrs1 { $2 }
410 constrs1 :: { [RdrNameConDecl] }
411 constrs1 : constr { [$1] }
412 | constr '|' constrs1 { $1 : $3 }
414 constr :: { RdrNameConDecl }
415 constr : src_loc ex_stuff data_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
416 | src_loc ex_stuff data_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
417 -- We use "data_fs" so as to include ()
419 newtype_constr :: { [RdrNameConDecl] {- Empty if handwritten abstract -} }
420 newtype_constr : { [] }
421 | src_loc '=' ex_stuff data_name atype { [mk_con_decl $4 $3 (NewCon $5 Nothing) $1] }
422 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
423 { [mk_con_decl $4 $3 (NewCon $8 (Just $6)) $1] }
425 ex_stuff :: { ([HsTyVar RdrName], RdrNameContext) }
426 ex_stuff : { ([],[]) }
427 | '__forall' forall context '=>' { ($2,$3) }
429 batypes :: { [RdrNameBangType] }
431 | batype batypes { $1 : $2 }
433 batype :: { RdrNameBangType }
434 batype : atype { Unbanged $1 }
435 | '!' atype { Banged $2 }
436 | '!' '!' atype { Unpacked $3 }
438 fields1 :: { [([RdrName], RdrNameBangType)] }
439 fields1 : field { [$1] }
440 | field ',' fields1 { $1 : $3 }
442 field :: { ([RdrName], RdrNameBangType) }
443 field : var_names1 '::' type { ($1, Unbanged $3) }
444 | var_names1 '::' '!' type { ($1, Banged $4) }
445 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
446 --------------------------------------------------------------------------
448 type :: { RdrNameHsType }
449 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
450 | '__forall' forall context '=>' type
451 { mkHsForAllTy (Just $2) $3 $5 }
452 | btype '->' type { MonoFunTy $1 $3 }
455 fuall :: { [RdrName] }
456 fuall : '[' uv_bndrs ']' { $2 }
458 forall :: { [HsTyVar RdrName] }
459 forall : '[' tv_bndrs ']' { $2 }
461 context :: { RdrNameContext }
463 | '{' context_list1 '}' { $2 }
465 context_list1 :: { RdrNameContext }
466 context_list1 : class { [$1] }
467 | class ',' context_list1 { $1 : $3 }
469 class :: { HsPred RdrName }
470 class : qcls_name atypes { (HsPClass $1 $2) }
471 | ipvar_name '::' type { (HsPIParam $1 $3) }
473 types0 :: { [RdrNameHsType] {- Zero or more -} }
474 types0 : {- empty -} { [ ] }
478 types2 :: { [RdrNameHsType] {- Two or more -} }
479 types2 : type ',' type { [$1,$3] }
480 | type ',' types2 { $1 : $3 }
482 btype :: { RdrNameHsType }
484 | btype atype { MonoTyApp $1 $2 }
485 | '__u' usage atype { MonoUsgTy $2 $3 }
487 usage :: { MonoUsageAnn RdrName }
488 usage : '-' { MonoUsOnce }
490 | uv_name { MonoUsVar $1 }
492 atype :: { RdrNameHsType }
493 atype : qtc_name { MonoTyVar $1 }
494 | tv_name { MonoTyVar $1 }
495 | '(' types2 ')' { MonoTupleTy $2 True{-boxed-} }
496 | '(#' types0 '#)' { MonoTupleTy $2 False{-unboxed-} }
497 | '[' type ']' { MonoListTy $2 }
498 | '{' qcls_name atypes '}' { MonoDictTy $2 $3 }
499 | '{' ipvar_name '::' type '}' { MonoIParamTy $2 $4 }
500 | '(' type ')' { $2 }
502 -- This one is dealt with via qtc_name
503 -- | '(' ')' { MonoTupleTy [] True }
505 atypes :: { [RdrNameHsType] {- Zero or more -} }
507 | atype atypes { $1 : $2 }
508 ---------------------------------------------------------------------
509 mod_fs :: { EncodedFS }
512 mod_name :: { ModuleName }
513 : mod_fs { mkSysModuleFS $1 }
516 ---------------------------------------------------
517 var_fs :: { EncodedFS }
520 | 'as' { SLIT("as") }
521 | 'qualified' { SLIT("qualified") }
522 | 'hiding' { SLIT("hiding") }
523 | 'forall' { SLIT("forall") }
524 | 'foreign' { SLIT("foreign") }
525 | 'export' { SLIT("export") }
526 | 'label' { SLIT("label") }
527 | 'dynamic' { SLIT("dynamic") }
528 | 'unsafe' { SLIT("unsafe") }
529 | 'with' { SLIT("with") }
530 | 'ccall' { SLIT("ccall") }
531 | 'stdcall' { SLIT("stdcall") }
533 qvar_fs :: { (EncodedFS, EncodedFS) }
537 var_occ :: { OccName }
538 : var_fs { mkSysOccFS varName $1 }
540 var_name :: { RdrName }
541 var_name : var_occ { mkRdrUnqual $1 }
543 qvar_name :: { RdrName }
544 qvar_name : var_name { $1 }
545 | qvar_fs { mkSysQual varName $1 }
547 ipvar_name :: { RdrName }
548 : IPVARID { mkSysUnqual ipName (tailFS $1) }
550 var_names :: { [RdrName] }
552 | var_name var_names { $1 : $2 }
554 var_names1 :: { [RdrName] }
555 var_names1 : var_name var_names { $1 : $2 }
557 ---------------------------------------------------
558 -- For some bizarre reason,
559 -- (,,,) is dealt with by the parser
560 -- Foo.(,,,) is dealt with by the lexer
563 data_fs :: { EncodedFS }
567 qdata_fs :: { (EncodedFS, EncodedFS) }
571 data_occ :: { OccName }
572 : data_fs { mkSysOccFS dataName $1 }
574 data_name :: { RdrName }
575 : data_occ { mkRdrUnqual $1 }
577 qdata_name :: { RdrName }
578 qdata_name : data_name { $1 }
579 | qdata_fs { mkSysQual dataName $1 }
581 qdata_names :: { [RdrName] }
583 | qdata_name qdata_names { $1 : $2 }
585 var_or_data_name :: { RdrName }
589 ---------------------------------------------------
590 tc_fs :: { EncodedFS }
593 tc_occ :: { OccName }
594 : tc_fs { mkSysOccFS tcName $1 }
596 tc_name :: { RdrName }
597 : tc_occ { mkRdrUnqual $1 }
599 qtc_name :: { RdrName }
601 | qdata_fs { mkSysQual tcName $1 }
603 ---------------------------------------------------
604 cls_name :: { RdrName }
605 : data_fs { mkSysUnqual clsName $1 }
607 qcls_name :: { RdrName }
609 | qdata_fs { mkSysQual clsName $1 }
611 ---------------------------------------------------
612 uv_name :: { RdrName }
613 : VARID { mkSysUnqual uvName $1 }
615 uv_bndr :: { RdrName }
618 uv_bndrs :: { [RdrName] }
620 | uv_bndr uv_bndrs { $1 : $2 }
622 ---------------------------------------------------
623 tv_name :: { RdrName }
624 : VARID { mkSysUnqual tvName $1 }
625 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
627 tv_bndr :: { HsTyVar RdrName }
628 : tv_name '::' akind { IfaceTyVar $1 $3 }
629 | tv_name { IfaceTyVar $1 boxedTypeKind }
631 tv_bndrs :: { [HsTyVar RdrName] }
633 | tv_bndr tv_bndrs { $1 : $2 }
635 ---------------------------------------------------
636 fds :: { [([RdrName], [RdrName])] }
638 | '|' fds1 { reverse $2 }
640 fds1 :: { [([RdrName], [RdrName])] }
641 : fds1 ',' fd { $3 : $1 }
644 fd :: { ([RdrName], [RdrName]) }
645 : varids0 '->' varids0 { (reverse $1, reverse $3) }
647 varids0 :: { [RdrName] }
649 | varids0 tv_name { $2 : $1 }
651 ---------------------------------------------------
654 | akind '->' kind { mkArrowKind $1 $3 }
657 : VARSYM { if $1 == SLIT("*") then
659 else if $1 == SLIT("?") then
661 else panic "ParseInterface: akind"
663 | '(' kind ')' { $2 }
665 --------------------------------------------------------------------------
667 id_info :: { [HsIdInfo RdrName] }
669 | id_info_item id_info { $1 : $2 }
671 id_info_item :: { HsIdInfo RdrName }
672 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
673 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
674 | '__M' { HsCprInfo }
675 | '__S' { HsStrictness (HsStrictnessInfo $1) }
676 | '__C' { HsNoCafRefs }
677 | '__P' qvar_name { HsWorker $2 }
679 inline_prag :: { InlinePragInfo }
680 : {- empty -} { NoInlinePragInfo }
681 | '[' INTEGER ']' { IMustNotBeINLINEd True (Just (fromInteger $2)) } -- INLINE n
682 | '[' '!' INTEGER ']' { IMustNotBeINLINEd False (Just (fromInteger $3)) } -- NOINLINE n
684 -------------------------------------------------------
685 core_expr :: { UfExpr RdrName }
686 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
687 | 'case' core_expr 'of' var_name
688 '{' core_alts '}' { UfCase $2 $4 $6 }
690 | 'let' '{' core_val_bndr '=' core_expr
691 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
692 | '__letrec' '{' rec_binds '}'
693 'in' core_expr { UfLet (UfRec $3) $6 }
695 | '__litlit' STRING atype { UfLitLit $2 $3 }
697 | '__inline_me' core_expr { UfNote UfInlineMe $2 }
698 | '__inline_call' core_expr { UfNote UfInlineCall $2 }
699 | '__coerce' atype core_expr { UfNote (UfCoerce $2) $3 }
700 | scc core_expr { UfNote (UfSCC $1) $2 }
703 fexpr :: { UfExpr RdrName }
704 fexpr : fexpr core_arg { UfApp $1 $2 }
707 core_arg :: { UfExpr RdrName }
708 : '@' atype { UfType $2 }
711 core_args :: { [UfExpr RdrName] }
713 | core_arg core_args { $1 : $2 }
715 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
716 core_aexpr : qvar_name { UfVar $1 }
717 | qdata_name { UfVar $1 }
718 -- This one means that e.g. "True" will parse as
719 -- (UfVar True_Id) rather than (UfCon True_Con []).
720 -- No big deal; it'll be inlined in a jiffy. I tried
721 -- parsing it to (Con con []) directly, but got bitten
722 -- when a real constructor Id showed up in an interface
723 -- file. As usual, a hack bites you in the end.
724 -- If you want to get a UfCon, then use the
725 -- curly-bracket notation (True {}).
727 -- This one is dealt with by qdata_name: see above comments
728 -- | '(' ')' { UfTuple (mkTupConRdrName 0) [] }
730 | core_lit { UfLit $1 }
731 | '(' core_expr ')' { $2 }
733 -- Tuple construtors are for the *worker* of the tuple
734 -- Going direct saves needless messing about
735 | '(' comma_exprs2 ')' { UfTuple (mkRdrNameWkr (mkTupConRdrName (length $2))) $2 }
736 | '(#' comma_exprs0 '#)' { UfTuple (mkRdrNameWkr (mkUbxTupConRdrName (length $2))) $2 }
738 | '{' '__ccall' ccall_string type '}'
740 (is_dyn, is_casm, may_gc) = $2
742 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
743 | otherwise = StaticTarget $3
745 ccall = CCall target is_casm may_gc cCallConv
751 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
752 comma_exprs0 : {- empty -} { [ ] }
753 | core_expr { [ $1 ] }
754 | comma_exprs2 { $1 }
756 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
757 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
758 | core_expr ',' comma_exprs2 { $1 : $3 }
760 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
762 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
764 core_alts :: { [UfAlt RdrName] }
766 | core_alt ';' core_alts { $1 : $3 }
768 core_alt :: { UfAlt RdrName }
769 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
771 core_pat :: { (UfConAlt RdrName, [RdrName]) }
772 core_pat : core_lit { (UfLitAlt $1, []) }
773 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
774 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
775 | '(' comma_var_names1 ')' { (UfDataAlt (mkTupConRdrName (length $2)), $2) }
776 | '(#' comma_var_names1 '#)' { (UfDataAlt (mkUbxTupConRdrName (length $2)), $2) }
777 | '__DEFAULT' { (UfDefault, []) }
778 | '(' core_pat ')' { $2 }
780 core_pat_names :: { [RdrName] }
781 core_pat_names : { [] }
782 | core_pat_name core_pat_names { $1 : $2 }
784 -- Tyvar names and variable names live in different name spaces
785 -- so they need to be signalled separately. But we don't record
786 -- types or kinds in a pattern; we work that out from the type
787 -- of the case scrutinee
788 core_pat_name :: { RdrName }
789 core_pat_name : var_name { $1 }
792 comma_var_names1 :: { [RdrName] } -- One or more
793 comma_var_names1 : var_name { [$1] }
794 | var_name ',' comma_var_names1 { $1 : $3 }
796 core_lit :: { Literal }
797 core_lit : integer { mkMachInt $1 }
798 | CHAR { MachChar $1 }
799 | STRING { MachStr $1 }
800 | rational { MachDouble $1 }
801 | '__word' integer { mkMachWord $2 }
802 | '__word64' integer { mkMachWord64 $2 }
803 | '__int64' integer { mkMachInt64 $2 }
804 | '__float' rational { MachFloat $2 }
805 | '__addr' integer { MachAddr $2 }
807 integer :: { Integer }
809 | '-' INTEGER { (-$2) }
811 rational :: { Rational }
813 | '-' RATIONAL { (-$2) }
815 core_bndr :: { UfBinder RdrName }
816 core_bndr : core_val_bndr { $1 }
817 | core_tv_bndr { $1 }
819 core_bndrs :: { [UfBinder RdrName] }
821 | core_bndr core_bndrs { $1 : $2 }
823 core_val_bndr :: { UfBinder RdrName }
824 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
826 core_tv_bndr :: { UfBinder RdrName }
827 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
828 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
830 ccall_string :: { FAST_STRING }
836 ------------------------------------------------------------------------
837 scc :: { CostCentre }
838 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
839 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
840 { NormalCC { cc_name = $3, cc_mod = $4,
841 cc_is_dupd = $5, cc_is_caf = $6 } }
843 cc_name :: { EncodedFS }
847 cc_dup :: { IsDupdCC }
848 cc_dup : { OriginalCC }
851 cc_caf :: { IsCafCC }
855 -------------------------------------------------------------------
857 src_loc :: { SrcLoc }
858 src_loc : {% getSrcLocP }
860 checkVersion :: { () }
861 : {-empty-} {% checkVersion Nothing }
862 | INTEGER {% checkVersion (Just (fromInteger $1)) }
864 -------------------------------------------------------------------
869 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
871 data IfaceStuff = PIface EncodedFS{-.hi module name-} ParsedIface
872 | PIdInfo [HsIdInfo RdrName]
873 | PType RdrNameHsType
874 | PRules [RdrNameRuleDecl]
875 | PDeprecs [RdrNameDeprecation]
877 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc