rationalized context convertion to dict and string types

This commit is contained in:
2026-05-21 03:52:48 +02:00
parent a62f27b104
commit e1c24daac4
5 changed files with 92 additions and 72 deletions
+1 -23
View File
@@ -40,7 +40,7 @@ func evalContextValue(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error
}
if sourceCtx != nil {
v = contextToDict(sourceCtx)
v = sourceCtx.ToDict()
} else if childValue != nil {
it, ok := childValue.(kern.Iterator)
if !ok {
@@ -63,28 +63,6 @@ func evalContextValue(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error
return
}
func contextToDict(ctx kern.ExprContext) (dict *kern.DictType) {
// Variables
keys := ctx.EnumVars(nil)
vars := kern.MakeDict()
for _, key := range keys {
value, _ := ctx.GetVar(key)
vars.SetItem(key, value)
}
// Functions
keys = ctx.EnumFuncs(func(name string) bool { return true })
funcs := kern.MakeDict()
for _, key := range keys {
funcInfo, _ := ctx.GetFuncInfo(key)
funcs.SetItem(key, funcInfo)
}
dict = kern.MakeDict()
dict.SetItem("vars", vars)
dict.SetItem("funcs", funcs)
return
}
// init
func init() {
scan.RegisterTermConstructor(scan.SymDoubleDollar, newContextTerm)