<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/filter.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
commit8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b (patch)
tree7a16883c17c2bdcc49b2f9d4f333dfc76c66248f /subex/filter.go
parent3c34366bdd5d817a184d6b1c901d03a16b6faa4b (diff)
downloadstred-go-8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b.tar
Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing
Diffstat (limited to 'subex/filter.go')
-rw-r--r--subex/filter.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/subex/filter.go b/subex/filter.go
new file mode 100644
index 0000000..1a1b6db
--- /dev/null
+++ b/subex/filter.go
@@ -0,0 +1,62 @@
+package subex
+
+import (
+ "main/walk"
+)
+
+type valueFilter interface {
+ valueFilter(value walk.Value) bool
+}
+
+type selectScalarFilter struct {
+ scalar walk.Scalar
+}
+func (scalar selectScalarFilter) valueFilter(value walk.Value) bool {
+ return value == scalar.scalar
+}
+
+type anyNumberFilter struct {}
+func (_ anyNumberFilter) valueFilter(value walk.Value) bool {
+ _, isNumber := value.(walk.NumberScalar)
+ return isNumber
+}
+
+type anyBoolFilter struct {}
+func (_ anyBoolFilter) valueFilter(value walk.Value) bool {
+ _, isBool := value.(walk.BoolScalar)
+ return isBool
+}
+
+type anyValueFilter struct {}
+func (_ anyValueFilter) valueFilter(value walk.Value) bool {
+ return true
+}
+
+type anyArrayFilter struct {}
+func (_ anyArrayFilter) valueFilter(value walk.Value) bool {
+ _, isArray := value.(walk.ArrayStructure)
+ return isArray
+}
+
+type anyStringFilter struct {}
+func (_ anyStringFilter) valueFilter(value walk.Value) bool {
+ _, isString := value.(walk.StringStructure)
+ return isString
+}
+
+
+type runeFilter interface {
+ runeFilter(r walk.StringRuneAtom) bool
+}
+
+type anyRuneFilter struct {}
+func (_ anyRuneFilter) runeFilter(r walk.StringRuneAtom) bool {
+ return true
+}
+
+type selectRuneFilter struct {
+ r rune
+}
+func (f selectRuneFilter) runeFilter(r walk.StringRuneAtom) bool {
+ return f.r == rune(r)
+}