GHC's CPP and Cabal's unlit

Duncan Coutts duncan.coutts at
Sat Dec 29 20:40:44 EST 2007

On Mon, 2007-12-17 at 16:08 +0000, Alistair Bayley wrote:
> Hello,
> I've not had any feedback on this. Is there some additional work for
> me to do to make the patches more acceptable for the cabal codebase?

I finally go round to looking at this. I'm fairly happy with it code
wise. I've done a bit of refactoring to improve handling of error
messages and to add back handling of line pragmas. I've kept the state
machine the same. Thanks for the test suite, that was particularly handy
as I was making some changes.

One bit I'm less sure about is the handling of paragraphs in comments.
Currently the code transforms:

blah blah

blah blah


-- blah blah

-- blah blah

but it transforms

blah blah
blah blah


-- blah blah
-- blah blah

spot the difference? Yeah, just white space. The completely blank line
separates the paragraphs into two comments which haddock will treat
differently from a single comment.

It comes from this code:

    -- special case here: a truly empty line will terminate
    -- a comment section (and send us into the "blank" state)
    comment (Blank ""   :ls) = Blank "" : blank ls
    -- but a line containing whitespace will be treated as a
    -- comment (prefixed with "-- "), unless it is followed by
    -- a program line, in which case it is really blank.
    comment (Blank     l:ls@(BirdTrack _:_)) = Blank l : blank ls
    comment (Blank     l:ls) = Comment l : comment ls

Perhaps we should just always make the trailing space part of a comment.
Obviously we'd have to handle space before some bird-track line without
complaining that it's a comment next to code. That might need one more

I've attached my changes.

I still think we need some larger scale test to make sure this is ok.
Perhaps there's some way of comparing the output with ghc's unlit. We'd
need to blank out "--" lines in both files and probably more to get them
to compare equal. Then we could test that on all the .lhs files we can
lay our hands on (ghc, hackage etc).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: haddock_unlit2.patch
Type: text/x-patch
Size: 48944 bytes
Desc: not available
Url :

More information about the cabal-devel mailing list