moved scanner sources to package 'scan'
This commit is contained in:
+15
-14
@@ -10,32 +10,33 @@ import (
|
||||
"strconv"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
)
|
||||
|
||||
//-------- group by term
|
||||
|
||||
func newGroupByTerm(tk *Token) (inst *term) {
|
||||
return &term{
|
||||
tk: *tk,
|
||||
children: make([]*term, 0, 2),
|
||||
position: posInfix,
|
||||
priority: priIterOp,
|
||||
evalFunc: evalGroupBy,
|
||||
func newGroupByTerm(tk *scan.Token) (inst *scan.Term) {
|
||||
return &scan.Term{
|
||||
Tk: *tk,
|
||||
Children: make([]*scan.Term, 0, 2),
|
||||
Position: scan.PosInfix,
|
||||
Priority: scan.PriIterOp,
|
||||
EvalFunc: evalGroupBy,
|
||||
}
|
||||
}
|
||||
|
||||
func evalGroupBy(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
var it kern.Iterator
|
||||
var item any
|
||||
var sKey string
|
||||
var keyByIndex bool
|
||||
|
||||
if err = opTerm.checkOperands(); err != nil {
|
||||
if err = opTerm.CheckOperands(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if leftValue, err = opTerm.children[0].Compute(ctx); err != nil {
|
||||
if leftValue, err = opTerm.Children[0].Compute(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -43,10 +44,10 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
return nil, fmt.Errorf("left operand of MAP must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||
}
|
||||
|
||||
rightTk := opTerm.children[1].tk
|
||||
if rightTk.IsSymbol(SymVariable) && rightTk.source == "__" {
|
||||
rightTk := opTerm.Children[1].Tk
|
||||
if rightTk.IsSymbol(scan.SymVariable) && rightTk.Source() == "__" {
|
||||
keyByIndex = true
|
||||
} else if rightValue, err = opTerm.children[1].Compute(ctx); err != nil {
|
||||
} else if rightValue, err = opTerm.Children[1].Compute(ctx); err != nil {
|
||||
return
|
||||
} else if kern.IsString(rightValue) {
|
||||
sKey = rightValue.(string)
|
||||
@@ -101,5 +102,5 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
|
||||
// init
|
||||
func init() {
|
||||
registerTermConstructor(SymKwGroupBy, newGroupByTerm)
|
||||
scan.RegisterTermConstructor(scan.SymKwGroupBy, newGroupByTerm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user