Implement PCRE Matching (prefer left-branch) #2

Merged
Rockingcool merged 48 commits from implementPCREMatchingRules into master 2025-02-09 15:24:29 -06:00
6 changed files with 559 additions and 364 deletions
Showing only changes of commit ed4ffde64e - Show all commits

View File

@@ -379,17 +379,17 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in
if currentState.isKleene { // Reverse order of adding things
rightState := currentState.splitState
copyThread(rightState, currentState)
currentStates = append(currentStates, *currentState.splitState)
currentStates = slices.Insert(currentStates, currentStateIdx+1, *rightState)
leftState := currentState.next
copyThread(leftState, currentState)
currentStates = append(currentStates, *currentState.next)
currentStates = slices.Insert(currentStates, currentStateIdx+2, *leftState)
} else {
leftState := currentState.next
copyThread(leftState, currentState)
currentStates = append(currentStates, *currentState.next)
currentStates = slices.Insert(currentStates, currentStateIdx+1, *leftState)
rightState := currentState.splitState
copyThread(rightState, currentState)
currentStates = append(currentStates, *currentState.splitState)
currentStates = slices.Insert(currentStates, currentStateIdx+2, *rightState)
}
continue
}
@@ -417,6 +417,8 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in
currentStates = slices.Insert(currentStates, currentStateIdx+1, allMatches...)
} else if currentState.groupEnd {
currentStates = append(currentStates, allMatches...)
} else if currentState.assert != noneAssert {
currentStates = append(currentStates, allMatches...)
} else {
nextStates = append(nextStates, allMatches...)
}