class Pushdown::State

A componented state object in a Pushdown automaton

Attributes

data[R]

The state data object that was used to create the State (if any)

Public Class Methods

inherited( subclass ) click to toggle source

Inheritance callback – allow subclasses to be instantiated, and add some class-instance data to them.

Calls superclass method
# File lib/pushdown/state.rb, line 26
def self::inherited( subclass )
        super

        subclass.public_class_method( :new )
        subclass.instance_variable_set( :@transitions, {} )
end
new( data=nil ) click to toggle source

Set up new States with an optional data object.

# File lib/pushdown/state.rb, line 60
def initialize( data=nil )
        @data = data
end
register_transition( type ) click to toggle source

Register a transition type declaration method.

# File lib/pushdown/state.rb, line 39
def self::register_transition( type )
        type = type.to_sym
        meth = lambda do |transition_name, *args|
                self.transitions[ transition_name ] = [ type, *args ]
        end

        method_name = "transition_%s" % [ type ]
        self.log.info "Setting up transition declaration method %p" % [ method_name ]
        define_singleton_method( method_name, &meth )
end
type_name() click to toggle source

Return the transition's type as a lowercase Symbol, such as that specified in transition declarations.

# File lib/pushdown/state.rb, line 53
def self::type_name
        class_name = self.name or return :anonymous
        return class_name.sub( /.*::/, '' ).downcase.to_sym
end

Public Instance Methods

description() click to toggle source

Return a description of the State as an engine phrase.

# File lib/pushdown/state.rb, line 144
def description
        return "%#x" % [ self.class.object_id ] unless self.class.name
        return self.class.name.sub( /.*::/, '' ).
                gsub( /([A-Z])([A-Z])/ ) { "#$1 #$2" }.
                gsub( /([a-z])([A-Z])/ ) { "#$1 #$2" }.downcase
end
on_event( event ) click to toggle source

Event callback – called by the automaton when its on_<stackname>_event method is called. This method can return a Transition or a Symbol which maps to one.

# File lib/pushdown/state.rb, line 109
def on_event( event )
        return nil # no-op
end
on_pause() click to toggle source

Stack callback – called when another state is pushed over this one.

# File lib/pushdown/state.rb, line 91
def on_pause
        return nil # no-op
end
on_resume() click to toggle source

Stack callback – called when another state is popped off from in front of this one, making it the current state.

# File lib/pushdown/state.rb, line 98
def on_resume
        return nil # no-op
end
on_start() click to toggle source

Stack callback – called when the state is added to the stack.

# File lib/pushdown/state.rb, line 79
def on_start
        return nil # no-op
end
on_stop() click to toggle source

Stack callback – called when the state is removed from the stack.

# File lib/pushdown/state.rb, line 85
def on_stop
        return nil # no-op
end
shadow_update( *data ) click to toggle source

State callback – interval callback called when the state is on the stack, even when the state is not the current one.

# File lib/pushdown/state.rb, line 127
def shadow_update( *data )
        return nil # no-op
end
transition( transition_name, automaton, stack_name ) click to toggle source

Create a new instance of Pushdown::Transition named transition_name that has been declared using one of the Transition Declaration methods.

# File lib/pushdown/state.rb, line 154
def transition( transition_name, automaton, stack_name )
        self.log.debug "Looking up the %p transition for %p via %p" %
                [ transition_name, self, automaton ]

        transition_type, state_class_name = self.class.transitions[ transition_name ]
        raise "no such transition %p for %p" % [ transition_name, self.class ] unless transition_type

        if state_class_name
                state_class = automaton.class.pushdown_state_class( stack_name, state_class_name )
                state_data = self.data

                return Pushdown::Transition.
                        create( transition_type, transition_name, state_class, state_data )
        else
                return Pushdown::Transition.create( transition_type, transition_name )
        end
end
type_name() click to toggle source

Return the transition's type as a lowercase Symbol, such as that specified in transition declarations.

# File lib/pushdown/state.rb, line 138
def type_name
        return self.class.type_name
end
unknown() click to toggle source

Allow introspection on declared transitions

# File lib/pushdown/state.rb, line 21
singleton_class.attr_reader :transitions
update( *data ) click to toggle source

State callback – interval callback called when the state is the current one. This method can return a Transition or a Symbol which maps to one.

# File lib/pushdown/state.rb, line 120
def update( *data )
        return nil # no-op
end