-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy patha_expr.go
More file actions
103 lines (100 loc) · 2.31 KB
/
a_expr.go
File metadata and controls
103 lines (100 loc) · 2.31 KB
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
96
97
98
99
100
101
102
103
package ast
type A_Expr struct {
Kind A_Expr_Kind
Name *List
Lexpr Node
Rexpr Node
Location int
}
func (n *A_Expr) Pos() int {
return n.Location
}
func (n *A_Expr) Format(buf *TrackedBuffer) {
if n == nil {
return
}
switch n.Kind {
case A_Expr_Kind_IN:
buf.astFormat(n.Lexpr)
buf.WriteString(" IN (")
buf.astFormat(n.Rexpr)
buf.WriteString(")")
case A_Expr_Kind_LIKE:
buf.astFormat(n.Lexpr)
buf.WriteString(" LIKE ")
buf.astFormat(n.Rexpr)
case A_Expr_Kind_ILIKE:
buf.astFormat(n.Lexpr)
buf.WriteString(" ILIKE ")
buf.astFormat(n.Rexpr)
case A_Expr_Kind_SIMILAR:
buf.astFormat(n.Lexpr)
buf.WriteString(" SIMILAR TO ")
buf.astFormat(n.Rexpr)
case A_Expr_Kind_BETWEEN:
buf.astFormat(n.Lexpr)
buf.WriteString(" BETWEEN ")
if l, ok := n.Rexpr.(*List); ok && len(l.Items) == 2 {
buf.astFormat(l.Items[0])
buf.WriteString(" AND ")
buf.astFormat(l.Items[1])
}
case A_Expr_Kind_NOT_BETWEEN:
buf.astFormat(n.Lexpr)
buf.WriteString(" NOT BETWEEN ")
if l, ok := n.Rexpr.(*List); ok && len(l.Items) == 2 {
buf.astFormat(l.Items[0])
buf.WriteString(" AND ")
buf.astFormat(l.Items[1])
}
case A_Expr_Kind_DISTINCT:
buf.astFormat(n.Lexpr)
buf.WriteString(" IS DISTINCT FROM ")
buf.astFormat(n.Rexpr)
case A_Expr_Kind_NOT_DISTINCT:
buf.astFormat(n.Lexpr)
buf.WriteString(" IS NOT DISTINCT FROM ")
buf.astFormat(n.Rexpr)
case A_Expr_Kind_NULLIF:
buf.WriteString("NULLIF(")
buf.astFormat(n.Lexpr)
buf.WriteString(", ")
buf.astFormat(n.Rexpr)
buf.WriteString(")")
case A_Expr_Kind_OP:
// Check if this is a named parameter (@name)
opName := ""
if n.Name != nil && len(n.Name.Items) == 1 {
if s, ok := n.Name.Items[0].(*String); ok {
opName = s.Str
}
}
if opName == "@" && !set(n.Lexpr) && set(n.Rexpr) {
// Named parameter: @name (no space after @)
buf.WriteString("@")
buf.astFormat(n.Rexpr)
} else {
// Standard binary operator
if set(n.Lexpr) {
buf.astFormat(n.Lexpr)
buf.WriteString(" ")
}
buf.astFormat(n.Name)
if set(n.Rexpr) {
buf.WriteString(" ")
buf.astFormat(n.Rexpr)
}
}
default:
// Fallback for other cases
if set(n.Lexpr) {
buf.astFormat(n.Lexpr)
buf.WriteString(" ")
}
buf.astFormat(n.Name)
if set(n.Rexpr) {
buf.WriteString(" ")
buf.astFormat(n.Rexpr)
}
}
}