Fixed bug with last state detection

This commit is contained in:
2024-10-21 23:17:10 -04:00
parent 82b33f3c9a
commit 8394e7867e
2 changed files with 7 additions and 0 deletions

View File

@@ -128,6 +128,9 @@ func thompson(re string) State {
for i := range s1.output {
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)
case '|':
s1 := pop(&nfa)

4
nfa.go
View File

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