Documentation ¶
Index ¶
- func AddFunction(name string, handler func(params ...any) (any, error))
- func AvailableFunctions() []string
- func Compile(input string, ops ...Option) (*vm.Program, error)
- func Eval(input string, env any) (any, error)
- func Parse(expr string) (*vm.Program, error)
- func Run(program *vm.Program, env any) (any, error)
- type Option
- func AllowUndefinedVariables() Option
- func AsAny() 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 DisableAllBuiltins() Option
- func DisableBuiltin(name string) Option
- func EnableBuiltin(name string) Option
- func Env(env any) Option
- func Function(name string, fn func(params ...any) (any, error), types ...any) 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 ¶
func AvailableFunctions ¶ added in v0.0.6
func AvailableFunctions() []string
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 DisableAllBuiltins ¶ added in v0.0.5
func DisableAllBuiltins() Option
DisableAllBuiltins disables all builtins.
func DisableBuiltin ¶ added in v0.0.5
DisableBuiltin disables builtin function.
func EnableBuiltin ¶ added in v0.0.5
EnableBuiltin enables builtin function.
func Env ¶
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.