From a631fc289c0ba5794a24df23909903890be54b93 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 21 Feb 2025 08:44:24 -0500 Subject: [PATCH] Clone 'isBackreference' and 'referredGroup' NFA fields, because they aren't thread variables --- regex/nfa.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/regex/nfa.go b/regex/nfa.go index 1ec3693..2232fb9 100644 --- a/regex/nfa.go +++ b/regex/nfa.go @@ -45,11 +45,11 @@ type nfaState struct { groupBegin bool // Whether or not the node starts a capturing group groupEnd bool // Whether or not the node ends a capturing group groupNum int // Which capturing group the node starts / ends + isBackreference bool // Whether or not current node is backreference + referredGroup int // If current node is a backreference, the node that it points to // The following properties depend on the current match - I should think about resetting them for every match. - 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. - isBackreference bool // Whether or not current node is backreference - referredGroup int // If current node is a backreference, the node that it points to - threadBackref int // If current node is a backreference, how many characters to look forward into the referred group + 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. + threadBackref int // If current node is a backreference, how many characters to look forward into the referred group } // Clones the NFA starting from the given state. @@ -86,6 +86,8 @@ func cloneStateHelper(stateToClone *nfaState, cloneMap map[*nfaState]*nfaState) groupEnd: stateToClone.groupEnd, groupBegin: stateToClone.groupBegin, groupNum: stateToClone.groupNum, + isBackreference: stateToClone.isBackreference, + referredGroup: stateToClone.referredGroup, } cloneMap[stateToClone] = clone for i, s := range stateToClone.output {