list iterators now support start, stop e step
This commit is contained in:
+32
-9
@@ -133,29 +133,52 @@ func evalIterator(ctx ExprContext, self *term) (v any, err error) {
|
||||
|
||||
v = dc
|
||||
} else if list, ok := firstChildValue.(*ListType); ok {
|
||||
v = NewListIterator(list)
|
||||
var args []any
|
||||
if args, err = evalSibling(ctx, self.children, nil); err == nil {
|
||||
v = NewListIterator(list, args)
|
||||
}
|
||||
} else {
|
||||
var list *ListType
|
||||
if list, err = evalChildren(ctx, self.children, firstChildValue); err == nil {
|
||||
v = NewListIterator(list)
|
||||
var list []any
|
||||
if list, err = evalSibling(ctx, self.children, firstChildValue); err == nil {
|
||||
v = NewArrayIterator(list)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func evalChildren(ctx ExprContext, terms []*term, firstChildValue any) (list *ListType, err error) {
|
||||
items := make(ListType, len(terms))
|
||||
// func evalChildren(ctx ExprContext, terms []*term, firstChildValue any) (list *ListType, err error) {
|
||||
// items := make(ListType, len(terms))
|
||||
// for i, tree := range terms {
|
||||
// var param any
|
||||
// if i == 0 && firstChildValue != nil {
|
||||
// param = firstChildValue
|
||||
// } else if param, err = tree.compute(ctx); err != nil {
|
||||
// break
|
||||
// }
|
||||
// items[i] = param
|
||||
// }
|
||||
// if err == nil {
|
||||
// list = &items
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
func evalSibling(ctx ExprContext, terms []*term, firstChildValue any) (list []any, err error) {
|
||||
items := make([]any, 0, len(terms))
|
||||
for i, tree := range terms {
|
||||
var param any
|
||||
if i == 0 && firstChildValue != nil {
|
||||
if i == 0 {
|
||||
if firstChildValue == nil {
|
||||
continue
|
||||
}
|
||||
param = firstChildValue
|
||||
} else if param, err = tree.compute(ctx); err != nil {
|
||||
break
|
||||
}
|
||||
items[i] = param
|
||||
items = append(items, param)
|
||||
}
|
||||
if err == nil {
|
||||
list = &items
|
||||
list = items
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user