From: Charles Thornton Date: 2008-02-10T04:27:00+09:00 Subject: Re: IRHG -- Dumping T-Nodes Thanks, I will study your info, Chuck T. Phlip wrote: > Charles Thornton wrote: > >> I have been looking a 'rubynode' . >> >> The problem is I don't have a clear idea of the >> actual structure of the AST. >> >> I assume that their is a tree structure of Nodes > > Yep. For some, the tree is simply a transliteration of the input. 'if > x then y end' turns into an 'if' node with leaves containing a > condition, a 'then' node, and an 'else' node. (So does ? : , by the way!) > > For others Ruby statements, the tree is deep and sick. For example, > all the arguments of a function, and some of its local variables, are > packed up into a node called "scope", where they don't exactly match > their location in the source. > > Pull down these files and play with them: > > http://phlip.svnrepository.com/svn/yar_wiki/lib/assert_2_0.rb > http://phlip.svnrepository.com/svn/yar_wiki/lib/ruby_reflector.rb > http://phlip.svnrepository.com/svn/yar_wiki/test/assert_2_0_test.rb > http://phlip.svnrepository.com/svn/yar_wiki/test/ruby_reflector_test.rb > > They should, roughly, how to disassemble a transformed list of > RubyNode objects back into a rough form of Ruby source. To see a tree > of nodes in action, add pp node to any of the functions like def _if, > and run all the tests. >