| HsWith (HsExpr id pat) -- implicit parameter binding
[(IPName id, HsExpr id pat)]
+ Bool -- True <=> this was a 'with' binding
+ -- (tmp, until 'with' is removed)
| HsDo HsDoContext
[Stmt id pat] -- "do":one or more stmts
= sep [hang (ptext SLIT("let")) 2 (pprBinds binds),
hang (ptext SLIT("in")) 2 (ppr expr)]
-ppr_expr (HsWith expr binds)
- = hsep [ppr expr, ptext SLIT("with"), pp_ipbinds binds]
+ppr_expr (HsWith expr binds is_with)
+ = sep [hang (ptext SLIT("let")) 2 (pp_ipbinds binds),
+ hang (ptext SLIT("in")) 2 (ppr expr)]
ppr_expr (HsDo do_or_list_comp stmts _) = pprDo do_or_list_comp stmts
ppr_expr (HsDoOut do_or_list_comp stmts _ _ _ _ _) = pprDo do_or_list_comp stmts
{- -*-haskell-*-
-----------------------------------------------------------------------------
-$Id: Parser.y,v 1.94 2002/03/28 09:59:03 simonmar Exp $
+$Id: Parser.y,v 1.95 2002/04/02 13:56:32 simonmar Exp $
Haskell grammar.
(don't know whether to reduce 'a' as a btype or shift the '->'.
conclusion: bogus expression anyway, doesn't matter)
+1 for ambiguity in '{-# RULES "name" [ ... #-}
+ we don't know whether the '[' starts the activation or not: it
+ might be the start of the declaration with the activation being
+ empty. --SDM 1/4/2002
+
1 for ambiguity in '{-# RULES "name" forall = ... #-}'
since 'forall' is a valid variable name, we don't know whether
to treat a forall on the input as the beginning of a quantifier
This saves explicitly defining a grammar for the rule lhs that
doesn't include 'forall'.
-1 for ambiguity in 'x @ Rec{..}'.
- Only sensible parse is 'x @ (Rec{..})', which is what resolving
- to shift gives us.
+1 for ambiguity in 'let ?x ...'
+ the parser can't tell whether the ?x is the lhs of a normal binding or
+ an implicit binding. Fortunately resolving as shift gives it the only
+ sensible meaning, namely the lhs of an implicit binding.
6 for conflicts between `fdecl' and `fdeclDEPRECATED', which are resolved
correctly, and moreover, should go away when `fdeclDEPRECATED' is removed.
: '{' decls '}' { $2 }
| layout_on decls close { $2 }
+letbinds :: { RdrNameHsExpr -> RdrNameHsExpr }
+ : decllist { HsLet (cvBinds cvValSig (groupBindings $1)) }
+ | '{' dbinds '}' { \e -> HsWith e $2 False{-not with-} }
+ | layout_on dbinds close { \e -> HsWith e $2 False{-not with-} }
+
fixdecl :: { RdrBinding }
: srcloc infix prec ops { foldr1 RdrAndBindings
[ RdrSig (FixSig (FixitySig n
exp :: { RdrNameHsExpr }
: infixexp '::' sigtype { (ExprWithTySig $1 $3) }
- | infixexp 'with' dbinding { HsWith $1 $3 }
+ | infixexp 'with' dbinding { HsWith $1 $3 True{-not a let-} }
| infixexp { $1 }
infixexp :: { RdrNameHsExpr }
returnP (HsLam (Match ps $5
(GRHSs (unguardedRHS $8 $7)
EmptyBinds placeHolderType))) }
- | 'let' declbinds 'in' exp { HsLet $2 $4 }
+ | 'let' letbinds 'in' exp { $2 $4 }
| 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
| 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
| '-' fexp { mkHsNegApp $2 }
| {- empty -} { [] }
aexp :: { RdrNameHsExpr }
+ : qvar '@' aexp { EAsPat $1 $3 }
+ | '~' aexp { ELazyPat $2 }
+ | aexp1 { $1 }
+
+aexp1 :: { RdrNameHsExpr }
: var_or_con '{|' gentype '|}' { (HsApp $1 (HsType $3)) }
- | aexp '{' fbinds '}' {% (mkRecConstrOrUpdate $1
+ | aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1
(reverse $3)) }
- | aexp1 { $1 }
+ | aexp2 { $1 }
var_or_con :: { RdrNameHsExpr }
: qvar { HsVar $1 }
| gcon { HsVar $1 }
-aexp1 :: { RdrNameHsExpr }
+aexp2 :: { RdrNameHsExpr }
: ipvar { HsIPVar $1 }
| var_or_con { $1 }
| literal { HsLit $1 }
| '[:' parr ':]' { $2 }
| '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
| '(' qopm infixexp ')' { (SectionR $2 $3) }
- | qvar '@' aexp { EAsPat $1 $3 }
| '_' { EWildPat }
- | '~' aexp1 { ELazyPat $2 }
texps :: { [RdrNameHsExpr] }
: texps ',' exp { $3 : $1 }
: dbinds ';' dbind { $3 : $1 }
| dbinds ';' { $1 }
| dbind { [$1] }
- | {- empty -} { [] }
+-- | {- empty -} { [] }
dbind :: { (IPName RdrName, RdrNameHsExpr) }
dbind : ipvar '=' exp { ($1, $3) }
rnExpr expr `thenRn` \ (expr',fvExpr) ->
returnRn (HsLet binds' expr', fvExpr)
-rnExpr (HsWith expr binds)
- = rnExpr expr `thenRn` \ (expr',fvExpr) ->
+rnExpr (HsWith expr binds is_with)
+ = warnCheckRn (not is_with) withWarning `thenRn_`
+ rnExpr expr `thenRn` \ (expr',fvExpr) ->
rnIPBinds binds `thenRn` \ (binds',fvBinds) ->
- returnRn (HsWith expr' binds', fvExpr `plusFV` fvBinds)
+ returnRn (HsWith expr' binds' is_with, fvExpr `plusFV` fvBinds)
rnExpr e@(HsDo do_or_lc stmts src_loc)
= pushSrcLocRn src_loc $
bogusCharError c
= ptext SLIT("character literal out of range: '\\") <> int c <> char '\''
+
+withWarning
+ = sep [quotes (ptext SLIT("with")),
+ ptext SLIT("is deprecated, use"),
+ quotes (ptext SLIT("let")),
+ ptext SLIT("instead")]
\end{code}