Make kleene() throw an error if the state is not quantifiable
This commit is contained in:
9
nfa.go
9
nfa.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
@@ -268,7 +269,11 @@ func concatenate(s1 *State, s2 *State) *State {
|
||||
return s1
|
||||
}
|
||||
|
||||
func kleene(s1 State) *State {
|
||||
func kleene(s1 State) (*State, error) {
|
||||
if s1.isEmpty && s1.assert != NONE {
|
||||
return nil, fmt.Errorf("previous token is not quantifiable")
|
||||
}
|
||||
|
||||
toReturn := &State{}
|
||||
toReturn.transitions = make(map[int][]*State)
|
||||
toReturn.content = newContents(EPSILON)
|
||||
@@ -283,7 +288,7 @@ func kleene(s1 State) *State {
|
||||
for _, c := range s1.content {
|
||||
toReturn.transitions[c], _ = unique_append(toReturn.transitions[c], &s1)
|
||||
}
|
||||
return toReturn
|
||||
return toReturn, nil
|
||||
}
|
||||
|
||||
func alternate(s1 *State, s2 *State) *State {
|
||||
|
Reference in New Issue
Block a user