From 1fd48ae6143e57e829e7cb93608356890c9c8606 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 3 Feb 2025 16:49:10 -0500 Subject: [PATCH] Store the current string pointer as a 'thread variable' (allows us to simulate backtracking) --- regex/nfa.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/regex/nfa.go b/regex/nfa.go index 8f63eb0..0ceea1b 100644 --- a/regex/nfa.go +++ b/regex/nfa.go @@ -45,6 +45,7 @@ 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. @@ -120,6 +121,7 @@ func resetThreadsHelper(state *nfaState, visitedMap map[*nfaState]bool) { } // Assuming it hasn't been visited state.threadGroups = nil + state.threadSP = 0 visitedMap[state] = true for _, v := range state.transitions { for _, nextState := range v {