{- -*-haskell-*-
-----------------------------------------------------------------------------
-$Id: Parser.y,v 1.124 2003/09/23 14:33:02 simonmar Exp $
+$Id: Parser.y,v 1.131 2003/11/27 13:26:39 simonmar Exp $
Haskell grammar.
#include "HsVersions.h"
import HsSyn
-import HsTypes ( mkHsTupCon )
-
import RdrHsSyn
-import HscTypes ( ParsedIface(..), IsBootInterface, noDependencies )
+import HscTypes ( ModIface, IsBootInterface, DeprecTxt )
import Lexer
import RdrName
-import PrelNames ( mAIN_Name, funTyConName, listTyConName,
- parrTyConName, consDataConName )
-import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon,
- tupleCon, nilDataCon )
+import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataCon,
+ listTyCon_RDR, parrTyCon_RDR, consDataCon_RDR )
+import Type ( funTyCon )
import ForeignCall ( Safety(..), CExportSpec(..),
- CCallConv(..), CCallTarget(..), defaultCCallConv,
+ CCallConv(..), CCallTarget(..), defaultCCallConv
)
-import OccName ( UserFS, varName, tcName, dataName, tcClsName, tvName )
-import TyCon ( DataConDetails(..) )
+import OccName ( UserFS, varName, dataName, tcClsName, tvName )
import DataCon ( DataCon, dataConName )
-import SrcLoc ( SrcLoc )
+import SrcLoc ( SrcLoc, noSrcLoc )
import Module
-import CmdLineOpts ( opt_SccProfilingOn, opt_InPackage )
+import CmdLineOpts ( opt_SccProfilingOn )
import Type ( Kind, mkArrowKind, liftedTypeKind )
-import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..),
- IPName(..), NewOrData(..), StrictnessMark(..),
- Activation(..), FixitySig(..) )
+import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
+ NewOrData(..), Activation(..) )
import Panic
import GLAEXTS
'safe' { T _ _ ITsafe }
'threadsafe' { T _ _ ITthreadsafe }
'unsafe' { T _ _ ITunsafe }
- 'with' { T _ _ ITwith }
'mdo' { T _ _ ITmdo }
'stdcall' { T _ _ ITstdcallconv }
'ccall' { T _ _ ITccallconv }
'{-# CORE' { T _ _ ITcore_prag } -- hdaume: annotated core
'{-# SCC' { T _ _ ITscc_prag }
'{-# DEPRECATED' { T _ _ ITdeprecated_prag }
+ '{-# UNPACK' { T _ _ ITunpack_prag }
'#-}' { T _ _ ITclose_prag }
'..' { T _ _ ITdotdot } -- reserved symbols
'[t|' { T _ _ ITopenTypQuote }
'[d|' { T _ _ ITopenDecQuote }
'|]' { T _ _ ITcloseQuote }
-ID_SPLICE { T _ _ (ITidEscape $$) } -- $x
+TH_ID_SPLICE { T _ _ (ITidEscape $$) } -- $x
'$(' { T _ _ ITparenEscape } -- $( exp )
-REIFY_TYPE { T _ _ ITreifyType }
-REIFY_DECL { T _ _ ITreifyDecl }
-REIFY_FIXITY { T _ _ ITreifyFixity }
+TH_VAR_QUOTE { T _ _ ITvarQuote } -- 'x
+TH_TY_QUOTE { T _ _ ITtyQuote } -- ''T
%monad { P } { >>= } { return }
%lexer { lexer } { T _ _ ITeof }
-----------------------------------------------------------------------------
-- Interfaces (.hi-boot files)
-iface :: { ParsedIface }
- : 'module' modid 'where' ifacebody
- { ParsedIface {
- pi_mod = $2,
- pi_pkg = opt_InPackage,
- pi_vers = 1, -- Module version
- pi_orphan = False,
- pi_exports = (1,[($2,mkIfaceExports $4)]),
- pi_deps = noDependencies,
- pi_usages = [],
- pi_fixity = [],
- pi_insts = [],
- pi_decls = map (\x -> (1,x)) $4,
- pi_rules = (1,[]),
- pi_deprecs = Nothing
- }
- }
-
-ifacebody :: { [RdrNameTyClDecl] }
+iface :: { ModIface }
+ : 'module' modid 'where' ifacebody { mkBootIface $2 $4 }
+
+ifacebody :: { [HsDecl RdrName] }
: '{' ifacedecls '}' { $2 }
| vocurly ifacedecls close { $2 }
-ifacedecls :: { [RdrNameTyClDecl] }
+ifacedecls :: { [HsDecl RdrName] }
: ifacedecl ';' ifacedecls { $1 : $3 }
| ';' ifacedecls { $2 }
| ifacedecl { [$1] }
| {- empty -} { [] }
-ifacedecl :: { RdrNameTyClDecl }
- : tycl_decl { $1 }
- | srcloc var '::' sigtype { IfaceSig $2 $4 [] $1 }
+ifacedecl :: { HsDecl RdrName }
+ : var '::' sigtype
+ { SigD (Sig $1 $3 noSrcLoc) }
+ | 'type' syn_hdr '=' ctype
+ { let (tc,tvs) = $2 in TyClD (TySynonym tc tvs $4 noSrcLoc) }
+ | new_or_data tycl_hdr
+ { TyClD (mkTyData $1 $2 [] Nothing noSrcLoc) }
+ | 'class' tycl_hdr fds
+ { TyClD (mkClassDecl $2 $3 [] EmptyMonoBinds noSrcLoc) }
+
+new_or_data :: { NewOrData }
+ : 'data' { DataType }
+ | 'newtype' { NewType }
-----------------------------------------------------------------------------
-- The Export List
: tycl_decl { RdrHsDecl (TyClD $1) }
| srcloc 'instance' inst_type where
{ let (binds,sigs) = cvMonoBindsAndSigs $4
- in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
+ in RdrHsDecl (InstD (InstDecl $3 binds sigs $1)) }
| srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
| 'foreign' fdecl { RdrHsDecl $2 }
| '{-# DEPRECATED' deprecations '#-}' { RdrBindings (reverse $2) }
-- Instead we just say b is out of scope
{ let (tc,tvs) = $3 in TySynonym tc tvs $5 $1 }
-
| srcloc 'data' tycl_hdr constrs deriving
- { mkTyData DataType $3 (DataCons (reverse $4)) $5 $1 }
+ { mkTyData DataType $3 (reverse $4) $5 $1 }
| srcloc 'newtype' tycl_hdr '=' newconstr deriving
- { mkTyData NewType $3 (DataCons [$5]) $6 $1 }
+ { mkTyData NewType $3 [$5] $6 $1 }
| srcloc 'class' tycl_hdr fds where
{ let
(binds,sigs) = cvMonoBindsAndSigs $5
in
- mkClassDecl $3 $4 sigs (Just binds) $1 }
+ mkClassDecl $3 $4 sigs binds $1 }
syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
-- type synonym declaration. Oh well.
-- (Eq a, Ord b) => T a b
-- Rather a lot of inlining here, else we get reduce/reduce errors
tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
- : context '=>' type {% checkTyClHdr $3 >>= \ (tc,tvs) ->
- return ($1, tc, tvs) }
- | type {% checkTyClHdr $1 >>= \ (tc,tvs) ->
- return ([], tc, tvs) }
+ : context '=>' type {% checkTyClHdr $1 $3 }
+ | type {% checkTyClHdr [] $1 }
-----------------------------------------------------------------------------
-- Nested declarations
binds :: { RdrNameHsBinds } -- May have implicit parameters
: decllist { cvBinds $1 }
- | '{' dbinds '}' { IPBinds $2 False{-not with-} }
- | vocurly dbinds close { IPBinds $2 False{-not with-} }
+ | '{' dbinds '}' { IPBinds $2 }
+ | vocurly dbinds close { IPBinds $2 }
wherebinds :: { RdrNameHsBinds } -- May have implicit parameters
: 'where' binds { $2 }
| sigtypes ',' sigtype { $3 : $1 }
sigtype :: { RdrNameHsType }
- : ctype { mkHsForAllTy Nothing [] $1 }
+ : ctype { mkImplicitHsForAllTy [] $1 }
+ -- Wrap an Implicit forall if there isn't one there already
sig_vars :: { [RdrName] }
: sig_vars ',' var { $3 : $1 }
-- A ctype is a for-all type
ctype :: { RdrNameHsType }
- : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
- | context '=>' type { mkHsForAllTy Nothing $1 $3 }
+ : 'forall' tv_bndrs '.' ctype { mkExplicitHsForAllTy $2 [] $4 }
+ | context '=>' type { mkImplicitHsForAllTy $1 $3 }
-- A type of form (context => type) is an *implicit* HsForAllTy
| type { $1 }
gentype :: { RdrNameHsType }
: btype { $1 }
- | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
- | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
- | btype '->' gentype { HsOpTy $1 HsArrow $3 }
+ | btype qtyconop gentype { HsOpTy $1 $2 $3 }
+ | btype '`' tyvar '`' gentype { HsOpTy $1 $3 $5 }
+ | btype '->' gentype { HsFunTy $1 $3 }
btype :: { RdrNameHsType }
: btype atype { HsAppTy $1 $2 }
atype :: { RdrNameHsType }
: gtycon { HsTyVar $1 }
| tyvar { HsTyVar $1 }
- | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
- | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
+ | '(' type ',' comma_types1 ')' { HsTupleTy Boxed ($2:$4) }
+ | '(#' comma_types1 '#)' { HsTupleTy Unboxed $2 }
| '[' type ']' { HsListTy $2 }
| '[:' type ':]' { HsPArrTy $2 }
| '(' ctype ')' { HsParTy $2 }
tv_bndr :: { RdrNameHsTyVar }
: tyvar { UserTyVar $1 }
- | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
+ | '(' tyvar '::' kind ')' { KindedTyVar $2 $4 }
fds :: { [([RdrName], [RdrName])] }
: {- empty -} { [] }
: ctype { unbangedType $1 }
| strict_mark atype { BangType $1 $2 }
-strict_mark :: { StrictnessMark }
- : '!' { MarkedUserStrict }
- | '!' '!' { MarkedUserUnboxed }
+strict_mark :: { HsBang }
+ : '!' { HsStrict }
+ | '{-# UNPACK' '#-}' '!' { HsUnbox }
deriving :: { Maybe RdrNameContext }
: {- empty -} { Nothing }
exp :: { RdrNameHsExpr }
: infixexp '::' sigtype { ExprWithTySig $1 $3 }
- | infixexp 'with' dbinding { HsLet (IPBinds $3 True{-not a let-}) $1 }
| fexp srcloc '-<' exp { HsArrApp $1 $4 placeHolderType HsFirstOrderApp True $2 }
| fexp srcloc '>-' exp { HsArrApp $4 $1 placeHolderType HsFirstOrderApp False $2 }
| fexp srcloc '-<<' exp { HsArrApp $1 $4 placeHolderType HsHigherOrderApp True $2 }
| '{-# CORE' STRING '#-}' exp { HsCoreAnn $2 $4 } -- hdaume: core annotation
- | reifyexp { HsReify $1 }
| fexp { $1 }
scc_annot :: { FastString }
: '_scc_' STRING { $2 }
| '{-# SCC' STRING '#-}' { $2 }
-ccallid :: { FastString }
- : VARID { $1 }
- | CONID { $1 }
-
fexp :: { RdrNameHsExpr }
- : fexp aexp { (HsApp $1 $2) }
+ : fexp aexp { HsApp $1 $2 }
| aexp { $1 }
-reifyexp :: { HsReify RdrName }
- : REIFY_DECL gtycon { Reify ReifyDecl $2 }
- | REIFY_DECL qvar { Reify ReifyDecl $2 }
- | REIFY_TYPE qcname { Reify ReifyType $2 }
- | REIFY_FIXITY qcname { Reify ReifyFixity $2 }
-
-aexps0 :: { [RdrNameHsExpr] }
- : aexps { reverse $1 }
-
aexps :: { [RdrNameHsExpr] }
: aexps aexp { $2 : $1 }
| {- empty -} { [] }
| aexp1 { $1 }
aexp1 :: { RdrNameHsExpr }
- : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
+ : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
| aexp2 { $1 }
-- Here was the syntax for type applications that I was planning
-- but there are difficulties (e.g. what order for type args)
-- so it's not enabled yet.
- | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
+-- But this case *is* used for the left hand side of a generic definition,
+-- which is parsed as an expression before being munged into a pattern
+ | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
aexp2 :: { RdrNameHsExpr }
: ipvar { HsIPVar $1 }
| '_' { EWildPat }
-- MetaHaskell Extension
- | srcloc ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
+ | srcloc TH_ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
| srcloc '$(' exp ')' { mkHsSplice $3 $1 } -- $( exp )
+ | srcloc TH_VAR_QUOTE qvar { HsBracket (VarBr $3) $1 }
+ | srcloc TH_VAR_QUOTE qcon { HsBracket (VarBr $3) $1 }
+ | srcloc TH_TY_QUOTE tyvar { HsBracket (VarBr $3) $1 }
+ | srcloc TH_TY_QUOTE gtycon { HsBracket (VarBr $3) $1 }
| srcloc '[|' exp '|]' { HsBracket (ExpBr $3) $1 }
| srcloc '[t|' ctype '|]' { HsBracket (TypBr $3) $1 }
| srcloc '[p|' infixexp '|]' {% checkPattern $1 $3 >>= \p ->
-----------------------------------------------------------------------------
-- Record Field Update/Construction
-fbinds :: { RdrNameHsRecordBinds }
- : fbinds ',' fbind { $3 : $1 }
- | fbinds ',' { $1 }
- | fbind { [$1] }
+fbinds :: { RdrNameHsRecordBinds }
+ : fbinds1 { $1 }
| {- empty -} { [] }
+fbinds1 :: { RdrNameHsRecordBinds }
+ : fbinds1 ',' fbind { $3 : $1 }
+ | fbind { [$1] }
+
fbind :: { (RdrName, RdrNameHsExpr) }
: qvar '=' exp { ($1,$3) }
-----------------------------------------------------------------------------
-- Implicit Parameter Bindings
-dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
- : '{' dbinds '}' { $2 }
- | vocurly dbinds close { $2 }
-
dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
: dbinds ';' dbind { $3 : $1 }
| dbinds ';' { $1 }
: oqtycon { $1 }
| '(' ')' { getRdrName unitTyCon }
| '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
- | '(' '->' ')' { nameRdrName funTyConName }
- | '[' ']' { nameRdrName listTyConName }
- | '[:' ':]' { nameRdrName parrTyConName }
+ | '(' '->' ')' { getRdrName funTyCon }
+ | '[' ']' { listTyCon_RDR }
+ | '[:' ':]' { parrTyCon_RDR }
oqtycon :: { RdrName } -- An "ordinary" qualified tycon
: qtycon { $1 }
: CONSYM { mkUnqual dataName $1 }
-- ':' means only list cons
- | ':' { nameRdrName consDataConName }
- -- NB: SrcName because we are reading source
+ | ':' { consDataCon_RDR }
-----------------------------------------------------------------------------