{-
-----------------------------------------------------------------------------
-$Id: Parser.y,v 1.70 2001/07/12 16:21:23 simonpj Exp $
+$Id: Parser.y,v 1.82 2002/01/29 09:58:18 simonpj Exp $
Haskell grammar.
-}
{
-module Parser ( parseModule, parseStmt ) where
+module Parser ( parseModule, parseStmt, parseIdentifier ) where
import HsSyn
import HsTypes ( mkHsTupCon )
import OccName ( UserFS, varName, tcName, dataName, tcClsName, tvName )
import SrcLoc ( SrcLoc )
import Module
-import Demand ( StrictnessMark(..) )
import CmdLineOpts ( opt_SccProfilingOn )
-import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..), NewOrData(..) )
+import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
+ NewOrData(..), StrictnessMark(..), Activation(..) )
import Panic
import GlaExts
'__A' { ITarity }
'__P' { ITspecialise }
'__C' { ITnocaf }
- '__U' { ITunfold $$ }
+ '__U' { ITunfold }
'__S' { ITstrict $$ }
'__M' { ITcprinfo $$ }
-}
QVARSYM { ITqvarsym $$ }
QCONSYM { ITqconsym $$ }
- IPVARID { ITipvarid $$ } -- GHC extension
+ IPDUPVARID { ITdupipvarid $$ } -- GHC extension
+ IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
CHAR { ITchar $$ }
STRING { ITstring $$ }
%lexer { lexer } { ITeof }
%name parseModule module
%name parseStmt maybe_stmt
+%name parseIdentifier identifier
%tokentype { Token }
%%
{ RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
| srcloc 'data' ctype constrs deriving
- {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
+ {% checkDataHeader "data" $3 `thenP` \(cs,c,ts) ->
returnP (RdrHsDecl (TyClD
(mkTyData DataType cs c ts (reverse $4) (length $4) $5 $1))) }
| srcloc 'newtype' ctype '=' newconstr deriving
- {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
+ {% checkDataHeader "newtype" $3 `thenP` \(cs,c,ts) ->
returnP (RdrHsDecl (TyClD
(mkTyData NewType cs c ts [$5] 1 $6 $1))) }
| srcloc 'class' ctype fds where
- {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
+ {% checkDataHeader "class" $3 `thenP` \(cs,c,ts) ->
let
(binds,sigs) = cvMonoBindsAndSigs cvClassOpSig (groupBindings $5)
in
decl :: { RdrBinding }
: fixdecl { $1 }
| valdef { $1 }
- | '{-# INLINE' srcloc opt_phase qvar '#-}' { RdrSig (InlineSig $4 $3 $2) }
- | '{-# NOINLINE' srcloc opt_phase qvar '#-}' { RdrSig (NoInlineSig $4 $3 $2) }
+ | '{-# INLINE' srcloc activation qvar '#-}' { RdrSig (InlineSig True $4 $3 $2) }
+ | '{-# NOINLINE' srcloc inverse_activation qvar '#-}' { RdrSig (InlineSig False $4 $3 $2) }
| '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
{ foldr1 RdrAndBindings
(map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
| '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
{ RdrSig (SpecInstSig $4 $2) }
-opt_phase :: { Maybe Int }
- : INTEGER { Just (fromInteger $1) }
- | {- empty -} { Nothing }
-
wherebinds :: { RdrNameHsBinds }
: where { cvBinds cvValSig (groupBindings $1) }
| {- empty -} { RdrNullBind }
rule :: { RdrBinding }
- : STRING rule_forall infixexp '=' srcloc exp
- { RdrHsDecl (RuleD (HsRule $1 [] $2 $3 $6 $5)) }
+ : STRING activation rule_forall infixexp '=' srcloc exp
+ { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
+
+activation :: { Activation } -- Omitted means AlwaysActive
+ : {- empty -} { AlwaysActive }
+ | explicit_activation { $1 }
+
+inverse_activation :: { Activation } -- Omitted means NeverActive
+ : {- empty -} { NeverActive }
+ | explicit_activation { $1 }
+
+explicit_activation :: { Activation } -- In brackets
+ : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
+ | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
rule_forall :: { [RdrNameRuleBndr] }
: 'forall' rule_var_list '.' { $2 }
ext_name :: { Maybe CLabelString }
: STRING { Just $1 }
+ | STRING STRING { Just $2 } -- Ignore "module name" for now
| {- empty -} { Nothing }
-- A ctype is a for-all type
ctype :: { RdrNameHsType }
: 'forall' tyvars '.' ctype { mkHsForAllTy (Just $2) [] $4 }
- | context type { mkHsForAllTy Nothing $1 $2 }
+ | context '=>' type { mkHsForAllTy Nothing $1 $3 }
-- A type of form (context => type) is an *implicit* HsForAllTy
| type { $1 }
newconstr :: { RdrNameConDecl }
: srcloc conid atype { mkConDecl $2 [] [] (VanillaCon [unbangedType $3]) $1 }
- | srcloc conid '{' var '::' type '}'
+ | srcloc conid '{' var '::' ctype '}'
{ mkConDecl $2 [] [] (RecCon [([$4], unbangedType $6)]) $1 }
constrs :: { [RdrNameConDecl] }
| constr { [$1] }
constr :: { RdrNameConDecl }
- : srcloc forall context constr_stuff
- { mkConDecl (fst $4) $2 $3 (snd $4) $1 }
+ : srcloc forall context '=>' constr_stuff
+ { mkConDecl (fst $5) $2 $3 (snd $5) $1 }
| srcloc forall constr_stuff
{ mkConDecl (fst $3) $2 [] (snd $3) $1 }
| {- empty -} { [] }
context :: { RdrNameContext }
- : btype '=>' {% checkContext $1 }
+ : btype {% checkContext $1 }
constr_stuff :: { (RdrName, RdrNameConDetails) }
: btype {% mkVanillaCon $1 [] }
| btype '!' atype satypes {% mkVanillaCon $1 (BangType MarkedUserStrict $3 : $4) }
+ | gtycon '{' '}' {% mkRecCon $1 [] }
| gtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
| sbtype conop sbtype { ($2, InfixCon $1 $3) }
: ctype { unbangedType $1 }
| '!' atype { BangType MarkedUserStrict $2 }
-deriving :: { Maybe [RdrName] }
+deriving :: { Maybe RdrNameContext }
: {- empty -} { Nothing }
- | 'deriving' qtycls { Just [$2] }
- | 'deriving' '(' ')' { Just [] }
- | 'deriving' '(' dclasses ')' { Just (reverse $3) }
-
-dclasses :: { [RdrName] }
- : dclasses ',' qtycls { $3 : $1 }
- | qtycls { [$1] }
+ | 'deriving' context { Just $2 }
+ -- Glasgow extension: allow partial
+ -- applications in derivings
-----------------------------------------------------------------------------
-- Value definitions
exp10 :: { RdrNameHsExpr }
: '\\' srcloc aexp aexps opt_asig '->' srcloc exp
{% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
- returnP (HsLam (Match [] ps $5
+ returnP (HsLam (Match ps $5
(GRHSs (unguardedRHS $8 $7)
EmptyBinds placeHolderType))) }
| 'let' declbinds 'in' exp { HsLet $2 $4 }
: ipvar { HsIPVar $1 }
| var_or_con { $1 }
| literal { HsLit $1 }
- | INTEGER { HsOverLit (HsIntegral $1) }
- | RATIONAL { HsOverLit (HsFractional $1) }
+ | INTEGER { HsOverLit (mkHsIntegral $1) }
+ | RATIONAL { HsOverLit (mkHsFractional $1) }
| '(' exp ')' { HsPar $2 }
| '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
| '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
alt :: { RdrNameMatch }
: srcloc infixexp opt_sig ralt wherebinds
{% (checkPattern $1 $2 `thenP` \p ->
- returnP (Match [] [p] $3
+ returnP (Match [p] $3
(GRHSs $4 $5 placeHolderType)) )}
ralt :: { [RdrNameGRHS] }
-----------------------------------------------------------------------------
-- Implicit Parameter Bindings
-dbinding :: { [(RdrName, RdrNameHsExpr)] }
+dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
: '{' dbinds '}' { $2 }
| layout_on dbinds close { $2 }
-dbinds :: { [(RdrName, RdrNameHsExpr)] }
+dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
: dbinds ';' dbind { $3 : $1 }
| dbinds ';' { $1 }
| dbind { [$1] }
| {- empty -} { [] }
-dbind :: { (RdrName, RdrNameHsExpr) }
+dbind :: { (IPName RdrName, RdrNameHsExpr) }
dbind : ipvar '=' exp { ($1, $3) }
-----------------------------------------------------------------------------
-- Variables, Constructors and Operators.
+identifier :: { RdrName }
+ : qvar { $1 }
+ | gcon { $1 }
+ | qop { $1 }
+
depreclist :: { [RdrName] }
depreclist : deprec_var { [$1] }
| deprec_var ',' depreclist { $1 : $3 }
-- whether it's a qvar or a var can be postponed until
-- *after* we see the close paren.
-ipvar :: { RdrName }
- : IPVARID { (mkUnqual varName (tailFS $1)) }
+ipvar :: { IPName RdrName }
+ : IPDUPVARID { Dupable (mkUnqual varName $1) }
+ | IPSPLITVARID { Linear (mkUnqual varName $1) }
qcon :: { RdrName }
: qconid { $1 }