Commit 64557b45 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Warn about top-level bangs (Trac #4477)

A simple refactoring in the parser
parent 3b2b4836
...@@ -1208,15 +1208,20 @@ docdecld :: { LDocDecl } ...@@ -1208,15 +1208,20 @@ docdecld :: { LDocDecl }
| docsection { L1 (case (unLoc $1) of (n, doc) -> DocGroup n doc) } | docsection { L1 (case (unLoc $1) of (n, doc) -> DocGroup n doc) }
decl :: { Located (OrdList (LHsDecl RdrName)) } decl :: { Located (OrdList (LHsDecl RdrName)) }
: sigdecl { $1 } : sigdecl { $1 }
| '!' aexp rhs {% do { pat <- checkPattern $2;
return (LL $ unitOL $ LL $ ValD ( | '!' aexp rhs {% do { let { e = LL (SectionR (LL (HsVar bang_RDR)) $2) };
PatBind (LL $ BangPat pat) (unLoc $3) pat <- checkPattern e;
placeHolderType placeHolderNames)) } } return $ LL $ unitOL $ LL $ ValD $
| infixexp opt_sig rhs {% do { r <- checkValDef $1 $2 $3; PatBind pat (unLoc $3)
let { l = comb2 $1 $> }; placeHolderType placeHolderNames } }
return $! (sL l (unitOL $! (sL l $ ValD r))) } } -- Turn it all into an expression so that
| docdecl { LL $ unitOL $1 } -- checkPattern can check that bangs are enabled
| infixexp opt_sig rhs {% do { r <- checkValDef $1 $2 $3;
let { l = comb2 $1 $> };
return $! (sL l (unitOL $! (sL l $ ValD r))) } }
| docdecl { LL $ unitOL $1 }
rhs :: { Located (GRHSs RdrName) } rhs :: { Located (GRHSs RdrName) }
: '=' exp wherebinds { sL (comb3 $1 $2 $3) $ GRHSs (unguardedRHS $2) (unLoc $3) } : '=' exp wherebinds { sL (comb3 $1 $2 $3) $ GRHSs (unguardedRHS $2) (unLoc $3) }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment