moved a subset of source file to the kern package
This commit is contained in:
+21
-19
@@ -7,6 +7,8 @@ package expr
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
)
|
||||
|
||||
// -------- iterator term
|
||||
@@ -25,11 +27,11 @@ func newIteratorTerm(tk *Token, args []*term) *term {
|
||||
|
||||
// -------- eval iterator
|
||||
|
||||
func evalTermArray(ctx ExprContext, terms []*term) (values []any, err error) {
|
||||
func evalTermArray(ctx kern.ExprContext, terms []*term) (values []any, err error) {
|
||||
values = make([]any, len(terms))
|
||||
for i, t := range terms {
|
||||
var value any
|
||||
if value, err = t.compute(ctx); err == nil {
|
||||
if value, err = t.Compute(ctx); err == nil {
|
||||
values[i] = value
|
||||
} else {
|
||||
break
|
||||
@@ -38,25 +40,25 @@ func evalTermArray(ctx ExprContext, terms []*term) (values []any, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func evalFirstChild(ctx ExprContext, iteratorTerm *term) (value any, err error) {
|
||||
func evalFirstChild(ctx kern.ExprContext, iteratorTerm *term) (value any, err error) {
|
||||
if len(iteratorTerm.children) < 1 || iteratorTerm.children[0] == nil {
|
||||
err = iteratorTerm.Errorf("missing the data-source parameter")
|
||||
return
|
||||
}
|
||||
|
||||
value, err = iteratorTerm.children[0].compute(ctx)
|
||||
value, err = iteratorTerm.children[0].Compute(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
func getDataSourceDict(iteratorTerm *term, firstChildValue any) (ds map[string]Functor, err error) {
|
||||
if dictAny, ok := firstChildValue.(*DictType); ok {
|
||||
requiredFields := []string{NextName}
|
||||
func getDataSourceDict(iteratorTerm *term, firstChildValue any) (ds map[string]kern.Functor, err error) {
|
||||
if dictAny, ok := firstChildValue.(*kern.DictType); ok {
|
||||
requiredFields := []string{kern.NextName}
|
||||
fieldsMask := 0b1
|
||||
foundFields := 0
|
||||
ds = make(map[string]Functor)
|
||||
ds = make(map[string]kern.Functor)
|
||||
for keyAny, item := range *dictAny {
|
||||
if key, ok := keyAny.(string); ok {
|
||||
if functor, ok := item.(Functor); ok {
|
||||
if functor, ok := item.(kern.Functor); ok {
|
||||
ds[key] = functor
|
||||
if index := slices.Index(requiredFields, key); index >= 0 {
|
||||
foundFields |= 1 << index
|
||||
@@ -78,9 +80,9 @@ func getDataSourceDict(iteratorTerm *term, firstChildValue any) (ds map[string]F
|
||||
return
|
||||
}
|
||||
|
||||
func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
func evalIterator(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
var firstChildValue any
|
||||
var ds map[string]Functor
|
||||
var ds map[string]kern.Functor
|
||||
|
||||
if firstChildValue, err = evalFirstChild(ctx, opTerm); err != nil {
|
||||
return
|
||||
@@ -95,7 +97,7 @@ func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
if len(ds) > 0 {
|
||||
var dc *dataCursor
|
||||
dcCtx := ctx.Clone()
|
||||
if initFunc, exists := ds[InitName]; exists && initFunc != nil {
|
||||
if initFunc, exists := ds[kern.InitName]; exists && initFunc != nil {
|
||||
var args []any
|
||||
var resource any
|
||||
if len(opTerm.children) > 1 {
|
||||
@@ -106,13 +108,13 @@ func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
args = []any{}
|
||||
}
|
||||
|
||||
actualParams := bindActualParams(initFunc, args)
|
||||
actualParams := kern.BindActualParams(initFunc, args)
|
||||
|
||||
initCtx := ctx.Clone()
|
||||
if resource, err = initFunc.InvokeNamed(initCtx, InitName, actualParams); err != nil {
|
||||
if resource, err = initFunc.InvokeNamed(initCtx, kern.InitName, actualParams); err != nil {
|
||||
return
|
||||
}
|
||||
exportObjects(dcCtx, initCtx)
|
||||
kern.ExportObjects(dcCtx, initCtx)
|
||||
dc = NewDataCursor(dcCtx, ds, resource)
|
||||
} else {
|
||||
dc = NewDataCursor(dcCtx, ds, nil)
|
||||
@@ -120,7 +122,7 @@ func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
|
||||
v = dc
|
||||
} else {
|
||||
if dictIt, ok := firstChildValue.(*DictType); ok {
|
||||
if dictIt, ok := firstChildValue.(*kern.DictType); ok {
|
||||
var args []any
|
||||
if args, err = evalSibling(ctx, opTerm.children, nil); err == nil {
|
||||
v, err = NewDictIterator(dictIt, args)
|
||||
@@ -129,7 +131,7 @@ func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
err = opTerm.children[0].Errorf("the data-source must be a dictionary")
|
||||
}
|
||||
}
|
||||
} else if list, ok := firstChildValue.(*ListType); ok {
|
||||
} else if list, ok := firstChildValue.(*kern.ListType); ok {
|
||||
var args []any
|
||||
if args, err = evalSibling(ctx, opTerm.children, nil); err == nil {
|
||||
v = NewListIterator(list, args)
|
||||
@@ -143,7 +145,7 @@ func evalIterator(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func evalSibling(ctx ExprContext, terms []*term, firstChildValue any) (list []any, err error) {
|
||||
func evalSibling(ctx kern.ExprContext, terms []*term, firstChildValue any) (list []any, err error) {
|
||||
items := make([]any, 0, len(terms))
|
||||
for i, tree := range terms {
|
||||
var param any
|
||||
@@ -152,7 +154,7 @@ func evalSibling(ctx ExprContext, terms []*term, firstChildValue any) (list []an
|
||||
continue
|
||||
}
|
||||
param = firstChildValue
|
||||
} else if param, err = tree.compute(ctx); err != nil {
|
||||
} else if param, err = tree.Compute(ctx); err != nil {
|
||||
break
|
||||
}
|
||||
items = append(items, param)
|
||||
|
||||
Reference in New Issue
Block a user