Class: Ibex::Impact::AutomatonImpact

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(automaton, symbol_ids) ⇒ AutomatonImpact

Returns a new instance of AutomatonImpact.

RBS:

  • (IR::Automaton automaton, Array[Integer]) -> void

Parameters:



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_statesArray[Integer] (readonly)

RBS:

  • @automaton: IR::Automaton

  • @symbol_ids: Array[Integer]

  • @production_ids: Array[Integer]

Returns:

  • (Array[Integer])


11
12
13
# File 'lib/ibex/impact/automaton_impact.rb', line 11

def affected_states
  @affected_states
end

#conflict_statesArray[Integer] (readonly)

Signature:

  • Array[Integer]

Returns:

  • (Array[Integer])


13
14
15
# File 'lib/ibex/impact/automaton_impact.rb', line 13

def conflict_states
  @conflict_states
end

#production_idsArray[Integer] (readonly)

Signature:

  • Array[Integer]

Returns:

  • (Array[Integer])


12
13
14
# File 'lib/ibex/impact/automaton_impact.rb', line 12

def production_ids
  @production_ids
end

Instance Method Details

#affected_productionsArray[Integer]

RBS:

  • () -> Array[Integer]

Returns:

  • (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_idsArray[Integer]

RBS:

  • () -> Array[Integer]

Returns:

  • (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?]

RBS:

  • (Hash[Symbol, Object?] diff) -> Hash[Symbol, Object?]

Parameters:

  • diff (Hash[Symbol, Object?])

Returns:

  • (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_idsArray[Integer]

RBS:

  • () -> Array[Integer]

Returns:

  • (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_hHash[Symbol, Object?]

RBS:

  • () -> Hash[Symbol, Object?]

Returns:

  • (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