Class: Ibex::Impact::AutomatonImpact
- Inherits:
-
Object
- Object
- Ibex::Impact::AutomatonImpact
- Defined in:
- lib/ibex/impact/automaton_impact.rb,
sig/ibex/impact/automaton_impact.rbs
Overview
Maps propagated grammar symbols to parser states and conflict changes.
Instance Attribute Summary collapse
- #affected_states ⇒ Array[Integer] readonly
- #conflict_states ⇒ Array[Integer] readonly
- #production_ids ⇒ Array[Integer] readonly
Instance Method Summary collapse
- #affected_productions ⇒ Array[Integer]
- #affected_state_ids ⇒ Array[Integer]
- #conflict_changes(diff) ⇒ Hash[Symbol, Object?]
- #conflict_state_ids ⇒ Array[Integer]
-
#initialize(automaton, symbol_ids) ⇒ AutomatonImpact
constructor
A new instance of AutomatonImpact.
- #to_h ⇒ Hash[Symbol, Object?]
Constructor Details
#initialize(automaton, symbol_ids) ⇒ AutomatonImpact
Returns a new instance of AutomatonImpact.
16 17 18 19 20 21 22 23 |
# File 'lib/ibex/impact/automaton_impact.rb', line 16 def initialize(automaton, symbol_ids) @automaton = automaton @symbol_ids = symbol_ids.uniq.sort #: Array[Integer] @production_ids = affected_productions @affected_states = affected_state_ids @conflict_states = conflict_state_ids freeze end |
Instance Attribute Details
#affected_states ⇒ Array[Integer] (readonly)
11 12 13 |
# File 'lib/ibex/impact/automaton_impact.rb', line 11 def affected_states @affected_states end |
#conflict_states ⇒ Array[Integer] (readonly)
13 14 15 |
# File 'lib/ibex/impact/automaton_impact.rb', line 13 def conflict_states @conflict_states end |
#production_ids ⇒ Array[Integer] (readonly)
12 13 14 |
# File 'lib/ibex/impact/automaton_impact.rb', line 12 def production_ids @production_ids end |
Instance Method Details
#affected_productions ⇒ Array[Integer]
38 39 40 41 42 |
# File 'lib/ibex/impact/automaton_impact.rb', line 38 def affected_productions @automaton.grammar.productions.filter_map do |production| production.id if @symbol_ids.include?(production.lhs) || production.rhs.any? { |id| @symbol_ids.include?(id) } end.sort end |
#affected_state_ids ⇒ Array[Integer]
45 46 47 48 49 |
# File 'lib/ibex/impact/automaton_impact.rb', line 45 def affected_state_ids @automaton.states.filter_map do |state| state.id if state.items.any? { |item| @production_ids.include?(item.production) } end.sort end |
#conflict_changes(diff) ⇒ Hash[Symbol, Object?]
26 27 28 |
# File 'lib/ibex/impact/automaton_impact.rb', line 26 def conflict_changes(diff) diff.fetch(:conflicts) #: Hash[Symbol, Object?] end |
#conflict_state_ids ⇒ Array[Integer]
52 53 54 |
# File 'lib/ibex/impact/automaton_impact.rb', line 52 def conflict_state_ids @automaton.states.filter_map { |state| state.id unless state.conflicts.empty? }.sort end |
#to_h ⇒ Hash[Symbol, Object?]
31 32 33 |
# File 'lib/ibex/impact/automaton_impact.rb', line 31 def to_h { states: @affected_states, productions: @production_ids, conflict_states: @conflict_states } end |