More improvements on expr vars & rec values
This commit is contained in:
@@ -28,8 +28,8 @@ func ResolveTypes(rt resolvableType, resolver func(typ string) Type) error {
|
||||
return rt.ResolveTypes(resolver)
|
||||
}
|
||||
|
||||
// cast intput into some well-known types
|
||||
func Cast(in interface{}) (tv TypedValue, err error) {
|
||||
// Typify detects input type and wraps it with expression type
|
||||
func Typify(in interface{}) (tv TypedValue, err error) {
|
||||
var is bool
|
||||
if tv, is = in.(TypedValue); is {
|
||||
return
|
||||
@@ -135,7 +135,7 @@ func CastToArray(val interface{}) (out []TypedValue, err error) {
|
||||
out = make([]TypedValue, ref.Len())
|
||||
for i := 0; i < ref.Len(); i++ {
|
||||
item := ref.Index(i).Interface()
|
||||
out[i], err = Cast(item)
|
||||
out[i], err = Typify(item)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func push(arr interface{}, nn ...interface{}) (out interface{}, err error) {
|
||||
stv = append(stv, tv)
|
||||
} else {
|
||||
// wrap unknown types...
|
||||
stv = append(stv, Must(Cast(n)))
|
||||
stv = append(stv, Must(Typify(n)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -66,11 +66,13 @@ func (p *gvalParser) ParseEvaluators(ee ...Evaluator) error {
|
||||
}
|
||||
|
||||
func (e *gvalEval) Eval(ctx context.Context, scope *Vars) (interface{}, error) {
|
||||
return e.evaluable(ctx, scope.Dict())
|
||||
return e.evaluable(ctx, scope)
|
||||
//return e.evaluable(ctx, scope.Dict())
|
||||
}
|
||||
|
||||
func (e *gvalEval) Test(ctx context.Context, scope *Vars) (bool, error) {
|
||||
r, err := e.evaluable(ctx, scope.Dict())
|
||||
r, err := e.evaluable(ctx, scope)
|
||||
//r, err := e.evaluable(ctx, scope.Dict())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -225,6 +226,10 @@ func (t *Vars) Value() (driver.Value, error) {
|
||||
return json.Marshal(t)
|
||||
}
|
||||
|
||||
func (t Vars) SelectGVal(_ context.Context, k string) (interface{}, error) {
|
||||
return t.Select(k)
|
||||
}
|
||||
|
||||
// UnmarshalJSON
|
||||
func (t *Vars) UnmarshalJSON(in []byte) (err error) {
|
||||
if len(in) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user