[Haskell-cafe] pretty printing with comments
Lennart Augustsson
lennart at augustsson.net
Tue Oct 20 09:46:47 EDT 2009
It's not an easy problem to pretty print (i.e. change indentation) and
preserve the comments. And always get it right.
On Tue, Oct 20, 2009 at 1:28 PM, Pasqualino "Titto" Assini
<tittoassini at gmail.com> wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list