Class RawParseTree
In: lib/parse_tree.rb
test/test_parse_tree.rb
Parent: Object

ParseTree is a RubyInline-style extension that accesses and traverses the internal parse tree created by ruby.

  class Example
    def blah
      return 1 + 1
    end
  end

  ParseTree.new.parse_tree(Example)
  => [[:class, :Example, :Object,
         [:defn,
           "blah",
           [:scope,
             [:block,
               [:args],
               [:return, [:call, [:lit, 1], "+", [:array, [:lit, 1]]]]]]]]]

Methods

Constants

VERSION = '3.0.9'
NODE_NAMES = [ # 00 :method, :fbody, :cfunc, :scope, :block, :if, :case, :when, :opt_n, :while, # 10 :until, :iter, :for, :break, :next, :redo, :retry, :begin, :rescue, :resbody, # 20 :ensure, :and, :or, :not, :masgn, :lasgn, :dasgn, :dasgn_curr, :gasgn, :iasgn, # 30 :cdecl, :cvasgn, :cvdecl, :op_asgn1, :op_asgn2, :op_asgn_and, :op_asgn_or, :call, :fcall, :vcall, # 40 :super, :zsuper, :array, :zarray, :hash, :return, :yield, :lvar, :dvar, :gvar, # 50 :ivar, :const, :cvar, :nth_ref, :back_ref, :match, :match2, :match3, :lit, :str, # 60 :dstr, :xstr, :dxstr, :evstr, :dregx, :dregx_once, :args, :argscat, :argspush, :splat, # 70 :to_ary, :svalue, :block_arg, :block_pass, :defn, :defs, :alias, :valias, :undef, :class, # 80 :module, :sclass, :colon2, :colon3, :cref, :dot2, :dot3, :flip2, :flip3, :attrset, # 90 :self, :nil, :true, :false, :defined, # 95 :newline, :postexe, :alloca, :dmethod, :bmethod, # 100 :memo, :ifunc, :dsym, :attrasgn, :last

Public Class methods

Initializes a ParseTree instance. Includes newline nodes if include_newlines which defaults to +$DEBUG+.

Front end translation method.

Public Instance methods

Main driver for ParseTree. Returns an array of arrays containing the parse tree for klasses.

Structure:

  [[:class, classname, superclassname, [:defn :method1, ...], ...], ...]

NOTE: v1.0 - v1.1 had the signature (klass, meth=nil). This wasn‘t used much at all and since parse_tree_for_method already existed, it was deemed more useful to expand this method to do multiple classes.

Returns the parse tree for just one method of a class klass.

Format:

  [:defn, :name, :body]

Returns the parse tree for a string source.

Format:

  [[sexps] ... ]

[Validate]