[project @ 2005-07-28 11:19:03 by simonmar]
[ghc-hetmet.git] / ghc / compiler / parser / ParserCore.y
index 757d5e3..5992810 100644 (file)
@@ -8,12 +8,11 @@ import HsSyn
 import RdrName
 import OccName
 import Kind( Kind(..) )
-import Name( nameOccName, nameModuleName )
+import Name( nameOccName, nameModule )
 import Module
 import ParserCoreUtils
 import LexCore
 import Literal
-import BasicTypes
 import SrcLoc
 import TysPrim( wordPrimTyCon, intPrimTyCon, charPrimTyCon, 
                floatPrimTyCon, doublePrimTyCon, addrPrimTyCon )
@@ -70,11 +69,10 @@ import Char
 %%
 
 module :: { HsExtCore RdrName }
-         : '%module' modid tdefs vdefgs
-               { HsExtCore (mkHomeModule $2) $3 $4 }
+         : '%module' modid tdefs vdefgs { HsExtCore $2 $3 $4 }
 
-modid  :: { ModuleName }
-       : CNAME                  { mkSysModuleNameFS (mkFastString $1) }
+modid  :: { Module }
+       : CNAME                  { mkSysModuleFS (mkFastString $1) }
 
 -------------------------------------------------------------
 --     Type and newtype declarations are in HsSyn syntax
@@ -85,17 +83,17 @@ tdefs       :: { [TyClDecl RdrName] }
 
 tdef   :: { TyClDecl RdrName }
        : '%data' q_tc_name tv_bndrs '=' '{' cons1 '}'
-                { mkTyData DataType (noLoc [], noLoc (ifaceExtRdrName $2), map toHsTvBndr $3) $6 Nothing }
+                { mkTyData DataType (noLoc (noLoc [], noLoc (ifaceExtRdrName $2), map toHsTvBndr $3)) Nothing $6 Nothing }
        | '%newtype' q_tc_name tv_bndrs trep 
                { let tc_rdr = ifaceExtRdrName $2 in
-                  mkTyData NewType (noLoc [], noLoc tc_rdr, map toHsTvBndr $3) ($4 (rdrNameOcc tc_rdr)) Nothing }
+                  mkTyData NewType (noLoc (noLoc [], noLoc tc_rdr, map toHsTvBndr $3)) Nothing ($4 (rdrNameOcc tc_rdr)) Nothing }
 
 -- For a newtype we have to invent a fake data constructor name
 -- It doesn't matter what it is, because it won't be used
 trep    :: { OccName -> [LConDecl RdrName] }
         : {- empty -}   { (\ tc_occ -> []) }
         | '=' ty        { (\ tc_occ -> let { dc_name  = mkRdrUnqual (setOccNameSpace dataName tc_occ) ;
-                                             con_info = PrefixCon [unbangedType (toHsType $2)] }
+                                            con_info = PrefixCon [toHsType $2] }
                                        in [noLoc $ ConDecl (noLoc dc_name) []
                                           (noLoc []) con_info]) }
 
@@ -105,7 +103,9 @@ cons1       :: { [LConDecl RdrName] }
 
 con    :: { LConDecl RdrName }
        : d_pat_occ attv_bndrs hs_atys 
-               { noLoc $ ConDecl (noLoc (mkRdrUnqual $1)) $2 (noLoc []) (PrefixCon (map unbangedType $3))}
+               { noLoc $ ConDecl (noLoc (mkRdrUnqual $1)) $2 (noLoc []) (PrefixCon $3)}
+        | d_pat_occ '::' ty
+                { noLoc $ GadtDecl (noLoc (mkRdrUnqual $1)) (toHsType $3) } 
 
 attv_bndrs :: { [LHsTyVarBndr RdrName] }
        : {- empty -}            { [] }
@@ -131,6 +131,7 @@ aty :: { IfaceType }
 bty    :: { IfaceType }
        : tv_occ atys    { foldl IfaceAppTy (IfaceTyVar $1) $2 }
         | q_tc_name atys  { IfaceTyConApp (IfaceTc $1) $2 }
+        | '(' ty ')' { $2 }
 
 ty     :: { IfaceType }
        : bty                        { $1 }
@@ -218,8 +219,9 @@ exp :: { IfaceExpr }
        : fexp                        { $1 }
        | '\\' bndrs '->' exp         { foldr IfaceLam $4 $2 }
        | '%let' let_bind '%in' exp   { IfaceLet $2 $4 }
-       | '%case' aexp '%of' id_bndr
-         '{' alts1 '}'               { IfaceCase $2 (fst $4) $6 }
+-- gaw 2004
+       | '%case' '(' ty ')' aexp '%of' id_bndr
+         '{' alts1 '}'               { IfaceCase $5 (fst $7) $3 $9 }
        | '%coerce' aty exp           { IfaceNote (IfaceCoerce $2) $3 }
        | '%note' STRING exp       
            { case $2 of
@@ -297,7 +299,7 @@ convRatLit i aty
 
 eqTc :: IfaceTyCon -> TyCon -> Bool   -- Ugh!
 eqTc (IfaceTc (ExtPkg mod occ)) tycon
-  = mod == nameModuleName nm && occ == nameOccName nm
+  = mod == nameModule nm && occ == nameOccName nm
   where
     nm = tyConName tycon