Make kleene() throw an error if the state is not quantifiable

master
Aadhavan Srinivasan 4 days ago
parent 8b6d35c106
commit ecab7cc522

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"slices" "slices"
) )
@ -268,7 +269,11 @@ func concatenate(s1 *State, s2 *State) *State {
return s1 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 := &State{}
toReturn.transitions = make(map[int][]*State) toReturn.transitions = make(map[int][]*State)
toReturn.content = newContents(EPSILON) toReturn.content = newContents(EPSILON)
@ -283,7 +288,7 @@ func kleene(s1 State) *State {
for _, c := range s1.content { for _, c := range s1.content {
toReturn.transitions[c], _ = unique_append(toReturn.transitions[c], &s1) toReturn.transitions[c], _ = unique_append(toReturn.transitions[c], &s1)
} }
return toReturn return toReturn, nil
} }
func alternate(s1 *State, s2 *State) *State { func alternate(s1 *State, s2 *State) *State {

Loading…
Cancel
Save