summaryrefslogtreecommitdiff
path: root/compiler/parser
diff options
context:
space:
mode:
authorTibor Erdesz <erdeszt@gmail.com>2017-06-29 19:37:13 -0400
committerBen Gamari <ben@smart-cactus.org>2017-06-29 19:38:16 -0400
commit007f255644f885d445e47e291e50eb12b5ecd08d (patch)
tree2d6269ea631c17096d9aefdf8b2551f667e0faed /compiler/parser
parent6171b0b326e52221a0631cf75eb4866b36abe631 (diff)
downloadhaskell-007f255644f885d445e47e291e50eb12b5ecd08d.tar.gz
Allow optional instance keyword in associated type family instances
Add the missing branch for parsing the optional 'instance' keyword in associated type family instance declarations. Fixes #13747 Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: simonpj, RyanGlScott, rwbarton, thomie, mpickering Differential Revision: https://phabricator.haskell.org/D3673
Diffstat (limited to 'compiler/parser')
-rw-r--r--compiler/parser/Parser.y34
1 files changed, 27 insertions, 7 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 6e4b7740d5..603ac27cf4 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -1215,25 +1215,37 @@ opt_family :: { [AddAnn] }
: {- empty -} { [] }
| 'family' { [mj AnnFamily $1] }
+opt_instance :: { [AddAnn] }
+ : {- empty -} { [] }
+ | 'instance' { [mj AnnInstance $1] }
+
-- Associated type instances
--
at_decl_inst :: { LInstDecl GhcPs }
- -- type instance declarations
- : 'type' ty_fam_inst_eqn
+ -- type instance declarations, with optional 'instance' keyword
+ : 'type' opt_instance ty_fam_inst_eqn
-- Note the use of type for the head; this allows
-- infix type constructors and type patterns
- {% ams $2 (fst $ unLoc $2) >>
- amms (mkTyFamInst (comb2 $1 $2) (snd $ unLoc $2))
- (mj AnnType $1:(fst $ unLoc $2)) }
+ {% ams $3 (fst $ unLoc $3) >>
+ amms (mkTyFamInst (comb2 $1 $3) (snd $ unLoc $3))
+ (mj AnnType $1:$2++(fst $ unLoc $3)) }
- -- data/newtype instance declaration
+ -- data/newtype instance declaration, with optional 'instance' keyword
+ -- (can't use opt_instance because you get reduce/reduce errors)
| data_or_newtype capi_ctype tycl_hdr constrs maybe_derivings
{% amms (mkDataFamInst (comb4 $1 $3 $4 $5) (snd $ unLoc $1) $2 $3
Nothing (reverse (snd $ unLoc $4))
(fmap reverse $5))
((fst $ unLoc $1):(fst $ unLoc $4)) }
- -- GADT instance declaration
+ | data_or_newtype 'instance' capi_ctype tycl_hdr constrs maybe_derivings
+ {% amms (mkDataFamInst (comb4 $1 $4 $5 $6) (snd $ unLoc $1) $3 $4
+ Nothing (reverse (snd $ unLoc $5))
+ (fmap reverse $6))
+ ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $5)) }
+
+ -- GADT instance declaration, with optional 'instance' keyword
+ -- (can't use opt_instance because you get reduce/reduce errors)
| data_or_newtype capi_ctype tycl_hdr opt_kind_sig
gadt_constrlist
maybe_derivings
@@ -1242,6 +1254,14 @@ at_decl_inst :: { LInstDecl GhcPs }
(fmap reverse $6))
((fst $ unLoc $1):(fst $ unLoc $4)++(fst $ unLoc $5)) }
+ | data_or_newtype 'instance' capi_ctype tycl_hdr opt_kind_sig
+ gadt_constrlist
+ maybe_derivings
+ {% amms (mkDataFamInst (comb4 $1 $4 $6 $7) (snd $ unLoc $1) $3
+ $4 (snd $ unLoc $5) (snd $ unLoc $6)
+ (fmap reverse $7))
+ ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $5)++(fst $ unLoc $6)) }
+
data_or_newtype :: { Located (AddAnn, NewOrData) }
: 'data' { sL1 $1 (mj AnnData $1,DataType) }
| 'newtype' { sL1 $1 (mj AnnNewtype $1,NewType) }