diff options
Diffstat (limited to 'subex/filter.go')
-rw-r--r-- | subex/filter.go | 62 |
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) +} |