exp

package
v0.0.0-...-79395b0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package exp contains expression types and the logic to evaluate them

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvLookup

func EnvLookup(e *types.Env, id string) (types.Expression, bool, error)

EnvLookup returns a variable either from current scope or the global registry

func RuleClose

func RuleClose(rule *types.Rule)

RuleClose closes a newly read rule so it can be used for evaluation

func RuleEval

func RuleEval(rule *types.Rule, env *types.Env) (bool, error)

func RuleVisitExpressions

func RuleVisitExpressions(rule *types.Rule, v visitor)

RuleVisitExpressions walks all expressions in a rule

func ScopeExtract

func ScopeExtract(s *types.Scope) map[string]interface{}

ScopeExtract extracts value from a scope

func Simplify

func Simplify(e types.Expression) types.Expression

Types

type ExtractExpression

type ExtractExpression struct {
	Offset   types.Expression
	Size     types.Expression
	Format   ExtractFormat
	Metadata *util.Register
}

func NewExtractExpression

func NewExtractExpression(o, s types.Expression, m *util.Register, f ExtractFormat) *ExtractExpression

func (*ExtractExpression) Eval

func (ee *ExtractExpression) Eval(env *types.Env) (types.Expression, error)

func (*ExtractExpression) Simplify

func (ee *ExtractExpression) Simplify() (types.Expression, error)

func (ExtractExpression) String

func (ue ExtractExpression) String() string

type ExtractFormat

type ExtractFormat int

extract types.Expression

const (
	Number ExtractFormat = iota
	String
	StringZ
)

type FunctionExpression

type FunctionExpression struct {
	Name     string
	Func     *util.Function
	Params   []types.Expression
	Metadata *util.Register
}

func NewFunctionExpression

func NewFunctionExpression(name string, m *util.Register,
	params ...types.Expression) (*FunctionExpression, error)

func (*FunctionExpression) Eval

func (fe *FunctionExpression) Eval(env *types.Env) (types.Expression, error)

func (*FunctionExpression) Simplify

func (fe *FunctionExpression) Simplify() (types.Expression, error)

func (FunctionExpression) String

func (fe FunctionExpression) String() string

type OperationExpression

type OperationExpression struct {
	Left      types.Expression
	Right     types.Expression
	Operation prim.Operation
}

operation types.Expression

func NewBinaryExpression

func NewBinaryExpression(left, right types.Expression,
	op prim.Operation) *OperationExpression

func NewUnaryExpression

func NewUnaryExpression(expr types.Expression, op prim.Operation) *OperationExpression

func (*OperationExpression) Eval

func (oe *OperationExpression) Eval(env *types.Env) (types.Expression, error)

func (*OperationExpression) Simplify

func (oe *OperationExpression) Simplify() (types.Expression, error)

func (OperationExpression) String

func (oe OperationExpression) String() string

type SliceExpression

type SliceExpression struct {
	Expr  types.Expression
	Start types.Expression
	End   types.Expression
}

SliceExpression contains an index/slice expresion

func NewSliceExpression

func NewSliceExpression(expr, start, end types.Expression) *SliceExpression

func (*SliceExpression) Eval

func (se *SliceExpression) Eval(env *types.Env) (types.Expression, error)

func (*SliceExpression) Simplify

func (se *SliceExpression) Simplify() (types.Expression, error)

func (SliceExpression) String

func (se SliceExpression) String() string

type ValueExpression

type ValueExpression struct {
	Value prim.Primitive
}

func NewBooleanExpression

func NewBooleanExpression(val bool) *ValueExpression

func NewNumberExpression

func NewNumberExpression(val uint64, size int, signed bool) *ValueExpression

func NewStringExpression

func NewStringExpression(s string) *ValueExpression

func NewStringExpressionRaw

func NewStringExpressionRaw(data []byte) *ValueExpression

func NewValueExpression

func NewValueExpression(val prim.Primitive) *ValueExpression

func (*ValueExpression) Eval

func (ve *ValueExpression) Eval(env *types.Env) (types.Expression, error)

func (*ValueExpression) Simplify

func (ve *ValueExpression) Simplify() (types.Expression, error)

func (ValueExpression) String

func (ve ValueExpression) String() string

type VariableExpression

type VariableExpression struct {
	Id string
}

variable types.Expression

func (*VariableExpression) Eval

func (ve *VariableExpression) Eval(env *types.Env) (types.Expression, error)

func (*VariableExpression) Simplify

func (ve *VariableExpression) Simplify() (types.Expression, error)

func (*VariableExpression) String

func (ve *VariableExpression) String() string

Directories

Path Synopsis
Package prim contains primitive types used in the epxressions
Package prim contains primitive types used in the epxressions

Jump to

Keyboard shortcuts

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