Commit 200c8e04 authored by Iavor S. Diatchki's avatar Iavor S. Diatchki Committed by Ben Gamari

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
parent dc8c03b2
......@@ -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 }
......
......@@ -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
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 _ _ = ()
==================== Parser ====================
module CommentsBeforeArguments where
f1 ::
() Comment before -> () Comment after -> () Result after
f1 _ _ = ()
f2 ::
() Comment before -> () Comment after -> () Result after
f2 _ _ = ()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment