[Haskell-cafe] pretty printing with comments

Pasqualino "Titto" Assini tittoassini at gmail.com
Tue Oct 20 07:28:30 EDT 2009


Thanks Niklas,

in fact this produced a source with comments:


import Language.Haskell.Exts.Annotated

main = do
  (ParseOk (mod,comments)) <- parseFileWithComments defaultParseMode "Test.hs"
  let pretty = exactPrint mod comments
  writeFile "Test_PRETTY.hs" pretty



However:
- The source code produced was incorrect:


class Dir d where

was rewritten as:

class Dir dwhere{


And:

instance Dir Directory where
  localDir (Local f) = return f

type URL= String


was rewritten as:


instance Dir Directory where
  localDir (Local f) = return f

  typeURL= String


Are these known bugs?


- Also, the printing is a bit too exact :-), I would like to keep my
comments AND get the code nicely reformatted.


Is there a way?

What people use to keep their haskell source files in tip-top shape?

Thanks

          titto






2009/10/20 Niklas Broberg <niklas.broberg at gmail.com>:
> Hi Pasqualino,
>
>> I am looking at the haskell-src-ext library.
>>
>> It can parse files with comments and it can pretty print but, for what
>> I can see it cannot do both :-)  (prettyPrint won't work on the
>> structure returned by parseFileWithComments).
>
> What you want is exactPrint, defined in
> Language.Haskell.Exts.Annotated.ExactPrint. :-)
>
> Cheers,
>
> /Niklas


More information about the Haskell-Cafe mailing list