ast_expr_builder.go
1.1 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
package astexpr
import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"strconv"
"strings"
)
func NewNumberExprAST(val string) NumberExprAST {
num, _ := strconv.ParseFloat(val, 64)
return NumberExprAST{
ExprType: TypeNumberExprAST,
Val: num,
Str: val,
}
}
func NewValueExprAST(val string) ValueExprAST {
return ValueExprAST{
ExprType: TypeValueExprAST,
Val: val,
Str: val,
}
}
func NewFieldExprAST(val string) FieldExprAST {
words := strings.Split(val, ".")
table := words[0]
filed := words[0]
if len(words) > 0 {
filed = words[1]
}
return FieldExprAST{
ExprType: TypeFieldExprAST,
Str: val,
Field: &domain.TableField{
FieldName: filed,
FieldSqlName: filed,
TableName: table,
},
}
}
func NewBinaryExprAST(op string, lhs ExprAST, rhs ExprAST) BinaryExprAST {
return BinaryExprAST{
ExprType: TypeBinaryExprAST,
Op: op,
Lhs: lhs,
Rhs: rhs,
}
}
func NewFunCallerExprAST(name string, args ...ExprAST) FunCallerExprAST {
return FunCallerExprAST{
ExprType: TypeFunCallerExprAST,
Name: name,
Args: args,
}
}