[commit: ghc] wip/T9023: Add parser for pattern synonym signatures (dbe2c5c)
git at git.haskell.org
git at git.haskell.org
Wed Jul 2 11:24:14 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/T9023
Link : http://ghc.haskell.org/trac/ghc/changeset/dbe2c5c44ffffb9252b33ec049edb189103c49a4/ghc
>---------------------------------------------------------------
commit dbe2c5c44ffffb9252b33ec049edb189103c49a4
Author: Dr. ERDI Gergo <gergo at erdi.hu>
Date: Wed Jul 2 19:23:47 2014 +0800
Add parser for pattern synonym signatures
>---------------------------------------------------------------
dbe2c5c44ffffb9252b33ec049edb189103c49a4
compiler/parser/Parser.y.pp | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
index 68f7e5b..6e4a3d5 100644
--- a/compiler/parser/Parser.y.pp
+++ b/compiler/parser/Parser.y.pp
@@ -816,8 +816,25 @@ role : VARID { L1 $ Just $ getVARID $1 }
-- Glasgow extension: pattern synonyms
pattern_synonym_decl :: { LHsDecl RdrName }
- : 'pattern' con vars0 patsyn_token pat { LL . ValD $ mkPatSynBind $2 (PrefixPatSyn $3) $5 $4 }
- | 'pattern' varid conop varid patsyn_token pat { LL . ValD $ mkPatSynBind $3 (InfixPatSyn $2 $4) $6 $5 }
+ : 'pattern' con vars0 patsyn_token pat
+ { LL . ValD $ mkPatSynBind $2 (PrefixPatSyn $3) $5 $4 }
+ | 'pattern' varid conop varid patsyn_token pat
+ { LL . ValD $ mkPatSynBind $3 (InfixPatSyn $2 $4) $6 $5 }
+
+pattern_synonym_sig :: { LSig RdrName }
+ : 'pattern' patsyn_context patsyn_stuff '::' patsyn_context type
+ { let (name, details) = unLoc $3
+ in LL $ PatSynSig name details $6 $2 $5 }
+
+patsyn_stuff :: { Located (Located RdrName, HsPatSynDetails (LHsType RdrName)) }
+ : constr_stuff
+ {% do { let { (L loc (name, con_details)) = $1 }
+ ; ps_details <- toPatSynSigDetails loc con_details
+ ; return $ LL (name, ps_details) } }
+
+patsyn_context :: { LHsContext RdrName }
+ : forall { L0 [] }
+ | forall context '=>' { $2 }
vars0 :: { [Located RdrName] }
: {- empty -} { [] }
@@ -1432,6 +1449,7 @@ sigdecl :: { Located (OrdList (LHsDecl RdrName)) }
{ LL $ toOL [ LL $ SigD (TypeSig ($1 : unLoc $3) $5) ] }
| infix prec ops { LL $ toOL [ LL $ SigD (FixSig (FixitySig n (Fixity $2 (unLoc $1))))
| n <- unLoc $3 ] }
+ | pattern_synonym_sig { LL . unitOL $ LL . SigD . unLoc $ $1 }
| '{-# INLINE' activation qvar '#-}'
{ LL $ unitOL (LL $ SigD (InlineSig $3 (mkInlinePragma (getINLINE $1) $2))) }
| '{-# SPECIALISE' activation qvar '::' sigtypes1 '#-}'
More information about the ghc-commits
mailing list