diff --git a/main.go b/main.go index 7a2f5ac..a04a100 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/nfa.go b/nfa.go index 0244b91..70bd855 100644 --- a/nfa.go +++ b/nfa.go @@ -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 }