36 lines
716 B
Go
36 lines
716 B
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// operand-dict.go
|
|
package expr
|
|
|
|
|
|
// -------- dict term
|
|
func newDictTerm(args map[any]*term) *term {
|
|
return &term{
|
|
tk: *NewValueToken(0, 0, SymDict, "{}", args),
|
|
parent: nil,
|
|
children: nil,
|
|
position: posLeaf,
|
|
priority: priValue,
|
|
evalFunc: evalDict,
|
|
}
|
|
}
|
|
|
|
// -------- dict func
|
|
func evalDict(ctx ExprContext, opTerm *term) (v any, err error) {
|
|
dict, _ := opTerm.value().(map[any]*term)
|
|
items := make(DictType, len(dict))
|
|
for key, tree := range dict {
|
|
var param any
|
|
if param, err = tree.compute(ctx); err != nil {
|
|
break
|
|
}
|
|
items[key] = param
|
|
}
|
|
if err == nil {
|
|
v = &items
|
|
}
|
|
return
|
|
}
|