stateful

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFloat = errors.New("value is not a float")

Functions

func FindReferenceVariables

func FindReferenceVariables(nodes ...ast.Node) []string

Types

type DynamicMethod added in v1.0.0

type DynamicMethod func(self interface{}, args ...interface{}) (interface{}, error)

type ErrSide

type ErrSide struct {
	IsLeft  bool
	IsRight bool
	// contains filtered or unexported fields
}

ErrSide wraps the error in the evaluation, we use this error to indicate the origin of the error left side or right side

type ErrTypeGuardFailed

type ErrTypeGuardFailed struct {
	RequestedType ast.ValueType
	ActualType    ast.ValueType
}

ErrTypeGuardFailed is returned when a speicifc value type is requested thorugh NodeEvaluator (for example: "Float64Value") when the node doesn't support the given type, for example "Float64Value" is called on BoolNode

func (ErrTypeGuardFailed) Error

func (e ErrTypeGuardFailed) Error() string

type EvalBinaryNode

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

EvalBinaryNode is stateful expression which

is evaluated using "expression trees" instead of stack based interpreter

func NewEvalBinaryNode

func NewEvalBinaryNode(node *ast.BinaryNode) (*EvalBinaryNode, error)

func (*EvalBinaryNode) EvalBool

func (e *EvalBinaryNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

EvalBool executes the expression based on eval bool

func (*EvalBinaryNode) EvalDuration added in v1.0.0

func (e *EvalBinaryNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalBinaryNode) EvalFloat

func (e *EvalBinaryNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

EvalNum executes the expression based on eval numeric

func (*EvalBinaryNode) EvalInt

func (e *EvalBinaryNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalBinaryNode) EvalRegex

func (n *EvalBinaryNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalBinaryNode) EvalString

func (e *EvalBinaryNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalBinaryNode) EvalTime added in v1.0.0

func (n *EvalBinaryNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalBinaryNode) IsDynamic added in v1.0.0

func (n *EvalBinaryNode) IsDynamic() bool

func (*EvalBinaryNode) Type

func (n *EvalBinaryNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalBoolNode

type EvalBoolNode struct {
	Node *ast.BoolNode
}

func (*EvalBoolNode) EvalBool

func (n *EvalBoolNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalBoolNode) EvalDuration added in v1.0.0

func (n *EvalBoolNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalBoolNode) EvalFloat

func (n *EvalBoolNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalBoolNode) EvalInt

func (n *EvalBoolNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalBoolNode) EvalRegex

func (n *EvalBoolNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalBoolNode) EvalString

func (n *EvalBoolNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalBoolNode) EvalTime added in v1.0.0

func (n *EvalBoolNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalBoolNode) IsDynamic added in v1.0.0

func (n *EvalBoolNode) IsDynamic() bool

func (*EvalBoolNode) Type

func (n *EvalBoolNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalDurationNode added in v1.0.0

type EvalDurationNode struct {
	Duration time.Duration
}

func (*EvalDurationNode) EvalBool added in v1.0.0

func (n *EvalDurationNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalDurationNode) EvalDuration added in v1.0.0

func (n *EvalDurationNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalDurationNode) EvalFloat added in v1.0.0

func (n *EvalDurationNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalDurationNode) EvalInt added in v1.0.0

func (n *EvalDurationNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalDurationNode) EvalRegex added in v1.0.0

func (n *EvalDurationNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalDurationNode) EvalString added in v1.0.0

func (n *EvalDurationNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalDurationNode) EvalTime added in v1.0.0

func (n *EvalDurationNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalDurationNode) IsDynamic added in v1.0.0

func (n *EvalDurationNode) IsDynamic() bool

func (*EvalDurationNode) Type added in v1.0.0

func (n *EvalDurationNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalFloatNode

type EvalFloatNode struct {
	Float64 float64
}

func (*EvalFloatNode) EvalBool

func (n *EvalFloatNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalFloatNode) EvalDuration added in v1.0.0

func (n *EvalFloatNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalFloatNode) EvalFloat

func (n *EvalFloatNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalFloatNode) EvalInt

func (n *EvalFloatNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalFloatNode) EvalRegex

func (n *EvalFloatNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalFloatNode) EvalString

func (n *EvalFloatNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalFloatNode) EvalTime added in v1.0.0

func (n *EvalFloatNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalFloatNode) IsDynamic added in v1.0.0

func (n *EvalFloatNode) IsDynamic() bool

func (*EvalFloatNode) Type

func (n *EvalFloatNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalFunctionNode

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

func NewEvalFunctionNode

func NewEvalFunctionNode(funcNode *ast.FunctionNode) (*EvalFunctionNode, error)

func (*EvalFunctionNode) EvalBool

func (n *EvalFunctionNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalFunctionNode) EvalDuration added in v1.0.0

func (n *EvalFunctionNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalFunctionNode) EvalFloat

func (n *EvalFunctionNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalFunctionNode) EvalInt

func (n *EvalFunctionNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalFunctionNode) EvalRegex

func (n *EvalFunctionNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalFunctionNode) EvalString

func (n *EvalFunctionNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalFunctionNode) EvalTime added in v1.0.0

func (n *EvalFunctionNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalFunctionNode) IsDynamic added in v1.0.0

func (n *EvalFunctionNode) IsDynamic() bool

func (*EvalFunctionNode) Type

func (n *EvalFunctionNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalIntNode

type EvalIntNode struct {
	Int64 int64
}

func (*EvalIntNode) EvalBool

func (n *EvalIntNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalIntNode) EvalDuration added in v1.0.0

func (n *EvalIntNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalIntNode) EvalFloat

func (n *EvalIntNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalIntNode) EvalInt

func (n *EvalIntNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalIntNode) EvalRegex

func (n *EvalIntNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalIntNode) EvalString

func (n *EvalIntNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalIntNode) EvalTime added in v1.0.0

func (n *EvalIntNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalIntNode) IsDynamic added in v1.0.0

func (n *EvalIntNode) IsDynamic() bool

func (*EvalIntNode) Type

func (n *EvalIntNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalLambdaNode added in v1.0.0

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

func NewEvalLambdaNode added in v1.0.0

func NewEvalLambdaNode(lambda *ast.LambdaNode) (*EvalLambdaNode, error)

func (*EvalLambdaNode) EvalBool added in v1.0.0

func (n *EvalLambdaNode) EvalBool(scope *Scope, _ ExecutionState) (bool, error)

func (*EvalLambdaNode) EvalDuration added in v1.0.0

func (n *EvalLambdaNode) EvalDuration(scope *Scope, _ ExecutionState) (time.Duration, error)

func (*EvalLambdaNode) EvalFloat added in v1.0.0

func (n *EvalLambdaNode) EvalFloat(scope *Scope, _ ExecutionState) (float64, error)

func (*EvalLambdaNode) EvalInt added in v1.0.0

func (n *EvalLambdaNode) EvalInt(scope *Scope, _ ExecutionState) (int64, error)

func (*EvalLambdaNode) EvalRegex added in v1.0.0

func (n *EvalLambdaNode) EvalRegex(scope *Scope, _ ExecutionState) (*regexp.Regexp, error)

func (*EvalLambdaNode) EvalString added in v1.0.0

func (n *EvalLambdaNode) EvalString(scope *Scope, _ ExecutionState) (string, error)

func (*EvalLambdaNode) EvalTime added in v1.0.0

func (n *EvalLambdaNode) EvalTime(scope *Scope, _ ExecutionState) (time.Time, error)

func (*EvalLambdaNode) IsDynamic added in v1.0.0

func (n *EvalLambdaNode) IsDynamic() bool

func (*EvalLambdaNode) Type added in v1.0.0

type EvalReferenceNode

type EvalReferenceNode struct {
	Node *ast.ReferenceNode
}

func (*EvalReferenceNode) EvalBool

func (n *EvalReferenceNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalReferenceNode) EvalDuration added in v1.0.0

func (n *EvalReferenceNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalReferenceNode) EvalFloat

func (n *EvalReferenceNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalReferenceNode) EvalInt

func (n *EvalReferenceNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalReferenceNode) EvalRegex

func (n *EvalReferenceNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalReferenceNode) EvalString

func (n *EvalReferenceNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalReferenceNode) EvalTime added in v1.0.0

func (n *EvalReferenceNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalReferenceNode) IsDynamic added in v1.0.0

func (n *EvalReferenceNode) IsDynamic() bool

func (*EvalReferenceNode) Type

func (n *EvalReferenceNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalRegexNode

type EvalRegexNode struct {
	Node *ast.RegexNode
}

func (*EvalRegexNode) EvalBool

func (n *EvalRegexNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalRegexNode) EvalDuration added in v1.0.0

func (n *EvalRegexNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalRegexNode) EvalFloat

func (n *EvalRegexNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalRegexNode) EvalInt

func (n *EvalRegexNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalRegexNode) EvalRegex

func (n *EvalRegexNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalRegexNode) EvalString

func (n *EvalRegexNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalRegexNode) EvalTime added in v1.0.0

func (n *EvalRegexNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalRegexNode) IsDynamic added in v1.0.0

func (n *EvalRegexNode) IsDynamic() bool

func (*EvalRegexNode) Type

func (n *EvalRegexNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalStringNode

type EvalStringNode struct {
	Node *ast.StringNode
}

func (*EvalStringNode) EvalBool

func (n *EvalStringNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalStringNode) EvalDuration added in v1.0.0

func (n *EvalStringNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalStringNode) EvalFloat

func (n *EvalStringNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalStringNode) EvalInt

func (n *EvalStringNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalStringNode) EvalRegex

func (n *EvalStringNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalStringNode) EvalString

func (n *EvalStringNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalStringNode) EvalTime added in v1.0.0

func (n *EvalStringNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalStringNode) IsDynamic added in v1.0.0

func (n *EvalStringNode) IsDynamic() bool

func (*EvalStringNode) Type

func (n *EvalStringNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type EvalUnaryNode

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

func NewEvalUnaryNode

func NewEvalUnaryNode(unaryNode *ast.UnaryNode) (*EvalUnaryNode, error)

func (*EvalUnaryNode) EvalBool

func (n *EvalUnaryNode) EvalBool(scope *Scope, executionState ExecutionState) (bool, error)

func (*EvalUnaryNode) EvalDuration added in v1.0.0

func (n *EvalUnaryNode) EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

func (*EvalUnaryNode) EvalFloat

func (n *EvalUnaryNode) EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)

func (*EvalUnaryNode) EvalInt

func (n *EvalUnaryNode) EvalInt(scope *Scope, executionState ExecutionState) (int64, error)

func (*EvalUnaryNode) EvalRegex

func (n *EvalUnaryNode) EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)

func (*EvalUnaryNode) EvalString

func (n *EvalUnaryNode) EvalString(scope *Scope, executionState ExecutionState) (string, error)

func (*EvalUnaryNode) EvalTime added in v1.0.0

func (n *EvalUnaryNode) EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)

func (*EvalUnaryNode) IsDynamic added in v1.0.0

func (n *EvalUnaryNode) IsDynamic() bool

func (*EvalUnaryNode) Type

func (n *EvalUnaryNode) Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)

type ExecutionState

type ExecutionState struct {
	Funcs Funcs
}

ExecutionState is auxiliary struct for data/context that needs to be passed to evaluation functions

func CreateExecutionState

func CreateExecutionState() ExecutionState

func (ExecutionState) ResetAll

func (ea ExecutionState) ResetAll()

type Expression

type Expression interface {
	Reset()

	EvalFloat(scope *Scope) (float64, error)
	EvalInt(scope *Scope) (int64, error)
	EvalString(scope *Scope) (string, error)
	EvalBool(scope *Scope) (bool, error)
	EvalDuration(scope *Scope) (time.Duration, error)

	Eval(scope *Scope) (interface{}, error)

	// Return a copy of the expression but with a Reset state.
	CopyReset() Expression
}

Expression is interface that describe expression with state and it's evaluation.

func NewExpression

func NewExpression(node ast.Node) (Expression, error)

NewExpression accept a node and try to "compile"/ "specialise" it in order to achieve better runtime performance.

For example:

Given a BinaryNode{ReferNode("value"), NumberNode{Float64:10}} during runtime
we can find the type of "value" and find the most matching comparison function - (float64,float64) or (int64,float64)

type Func added in v1.0.0

type Func interface {
	Reset()
	Call(...interface{}) (interface{}, error)
}

A callable function from within the expression

type Funcs added in v1.0.0

type Funcs map[string]Func

Lookup for functions

func NewFunctions added in v1.0.0

func NewFunctions() Funcs

Return set of built-in Funcs

type NodeEvaluator

type NodeEvaluator interface {
	EvalFloat(scope *Scope, executionState ExecutionState) (float64, error)
	EvalInt(scope *Scope, executionState ExecutionState) (int64, error)
	EvalString(scope *Scope, executionState ExecutionState) (string, error)
	EvalBool(scope *Scope, executionState ExecutionState) (bool, error)
	EvalRegex(scope *Scope, executionState ExecutionState) (*regexp.Regexp, error)
	EvalTime(scope *Scope, executionState ExecutionState) (time.Time, error)
	EvalDuration(scope *Scope, executionState ExecutionState) (time.Duration, error)

	// Type returns the type of ast.ValueType
	Type(scope ReadOnlyScope, executionState ExecutionState) (ast.ValueType, error)
	// Whether the type returned by the node can change.
	IsDynamic() bool
}

NodeEvaluator provides a generic way for trying to fetch node value, if a speicifc type is requested (so Value isn't called, the *Value is called) ErrTypeGuardFailed must be returned

type ReadOnlyScope

type ReadOnlyScope interface {
	Get(name string) (interface{}, error)
}

type Scope added in v1.0.0

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

Contains a set of variables references and their values.

func NewScope added in v1.0.0

func NewScope() *Scope

Initialize a new Scope object.

func (*Scope) DynamicMethod added in v1.0.0

func (s *Scope) DynamicMethod(name string) DynamicMethod

func (*Scope) Get added in v1.0.0

func (s *Scope) Get(name string) (interface{}, error)

Get returns the value of 'name'.

func (*Scope) Has added in v1.0.0

func (s *Scope) Has(name string) bool

Whether a value has been set on the scope

func (*Scope) Reset added in v1.0.0

func (s *Scope) Reset()

Reset all scope values to an empty state.

func (*Scope) Set added in v1.0.0

func (s *Scope) Set(name string, value interface{})

Set defines a name -> value pairing in the scope.

func (*Scope) SetDynamicMethod added in v1.0.0

func (s *Scope) SetDynamicMethod(name string, m DynamicMethod)

type ScopePool

type ScopePool interface {
	Get() *Scope
	Put(scope *Scope)

	ReferenceVariables() []string
}

ScopePool - pooling mechanism for Scope The idea behind scope pool is to pool scopes and to put them only the needed variables for execution.

func NewScopePool

func NewScopePool(referenceVariables []string) ScopePool

NewScopePool - creates new ScopePool for the given Node

Jump to

Keyboard shortcuts

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