### Problem with transformation rule

- From:
- Thiel Chang
- Date:
- 2011-04-28 @ 12:57

Hi guys,
I tried to transform the following parse tree:
{:ae=>
[{:term=>{:factor=>{:ident=>"a"@0}}},
{:plus=>"+ "@2,
:term1=>
[{:factor=>{:ident=>"b"@4}},
{:mult=>"* "@6, :factor1=>{:ident=>"c"@8}}]}]}
One of the transformation rules I applied is:
@t.rule(:factor1 => simple(:str)) { str
puts "Test Factor1"
str
}
And the result after the transformation is:
{:ae=>
["a"@0, {:plus=>"+ "@2, :term1=>["b"@4, {:mult=>"* "@6, :factor1=>"c"@8}]}]}
However, I expected in the output: "Test Factor1" but it did not.
It seems if this rule was not or ( could not be) applied.
Can anyone explain why it did not?
Thanks in advance ,
Thiel

### Re: Problem with transformation rule

- From:
- Kaspar Schiess
- Date:
- 2011-04-28 @ 13:56

Hi Thiel,
> {:mult=>"* "@6, :factor1=>{:ident=>"c"@8}}]}]}
...
> @t.rule(:factor1 => simple(:str)) { ... }
...
> {:ae=>
>
> ["a"@0, {:plus=>"+ "@2, :term1=>["b"@4, {:mult=>"* "@6, :factor1=>"c"@8}]}]}
The fact that :factor1 contains a different value after the transform
means that another rule but the one you show here has applied. The
transformation code is crafted such that you cannot create endless loops
with it - it replaces leaves first, moving up the tree until it reaches
the root. Only once.
So once a rule has applied, no other rules are applied to the result of
the first rule. I am sure that if you were to reapply the same set of
transformation rules to the result you give above, you would trigger
:factor1 => simple(...).
Please give the code samples on something like https://gist.github.com/
next time - They will be easier to work on.
regards,
kaspar