resolve

package
v0.401.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpressionNotParseable = errors.New("expression is invalid and cannot be parsed")
)
View Source
var ErrExpressionNotValidIdent = errors.New("expression is not an ident")
View Source
var ErrExpressionNotValidIdentArray = errors.New("expression is not an ident array")

Functions

func AsIdent

func AsIdent(expression *parser.Expression) (*parser.ExpressionIdent, error)

AsIdent expects and retrieves the single ident operand in an expression

func AsIdentArray

func AsIdentArray(expression *parser.Expression) ([]*parser.ExpressionIdent, error)

AsIdentArray expects and retrieves the array of idents

func FieldLookups

func FieldLookups(model *parser.ModelNode, expression *parser.Expression) ([][]*parser.ExpressionIdent, error)

FieldLookups retrieves groups of ident lookups using equals comparison which could apply as a filter

func IdentOperands

func IdentOperands(expression *parser.Expression) ([]*parser.ExpressionIdent, error)

IdentOperands retrieves all the ident operands in an expression

func RunCelVisitor

func RunCelVisitor[T any](expression *parser.Expression, visitor Visitor[T]) (T, error)

func ToValue

func ToValue[T any](expression *parser.Expression) (T, bool, error)

ToValue expects and resolves to a specific type by evaluating the expression

func ToValueArray

func ToValueArray[T any](expression *parser.Expression) ([]T, error)

ToValueArray expects and resolves to a specific array type by evaluating the expression

Types

type CelVisitor

type CelVisitor[T any] struct {
	// contains filtered or unexported fields
}

CelVisitor steps through the CEL AST and calls out to the visitor

func (*CelVisitor[T]) SelectExpr

func (w *CelVisitor[T]) SelectExpr(expr *exprpb.Expr) error

type Visitor

type Visitor[T any] interface {
	// StartTerm is called when a new term is visited
	StartTerm(nested bool) error
	// EndTerm is called when a term is finished
	EndTerm(nested bool) error
	// StartFunction is called when a function is started
	StartFunction(name string) error
	// EndFunction is called when a function is finished
	EndFunction() error
	// VisitAnd is called when an 'and' operator is visited between conditions
	VisitAnd() error
	// VisitAnd is called when an 'or' operator is visited between conditions
	VisitOr() error
	// VisitNot is called when a logical not '!' is visited before a condition
	VisitNot() error
	// VisitLiteral is called when a literal operand is visited (e.g. "Keel")
	VisitLiteral(value any) error
	// VisitIdent is called when a field operand, variable or enum value is visited (e.g. post.name)
	VisitIdent(ident *parser.ExpressionIdent) error
	// VisitIdentArray is called when an ident array is visited (e.g. [Category.Sport, Category.Edu])
	VisitIdentArray(idents []*parser.ExpressionIdent) error
	// VisitOperator is called when a condition's operator visited (e.g. ==)
	VisitOperator(operator string) error
	// Returns a value after the visitor has completed executing
	Result() (T, error)
}

Jump to

Keyboard shortcuts

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