Change kleene() to an alternation-style construct
This commit is contained in:
15
regex/nfa.go
15
regex/nfa.go
@@ -116,7 +116,6 @@ func cloneStateHelper(stateToClone *nfaState, cloneMap map[*nfaState]*nfaState)
|
||||
clone.rightState = clone
|
||||
}
|
||||
clone.rightState = cloneStateHelper(stateToClone.rightState, cloneMap)
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
@@ -326,12 +325,16 @@ func kleene(s1 nfaState) (*nfaState, error) {
|
||||
return nil, fmt.Errorf("previous token is not quantifiable")
|
||||
}
|
||||
|
||||
toReturn := &nfaState{}
|
||||
toReturn.transitions = make(map[int][]*nfaState)
|
||||
toReturn.content = newContents(epsilon)
|
||||
emptyState := zeroLengthMatchState()
|
||||
emptyState.assert = noneAssert
|
||||
toReturn := alternate(&s1, &emptyState)
|
||||
|
||||
// toReturn := &nfaState{}
|
||||
// toReturn.transitions = make(map[int][]*nfaState)
|
||||
// toReturn.content = newContents(epsilon)
|
||||
toReturn.isEmpty = true
|
||||
toReturn.isKleene = true
|
||||
toReturn.output = append(toReturn.output, toReturn)
|
||||
toReturn.output = []*nfaState{&emptyState}
|
||||
for i := range s1.output {
|
||||
for _, c := range toReturn.content {
|
||||
s1.output[i].transitions[c], _ = uniqueAppend(s1.output[i].transitions[c], toReturn)
|
||||
@@ -340,6 +343,7 @@ func kleene(s1 nfaState) (*nfaState, error) {
|
||||
for _, c := range s1.content {
|
||||
toReturn.transitions[c], _ = uniqueAppend(toReturn.transitions[c], &s1)
|
||||
}
|
||||
//toReturn.kleeneState = &s1
|
||||
return toReturn, nil
|
||||
}
|
||||
|
||||
@@ -374,7 +378,6 @@ func question(s1 *nfaState) *nfaState { // Use the fact that ab? == a(b|)
|
||||
s2.content = newContents(epsilon)
|
||||
s2.output = append(s2.output, s2)
|
||||
s2.isEmpty = true
|
||||
s2.isAlternation = true
|
||||
s3 := alternate(s1, s2)
|
||||
return s3
|
||||
}
|
||||
|
Reference in New Issue
Block a user