[Haddock] [haddock] #10: Parsing module without explicit module declaration fails (was: Parsing fails for modules without explicit module declaration)

haddock haddock at projects.haskell.org
Tue Oct 16 09:59:33 BST 2012


#10: Parsing module without explicit module declaration fails
-------------------+--------------------------------------------------------
Reporter:  waern   |        Owner:  SimonHengel
    Type:  defect  |       Status:  assigned   
Priority:  major   |    Milestone:  _|_        
 Version:  0.x     |   Resolution:             
Keywords:          |  
-------------------+--------------------------------------------------------
Description changed by SimonHengel:

Old 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!"
> }}}

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 module headers.
 When the parser sees the Haddock comment at the
 beginning it then wants the next declaration to be a module header
 (the 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:8>
haddock <http://www.haskell.org/haddock>
Haddock, The Haskell Documentation Tool


More information about the Haddock mailing list