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

Public Instance methods

Rewrites :attrasgn nodes to the unified :call format:

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

becomes:

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

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

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

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]

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

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

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

Rewrites self into lvars

Rewrites until nodes into while nodes.

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

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

Rewrites :zarray nodes to :array with no args.

[Validate]