I'll have another crack at it ;)

I think you're problem is that you're only matching on :factor, whereas your
hash contains :plus and :term too, so you need to match those also. The
logic seems to be that you have to explicitly match all labelled terms that
are present. Of course, just because you'ved matched them, you don't have to
use them.

For example:

#!/usr/bin/env ruby
require 'parslet'
require 'ap'

t = {
    :result => {
                :term => {
                            :factor => "a",
                            :plus => "+ ",
                            :term=>"b"
                        }
                }
    }

transform = Parslet::Transform.new do
    rule(:factor => simple(:str), :plus => simple(:str2), :term =>
simple(:str3)) { str }
end

puts "original:"
ap t
puts "transform:"
ap transform.apply(t)  # matches



will give the result:

transform:
{
    :result => {
        :term => "a"
    }
}



Which is closer to what you wanted?

cheers

ant

Reply via email to