From f5c868566b6de23d3759c7c6d0bda398e3ef9a1c Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 14 Feb 2025 11:37:14 -0500 Subject: [PATCH] Added field to NFA, denoting if a node is lazy or not --- regex/nfa.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/regex/nfa.go b/regex/nfa.go index 8f454cf..1ec3693 100644 --- a/regex/nfa.go +++ b/regex/nfa.go @@ -34,6 +34,7 @@ type nfaState struct { isKleene bool // Identifies whether current node is a 0-state representing Kleene star isQuestion bool // Identifies whether current node is a 0-state representing the question operator isAlternation bool // Identifies whether current node is a 0-state representing an alternation + isLazy bool // Only for split states - Identifies whether or not to flip the order of branches (try one branch before the other) splitState *nfaState // Only for alternation states - the 'other' branch of the alternation ('next' is the first) assert assertType // Type of assertion of current node - NONE means that the node doesn't assert anything allChars bool // Whether or not the state represents all characters (eg. a 'dot' metacharacter). A 'dot' node doesn't store any contents directly, as it would take up too much space @@ -77,6 +78,7 @@ func cloneStateHelper(stateToClone *nfaState, cloneMap map[*nfaState]*nfaState) isKleene: stateToClone.isKleene, isQuestion: stateToClone.isQuestion, isAlternation: stateToClone.isAlternation, + isLazy: stateToClone.isLazy, assert: stateToClone.assert, allChars: stateToClone.allChars, except: append([]rune{}, stateToClone.except...), @@ -421,6 +423,7 @@ func (s nfaState) equals(other nfaState) bool { s.next == other.next && s.isKleene == other.isKleene && s.isQuestion == other.isQuestion && + s.isLazy == other.isLazy && s.isAlternation == other.isAlternation && s.splitState == other.splitState && s.assert == other.assert &&