I finished implementing all the printing code for a little AST pretty-printer. It's in the 'codegen' project in svn, under src/nodeprinter.rb. It makes use of the ever-so-secret "JRuby" class that provides access to the AST.

An example, based on our own little "etc.rb" script:

BlockNode[]: {NewlineNode[], NewlineNode[], NewlineNode[]}
 NewlineNode[]
  CallNode[] new
   ConstNode [Struct] Struct
 NewlineNode[]
  ModuleNode[]
   Colon2Node [Process] Process
   ScopeNode[]
    NewlineNode[]
     DefsNode[] times
      SelfNode[]
      ArgsNode[]
      ScopeNode[]
       NewlineNode[]
        CallNode[] new
         Colon2Node [ConstNode [Struct]Tms] Tms
          ConstNode [Struct] Struct
 NewlineNode[]
  ModuleNode[]
   Colon2Node [Signal] Signal
   ScopeNode[]
    NewlineNode[]
     DefsNode[] trap
      SelfNode[]
      ArgsNode[]
       sig
      ScopeNode[]

It's obviously not EVERYTHING stored in the AST, but it's almost everything and it gives you a good idea of the parse structure. This script could be a good base for a sort of "uneval" that takes in a node and outputs the Ruby code that produced it. Comments and questions are welcome.

--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to