[Pharo-project] learning rewrite rules

Lukas Renggli renggli at gmail.com
Wed Nov 3 16:55:59 CET 2010

> However, the problem here is that I do not know how to replace all the "browser" appearances with "a" inside the andShow: block. I tried multiple variations like the one below, but I could not seem to get it to work as I want.
>        replace: '`@browser showOn: `@target; from: `@origin; using: [
>                `@browser ``@.statements]' with: '`@browser transmit to: `@target; from: `@origin; andShow: [:a | a ``@.statements]';
> Can anyone point me into the right direction?

Yes, you can put in the replacement code some code snippets like

    `{ :context | ... }

Replace the "..." with some Smalltalk code that returns a parse tree
node (or a collection of parse-tree nodes). The context-variable is a
dictionary containing the current bindings of the matched nodes. So
you can perform a sub-rewrite on ``@.statements to replace all
accesses to `@browser with the variable a; and you return the
transformed tree.


Lukas Renggli

More information about the Pharo-project mailing list