[commit: ghc] master: Allow Haddock comments before function arguments. (200c8e0)

git at git.haskell.org git at git.haskell.org
Fri Jun 8 00:10:15 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/200c8e046b44e38698d7e7bb9801f306e9570a0a/ghc

>---------------------------------------------------------------

commit 200c8e046b44e38698d7e7bb9801f306e9570a0a
Author: Iavor Diatchki <iavor.diatchki at gmail.com>
Date:   Thu Jun 7 13:32:27 2018 -0400

    Allow Haddock comments before function arguments.
    
    Currently, documentation strings on function arguments has to be written
    after the argument (i.e., using `{-^ -}` comments).  This patch allows
    us to use `{-| -}` comments to put the comment string before an
    argument.   The same works for the results of functions.
    
    Reviewers: bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie, mpickering, carter
    
    Differential Revision: https://phabricator.haskell.org/D4767


>---------------------------------------------------------------

200c8e046b44e38698d7e7bb9801f306e9570a0a
 compiler/parser/Parser.y                           |  9 +++++++
 .../should_compile_flag_haddock/haddockA038.stderr |  4 +--
 .../should_compile_flag_haddock/haddockA039.hs     | 29 ++++++++++++++++++++++
 .../should_compile_flag_haddock/haddockA039.stderr | 11 ++++++++
 4 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 6fc233e..25edb3e 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -1890,6 +1890,7 @@ type :: { LHsType GhcPs }
 typedoc :: { LHsType GhcPs }
         : btype                          { $1 }
         | btype docprev                  { sLL $1 $> $ HsDocTy noExt $1 $2 }
+        | docnext btype                  { sLL $1 $> $ HsDocTy noExt $2 $1 }
         | btype '->'     ctypedoc        {% ams $1 [mu AnnRarrow $2] -- See note [GADT decl discards annotations]
                                          >> ams (sLL $1 $> $ HsFunTy noExt $1 $3)
                                                 [mu AnnRarrow $2] }
@@ -1899,6 +1900,14 @@ typedoc :: { LHsType GhcPs }
                                                             (HsDocTy noExt $1 $2))
                                                          $4)
                                                 [mu AnnRarrow $3] }
+        | docnext btype '->' ctypedoc    {% ams $2 [mu AnnRarrow $3] -- See note [GADT decl discards annotations]
+                                         >> ams (sLL $1 $> $
+                                                 HsFunTy noExt (L (comb2 $1 $2)
+                                                            (HsDocTy noExt $2 $1))
+                                                         $4)
+                                                [mu AnnRarrow $3] }
+
+
 
 -- See Note [Parsing ~]
 btype :: { LHsType GhcPs }
diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA038.stderr b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA038.stderr
index 94318ef..3021fa7 100644
--- a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA038.stderr
+++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA038.stderr
@@ -3,5 +3,5 @@
 module UnamedConstructorStrictFields where
 data A = A
 data B = B
-data Foo = MkFoo {-# UNPACK #-} !A  Unpacked strict field B
-data Bar = {-# UNPACK #-} !A  Unpacked strict field :%% B
+data Foo = MkFoo {-# UNPACK #-} !A " Unpacked strict field" B
+data Bar = {-# UNPACK #-} !A " Unpacked strict field" :%% B
diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.hs b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.hs
new file mode 100644
index 0000000..79d23e9
--- /dev/null
+++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.hs
@@ -0,0 +1,29 @@
+module CommentsBeforeArguments where
+
+data A = A
+data B = B
+
+f1 :: {-| Comment before -}
+     () ->
+
+     ()
+     {-^ Comment after -} ->
+
+     ()
+     {-^ Result after -}
+f1 _ _ = ()
+
+
+f2 :: {-| Comment before -}
+     () ->
+
+     ()
+     {-^ Comment after -} ->
+
+     {-| Result after -}
+     ()
+f2 _ _ = ()
+
+
+
+
diff --git a/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.stderr b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.stderr
new file mode 100644
index 0000000..0c12f5c
--- /dev/null
+++ b/testsuite/tests/haddock/should_compile_flag_haddock/haddockA039.stderr
@@ -0,0 +1,11 @@
+
+==================== Parser ====================
+module CommentsBeforeArguments where
+f1 ::
+  ()  Comment before  -> ()  Comment after  -> ()  Result after 
+f1 _ _ = ()
+f2 ::
+  ()  Comment before  -> ()  Comment after  -> ()  Result after 
+f2 _ _ = ()
+
+



More information about the ghc-commits mailing list