cond_expr

package
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFnMap = map[string]map[token.Token]conditionFn{
	"==": {
		token.NUM:    equal[float64],
		token.BOOL:   equal[bool],
		token.STRING: equalStr,
	},
	"!=": {
		token.NUM:    unEqual[float64],
		token.BOOL:   unEqual[bool],
		token.STRING: unEqualStr,
	},
	">=": {
		token.NUM:    gte[float64],
		token.STRING: gte[string],
	},
	"<=": {
		token.NUM:    lte[float64],
		token.STRING: lte[string],
	},
	">": {
		token.NUM:    gt[float64],
		token.STRING: lt[string],
	},
	"<": {
		token.NUM:    lt[float64],
		token.STRING: lt[string],
	},
	"contains": {
		token.STRING: contains,
	},
	"unContains": {
		token.STRING: unContains,
	},
	"startsWith": {
		token.STRING: startsWith,
	},
	"unStartsWith": {
		token.STRING: unStartsWith,
	},
	"endsWith": {
		token.STRING: endsWith,
	},
	"unEndsWith": {
		token.STRING: unEndsWith,
	},
	"reg": {
		token.STRING: reg,
	},
	"containsBit": {
		token.NUM:    containsBit,
		token.STRING: containsBit,
	},
	"unContainsBit": {
		token.NUM:    unContainsBit,
		token.STRING: unContainsBit,
	},
	"&": {},
	"|": {},
}
View Source
var StdExecutor = New(nil, nil)

Functions

func OperatorAnd

func OperatorAnd(left, right bool) bool

func OperatorOr

func OperatorOr(left, right bool) bool

Types

type Executor

type Executor struct {
	FnMap map[string]map[token.Token]conditionFn

	// KeyMap 字段映射
	// 	存在映射 => key 转换为映射值
	KeyMap map[string]string
}

func New

func New(fnMap map[string]map[token.Token]conditionFn, keyMap map[string]string) *Executor

func (*Executor) DoAst

func (e *Executor) DoAst(m map[string]any, ast *expression.AstNode, prefix, suffix string) (result bool, keys []string)

DoAst 执行 ast

func (*Executor) DoExpr

func (e *Executor) DoExpr(m map[string]any, expr string, prefix, suffix string) (result bool, keys []string, err error)

DoExpr 执行表达式

func (*Executor) DoTerm

func (e *Executor) DoTerm(m map[string]any, term *expression.AstNode, prefix, suffix string) (result bool, keys []string)

DoTerm 执行 term

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL