Implement PCRE Matching (prefer left-branch) #2

Merged
Rockingcool merged 48 commits from implementPCREMatchingRules into master 2025-02-09 15:24:29 -06:00
6 changed files with 631 additions and 373 deletions
Showing only changes of commit d2ad0d95a8 - Show all commits

View File

@@ -329,9 +329,6 @@ func kleene(s1 *nfaState) (*nfaState, error) {
toReturn.isAlternation = true
toReturn.content = newContents(epsilon)
toReturn.splitState = s1
for i := range s1.output {
s1.output[i].next = toReturn
}
// toReturn := &nfaState{}
// toReturn.transitions = make(map[int][]*nfaState)
@@ -373,14 +370,20 @@ func alternate(s1 *nfaState, s2 *nfaState) *nfaState {
return toReturn
}
func question(s1 *nfaState) *nfaState { // Use the fact that ab? == a(b|)
s2 := &nfaState{}
func question(s1 *nfaState) (*nfaState, error) { // Use the fact that ab? == a(b|)
if s1.isEmpty && s1.assert != noneAssert {
return nil, fmt.Errorf("previous token is not quantifiable")
}
toReturn := &nfaState{}
toReturn.isEmpty = true
toReturn.isAlternation = true
toReturn.isQuestion = true
toReturn.content = newContents(epsilon)
toReturn.splitState = s1
toReturn.output = append([]*nfaState{}, toReturn)
toReturn.output = append(toReturn.output, s1.output...)
// s2.transitions = make(map[int][]*nfaState)
s2.content = newContents(epsilon)
s2.output = append(s2.output, s2)
s2.isEmpty = true
s3 := alternate(s1, s2)
return s3
return toReturn, nil
}
// Creates and returns a new state with the 'default' values.