ast

package
Version: v0.0.0-...-46d7da7 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractEQMatches

func ExtractEQMatches(src string) (map[string]interface{}, error)

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

NewFinder returns a new AttributeDescriptorFinder instance, based on the given attributes

type Constant

type Constant struct {
	StrValue string
	Value    interface{}
	Type     dpb.ValueType
}

Constant models a typed constant.

func (*Constant) String

func (c *Constant) String() string

type Expression

type Expression struct {
	// Oneof the following
	Const *Constant
	Var   *Variable
	Fn    *Function
}

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.

func (*Function) String

func (f *Function) String() string

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.

type Variable

type Variable struct {
	Name string
}

Variable models a variable.

func (*Variable) String

func (v *Variable) String() string

Jump to

Keyboard shortcuts

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