Documentation
¶
Index ¶
- Constants
- Variables
- func DestructParamsInt2(opName string, params []Value) (a, b int64, e error)
- func DestructParamsStr2(opName string, params []Value) (a, b string, e error)
- func Dump(e *Expr) string
- func DumpTable(expr *Expr, skipEventNode bool) string
- func GenerateTestCase(expr string, want Value, valMap map[string]interface{}) string
- func HandleDebugEvent(e *Expr)
- func IndentByParentheses(s string) string
- func OpExecError(opName string, err error) error
- func ParamTypeError(opName string, want string, got Value) error
- func ParamsCountError(opName string, want, got int) error
- func RegisterOperator(cc *Config, name string, op Operator) error
- func ToValueMap(m map[string]interface{}) map[string]Value
- type CompileOption
- type Config
- type Ctx
- type Event
- type EventType
- type Expr
- type GenExprConfig
- type GenExprOption
- type GenExprResult
- type GenExprType
- type LoopEventData
- type MapVarFetcher
- type NodeType
- type OpEventData
- type Operator
- type Option
- type SliceVarFetcher
- type Value
- type VariableFetcher
- type VariableKey
Constants ¶
Variables ¶
View Source
var ( EnableUndefinedVariable Option = func(c *Config) { c.CompileOptions[AllowUndefinedVariable] = true } EnableDebug Option = func(c *Config) { c.CompileOptions[Debug] = true } EnableReportEvent Option = func(c *Config) { c.CompileOptions[ReportEvent] = true } Optimizations = func(enable bool, opts ...CompileOption) Option { return func(c *Config) { if len(opts) == 0 || (len(opts) == 1 && opts[0] == Optimize) { opts = optimizations } for _, opt := range opts { if optimizerMap[opt] != nil { c.CompileOptions[opt] = enable } } } } EnableInfixNotation Option = func(c *Config) { c.CompileOptions[InfixNotation] = true } // RegVarAndOp registers variables and operators to config RegVarAndOp = func(vals map[string]interface{}) Option { return func(c *Config) { for k, v := range vals { switch a := v.(type) { case Operator: c.OperatorMap[k] = a case func(*Ctx, []Value) (Value, error): c.OperatorMap[k] = a default: GetOrRegisterKey(c, k) } } } } // ExtendConf extends source config ExtendConf = func(src *Config) Option { return func(c *Config) { if src != nil { copyConfig(c, src) } } } )
View Source
var DNE = dne{DoesNotExist: "DNE"}
View Source
var ErrDNE = errors.New("DNE")
Functions ¶
func DestructParamsInt2 ¶ added in v1.1.0
func DestructParamsStr2 ¶ added in v1.1.0
func GenerateTestCase ¶
func HandleDebugEvent ¶
func HandleDebugEvent(e *Expr)
func IndentByParentheses ¶
func OpExecError ¶
func ParamsCountError ¶
func ToValueMap ¶
Types ¶
type CompileOption ¶
type CompileOption string
const ( Optimize CompileOption = "optimize" // switch for all optimizations Reordering CompileOption = "reordering" FastEvaluation CompileOption = "fast_evaluation" ReduceNesting CompileOption = "reduce_nesting" ConstantFolding CompileOption = "constant_folding" Debug CompileOption = "debug" ReportEvent CompileOption = "report_event" InfixNotation CompileOption = "infix_notation" AllowUndefinedVariable CompileOption = "allow_undefined_variable" )
type Config ¶ added in v1.2.0
type Config struct { ConstantMap map[string]Value OperatorMap map[string]Operator VariableKeyMap map[string]VariableKey // cost of performance CostsMap map[string]float64 // compile options CompileOptions map[CompileOption]bool StatelessOperators []string }
func CopyConfig ¶ added in v1.2.0
type Ctx ¶
type Ctx struct { VariableFetcher Ctx context.Context }
func NewCtxFromVars ¶ added in v1.2.0
type GenExprConfig ¶
type GenExprConfig struct { EnableVariable bool EnableCondition bool EnableTryEval bool WantError bool GenType GenExprType NumVariables []GenExprResult BoolVariables []GenExprResult DneVariables []GenExprResult }
type GenExprOption ¶
type GenExprOption func(conf *GenExprConfig)
var ( EnableVariable GenExprOption = func(c *GenExprConfig) { c.EnableVariable = true } EnableCondition GenExprOption = func(c *GenExprConfig) { c.EnableCondition = true } EnableTryEval GenExprOption = func(c *GenExprConfig) { c.EnableTryEval = true } GenType = func(genType GenExprType) GenExprOption { return func(c *GenExprConfig) { c.GenType = genType } } GenVariables = func(m map[string]interface{}) GenExprOption { return func(c *GenExprConfig) { var ( numVars []GenExprResult boolVars []GenExprResult dneVars []GenExprResult ) for k, v := range m { if v == DNE { dneVars = append(dneVars, GenExprResult{Expr: k, Res: v}) continue } v = UnifyType(v) switch v.(type) { case int64: numVars = append(numVars, GenExprResult{Expr: k, Res: v}) case bool: boolVars = append(boolVars, GenExprResult{Expr: k, Res: v}) } } c.NumVariables = append(c.NumVariables, numVars...) c.BoolVariables = append(c.BoolVariables, boolVars...) c.DneVariables = append(c.DneVariables, dneVars...) } } )
type GenExprResult ¶
func GenerateRandomExpr ¶
func GenerateRandomExpr(level int, random *rand.Rand, opts ...GenExprOption) GenExprResult
GenerateRandomExpr generate random expression
type LoopEventData ¶ added in v1.1.0
type MapVarFetcher ¶ added in v1.2.0
func NewMapVarFetcher ¶ added in v1.2.0
func NewMapVarFetcher(vals map[string]interface{}) MapVarFetcher
func (MapVarFetcher) Cached ¶ added in v1.2.0
func (s MapVarFetcher) Cached(_ VariableKey, key string) bool
func (MapVarFetcher) Get ¶ added in v1.2.0
func (s MapVarFetcher) Get(_ VariableKey, key string) (Value, error)
func (MapVarFetcher) Set ¶ added in v1.2.0
func (s MapVarFetcher) Set(_ VariableKey, key string, val Value) error
type OpEventData ¶
type SliceVarFetcher ¶ added in v1.2.0
type SliceVarFetcher []Value
func NewSliceVarFetcher ¶ added in v1.2.0
func NewSliceVarFetcher(cc *Config, vals map[string]interface{}) SliceVarFetcher
func (SliceVarFetcher) Cached ¶ added in v1.2.0
func (s SliceVarFetcher) Cached(key VariableKey, _ string) bool
func (SliceVarFetcher) Get ¶ added in v1.2.0
func (s SliceVarFetcher) Get(key VariableKey, _ string) (Value, error)
func (SliceVarFetcher) Set ¶ added in v1.2.0
func (s SliceVarFetcher) Set(key VariableKey, _ string, val Value) error
type VariableFetcher ¶ added in v1.2.0
type VariableFetcher interface { // Get gets a value from the variable Get(varKey VariableKey, strKey string) (Value, error) // Set sets the value and the associated key to the variable Set(varKey VariableKey, strKey string, val Value) error // Cached returns whether the value of the key has been cached Cached(varKey VariableKey, strKey string) bool }
VariableFetcher is used to fetch values of the expression variables. Note that there are two types of keys in each method parameters, varKey is of type VariableKey, strKey is of type string, varKey offers better performance, strKey offers more flexibility, we can use any of them, as they will all be passed in during the expression execution. we recommend using varKey (if it satisfies your requirements) to get better performance.
type VariableKey ¶ added in v1.2.0
type VariableKey int16
const UndefinedVarKey VariableKey = math.MinInt16
UndefinedVarKey means that the current key is undefined in the VariableKey type In this case you should use the string type key
func GetOrRegisterKey ¶
func GetOrRegisterKey(cc *Config, name string) VariableKey
Source Files
¶
Click to show internal directories.
Click to hide internal directories.