executor

package
v0.0.0-...-377a6f8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(e Executor, call *script.CallFunc) ([]interface{}, error)

func Register

func Register(name string, f Function)

Register a Function against a name. This will panic if name has already been registered

func RegisterFloat1

func RegisterFloat1(name string, f func(float64) float64)

RegisterFloat1 registers a function that accepts a float64 as its argument and returns a float64. This is common for mathematical functions

func RegisterFloat2

func RegisterFloat2(name string, f func(float64, float64) float64)

RegisterFloat2 registers a function that accepts 2 float64's as arguments and returns a float64. This is common for mathematical functions

Types

type CreateCloser

type CreateCloser interface {
	io.Closer
	// Create is called when the resource is referenced before the statement is executed
	Create() error
}

CreateCloser interface implemented by types that can be used as resources

type Executor

type Executor interface {
	ExpressionExecutor
	Run() error
	// ProcessParameters will call each parameter in a CallFunc returning the true values
	ProcessParameters(*script.CallFunc) ([]interface{}, error)
	// ArgsToValues will take a slice of arguments and convert to reflect.Value.
	// This will handle if CallFunc.Variadic is set
	ArgsToValues(cf *script.CallFunc, tf reflect.Type, args []interface{}) ([]reflect.Value, error)
	CallReflectFuncImpl(*script.CallFunc, reflect.Value, []interface{}) (interface{}, error)
}

func New

func New(s *script.Script) (Executor, error)

type ExpressionExecutor

type ExpressionExecutor interface {
	Calculator() calculator.Calculator
	GlobalScope() state.Variables
	Expression(op *script.Expression) error
	Statement(statements *script.Statement) error
	Statements(statements *script.Statements) error
}

func NewExpressionExecutor

func NewExpressionExecutor() ExpressionExecutor

NewExpressionExecutor returns an Executor that can evaluate Expressions. All packages are available, but no functions can be defined.

type Function

type Function func(e Executor, call *script.CallFunc) error

func FuncDelegate

func FuncDelegate(f any) Function

func Lookup

func Lookup(name string) (Function, bool)

Lookup a registered Function by name

func Of

func Of(funcs ...Function) Function

func (Function) Do

func (f Function) Do(e Executor, call *script.CallFunc) error

func (Function) RequireArgs

func (f Function) RequireArgs(n int) Function

RequireArgs enforces a function to be called with n arguments

func (Function) RequireArgsRange

func (f Function) RequireArgsRange(min, max int) Function

RequireArgsRange enforces a function to be called with a range of arguments

func (Function) RequireMaxArgs

func (f Function) RequireMaxArgs(n int) Function

RequireMaxArgs enforces a function to be called with a maximum of n arguments

func (Function) RequireMinArgs

func (f Function) RequireMinArgs(n int) Function

RequireMinArgs enforces a function to be called with at least n arguments

func (Function) Then

func (f Function) Then(b Function) Function

Jump to

Keyboard shortcuts

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