From: Caleb Clausen Date: 2009-08-05T02:04:51+09:00 Subject: Re: Kind of ParsTree for 1.9.1 On 8/4/09, Thomas Chust wrote: > the Ruby 1.9.1p243 that I installed from source came with a library > called 'ripper' that can produce S-expression parse trees from Ruby > code, like this: > > $ cat foo.rb > require 'ripper' > require 'pp' > > pp Ripper.sexp %{ > def foo > :bar > end > } Hey, I've been wondering how one gets a tree out of ripper, or even if it can be done at all. Thanks! > $ ruby foo.rb > [:program, > [[:def, > [:@ident, "foo", [2, 6]], > [:params, nil, nil, nil, nil, nil], > [:body_stmt, > [[:symbol_literal, [:symbol, [:@ident, "bar", [3, 5]]]]], > nil, > nil, > nil]]]] > > I played around with that a little, but didn't try to code anything > serious. Also, since I'm new to Ruby and haven't used ParseTree > before, I don't know how compatible the abstract syntax tree > representations are. That's definitely not compatible with any of the ParseTree formats.