diff options
author | Sebastian Graf <sgraf1337@gmail.com> | 2019-09-23 10:34:01 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-09-24 01:07:57 -0400 |
commit | f97a7aacb5ff2c7a53f5e08e9d75edbb67e13cf8 (patch) | |
tree | d7a6b9748b0d336534abb6762cf435b68ab1e9d0 /compiler/parser | |
parent | b5f24fb473560cc533143846329666896e9861be (diff) | |
download | haskell-f97a7aacb5ff2c7a53f5e08e9d75edbb67e13cf8.tar.gz |
Fix some duplication in the parser
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.
Diffstat (limited to 'compiler/parser')
-rw-r--r-- | compiler/parser/Parser.y | 24 |
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) } |