Class: Rewriter

Class | Rewriter
In: | lib/rewriter.rb
Parent: | SexpProcessor

Rewriter (probably should be renamed) is a first-pass filter that normalizes some of ruby‘s ASTs to make them more processable later in the pipeline. It only has processors for what it is interested in, so real the individual methods for a better understanding of what it does.

### Methods

process_attrasgn process_call process_case process_defn process_fcall process_if process_iter process_self process_until process_vcall process_when process_zarray

### Public Instance methods

process_attrasgn(exp)

Rewrites :attrasgn nodes to the unified :call format:

[:attrasgn, lhs, :name=, args],

becomes:

[:call, lhs, :name=, args]

process_call(exp)

Rewrites :call nodes to the unified :call format: [:call, lhs, :name, args]

process_case(exp)

Rewrites :case/:when nodes as nested :if nodes.

process_defn(exp)

Rewrites :defn nodes to pull the functions arguments to the top:

Input:

      [:defn, name, [:scope, [:block, [:args, ...]]]]
      [:defn, name, [:fbody, [:scope, [:block, [:args, ...]]]]]
      [:defn, name, [:ivar, name]]
      [:defn, name, [:attrset, name]]

Output:

      [:defn, name, args, body]

process_fcall(exp)

Rewrites :fcall nodes to the unified :call format: [:call, lhs, :name, args]

process_if(exp)

I‘m not really sure what this is for, other than to guarantee that there are 4 elements in the sexp.

process_iter(exp)

Rewrites specific :iter nodes into while loops: [DOC]

process_self(exp)

Rewrites self into lvars

process_until(exp)

Rewrites until nodes into while nodes.

process_vcall(exp)

Rewrites :vcall nodes to the unified :call format: [:call, lhs, :name, args]

process_when(exp)

Rewrites :when nodes so :case can digest it into if/else structure [:when, [args], body]

process_zarray(exp)

Rewrites :zarray nodes to :array with no args.

[Validate]