iter-iter: changed item operation from function and args to a list of expressions
This commit is contained in:
+30
-47
@@ -5,9 +5,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
@@ -144,60 +142,45 @@ func evalIterator(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
if args, err = evalSiblings(ctx, opTerm.Children, intVal); err == nil {
|
||||
v, err = NewIntIterator(args)
|
||||
}
|
||||
} else if it, ok := firstChildValue.(kern.Iterator); ok {
|
||||
v, err = NewIterIter(it, ctx, opTerm.Children[1:])
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
v = NewArrayIterator(siblings)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func evalIterIter(ctx kern.ExprContext, firstChildValue any, siblings []any) (v any, err error) {
|
||||
var op kern.Functor
|
||||
var args map[string]any
|
||||
// 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
|
||||
}
|
||||
// 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))
|
||||
|
||||
Reference in New Issue
Block a user