invocation

package
v0.0.0-...-f9dd102 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package invocation provides a mechanism for defining and invoking functions in a yamlpath expression.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownFunc = errors.New("unknown function")

ErrUnknownFunc is an error that is returned when a function is not found in the function table.

Functions

This section is empty.

Types

type Context

type Context interface {
	// Root returns the root node that started the full YAMLPath.
	Root() []*yaml.Node

	// Current returns the current node in the YAMLPath expression.
	// This is typically the node that should be operated on.
	Current() []*yaml.Node

	// NewContext returns a new context with the given node as the current node.
	NewContext([]*yaml.Node) Context

	// WithContext returns a new context with the given context.
	WithContext(context.Context) Context

	// GetContext retrieves the context from the invocation context.
	Context() context.Context
}

Context is a representation of the current context of the yamlpath expression.

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry is a function entry in the function table.

func (*Entry) Invoke

func (e *Entry) Invoke(ctx Context, params ...Parameter) ([]*yaml.Node, error)

Invoke invokes the function with the given context and arguments.

func (*Entry) SetArity

func (e *Entry) SetArity(a arity.Arity)

SetArity sets the arity of the function entry.

func (*Entry) TestArity

func (e *Entry) TestArity(n int) error

TestArity tests the arity of the function with the given number of arguments.

type Func

type Func interface {
	// Invoke invokes the function with the given context and arguments.
	Invoke(ctx Context, params ...Parameter) ([]*yaml.Node, error)

	// TestArity tests the arity of the function with the given number of
	// arguments.
	TestArity(n int) error
}

Func is a representation of a function that can be used in a yamlpath expression.

type Parameter

type Parameter interface {
	// GetArg retrieves the argument from the parameter.
	GetArg(Context) ([]*yaml.Node, error)
}

Parameter is a representation of a parameter that can be used in a yamlpath expression.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is an invocation table that maps function names to function definitions.

func NewTable

func NewTable() *Table

NewTable creates a new function table.

func (*Table) Add

func (t *Table) Add(name string, fn funcEntry) *Entry

Add adds a function to the table. By default, functions have an arity of zero -- meaning no arguments may be provided to them. To set the arity of the function, use the Entry.SetArity method on the returned Entry.

func (*Table) Lookup

func (t *Table) Lookup(name string) (fn Func, ok bool)

Lookup performs a function lookup in the table, and if the function is not found, it will recursively search the parent table. If the function is not found in the parent table, ok will be set to false and fn will be nil.

func (*Table) New

func (t *Table) New() *Table

New creates a new function table from the current parent table.

Directories

Path Synopsis
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.
Package invocationtest provides test-doubles for the invocation package
Package invocationtest provides test-doubles for the invocation package

Jump to

Keyboard shortcuts

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