Sha256: 0022a0e4d4504c8828a4c676d0a8354b09b2c2093743ed8ca2ca90f8d947cc75

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Rley # This module is used as a namespace
  module Parser # This module is used as a namespace
    # Helper class that keeps track of the parse entries used
    # while a Parsing instance is constructing a parse forest.
    class ParseEntryTracker
      # The index of the current entry set
      attr_reader(:entry_set_index)

      # The current parse entry
      attr_reader(:parse_entry)

      # The already processed entries from current entry set
      attr_reader(:processed_entries)

      # Constructor.
      def initialize(aEntrySetIndex)
        self.entry_set_index = aEntrySetIndex
      end

      # Write accessor. Sets the value of the entry set index
      def entry_set_index=(anIndex)
        @entry_set_index = anIndex
        @processed_entries = {}
      end

      # Write accessor. Set the given parse entry as the current one.
      def parse_entry=(aParseEntry)
        raise StandardError, 'Nil parse entry' if aParseEntry.nil?

        @parse_entry = aParseEntry
        processed_entries[parse_entry] = true
      end

      # Take the first provided entry that wasn't processed yet.
      def select_entry(theEntrys)
        a_entry = theEntrys.find { |st| !processed_entries.include?(st) }
        self.parse_entry = a_entry
      end

      # The dotted item for the current parse entry.
      def curr_dotted_item
        parse_entry.dotted_rule
      end

      def symbol_on_left
        curr_dotted_item.prev_symbol
      end

      # Notification that one begins with the previous entry set
      def to_prev_entry_set
        self.entry_set_index = entry_set_index - 1
      end
    end # class
  end # module
end # module

# End of file

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rley-0.8.11 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.10 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.09 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.08 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.06 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.05 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.03 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.02 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.01 lib/rley/parser/parse_entry_tracker.rb
rley-0.8.00 lib/rley/parser/parse_entry_tracker.rb
rley-0.7.08 lib/rley/parser/parse_entry_tracker.rb