Move FA#build_tables to Lexer::DFA
This commit is contained in:
parent
9459883e74
commit
51a31317a6
@ -56,35 +56,6 @@ module Imbecile
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_tables
|
|
||||||
transition_table = []
|
|
||||||
state_table = []
|
|
||||||
states = enumerate
|
|
||||||
states.each do |state, id|
|
|
||||||
accepts =
|
|
||||||
if state.accepts.nil?
|
|
||||||
TOKEN_NONE
|
|
||||||
elsif state.accepts.name
|
|
||||||
state.accepts.id
|
|
||||||
else
|
|
||||||
TOKEN_DROP
|
|
||||||
end
|
|
||||||
state_table << {
|
|
||||||
transition_table_index: transition_table.size,
|
|
||||||
n_transitions: state.transitions.size,
|
|
||||||
accepts: accepts,
|
|
||||||
}
|
|
||||||
state.transitions.each do |transition|
|
|
||||||
transition_table << {
|
|
||||||
first: transition.code_point_range.first,
|
|
||||||
last: transition.code_point_range.last,
|
|
||||||
destination: states[transition.destination],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
[transition_table, state_table]
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,35 @@ module Imbecile
|
|||||||
@start_state = @states[0]
|
@start_state = @states[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_tables
|
||||||
|
transition_table = []
|
||||||
|
state_table = []
|
||||||
|
states = enumerate
|
||||||
|
states.each do |state, id|
|
||||||
|
accepts =
|
||||||
|
if state.accepts.nil?
|
||||||
|
TOKEN_NONE
|
||||||
|
elsif state.accepts.name
|
||||||
|
state.accepts.id
|
||||||
|
else
|
||||||
|
TOKEN_DROP
|
||||||
|
end
|
||||||
|
state_table << {
|
||||||
|
transition_table_index: transition_table.size,
|
||||||
|
n_transitions: state.transitions.size,
|
||||||
|
accepts: accepts,
|
||||||
|
}
|
||||||
|
state.transitions.each do |transition|
|
||||||
|
transition_table << {
|
||||||
|
first: transition.code_point_range.first,
|
||||||
|
last: transition.code_point_range.last,
|
||||||
|
destination: states[transition.destination],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
[transition_table, state_table]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def register_nfa_state_set(nfa_state_set)
|
def register_nfa_state_set(nfa_state_set)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user