rationalized context convertion to dict and string types
This commit is contained in:
+1
-23
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user