From: Macario Ortega Date: 2009-08-05T02:05:40+09:00 Subject: Re: Kind of ParsTree for 1.9.1 Thomas, Thanks for you reply. I wish there was more info on ripper, definitelly useful :) Allthough nice thing about ParseTree is that it works with "live" objects, meanining there is no need to resort to the source you can extract the AST for a Class even it was defined with eval or redefined later. Thomas Chust wrote: > 2009/8/4 Macario Ortega : >> [...] >> Hi, I've been missing ParseTree very badly in 1.9.1. So in my naivit� I >> decided to try to convert YARV iseq's to Sexp's similar of those >> produced by ParseTree. >> [...] >> Is someone aware of a similar effort? >> [...] > > Hello, > > 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 > } > > $ 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. > > cu, > Thomas -- Posted via http://www.ruby-forum.com/.