Move DFA#nil_transition_states to NFA::State

This commit is contained in:
josh committed 2021-05-21 14:27:42 -04:00
1 parent f64f3683c6
commit 952bffc33c
2 files changed
+22 -24

No files matched your search

+1 -24
View File
@@ -8,30 +8,7 @@ module Imbecile
nfas.each do |nfa|
start_nfa.start_state.add_transition(nil, nfa.start_state)
end
nil_transition_states = nil_transition_states(start_nfa.start_state)
end
private
# Determine the set of states that can be reached by nil transitions
# from the given state.
#
# @return [Set<NFA::State>]
# Set of states.
def nil_transition_states(state)
states = Set[state]
analyze_state = lambda do |state|
state.transitions.each do |range, dest_state|
if range.nil?
unless states.include?(dest_state)
states << dest_state
analyze_state[dest_state]
end
end
end
end
analyze_state[state]
states
nil_transition_states = start_nfa.start_state.nil_transition_states
end
end
+21
View File
@@ -16,6 +16,27 @@ module Imbecile
@transitions << [code_point, destination_state]
end
# Determine the set of states that can be reached by nil transitions.
# from this state.
#
# @return [Set<NFA::State>]
# Set of states.
def nil_transition_states
states = Set[self]
analyze_state = lambda do |state|
state.transitions.each do |range, dest_state|
if range.nil?
unless states.include?(dest_state)
states << dest_state
analyze_state[dest_state]
end
end
end
end
analyze_state[self]
states
end
end
attr_accessor :start_state