Documentation ¶
Index ¶
- func AddFunction(name string, handler func(params ...any) (any, error))
- func Compile(input string, ops ...Option) (*vm.Program, error)
- func Eval(input string, env interface{}) (interface{}, error)
- func Parse(expr string) (*vm.Program, error)
- func Run(program *vm.Program, env interface{}) (interface{}, error)
- type Option
- func AllowUndefinedVariables() Option
- func AsBool() Option
- func AsFloat64() Option
- func AsInt() Option
- func AsInt64() Option
- func AsKind(kind reflect.Kind) Option
- func ConstExpr(fn string) Option
- func Env(env interface{}) Option
- func Function(name string, fn func(params ...interface{}) (interface{}, error), ...) Option
- func Operator(operator string, fn ...string) Option
- func Optimize(b bool) Option
- func Patch(visitor ast.Visitor) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
Option for configuring config.
func AllowUndefinedVariables ¶
func AllowUndefinedVariables() Option
AllowUndefinedVariables allows to use undefined variables inside expressions. This can be used with expr.Env option to partially define a few variables.
func ConstExpr ¶
ConstExpr defines func expression as constant. If all argument to this function is constants, then it can be replaced by result of this func call on compile step.
func Env ¶
func Env(env interface{}) Option
Env specifies expected input of env for type checks. If struct is passed, all fields will be treated as variables, as well as all fields of embedded structs and struct itself. If map is passed, all items will be treated as variables. Methods defined on this type will be available as functions.
func Function ¶
func Function(name string, fn func(params ...interface{}) (interface{}, error), types ...interface{}) Option
Function adds function to list of functions what will be available in expressions.