Class: RegularExpression::NFA::State

Inherits:
Object
  • Object
show all
Defined in:
lib/regular_expression/nfa.rb

Direct Known Subclasses

FinishState, StartState

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



16
17
18
# File 'lib/regular_expression/nfa.rb', line 16

def initialize
  @transitions = []
end

Instance Attribute Details

#transitionsObject (readonly)



14
15
16
# File 'lib/regular_expression/nfa.rb', line 14

def transitions
  @transitions
end

Instance Method Details

#add_transition(transition) ⇒ Object



20
21
22
# File 'lib/regular_expression/nfa.rb', line 20

def add_transition(transition)
  transitions << transition
end

#to_dot(graph, visited) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/regular_expression/nfa.rb', line 24

def to_dot(graph, visited)
  return visited[self] if visited.include?(self)

  source = graph.add_node(object_id, label: "")
  visited[self] = source

  transitions.each do |transition|
    target = transition.state.to_dot(graph, visited)
    source.connect(target, label: transition.label)
  end

  source
end