Updated nodeType constants so that they aren't exported
This commit is contained in:
@@ -450,7 +450,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
}
|
||||
// 'regex' should now contain the lookaround regex, plus the characters at the start (which indicate pos/neg, ahead/behind)
|
||||
// Now we should filter that out.
|
||||
toAppend := postfixNode{nodetype: ASSERTION, startReps: 1, endReps: 1}
|
||||
toAppend := postfixNode{nodetype: assertionNode, startReps: 1, endReps: 1}
|
||||
if regex[0] == '<' { // Lookbehind
|
||||
toAppend.lookaroundDir = LOOKBEHIND
|
||||
regex = regex[1:]
|
||||
@@ -489,7 +489,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
topStack, _ = peek(opStack)
|
||||
}
|
||||
outQueueFinalElement, _ := peek(outQueue)
|
||||
if (c == '*' && outQueueFinalElement.nodetype == KLEENE) || (c == '+' && outQueueFinalElement.nodetype == PLUS) { // You cannot apply a quantifier to a quantifier in this way
|
||||
if (c == '*' && outQueueFinalElement.nodetype == kleeneNode) || (c == '+' && outQueueFinalElement.nodetype == plusNode) { // You cannot apply a quantifier to a quantifier in this way
|
||||
return nil, fmt.Errorf("illegal use of token '%c'", c)
|
||||
}
|
||||
opStack = append(opStack, c)
|
||||
@@ -751,7 +751,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
|
||||
idx := len(outQueue) - 1
|
||||
// Get the last added node
|
||||
if idx < 0 || outQueue[idx].nodetype == LPAREN {
|
||||
if idx < 0 || outQueue[idx].nodetype == lparenNode {
|
||||
return nil, fmt.Errorf("numeric specifier with no content")
|
||||
}
|
||||
outQueue[idx].startReps = startRangeNum
|
||||
@@ -814,7 +814,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
|
||||
for _, c := range re {
|
||||
if c.nodetype == CHARACTER || c.nodetype == ASSERTION {
|
||||
if c.nodetype == characterNode || c.nodetype == assertionNode {
|
||||
state := State{}
|
||||
state.transitions = make(map[int][]*State)
|
||||
if c.allChars {
|
||||
@@ -865,7 +865,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
state.output = make([]*State, 0)
|
||||
state.output = append(state.output, &state)
|
||||
state.isEmpty = false
|
||||
if c.nodetype == ASSERTION {
|
||||
if c.nodetype == assertionNode {
|
||||
state.isEmpty = true // This is a little weird. A lookaround has the 'isEmpty' flag set, even though it _isn't_ empty (the contents are the regex). But, there's so much error-checking that relies on this flag that it's better to keep it this way.
|
||||
state.content = newContents(EPSILON) // Ideally, an assertion shouldn't have any content, since it doesn't say anything about the content of string
|
||||
if c.lookaroundDir == 0 || c.lookaroundSign == 0 {
|
||||
@@ -917,7 +917,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
|
||||
nfa = append(nfa, &state)
|
||||
}
|
||||
if c.nodetype == LPAREN || c.nodetype == RPAREN {
|
||||
if c.nodetype == lparenNode || c.nodetype == rparenNode {
|
||||
s := &State{}
|
||||
s.assert = NONE
|
||||
s.content = newContents(EPSILON)
|
||||
@@ -926,7 +926,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
s.output = append(s.output, s)
|
||||
s.transitions = make(map[int][]*State)
|
||||
// LPAREN nodes are just added normally
|
||||
if c.nodetype == LPAREN {
|
||||
if c.nodetype == lparenNode {
|
||||
numGroups++
|
||||
s.groupBegin = true
|
||||
s.groupNum = numGroups
|
||||
@@ -940,7 +940,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
// If the middle node doesn't exist (ie. something like '()' ), that's fine, I just connect the LPAREN
|
||||
// and RPAREN nodes.
|
||||
// If neither node exists, that's a problem so I return an error.
|
||||
if c.nodetype == RPAREN {
|
||||
if c.nodetype == rparenNode {
|
||||
s.groupEnd = true
|
||||
middleNode, err1 := pop(&nfa)
|
||||
lparenNode, err2 := pop(&nfa)
|
||||
@@ -969,7 +969,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.nodetype == CHARCLASS { // A Character class consists of all the nodes in it, alternated
|
||||
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 {
|
||||
s := newState()
|
||||
@@ -996,7 +996,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
// Must be an operator if it isn't a character
|
||||
switch c.nodetype {
|
||||
case CONCATENATE:
|
||||
case concatenateNode:
|
||||
s2 := mustPop(&nfa)
|
||||
// Relax the requirements for concatenation a little bit - If
|
||||
// the second element is not found ie. the postfixNodes look
|
||||
@@ -1008,7 +1008,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
s1 = concatenate(s1, s2)
|
||||
nfa = append(nfa, s1)
|
||||
}
|
||||
case KLEENE: // Create a 0-state, concat the popped state after it, concat the 0-state after the popped state
|
||||
case kleeneNode: // Create a 0-state, concat the popped state after it, concat the 0-state after the popped state
|
||||
s1, err := pop(&nfa)
|
||||
if err != nil {
|
||||
return Reg{}, fmt.Errorf("error applying kleene star")
|
||||
@@ -1018,7 +1018,7 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
return Reg{}, err
|
||||
}
|
||||
nfa = append(nfa, stateToAdd)
|
||||
case PLUS: // a+ is equivalent to aa*
|
||||
case plusNode: // a+ is equivalent to aa*
|
||||
s1 := mustPop(&nfa)
|
||||
s2, err := kleene(*s1)
|
||||
if err != nil {
|
||||
@@ -1026,14 +1026,14 @@ func thompson(re []postfixNode) (Reg, error) {
|
||||
}
|
||||
s1 = concatenate(s1, s2)
|
||||
nfa = append(nfa, s1)
|
||||
case QUESTION: // ab? is equivalent to a(b|)
|
||||
case questionNode: // ab? is equivalent to a(b|)
|
||||
s1, err := pop(&nfa)
|
||||
if err != nil {
|
||||
return Reg{}, fmt.Errorf("error applying question operator")
|
||||
}
|
||||
s2 := question(s1)
|
||||
nfa = append(nfa, s2)
|
||||
case PIPE:
|
||||
case pipeNode:
|
||||
// A pipe operator doesn't actually need either operand to be present. If an operand isn't present,
|
||||
// it is replaced with an implicit 'matchZeroLength' state (this is the same thing that we add at the top if our
|
||||
// input has zero postfixNodes).
|
||||
|
Reference in New Issue
Block a user