Class: Sexp

Class | Sexp
In: | lib/sexp.rb
Parent: | Array

Sexps are the basic storage mechanism of SexpProcessor. Sexps have a `type` (to be renamed `node_type`) which is the first element of the Sexp. The type is used by SexpProcessor to determine whom to dispatch the Sexp to for processing.

### Methods

=== =~ array_type? each_of_type find_and_replace_all for from_array gsub method_missing new sexp_body shift structure sub

### Public Class methods

for(klass, method = nil, walk_ancestors = false)

Creates a new Sexp for `klass` or `method` in `klass`.

If `walk_ancestors` is true and `method` is provided, walks the ancestors of `klass` until a method definition is found.

from_array(a)

Creates a new Sexp from Array `a`, typically from ParseTree::translate.

new(*args)

Create a new Sexp containing `args`.

### Public Instance methods

===(sexp)

Returns true if this Sexp‘s pattern matches `sexp`.

=~(pattern)

Returns true if this Sexp matches `pattern`. (Opposite of #===.)

array_type?()

Returns true if the node_type is `array` or `args`.

REFACTOR: to TypedSexp - we only care when we have units.

each_of_type(t, &b)

Enumeratates the sexp yielding to `b` when the node_type == `t`.

find_and_replace_all(from, to)

Replaces all elements whose node_type is `from` with `to`. Used only for the most trivial of rewrites.

gsub(pattern, repl)

Replaces all Sexps matching `pattern` with Sexp `repl`.

method_missing(meth, delete=false)

Returns the node named `node`, deleting it if `delete` is true.

sexp_body()

Returns the Sexp without the node_type.

shift()

If run with debug, Sexp will raise if you shift on an empty Sexp. Helps with debugging.

structure()

Returns the bare bones structure of the sexp. s(:a, :b, s(:c, :d), :e) => s(:a, s(:c))

sub(pattern, repl)

Replaces the Sexp matching `pattern` with `repl`.

[Validate]