[Pharo-project] learning rewrite rules

Lukas Renggli renggli at gmail.com
Thu Nov 4 10:57:02 CET 2010


On 4 November 2010 10:09, Stéphane Ducasse <stephane.ducasse at inria.fr> wrote:
> I'm adding some other files (in french) :(
> but I'm stuck with git....

git pull
git add french-rewrite.tex
git commit
git push

>> Yeah, where do I find that chapter?
>>
>> There is a section on the AST matching/search in my PhD as Helvetia
>> builds on top of it. Not on the AST rewriting though, Helvetia uses a
>> different mechanism there. Still it might be a good start.
>>
>> Lukas
>>
>> On 4 November 2010 09:49, Stéphane Ducasse <stephane.ducasse at inria.fr> wrote:
>>> lukas
>>>
>>> I would love to have a chapter on Rules. I have a starter that I wrote long time ago for the squeak french book
>>> but it would be cool if you could add to it.
>>>
>>> Stef
>>>
>>> On Nov 4, 2010, at 12:55 AM, Lukas Renggli wrote:
>>>
>>>>> 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:
>>>>
>>>>    `@.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 }
>>>>
>>>> Cheers,
>>>> Lukas
>>>>
>>>> --
>>>> Lukas Renggli
>>>> www.lukas-renggli.ch
>>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> www.lukas-renggli.ch
>>
>
>
>



-- 
Lukas Renggli
www.lukas-renggli.ch




More information about the Pharo-project mailing list