From c807d6664ecffaa403148744a998d840e58eb2c3 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Wed, 20 Nov 2024 10:39:24 -0500 Subject: [PATCH] Changed generation of characters for non-whitespace, non-digit and non-word characters - it's basically an inverted character class now --- postfixNode.go | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/postfixNode.go b/postfixNode.go index 78fbc5b..2a54bc9 100644 --- a/postfixNode.go +++ b/postfixNode.go @@ -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)