Removed unnecessary duplication of assertion checking

This commit is contained in:
2024-11-20 10:38:41 -05:00
parent 1ba871d618
commit ea64ddc88a

15
nfa.go
View File

@@ -111,17 +111,10 @@ func (s State) matchesFor(str []rune, idx int) ([]*State, int) {
// Assertions can be viewed as 'checks'. If the check fails, we return
// an empty array and 0.
// If it passes, we treat it like any other state, and return all the transitions.
if s.assert == SOS && idx != 0 {
return make([]*State, 0), -1
}
if s.assert == EOS && idx != len(str) {
return make([]*State, 0), -1
}
if s.assert == WBOUND && !isWordBoundary(str, idx) {
return make([]*State, 0), -1
}
if s.assert == NONWBOUND && isWordBoundary(str, idx) {
return make([]*State, 0), -1
if s.assert != NONE {
if s.checkAssertion(str, idx) == false {
return make([]*State, 0), -1
}
}
listTransitions := s.transitions[int(str[idx])]
for _, dest := range s.transitions[int(ANY_CHAR)] {