diff options
author | Iavor Diatchki <iavor.diatchki@gmail.com> | 2018-06-07 13:32:27 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-06-07 18:06:31 -0400 |
commit | 200c8e046b44e38698d7e7bb9801f306e9570a0a (patch) | |
tree | c3e815b1c59d4fbf1c03cf4bffccf609ea1c9a63 | |
parent | dc8c03b2a5c70d3169e88d407f3ef28e0cb26af5 (diff) | |
download | haskell-200c8e046b44e38698d7e7bb9801f306e9570a0a.tar.gz |
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
4 files changed, 51 insertions, 2 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y index 6fc233ed42..25edb3e591 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 94318efe2b..3021fa7195 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 0000000000..79d23e9ec1 --- /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 0000000000..0c12f5c62f --- /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 _ _ = () + + |