summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFinley McIlwaine <finleymcilwaine@gmail.com>2023-05-01 08:36:06 -0600
committerFinley McIlwaine <finleymcilwaine@gmail.com>2023-05-17 19:58:53 +0000
commit57ba64dba592f5efaea5e9b61f2e7e2e7267179e (patch)
tree5bafc65cff9cae8fb337ff751a81dca4c9e3a25e
parent2972fd66f91cb51426a1df86b8166a067015e231 (diff)
downloadhaskell-wip/t23315.tar.gz
Insert documentation into parsed signature moduleswip/t23315
Causes haddock comments in signature modules to be properly inserted into the AST (just as they are for regular modules) if the `-haddock` flag is given. Also adds a test that compares `-ddump-parsed-ast` output for a signature module to prevent further regressions. Fixes #23315
-rw-r--r--compiler/GHC/Parser.y23
-rw-r--r--testsuite/tests/parser/should_compile/T23315/Makefile18
-rw-r--r--testsuite/tests/parser/should_compile/T23315/Setup.hs2
-rw-r--r--testsuite/tests/parser/should_compile/T23315/T23315.cabal10
-rw-r--r--testsuite/tests/parser/should_compile/T23315/T23315.hsig4
-rw-r--r--testsuite/tests/parser/should_compile/T23315/T23315.stderr112
-rw-r--r--testsuite/tests/parser/should_compile/T23315/all.T3
7 files changed, 166 insertions, 6 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index a61a133574..c89c13477f 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -751,7 +751,7 @@ TH_QQUASIQUOTE { L _ (ITqQuasiQuote _) }
-- Exported parsers
%name parseModuleNoHaddock module
-%name parseSignature signature
+%name parseSignatureNoHaddock signature
%name parseImport importdecl
%name parseStatement e_stmt
%name parseDeclaration topdecl
@@ -4416,18 +4416,29 @@ pvL :: MonadP m => m (LocatedAn t a) -> m (Located a)
pvL a = do { av <- a
; return (reLoc av) }
--- | Parse a Haskell module with Haddock comments.
--- This is done in two steps:
+-- | Parse a Haskell module with Haddock comments. This is done in two steps:
--
-- * 'parseModuleNoHaddock' to build the AST
-- * 'addHaddockToModule' to insert Haddock comments into it
--
--- This is the only parser entry point that deals with Haddock comments.
--- The other entry points ('parseDeclaration', 'parseExpression', etc) do
--- not insert them into the AST.
+-- This and the signature module parser are the only parser entry points that
+-- deal with Haddock comments. The other entry points ('parseDeclaration',
+-- 'parseExpression', etc) do not insert them into the AST.
parseModule :: P (Located (HsModule GhcPs))
parseModule = parseModuleNoHaddock >>= addHaddockToModule
+-- | Parse a Haskell signature module with Haddock comments. This is done in two
+-- steps:
+--
+-- * 'parseSignatureNoHaddock' to build the AST
+-- * 'addHaddockToModule' to insert Haddock comments into it
+--
+-- This and the module parser are the only parser entry points that deal with
+-- Haddock comments. The other entry points ('parseDeclaration',
+-- 'parseExpression', etc) do not insert them into the AST.
+parseSignature :: P (Located (HsModule GhcPs))
+parseSignature = parseSignatureNoHaddock >>= addHaddockToModule
+
commentsA :: (Monoid ann) => SrcSpan -> EpAnnComments -> SrcSpanAnn' (EpAnn ann)
commentsA loc cs = SrcSpanAnn (EpAnn (Anchor (rs loc) UnchangedAnchor) mempty cs) loc
diff --git a/testsuite/tests/parser/should_compile/T23315/Makefile b/testsuite/tests/parser/should_compile/T23315/Makefile
new file mode 100644
index 0000000000..879e49d09f
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/Makefile
@@ -0,0 +1,18 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+SETUP = ./Setup -v0
+
+T23315: clean
+ $(MAKE) clean
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
+ $(SETUP) clean
+ $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)'
+ $(SETUP) build 1>&2
+ifneq "$(CLEANUP)" ""
+ $(MAKE) clean
+endif
+
+clean :
+ $(RM) -r */dist Setup$(exeext) *.o *.hi
diff --git a/testsuite/tests/parser/should_compile/T23315/Setup.hs b/testsuite/tests/parser/should_compile/T23315/Setup.hs
new file mode 100644
index 0000000000..bf6890196c
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain \ No newline at end of file
diff --git a/testsuite/tests/parser/should_compile/T23315/T23315.cabal b/testsuite/tests/parser/should_compile/T23315/T23315.cabal
new file mode 100644
index 0000000000..a654745c6d
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/T23315.cabal
@@ -0,0 +1,10 @@
+name: T23315
+version: 0.1.0.0
+build-type: Simple
+cabal-version: 2.0
+
+library
+ signatures: T23315
+ build-depends: base >= 4.3 && < 5
+ default-language: Haskell2010
+ ghc-options: -Wall -haddock -ddump-parsed-ast
diff --git a/testsuite/tests/parser/should_compile/T23315/T23315.hsig b/testsuite/tests/parser/should_compile/T23315/T23315.hsig
new file mode 100644
index 0000000000..c49390e642
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/T23315.hsig
@@ -0,0 +1,4 @@
+signature T23315 where
+-- | My unit
+a :: ()
+-- ^ More docs
diff --git a/testsuite/tests/parser/should_compile/T23315/T23315.stderr b/testsuite/tests/parser/should_compile/T23315/T23315.stderr
new file mode 100644
index 0000000000..1cc94f80b8
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/T23315.stderr
@@ -0,0 +1,112 @@
+
+==================== Parser AST ====================
+
+(L
+ { T23315.hsig:1:1 }
+ (HsModule
+ (XModulePs
+ (EpAnn
+ (Anchor
+ { T23315.hsig:1:1 }
+ (UnchangedAnchor))
+ (AnnsModule
+ [(AddEpAnn AnnSignature (EpaSpan { T23315.hsig:1:1-9 }))
+ ,(AddEpAnn AnnWhere (EpaSpan { T23315.hsig:1:18-22 }))]
+ []
+ (Nothing))
+ (EpaComments
+ []))
+ (VirtualBraces
+ (1))
+ (Nothing)
+ (Nothing))
+ (Just
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:1:11-16 })
+ {ModuleName: T23315}))
+ (Nothing)
+ []
+ [(L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:2:1-12 })
+ (DocD
+ (NoExtField)
+ (DocCommentNext
+ (L
+ { T23315.hsig:2:1-12 }
+ (WithHsDocIdentifiers
+ (MultiLineDocString
+ (HsDocStringNext)
+ (:|
+ (L
+ { T23315.hsig:2:5-12 }
+ (HsDocStringChunk
+ " My unit"))
+ []))
+ [])))))
+ ,(L
+ (SrcSpanAnn (EpAnn
+ (Anchor
+ { T23315.hsig:3:1-7 }
+ (UnchangedAnchor))
+ (AnnListItem
+ [])
+ (EpaComments
+ [])) { T23315.hsig:3:1-7 })
+ (SigD
+ (NoExtField)
+ (TypeSig
+ (EpAnn
+ (Anchor
+ { T23315.hsig:3:1 }
+ (UnchangedAnchor))
+ (AnnSig
+ (AddEpAnn AnnDcolon (EpaSpan { T23315.hsig:3:3-4 }))
+ [])
+ (EpaComments
+ []))
+ [(L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:3:1 })
+ (Unqual
+ {OccName: a}))]
+ (HsWC
+ (NoExtField)
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:3:6-7 })
+ (HsSig
+ (NoExtField)
+ (HsOuterImplicit
+ (NoExtField))
+ (L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:3:6-7 })
+ (HsTupleTy
+ (EpAnn
+ (Anchor
+ { T23315.hsig:3:6 }
+ (UnchangedAnchor))
+ (AnnParen
+ (AnnParens)
+ (EpaSpan { T23315.hsig:3:6 })
+ (EpaSpan { T23315.hsig:3:7 }))
+ (EpaComments
+ []))
+ (HsBoxedOrConstraintTuple)
+ []))))))))
+ ,(L
+ (SrcSpanAnn (EpAnnNotUsed) { T23315.hsig:4:1-14 })
+ (DocD
+ (NoExtField)
+ (DocCommentPrev
+ (L
+ { T23315.hsig:4:1-14 }
+ (WithHsDocIdentifiers
+ (MultiLineDocString
+ (HsDocStringPrevious)
+ (:|
+ (L
+ { T23315.hsig:4:5-14 }
+ (HsDocStringChunk
+ " More docs"))
+ []))
+ [])))))]))
+
+
diff --git a/testsuite/tests/parser/should_compile/T23315/all.T b/testsuite/tests/parser/should_compile/T23315/all.T
new file mode 100644
index 0000000000..940dd71d2e
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T23315/all.T
@@ -0,0 +1,3 @@
+test('T23315',
+ [extra_files(['Setup.hs']), js_broken(22352)],
+ makefile_test, [])