Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractEQMatches ¶
ExtractEQMatches extracts equality sub expressions from the match expression. It only extracts `attribute == literal` type equality matches. It returns a list of <attribute name, value> such that if **any** of these comparisons is false, the expression will evaluate to false. These sub expressions can be hoisted out of the match clause and evaluated separately. For example destination.service == "abc" -- Used to index rules by destination service. context.protocol == "tcp" -- Used to filter rules by context
func FuncMap ¶
func FuncMap(functions []FunctionMetadata) map[string]FunctionMetadata
FuncMap generates a full function map, combining the intrinsic functions needed for type-checking, along with external functions that are supplied as the functions parameter.
Types ¶
type AttributeDescriptorFinder ¶
type AttributeDescriptorFinder interface { // GetAttribute finds attribute descriptor in the vocabulary. returns nil if not found. GetAttribute(name string) *cfgpb.AttributeManifest_AttributeInfo }
AttributeDescriptorFinder finds attribute descriptors.
func NewFinder ¶
func NewFinder(attributes map[string]*configpb.AttributeManifest_AttributeInfo) AttributeDescriptorFinder
NewFinder returns a new AttributeDescriptorFinder instance, based on the given attributes
type Expression ¶
Expression is a simplified expression AST
func Parse ¶
func Parse(src string) (ex *Expression, err error)
Parse parses a given expression to ast.Expression.
func (*Expression) EvalType ¶
func (e *Expression) EvalType(attrs AttributeDescriptorFinder, fMap map[string]FunctionMetadata) (valueType dpb.ValueType, err error)
EvalType Function an expression using fMap and attribute vocabulary. Returns the type that this expression evaluates to.
func (*Expression) String ¶
func (e *Expression) String() string
String produces postfix version with all operators converted to function names
type Function ¶
type Function struct { Name string Target *Expression Args []*Expression }
Function models a function with multiple parameters 1st arg can be thought of as the receiver.
func (*Function) EvalType ¶
func (f *Function) EvalType(attrs AttributeDescriptorFinder, fMap map[string]FunctionMetadata) (valueType dpb.ValueType, err error)
EvalType Function using fMap and attribute vocabulary. Return static or computed return type if all args have correct type.
type FunctionMetadata ¶
type FunctionMetadata struct { // Name is the name of the function. Name string // Instance indicates that this is an instance method. Instance bool // TargetType is the type of the instance method target, if this function is an instance method. TargetType config.ValueType // ReturnType is the return type of the function. ReturnType config.ValueType // ArgumentTypes is the types of the arguments in the order that is expected by the function. ArgumentTypes []config.ValueType }
FunctionMetadata contains type metadata for functions.