Hi guys,
I am still trying to understand the Parslet transformations.
My rules are:
Rule Leaves:
@t.rule(:ident => simple(:str)) { str
#Some code
str
}
Rule Factor1:
@t.rule(:factor => simple(:str)) { str
#some code
str
}
Rule Factor2:
@t.rule(:factor => simple(:str)) { str
#Some code
str
}
My program code is:
transforms = [Leaves, Factor1, Factor2]
str = ' a + b '
tree = parser.parse_with_debug( str )
puts "PARSING : #{str}"
puts "ORIGINAL TREE: "
pp tree
transforms.inject(tree) do | tree, rule |
puts "\nTRANSFORMED BY RULE: #{rule.to_s}"
trans = rule.new(st,at,gt)
tree = trans.apply(tree)
pp tree
tree
end
The output is:
PARSING : a + b
ORIGINAL TREE:
{:result=>
{:term=>
{:factor=>{:ident=>"a"@2},
:plus=>"+ "@4,
:term=>{:factor=>{:ident=>"b"@6}}}}}
TRANSFORMED BY RULE: Leaves
{:result=>{:term=>{:factor=>"a"@2, :plus=>"+ "@4, :term=>{:factor=>"b"@6}}}}
TRANSFORMED BY RULE: Factor1
{:result=>{:term=>{:factor=>"a"@2, :plus=>"+ "@4, :term=>"b"@6}}}
TRANSFORMED BY RULE: Factor2
{: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?"
Thanks in advance,
Thiel