new iter-iter iterator and kern.func-info module

This commit is contained in:
2026-05-05 20:38:30 +02:00
parent 7f34ccf955
commit acd4f8487d
30 changed files with 527 additions and 485 deletions
+55 -7
View File
@@ -5,7 +5,9 @@
package expr
import (
"fmt"
"slices"
"strconv"
"strings"
"git.portale-stac.it/go-pkg/expr/kern"
@@ -125,7 +127,7 @@ func evalIterator(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
} else {
if dictIt, ok := firstChildValue.(*kern.DictType); ok {
var args []any
if args, err = evalSibling(ctx, opTerm.Children, nil); err == nil {
if args, err = evalSiblings(ctx, opTerm.Children, nil); err == nil {
v, err = NewDictIterator(dictIt, args)
}
} else {
@@ -134,24 +136,70 @@ func evalIterator(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
}
} else if list, ok := firstChildValue.(*kern.ListType); ok {
var args []any
if args, err = evalSibling(ctx, opTerm.Children, nil); err == nil {
if args, err = evalSiblings(ctx, opTerm.Children, nil); err == nil {
v = NewListIterator(list, args)
}
} else if intVal, ok := firstChildValue.(int64); ok {
var args []any
if args, err = evalSibling(ctx, opTerm.Children, intVal); err == nil {
if args, err = evalSiblings(ctx, opTerm.Children, intVal); err == nil {
v, err = NewIntIterator(args)
}
} else {
var list []any
if list, err = evalSibling(ctx, opTerm.Children, firstChildValue); err == nil {
v = NewArrayIterator(list)
var siblings []any
if siblings, err = evalSiblings(ctx, opTerm.Children, firstChildValue); err == nil {
// if v, err = evalIterIter(ctx, firstChildValue, siblings); err == nil && v == nil {
// if it, ok := firstChildValue.(kern.Iterator); ok {
// if len(siblings) > 1 {
// if op, ok := siblings[1].(kern.Functor); ok {
// args := make(map[string]any, len(siblings)-2)
// for i, arg := range siblings[2:] {
// args["arg"+strconv.Itoa(i+1)] = arg
// }
// v, err = NewIterIter(it, ctx, op, args)
// } else {
// err = opTerm.Children[1].Errorf("the first sibling parameter must be a functor to be used as operation for the iterator")
// }
// } else {
// v, err = NewIterIter(it, ctx, nil, nil)
// }
if v, err = evalIterIter(ctx, firstChildValue, siblings); err == nil && v == nil {
v = NewArrayIterator(siblings)
}
}
}
return
}
func evalSibling(ctx kern.ExprContext, terms []*scan.Term, firstChildValue any) (list []any, err error) {
func evalIterIter(ctx kern.ExprContext, firstChildValue any, siblings []any) (v any, err error) {
var op kern.Functor
var args map[string]any
if it, ok := firstChildValue.(kern.Iterator); ok {
if len(siblings) > 1 {
if op, ok = siblings[1].(kern.Functor); ok {
args = make(map[string]any, len(siblings)-2)
for i, arg := range siblings[2:] {
switch a := arg.(type) {
case *kern.DictType:
for keyAny, item := range *a {
if key, ok := keyAny.(string); ok {
args[key] = item
}
}
default:
args["arg"+strconv.Itoa(i+1)] = arg
}
}
} else if op == nil {
return nil, fmt.Errorf("the first sibling parameter must be a functor to be used as operation for the iterator")
}
}
v, err = NewIterIter(it, ctx, op, args)
}
return
}
func evalSiblings(ctx kern.ExprContext, terms []*scan.Term, firstChildValue any) (list []any, err error) {
items := make([]any, 0, len(terms))
for i, tree := range terms {
var param any