Added list '[]' data type. Fix: function with no arguments
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// operand-list.go
|
||||
package expr
|
||||
|
||||
// -------- list term
|
||||
func newListTerm(args []*term) *term {
|
||||
return &term{
|
||||
tk: *NewToken(SymList, "[]"),
|
||||
class: classVar,
|
||||
kind: kindUnknown,
|
||||
parent: nil,
|
||||
children: args,
|
||||
position: posLeaf,
|
||||
priority: priValue,
|
||||
evalFunc: evalList,
|
||||
}
|
||||
}
|
||||
|
||||
// -------- list func
|
||||
func evalList(ctx exprContext, self *term) (v any, err error) {
|
||||
items := make([]any, len(self.children))
|
||||
for i, tree := range self.children {
|
||||
var param any
|
||||
if param, err = tree.compute(ctx); err != nil {
|
||||
break
|
||||
}
|
||||
items[i] = param
|
||||
}
|
||||
if err == nil {
|
||||
v = items
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user