Hi Ant,
Thanks for your answer.
I agree with your comment and changed the Factor2 rule into:
@t.rule(:factor => subtree(:x)) { x
#Some code
x
}
But it still gives the same output: {:result=>{:term=>{:factor=>"a"@2,
:plus=>"+ "@4, :term=>"b"@6}}}
I read the Parslet rdoc documentation but unfortunately it lacks genuine
examples of transformation rules for those who want to do semantic actions.
It requires a lot of patience to struggle on :-)
Cheers,
Thiel
Op 5-5-2011 13:59, Ant Skelton schreef:
Hi.
I am still trying to understand the Parslet transformations.
My rules are:
Rule Factor2:
@t.rule(:factor => simple(:str)) { str
#Some code
str
}
{:result=>{:term=>{:factor=>"a"@2, :plus=>"+ "@4, :term=>"b"@6}}}
My question: "why does not :term=>{factor=>"a" being transformed in
:term => "a" after firing the Factor2 rule?"
Because you asked to match a simple() thing, but in your parse tree,
:factor points to a subtree, not a simple scalar.
Something else that always trips me up is that sequence() only matches
arrays of simple things, not arrays that contain other sequences, or
subtrees.
HTH
ant