From ea64ddc88ae1de199998da75e4add446863aed1a Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Wed, 20 Nov 2024 10:38:41 -0500 Subject: [PATCH] Removed unnecessary duplication of assertion checking --- nfa.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/nfa.go b/nfa.go index 8436e91..095eeb6 100644 --- a/nfa.go +++ b/nfa.go @@ -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)] {