Class: Ibex::Impact::Graph
- Inherits:
-
Object
- Object
- Ibex::Impact::Graph
- Defined in:
- lib/ibex/impact/graph.rb
Overview
Combines reference, FIRST, and FOLLOW propagation dependencies.
Constant Summary collapse
- EDGE_KINDS =
: Array
%i[reference first follow_lhs follow_first].freeze
- KIND_ALIASES =
{ all: EDGE_KINDS, reference: [:reference], first: [:first], follow: %i[follow_lhs follow_first], follow_lhs: [:follow_lhs], follow_first: [:follow_first] }.freeze
Instance Attribute Summary collapse
-
#grammar ⇒ Object
readonly
: Hash[Symbol, Array[Symbol]].
-
#sets ⇒ Object
readonly
: Analysis::Sets.
Instance Method Summary collapse
- #adjacency(kind) ⇒ Object
- #edges(kind = :all) ⇒ Object
-
#initialize(grammar, sets: nil) ⇒ Graph
constructor
A new instance of Graph.
Constructor Details
Instance Attribute Details
#grammar ⇒ Object (readonly)
: Hash[Symbol, Array[Symbol]]
40 41 42 |
# File 'lib/ibex/impact/graph.rb', line 40 def grammar @grammar end |
#sets ⇒ Object (readonly)
: Analysis::Sets
41 42 43 |
# File 'lib/ibex/impact/graph.rb', line 41 def sets @sets end |
Instance Method Details
#adjacency(kind) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ibex/impact/graph.rb', line 60 def adjacency(kind) result = Array.new(@grammar.symbols.length) { [] } edges(kind).each { |edge| result[edge.source] << edge.target } result.each(&:uniq!) result end |
#edges(kind = :all) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/ibex/impact/graph.rb', line 52 def edges(kind = :all) selected = KIND_ALIASES.fetch(kind.to_sym) { raise ArgumentError, "unknown impact edge kind #{kind}" } return selected.flat_map { |name| @edges.fetch(name) }.sort_by(&:sort_key) if selected.length > 1 @edges.fetch(selected.fetch(0)) end |