[Git][ghc/ghc][wip/t23315] Insert documentation into parsed signature modules

Finley McIlwaine (@FinleyMcIlwaine) gitlab at gitlab.haskell.org
Mon May 1 20:54:32 UTC 2023



Finley McIlwaine pushed to branch wip/t23315 at Glasgow Haskell Compiler / GHC


Commits:
37f93685 by Finley McIlwaine at 2023-05-01T14:53:55-06:00
Insert documentation into parsed signature modules

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

- - - - -


7 changed files:

- compiler/GHC/Parser.y
- + testsuite/tests/parser/should_compile/T23315/Makefile
- + testsuite/tests/parser/should_compile/T23315/Setup.hs
- + testsuite/tests/parser/should_compile/T23315/T23315.cabal
- + testsuite/tests/parser/should_compile/T23315/T23315.hsig
- + testsuite/tests/parser/should_compile/T23315/T23315.stderr
- + testsuite/tests/parser/should_compile/T23315/all.T


Changes:

=====================================
compiler/GHC/Parser.y
=====================================
@@ -743,7 +743,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
@@ -4376,18 +4376,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
 


=====================================
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


=====================================
testsuite/tests/parser/should_compile/T23315/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
\ No newline at end of file


=====================================
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


=====================================
testsuite/tests/parser/should_compile/T23315/T23315.hsig
=====================================
@@ -0,0 +1,4 @@
+signature T23315 where
+-- | My unit
+a :: ()
+-- ^ More docs


=====================================
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"))
+          []))
+        [])))))]))
+
+


=====================================
testsuite/tests/parser/should_compile/T23315/all.T
=====================================
@@ -0,0 +1,3 @@
+test('T23315',
+     [extra_files(['Setup.hs']), js_broken(22352)],
+     makefile_test, [])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/37f936856fcccb61cf52e57a08cbfa54a86e3c78

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/37f936856fcccb61cf52e57a08cbfa54a86e3c78
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230501/5cfce462/attachment-0001.html>


More information about the ghc-commits mailing list