Moved case-insensitive stuff to thompson(); fixed case-insensitivity in character classes and ranges

master
Aadhavan Srinivasan 5 days ago
parent c92b3d0e7c
commit 6e309be71c

@ -812,18 +812,36 @@ func thompson(re []postfixNode) (Reg, error) {
// and them to the state's _content_. As mentioned above, if the exception has exceptions, then we can match
// those.
nodeExceptChars := slices.Concat(Map(node.except, func(node postfixNode) []rune {
return node.contents
nodeContents := node.contents
if caseInsensitive {
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
return allCases(r, caseInsensitive)
})...)
}
return nodeContents
})...)
state.content = rune2Contents(nodeExceptChars)
} else {
state.except = append(state.except, node.contents...)
charsToAdd := node.contents
if caseInsensitive {
charsToAdd = slices.Concat(Map(charsToAdd, func(r rune) []rune {
return allCases(r, caseInsensitive)
})...)
}
state.except = append(state.except, charsToAdd...)
}
}
}
}
// Convert the current contents to []int, convert the result of rune2contents to []int, append then
// convert back to stateContents.
state.content = stateContents(append([]int(state.content), []int(rune2Contents(c.contents))...))
runesToAdd := c.contents
if caseInsensitive {
runesToAdd = slices.Concat(Map(runesToAdd, func(r rune) []rune {
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
@ -935,7 +953,13 @@ func thompson(re []postfixNode) (Reg, error) {
// Map the list of nodes to a list of states, each state containing the contents of a specific node
states := Map(c.nodeContents, func(node postfixNode) *State {
s := newState()
s.content = rune2Contents(node.contents)
nodeContents := node.contents
if caseInsensitive {
nodeContents = slices.Concat(Map(nodeContents, func(r rune) []rune {
return allCases(r, caseInsensitive)
})...)
}
s.content = rune2Contents(nodeContents)
return &s
})
// Reduce the list of states down to a single state by alternating them

Loading…
Cancel
Save