Renamed 'state' to 'nfaState' because 'state' by itself means nothing
This commit is contained in:
@@ -14,7 +14,7 @@ var notDotChars []rune
|
||||
// the startState of the NFA representation of the regex, and the number of capturing
|
||||
// groups in the regex.
|
||||
type Reg struct {
|
||||
start *State
|
||||
start *nfaState
|
||||
numGroups int
|
||||
}
|
||||
|
||||
@@ -799,8 +799,8 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
// Thompson's algorithm. Constructs Finite-State Automaton from given string.
|
||||
// Returns start state and number of groups in regex.
|
||||
func thompson(re []postfixNode) (Reg, error) {
|
||||
nfa := make([]*State, 0) // Stack of states
|
||||
numGroups := 0 // Number of capturing groups
|
||||
nfa := make([]*nfaState, 0) // Stack of states
|
||||
numGroups := 0 // Number of capturing groups
|
||||
|
||||
// If thompson() receives an empty regex, then whatever was given to shuntingYard()
|
||||
// was parsed away. This doesn't mean that the regex itself is empty.
|
||||
@@ -815,8 +815,8 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
|
||||
for _, c := range re {
|
||||
if c.nodetype == characterNode || c.nodetype == assertionNode {
|
||||
stateToAdd := State{}
|
||||
stateToAdd.transitions = make(map[int][]*State)
|
||||
stateToAdd := nfaState{}
|
||||
stateToAdd.transitions = make(map[int][]*nfaState)
|
||||
if c.allChars {
|
||||
stateToAdd.allChars = true
|
||||
if len(c.except) != 0 {
|
||||
@@ -862,7 +862,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
})...)
|
||||
}
|
||||
stateToAdd.content = stateContents(append([]int(stateToAdd.content), []int(rune2Contents(runesToAdd))...))
|
||||
stateToAdd.output = make([]*State, 0)
|
||||
stateToAdd.output = make([]*nfaState, 0)
|
||||
stateToAdd.output = append(stateToAdd.output, &stateToAdd)
|
||||
stateToAdd.isEmpty = false
|
||||
if c.nodetype == assertionNode {
|
||||
@@ -918,13 +918,13 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
nfa = append(nfa, &stateToAdd)
|
||||
}
|
||||
if c.nodetype == lparenNode || c.nodetype == rparenNode {
|
||||
s := &State{}
|
||||
s := &nfaState{}
|
||||
s.assert = noneAssert
|
||||
s.content = newContents(EPSILON)
|
||||
s.isEmpty = true
|
||||
s.output = make([]*State, 0)
|
||||
s.output = make([]*nfaState, 0)
|
||||
s.output = append(s.output, s)
|
||||
s.transitions = make(map[int][]*State)
|
||||
s.transitions = make(map[int][]*nfaState)
|
||||
// LPAREN nodes are just added normally
|
||||
if c.nodetype == lparenNode {
|
||||
numGroups++
|
||||
@@ -971,7 +971,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
if c.nodetype == charclassNode { // A Character class consists of all the nodes in it, alternated
|
||||
// Map the list of nodes to a list of states, each state containing the contents of a specific node
|
||||
states := funcMap(c.nodeContents, func(node postfixNode) *State {
|
||||
states := funcMap(c.nodeContents, func(node postfixNode) *nfaState {
|
||||
s := newState()
|
||||
nodeContents := node.contents
|
||||
if caseInsensitive {
|
||||
@@ -989,7 +989,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
return &s
|
||||
})
|
||||
// Reduce the list of states down to a single state by alternating them
|
||||
toAdd := funcReduce(states, func(s1 *State, s2 *State) *State {
|
||||
toAdd := funcReduce(states, func(s1 *nfaState, s2 *nfaState) *nfaState {
|
||||
return alternate(s1, s2)
|
||||
})
|
||||
nfa = append(nfa, toAdd)
|
||||
@@ -1066,7 +1066,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
return Reg{}, fmt.Errorf("numeric specifier - start greater than end")
|
||||
}
|
||||
poppedState := mustPop(&nfa)
|
||||
var stateToAdd *State = nil
|
||||
var stateToAdd *nfaState = nil
|
||||
// Take advantage of the following facts:
|
||||
// a{5} == aaaaa
|
||||
// a{3,5} == aaaa?a?
|
||||
|
Reference in New Issue
Block a user