44 lines
955 B
Go
44 lines
955 B
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// operand-list.go
|
|
package expr
|
|
|
|
import (
|
|
"git.portale-stac.it/go-pkg/expr/kern"
|
|
"git.portale-stac.it/go-pkg/expr/scan"
|
|
)
|
|
|
|
// -------- list term
|
|
func newListTermA(args ...*scan.Term) *scan.Term {
|
|
return newListTerm(0, 0, args)
|
|
}
|
|
|
|
func newListTerm(row, col int, args []*scan.Term) *scan.Term {
|
|
return &scan.Term{
|
|
Tk: *scan.NewValueToken(row, col, scan.SymList, "[]", args),
|
|
Parent: nil,
|
|
Children: nil,
|
|
Position: scan.PosLeaf,
|
|
Priority: scan.PriValue,
|
|
EvalFunc: evalList,
|
|
}
|
|
}
|
|
|
|
// -------- list func
|
|
func evalList(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|
list, _ := opTerm.Value().([]*scan.Term)
|
|
items := make(kern.ListType, len(list))
|
|
for i, tree := range list {
|
|
var param any
|
|
if param, err = tree.Compute(ctx); err != nil {
|
|
break
|
|
}
|
|
items[i] = param
|
|
}
|
|
if err == nil {
|
|
v = &items
|
|
}
|
|
return
|
|
}
|