the dataCursor struct has been moved fro operand-iterator.go to the new file data-cursor.go
This commit is contained in:
parent
62e16219f7
commit
2ab896bbac
50
data-cursor.go
Normal file
50
data-cursor.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// data-cursors.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initName = "init"
|
||||||
|
nextName = "next"
|
||||||
|
currentName = "current"
|
||||||
|
)
|
||||||
|
|
||||||
|
type dataCursor struct {
|
||||||
|
ds map[any]*term
|
||||||
|
ctx ExprContext
|
||||||
|
index int
|
||||||
|
resource any
|
||||||
|
nextFunc Functor
|
||||||
|
currentFunc Functor
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *dataCursor) String() string {
|
||||||
|
return "$(...)"
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
err = io.EOF
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
if item == nil {
|
||||||
|
err = io.EOF
|
||||||
|
} else {
|
||||||
|
dc.index++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *dataCursor) Index() int {
|
||||||
|
return dc.index
|
||||||
|
}
|
@ -6,58 +6,10 @@ package expr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// -------- iterator term
|
// -------- iterator term
|
||||||
|
|
||||||
const (
|
|
||||||
initName = "init"
|
|
||||||
nextName = "next"
|
|
||||||
currentName = "current"
|
|
||||||
)
|
|
||||||
|
|
||||||
type dataCursor struct {
|
|
||||||
ds map[any]*term
|
|
||||||
ctx ExprContext
|
|
||||||
index int
|
|
||||||
resource any
|
|
||||||
nextFunc Functor
|
|
||||||
currentFunc Functor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dc *dataCursor) String() string {
|
|
||||||
var s string
|
|
||||||
if item, err := dc.Current(); err == nil {
|
|
||||||
s = fmt.Sprintf("%v", item)
|
|
||||||
} else {
|
|
||||||
s = "(nil)"
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
err = io.EOF
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
if item == nil {
|
|
||||||
err = io.EOF
|
|
||||||
} else {
|
|
||||||
dc.index++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dc *dataCursor) Index() int {
|
|
||||||
return dc.index
|
|
||||||
}
|
|
||||||
|
|
||||||
func newIteratorTerm(tk *Token, dsTerm *term, args []*term) *term {
|
func newIteratorTerm(tk *Token, dsTerm *term, args []*term) *term {
|
||||||
tk.Sym = SymIterator
|
tk.Sym = SymIterator
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user