Changed generation of characters for non-whitespace, non-digit and non-word characters - it's basically an inverted character class now

master
Aadhavan Srinivasan 1 month ago
parent d986999001
commit c807d6664e

@ -1,9 +1,5 @@
package main
import (
"slices"
)
type NodeType int
// This is a list of the possible node types
@ -39,27 +35,21 @@ func newEscapedNode(c rune) postfixNode {
case 's': // Whitespace
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, whitespaceChars...)
case 'S': // Non-whitespace - I am doing this in a fancy way, generating all dot characters, then removing whitespace characters from it
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
return slices.Contains(whitespaceChars, r)
})...)
case 'S': // Non-whitespace
toReturn = newPostfixDotNode()
toReturn.except = append([]rune{}, whitespaceChars...)
case 'd': // Digits
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, digitChars...)
case 'D': // Non-digits - same fancy way as 'S'
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
return slices.Contains(digitChars, r)
})...)
case 'D': // Non-digits
toReturn = newPostfixDotNode()
toReturn.except = append([]rune{}, digitChars...)
case 'w': // word character
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, wordChars...)
case 'W': // Non-word character - same fancy way as 'S' and 'D'
toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool {
return slices.Contains(wordChars, r)
})...)
case 'W': // Non-word character
toReturn = newPostfixDotNode()
toReturn.except = append([]rune{}, wordChars...)
case 'b', 'B':
toReturn.nodetype = ASSERTION
toReturn.contents = append(toReturn.contents, c)

Loading…
Cancel
Save