Fixed bug with last state detection

master
Aadhavan Srinivasan 2 months ago
parent 82b33f3c9a
commit 8394e7867e

@ -128,6 +128,9 @@ func thompson(re string) State {
for i := range s1.output { for i := range s1.output {
s1.output[i].transitions[s1.content] = &s1 s1.output[i].transitions[s1.content] = &s1
} }
// Reset output to s1 (in case s1 was a union operator state, which has multiple outputs)
s1.output = nil
s1.output = append(s1.output, &s1)
nfa = append(nfa, s1) nfa = append(nfa, s1)
case '|': case '|':
s1 := pop(&nfa) s1 := pop(&nfa)

@ -21,6 +21,10 @@ func verifyLastStatesHelper(state *State, visited map[*State]bool) {
state.isLast = true state.isLast = true
return return
} }
if state.transitions[state.content] == state { // Eg. a*
state.isLast = true
return
}
if visited[state] == true { if visited[state] == true {
return return
} }

Loading…
Cancel
Save