Re: [Haskell-cafe] pretty printing with comments

2009-10-22 Thread Niklas Broberg
 I'll see when I can get to fixing it, hopefully it won't be long.

Two fairly easy bugs to fix, darcs repo is updated. It's probably high
time I did another release, stay tuned.

I just can't believe I didn't have a single class declaration in my
test suite to catch the first one! Or that no one else triggered it
before (I guess no one has actually started using exactPrint in their
code yet).

Thanks again for reporting! :-)

Cheers,

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] pretty printing with comments

2009-10-20 Thread Pasqualino Titto Assini
Hi,

Is there any simple way of pretty printing haskell source code while
preserving the comments?

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).

Thanks,

 titto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Niklas Broberg
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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Pasqualino Titto Assini
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.brob...@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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Lennart Augustsson
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
tittoass...@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.brob...@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@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Niklas Broberg
Hi again,

 However:
 - The source code produced was incorrect:


 class Dir d where

 was rewritten as:

 class Dir dwhere{

That's weird, I'll look into it, thanks.

 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

Sorry, I don't see the difference between these two. Did you write the
correct one twice by mistake?

 Are these known bugs?

No, there are no known bugs so please report everything you find!
exactPrint is new and most likely sparsely used as of yet. I'd expect
there to be a few bugs lying around here and there, and I appreciate
all reports!

 - 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?

No. Like Lennart points out that's a really difficult problem, not to
say impossible, where do you place the comments after reformatting?

Cheers,

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread minh thu
2009/10/20 Niklas Broberg niklas.brob...@gmail.com:
 Hi again,

 However:
 - The source code produced was incorrect:


 class Dir d where

 was rewritten as:

 class Dir dwhere{

 That's weird, I'll look into it, thanks.

 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

 Sorry, I don't see the difference between these two. Did you write the
 correct one twice by mistake?

In case Pasqualino doesn't see your mail real soon...
Maybe the difference is the missing space between type and URL.

Cheers,
Thu
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Niklas Broberg
 instance Dir Directory where
  localDir (Local f) = return f

  typeURL= String

 Sorry, I don't see the difference between these two. Did you write the
 correct one twice by mistake?

 In case Pasqualino doesn't see your mail real soon...
 Maybe the difference is the missing space between type and URL.

Ah, of course, I see it now, thanks!

Cheers,

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Pasqualino Titto Assini
Hi,

there is also another difference:

type URL= String

was a top level definition but it has been moved under the previous
instance declaration.

I attach a source fragment and another file with the pretty printed
output containing these three errors.


Regarding the problem of pretty printing while keeping the comments I
imagine that you would like the comments to be associated with the
previous syntactical element (module, top level declaration or
expression) and be rendered in the same relative position in the
pretty printed output.

I agree that it doesn't sound like an easy task.

However, similar systems exists for most languages (I loved my Java
reformatter in Eclipse) and it would be very handy in Haskell as well.


Best,

 titto





2009/10/20 Niklas Broberg niklas.brob...@gmail.com:
 instance Dir Directory where
  localDir (Local f) = return f

  typeURL= String

 Sorry, I don't see the difference between these two. Did you write the
 correct one twice by mistake?

 In case Pasqualino doesn't see your mail real soon...
 Maybe the difference is the missing space between type and URL.

 Ah, of course, I see it now, thanks!

 Cheers,

 /Niklas




-- 
Pasqualino Titto Assini, Ph.D.
http://quicquid.org/
class Dir d where
  localDir :: d - IO FilePath

data Package = Cabal Directory 
   | SourceTree Directory
 deriving (Read,Show,Typeable,Data)


-- A (possibly remote) directory that can be mapped to a local one.
data Directory = Local FilePath
   | Darcs {url::URL,darcsVersion::DarcsVersion,subDirectory::FilePath} deriving (Read,Show,Typeable,Data)

data DarcsVersion = Patch String | Tag String deriving (Read,Show,Typeable,Data)

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

  localDir (Darcs {url=url,darcsVersion=Patch patch,subDirectory=subDir}) = do 
tmp - createTempDir 0 haskelld
darcsOut - runDarcsCommand tmp get [--lazy,--to-match,hash ++ patch,url,fs]
print darcsOut
let (ExitSuccess,,out) = darcsOut 
print out
return $ tmp / fs / subDir

type URL = String
class Dir dwhere{
  localDir :: d - IO FilePath

data Package = Cabal Directory
   | SourceTree Directory
 deriving (Read,Show,Typeable,Data)


-- A (possibly remote) directory that can be mapped to a local one.
data Directory = Local FilePath
   | Darcs {url::URL,darcsVersion::DarcsVersion,subDirectory::FilePath} deriving (Read,Show,Typeable,Data)

data DarcsVersion = Patch String | Tag String deriving (Read,Show,Typeable,Data)

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

  localDir (Darcs {url=url,darcsVersion=Patch patch,subDirectory=subDir}) = do
tmp - createTempDir 0 haskelld
darcsOut - runDarcsCommand tmp get [--lazy,--to-match,hash ++ patch,url,fs]
print darcsOut
let (ExitSuccess,,out) = darcsOut
print out
return $ tmp / fs / subDir

  typeURL= String
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pretty printing with comments

2009-10-20 Thread Niklas Broberg
Hi again,

 I attach a source fragment and another file with the pretty printed
 output containing these three errors.

Thanks, I've opened a ticket for this issue here:

http://trac.haskell.org/haskell-src-exts/ticket/65

I'll see when I can get to fixing it, hopefully it won't be long.

Cheers,

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe