diff --git a/matching.go b/matching.go index 9a18987..83e7f04 100644 --- a/matching.go +++ b/matching.go @@ -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. // It uses the same algorithm to find zero-states as the one inside the loop, // 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. -// 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) +func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*State) bool { zeroStates, isZero := takeZeroState(states, numGroups, idx) tempstates := make([]*State, 0, len(zeroStates)+len(states)) tempstates = append(tempstates, states...) @@ -113,10 +109,10 @@ func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*State) (bo } for _, state := range tempstates { 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. @@ -177,18 +173,13 @@ func findAllMatchesHelper(start *State, str []rune, offset int, numGroups int) ( if offset == len(str) { // 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. + // TODO - fill in capturing groups for these matches if start.isEmpty { to_return := newMatch(numGroups + 1) if start.groupBegin { to_return[start.groupNum].startIdx = offset } - if ok, openGrps, closeGrps := zeroMatchPossible(str, offset, numGroups, start); ok { - for _, gIdx := range openGrps { - to_return[gIdx].startIdx = offset - } - for _, gIdx := range closeGrps { - to_return[gIdx].endIdx = offset - } + if ok := zeroMatchPossible(str, offset, numGroups, start); ok { to_return[0] = Group{offset, offset} 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 if foundPath == false { - if ok, _, _ := zeroMatchPossible(str, i, numGroups, currentStates...); ok { + if ok := zeroMatchPossible(str, i, numGroups, currentStates...); ok { if tempIndices[0].isValid() == false { tempIndices[0] = Group{startIdx, startIdx} }