diff options
Diffstat (limited to 'compiler/parser')
-rw-r--r-- | compiler/parser/Parser.y | 34 |
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) } |