From: Eric Hodel Date: 2006-11-14T06:01:16+09:00 Subject: Re: Ruby parsing in Ruby On Nov 12, 2006, at 8:35 AM, Wil wrote: > Timothy Goddard wrote: >> Wil wrote: >>> What would be the easiest way to parse Ruby source into parse >>> trees in >>> Ruby? Thanks! >> >> Take a look at parsetree. It should be able to do this quite happily >> and uses Ruby's own parser. This avoids compatibility issues. > > Hrm, I remember stumbling over parsetree, and it seems like the > classes > need to already exist in object/class space (at least from the example > that they give). What if you just had a string of the source of the > classes? Perhaps they're one in the same. I should look at Parsetree > a little bit closer. $ ri ParseTree | grep string parse_tree, parse_tree_for_method, parse_tree_for_string, process $ ri ParseTree#parse_tree_for_string ---------------------------------------- ParseTree#parse_tree_for_string parse_tree_for_string(source, filename = nil, line = nil, newlines = false) ------------------------------------------------------------------------ Returns the parse tree for a string +source+. Format: [[sexps] ... ] -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com