Renamed variable to avoid conflicting with type name

master
Aadhavan Srinivasan 3 days ago
parent af5b6ebe08
commit 7e88b8a4b0

@ -815,10 +815,10 @@ func thompson(re []postfixNode) (Reg, error) {
for _, c := range re {
if c.nodetype == characterNode || c.nodetype == assertionNode {
state := State{}
state.transitions = make(map[int][]*State)
stateToAdd := State{}
stateToAdd.transitions = make(map[int][]*State)
if c.allChars {
state.allChars = true
stateToAdd.allChars = true
if len(c.except) != 0 {
// For each node that I am 'excepting' (eg. in an inverted character class):
// - If the node itself has exceptions, then the exceptions cancel out.
@ -827,7 +827,7 @@ func thompson(re []postfixNode) (Reg, error) {
// - If the node doesn't have exceptions (allChars == false) then the contents of the node are added to the except list.
for _, node := range c.except {
if node.allChars {
state.allChars = false
stateToAdd.allChars = false
// For each postfixNode in node.except, extract the contents of the postfixNode. Concatenate them all,
// and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
// those.
@ -840,7 +840,7 @@ func thompson(re []postfixNode) (Reg, error) {
}
return nodeContents
})...)
state.content = rune2Contents(nodeExceptChars)
stateToAdd.content = rune2Contents(nodeExceptChars)
} else {
charsToAdd := node.contents
if caseInsensitive {
@ -848,7 +848,7 @@ func thompson(re []postfixNode) (Reg, error) {
return allCases(r, caseInsensitive)
})...)
}
state.except = append(state.except, charsToAdd...)
stateToAdd.except = append(stateToAdd.except, charsToAdd...)
}
}
}
@ -861,43 +861,43 @@ func thompson(re []postfixNode) (Reg, error) {
return allCases(r, caseInsensitive)
})...)
}
state.content = stateContents(append([]int(state.content), []int(rune2Contents(runesToAdd))...))
state.output = make([]*State, 0)
state.output = append(state.output, &state)
state.isEmpty = false
stateToAdd.content = stateContents(append([]int(stateToAdd.content), []int(rune2Contents(runesToAdd))...))
stateToAdd.output = make([]*State, 0)
stateToAdd.output = append(stateToAdd.output, &stateToAdd)
stateToAdd.isEmpty = false
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
stateToAdd.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.
stateToAdd.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 {
switch c.contents[0] {
case '^':
state.assert = sosAssert
stateToAdd.assert = sosAssert
case '$':
state.assert = eosAssert
stateToAdd.assert = eosAssert
case 'b':
state.assert = wboundAssert
stateToAdd.assert = wboundAssert
case 'B':
state.assert = nonwboundAssert
stateToAdd.assert = nonwboundAssert
}
} else { // Lookaround
state.lookaroundRegex = string(c.contents)
stateToAdd.lookaroundRegex = string(c.contents)
if c.lookaroundDir == lookahead {
if c.lookaroundSign == positive {
state.assert = plaAssert
stateToAdd.assert = plaAssert
}
if c.lookaroundSign == negative {
state.assert = nlaAssert
stateToAdd.assert = nlaAssert
}
}
if c.lookaroundDir == lookbehind {
if c.lookaroundSign == positive {
state.assert = plbAssert
stateToAdd.assert = plbAssert
}
if c.lookaroundSign == negative {
state.assert = nlbAssert
stateToAdd.assert = nlbAssert
}
}
tmpRe, err := shuntingYard(state.lookaroundRegex)
tmpRe, err := shuntingYard(stateToAdd.lookaroundRegex)
if err != nil {
return Reg{}, fmt.Errorf("error parsing lookaround: %w", err)
}
@ -905,17 +905,17 @@ func thompson(re []postfixNode) (Reg, error) {
if err != nil {
return Reg{}, fmt.Errorf("error compiling lookaround: %w", err)
}
state.lookaroundNFA = reg.start
state.lookaroundNumCaptureGroups = reg.numGroups
stateToAdd.lookaroundNFA = reg.start
stateToAdd.lookaroundNumCaptureGroups = reg.numGroups
}
}
// Replace ESC_BACKSLASH with actual backslash, so that we can actually check if we encounter it
replaceByValue([]int(state.content), int(ESC_BACKSLASH), '\\')
replaceByValue(state.except, ESC_BACKSLASH, '\\')
replaceByValue([]int(stateToAdd.content), int(ESC_BACKSLASH), '\\')
replaceByValue(stateToAdd.except, ESC_BACKSLASH, '\\')
nfa = append(nfa, &state)
nfa = append(nfa, &stateToAdd)
}
if c.nodetype == lparenNode || c.nodetype == rparenNode {
s := &State{}

Loading…
Cancel
Save