X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fparser%2FParser.y.pp;h=01ad57973365110cae5e24c1e4a868d3d7cbfb09;hb=508a505e9853984bfdaa3ad855ae3fcbc6d31787;hp=83050228ab434558f2c876413e8e4c93a7763b33;hpb=05eae53416443026fa1a042919881321047cc048;p=ghc-hetmet.git diff --git a/ghc/compiler/parser/Parser.y.pp b/ghc/compiler/parser/Parser.y.pp index 8305022..01ad579 100644 --- a/ghc/compiler/parser/Parser.y.pp +++ b/ghc/compiler/parser/Parser.y.pp @@ -8,7 +8,8 @@ -- --------------------------------------------------------------------------- { -module Parser ( parseModule, parseStmt, parseIdentifier, parseIface, parseType ) where +module Parser ( parseModule, parseStmt, parseIdentifier, parseType, + parseHeader ) where #define INCLUDE #include INCLUDE "HsVersions.h" @@ -274,8 +275,8 @@ TH_TY_QUOTE { L _ ITtyQuote } -- ''T %name parseModule module %name parseStmt maybe_stmt %name parseIdentifier identifier -%name parseIface iface %name parseType ctype +%partial parseHeader header %tokentype { Located Token } %% @@ -318,36 +319,19 @@ cvtopdecls :: { [LHsDecl RdrName] } : topdecls { cvTopDecls $1 } ----------------------------------------------------------------------------- --- Interfaces (.hi-boot files) +-- Module declaration & imports only -iface :: { ModIface } - : 'module' modid 'where' ifacebody { mkBootIface (unLoc $2) $4 } - -ifacebody :: { [HsDecl RdrName] } - : '{' ifacedecls '}' { $2 } - | vocurly ifacedecls close { $2 } - -ifacedecls :: { [HsDecl RdrName] } - : ifacedecl ';' ifacedecls { $1 : $3 } - | ';' ifacedecls { $2 } - | ifacedecl { [$1] } - | {- empty -} { [] } +header :: { Located (HsModule RdrName) } + : 'module' modid maybemoddeprec maybeexports 'where' header_body + {% fileSrcSpan >>= \ loc -> + return (L loc (HsModule (Just $2) $4 $6 [] $3)) } + | missing_module_keyword importdecls + {% fileSrcSpan >>= \ loc -> + return (L loc (HsModule Nothing Nothing $2 [] Nothing)) } -ifacedecl :: { HsDecl RdrName } - : var '::' sigtype - { SigD (Sig $1 $3) } - | 'type' syn_hdr '=' ctype - { let (tc,tvs) = $2 in TyClD (TySynonym tc tvs $4) } - | 'data' tycl_hdr constrs -- No deriving in hi-boot - { TyClD (mkTyData DataType $2 Nothing (reverse (unLoc $3)) Nothing) } - | 'data' tycl_hdr 'where' gadt_constrlist - { TyClD (mkTyData DataType $2 Nothing (reverse (unLoc $4)) Nothing) } - | 'newtype' tycl_hdr -- Constructor is optional - { TyClD (mkTyData NewType $2 Nothing [] Nothing) } - | 'newtype' tycl_hdr '=' newconstr - { TyClD (mkTyData NewType $2 Nothing [$4] Nothing) } - | 'class' tycl_hdr fds - { TyClD (mkClassDecl (unLoc $2) (unLoc $3) [] emptyBag) } +header_body :: { [LImportDecl RdrName] } + : '{' importdecls { $2 } + | vocurly importdecls { $2 } ----------------------------------------------------------------------------- -- The Export List @@ -873,6 +857,7 @@ gadt_constrlist :: { Located [LConDecl RdrName] } gadt_constrs :: { Located [LConDecl RdrName] } : gadt_constrs ';' gadt_constr { LL ($3 : unLoc $1) } + | gadt_constrs ';' { $1 } | gadt_constr { L1 [$1] } gadt_constr :: { LConDecl RdrName }