temporary
This commit is contained in:
parent
d2bab5fd9e
commit
894b1884eb
@ -23,24 +23,36 @@ type dataCursor struct {
|
|||||||
currentFunc Functor
|
currentFunc Functor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDataCursor(ctx ExprContext) (dc *dataCursor) {
|
||||||
|
dc = &dataCursor{
|
||||||
|
index: -1,
|
||||||
|
ctx: ctx.Clone(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (dc *dataCursor) String() string {
|
func (dc *dataCursor) String() string {
|
||||||
return "$(...)"
|
return "$(...)"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *dataCursor) Current() (item any, err error) { // must return io.EOF at the last item
|
func (dc *dataCursor) Current() (item any, err error) { // must return io.EOF at the last item
|
||||||
if item, err = dc.currentFunc.Invoke(dc.ctx, currentName, []any{}); err == nil && item == nil {
|
ctx := cloneContext(dc.ctx)
|
||||||
|
if item, err = dc.currentFunc.Invoke(ctx, currentName, []any{}); err == nil && item == nil {
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
}
|
}
|
||||||
|
exportObjects(dc.ctx, ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *dataCursor) Next() (item any, err error) { // must return io.EOF after the last item
|
func (dc *dataCursor) Next() (item any, err error) { // must return io.EOF after the last item
|
||||||
if item, err = dc.nextFunc.Invoke(dc.ctx, nextName, []any{}); err == nil {
|
ctx := cloneContext(dc.ctx)
|
||||||
|
if item, err = dc.nextFunc.Invoke(ctx, nextName, []any{}); err == nil {
|
||||||
if item == nil {
|
if item == nil {
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
} else {
|
} else {
|
||||||
dc.index++
|
dc.index++
|
||||||
}
|
}
|
||||||
|
exportObjects(dc.ctx, ctx)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
19
expr_test.go
19
expr_test.go
@ -27,11 +27,22 @@ func TestExpr(t *testing.T) {
|
|||||||
succeeded := 0
|
succeeded := 0
|
||||||
failed := 0
|
failed := 0
|
||||||
|
|
||||||
// inputs1 := []inputType{
|
inputs1 := []inputType{
|
||||||
// /* 1 */ {`0?{}`, nil, nil},
|
/* 1 */ {`
|
||||||
// }
|
ds={
|
||||||
|
"init":func(end){@end=end; @current=0 but true},
|
||||||
|
"current":func(){current},
|
||||||
|
"next":func(){
|
||||||
|
((next=current+1) <= end) ? [true] {@current=next but current} :: {nil}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
it=$(ds,3);
|
||||||
|
it++;
|
||||||
|
it++
|
||||||
|
`, int64(1), nil},
|
||||||
|
}
|
||||||
|
|
||||||
for i, input := range inputs {
|
for i, input := range inputs1 {
|
||||||
var expr Expr
|
var expr Expr
|
||||||
var gotResult any
|
var gotResult any
|
||||||
var gotErr error
|
var gotErr error
|
||||||
|
@ -77,10 +77,7 @@ func evalIterator(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dc := &dataCursor{
|
dc := newDataCursor(ctx)
|
||||||
index: -1,
|
|
||||||
ctx: ctx.Clone(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if initFunc, exists := ds[initName]; exists && initFunc != nil {
|
if initFunc, exists := ds[initName]; exists && initFunc != nil {
|
||||||
var args []any
|
var args []any
|
||||||
@ -91,9 +88,12 @@ func evalIterator(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
} else {
|
} else {
|
||||||
args = []any{}
|
args = []any{}
|
||||||
}
|
}
|
||||||
if dc.resource, err = initFunc.Invoke(dc.ctx, initName, args); err != nil {
|
|
||||||
|
initCtx := dc.ctx.Clone()
|
||||||
|
if dc.resource, err = initFunc.Invoke(initCtx, initName, args); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
exportObjects(dc.ctx, initCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.nextFunc, _ = ds[nextName]
|
dc.nextFunc, _ = ds[nextName]
|
||||||
|
Loading…
Reference in New Issue
Block a user