Adding a statement when rewriting

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

Adding a statement when rewriting

Sean P. DeNigris
Administrator
rewriter := RBParseTreeRewriter new
                replace: 'attributes := OrderedCollection new.'
                with: 'attributes := Set new'.
        tree := ConfigurationTemplate parseTreeFor: #customProjectAttributes.
        rewriter executeTree: tree.
returns true, but:
        rewriter := RBParseTreeRewriter new
                replace: 'attributes := OrderedCollection new.'
                with: 'attributes := Set new. self halt'.
        tree := ConfigurationTemplate parseTreeFor: #customProjectAttributes.
        rewriter executeTree: tree.
returns false.

Why does adding a statement cause this rewrite to fail and how should I bet doing it?

Thanks,
Sean


Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Adding a statement when rewriting

stephane ducasse

On Feb 9, 2013, at 9:19 PM, Sean P. DeNigris <[hidden email]> wrote:

> rewriter := RBParseTreeRewriter new
> replace: 'attributes := OrderedCollection new.'
> with: 'attributes := Set new'.
> tree := ConfigurationTemplate parseTreeFor: #customProjectAttributes.
> rewriter executeTree: tree.
> returns true, but:
> rewriter := RBParseTreeRewriter new
> replace: 'attributes := OrderedCollection new.'
> with: 'attributes := Set new. self halt'.
> tree := ConfigurationTemplate parseTreeFor: #customProjectAttributes.
> rewriter executeTree: tree.
> returns false.
>
> Why does adding a statement cause this rewrite to fail and how should I bet
> doing it?

I'm puzzle too.
I started to write a chapter on the rewrtie engine to force me to look at it but I got distracted.

>
> Thanks,
> Sean
>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/Adding-a-statement-when-rewriting-tp4668879.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Adding a statement when rewriting

Sean P. DeNigris
Administrator
stephane ducasse wrote
I'm puzzle too.
Thanks for taking a look. I got it to work by matching the source of the whole method like this:
'| `@Temps |
attributes := OrderedCollection new.
(condition) ifTrue: [ attributes add: #zinc ] "My new statement here".
``@.Statements.'.

My naive guess is that if you try to modify more than a single node, you must operate on the next biggest node...
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Adding a statement when rewriting

Sean P. DeNigris
Administrator
In reply to this post by stephane ducasse
stephane ducasse wrote
I started to write a chapter on the rewrtie engine to force me to look at it but I got distracted.
I found http://www.refactory.com/the-rewritetool which is a good starting point...
Cheers,
Sean