operator-context.go: now supports contextes that implement the Formatter interface

This commit is contained in:
Celestino Amoroso 2024-05-03 06:31:36 +02:00
parent f9486fa1bd
commit 8d9963207e

View File

@ -31,16 +31,20 @@ func evalContextValue(ctx ExprContext, self *term) (v any, err error) {
} }
if sourceCtx != nil { if sourceCtx != nil {
keys := sourceCtx.EnumVars(func(name string) bool { return name[0] != '_' }) if formatter, ok := ctx.(Formatter); ok {
d := make(map[string]any) v = formatter.ToString(0)
for _, key := range keys { } else {
d[key], _ = sourceCtx.GetVar(key) keys := sourceCtx.EnumVars(func(name string) bool { return name[0] != '_' })
d := make(map[string]any)
for _, key := range keys {
d[key], _ = sourceCtx.GetVar(key)
}
keys = sourceCtx.EnumFuncs(func(name string) bool { return true })
for _, key := range keys {
d[key], _ = sourceCtx.GetFuncInfo(key)
}
v = d
} }
keys = sourceCtx.EnumFuncs(func(name string) bool { return true })
for _, key := range keys {
d[key], _ =sourceCtx.GetFuncInfo(key)
}
v = d
} else { } else {
err = self.errIncompatibleType(childValue) err = self.errIncompatibleType(childValue)
} }