Skip to content

Instantly share code, notes, and snippets.

@chrislloyd
Created January 31, 2011 04:52
Show Gist options
  • Save chrislloyd/803657 to your computer and use it in GitHub Desktop.
Save chrislloyd/803657 to your computer and use it in GitHub Desktop.
require 'parslet'
tree = {:multi=>
[{:tag=>{:name=>"Foo"}},
{:block=>{:name=>"Foo", :multi=>[{:static=>"Bar"}]}}]}
transformer = Parslet::Transform.new do
rule :static => simple(:text) do
'STATIC'
end
rule :tag => {:name => simple(:name)} do
'TAG'
end
rule :multi => subtree(:body) do
[:multi, *body]
end
end
p transformer.apply tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment