X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fparser%2FParser.y.pp;h=dc86c0040e74249e42162b21aa4c744ab655e61b;hb=3734da50be1d8e1ddad5b5fe5c46fcfb3192d1da;hp=da0082567ca4b8b860ae88e8183588eec218731f;hpb=afef39736dcde6f4947a6f362f9e6b3586933db4;p=ghc-hetmet.git diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp index da00825..dc86c00 100644 --- a/compiler/parser/Parser.y.pp +++ b/compiler/parser/Parser.y.pp @@ -113,6 +113,7 @@ and LL. Each of these macros can be thought of as having type They each add a SrcSpan to their argument. L0 adds 'noSrcSpan', used for empty productions + -- This doesn't seem to work anymore -=chak L1 for a production with a single token on the lhs. Grabs the SrcSpan from that token. @@ -175,7 +176,7 @@ incorrect. 'where' { L _ ITwhere } '_scc_' { L _ ITscc } -- ToDo: remove - 'forall' { L _ ITforall } -- GHC extension keywords + 'forall' { L _ ITforall } -- GHC extension keywords 'foreign' { L _ ITforeign } 'export' { L _ ITexport } 'label' { L _ ITlabel } @@ -184,6 +185,7 @@ incorrect. 'threadsafe' { L _ ITthreadsafe } 'unsafe' { L _ ITunsafe } 'mdo' { L _ ITmdo } + 'iso' { L _ ITiso } 'stdcall' { L _ ITstdcallconv } 'ccall' { L _ ITccallconv } 'dotnet' { L _ ITdotnet } @@ -442,7 +444,7 @@ topdecls :: { OrdList (LHsDecl RdrName) } topdecl :: { OrdList (LHsDecl RdrName) } : cl_decl { unitOL (L1 (TyClD (unLoc $1))) } - | ty_decl {% checkTopTyClD $1 >>= return.unitOL.L1 } + | ty_decl { unitOL (L1 (TyClD (unLoc $1))) } | 'instance' inst_type where { let (binds, sigs, ats) = cvBindsAndSigs (unLoc $3) in unitOL (L (comb3 $1 $2 $3) @@ -465,8 +467,9 @@ cl_decl :: { LTyClDecl RdrName } : 'class' tycl_hdr fds where {% do { let { (binds, sigs, ats) = cvBindsAndSigs (unLoc $4) - ; (ctxt, tc, tvs, Just tparms) = unLoc $2} - ; checkTyVars tparms + ; (ctxt, tc, tvs, tparms) = unLoc $2} + ; checkTyVars tparms False -- only type vars allowed + ; checkKindSigs ats ; return $ L (comb4 $1 $2 $3 $4) (mkClassDecl (ctxt, tc, tvs) (unLoc $3) sigs binds ats) } } @@ -474,27 +477,78 @@ cl_decl :: { LTyClDecl RdrName } -- Type declarations -- ty_decl :: { LTyClDecl RdrName } - : 'type' type '=' ctype - -- Note type on the left of the '='; this allows - -- infix type constructors to be declared + -- type function signature and equations (w/ type synonyms as special + -- case); we need to handle all this in one rule to avoid a large + -- number of shift/reduce conflicts + : 'type' opt_iso type kind_or_ctype + -- + -- Note the use of type for the head; this allows + -- infix type constructors to be declared and type + -- patterns for type function equations -- - -- Note ctype, not sigtype, on the right - -- We allow an explicit for-all but we don't insert one - -- in type Foo a = (b,b) - -- Instead we just say b is out of scope - {% do { (tc,tvs) <- checkSynHdr $2 - ; return (LL (TySynonym tc tvs $4)) } } - + -- We have that `typats :: Maybe [LHsType name]' is `Nothing' + -- (in the second case alternative) when all arguments are + -- variables (and we thus have a vanilla type synonym + -- declaration); otherwise, it contains all arguments as type + -- patterns. + -- + {% case $4 of + Left kind -> + do { (tc, tvs, _) <- checkSynHdr $3 False + ; return (L (comb3 $1 $3 kind) + (TyFunction tc tvs $2 (unLoc kind))) + } + Right ty | not $2 -> + do { (tc, tvs, typats) <- checkSynHdr $3 True + ; return (L (comb2 $1 ty) + (TySynonym tc tvs typats ty)) } + Right ty | otherwise -> + parseError (comb2 $1 ty) + "iso tag is only allowed in kind signatures" + } + + -- kind signature of indexed type + | data_or_newtype tycl_hdr '::' kind + {% do { let {(ctxt, tc, tvs, tparms) = unLoc $2} + ; checkTyVars tparms False -- no type pattern + ; return $ + L (comb3 $1 $2 $4) + (mkTyData (unLoc $1) (ctxt, tc, tvs, Nothing) + (Just (unLoc $4)) [] Nothing) } } + + -- data type or newtype declaration | data_or_newtype tycl_hdr constrs deriving - { L (comb4 $1 $2 $3 $4) -- We need the location on tycl_hdr - -- in case constrs and deriving are both empty - (mkTyData (unLoc $1) (unLoc $2) Nothing (reverse (unLoc $3)) (unLoc $4)) } - + {% do { let {(ctxt, tc, tvs, tparms) = unLoc $2} + ; tpats <- checkTyVars tparms True -- can have type pats + ; return $ + L (comb4 $1 $2 $3 $4) + -- We need the location on tycl_hdr in case + -- constrs and deriving are both empty + (mkTyData (unLoc $1) (ctxt, tc, tvs, tpats) + Nothing (reverse (unLoc $3)) (unLoc $4)) } } + + -- GADT declaration | data_or_newtype tycl_hdr opt_kind_sig 'where' gadt_constrlist deriving - { L (comb4 $1 $2 $4 $5) - (mkTyData (unLoc $1) (unLoc $2) $3 (reverse (unLoc $5)) (unLoc $6)) } + {% do { let {(ctxt, tc, tvs, tparms) = unLoc $2} + ; tpats <- checkTyVars tparms True -- can have type pats + ; return $ + L (comb4 $1 $2 $4 $5) + (mkTyData (unLoc $1) (ctxt, tc, tvs, tpats) $3 + (reverse (unLoc $5)) (unLoc $6)) } } + +opt_iso :: { Bool } + : { False } + | 'iso' { True } + +kind_or_ctype :: { Either (Located Kind) (LHsType RdrName) } + : '::' kind { Left (LL (unLoc $2)) } + | '=' ctype { Right (LL (unLoc $2)) } + -- Note ctype, not sigtype, on the right of '=' + -- We allow an explicit for-all but we don't insert one + -- in type Foo a = (b,b) + -- Instead we just say b is out of scope data_or_newtype :: { Located NewOrData } : 'data' { L1 DataType } @@ -502,9 +556,9 @@ data_or_newtype :: { Located NewOrData } opt_kind_sig :: { Maybe Kind } : { Nothing } - | '::' kind { Just $2 } + | '::' kind { Just (unLoc $2) } --- tycl_hdr parses the header of a type decl, +-- tycl_hdr parses the header of a class or data type decl, -- which takes the form -- T a b -- Eq a => T a @@ -514,7 +568,7 @@ opt_kind_sig :: { Maybe Kind } tycl_hdr :: { Located (LHsContext RdrName, Located RdrName, [LHsTyVarBndr RdrName], - Maybe [LHsType RdrName]) } + [LHsType RdrName]) } : context '=>' type {% checkTyClHdr $1 $3 >>= return.LL } | type {% checkTyClHdr (noLoc []) $1 >>= return.L1 } @@ -719,7 +773,7 @@ atype :: { LHsType RdrName } | '[' ctype ']' { LL $ HsListTy $2 } | '[:' ctype ':]' { LL $ HsPArrTy $2 } | '(' ctype ')' { LL $ HsParTy $2 } - | '(' ctype '::' kind ')' { LL $ HsKindSig $2 $4 } + | '(' ctype '::' kind ')' { LL $ HsKindSig $2 (unLoc $4) } -- Generics | INTEGER { L1 (HsNumTy (getINTEGER $1)) } @@ -748,7 +802,8 @@ tv_bndrs :: { [LHsTyVarBndr RdrName] } tv_bndr :: { LHsTyVarBndr RdrName } : tyvar { L1 (UserTyVar (unLoc $1)) } - | '(' tyvar '::' kind ')' { LL (KindedTyVar (unLoc $2) $4) } + | '(' tyvar '::' kind ')' { LL (KindedTyVar (unLoc $2) + (unLoc $4)) } fds :: { Located [Located ([RdrName], [RdrName])] } : {- empty -} { noLoc [] } @@ -769,14 +824,14 @@ varids0 :: { Located [RdrName] } ----------------------------------------------------------------------------- -- Kinds -kind :: { Kind } +kind :: { Located Kind } : akind { $1 } - | akind '->' kind { mkArrowKind $1 $3 } + | akind '->' kind { LL (mkArrowKind (unLoc $1) (unLoc $3)) } -akind :: { Kind } - : '*' { liftedTypeKind } - | '!' { unliftedTypeKind } - | '(' kind ')' { $2 } +akind :: { Located Kind } + : '*' { L1 liftedTypeKind } + | '!' { L1 unliftedTypeKind } + | '(' kind ')' { LL (unLoc $2) } -----------------------------------------------------------------------------