Removed return values that weren't being used

master
Aadhavan Srinivasan 1 week ago
parent 332c2fe5a2
commit 8c8e209587

@ -94,11 +94,7 @@ func takeZeroState(states []*State, numGroups int, idx int) (rtv []*State, isZer
// from any of the given states, given the string and our position in it. // from any of the given states, given the string and our position in it.
// It uses the same algorithm to find zero-states as the one inside the loop, // It uses the same algorithm to find zero-states as the one inside the loop,
// so I should probably put it in a function. // so I should probably put it in a function.
// It also returns all the capturing groups that both begin and end at the current index. func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*State) bool {
// This is because, by definition, zero-states don't move forward in the string.
func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*State) (bool, []int, []int) {
allOpenParenGroups := make([]int, 0)
allCloseParenGroups := make([]int, 0)
zeroStates, isZero := takeZeroState(states, numGroups, idx) zeroStates, isZero := takeZeroState(states, numGroups, idx)
tempstates := make([]*State, 0, len(zeroStates)+len(states)) tempstates := make([]*State, 0, len(zeroStates)+len(states))
tempstates = append(tempstates, states...) tempstates = append(tempstates, states...)
@ -113,10 +109,10 @@ func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*State) (bo
} }
for _, state := range tempstates { for _, state := range tempstates {
if state.isEmpty && (state.assert == NONE || state.checkAssertion(str, idx)) && state.isLast { if state.isEmpty && (state.assert == NONE || state.checkAssertion(str, idx)) && state.isLast {
return true, allOpenParenGroups, allCloseParenGroups return true
} }
} }
return false, allOpenParenGroups, allCloseParenGroups return false
} }
// Prunes the slice by removing overlapping indices. // Prunes the slice by removing overlapping indices.
@ -177,18 +173,13 @@ func findAllMatchesHelper(start *State, str []rune, offset int, numGroups int) (
if offset == len(str) { if offset == len(str) {
// Get all zero-state matches. If we can get to a zero-state without matching anything, we // Get all zero-state matches. If we can get to a zero-state without matching anything, we
// can add a zero-length match. This is all true only if the start state itself matches nothing. // can add a zero-length match. This is all true only if the start state itself matches nothing.
// TODO - fill in capturing groups for these matches
if start.isEmpty { if start.isEmpty {
to_return := newMatch(numGroups + 1) to_return := newMatch(numGroups + 1)
if start.groupBegin { if start.groupBegin {
to_return[start.groupNum].startIdx = offset to_return[start.groupNum].startIdx = offset
} }
if ok, openGrps, closeGrps := zeroMatchPossible(str, offset, numGroups, start); ok { if ok := zeroMatchPossible(str, offset, numGroups, start); ok {
for _, gIdx := range openGrps {
to_return[gIdx].startIdx = offset
}
for _, gIdx := range closeGrps {
to_return[gIdx].endIdx = offset
}
to_return[0] = Group{offset, offset} to_return[0] = Group{offset, offset}
return true, to_return, offset + 1 return true, to_return, offset + 1
} }
@ -329,7 +320,7 @@ func findAllMatchesHelper(start *State, str []rune, offset int, numGroups int) (
// Check if we can find a zero-length match // Check if we can find a zero-length match
if foundPath == false { if foundPath == false {
if ok, _, _ := zeroMatchPossible(str, i, numGroups, currentStates...); ok { if ok := zeroMatchPossible(str, i, numGroups, currentStates...); ok {
if tempIndices[0].isValid() == false { if tempIndices[0].isValid() == false {
tempIndices[0] = Group{startIdx, startIdx} tempIndices[0] = Group{startIdx, startIdx}
} }

Loading…
Cancel
Save