Mark regex NFA end state as accepting the token

This commit is contained in:
Josh Holtrop 2021-05-18 16:34:26 -04:00
parent 7196a0605a
commit c77c81bf25
2 changed files with 4 additions and 1 deletions

View File

@ -41,8 +41,9 @@ module Imbecile
# Build NFA from each token expression. # Build NFA from each token expression.
@tokens.each do |token_name, token_def| @tokens.each do |token_name, token_def|
token_def[:regex] = Regex.new(token_def[:pattern]) token_def[:regex] = Regex.new(token_def[:pattern])
token_def[:regex].nfa.end_state.accepts = token_name
end end
dfa = DFA.new(@tokens.map {|token_name, token_def| token_def[:regex].nfa}) dfa = Regex::DFA.new(@tokens.map {|token_name, token_def| token_def[:regex].nfa})
end end
end end

View File

@ -5,6 +5,8 @@ module Imbecile
class State class State
attr_accessor :accepts
def initialize def initialize
@transitions = [] @transitions = []
end end