diff options
Diffstat (limited to 'compiler/parser')
| -rw-r--r-- | compiler/parser/Lexer.x | 1 | ||||
| -rw-r--r-- | compiler/parser/Parser.y.pp | 20 | ||||
| -rw-r--r-- | compiler/parser/RdrHsSyn.lhs | 46 | 
3 files changed, 26 insertions, 41 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index a2d2276901..46f7488dcc 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -1893,6 +1893,7 @@ mkPState flags buf loc =                 .|. unboxedTuplesBit  `setBitIf` xopt Opt_UnboxedTuples   flags                 .|. datatypeContextsBit `setBitIf` xopt Opt_DatatypeContexts flags                 .|. transformComprehensionsBit `setBitIf` xopt Opt_TransformListComp flags +               .|. transformComprehensionsBit `setBitIf` xopt Opt_MonadComprehensions flags                 .|. rawTokenStreamBit `setBitIf` dopt Opt_KeepRawTokenStream flags                 .|. alternativeLayoutRuleBit `setBitIf` xopt Opt_AlternativeLayoutRule flags                 .|. relaxedLayoutBit  `setBitIf` xopt Opt_RelaxedLayout flags diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp index bfadfbaff8..aa20ea6799 100644 --- a/compiler/parser/Parser.y.pp +++ b/compiler/parser/Parser.y.pp @@ -1283,14 +1283,9 @@ exp10 :: { LHsExpr RdrName }     	| 'case' exp 'of' altslist		{ LL $ HsCase $2 (mkMatchGroup (unLoc $4)) }  	| '-' fexp				{ LL $ NegApp $2 noSyntaxExpr } -  	| 'do' stmtlist			{% let loc = comb2 $1 $2 in -					   checkDo loc (unLoc $2)  >>= \ (stmts,body) -> -					   return (L loc (mkHsDo DoExpr stmts body)) } -  	| 'mdo' stmtlist		{% let loc = comb2 $1 $2 in -					   checkDo loc (unLoc $2)  >>= \ (stmts,body) -> -                                           return (L loc (mkHsDo MDoExpr -                                                                 [L loc (mkRecStmt stmts)] -                                                                 body)) } +  	| 'do' stmtlist			{ L (comb2 $1 $2) (mkHsDo DoExpr  (unLoc $2)) } +  	| 'mdo' stmtlist		{ L (comb2 $1 $2) (mkHsDo MDoExpr (unLoc $2)) } +          | scc_annot exp		    		{ LL $ if opt_SccProfilingOn  							then HsSCC (unLoc $1) $2  							else HsPar $2 } @@ -1465,7 +1460,10 @@ list :: { LHsExpr RdrName }  	| texp ',' exp '..' 	{ LL $ ArithSeq noPostTcExpr (FromThen $1 $3) }  	| texp '..' exp	 	{ LL $ ArithSeq noPostTcExpr (FromTo $1 $3) }  	| texp ',' exp '..' exp	{ LL $ ArithSeq noPostTcExpr (FromThenTo $1 $3 $5) } -	| texp '|' flattenedpquals	{ sL (comb2 $1 $>) $ mkHsDo ListComp (unLoc $3) $1 } +	| texp '|' flattenedpquals	 +             {% checkMonadComp >>= \ ctxt -> +		return (sL (comb2 $1 $>) $  +                        mkHsComp ctxt (unLoc $3) $1) }  lexps :: { Located [LHsExpr RdrName] }  	: lexps ',' texp 		{ LL (((:) $! $3) $! unLoc $1) } @@ -1480,7 +1478,7 @@ flattenedpquals :: { Located [LStmt RdrName] }                      -- We just had one thing in our "parallel" list so                       -- we simply return that thing directly -                    qss -> L1 [L1 $ ParStmt [(qs, undefined) | qs <- qss]] +                    qss -> L1 [L1 $ ParStmt [(qs, undefined) | qs <- qss] noSyntaxExpr noSyntaxExpr noSyntaxExpr]                      -- We actually found some actual parallel lists so                      -- we wrap them into as a ParStmt                  } @@ -1537,7 +1535,7 @@ parr :: { LHsExpr RdrName }  						       (reverse (unLoc $1)) }  	| texp '..' exp	 		{ LL $ PArrSeq noPostTcExpr (FromTo $1 $3) }  	| texp ',' exp '..' exp		{ LL $ PArrSeq noPostTcExpr (FromThenTo $1 $3 $5) } -	| texp '|' flattenedpquals	{ LL $ mkHsDo PArrComp (unLoc $3) $1 } +	| texp '|' flattenedpquals	{ LL $ mkHsComp PArrComp (unLoc $3) $1 }  -- We are reusing `lexps' and `flattenedpquals' from the list case. diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs index 47abf232e2..3b14990ec0 100644 --- a/compiler/parser/RdrHsSyn.lhs +++ b/compiler/parser/RdrHsSyn.lhs @@ -40,8 +40,7 @@ module RdrHsSyn (  	checkPattern,	      -- HsExp -> P HsPat  	bang_RDR,  	checkPatterns,	      -- SrcLoc -> [HsExp] -> P [HsPat] -	checkDo,	      -- [Stmt] -> P [Stmt] -	checkMDo,	      -- [Stmt] -> P [Stmt] +	checkMonadComp,       -- P (HsStmtContext RdrName)  	checkValDef,	      -- (SrcLoc, HsExp, HsRhs, [HsDecl]) -> P HsDecl  	checkValSig,	      -- (SrcLoc, HsExp, HsRhs, [HsDecl]) -> P HsDecl  	checkDoAndIfThenElse, @@ -54,6 +53,7 @@ import Class            ( FunDep )  import TypeRep          ( Kind )  import RdrName		( RdrName, isRdrTyVar, isRdrTc, mkUnqual, rdrNameOcc,   			  isRdrDataCon, isUnqual, getRdrName, setRdrNameSpace ) +import Name             ( Name )  import BasicTypes	( maxPrecedence, Activation(..), RuleMatchInfo,                            InlinePragma(..), InlineSpec(..) )  import Lexer @@ -611,34 +611,6 @@ checkPred (L spn ty)      check loc _                        _    = parseErrorSDoc loc                                  (text "malformed class assertion:" <+> ppr ty) ---------------------------------------------------------------------------- --- Checking statements in a do-expression --- 	We parse   do { e1 ; e2 ; } --- 	as [ExprStmt e1, ExprStmt e2] --- checkDo (a) checks that the last thing is an ExprStmt ---	   (b) returns it separately --- same comments apply for mdo as well - -checkDo, checkMDo :: SrcSpan -> [LStmt RdrName] -> P ([LStmt RdrName], LHsExpr RdrName) - -checkDo	 = checkDoMDo "a " "'do'" -checkMDo = checkDoMDo "an " "'mdo'" - -checkDoMDo :: String -> String -> SrcSpan -> [LStmt RdrName] -> P ([LStmt RdrName], LHsExpr RdrName) -checkDoMDo _   nm loc []   = parseErrorSDoc loc (text ("Empty " ++ nm ++ " construct")) -checkDoMDo pre nm _   ss   = do -  check ss -  where  -	check  []                     = panic "RdrHsSyn:checkDoMDo" -	check  [L _ (ExprStmt e _ _)] = return ([], e) -	check  [L l e] = parseErrorSDoc l -                         (text ("The last statement in " ++ pre ++ nm ++ -					            " construct must be an expression:") -                       $$ ppr e) -	check (s:ss) = do -	  (ss',e') <-  check ss -	  return ((s:ss'),e') -  -- -------------------------------------------------------------------------  -- Checking Patterns. @@ -912,6 +884,20 @@ isFunLhs e = go e []  		 _ -> return Nothing }     go _ _ = return Nothing + +--------------------------------------------------------------------------- +-- Check for monad comprehensions +-- +-- If the flag MonadComprehensions is set, return a `MonadComp' context, +-- otherwise use the usual `ListComp' context + +checkMonadComp :: P (HsStmtContext Name) +checkMonadComp = do +    pState <- getPState +    return $ if xopt Opt_MonadComprehensions (dflags pState) +                then MonadComp +                else ListComp +  ---------------------------------------------------------------------------  -- Miscellaneous utilities  | 
