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