From 8d9963207e64be78536f8ae2a84f5532d07389c8 Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Fri, 3 May 2024 06:31:36 +0200 Subject: [PATCH] operator-context.go: now supports contextes that implement the Formatter interface --- operator-context.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/operator-context.go b/operator-context.go index 4ee4685..20b1e1d 100644 --- a/operator-context.go +++ b/operator-context.go @@ -31,16 +31,20 @@ func evalContextValue(ctx ExprContext, self *term) (v any, err error) { } if sourceCtx != nil { - keys := sourceCtx.EnumVars(func(name string) bool { return name[0] != '_' }) - d := make(map[string]any) - for _, key := range keys { - d[key], _ = sourceCtx.GetVar(key) + 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 { + 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 { err = self.errIncompatibleType(childValue) }