iter-ops raised above assign; 'cat' operator returns an iterator; $$ operator supports iterators producing a list of items

This commit is contained in:
2026-05-09 12:15:59 +02:00
parent 5285b61320
commit e5a61b5638
6 changed files with 159 additions and 10 deletions
+17 -1
View File
@@ -5,6 +5,8 @@
package expr
import (
"io"
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/scan"
)
@@ -23,8 +25,8 @@ func newContextTerm(tk *scan.Token) (inst *scan.Term) {
func evalContextValue(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
var childValue any
var sourceCtx kern.ExprContext
if len(opTerm.Children) == 0 {
sourceCtx = ctx
} else if opTerm.Children[0].Symbol() == scan.SymVariable && opTerm.Children[0].Source() == "global" {
@@ -53,6 +55,20 @@ func evalContextValue(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error
}
v = d
}
} else if childValue != nil {
if it, ok := childValue.(kern.Iterator); ok {
var item any
values := kern.NewListA()
for item, err = it.Next(); err == nil; item, err = it.Next() {
values.AppendItem(item)
}
if err == io.EOF {
err = nil
v = values
}
} else {
err = opTerm.ErrIncompatiblePrefixPostfixType(childValue)
}
} else {
err = opTerm.ErrIncompatiblePrefixPostfixType(childValue)
}