Wrote function to check if a state is in an nfaState, based on the Equals function
This commit is contained in:
31
regex/nfa.go
31
regex/nfa.go
@@ -47,7 +47,6 @@ type nfaState struct {
|
||||
// The following properties depend on the current match - I should think about resetting them for every match.
|
||||
zeroMatchFound bool // Whether or not the state has been used for a zero-length match - only relevant for zero states
|
||||
threadGroups []Group // Assuming that a state is part of a 'thread' in the matching process, this array stores the indices of capturing groups in the current thread. As matches are found for this state, its groups will be copied over.
|
||||
threadSP int // The string pointer of the thread - where it is in the input string
|
||||
}
|
||||
|
||||
// Clones the NFA starting from the given state.
|
||||
@@ -123,7 +122,6 @@ func resetThreadsHelper(state *nfaState, visitedMap map[*nfaState]bool) {
|
||||
}
|
||||
// Assuming it hasn't been visited
|
||||
state.threadGroups = nil
|
||||
state.threadSP = 0
|
||||
visitedMap[state] = true
|
||||
if state.isAlternation {
|
||||
resetThreadsHelper(state.next, visitedMap)
|
||||
@@ -408,3 +406,32 @@ func zeroLengthMatchState() nfaState {
|
||||
start.assert = alwaysTrueAssert
|
||||
return start
|
||||
}
|
||||
|
||||
func (s nfaState) equals(other nfaState) bool {
|
||||
return slices.Equal(s.content, other.content) &&
|
||||
s.isEmpty == other.isEmpty &&
|
||||
s.isLast == other.isLast &&
|
||||
slices.Equal(s.output, other.output) &&
|
||||
s.next == other.next &&
|
||||
s.isKleene == other.isKleene &&
|
||||
s.isQuestion == other.isQuestion &&
|
||||
s.isAlternation == other.isAlternation &&
|
||||
s.splitState == other.splitState &&
|
||||
s.assert == other.assert &&
|
||||
s.allChars == other.allChars &&
|
||||
slices.Equal(s.except, other.except) &&
|
||||
s.lookaroundNFA == other.lookaroundNFA &&
|
||||
s.groupBegin == other.groupBegin &&
|
||||
s.groupEnd == other.groupEnd &&
|
||||
s.groupNum == other.groupNum &&
|
||||
slices.Equal(s.threadGroups, other.threadGroups)
|
||||
}
|
||||
|
||||
func stateExists(list []nfaState, s nfaState) bool {
|
||||
for i := range list {
|
||||
if list[i].equals(s) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user