/
expr.go
95 lines (76 loc) · 1.32 KB
/
expr.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package filter
import "fmt"
type expr interface {
String() string
}
type binaryExpr struct {
op *binaryOp
l, r expr
}
func (e binaryExpr) String() string {
return e.l.String() + " " + e.op.name + " " + e.r.String()
}
type attrExpr struct {
attr string
}
func (e attrExpr) String() string {
return e.attr
}
type selectorExpr struct {
ident string
objExpr expr
}
func (e selectorExpr) String() string {
return e.objExpr.String() + "." + e.ident
}
type parenExpr struct {
inner expr
}
func (e parenExpr) String() string {
return "(" + e.inner.String() + ")"
}
type valueExpr struct {
typ token
value string
}
func (e valueExpr) String() string {
return e.value
}
type envExpr struct {
ident string
expr expr
}
func (e envExpr) String() string {
return e.ident + "(" + e.expr.String() + ")"
}
type placeholderExpr struct {
num int
}
func (e placeholderExpr) String() string {
return fmt.Sprintf("$%d", e.num)
}
// Type defines the value types in filter expressions.
type Type int
//defines the value types in filter expressions.
const (
Any Type = iota
Bool
String
Integer
Object
)
func (t Type) String() string {
switch t {
case Any:
return "any"
case Bool:
return "bool"
case String:
return "string"
case Integer:
return "integer"
case Object:
return "object"
}
panic("unknown type")
}