Methods
Classes and Modules
Module StateParser::Constants
Class StateParser::Marker
Class StateParser::State
Attributes
[R] machine
Public Class methods
new( machine )
# File lib/facets/more/stateparser.rb, line 328
  def initialize( machine )
    @machine = machine
  end
Public Instance methods
parse( text )
# File lib/facets/more/stateparser.rb, line 332
  def parse( text )
    stack = reparse( text )
    return stack
  end
Private Instance methods
reparse( text )
# File lib/facets/more/stateparser.rb, line 339
  def reparse( text )

    state = State.new( text, @machine )
    root = Marker.new #state.stack
    current = root
    finished = nil

    until finished
      state.clear_current
      index = text.length  # by comparision to find the nearest match

      unless state.tkstack.empty? #state.stack.empty?
        raise "not a marker on end of stack?" unless Marker === state.stack.last  # should not happen
        index = state.next_end( index )
      end

      machine.tokens.each do |tokn|
        index = state.next_start( tokn, index )
        # NOTE not making sure there is a matching end token.
        # bad or good idea? the code might go here if need be
        # but the parser is faster without it.
      end

#       # finished is +nil+ if were just getting started
#       # +false+ while running and then +true+ when done.
#       unless state.stack.last
#         finished = ( finished.nil? ? false : true )
#         state.mode = :FINISH if finished
#       end

      case state.mode
      when :START
        buffer_text = state.text[state.offset...index]
        current << buffer_text unless buffer_text.empty?

        # signal flush
        state.trigger_flush( buffer_text )

        # adjust current
        mock = state.mock( current )
        current << mock
        current = mock
        state.stack << mock

        # add token to token stack
        state.tkstack << current.token if current.token

        state.next_offset

        # signal start trigger
        state.trigger

      when :END
        buffer_text = state.text[state.offset...index].chomp("\n")
        current << buffer_text unless buffer_text.empty?

        # signal flush
        state.trigger_flush( buffer_text )

        # adjust current
        mock = state.stack.pop
        mock.outer_range = mock.begins...state.current_ends
        mock.inner_range = mock.ends...state.current_begins
        current = mock.parent

        # remove token from token stack
        state.tkstack.pop

        state.next_offset

        # signal ending trigger
        state.end_trigger

      when :UNIT
        buffer_text = state.text[state.offset...index] #.chomp("\n")
        current << buffer_text unless buffer_text.empty?

        # signal flush
        state.trigger_flush( buffer_text )

        # adjust current
        mock = state.mock( current )

        mock.outer_range = state.current_begins...state.current_ends
        current << mock

        #state.tkstack << current.token

        state.next_offset

        # signal start trigger
        state.trigger

      else
        buffer_text = state.text[state.offset..-1].chomp("\n")
        current << buffer_text unless buffer_text.empty?

        # signal flush
        state.trigger_flush( buffer_text )

        # signal finish
        state.trigger_finish

        # wrap it up
        finished = true

      end #case state.mode

    end #until finished

    return root
  end