Sha256: 50dcf56630d7819598eebc4f26c4d57e606812139d6686fad0a28872d42521d3

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

require 'forwardable' # Delegation

module Rley # This module is used as a namespace
  module Parser # This module is used as a namespace
    class StateSet
      extend Forwardable
      def_delegators :states, :empty?, :size, :first, :each
      
      # The set of parse states
      attr_reader(:states)
      
    
      def initialize()
        @states = []
      end
      
      # Append the given state (if it isn't yet in the set) 
      # to the list of states
      # @param aState [ParseState] the state to push.
      def push_state(aState)
        @states << aState unless include?(aState)
      end
      
      # The list of ParseState that expect the given terminal
      def states_expecting(aTerminal)
        return states.select { |s| s.dotted_rule.next_symbol == aTerminal }
      end
      
      # The list of ParseState that involve the given production
      def states_for(aProduction)
        return states.select { |s| s.dotted_rule.production == aProduction }
      end
      
      private
      
      def include?(aState)
        # TODO: make it better than linear search
        return states.include?(aState)
      end
    end # class
  end # module
end # module
# End of file

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rley-0.0.17 lib/rley/parser/state_set.rb
rley-0.0.16 lib/rley/parser/state_set.rb
rley-0.0.15 lib/rley/parser/state_set.rb
rley-0.0.14 lib/rley/parser/state_set.rb
rley-0.0.13 lib/rley/parser/state_set.rb
rley-0.0.12 lib/rley/parser/state_set.rb
rley-0.0.11 lib/rley/parser/state_set.rb
rley-0.0.10 lib/rley/parser/state_set.rb
rley-0.0.09 lib/rley/parser/state_set.rb
rley-0.0.08 lib/rley/parser/state_set.rb
rley-0.0.07 lib/rley/parser/state_set.rb
rley-0.0.06 lib/rley/parser/state_set.rb
rley-0.0.05 lib/rley/parser/state_set.rb