SimpleFuncStore is now derived from SimpleVarStore
This commit is contained in:
		
							parent
							
								
									0ba96e65a5
								
							
						
					
					
						commit
						7f9d7690f9
					
				@ -1,15 +1,15 @@
 | 
			
		||||
// simple-var-store.go
 | 
			
		||||
// simple-func-store.go
 | 
			
		||||
package expr
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
 | 
			
		||||
type SimpleFuncStore struct {
 | 
			
		||||
	varStore  map[string]any
 | 
			
		||||
	SimpleVarStore
 | 
			
		||||
	funcStore map[string]*funcInfo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type funcInfo struct {
 | 
			
		||||
	name string
 | 
			
		||||
	name    string
 | 
			
		||||
	minArgs int
 | 
			
		||||
	maxArgs int
 | 
			
		||||
	functor Functor
 | 
			
		||||
@ -33,41 +33,18 @@ func (info *funcInfo) Functor() Functor {
 | 
			
		||||
 | 
			
		||||
func NewSimpleFuncStore() *SimpleFuncStore {
 | 
			
		||||
	return &SimpleFuncStore{
 | 
			
		||||
		varStore:  make(map[string]any),
 | 
			
		||||
		funcStore: make(map[string]*funcInfo),
 | 
			
		||||
		SimpleVarStore: SimpleVarStore{varStore: make(map[string]any)},
 | 
			
		||||
		funcStore:      make(map[string]*funcInfo),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ctx *SimpleFuncStore) Clone() exprContext {
 | 
			
		||||
	return &SimpleFuncStore{
 | 
			
		||||
		varStore:  CloneMap(ctx.varStore),
 | 
			
		||||
		funcStore: CloneMap(ctx.funcStore),
 | 
			
		||||
		SimpleVarStore: SimpleVarStore{varStore: CloneMap(ctx.varStore)},
 | 
			
		||||
		funcStore:      CloneMap(ctx.funcStore),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ctx *SimpleFuncStore) GetVar(varName string) (v any, exists bool) {
 | 
			
		||||
	v, exists = ctx.varStore[varName]
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ctx *SimpleFuncStore) SetVar(varName string, value any) {
 | 
			
		||||
	ctx.varStore[varName] = value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ctx *SimpleFuncStore) 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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ctx *SimpleFuncStore) GetFuncInfo(name string) (info exprFunc) {
 | 
			
		||||
	info, _ = ctx.funcStore[name]
 | 
			
		||||
	return
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user