Documentation ¶
Index ¶
- Variables
- type Array
- type ArrayComparison
- type Call
- type Comparison
- type Evaluatable
- type Expression
- type ExpressionCache
- type Function
- type FunctionMap
- type Instance
- type InstanceResult
- type IterableComparison
- type IterableExpression
- type Iterator
- type PathExpression
- type ScalarComparison
- type Term
- type Unary
- type Value
- type VarMap
Constants ¶
This section is empty.
Variables ¶
var Cache = NewCache(cache.NoExpiration, 0)
Cache declares a default cache for expression evaluation with no key experation
var ( // ErrEmptyExpression is returned for empty string used as expression input ErrEmptyExpression = errors.New("invalid empty expression") )
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct { Pos lexer.Position Values []Value `parser:"\"[\" @@ { \",\" @@ } \"]\""` Ident *string `parser:"| @Ident"` }
Array provides support for array syntax and may contain any valid Values (mixed allowed)
type ArrayComparison ¶
type ArrayComparison struct { Pos lexer.Position Op *string `parser:"( @( \"in\" | \"not\" \"in\" )"` // TODO: likely doesn't work with rhs expression Array *Array `parser:"@@ )"` }
ArrayComparison represents syntax for array comparison
type Call ¶
type Call struct { Pos lexer.Position Name string `parser:"@Ident"` Args []*Expression `parser:"\"(\" [ @@ { \",\" @@ } ] \")\""` }
Call implements function call syntax
type Comparison ¶
type Comparison struct { Pos lexer.Position Term *Term `parser:"@@"` ScalarComparison *ScalarComparison `parser:"[ @@"` ArrayComparison *ArrayComparison `parser:"| @@ ]"` }
Comparison represents syntax for comparison operations
func (*Comparison) Evaluate ¶
func (c *Comparison) Evaluate(instance *Instance) (interface{}, error)
Evaluate implements Evaluatable interface
type Evaluatable ¶
Evaluatable abstracts part of an expression that can be evaluated for an instance
type Expression ¶
type Expression struct { Pos lexer.Position Comparison *Comparison `parser:"@@"` Op *string `parser:"[ @( \"|\" \"|\" | \"&\" \"&\" )"` Next *Expression `parser:" @@ ]"` }
Expression represents basic expression syntax that can be evaluated for an Instance
func ParseExpression ¶
func ParseExpression(s string) (*Expression, error)
ParseExpression parses Expression from a string
func (*Expression) BoolEvaluate ¶
func (e *Expression) BoolEvaluate(instance *Instance) (bool, error)
BoolEvaluate evaluates an expression for an instance as a boolean value
func (*Expression) Evaluate ¶
func (e *Expression) Evaluate(instance *Instance) (interface{}, error)
Evaluate evaluates an expression for an instance
type ExpressionCache ¶
type ExpressionCache struct {
// contains filtered or unexported fields
}
ExpressionCache implements cached parsing for expressions
func NewCache ¶
func NewCache(defaultExpiration, cleanupInterval time.Duration) *ExpressionCache
NewCache returns a new instance of evalCache
func (*ExpressionCache) ParseExpression ¶
func (c *ExpressionCache) ParseExpression(s string) (*Expression, error)
ParseExpression parses Expression from a string
func (*ExpressionCache) ParseIterable ¶
func (c *ExpressionCache) ParseIterable(s string) (*IterableExpression, error)
ParseIterable parses IterableExpression from a string
func (*ExpressionCache) ParsePath ¶
func (c *ExpressionCache) ParsePath(s string) (*PathExpression, error)
ParsePath parses PathExpression from a string
type Instance ¶
type Instance struct { // Instance functions Functions FunctionMap // Vars defined during evaluation. Vars VarMap }
Instance for evaluation
type InstanceResult ¶
InstanceResult captures an Instance along with the passed or failed status for the result
type IterableComparison ¶
type IterableComparison struct { Pos lexer.Position Fn *string `parser:"@( \"count\" | \"all\" | \"none\" )"` Expression *Expression `parser:"\"(\" @@ \")\""` ScalarComparison *ScalarComparison `parser:"[ @@ ]"` }
IterableComparison allows evaluating a builtin pseudo-funciion for an iterable expression
type IterableExpression ¶
type IterableExpression struct { Pos lexer.Position IterableComparison *IterableComparison `parser:"@@"` Expression *Expression `parser:"| @@"` }
IterableExpression represents an iterable expration that can be evaluated for an Iterator
func ParseIterable ¶
func ParseIterable(s string) (*IterableExpression, error)
ParseIterable parses IterableExpression from a string
func (*IterableExpression) Evaluate ¶
func (e *IterableExpression) Evaluate(instance *Instance) (bool, error)
Evaluate evaluates an iterable expression for a single instance
func (*IterableExpression) EvaluateIterator ¶
func (e *IterableExpression) EvaluateIterator(it Iterator, global *Instance) (*InstanceResult, error)
EvaluateIterator evaluates an iterable expression for an iterator
type PathExpression ¶
type PathExpression struct { Pos lexer.Position Path *string `parser:"@UnixSystemPath"` Expression *Expression `parser:"| @@"` }
PathExpression represents an expression evaluating to a file path or file glob
func ParsePath ¶
func ParsePath(s string) (*PathExpression, error)
ParsePath parses PathExpression from a string
func (*PathExpression) Evaluate ¶
func (e *PathExpression) Evaluate(instance *Instance) (interface{}, error)
Evaluate evaluates a path expression for an instance
type ScalarComparison ¶
type ScalarComparison struct { Pos lexer.Position Op *string `parser:"@( \">\" \"=\" | \"<\" \"=\" | \">\" | \"<\" | \"!\" \"=\" | \"=\" \"=\" | \"=\" \"~\" | \"!\" \"~\" )"` Next *Comparison `parser:" @@"` }
ScalarComparison represents syntax for scalar comparison
type Term ¶
type Term struct { Pos lexer.Position Unary *Unary `parser:"@@"` Op *string `parser:"[ @( \"&\" | \"|\" | \"^\" | \"+\" )"` Next *Term `parser:" @@ ]"` }
Term is an abstract term allowing optional binary bit operation syntax
type Unary ¶
type Unary struct { Pos lexer.Position Op *string `parser:"( @( \"!\" | \"-\" | \"^\" )"` Unary *Unary `parser:" @@ )"` Value *Value `parser:"| @@"` }
Unary is a unary bit operation syntax
type Value ¶
type Value struct { Pos lexer.Position Hex *string `parser:" @Hex"` Octal *string `parser:"| @Octal"` Decimal *int64 `parser:"| @Decimal"` String *string `parser:"| @String"` Call *Call `parser:"| @@"` Variable *string `parser:"| @Ident"` Subexpression *Expression `parser:"| \"(\" @@ \")\""` }
Value provides support for various value types in expression including integers in various form, strings, function calls, variables and subexpressions