GoFastExpress

package
v0.0.0-...-90fccff Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

GOFastExpress 一个快速的表达式引擎

特性
  • 非常简单的抽象语法树
  • 尽可能使用强制类型转换代替反射,提高性能
  • 参数可以为nil,可以判空,return的变量必须有值或者为nil,不为指针
  • 支持语法 + - * / == != >= <=

Documentation

Index

Constants

View Source
const (
	NArg    nodeType = iota
	NString          //string 节点
	NFloat           //float节点
	NInt             //int 节点
	NUInt            //uint节点
	NBool            //bool节点
	NNil             //空节点
	NBinary          //二元计算节点
	NOpt             //操作符节点
)

Variables

View Source
var NotSupportOptMap = map[string]bool{
	"=": true,
	"!": true,
	"@": true,
	"#": true,
	"$": true,
	"^": true,
	"&": true,
	"(": true,
	")": true,
	"`": true,
}

Functions

func DoCalculationAction

func DoCalculationAction(express string, operator Operator, a interface{}, b interface{}, av reflect.Value, bv reflect.Value) (interface{}, error)

func DoEqualAction

func DoEqualAction(express string, operator Operator, a interface{}, b interface{}, av reflect.Value, bv reflect.Value) (bool, error)

func Eval

func Eval(express string, operator Operator, a interface{}, b interface{}) (interface{}, error)

func EvalTakes

func EvalTakes(argNode ArgNode, arg interface{}) (interface{}, error)

取值

func GetDeepPtr

func GetDeepPtr(v reflect.Value) reflect.Value

func GetDeepValue

func GetDeepValue(av reflect.Value, arg interface{}) (interface{}, reflect.Value)

Types

type ArgNode

type ArgNode struct {
	// contains filtered or unexported fields
}

参数节点

func (ArgNode) Eval

func (it ArgNode) Eval(env interface{}) (interface{}, error)

func (ArgNode) Express

func (it ArgNode) Express() string

func (ArgNode) Type

func (it ArgNode) Type() nodeType

type BinaryNode

type BinaryNode struct {
	// contains filtered or unexported fields
}

计算节点

func (BinaryNode) Eval

func (it BinaryNode) Eval(env interface{}) (interface{}, error)

func (BinaryNode) Express

func (it BinaryNode) Express() string

func (BinaryNode) Type

func (it BinaryNode) Type() nodeType

type BoolNode

type BoolNode struct {
	// contains filtered or unexported fields
}

值节点

func (BoolNode) Eval

func (it BoolNode) Eval(env interface{}) (interface{}, error)

func (BoolNode) Express

func (it BoolNode) Express() string

func (BoolNode) Type

func (it BoolNode) Type() nodeType

type FloatNode

type FloatNode struct {
	// contains filtered or unexported fields
}

值节点

func (FloatNode) Eval

func (it FloatNode) Eval(env interface{}) (interface{}, error)

func (FloatNode) Express

func (it FloatNode) Express() string

func (FloatNode) Type

func (it FloatNode) Type() nodeType

type IntNode

type IntNode struct {
	// contains filtered or unexported fields
}

值节点

func (IntNode) Eval

func (it IntNode) Eval(env interface{}) (interface{}, error)

func (IntNode) Express

func (it IntNode) Express() string

func (IntNode) Type

func (it IntNode) Type() nodeType

type NilNode

type NilNode struct {
	// contains filtered or unexported fields
}

空节点

func (NilNode) Eval

func (NilNode) Eval(env interface{}) (interface{}, error)

func (NilNode) Express

func (it NilNode) Express() string

func (NilNode) Type

func (it NilNode) Type() nodeType

type Node

type Node interface {
	Type() nodeType
	Eval(env interface{}) (interface{}, error)
	Express() string
}

抽象语法树节点

func Parser

func Parser(express string) (Node, error)

type Operator

type Operator = string

操作符

const (
	//计算操作符
	Add    Operator = "+"
	Reduce Operator = "-"
	Ride   Operator = "*"
	Divide Operator = "/"

	//比较操作符
	And       Operator = "&&"
	Or        Operator = "||"
	Equal     Operator = "=="
	UnEqual   Operator = "!="
	Less      Operator = "<"
	LessEqual Operator = "<="
	More      Operator = ">"
	MoreEqual Operator = ">="

	Nil  Operator = "nil"
	Null Operator = "null"
)

func ParserOperators

func ParserOperators(express string) []Operator

type OptNode

type OptNode struct {
	// contains filtered or unexported fields
}

func (OptNode) Eval

func (it OptNode) Eval(env interface{}) (interface{}, error)

func (OptNode) Express

func (it OptNode) Express() string

func (OptNode) IsCalculationOperator

func (it OptNode) IsCalculationOperator() bool

func (OptNode) Type

func (it OptNode) Type() nodeType

type StringNode

type StringNode struct {
	// contains filtered or unexported fields
}

值节点

func (StringNode) Eval

func (it StringNode) Eval(env interface{}) (interface{}, error)

func (StringNode) Express

func (it StringNode) Express() string

func (StringNode) Type

func (it StringNode) Type() nodeType

type UIntNode

type UIntNode struct {
	// contains filtered or unexported fields
}

func (UIntNode) Eval

func (it UIntNode) Eval(env interface{}) (interface{}, error)

func (UIntNode) Express

func (it UIntNode) Express() string

func (UIntNode) Type

func (it UIntNode) Type() nodeType

Jump to

Keyboard shortcuts

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