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 HsPragmas ( noDataPragmas, noClassPragmas )
47 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind )
48 import IdInfo ( exactArity, InlinePragInfo(..) )
49 import PrimOp ( CCall(..), CCallTarget(..) )
52 import RnMonad ( ParsedIface(..) )
53 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
54 ImportVersion, ExportItem, WhatsImported(..),
57 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual )
58 import Name ( OccName )
59 import OccName ( mkSysOccFS,
60 tcName, varName, ipName, dataName, clsName, tvName, uvName,
63 import Module ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
64 import SrcLoc ( SrcLoc )
65 import CmdLineOpts ( opt_InPackage )
67 import List ( insert )
68 import Class ( DefMeth (..) )
71 import FastString ( tailFS )
76 %monad { P }{ thenP }{ returnP }
77 %lexer { lexer } { ITeof }
81 'case' { ITcase } -- Haskell keywords
84 'default' { ITdefault }
85 'deriving' { ITderiving }
95 'instance' { ITinstance }
98 'newtype' { ITnewtype }
100 'qualified' { ITqualified }
105 'forall' { ITforall } -- GHC extension keywords
106 'foreign' { ITforeign }
107 'export' { ITexport }
109 'dynamic' { ITdynamic }
110 'unsafe' { ITunsafe }
112 'stdcall' { ITstdcallconv }
113 'ccall' { ITccallconv }
115 '__interface' { ITinterface } -- interface keywords
116 '__export' { IT__export }
117 '__depends' { ITdepends }
118 '__forall' { IT__forall }
119 '__letrec' { ITletrec }
120 '__coerce' { ITcoerce }
121 '__inline_me' { ITinlineMe }
122 '__inline_call'{ ITinlineCall }
123 '__DEFAULT' { ITdefaultbranch }
125 '__integer' { ITinteger_lit }
126 '__float' { ITfloat_lit }
127 '__word' { ITword_lit }
128 '__int64' { ITint64_lit }
129 '__word64' { ITword64_lit }
130 '__rational' { ITrational_lit }
131 '__addr' { ITaddr_lit }
132 '__label' { ITlabel_lit }
133 '__litlit' { ITlit_lit }
134 '__string' { ITstring_lit }
135 '__ccall' { ITccall $$ }
137 '__sccC' { ITsccAllCafs }
140 '__fuall' { ITfuall }
143 '__P' { ITspecialise }
145 '__U' { ITunfold $$ }
146 '__S' { ITstrict $$ }
149 '__D' { ITdeprecated }
151 '..' { ITdotdot } -- reserved symbols
164 '/\\' { ITbiglam } -- GHC-extension symbols
166 '{' { ITocurly } -- special symbols
168 '{|' { ITocurlybar } -- special symbols
169 '|}' { ITccurlybar } -- special symbols
179 VARID { ITvarid $$ } -- identifiers
181 VARSYM { ITvarsym $$ }
182 CONSYM { ITconsym $$ }
183 QVARID { ITqvarid $$ }
184 QCONID { ITqconid $$ }
185 QVARSYM { ITqvarsym $$ }
186 QCONSYM { ITqconsym $$ }
188 IPVARID { ITipvarid $$ } -- GHC extension
190 PRAGMA { ITpragma $$ }
193 STRING { ITstring $$ }
194 INTEGER { ITinteger $$ }
195 RATIONAL { ITrational $$ }
196 CLITLIT { ITlitlit $$ }
198 UNKNOWN { ITunknown $$ }
201 -- iface_stuff is the main production.
202 -- It recognises (a) a whole interface file
203 -- (b) a type (so that type sigs can be parsed lazily)
204 -- (c) the IdInfo part of a signature (same reason)
206 iface_stuff :: { IfaceStuff }
207 iface_stuff : iface { PIface $1 }
209 | id_info { PIdInfo $1 }
210 | '__R' rules { PRules $2 }
211 | '__D' deprecs { PDeprecs $2 }
214 iface :: { ParsedIface }
215 iface : '__interface' package mod_name
217 orphans checkVersion 'where'
225 pi_mod = mkModule $3 $2, -- Module itself
226 pi_vers = $4, -- Module version
228 pi_exports = $9, -- Exports
229 pi_usages = $10, -- Usages
230 pi_fixity = (fst $5,$11), -- Fixies
231 pi_insts = $12, -- Local instances
232 pi_decls = $13, -- Decls
233 pi_rules = (snd $5,fst $14), -- Rules
234 pi_deprecs = snd $14 -- Deprecations
237 -- Versions for fixities and rules (optional)
238 sub_versions :: { (Version,Version) }
239 : '[' version version ']' { ($2,$3) }
240 | {- empty -} { (initialVersion, initialVersion) }
242 --------------------------------------------------------------------------
244 import_part :: { [ImportVersion OccName] }
246 | import_decl import_part { $1 : $2 }
248 import_decl :: { ImportVersion OccName }
249 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
250 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
252 orphans :: { WhetherHasOrphans }
256 is_boot :: { IsBootInterface }
260 whats_imported :: { WhatsImported OccName }
261 whats_imported : { NothingAtAll }
262 | '::' version { Everything $2 }
263 | '::' version version version name_version_pairs { Specifically $2 $3 $4 $5 }
265 name_version_pairs :: { [(OccName, Version)] }
266 name_version_pairs : { [] }
267 | name_version_pair name_version_pairs { $1 : $2 }
269 name_version_pair :: { (OccName, Version) }
270 name_version_pair : var_occ version { ($1, $2) }
271 | tc_occ version { ($1, $2) }
274 --------------------------------------------------------------------------
276 exports_part :: { [ExportItem] }
277 exports_part : { [] }
278 | '__export' mod_name entities ';'
279 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
281 entities :: { [RdrAvailInfo] }
283 | entity entities { $1 : $2 }
285 entity :: { RdrAvailInfo }
286 entity : var_occ { Avail $1 }
287 | tc_occ { AvailTC $1 [$1] }
288 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
289 | tc_occ stuff_inside { AvailTC $1 (insert $1 $2) }
290 -- The 'insert' is important. The stuff_inside is sorted, and
291 -- insert keeps it that way. This is important when comparing
292 -- against the new interface file, which has the stuff in sorted order
293 -- If they differ, we'll bump the module number when it's unnecessary
295 stuff_inside :: { [OccName] }
296 stuff_inside : '{' val_occs '}' { $2 }
298 val_occ :: { OccName }
302 val_occs :: { [OccName] }
304 | val_occ val_occs { $1 : $2 }
307 --------------------------------------------------------------------------
309 fix_decl_part :: { [RdrNameFixitySig] }
310 fix_decl_part : {- empty -} { [] }
311 | fix_decls ';' { $1 }
313 fix_decls :: { [RdrNameFixitySig] }
315 | fix_decl fix_decls { $1 : $2 }
317 fix_decl :: { RdrNameFixitySig }
318 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
320 fixity :: { FixityDirection }
321 fixity : 'infixl' { InfixL }
322 | 'infixr' { InfixR }
326 prec : INTEGER { fromInteger $1 }
328 -----------------------------------------------------------------------------
330 csigs :: { [RdrNameSig] }
332 | 'where' '{' csigs1 '}' { $3 }
334 csigs1 :: { [RdrNameSig] }
336 | csig ';' csigs1 { $1 : $3 }
338 csig :: { RdrNameSig }
339 csig : src_loc var_name '::' type { mkClassOpSig NoDefMeth $2 $4 $1 }
340 | src_loc var_name '=' '::' type { mkClassOpSig (DefMeth (error "DefMeth") )
342 | src_loc var_name ';' '::' type { mkClassOpSig GenDefMeth $2 $5 $1 }
344 --------------------------------------------------------------------------
346 instance_decl_part :: { [RdrNameInstDecl] }
347 instance_decl_part : {- empty -} { [] }
348 | instance_decl_part inst_decl { $2 : $1 }
350 inst_decl :: { RdrNameInstDecl }
351 inst_decl : src_loc 'instance' type '=' var_name ';'
353 EmptyMonoBinds {- No bindings -}
354 [] {- No user pragmas -}
355 (Just $5) {- Dfun id -}
359 --------------------------------------------------------------------------
361 decls_part :: { [(Version, RdrNameHsDecl)] }
364 | opt_version decl ';' decls_part { ($1,$2):$4 }
366 decl :: { RdrNameHsDecl }
367 decl : src_loc var_name '::' type maybe_idinfo
368 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
369 | src_loc 'type' tc_name tv_bndrs '=' type
370 { TyClD (TySynonym $3 $4 $6 $1) }
371 | src_loc 'data' opt_decl_context tc_name tv_bndrs constrs
372 { TyClD (mkTyData DataType $3 $4 $5 $6 (length $6) Nothing noDataPragmas $1) }
373 | src_loc 'newtype' opt_decl_context tc_name tv_bndrs newtype_constr
374 { TyClD (mkTyData NewType $3 $4 $5 $6 1 Nothing noDataPragmas $1) }
375 | src_loc 'class' opt_decl_context tc_name tv_bndrs fds csigs
376 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds
379 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
380 maybe_idinfo : {- empty -} { \_ -> [] }
381 | pragma { \x -> case $1 of
382 POk _ (PIdInfo id_info) -> id_info
384 pprPanic "IdInfo parse failed"
388 pragma :: { ParseResult IfaceStuff }
389 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
395 -----------------------------------------------------------------------------
397 rules_and_deprecs :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
398 rules_and_deprecs : {- empty -} { ([], []) }
399 | rules_and_deprecs rule_or_deprec
401 append2 (xs1,ys1) (xs2,ys2) =
402 (xs1 `app` xs2, ys1 `app` ys2)
403 xs `app` [] = xs -- performance paranoia
404 xs `app` ys = xs ++ ys
408 rule_or_deprec :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
409 rule_or_deprec : pragma { case $1 of
410 POk _ (PRules rules) -> (rules,[])
411 POk _ (PDeprecs deprecs) -> ([],deprecs)
412 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
415 -----------------------------------------------------------------------------
417 rules :: { [RdrNameRuleDecl] }
419 | rule ';' rules { $1:$3 }
421 rule :: { RdrNameRuleDecl }
422 rule : src_loc STRING rule_forall qvar_name
423 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
425 rule_forall :: { [UfBinder RdrName] }
426 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
428 -----------------------------------------------------------------------------
430 deprecs :: { [RdrNameDeprecation] }
431 deprecs : {- empty -} { [] }
432 | deprec ';' deprecs { $1 : $3 }
434 deprec :: { RdrNameDeprecation }
435 deprec : src_loc STRING { Deprecation (IEModuleContents undefined) $2 $1 }
436 | src_loc deprec_name STRING { Deprecation $2 $3 $1 }
438 -- SUP: TEMPORARY HACK
439 deprec_name :: { RdrNameIE }
440 : var_name { IEVar $1 }
441 | data_name { IEThingAbs $1 }
443 -----------------------------------------------------------------------------
445 version :: { Version }
446 version : INTEGER { fromInteger $1 }
448 opt_version :: { Version }
449 opt_version : version { $1 }
450 | {- empty -} { initialVersion }
452 opt_decl_context :: { RdrNameContext }
453 opt_decl_context : { [] }
454 | context '=>' { $1 }
456 ----------------------------------------------------------------------------
458 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
460 | '=' constrs1 { $2 }
462 constrs1 :: { [RdrNameConDecl] }
463 constrs1 : constr { [$1] }
464 | constr '|' constrs1 { $1 : $3 }
466 constr :: { RdrNameConDecl }
467 constr : src_loc ex_stuff data_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
468 | src_loc ex_stuff data_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
469 -- We use "data_fs" so as to include ()
471 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
472 newtype_constr : src_loc '=' ex_stuff data_name atype { [mk_con_decl $4 $3 (VanillaCon [Unbanged $5]) $1] }
473 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
474 { [mk_con_decl $4 $3 (RecCon [([$6], Unbanged $8)]) $1] }
476 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
477 ex_stuff : { ([],[]) }
478 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
480 batypes :: { [RdrNameBangType] }
482 | batype batypes { $1 : $2 }
484 batype :: { RdrNameBangType }
485 batype : atype { Unbanged $1 }
486 | '!' atype { Banged $2 }
487 | '!' '!' atype { Unpacked $3 }
489 fields1 :: { [([RdrName], RdrNameBangType)] }
490 fields1 : field { [$1] }
491 | field ',' fields1 { $1 : $3 }
493 field :: { ([RdrName], RdrNameBangType) }
494 field : var_names1 '::' type { ($1, Unbanged $3) }
495 | var_names1 '::' '!' type { ($1, Banged $4) }
496 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
497 --------------------------------------------------------------------------
499 type :: { RdrNameHsType }
500 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
501 | '__forall' tv_bndrs
502 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
503 | btype '->' type { HsFunTy $1 $3 }
506 fuall :: { [RdrName] }
507 fuall : '[' uv_bndrs ']' { $2 }
509 opt_context :: { RdrNameContext }
513 context :: { RdrNameContext }
514 context : '(' context_list1 ')' { $2 }
515 | '{' context_list1 '}' { $2 } -- Backward compatibility
517 context_list1 :: { RdrNameContext }
518 context_list1 : class { [$1] }
519 | class ',' context_list1 { $1 : $3 }
521 class :: { HsPred RdrName }
522 class : qcls_name atypes { (HsPClass $1 $2) }
523 | ipvar_name '::' type { (HsPIParam $1 $3) }
525 types0 :: { [RdrNameHsType] {- Zero or more -} }
526 types0 : {- empty -} { [ ] }
530 types2 :: { [RdrNameHsType] {- Two or more -} }
531 types2 : type ',' type { [$1,$3] }
532 | type ',' types2 { $1 : $3 }
534 btype :: { RdrNameHsType }
536 | btype atype { HsAppTy $1 $2 }
537 | '__u' usage atype { HsUsgTy $2 $3 }
539 usage :: { HsUsageAnn RdrName }
540 usage : '-' { HsUsOnce }
542 | uv_name { HsUsVar $1 }
544 atype :: { RdrNameHsType }
545 atype : qtc_name { HsTyVar $1 }
546 | tv_name { HsTyVar $1 }
547 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
548 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
549 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
550 | '[' type ']' { HsListTy $2 }
551 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
552 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
553 | '(' type ')' { $2 }
555 atypes :: { [RdrNameHsType] {- Zero or more -} }
557 | atype atypes { $1 : $2 }
558 ---------------------------------------------------------------------
559 package :: { PackageName }
561 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
562 -- which can omit the package Id
563 -- Module loops are always within a package
565 mod_name :: { ModuleName }
566 : CONID { mkSysModuleNameFS $1 }
569 ---------------------------------------------------
570 var_fs :: { EncodedFS }
573 | 'as' { SLIT("as") }
574 | 'qualified' { SLIT("qualified") }
575 | 'hiding' { SLIT("hiding") }
576 | 'forall' { SLIT("forall") }
577 | 'foreign' { SLIT("foreign") }
578 | 'export' { SLIT("export") }
579 | 'label' { SLIT("label") }
580 | 'dynamic' { SLIT("dynamic") }
581 | 'unsafe' { SLIT("unsafe") }
582 | 'with' { SLIT("with") }
583 | 'ccall' { SLIT("ccall") }
584 | 'stdcall' { SLIT("stdcall") }
586 qvar_fs :: { (EncodedFS, EncodedFS) }
590 var_occ :: { OccName }
591 : var_fs { mkSysOccFS varName $1 }
593 var_name :: { RdrName }
594 var_name : var_occ { mkRdrUnqual $1 }
596 qvar_name :: { RdrName }
597 qvar_name : var_name { $1 }
598 | qvar_fs { mkSysQual varName $1 }
600 ipvar_name :: { RdrName }
601 : IPVARID { mkSysUnqual ipName (tailFS $1) }
603 var_names :: { [RdrName] }
605 | var_name var_names { $1 : $2 }
607 var_names1 :: { [RdrName] }
608 var_names1 : var_name var_names { $1 : $2 }
610 ---------------------------------------------------
611 -- For some bizarre reason,
612 -- (,,,) is dealt with by the parser
613 -- Foo.(,,,) is dealt with by the lexer
616 data_fs :: { EncodedFS }
620 qdata_fs :: { (EncodedFS, EncodedFS) }
624 data_occ :: { OccName }
625 : data_fs { mkSysOccFS dataName $1 }
627 data_name :: { RdrName }
628 : data_occ { mkRdrUnqual $1 }
630 qdata_name :: { RdrName }
631 qdata_name : data_name { $1 }
632 | qdata_fs { mkSysQual dataName $1 }
634 qdata_names :: { [RdrName] }
636 | qdata_name qdata_names { $1 : $2 }
638 var_or_data_name :: { RdrName }
642 ---------------------------------------------------
643 tc_fs :: { EncodedFS }
646 tc_occ :: { OccName }
647 : tc_fs { mkSysOccFS tcName $1 }
649 tc_name :: { RdrName }
650 : tc_occ { mkRdrUnqual $1 }
652 qtc_name :: { RdrName }
654 | qdata_fs { mkSysQual tcName $1 }
656 ---------------------------------------------------
657 cls_name :: { RdrName }
658 : data_fs { mkSysUnqual clsName $1 }
660 qcls_name :: { RdrName }
662 | qdata_fs { mkSysQual clsName $1 }
664 ---------------------------------------------------
665 uv_name :: { RdrName }
666 : VARID { mkSysUnqual uvName $1 }
668 uv_bndr :: { RdrName }
671 uv_bndrs :: { [RdrName] }
673 | uv_bndr uv_bndrs { $1 : $2 }
675 ---------------------------------------------------
676 tv_name :: { RdrName }
677 : VARID { mkSysUnqual tvName $1 }
678 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
680 tv_bndr :: { HsTyVarBndr RdrName }
681 : tv_name '::' akind { IfaceTyVar $1 $3 }
682 | tv_name { IfaceTyVar $1 boxedTypeKind }
684 tv_bndrs :: { [HsTyVarBndr RdrName] }
685 tv_bndrs : tv_bndrs1 { $1 }
686 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
688 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
690 | tv_bndr tv_bndrs1 { $1 : $2 }
692 ---------------------------------------------------
693 fds :: { [([RdrName], [RdrName])] }
695 | '|' fds1 { reverse $2 }
697 fds1 :: { [([RdrName], [RdrName])] }
698 : fds1 ',' fd { $3 : $1 }
701 fd :: { ([RdrName], [RdrName]) }
702 : varids0 '->' varids0 { (reverse $1, reverse $3) }
704 varids0 :: { [RdrName] }
706 | varids0 tv_name { $2 : $1 }
708 ---------------------------------------------------
711 | akind '->' kind { mkArrowKind $1 $3 }
714 : VARSYM { if $1 == SLIT("*") then
716 else if $1 == SLIT("?") then
718 else panic "ParseInterface: akind"
720 | '(' kind ')' { $2 }
722 --------------------------------------------------------------------------
724 id_info :: { [HsIdInfo RdrName] }
726 | id_info_item id_info { $1 : $2 }
728 id_info_item :: { HsIdInfo RdrName }
729 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
730 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
731 | '__M' { HsCprInfo }
732 | '__S' { HsStrictness (mkStrictnessInfo $1) }
733 | '__C' { HsNoCafRefs }
734 | '__P' qvar_name { HsWorker $2 }
736 inline_prag :: { InlinePragInfo }
737 : {- empty -} { NoInlinePragInfo }
738 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
740 from_prag :: { Bool }
741 : {- empty -} { True }
744 phase :: { Maybe Int }
745 : {- empty -} { Nothing }
746 | INTEGER { Just (fromInteger $1) }
748 -------------------------------------------------------
749 core_expr :: { UfExpr RdrName }
750 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
751 | 'case' core_expr 'of' var_name
752 '{' core_alts '}' { UfCase $2 $4 $6 }
754 | 'let' '{' core_val_bndr '=' core_expr
755 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
756 | '__letrec' '{' rec_binds '}'
757 'in' core_expr { UfLet (UfRec $3) $6 }
759 | '__litlit' STRING atype { UfLitLit $2 $3 }
763 fexpr :: { UfExpr RdrName }
764 fexpr : fexpr core_arg { UfApp $1 $2 }
765 | scc core_aexpr { UfNote (UfSCC $1) $2 }
766 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
767 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
768 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
771 core_arg :: { UfExpr RdrName }
772 : '@' atype { UfType $2 }
775 core_args :: { [UfExpr RdrName] }
777 | core_arg core_args { $1 : $2 }
779 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
780 core_aexpr : qvar_name { UfVar $1 }
781 | qdata_name { UfVar $1 }
783 | core_lit { UfLit $1 }
784 | '(' core_expr ')' { $2 }
786 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
787 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
788 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
790 | '{' '__ccall' ccall_string type '}'
792 (is_dyn, is_casm, may_gc) = $2
794 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
795 | otherwise = StaticTarget $3
797 ccall = CCall target is_casm may_gc cCallConv
803 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
804 comma_exprs0 : {- empty -} { [ ] }
805 | core_expr { [ $1 ] }
806 | comma_exprs2 { $1 }
808 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
809 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
810 | core_expr ',' comma_exprs2 { $1 : $3 }
812 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
814 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
816 core_alts :: { [UfAlt RdrName] }
818 | core_alt ';' core_alts { $1 : $3 }
820 core_alt :: { UfAlt RdrName }
821 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
823 core_pat :: { (UfConAlt RdrName, [RdrName]) }
824 core_pat : core_lit { (UfLitAlt $1, []) }
825 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
826 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
827 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
828 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
829 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
830 | '__DEFAULT' { (UfDefault, []) }
831 | '(' core_pat ')' { $2 }
833 core_pat_names :: { [RdrName] }
834 core_pat_names : { [] }
835 | core_pat_name core_pat_names { $1 : $2 }
837 -- Tyvar names and variable names live in different name spaces
838 -- so they need to be signalled separately. But we don't record
839 -- types or kinds in a pattern; we work that out from the type
840 -- of the case scrutinee
841 core_pat_name :: { RdrName }
842 core_pat_name : var_name { $1 }
845 comma_var_names1 :: { [RdrName] } -- One or more
846 comma_var_names1 : var_name { [$1] }
847 | var_name ',' comma_var_names1 { $1 : $3 }
849 core_lit :: { Literal }
850 core_lit : integer { mkMachInt $1 }
851 | CHAR { MachChar $1 }
852 | STRING { MachStr $1 }
853 | rational { MachDouble $1 }
854 | '__word' integer { mkMachWord $2 }
855 | '__word64' integer { mkMachWord64 $2 }
856 | '__int64' integer { mkMachInt64 $2 }
857 | '__float' rational { MachFloat $2 }
858 | '__addr' integer { MachAddr $2 }
859 | '__label' STRING { MachLabel $2 }
861 integer :: { Integer }
863 | '-' INTEGER { (-$2) }
865 rational :: { Rational }
867 | '-' RATIONAL { (-$2) }
869 core_bndr :: { UfBinder RdrName }
870 core_bndr : core_val_bndr { $1 }
871 | core_tv_bndr { $1 }
873 core_bndrs :: { [UfBinder RdrName] }
875 | core_bndr core_bndrs { $1 : $2 }
877 core_val_bndr :: { UfBinder RdrName }
878 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
880 core_tv_bndr :: { UfBinder RdrName }
881 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
882 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
884 ccall_string :: { FAST_STRING }
890 ------------------------------------------------------------------------
891 scc :: { CostCentre }
892 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
893 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
894 { NormalCC { cc_name = $3, cc_mod = $4,
895 cc_is_dupd = $5, cc_is_caf = $6 } }
897 cc_name :: { EncodedFS }
901 cc_dup :: { IsDupdCC }
902 cc_dup : { OriginalCC }
905 cc_caf :: { IsCafCC }
909 -------------------------------------------------------------------
911 src_loc :: { SrcLoc }
912 src_loc : {% getSrcLocP }
914 -- Check the project version: this makes sure
915 -- that the project version (e.g. 407) in the interface
916 -- file is the same as that for the compiler that's reading it
917 checkVersion :: { () }
918 : {-empty-} {% checkVersion Nothing }
919 | INTEGER {% checkVersion (Just (fromInteger $1)) }
921 -------------------------------------------------------------------
926 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
928 data IfaceStuff = PIface ParsedIface
929 | PIdInfo [HsIdInfo RdrName]
930 | PType RdrNameHsType
931 | PRules [RdrNameRuleDecl]
932 | PDeprecs [RdrNameDeprecation]
934 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc