diff --git a/matching.go b/matching.go index 09700cd..5afe6ca 100644 --- a/matching.go +++ b/matching.go @@ -98,12 +98,15 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset i++ } - // End-of-string reached. Go to any 0-states. Then check if any of our states are in the end position. - for _, state := range currentStates { - if len(state.transitions[EPSILON]) > 0 { - tempStates = append(tempStates, state.transitions[EPSILON]...) - } + // End-of-string reached. Go to any 0-states, until there are no more 0-states to go to. Then check if any of our states are in the end position. + // This is the exact same algorithm used inside the loop, so I should probably put it in a function. + zeroStates, isZero := takeZeroState(currentStates) + tempStates = append(tempStates, zeroStates...) + for isZero == true { + zeroStates, isZero = takeZeroState(tempStates) + tempStates = append(tempStates, zeroStates...) } + currentStates = append(currentStates, tempStates...) tempStates = nil