@ -251,35 +251,39 @@ func (regex Reg) FindAllSubmatch(str string) []Match {
return indices
return indices
}
}
func addStateToList ( idx int , list [ ] nfaState , state nfaState , threadGroups [ ] Group ) [ ] nfaState {
func addStateToList ( str [ ] rune , idx int , list [ ] nfaState , state nfaState , threadGroups [ ] Group ) [ ] nfaState {
if stateExists ( list , state ) {
if stateExists ( list , state ) {
return list
return list
}
}
if state . isKleene || state . isQuestion {
if state . isKleene || state . isQuestion {
copyThread ( state . splitState , state )
copyThread ( state . splitState , state )
list = addStateToList ( idx, list , * state . splitState , threadGroups )
list = addStateToList ( str, idx, list , * state . splitState , threadGroups )
copyThread ( state . next , state )
copyThread ( state . next , state )
list = addStateToList ( idx, list , * state . next , threadGroups )
list = addStateToList ( str, idx, list , * state . next , threadGroups )
return list
return list
}
}
if state . isAlternation {
if state . isAlternation {
copyThread ( state . next , state )
copyThread ( state . next , state )
list = addStateToList ( idx, list , * state . next , threadGroups )
list = addStateToList ( str, idx, list , * state . next , threadGroups )
copyThread ( state . splitState , state )
copyThread ( state . splitState , state )
list = addStateToList ( idx, list , * state . splitState , threadGroups )
list = addStateToList ( str, idx, list , * state . splitState , threadGroups )
return list
return list
}
}
state . threadGroups = append ( [ ] Group { } , threadGroups ... )
state . threadGroups = append ( [ ] Group { } , threadGroups ... )
if state . assert != noneAssert {
if state . checkAssertion ( str , idx ) {
copyThread ( state . next , state )
return append ( list , addStateToList ( str , idx , list , * state . next , state . threadGroups ) ... )
}
}
if state . groupBegin {
if state . groupBegin {
state . threadGroups [ state . groupNum ] . StartIdx = idx
state . threadGroups [ state . groupNum ] . StartIdx = idx
return append ( list , addStateToList ( idx , list , * state . next , state . threadGroups ) ... )
return append ( list , addStateToList ( str, idx, list , * state . next , state . threadGroups ) ... )
}
}
if state . groupEnd {
if state . groupEnd {
state . threadGroups [ state . groupNum ] . EndIdx = idx
state . threadGroups [ state . groupNum ] . EndIdx = idx
return append ( list , addStateToList ( idx, list , * state . next , state . threadGroups ) ... )
return append ( list , addStateToList ( str, idx, list , * state . next , state . threadGroups ) ... )
}
}
state . threadGroups = append ( [ ] Group { } , threadGroups ... )
return append ( list , state )
return append ( list , state )
}
}
@ -340,7 +344,7 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in
start . threadGroups = newMatch ( numGroups + 1 )
start . threadGroups = newMatch ( numGroups + 1 )
start . threadGroups [ 0 ] . StartIdx = i
start . threadGroups [ 0 ] . StartIdx = i
currentStates = addStateToList ( i, currentStates , * start , start . threadGroups )
currentStates = addStateToList ( str, i, currentStates , * start , start . threadGroups )
var match Match = nil
var match Match = nil
// var isEmptyAndNoAssertion bool
// var isEmptyAndNoAssertion bool
// Main loop
// Main loop
@ -362,7 +366,7 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in
break
break
} else if ! currentState . isAlternation && ! currentState . isKleene && ! currentState . isQuestion && ! currentState . groupBegin && ! currentState . groupEnd { // Normal character or assertion
} else if ! currentState . isAlternation && ! currentState . isKleene && ! currentState . isQuestion && ! currentState . groupBegin && ! currentState . groupEnd { // Normal character or assertion
if currentState . contentContains ( str , idx ) {
if currentState . contentContains ( str , idx ) {
nextStates = addStateToList ( idx+ 1 , nextStates , * currentState . next , currentState . threadGroups )
nextStates = addStateToList ( str, idx+ 1 , nextStates , * currentState . next , currentState . threadGroups )
}
}
}
}