Mark regex NFA end state as accepting the token
This commit is contained in:
parent
7196a0605a
commit
c77c81bf25
@ -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
|
||||||
|
@ -5,6 +5,8 @@ module Imbecile
|
|||||||
|
|
||||||
class State
|
class State
|
||||||
|
|
||||||
|
attr_accessor :accepts
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@transitions = []
|
@transitions = []
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user