[ANN] Gutenberg: a pretty printer for Smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
Hi,

I've ported Gutenberg from VW. The package contains a pretty-printing
algo (taken from Philip Wadler's papers on Haskell pretty-printer
combinators) and a visitor to replace the RB one.

It is available from:
    http://www.squeaksource.com/Gutenberg.html

Once loaded you can activate it by evaluating this:
    RBProgramNode formatterClass: RBPrettyFormatter.
You'll need to set the 'useRBASTForPrettyPrint' preference and use the
browser in 'prettyPrint' mode.

I need comments on the packaging, the pretty-printing itself (yes, it
adds periods everywhere...) and ideas on making it customizable
without basically rewriting a new visitor.

Oh, and I decline any responsibility if it breaks your code :}

--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Cassou-3
Damien Pollet wrote:

> Hi,
>
> I've ported Gutenberg from VW. The package contains a pretty-printing
> algo (taken from Philip Wadler's papers on Haskell pretty-printer
> combinators) and a visitor to replace the RB one.
>
> It is available from:
>    http://www.squeaksource.com/Gutenberg.html
>
> Once loaded you can activate it by evaluating this:
>    RBProgramNode formatterClass: RBPrettyFormatter.
> You'll need to set the 'useRBASTForPrettyPrint' preference and use the
> browser in 'prettyPrint' mode.



Thank you, I really needed this. I will try and let you know.


> I need comments on the packaging, the pretty-printing itself (yes, it
> adds periods everywhere...) and ideas on making it customizable
> without basically rewriting a new visitor.
>
> Oh, and I decline any responsibility if it breaks your code :}


Hope it won't :-)

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Cassou-3
In reply to this post by Damien Pollet
The package is perfect. Everything works out of the box after having
selected the good options.

But as you may already know, the algorithm is a bit weird and more of my
methods are more difficult to read with your pretty printer in my
opinion. Do you want examples ?

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
On 7/16/06, Damien Cassou <[hidden email]> wrote:
> But as you may already know, the algorithm is a bit weird and more of my
> methods are more difficult to read with your pretty printer in my
> opinion. Do you want examples ?

Heh :) Indeed I want examples, and how they should have been prettyfied :)

--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
I guess your examples will be sequences of short phrases, that get on
a single line. I probably should force line breaks after periods, and
keep optional breaks for cascades...

This raises another question... to take some layout clues from the
original source, I'd like to know if there are blank lines, or if the
developer separated two phrases by a line break (or not). Knowing this
the prettyprinter could keep blank lines, or choose between forced or
optional line breaks...

There is another problem I know: the prettyprinting is only made when
the method is displayed: if you edit it and save it, the source is
saved as you wrote it, *then* it is prettyprinted and redisplayed.

--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Cassou-3
In reply to this post by Damien Pollet
Here is an example of an automatic formatting:


1 renderCategoriesOn: html 
2     html fieldSet legend: 'Choose one or more categories';
3  
4         with: [html
5                 unorderedList: [self allCategories
6                         do: [:category | html
7                                 listItem: [html checkbox
8                                         value: (self belongsToCategory: category);
9                                
10                                         onTrue: [self addCategory: category]
11                                         onFalse: [self removeCategory: category];
12                                        
13                                         with: [html text: category asString]]]
14                         separatedBy: [html break]]]


Here are my opinion:

- use spaces instead of tabs (I don't know if this is wanted)
- on line 2, #legend: can be put in the following line
- the line 3 should not be empty
- on line 4, #with: should be aligned with #legend:
- the #do: on line 6 should be under (self allCategories) and not under #unorderedList:
- the same for #listItem: on line 7, and the three messages applied to (html checkbox) on lines 8, 10-11, 13.
- #separatedBy: should stay under the #do: if you move it (but it is ok currently)

These is just my taste. Others might have different opinions.

Here is how I found have formatted it manually which is a bit different from what you did + points before:

renderCategoriesOn: html 
  html fieldSet
    legend: 'Choose one or more categories';
    with:   [html unorderedList: [
                 self allCategories
                      do: [:category |
                            html listItem: [
                                html checkbox
                                    value: (self belongsToCategory: category);
                                    onTrue: [self addCategory: category] onFalse: [self removeCategory: category];
                                    with: [html text: category asString]]]
                                    separatedBy: [html break]]]


Hope it can helps you

Bye


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Philippe Marschall
In reply to this post by Damien Pollet
2006/7/16, Damien Pollet <[hidden email]>:
> Hi,
>
> I've ported Gutenberg from VW. The package contains a pretty-printing
> algo (taken from Philip Wadler's papers on Haskell pretty-printer
> combinators) and a visitor to replace the RB one.
>
> It is available from:
>     http://www.squeaksource.com/Gutenberg.html

Cool

> Once loaded you can activate it by evaluating this:
>     RBProgramNode formatterClass: RBPrettyFormatter.
> You'll need to set the 'useRBASTForPrettyPrint' preference and use the
> browser in 'prettyPrint' mode.
>
> I need comments on the packaging, the pretty-printing itself (yes, it
> adds periods everywhere...) and ideas on making it customizable
> without basically rewriting a new visitor.

Maybe I'm just seeing things. But I'm missing stuff that should be there
- I think the preference should be named something like
useGutenbergForPrettyPrint (btw Markus renamed #useRBASTForPrettyPrint
to #useRBForPrettyPrint)
- an initialize on the class side, that installs the preference
- an unload on the same class, that removes the preference
- An override in Behavior >> #prettyPrinterClass, implemented so, that
you can switch between old pretty printer, rb pretty printer and
gutenberg.

> Oh, and I decline any responsibility if it breaks your code :}

Do you take responsibility if it  makes my code work? ;)

Philippe

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Marcus Denker

On 17.07.2006, at 09:33, Philippe Marschall wrote:

> 2006/7/16, Damien Pollet <[hidden email]>:
>> Hi,
>>
>> I've ported Gutenberg from VW. The package contains a pretty-printing
>> algo (taken from Philip Wadler's papers on Haskell pretty-printer
>> combinators) and a visitor to replace the RB one.
>>
>> It is available from:
>>     http://www.squeaksource.com/Gutenberg.html
>
> Cool
>
>> Once loaded you can activate it by evaluating this:
>>     RBProgramNode formatterClass: RBPrettyFormatter.
>> You'll need to set the 'useRBASTForPrettyPrint' preference and use  
>> the
>> browser in 'prettyPrint' mode.
>>
>> I need comments on the packaging, the pretty-printing itself (yes, it
>> adds periods everywhere...) and ideas on making it customizable
>> without basically rewriting a new visitor.
>
> Maybe I'm just seeing things. But I'm missing stuff that should be  
> there
> - I think the preference should be named something like
> useGutenbergForPrettyPrint (btw Markus renamed #useRBASTForPrettyPrint
> to #useRBForPrettyPrint)

Hmm... it's now useRBASTForPrettyPrint in the latest version





Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
In reply to this post by Damien Cassou-3
On 7/17/06, Damien Cassou <[hidden email]> wrote:
>  Here is an example of an automatic formatting:

It seems you're not using gutenberg... here is how it formats your code:
renderCategoriesOn: html
    (html fieldSet) legend: ''Choose one or more categories'';
        with: [
                html
                    unorderedList: [
                        self allCategories
                            do: [:category |
                                html
                                    listItem: [
                                        (html checkbox)
                                                value: (self

belongsToCategory: category);
                                            onTrue: [
                                                    self
                                                        addCategory: category.]
                                                onFalse: [
                                                    self

removeCategory: category.];
                                            with: [
                                                    html
                                                        text: category
                                                            asString.].].]
                            separatedBy: [html break.].].].

quite long... makes me doubt if that algorithm is of any use for
smalltalk code :/

--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
In reply to this post by Philippe Marschall
On 7/17/06, Philippe Marschall <[hidden email]> wrote:
> Maybe I'm just seeing things. But I'm missing stuff that should be there
> - I think the preference should be named something like
> useGutenbergForPrettyPrint (btw Markus renamed #useRBASTForPrettyPrint
> to #useRBForPrettyPrint)

Hmm in fact this preference activates the default RMFormatter, and
gutenberg is another subclass, so #useGutenbergForPrettyPrint would be
a separate pref.

For #useRBASTForPrettyPrint, how *should* it be named? I submitted
0003908 on mantis some time ago about related issues...

> - an initialize on the class side, that installs the preference
> - an unload on the same class, that removes the preference
> - An override in Behavior >> #prettyPrinterClass, implemented so, that
> you can switch between old pretty printer, rb pretty printer and
> gutenberg.

Thanks for the pointers, I must admit I still have to learn how the
packaging works in Squeak :)


--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Marcus Denker

On 17.07.2006, at 12:16, Damien Pollet wrote:

> On 7/17/06, Philippe Marschall <[hidden email]> wrote:
>> Maybe I'm just seeing things. But I'm missing stuff that should be  
>> there
>> - I think the preference should be named something like
>> useGutenbergForPrettyPrint (btw Markus renamed  
>> #useRBASTForPrettyPrint
>> to #useRBForPrettyPrint)
>
> Hmm in fact this preference activates the default RMFormatter, and
> gutenberg is another subclass, so #useGutenbergForPrettyPrint would be
> a separate pref.
>
> For #useRBASTForPrettyPrint, how *should* it be named? I submitted
> 0003908 on mantis some time ago about related issues...
>

I harvested all your fixes from that bugreport:  
#useRBASTForPrettyPrint is it,
and I fixed the one problem in the image (sending to the instance, not
the class of the Parser for prettyprinting).

There is another small fix for the same issue pending that will be in  
3.9 soon.
(http://bugs.impara.de/view.php?id=4273)


      Marcus



Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Pollet
On 7/17/06, Marcus Denker <[hidden email]> wrote:
> I harvested all your fixes from that bugreport:

Yes, I was not complaining...
Just wanted to make sure I hadn't submitted a 'back to the previous
feature' bugfix :)

--
 Damien Pollet
 type less, do more

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Cassou-3
In reply to this post by Damien Pollet
Here is how VW formats this same method. This is much better in my opinion:


renderCategoriesOn: html

    (html fieldSet)

        legend: 'Choose one or more categories';

        with:

                [html unorderedList:

                        [self allCategories do:

                                [:category |

                                html listItem:

                                        [(html checkbox)

                                            value: (self belongsToCategory: category);

                                            onTrue: [self addCategory: category]

                                                onFalse: [self removeCategory: category];

                                            with: [html text: category asString]]]

                            separatedBy: [html break]]]




Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Gutenberg: a pretty printer for Smalltalk

Damien Cassou-3
In reply to this post by Damien Pollet
Damien Pollet wrote:
> On 7/17/06, Damien Cassou <[hidden email]> wrote:
>>  Here is an example of an automatic formatting:
>
> It seems you're not using gutenberg...


you are right. It works now after having implemented fixes found in bug
0003908 on mantis and executed the code you give in your first post.


> quite long... makes me doubt if that algorithm is of any use for
> smalltalk code :/

Sure, no so good