[Haddock] [haddock] #10: Modules without an explicit module declaration can not be parsed (was: Starting the module with -- | doc followed by a declaration doesn't parse)

haddock haddock at projects.haskell.org
Tue Oct 16 09:55:31 BST 2012


#10: Modules without an explicit module declaration can not be parsed
-------------------+--------------------------------------------------------
Reporter:  waern   |        Owner:  SimonHengel
    Type:  defect  |       Status:  assigned   
Priority:  major   |    Milestone:  _|_        
 Version:  0.x     |   Resolution:             
Keywords:          |  
-------------------+--------------------------------------------------------
Description changed by SimonHengel:

Old description:

> Parser bug: starting the module with '-- | doc' followed by a declaration
> doesn't parse, because the '-- | doc' is interpreted as the module
> documentation (the GHC grammar has an S/R conflict because of this).
>
> This could be fixed if we parse Haddock comments separately from the
> Haskell code, and match up Haddock comments with AST nodes in a later
> step.

New description:

 If a module does not contain an explicit module declaration
 '''and''' starts with
 {{{
 -- | some comment
 }}}
 then parsing fails.

 This is a bug in GHC's parser.  It is only triggered if
 [http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/DynFlags.html#v:Opt_Haddock
 Opt_Haddock] is used.

 === Details ===
 GHC's parser has a rule for Haddock comments on the module headers.
 When the parser sees the Haddock comment at the
 beginning it then wants the next declaration to be a module header
 (the GHC grammar has an S/R conflict because of this).

 One possible solution could be to parse Haddock comments separately from
 the Haskell code, and match up Haddock comments with AST nodes in a later
 step.

 === Steps to reproduce ===
 {{{
 -- | Hi there
 main = print "Hello World!"
 }}}

 Running
 {{{
 $ haddock Main.hs
 }}}
 fails with:
 {{{
 Main.hs:2:1: parse error on input `main'
 }}}

 In contrast both of the following example work just fine:

 {{{
 {-
 Hi there
 -}
 main = print "Hello World!"
 }}}
 {{{
 foo = 23
 -- | Hi there
 main = print "Hello World!"
 }}}

--

-- 
Ticket URL: <http://trac.haskell.org/haddock/ticket/10#comment:6>
haddock <http://www.haskell.org/haddock>
Haddock, The Haskell Documentation Tool


More information about the Haddock mailing list