[Pharo-project] learning rewrite rules

Lukas Renggli renggli at gmail.com
Thu Nov 4 00:55:02 CET 2010

> If I try to match it like:
>  '`@browser showOn: `@target; from: `@origin; using: [ `@browser ``@.statements]'

The match expression

    `@browser ``@.statements

doesn't make sense. Statements (.) cannot be a message selector that
would be expected after a receiver. Also, you cannot have a selector
list (@) if you don't give also an argument list to match. So the
closest valid thing is

    `@browser `message

which looks for unary message sends (recursive is not necessary here
either, because there is nothing to recurse into), or

    `@browser `@message: ``@message

which looks for arbitrary message sends and recursively into all arguments.

> It seems to only get those appearances which contain a single appearance of browser inside the block.

As I wrote in the previous mail you need to do it with nested
rewrites. Inside the block you match for any sequence of statements:


And as replacement you use the `{ :context | ... } trick to perform a
new rewrite somehow along the following untested lines:

    `{ :context |
        RBParseTreeRewriter new
            " replace whatever matched to `@browser with the variable a "
            replaceTree: (context at: '`@browser') with: (RBParser
parseExpression: 'a');
            " execute on the list of statements "
            executeTree: (context at: '`@.statements');
            " return the rewritten tree "
            tree }


Lukas Renggli

More information about the Pharo-project mailing list