expr

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFunction

func AddFunction(name string, handler func(params ...any) (any, error))

func AvailableFunctions added in v0.0.6

func AvailableFunctions() []string

func Compile

func Compile(input string, ops ...Option) (*vm.Program, error)

Compile parses and compiles given input expression to bytecode program.

func Eval

func Eval(input string, env any) (any, error)

Eval parses, compiles and runs given input.

func Parse

func Parse(expr string) (*vm.Program, error)

func Run

func Run(program *vm.Program, env any) (any, error)

Run evaluates given bytecode program.

Types

type Option

type Option func(c *conf.Config)

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 AsAny added in v0.0.5

func AsAny() Option

AsAny tells the compiler to expect any result.

func AsBool

func AsBool() Option

AsBool tells the compiler to expect a boolean result.

func AsFloat64

func AsFloat64() Option

AsFloat64 tells the compiler to expect a float64 result.

func AsInt

func AsInt() Option

AsInt tells the compiler to expect an int result.

func AsInt64

func AsInt64() Option

AsInt64 tells the compiler to expect an int64 result.

func AsKind

func AsKind(kind reflect.Kind) Option

AsKind tells the compiler to expect kind of the result.

func ConstExpr

func ConstExpr(fn string) Option

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

func DisableBuiltin(name string) Option

DisableBuiltin disables builtin function.

func EnableBuiltin added in v0.0.5

func EnableBuiltin(name string) Option

EnableBuiltin enables builtin function.

func Env

func Env(env any) 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 ...any) (any, error), types ...any) Option

Function adds function to list of functions what will be available in expressions.

func Operator

func Operator(operator string, fn ...string) Option

Operator allows to replace a binary operator with a function.

func Optimize

func Optimize(b bool) Option

Optimize turns optimizations on or off.

func Patch

func Patch(visitor ast.Visitor) Option

Patch adds visitor to list of visitors what will be applied before compiling AST to bytecode.

Jump to

Keyboard shortcuts

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