AST visualization with Roassal

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

AST visualization with Roassal

Mark Rizun
Hi, everyone!

First of all, using Roassal is fun and effective :)
But while working on AST visualization I found that sometimes Roassal builds wrong tree layout (or maybe I'm just doing something wrong).
For instance, try two following scripts in playground:

*************************
#1

| ast builder |
        ast := RBParser parseExpression: 'self foo. self foo'.
        builder := RTMondrian new.
        builder shape ellipse size: 15.
        builder nodes: ast allChildren.
        builder edges connectFrom: #parent.
        builder layout tree.
        builder build.
        builder view

*************************

*************************
#2

        | ast builder |
        ast := RBParser parseExpression: 'self foo. super foo'.
        builder := RTMondrian new.
        builder shape ellipse size: 15.
        builder nodes: ast allChildren.
        builder edges connectFrom: #parent.
        builder layout tree.
        builder build.
        builder view

*************************

First script builds wrong tree. I think it's because somewhere in roassal objects (in this case ast nodes) are compared by value. That is why when we have two equal receivers in script #1 it fails to build a tree.

Thanks,
Mark
Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

Peter Uhnak
I think it's because somewhere in roassal
objects (in this case ast nodes) are compared by value.

Pretty much; there is test for equality

RTGroup>>elementFromModel: anObject
    ^ self detect: [ :el | el model = anObject ] ifNone: [ nil ]

and equality is more often than not wanted.

So solution might be to tell Mondrian that you want to compare by identity and not equality?

Peter
Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

Mark Rizun
Pretty much; there is test for equality

RTGroup>>elementFromModel: anObject
    ^ self detect: [ :el | el model = anObject ] ifNone: [ nil ]

and equality is more often than not wanted.

So solution might be to tell Mondrian that you want to compare by identity and not equality?

Exactly! I'd like to have an option to select how I want to compare objects.
Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

Marcus Denker-4

On 30 Jul 2015, at 16:47, Mark Rizun <[hidden email]> wrote:

Pretty much; there is test for equality

RTGroup>>elementFromModel: anObject
    ^ self detect: [ :el | el model = anObject ] ifNone: [ nil ]

and equality is more often than not wanted.

So solution might be to tell Mondrian that you want to compare by identity and not equality?

Exactly! I'd like to have an option to select how I want to compare objects.

It uses already a block to do the comparision… if you make that pluggable
(add ivar, set it to  [ :el | el model = anObject ] in #initialize, add accessor)
then you can just provide your own block with #== instead.

Marcus
Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

abergel
In reply to this post by Peter Uhnak
Frankly, I often find weird to override #=

Alexandre
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Jul 30, 2015, at 11:41 AM, Peter Uhnák <[hidden email]> wrote:

I think it's because somewhere in roassal
objects (in this case ast nodes) are compared by value.

Pretty much; there is test for equality

RTGroup>>elementFromModel: anObject
    ^ self detect: [ :el | el model = anObject ] ifNone: [ nil ]

and equality is more often than not wanted.

So solution might be to tell Mondrian that you want to compare by identity and not equality?

Peter

Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

abergel
In reply to this post by Mark Rizun
Hi Mark,

I have introduced a class RTIdentityGroup. 

You can do:

 -=-=-= -=-=-= -=-=-= -=-=-=
ast := RBParser parseExpression: 'self foo. self foo'.
builder := RTMondrian new.
builder shape ellipse size: 15.
nodes := builder nodes: ast allChildren.
builder edges 
elements: nodes asIdentityGroup;
connectFrom: #parent.
builder layout tree.
builder 
 -=-=-= -=-=-= -=-=-= -=-=-=

You obtain this:

Maybe Marcus will have the same problem.

Cheers,
Alexandre

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Jul 30, 2015, at 11:47 AM, Mark Rizun <[hidden email]> wrote:

Pretty much; there is test for equality

RTGroup>>elementFromModel: anObject
    ^ self detect: [ :el | el model = anObject ] ifNone: [ nil ]

and equality is more often than not wanted.

So solution might be to tell Mondrian that you want to compare by identity and not equality?

Exactly! I'd like to have an option to select how I want to compare objects.

Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

Marcus Denker-4

> On 30 Jul 2015, at 17:26, Alexandre Bergel <[hidden email]> wrote:
>
> Hi Mark,
>
> I have introduced a class RTIdentityGroup.
>
> You can do:
>
>  -=-=-= -=-=-= -=-=-= -=-=-=
> ast := RBParser parseExpression: 'self foo. self foo'.
> builder := RTMondrian new.
> builder shape ellipse size: 15.
> nodes := builder nodes: ast allChildren.
> builder edges
> elements: nodes asIdentityGroup;
> connectFrom: #parent.
> builder layout tree.
> builder
>  -=-=-= -=-=-= -=-=-= -=-=-=
>
> You obtain this:
> <Screen Shot 2015-07-30 at 12.25.25 PM.png>
>
> Maybe Marcus will have the same problem.

Yes, we checked. This explains the strange “too large” rectangle :-)

        Marcus


Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

Mark Rizun

Great, everybody is happy ;)
Thanks Alex !

30 лип. 2015 5:40 пп "Marcus Denker" <[hidden email]> пише:

> On 30 Jul 2015, at 17:26, Alexandre Bergel <[hidden email]> wrote:
>
> Hi Mark,
>
> I have introduced a class RTIdentityGroup.
>
> You can do:
>
>  -=-=-= -=-=-= -=-=-= -=-=-=
>       ast := RBParser parseExpression: 'self foo. self foo'.
>       builder := RTMondrian new.
>       builder shape ellipse size: 15.
>       nodes := builder nodes: ast allChildren.
>       builder edges
>               elements: nodes asIdentityGroup;
>               connectFrom: #parent.
>       builder layout tree.
>       builder
>  -=-=-= -=-=-= -=-=-= -=-=-=
>
> You obtain this:
> <Screen Shot 2015-07-30 at 12.25.25 PM.png>
>
> Maybe Marcus will have the same problem.

Yes, we checked. This explains the strange “too large” rectangle :-)

        Marcus


Reply | Threaded
Open this post in threaded view
|

Re: AST visualization with Roassal

abergel
In reply to this post by Marcus Denker-4
Excellent!

Alexandre
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Jul 30, 2015, at 12:40 PM, Marcus Denker <[hidden email]> wrote:

Yes, we checked. This explains the strange “too large” rectangle :-)