class Rley::Parser::ParseEntrySet
Responsibilities:
-
To know all the parse entries in the set
Attributes
@return [Array<ParseEntry>] The array of parse entries
@return [Hash] A Hash with pairs { hash of ParseEntry
=> ParseEntry
}
Public Class Methods
Source
# File lib/rley/parser/parse_entry_set.rb, line 23 def initialize @entries = [] @membership = {} @entries4term = Hash.new { |hash, key| hash[key] = [] } @entries4n_term = Hash.new { |hash, key| hash[key] = [] } end
Constructor.
Public Instance Methods
Source
# File lib/rley/parser/parse_entry_set.rb, line 43 def [](index) entries[index] end
Access the entry at given position
Source
# File lib/rley/parser/parse_entry_set.rb, line 80 def ambiguities complete_entries = entries.select(&:exit_entry?) return [] if complete_entries.size <= 1 # Group parse entries by lhs symbol and origin groupings = complete_entries.group_by do |entry| entry.vertex.dotted_item.lhs.object_id.to_s end # Retain the groups having more than one element. ambiguous_groups = [] groupings.each_value do |a_group| ambiguous_groups << a_group if a_group.size > 1 end ambiguous_groups end
Return an Array of Arrays of ambiguous parse entries.
Source
# File lib/rley/parser/parse_entry_set.rb, line 104 def count_edges # rubocop: disable Lint/UselessAssignment entries.reduce(0) do |sub_result, entry| sub_result += entry.vertex.edges.size end end
Source
# File lib/rley/parser/parse_entry_set.rb, line 55 def entries4n_term(aNonTerminal) @entries4n_term.fetch(aNonTerminal, []) end
Returns a Hash with pairs of the form:
non terminal symbol => [ parse entry expecting the non-terminal ]
Source
# File lib/rley/parser/parse_entry_set.rb, line 49 def entries4term(aTerminal) @entries4term.fetch(aTerminal, []) end
Returns a Hash with pairs of the form:
terminal symbol => [ parse entry expecting the terminal ]
Source
# File lib/rley/parser/parse_entry_set.rb, line 100 def expected_terminals return @entries4term.keys end
The list of distinct expected terminal symbols. An expected symbol is on the left of a dot in a parse state of the parse set.
Source
# File lib/rley/parser/parse_entry_set.rb, line 33 def inspect result = +"#<#{self.class.name}:#{object_id}" result << ' @entries=[' entries.each { |e| result << e.inspect } result << ']>' result end
Returns a string containing a human-readable representation of the set of parse entries. @return [String]
Source
# File lib/rley/parser/parse_entry_set.rb, line 63 def push_entry(anEntry) entry_key = anEntry.hash # @type var result : ParseEntry | false result = membership.fetch(entry_key, false) unless result @entries << anEntry membership[entry_key] = anEntry expecting = anEntry.next_symbol add_lookup4symbol(anEntry) if expecting result = anEntry end # @type var result : ParseEntry result end
Append the given entry (if it isn’t yet in the set) to the list of parse entries @param anEntry [ParseEntry] the parse entry to push. @return [ParseEntry] the passed parse entry if it pushes it
Private Instance Methods
Source
# File lib/rley/parser/parse_entry_set.rb, line 114 def add_lookup4symbol(anEntry) symb = anEntry.next_symbol if symb.is_a?(Syntax::Terminal) @entries4term[symb] << anEntry else # @type var symb : Syntax::NonTerminal @entries4n_term[symb] << anEntry end end
rubocop: enable Lint/UselessAssignment