Implement PCRE Matching (prefer left-branch) #2

Merged
Rockingcool merged 48 commits from implementPCREMatchingRules into master 2025-02-09 15:24:29 -06:00
10 changed files with 438 additions and 584 deletions
Showing only changes of commit 1f5a363539 - Show all commits

View File

@@ -133,7 +133,7 @@ func resetThreadsHelper(state *nfaState, visitedMap map[*nfaState]bool) {
// Checks if the given state's assertion is true. Returns true if the given
// state doesn't have an assertion.
func (s nfaState) checkAssertion(str []rune, idx int) bool {
func (s nfaState) checkAssertion(str []rune, idx int, preferLongest bool) bool {
if s.assert == alwaysTrueAssert {
return true
}
@@ -183,7 +183,7 @@ func (s nfaState) checkAssertion(str []rune, idx int) bool {
strToMatch = string(runesToMatch)
}
regComp := Reg{startState, s.lookaroundNumCaptureGroups, s.lookaroundRegex}
regComp := Reg{startState, s.lookaroundNumCaptureGroups, s.lookaroundRegex, preferLongest}
matchIndices := regComp.FindAll(strToMatch)
numMatchesFound := 0
@@ -210,9 +210,9 @@ func (s nfaState) checkAssertion(str []rune, idx int) bool {
}
// Returns true if the contents of 's' contain the value at the given index of the given string
func (s nfaState) contentContains(str []rune, idx int) bool {
func (s nfaState) contentContains(str []rune, idx int, preferLongest bool) bool {
if s.assert != noneAssert {
return s.checkAssertion(str, idx)
return s.checkAssertion(str, idx, preferLongest)
}
if idx >= len(str) {
return false