Skip to content
Snippets Groups Projects
Commit 93bc6cd3 authored by Alex Petraky's avatar Alex Petraky :basketball_player_tone1: Committed by Pavel Antonov
Browse files

feat: Обновлена версия expr до v1.17.2

Issue: #3170
parent 997c0c3a
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 ...@@ -10,8 +10,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI= github.com/expr-lang/expr v1.17.2 h1:o0A99O/Px+/DTjEnQiodAgOIK9PPxL8DtXhBRKC+Iso=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= github.com/expr-lang/expr v1.17.2/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU= github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU=
github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg= github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
......
...@@ -37,10 +37,6 @@ func GetDefaultConfig(e map[string]interface{}) *conf.Config { ...@@ -37,10 +37,6 @@ func GetDefaultConfig(e map[string]interface{}) *conf.Config {
return defaultConfig.GetConfig(e) return defaultConfig.GetConfig(e)
} }
// func GetDefaultEnv(e map[string]interface{}) map[string]interface{} {
// return defaultConfig.GetEnv(e)
// }
func Extend(kv ...interface{}) expr.Option { func Extend(kv ...interface{}) expr.Option {
e := make(map[string]interface{}) e := make(map[string]interface{})
i := 0 i := 0
...@@ -62,23 +58,19 @@ func Extend(kv ...interface{}) expr.Option { ...@@ -62,23 +58,19 @@ func Extend(kv ...interface{}) expr.Option {
func ExtendMap(e map[string]interface{}) expr.Option { func ExtendMap(e map[string]interface{}) expr.Option {
return func(c *conf.Config) { return func(c *conf.Config) {
var env map[string]interface{} env := make(map[string]interface{})
if !c.Env.IsUnknown() {
var ok bool var ok bool
if c.Env == nil { if env, ok = c.EnvObject.(map[string]interface{}); !ok {
env = make(map[string]interface{})
} else {
if env, ok = c.Env.(map[string]interface{}); !ok {
panic("only map expr environment is supported") panic("only map expr environment is supported")
} }
} }
for k, v := range e { for k, v := range e {
if _, ok := env[k]; !ok { if _, ok := env[k]; !ok {
env[k] = v env[k] = v
} }
} }
c.Strict = true c.WithEnv(env)
c.MapEnv = true
c.Env = env
c.Types = conf.CreateTypesTable(c.Env)
} }
} }
...@@ -28,14 +28,12 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf ...@@ -28,14 +28,12 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf
e[EnvContextKey] = ctx e[EnvContextKey] = ctx
cfg := GetDefaultConfig(e) cfg := GetDefaultConfig(e)
env, _ = cfg.Env.(map[string]interface{})
program, err := exprcompiler.Compile(tree, cfg) program, err := exprcompiler.Compile(tree, cfg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
output, err := vm.Run(program, env) output, err := vm.Run(program, e)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -19,7 +19,7 @@ func TestFormat(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestFormat(t *testing.T) {
}{ }{
{"sprintf#1", "sprintf(s1, s2)", map[string]interface{}{"s1": "hello %s", "s2": "world"}, "hello world"}, {"sprintf#1", "sprintf(s1, s2)", map[string]interface{}{"s1": "hello %s", "s2": "world"}, "hello world"},
{"sprintf#2", "sprintf(s1, s2)", map[string]interface{}{"s1": nil, "s2": nil}, ""}, {"sprintf#2", "sprintf(s1, s2)", map[string]interface{}{"s1": nil, "s2": nil}, ""},
{"sprintf#3", "sprintf(s1, s2)", map[string]interface{}{"s1": "hello %s", "s2": nil}, "hello %!s(<nil>)"}, {"sprintf#3", "sprintf(s1, s2)", map[string]interface{}{"s1": "hello %s", "s2": nil}, "hello []"},
{"to_upper#1", "to_upper(s1)", map[string]interface{}{"s1": "hello"}, "HELLO"}, {"to_upper#1", "to_upper(s1)", map[string]interface{}{"s1": "hello"}, "HELLO"},
{"to_upper#2", "to_upper(s1)", map[string]interface{}{"s1": nil}, ""}, {"to_upper#2", "to_upper(s1)", map[string]interface{}{"s1": nil}, ""},
{"trim_space#1", "trim_space(s1)", map[string]interface{}{"s1": " hel lo wor ld "}, "hel lo wor ld"}, {"trim_space#1", "trim_space(s1)", map[string]interface{}{"s1": " hel lo wor ld "}, "hel lo wor ld"},
......
...@@ -62,7 +62,7 @@ func convertToMongo(ctx context.Context, config *MongoExprConfig, tree *parser.T ...@@ -62,7 +62,7 @@ func convertToMongo(ctx context.Context, config *MongoExprConfig, tree *parser.T
op(exprConfig) op(exprConfig)
} }
env = exprConfig.Env.(map[string]interface{}) env, _ = exprConfig.EnvObject.(map[string]interface{})
c := &compiler{ c := &compiler{
tree: tree, tree: tree,
...@@ -135,8 +135,6 @@ func (c *compiler) compile(node ast.Node) interface{} { ...@@ -135,8 +135,6 @@ func (c *compiler) compile(node ast.Node) interface{} {
return c.CallNode(n) return c.CallNode(n)
case *ast.BuiltinNode: case *ast.BuiltinNode:
return c.BuiltinNode(n) return c.BuiltinNode(n)
case *ast.ClosureNode:
return c.ClosureNode(n)
case *ast.PointerNode: case *ast.PointerNode:
return c.PointerNode(n) return c.PointerNode(n)
case *ast.ConditionalNode: case *ast.ConditionalNode:
...@@ -615,10 +613,6 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} { ...@@ -615,10 +613,6 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
// return size // return size
// } // }
func (c *compiler) ClosureNode(node *ast.ClosureNode) interface{} {
return c.compile(node.Node)
}
func (c *compiler) PointerNode(node *ast.PointerNode) interface{} { func (c *compiler) PointerNode(node *ast.PointerNode) interface{} {
panic("unsupported pointer node") panic("unsupported pointer node")
// c.emit(OpLoad, c.makeConstant("array")...) // c.emit(OpLoad, c.makeConstant("array")...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment