expr/simple-var-store.go

58 lines
1.2 KiB
Go
Raw Normal View History

2024-03-28 06:29:11 +01:00
// simple-var-store.go
package expr
type SimpleVarStore struct {
varStore map[string]any
2024-03-28 06:29:11 +01:00
}
func NewSimpleVarStore() *SimpleVarStore {
return &SimpleVarStore{
varStore: make(map[string]any),
2024-03-28 06:29:11 +01:00
}
}
func (ctx *SimpleVarStore) Clone() (clone exprContext) {
clone = &SimpleVarStore{
varStore: CloneMap(ctx.varStore),
}
return clone
}
func (ctx *SimpleVarStore) GetVar(varName string) (v any, exists bool) {
v, exists = ctx.varStore[varName]
2024-03-28 06:29:11 +01:00
return
}
func (ctx *SimpleVarStore) SetVar(varName string, value any) {
ctx.varStore[varName] = value
}
func (ctx *SimpleVarStore) EnumVars(acceptor func(name string) (accept bool)) (varNames []string) {
varNames = make([]string, 0)
for name := range ctx.varStore {
if acceptor != nil {
if acceptor(name) {
varNames = append(varNames, name)
}
} else {
varNames = append(varNames, name)
}
}
return
2024-03-28 06:29:11 +01:00
}
func (ctx *SimpleVarStore) GetFuncInfo(name string) (f exprFunc) {
return
}
func (ctx *SimpleVarStore) Call(name string, args []any) (result any, err error) {
return
}
func (ctx *SimpleVarStore) RegisterFunc(name string, functor Functor, minArgs, maxArgs int) {
}
2024-04-06 01:00:29 +02:00
func (ctx *SimpleVarStore) EnumFuncs(acceptor func(name string) (accept bool)) (funcNames []string) {
return
}