summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sgraf1337@gmail.com>2019-09-23 10:34:01 +0000
committerSebastian Graf <sgraf1337@gmail.com>2019-09-23 13:02:31 +0000
commit875f4974f4bb1a184c819427ece042af68293081 (patch)
tree301b2aeb4e6a0ab01d7bd9241e321ea51c4245e6
parentded96fb3ad540e0145483574b4a09bdcbe964c88 (diff)
downloadhaskell-wip/parser-less-dup.tar.gz
Fix some duplication in the parserwip/parser-less-dup
D3673 experienced reduce/reduce conflicts when trying to use opt_instance for associated data families. That was probably because the author tried to use it for Haskell98-syntax without also applying it to GADT-syntax, which actually leads to a reduce/reduce conflict. Consider the following state: ``` data . T = T data . T where T :: T ``` The parser must decide at this point whether or not to reduce an empty `opt_instance`. But doing so would also commit to either Haskell98 or GADT syntax! Good thing we also accept an optional "instance" for GADT syntax, so the `opt_instance` is there in both productions and there's no reduce/reduce conflict anymore. Also no need to inline `opt_instance`, how it used to be.
-rw-r--r--compiler/parser/Parser.y24
1 files changed, 4 insertions, 20 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index e61ff31844..276fcb1c5b 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -1320,36 +1320,20 @@ at_decl_inst :: { LInstDecl GhcPs }
(mj AnnType $1:$2++(fst $ unLoc $3)) }
-- 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_inst constrs maybe_derivings
- {% amms (mkDataFamInst (comb4 $1 $3 $4 $5) (snd $ unLoc $1) $2 (snd $ unLoc $3)
- Nothing (reverse (snd $ unLoc $4))
- (fmap reverse $5))
- ((fst $ unLoc $1):(fst $ unLoc $3) ++ (fst $ unLoc $4)) }
-
- | data_or_newtype 'instance' capi_ctype tycl_hdr_inst constrs maybe_derivings
+ | data_or_newtype opt_instance capi_ctype tycl_hdr_inst constrs maybe_derivings
{% amms (mkDataFamInst (comb4 $1 $4 $5 $6) (snd $ unLoc $1) $3 (snd $ unLoc $4)
Nothing (reverse (snd $ unLoc $5))
(fmap reverse $6))
- ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $4)++(fst $ unLoc $5)) }
+ ((fst $ unLoc $1):$2++(fst $ unLoc $4)++(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_inst opt_kind_sig
- gadt_constrlist
- maybe_derivings
- {% amms (mkDataFamInst (comb4 $1 $3 $5 $6) (snd $ unLoc $1) $2
- (snd $ unLoc $3) (snd $ unLoc $4) (snd $ unLoc $5)
- (fmap reverse $6))
- ((fst $ unLoc $1):(fst $ unLoc $3)++(fst $ unLoc $4)++(fst $ unLoc $5)) }
-
- | data_or_newtype 'instance' capi_ctype tycl_hdr_inst opt_kind_sig
+ | data_or_newtype opt_instance capi_ctype tycl_hdr_inst opt_kind_sig
gadt_constrlist
maybe_derivings
{% amms (mkDataFamInst (comb4 $1 $4 $6 $7) (snd $ unLoc $1) $3
(snd $ unLoc $4) (snd $ unLoc $5) (snd $ unLoc $6)
(fmap reverse $7))
- ((fst $ unLoc $1):mj AnnInstance $2:(fst $ unLoc $4)++(fst $ unLoc $5)++(fst $ unLoc $6)) }
+ ((fst $ unLoc $1):$2++(fst $ unLoc $4)++(fst $ unLoc $5)++(fst $ unLoc $6)) }
data_or_newtype :: { Located (AddAnn, NewOrData) }
: 'data' { sL1 $1 (mj AnnData $1,DataType) }