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 package main
import (
"slices"
)
type NodeType int type NodeType int
// This is a list of the possible node types // This is a list of the possible node types
@ -39,27 +35,21 @@ func newEscapedNode(c rune) postfixNode {
case 's': // Whitespace case 's': // Whitespace
toReturn.nodetype = CHARACTER toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, whitespaceChars...) 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 case 'S': // Non-whitespace
toReturn.nodetype = CHARACTER toReturn = newPostfixDotNode()
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool { toReturn.except = append([]rune{}, whitespaceChars...)
return slices.Contains(whitespaceChars, r)
})...)
case 'd': // Digits case 'd': // Digits
toReturn.nodetype = CHARACTER toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, digitChars...) toReturn.contents = append(toReturn.contents, digitChars...)
case 'D': // Non-digits - same fancy way as 'S' case 'D': // Non-digits
toReturn.nodetype = CHARACTER toReturn = newPostfixDotNode()
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool { toReturn.except = append([]rune{}, digitChars...)
return slices.Contains(digitChars, r)
})...)
case 'w': // word character case 'w': // word character
toReturn.nodetype = CHARACTER toReturn.nodetype = CHARACTER
toReturn.contents = append(toReturn.contents, wordChars...) toReturn.contents = append(toReturn.contents, wordChars...)
case 'W': // Non-word character - same fancy way as 'S' and 'D' case 'W': // Non-word character
toReturn.nodetype = CHARACTER toReturn = newPostfixDotNode()
toReturn.contents = append(toReturn.contents, slices.DeleteFunc(dotChars(), func(r rune) bool { toReturn.except = append([]rune{}, wordChars...)
return slices.Contains(wordChars, r)
})...)
case 'b', 'B': case 'b', 'B':
toReturn.nodetype = ASSERTION toReturn.nodetype = ASSERTION
toReturn.contents = append(toReturn.contents, c) toReturn.contents = append(toReturn.contents, c)

Loading…
Cancel
Save