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,6 +31,9 @@ func evalContextValue(ctx ExprContext, self *term) (v any, err error) {
}
if sourceCtx != nil {
if formatter, ok := ctx.(Formatter); ok {
v = formatter.ToString(0)
} else {
keys := sourceCtx.EnumVars(func(name string) bool { return name[0] != '_' })
d := make(map[string]any)
for _, key := range keys {
@ -41,6 +44,7 @@ func evalContextValue(ctx ExprContext, self *term) (v any, err error) {
d[key], _ = sourceCtx.GetFuncInfo(key)
}
v = d
}
} else {
err = self.errIncompatibleType(childValue)
}