Class: SexpProcessor

Class | SexpProcessor
In: | lib/sexp_processor.rb
Parent: | Object

SexpProcessor provides a uniform interface to process Sexps.

In order to create your own SexpProcessor subclass you‘ll need to call super in the initialize method, then set any of the Sexp flags you want to be different from the defaults.

SexpProcessor uses a Sexp‘s type to determine which process method to call in the subclass. For Sexp `s(:lit, 1)` SexpProcessor will call process_lit, if it is defined.

You can also specify a default method to call for any Sexp types without a process_<type> method or use the default processor provided to skip over them.

Here is a simple example:

      class MyProcessor < SexpProcessor
        def initialize
          super
          self.strict = false
        end

        def process_lit(exp)
          val = exp.shift
          return val
        end
      end

### Methods

assert_empty assert_type new on_error_in process process_dummy rewrite

### Attributes

auto_shift_type | [RW] | Automatically shifts off the Sexp type before handing the Sexp to process_<type>
context | [R] | Return a stack of contexts. Most recent node is first.
debug | [RW] | A Hash of Sexp types and Regexp. Print a debug message if the Sexp type matches the Hash key and the Sexp‘s inspect output matches the Regexp.
default_method | [RW] | A default method to call if a process_<type> method is not found for the Sexp type.
expected | [RW] | Expected result class
require_empty | [RW] | Raise an exception if the Sexp is not empty after processing
strict | [RW] | Raise an exception if no process_<type> method is found for a Sexp.
unsupported | [RW] | An array that specifies node types that are unsupported by this processor. SexpProcessor will raise UnsupportedNodeError if you try to process one of those node types.
warn_on_default | [RW] | Emit a warning when the method in default_method is called.

### Public Class methods

new()

Creates a new SexpProcessor. Use super to invoke this initializer from SexpProcessor subclasses, then use the attributes above to customize the functionality of the SexpProcessor

### Public Instance methods

assert_empty(meth, exp, exp_orig)
assert_type(list, typ)

Raises unless the Sexp type for `list` matches `typ`

on_error_in(node_type, &block)

Registers an error handler for `node`

process(exp)

Default Sexp processor. Invokes process_<type> methods matching the Sexp type given. Performs additional checks as specified by the initializer.

process_dummy(exp)

A fairly generic processor for a dummy node. Dummy nodes are used when your processor is doing a complicated rewrite that replaces the current sexp with multiple sexps.

Bogus Example:

      def process_something(exp)
        return s(:dummy, process(exp), s(:extra, 42))
      end

rewrite(exp)

[Validate]