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 find_node find_nodes from_array gsub line mass method_missing new sexp_body sexp_type shift structure sub

### Attributes

comments | [RW] |
file | [RW] |
line | [W] |

### Public Class methods

from_array(a)

Creates a new Sexp from Array `a`.

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.

find_node(name, delete = false)
find_nodes(name)

Find every node with type `name`.

gsub(pattern, repl)

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

line(n=nil)

If passed a line number, sets the line and returns self. Otherwise returns the line number. This allows you to do message cascades and still get the sexp back.

mass()

Returns the size of the sexp, flattened.

method_missing(meth, delete = false)

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

sexp_body()

Returns the Sexp body, ie the values without the node type.

sexp_type()

Returns the node type of the Sexp.

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]