diff options
author | Ben Gamari <ben@smart-cactus.org> | 2019-12-10 13:43:32 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-12-10 13:45:45 -0500 |
commit | 4f2620c09778d9ad0a85c527cbcec2d7c40bd55e (patch) | |
tree | f74aaa8fa02cd3faacf367ad2baefa59cd65f023 /compiler/parser/Parser.y | |
parent | d46a72e19e1b508358827e7270139f3273915697 (diff) | |
download | haskell-wip/T17561.tar.gz |
parser: Correctly parse modules starting with declaration-and-docstringwip/T17561
Previously the module header parser would start by parsing a
maybedocheader. This would consume the docstring and commit us to
parsing a `module ... where` header. However, a module lacking a `module
... where` header may also begin with a docstring, but one rather
belonging to a declaration. Restructure the parser to ensure that this
case is handled correctly.
Fixes #17561.
Diffstat (limited to 'compiler/parser/Parser.y')
-rw-r--r-- | compiler/parser/Parser.y | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index ce4d277f6b..7c520d0bd8 100644 --- a/compiler/parser/Parser.y +++ b/compiler/parser/Parser.y @@ -766,13 +766,22 @@ signature :: { Located (HsModule GhcPs) } ([mj AnnSignature $2, mj AnnWhere $6] ++ fst $7) } module :: { Located (HsModule GhcPs) } - : maybedocheader 'module' modid maybemodwarning maybeexports 'where' body + -- it is important that we include both rules below and not use + -- maybedocheader here since we may have a module which begins with a + -- declaration with docstring (see #17561). + : moduleheader 'module' modid maybemodwarning maybeexports 'where' body {% fileSrcSpan >>= \ loc -> ams (L loc (HsModule (Just $3) $5 (fst $ snd $7) (snd $ snd $7) $4 $1) ) ([mj AnnModule $2, mj AnnWhere $6] ++ fst $7) } - | body2 + | 'module' modid maybemodwarning maybeexports 'where' body + {% fileSrcSpan >>= \ loc -> + ams (L loc (HsModule (Just $2) $4 (fst $ snd $6) + (snd $ snd $6) $3 Nothing) + ) + ([mj AnnModule $1, mj AnnWhere $5] ++ fst $6) } + | body2 {% fileSrcSpan >>= \ loc -> ams (L loc (HsModule Nothing Nothing (fst $ snd $1) (snd $ snd $1) Nothing Nothing)) |