<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/filter.go
blob: dce0f0e554a9c19e789fe28361f41d35cd8ee178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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.NumberValue)
	return isNumber
}

type anyBoolFilter struct {}
func (_ anyBoolFilter) valueFilter(value walk.Value) bool {
	_, isBool := value.(walk.BoolValue)
	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.ArrayValue)
	return isArray
}

type anyStringFilter struct {}
func (_ anyStringFilter) valueFilter(value walk.Value) bool {
	_, isString := value.(walk.StringValue)
	return isString
}


type runeFilter interface {
	runeFilter(r rune) bool
}

type anyRuneFilter struct {}
func (_ anyRuneFilter) runeFilter(r rune) bool {
	return true
}

type selectRuneFilter struct {
	r rune
}
func (f selectRuneFilter) runeFilter(r rune) bool {
	return f.r == r
}