1 {- Notes about the syntax of interface files
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 interface "edison" M 4 6 2 ! 406 Module M, version 4, from package 'edison',
6 Fixities version 6, rules version 2
7 Interface syntax version 406
8 ! means M contains orphans
12 import Foo ; To compile M I used nothing from Foo, but it's
13 below me in the hierarchy
15 import Foo ! @ ; Ditto, but the ! means that Foo contains orphans
16 and the @ means that Foo is a boot interface
18 import Foo :: 3 ; To compile M I used everything from Foo, which has
21 import Foo :: 3 2 6 a 1 b 3 c 7 ; To compile M I used Foo. It had
25 and some specific things besides.
31 module ParseIface ( parseIface, IfaceStuff(..) ) where
33 #include "HsVersions.h"
35 import HsSyn -- quite a bit of stuff
36 import RdrHsSyn -- oodles of synonyms
37 import HsTypes ( mkHsForAllTy, mkHsUsForAllTy, mkHsTupCon )
39 import Demand ( mkStrictnessInfo )
40 import Literal ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
41 import BasicTypes ( Fixity(..), FixityDirection(..),
42 NewOrData(..), Version, initialVersion, Boxity(..)
44 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
45 import CallConv ( cCallConv )
46 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind )
47 import IdInfo ( exactArity, InlinePragInfo(..) )
48 import PrimOp ( CCall(..), CCallTarget(..) )
51 import RnMonad ( ParsedIface(..), ExportItem, IfaceDeprecs )
52 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
53 ImportVersion, WhatsImported(..),
56 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual )
57 import Name ( OccName )
58 import OccName ( mkSysOccFS,
59 tcName, varName, ipName, dataName, clsName, tvName, uvName,
62 import Module ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
63 import SrcLoc ( SrcLoc )
64 import CmdLineOpts ( opt_InPackage )
66 import List ( insert )
67 import Class ( DefMeth (..) )
70 import FastString ( tailFS )
75 %monad { P }{ thenP }{ returnP }
76 %lexer { lexer } { ITeof }
80 'case' { ITcase } -- Haskell keywords
83 'default' { ITdefault }
84 'deriving' { ITderiving }
94 'instance' { ITinstance }
97 'newtype' { ITnewtype }
99 'qualified' { ITqualified }
104 'forall' { ITforall } -- GHC extension keywords
105 'foreign' { ITforeign }
106 'export' { ITexport }
108 'dynamic' { ITdynamic }
109 'unsafe' { ITunsafe }
111 'stdcall' { ITstdcallconv }
112 'ccall' { ITccallconv }
114 '__interface' { ITinterface } -- interface keywords
115 '__export' { IT__export }
116 '__depends' { ITdepends }
117 '__forall' { IT__forall }
118 '__letrec' { ITletrec }
119 '__coerce' { ITcoerce }
120 '__inline_me' { ITinlineMe }
121 '__inline_call'{ ITinlineCall }
122 '__DEFAULT' { ITdefaultbranch }
124 '__integer' { ITinteger_lit }
125 '__float' { ITfloat_lit }
126 '__word' { ITword_lit }
127 '__int64' { ITint64_lit }
128 '__word64' { ITword64_lit }
129 '__rational' { ITrational_lit }
130 '__addr' { ITaddr_lit }
131 '__label' { ITlabel_lit }
132 '__litlit' { ITlit_lit }
133 '__string' { ITstring_lit }
134 '__ccall' { ITccall $$ }
136 '__sccC' { ITsccAllCafs }
139 '__fuall' { ITfuall }
142 '__P' { ITspecialise }
144 '__U' { ITunfold $$ }
145 '__S' { ITstrict $$ }
148 '__D' { ITdeprecated }
150 '..' { ITdotdot } -- reserved symbols
163 '/\\' { ITbiglam } -- GHC-extension symbols
165 '{' { ITocurly } -- special symbols
167 '{|' { ITocurlybar } -- special symbols
168 '|}' { ITccurlybar } -- special symbols
178 VARID { ITvarid $$ } -- identifiers
180 VARSYM { ITvarsym $$ }
181 CONSYM { ITconsym $$ }
182 QVARID { ITqvarid $$ }
183 QCONID { ITqconid $$ }
184 QVARSYM { ITqvarsym $$ }
185 QCONSYM { ITqconsym $$ }
187 IPVARID { ITipvarid $$ } -- GHC extension
189 PRAGMA { ITpragma $$ }
192 STRING { ITstring $$ }
193 INTEGER { ITinteger $$ }
194 RATIONAL { ITrational $$ }
195 CLITLIT { ITlitlit $$ }
197 UNKNOWN { ITunknown $$ }
200 -- iface_stuff is the main production.
201 -- It recognises (a) a whole interface file
202 -- (b) a type (so that type sigs can be parsed lazily)
203 -- (c) the IdInfo part of a signature (same reason)
205 iface_stuff :: { IfaceStuff }
206 iface_stuff : iface { PIface $1 }
208 | id_info { PIdInfo $1 }
209 | rules_and_deprecs { PRulesAndDeprecs $1 }
211 iface :: { ParsedIface }
212 iface : '__interface' package mod_name
214 orphans checkVersion 'where'
220 rules_and_deprecs_part
222 pi_mod = mkModule $3 $2, -- Module itself
223 pi_vers = $4, -- Module version
225 pi_exports = (fst $5, $9), -- Exports
226 pi_usages = $10, -- Usages
227 pi_fixity = $11, -- Fixies
228 pi_insts = $12, -- Local instances
229 pi_decls = $13, -- Decls
230 pi_rules = (snd $5,fst $14), -- Rules
231 pi_deprecs = snd $14 -- Deprecations
234 -- Versions for exports and rules (optional)
235 sub_versions :: { (Version,Version) }
236 : '[' version version ']' { ($2,$3) }
237 | {- empty -} { (initialVersion, initialVersion) }
239 --------------------------------------------------------------------------
241 import_part :: { [ImportVersion OccName] }
243 | import_decl import_part { $1 : $2 }
245 import_decl :: { ImportVersion OccName }
246 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
247 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
249 orphans :: { WhetherHasOrphans }
253 is_boot :: { IsBootInterface }
257 whats_imported :: { WhatsImported OccName }
258 whats_imported : { NothingAtAll }
259 | '::' version { Everything $2 }
260 | '::' version version name_version_pairs version { Specifically $2 (Just $3) $4 $5 }
262 name_version_pairs :: { [(OccName, Version)] }
263 name_version_pairs : { [] }
264 | name_version_pair name_version_pairs { $1 : $2 }
266 name_version_pair :: { (OccName, Version) }
267 name_version_pair : var_occ version { ($1, $2) }
268 | tc_occ version { ($1, $2) }
271 --------------------------------------------------------------------------
273 exports_part :: { [ExportItem] }
274 exports_part : { [] }
275 | '__export' mod_name entities ';'
276 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
278 entities :: { [RdrAvailInfo] }
280 | entity entities { $1 : $2 }
282 entity :: { RdrAvailInfo }
283 entity : var_occ { Avail $1 }
284 | tc_occ { AvailTC $1 [$1] }
285 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
286 | tc_occ stuff_inside { AvailTC $1 (insert $1 $2) }
287 -- The 'insert' is important. The stuff_inside is sorted, and
288 -- insert keeps it that way. This is important when comparing
289 -- against the new interface file, which has the stuff in sorted order
290 -- If they differ, we'll bump the module number when it's unnecessary
292 stuff_inside :: { [OccName] }
293 stuff_inside : '{' val_occs '}' { $2 }
295 val_occ :: { OccName }
299 val_occs :: { [OccName] }
301 | val_occ val_occs { $1 : $2 }
304 --------------------------------------------------------------------------
306 fix_decl_part :: { [RdrNameFixitySig] }
307 fix_decl_part : {- empty -} { [] }
308 | fix_decls ';' { $1 }
310 fix_decls :: { [RdrNameFixitySig] }
312 | fix_decl fix_decls { $1 : $2 }
314 fix_decl :: { RdrNameFixitySig }
315 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
317 fixity :: { FixityDirection }
318 fixity : 'infixl' { InfixL }
319 | 'infixr' { InfixR }
323 prec : INTEGER { fromInteger $1 }
325 -----------------------------------------------------------------------------
327 csigs :: { [RdrNameSig] }
329 | 'where' '{' csigs1 '}' { $3 }
331 csigs1 :: { [RdrNameSig] }
333 | csig ';' csigs1 { $1 : $3 }
335 csig :: { RdrNameSig }
336 csig : src_loc var_name '::' type { mkClassOpSig NoDefMeth $2 $4 $1 }
337 | src_loc var_name '=' '::' type { mkClassOpSig (DefMeth (error "DefMeth") )
339 | src_loc var_name ';' '::' type { mkClassOpSig GenDefMeth $2 $5 $1 }
341 --------------------------------------------------------------------------
343 instance_decl_part :: { [RdrNameInstDecl] }
344 instance_decl_part : {- empty -} { [] }
345 | instance_decl_part inst_decl { $2 : $1 }
347 inst_decl :: { RdrNameInstDecl }
348 inst_decl : src_loc 'instance' type '=' var_name ';'
350 EmptyMonoBinds {- No bindings -}
351 [] {- No user pragmas -}
352 (Just $5) {- Dfun id -}
356 --------------------------------------------------------------------------
358 decls_part :: { [(Version, RdrNameHsDecl)] }
361 | opt_version decl ';' decls_part { ($1,$2):$4 }
363 decl :: { RdrNameHsDecl }
364 decl : src_loc var_name '::' type maybe_idinfo
365 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
366 | src_loc 'type' tc_name tv_bndrs '=' type
367 { TyClD (TySynonym $3 $4 $6 $1) }
368 | src_loc 'data' opt_decl_context tc_name tv_bndrs constrs
369 { TyClD (mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1) }
370 | src_loc 'newtype' opt_decl_context tc_name tv_bndrs newtype_constr
371 { TyClD (mkTyData NewType $3 $4 $5 $6 1 Nothing $1) }
372 | src_loc 'class' opt_decl_context tc_name tv_bndrs fds csigs
373 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds $1) }
375 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
376 maybe_idinfo : {- empty -} { \_ -> [] }
377 | pragma { \x -> case $1 of
378 POk _ (PIdInfo id_info) -> id_info
380 pprPanic "IdInfo parse failed"
384 pragma :: { ParseResult IfaceStuff }
385 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
391 -----------------------------------------------------------------------------
393 rules_and_deprecs_part :: { ([RdrNameRuleDecl], IfaceDeprecs) }
394 rules_and_deprecs_part : {- empty -} { ([], Nothing) }
395 | pragma { case $1 of
396 POk _ (PRulesAndDeprecs rds) -> rds
397 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
400 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
401 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
404 -----------------------------------------------------------------------------
406 rule_prag :: { [RdrNameRuleDecl] }
407 rule_prag : {- empty -} { [] }
410 rules :: { [RdrNameRuleDecl] }
412 | rule ';' rules { $1:$3 }
414 rule :: { RdrNameRuleDecl }
415 rule : src_loc STRING rule_forall qvar_name
416 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
418 rule_forall :: { [UfBinder RdrName] }
419 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
421 -----------------------------------------------------------------------------
423 deprec_prag :: { IfaceDeprecs }
424 deprec_prag : {- empty -} { Nothing }
425 | '__D' deprecs { Just $2 }
427 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
428 deprecs : STRING { Left $1 }
429 | deprec_list { Right $1 }
431 deprec_list :: { [(RdrName,DeprecTxt)] }
432 deprec_list : deprec { [$1] }
433 | deprec ';' deprec_list { $1 : $3 }
435 deprec :: { (RdrName,DeprecTxt) }
436 deprec : deprec_name STRING { ($1, $2) }
438 deprec_name :: { RdrName }
442 -----------------------------------------------------------------------------
444 version :: { Version }
445 version : INTEGER { fromInteger $1 }
447 opt_version :: { Version }
448 opt_version : version { $1 }
449 | {- empty -} { initialVersion }
451 opt_decl_context :: { RdrNameContext }
452 opt_decl_context : { [] }
453 | context '=>' { $1 }
455 ----------------------------------------------------------------------------
457 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
459 | '=' constrs1 { $2 }
461 constrs1 :: { [RdrNameConDecl] }
462 constrs1 : constr { [$1] }
463 | constr '|' constrs1 { $1 : $3 }
465 constr :: { RdrNameConDecl }
466 constr : src_loc ex_stuff data_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
467 | src_loc ex_stuff data_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
468 -- We use "data_fs" so as to include ()
470 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
471 newtype_constr : src_loc '=' ex_stuff data_name atype { [mk_con_decl $4 $3 (VanillaCon [Unbanged $5]) $1] }
472 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
473 { [mk_con_decl $4 $3 (RecCon [([$6], Unbanged $8)]) $1] }
475 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
476 ex_stuff : { ([],[]) }
477 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
479 batypes :: { [RdrNameBangType] }
481 | batype batypes { $1 : $2 }
483 batype :: { RdrNameBangType }
484 batype : atype { Unbanged $1 }
485 | '!' atype { Banged $2 }
486 | '!' '!' atype { Unpacked $3 }
488 fields1 :: { [([RdrName], RdrNameBangType)] }
489 fields1 : field { [$1] }
490 | field ',' fields1 { $1 : $3 }
492 field :: { ([RdrName], RdrNameBangType) }
493 field : var_names1 '::' type { ($1, Unbanged $3) }
494 | var_names1 '::' '!' type { ($1, Banged $4) }
495 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
496 --------------------------------------------------------------------------
498 type :: { RdrNameHsType }
499 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
500 | '__forall' tv_bndrs
501 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
502 | btype '->' type { HsFunTy $1 $3 }
505 fuall :: { [RdrName] }
506 fuall : '[' uv_bndrs ']' { $2 }
508 opt_context :: { RdrNameContext }
512 context :: { RdrNameContext }
513 context : '(' context_list1 ')' { $2 }
514 | '{' context_list1 '}' { $2 } -- Backward compatibility
516 context_list1 :: { RdrNameContext }
517 context_list1 : class { [$1] }
518 | class ',' context_list1 { $1 : $3 }
520 class :: { HsPred RdrName }
521 class : qcls_name atypes { (HsPClass $1 $2) }
522 | ipvar_name '::' type { (HsPIParam $1 $3) }
524 types0 :: { [RdrNameHsType] {- Zero or more -} }
525 types0 : {- empty -} { [ ] }
529 types2 :: { [RdrNameHsType] {- Two or more -} }
530 types2 : type ',' type { [$1,$3] }
531 | type ',' types2 { $1 : $3 }
533 btype :: { RdrNameHsType }
535 | btype atype { HsAppTy $1 $2 }
536 | '__u' usage atype { HsUsgTy $2 $3 }
538 usage :: { HsUsageAnn RdrName }
539 usage : '-' { HsUsOnce }
541 | uv_name { HsUsVar $1 }
543 atype :: { RdrNameHsType }
544 atype : qtc_name { HsTyVar $1 }
545 | tv_name { HsTyVar $1 }
546 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
547 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
548 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
549 | '[' type ']' { HsListTy $2 }
550 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
551 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
552 | '(' type ')' { $2 }
554 atypes :: { [RdrNameHsType] {- Zero or more -} }
556 | atype atypes { $1 : $2 }
557 ---------------------------------------------------------------------
558 package :: { PackageName }
560 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
561 -- which can omit the package Id
562 -- Module loops are always within a package
564 mod_name :: { ModuleName }
565 : CONID { mkSysModuleNameFS $1 }
568 ---------------------------------------------------
569 var_fs :: { EncodedFS }
572 | 'as' { SLIT("as") }
573 | 'qualified' { SLIT("qualified") }
574 | 'hiding' { SLIT("hiding") }
575 | 'forall' { SLIT("forall") }
576 | 'foreign' { SLIT("foreign") }
577 | 'export' { SLIT("export") }
578 | 'label' { SLIT("label") }
579 | 'dynamic' { SLIT("dynamic") }
580 | 'unsafe' { SLIT("unsafe") }
581 | 'with' { SLIT("with") }
582 | 'ccall' { SLIT("ccall") }
583 | 'stdcall' { SLIT("stdcall") }
585 qvar_fs :: { (EncodedFS, EncodedFS) }
589 var_occ :: { OccName }
590 : var_fs { mkSysOccFS varName $1 }
592 var_name :: { RdrName }
593 var_name : var_occ { mkRdrUnqual $1 }
595 qvar_name :: { RdrName }
596 qvar_name : var_name { $1 }
597 | qvar_fs { mkSysQual varName $1 }
599 ipvar_name :: { RdrName }
600 : IPVARID { mkSysUnqual ipName (tailFS $1) }
602 var_names :: { [RdrName] }
604 | var_name var_names { $1 : $2 }
606 var_names1 :: { [RdrName] }
607 var_names1 : var_name var_names { $1 : $2 }
609 ---------------------------------------------------
610 -- For some bizarre reason,
611 -- (,,,) is dealt with by the parser
612 -- Foo.(,,,) is dealt with by the lexer
615 data_fs :: { EncodedFS }
619 qdata_fs :: { (EncodedFS, EncodedFS) }
623 data_occ :: { OccName }
624 : data_fs { mkSysOccFS dataName $1 }
626 data_name :: { RdrName }
627 : data_occ { mkRdrUnqual $1 }
629 qdata_name :: { RdrName }
630 qdata_name : data_name { $1 }
631 | qdata_fs { mkSysQual dataName $1 }
633 var_or_data_name :: { RdrName }
637 ---------------------------------------------------
638 tc_fs :: { EncodedFS }
641 tc_occ :: { OccName }
642 : tc_fs { mkSysOccFS tcName $1 }
644 tc_name :: { RdrName }
645 : tc_occ { mkRdrUnqual $1 }
647 qtc_name :: { RdrName }
649 | qdata_fs { mkSysQual tcName $1 }
651 ---------------------------------------------------
652 cls_name :: { RdrName }
653 : data_fs { mkSysUnqual clsName $1 }
655 qcls_name :: { RdrName }
657 | qdata_fs { mkSysQual clsName $1 }
659 ---------------------------------------------------
660 uv_name :: { RdrName }
661 : VARID { mkSysUnqual uvName $1 }
663 uv_bndr :: { RdrName }
666 uv_bndrs :: { [RdrName] }
668 | uv_bndr uv_bndrs { $1 : $2 }
670 ---------------------------------------------------
671 tv_name :: { RdrName }
672 : VARID { mkSysUnqual tvName $1 }
673 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
675 tv_bndr :: { HsTyVarBndr RdrName }
676 : tv_name '::' akind { IfaceTyVar $1 $3 }
677 | tv_name { IfaceTyVar $1 boxedTypeKind }
679 tv_bndrs :: { [HsTyVarBndr RdrName] }
680 tv_bndrs : tv_bndrs1 { $1 }
681 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
683 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
685 | tv_bndr tv_bndrs1 { $1 : $2 }
687 ---------------------------------------------------
688 fds :: { [([RdrName], [RdrName])] }
690 | '|' fds1 { reverse $2 }
692 fds1 :: { [([RdrName], [RdrName])] }
693 : fds1 ',' fd { $3 : $1 }
696 fd :: { ([RdrName], [RdrName]) }
697 : varids0 '->' varids0 { (reverse $1, reverse $3) }
699 varids0 :: { [RdrName] }
701 | varids0 tv_name { $2 : $1 }
703 ---------------------------------------------------
706 | akind '->' kind { mkArrowKind $1 $3 }
709 : VARSYM { if $1 == SLIT("*") then
711 else if $1 == SLIT("?") then
713 else panic "ParseInterface: akind"
715 | '(' kind ')' { $2 }
717 --------------------------------------------------------------------------
719 id_info :: { [HsIdInfo RdrName] }
720 : id_info_item { [$1] }
721 | id_info_item id_info { $1 : $2 }
723 id_info_item :: { HsIdInfo RdrName }
724 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
725 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
726 | '__M' { HsCprInfo }
727 | '__S' { HsStrictness (mkStrictnessInfo $1) }
728 | '__C' { HsNoCafRefs }
729 | '__P' qvar_name { HsWorker $2 }
731 inline_prag :: { InlinePragInfo }
732 : {- empty -} { NoInlinePragInfo }
733 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
735 from_prag :: { Bool }
736 : {- empty -} { True }
739 phase :: { Maybe Int }
740 : {- empty -} { Nothing }
741 | INTEGER { Just (fromInteger $1) }
743 -------------------------------------------------------
744 core_expr :: { UfExpr RdrName }
745 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
746 | 'case' core_expr 'of' var_name
747 '{' core_alts '}' { UfCase $2 $4 $6 }
749 | 'let' '{' core_val_bndr '=' core_expr
750 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
751 | '__letrec' '{' rec_binds '}'
752 'in' core_expr { UfLet (UfRec $3) $6 }
754 | '__litlit' STRING atype { UfLitLit $2 $3 }
758 fexpr :: { UfExpr RdrName }
759 fexpr : fexpr core_arg { UfApp $1 $2 }
760 | scc core_aexpr { UfNote (UfSCC $1) $2 }
761 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
762 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
763 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
766 core_arg :: { UfExpr RdrName }
767 : '@' atype { UfType $2 }
770 core_args :: { [UfExpr RdrName] }
772 | core_arg core_args { $1 : $2 }
774 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
775 core_aexpr : qvar_name { UfVar $1 }
776 | qdata_name { UfVar $1 }
778 | core_lit { UfLit $1 }
779 | '(' core_expr ')' { $2 }
781 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
782 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
783 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
785 | '{' '__ccall' ccall_string type '}'
787 (is_dyn, is_casm, may_gc) = $2
789 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
790 | otherwise = StaticTarget $3
792 ccall = CCall target is_casm may_gc cCallConv
798 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
799 comma_exprs0 : {- empty -} { [ ] }
800 | core_expr { [ $1 ] }
801 | comma_exprs2 { $1 }
803 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
804 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
805 | core_expr ',' comma_exprs2 { $1 : $3 }
807 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
809 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
811 core_alts :: { [UfAlt RdrName] }
813 | core_alt ';' core_alts { $1 : $3 }
815 core_alt :: { UfAlt RdrName }
816 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
818 core_pat :: { (UfConAlt RdrName, [RdrName]) }
819 core_pat : core_lit { (UfLitAlt $1, []) }
820 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
821 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
822 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
823 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
824 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
825 | '__DEFAULT' { (UfDefault, []) }
826 | '(' core_pat ')' { $2 }
828 core_pat_names :: { [RdrName] }
829 core_pat_names : { [] }
830 | core_pat_name core_pat_names { $1 : $2 }
832 -- Tyvar names and variable names live in different name spaces
833 -- so they need to be signalled separately. But we don't record
834 -- types or kinds in a pattern; we work that out from the type
835 -- of the case scrutinee
836 core_pat_name :: { RdrName }
837 core_pat_name : var_name { $1 }
840 comma_var_names1 :: { [RdrName] } -- One or more
841 comma_var_names1 : var_name { [$1] }
842 | var_name ',' comma_var_names1 { $1 : $3 }
844 core_lit :: { Literal }
845 core_lit : integer { mkMachInt $1 }
846 | CHAR { MachChar $1 }
847 | STRING { MachStr $1 }
848 | rational { MachDouble $1 }
849 | '__word' integer { mkMachWord $2 }
850 | '__word64' integer { mkMachWord64 $2 }
851 | '__int64' integer { mkMachInt64 $2 }
852 | '__float' rational { MachFloat $2 }
853 | '__addr' integer { MachAddr $2 }
854 | '__label' STRING { MachLabel $2 }
856 integer :: { Integer }
858 | '-' INTEGER { (-$2) }
860 rational :: { Rational }
862 | '-' RATIONAL { (-$2) }
864 core_bndr :: { UfBinder RdrName }
865 core_bndr : core_val_bndr { $1 }
866 | core_tv_bndr { $1 }
868 core_bndrs :: { [UfBinder RdrName] }
870 | core_bndr core_bndrs { $1 : $2 }
872 core_val_bndr :: { UfBinder RdrName }
873 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
875 core_tv_bndr :: { UfBinder RdrName }
876 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
877 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
879 ccall_string :: { FAST_STRING }
885 ------------------------------------------------------------------------
886 scc :: { CostCentre }
887 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
888 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
889 { NormalCC { cc_name = $3, cc_mod = $4,
890 cc_is_dupd = $5, cc_is_caf = $6 } }
892 cc_name :: { EncodedFS }
896 cc_dup :: { IsDupdCC }
897 cc_dup : { OriginalCC }
900 cc_caf :: { IsCafCC }
904 -------------------------------------------------------------------
906 src_loc :: { SrcLoc }
907 src_loc : {% getSrcLocP }
909 -- Check the project version: this makes sure
910 -- that the project version (e.g. 407) in the interface
911 -- file is the same as that for the compiler that's reading it
912 checkVersion :: { () }
913 : {-empty-} {% checkVersion Nothing }
914 | INTEGER {% checkVersion (Just (fromInteger $1)) }
916 -------------------------------------------------------------------
921 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
923 data IfaceStuff = PIface ParsedIface
924 | PIdInfo [HsIdInfo RdrName]
925 | PType RdrNameHsType
926 | PRulesAndDeprecs ([RdrNameRuleDecl], IfaceDeprecs)
928 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc