Ticket #114: LambdaMatch.hunk

File LambdaMatch.hunk, 1.3 KB (added by claus, 7 years ago)

updated syntax patch for GHC: be conservative, require parentheses

Line 
1{
2hunk ./compiler/parser/Parser.y.pp 1181
3+-- we could probably allow this in texp as well, [_$_]
4+--  but for list, where texp is followed by pquals..
5+-- what about rhs?
6+-- we probably need to rearrange the grammar if we want to be more specific?
7+expOrLambdaMatch :: { LHsExpr RdrName }
8+       : '|' aexp aexps opt_asig ralt [_$_]
9+                       {% checkPatterns ($2 : reverse $3) >>= \ ps -> do
10+         let lift (L _ (GRHS gd e)) = [_$_]
11+              LL (GRHS gd (mkHsApp (nlHsVar $ mkUnqual dataName FSLIT("Match"))
12+                           (mkHsApp (nlHsVar $ mkUnqual varName FSLIT("return"))
13+                            e))) [_$_]
14+         return (LL $ HsPar $ LL $ HsLam (mkMatchGroup [
15+                  LL $ Match ps $4 (GRHSs (map lift (unLoc $5)) emptyLocalBinds),
16+                  LL $ Match (map (const nlWildPat) ps) $4
17+                  (GRHSs (unguardedRHS (nlHsApp (nlHsVar $ mkUnqual dataName FSLIT("Match"))
18+                                        (nlHsApp (nlHsVar $ mkUnqual varName FSLIT("fail"))
19+                                         (nlHsLit $ mkHsString "lambda-match failure"))))
20+                  emptyLocalBinds
21+                                                       )])) }
22+  | exp     { $1 }
23+
24hunk ./compiler/parser/Parser.y.pp 1275
25-       | '(' exp ')'                   { LL (HsPar $2) }
26+       | '(' expOrLambdaMatch ')'                      { LL (HsPar $2) }
27}