eval

package
v0.0.0-...-c922539 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const MaxCallDepth = 100

Variables

View Source
var (
	DebugEnabled = true
)

Functions

func Any

func Any(kinds map[string]any) value.Value

func Atoi

func Atoi(_ context.Context, args []value.Value) (value.Value, bool, error)

func Base64

func Base64(_ context.Context, args []value.Value) (value.Value, bool, error)

func Base64Decode

func Base64Decode(_ context.Context, args []value.Value) (value.Value, bool, error)

func Basename

func Basename(_ context.Context, args []value.Value) (value.Value, bool, error)

func Break

func Break() value.Value

func Catch

func Catch(ctx context.Context, args []value.Value) (value.Value, bool, error)

func Contains

func Contains(ctx context.Context, args []value.Value) (value.Value, bool, error)

func Cut

func Cut(_ context.Context, args []value.Value) (value.Value, bool, error)

func Debug

func Debug(_ context.Context, args []value.Value) (value.Value, bool, error)

func Describe

func Describe(ctx context.Context, args []value.Value) (value.Value, bool, error)

func Dirname

func Dirname(_ context.Context, args []value.Value) (value.Value, bool, error)

func EndsWith

func EndsWith(_ context.Context, args []value.Value) (value.Value, bool, error)

func Enum

func Enum(_ context.Context, args []value.Value) (value.Value, bool, error)

func Error

func Error(_ context.Context, args []value.Value) (value.Value, bool, error)

func EvalExpr

func EvalExpr(ctx context.Context, expr Expression, opts ...EvalOption) (value.Value, bool, error)

func EvalSchema

func EvalSchema(ctx context.Context, expr Expression) (value.Schema, bool, error)

func FileExt

func FileExt(_ context.Context, args []value.Value) (value.Value, bool, error)

func FromHex

func FromHex(_ context.Context, args []value.Value) (value.Value, bool, error)

func FromJSON

func FromJSON(_ context.Context, args []value.Value) (value.Value, bool, error)

func FromYAML

func FromYAML(_ context.Context, args []value.Value) (value.Value, bool, error)

func IndexOf

func IndexOf(_ context.Context, args []value.Value) (value.Value, bool, error)

func Int

func Int() value.Value

func IsA

func IsA(ctx context.Context, args []value.Value) (value.Value, bool, error)

func IsAllowNewKeys

func IsAllowNewKeys(ctx context.Context) bool

func IsSchema

func IsSchema(ctx context.Context) bool

func Join

func Join(_ context.Context, args []value.Value) (value.Value, bool, error)

func JoinHostPort

func JoinHostPort(_ context.Context, args []value.Value) (value.Value, bool, error)

func Keys

func Keys(_ context.Context, args []value.Value) (value.Value, bool, error)

func Len

func Len(_ context.Context, args []value.Value) (value.Value, bool, error)

func Merge

func Merge(_ context.Context, args []value.Value) (value.Value, bool, error)

func Mod

func Mod(_ context.Context, args []value.Value) (value.Value, bool, error)

func NativeFuncValue

func NativeFuncValue(f func(context.Context, []value.Value) (value.Value, bool, error)) value.Value

func NewErrUnknownError

func NewErrUnknownError(node ast.Node) error

func PathJoin

func PathJoin(_ context.Context, args []value.Value) (value.Value, bool, error)

func Range

func Range(_ context.Context, args []value.Value) (value.Value, bool, error)

func Replace

func Replace(_ context.Context, args []value.Value) (value.Value, bool, error)

func Sha1sum

func Sha1sum(_ context.Context, args []value.Value) (value.Value, bool, error)

func Sha256sum

func Sha256sum(_ context.Context, args []value.Value) (value.Value, bool, error)

func Sha512sum

func Sha512sum(_ context.Context, args []value.Value) (value.Value, bool, error)

func Skip

func Skip() value.Value

func Sort

func Sort(ctx context.Context, args []value.Value) (value.Value, bool, error)

func Split

func Split(_ context.Context, args []value.Value) (value.Value, bool, error)

func SplitHostPort

func SplitHostPort(_ context.Context, args []value.Value) (value.Value, bool, error)

func StartsWith

func StartsWith(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToHex

func ToHex(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToJSON

func ToJSON(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToLower

func ToLower(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToTitle

func ToTitle(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToUpper

func ToUpper(_ context.Context, args []value.Value) (value.Value, bool, error)

func ToYAML

func ToYAML(_ context.Context, args []value.Value) (value.Value, bool, error)

func Trim

func Trim(_ context.Context, args []value.Value) (value.Value, bool, error)

func TrimPrefix

func TrimPrefix(_ context.Context, args []value.Value) (value.Value, bool, error)

func TrimSuffix

func TrimSuffix(_ context.Context, args []value.Value) (value.Value, bool, error)

func WithAllowNewKeys

func WithAllowNewKeys(ctx context.Context, allowNewKeys bool) context.Context

func WithSchema

func WithSchema(ctx context.Context, schema bool) context.Context

func WithScope

func WithScope(ctx context.Context, scope Scope) context.Context

Types

type Array

type Array struct {
	Pos      value.Position
	Comments Comments
	Items    []Expression
}

func (*Array) ToValue

func (a *Array) ToValue(ctx context.Context) (value.Value, bool, error)

type BuildOption

type BuildOption struct {
	PositionalArgs []any
	Args           map[string]any
	Profiles       []string
}

type BuildOptions

type BuildOptions []BuildOption

func (BuildOptions) Merge

func (b BuildOptions) Merge() (merged BuildOption)

type Call

type Call struct {
	Comments Comments
	Pos      value.Position
	Func     Expression
	Args     []Field
}

func (*Call) ToValue

func (c *Call) ToValue(ctx context.Context) (value.Value, bool, error)

type Comments

type Comments struct {
	Comments [][]string
}

func (Comments) Last

func (c Comments) Last() string

type Default

type Default struct {
	Comments Comments
	Expr     Expression
	Pos      value.Position
}

func (*Default) ToValue

func (d *Default) ToValue(ctx context.Context) (value.Value, bool, error)

type Embedded

type Embedded struct {
	Pos        value.Position
	Comments   Comments
	Expression Expression
}

func (*Embedded) IsForLookup

func (e *Embedded) IsForLookup(_ context.Context) bool

func (*Embedded) IsForValue

func (e *Embedded) IsForValue(_ context.Context) bool

func (*Embedded) IsPositionalArgument

func (e *Embedded) IsPositionalArgument() bool

func (*Embedded) Position

func (e *Embedded) Position() value.Position

func (*Embedded) ToValueForIndex

func (e *Embedded) ToValueForIndex(ctx context.Context, fieldIndex int) (value.Value, bool, error)

type ErrInvalidArgument

type ErrInvalidArgument struct {
	Err error
}

func (*ErrInvalidArgument) Error

func (e *ErrInvalidArgument) Error() string

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key     string
	Message string
	Err     error
}

func (*ErrKeyNotFound) Error

func (e *ErrKeyNotFound) Error() string

func (*ErrKeyNotFound) Unwrap

func (e *ErrKeyNotFound) Unwrap() error

type ErrUnknownError

type ErrUnknownError struct {
	Node ast.Node
}

func (*ErrUnknownError) Error

func (e *ErrUnknownError) Error() string

type ErrorValue

type ErrorValue struct {
	value.Value
}

func (ErrorValue) Error

func (e ErrorValue) Error() string

type EvalOption

type EvalOption struct {
	Globals       map[string]any
	GlobalsLookup ScopeFunc
}

func (EvalOption) Complete

func (e EvalOption) Complete() EvalOption

type EvalOptions

type EvalOptions []EvalOption

func (EvalOptions) Merge

func (e EvalOptions) Merge() (result EvalOption)

type Expression

type Expression interface {
	ToValue(ctx context.Context) (value.Value, bool, error)
}

type Field

type Field interface {
	ToValueForIndex(ctx context.Context, idx int) (value.Value, bool, error)
	Position() value.Position

	// IsForLookup Should this field be added to the current scope and it's keys available as scope keys
	IsForLookup(ctx context.Context) bool
	// IsForValue Should this fields value be contributed to the rendered data
	IsForValue(ctx context.Context) bool
}

type FieldKey

type FieldKey struct {
	Match         Expression
	Interpolation Expression
	Key           string
	Pos           value.Position
}

func (*FieldKey) ToString

func (k *FieldKey) ToString(ctx context.Context) (_ string, undef value.Value, _ bool, _ error)

type File

type File struct {
	PositionalArgs []any
	Args           map[string]any
	Profiles       []string
	Body           *Struct
}

func Build

func Build(file *ast.File, opts ...BuildOption) (*File, error)

func (*File) CallArgs

func (f *File) CallArgs() (result []value.CallArgument)

func (*File) Describe

func (f *File) Describe(ctx context.Context) (*value.FuncSchema, error)

func (*File) ToValue

func (f *File) ToValue(ctx context.Context) (value.Value, bool, error)

type For

type For struct {
	Comments   Comments
	Key        string
	Value      string
	Collection Expression
	Body       Expression
	Else       Expression
	Merge      bool
	Position   value.Position
}

func (*For) ToValue

func (f *For) ToValue(ctx context.Context) (value.Value, bool, error)

type Function

type Function struct {
	Pos            value.Position
	Scope          Scope
	Body           Expression
	ReturnType     Expression
	ArgsSchema     value.Schema
	ArgNames       value.Names
	ProfilesSchema value.Schema
	ProfileNames   value.Names
	FuncSchema     *value.FuncSchema
	ReturnBody     bool
	AssignRoot     bool
	UnscopedArgs   bool
	// contains filtered or unexported fields
}

func (*Function) Call

func (c *Function) Call(ctx context.Context, args []value.CallArgument) (ret value.Value, ok bool, err error)

func (*Function) Eq

func (c *Function) Eq(right value.Value) (value.Value, error)

func (*Function) Kind

func (c *Function) Kind() value.Kind

func (*Function) Returns

func (c *Function) Returns(ctx context.Context) (value.Value, bool, error)

type FunctionDefinition

type FunctionDefinition struct {
	Comments   Comments
	Pos        value.Position
	Body       *Struct
	ReturnType Expression
	ReturnBody bool
	AssignRoot bool
}

func (*FunctionDefinition) ToValue

func (f *FunctionDefinition) ToValue(ctx context.Context) (value.Value, bool, error)

type If

type If struct {
	Pos       value.Position
	Comments  Comments
	Condition Expression
	Value     Expression
	Else      Expression
}

func (*If) ToValue

func (i *If) ToValue(ctx context.Context) (ret value.Value, ok bool, err error)

type Index

type Index struct {
	Comments Comments
	Pos      value.Position
	Base     Expression
	Index    Expression
}

func (*Index) ToValue

func (i *Index) ToValue(ctx context.Context) (value.Value, bool, error)

type Interpolation

type Interpolation struct {
	Parts []any
}

func (*Interpolation) ToValue

func (i *Interpolation) ToValue(ctx context.Context) (value.Value, bool, error)

type IsArgumentDefinition

type IsArgumentDefinition interface {
	IsArgumentDefinition() bool
}

type IsPositionalArgument

type IsPositionalArgument interface {
	IsPositionalArgument() bool
}

type KeyValue

type KeyValue struct {
	Comments Comments
	Key      FieldKey
	Value    Expression
	Pos      value.Position
	Local    bool
	Optional bool
}

func (*KeyValue) IsArgumentDefinition

func (k *KeyValue) IsArgumentDefinition() bool

func (*KeyValue) IsForLookup

func (k *KeyValue) IsForLookup(_ context.Context) bool

func (*KeyValue) IsForValue

func (k *KeyValue) IsForValue(ctx context.Context) bool

func (*KeyValue) Position

func (k *KeyValue) Position() value.Position

func (*KeyValue) ToValueForIndex

func (k *KeyValue) ToValueForIndex(ctx context.Context, i int) (value.Value, bool, error)

type LambdaDefinition

type LambdaDefinition struct {
	Comments Comments
	Pos      value.Position
	Vars     []string
	Body     Expression
}

func (*LambdaDefinition) ToValue

func (f *LambdaDefinition) ToValue(ctx context.Context) (value.Value, bool, error)

type Lookup

type Lookup struct {
	Comments Comments
	Pos      value.Position
	Key      string
}

func (*Lookup) ToValue

func (l *Lookup) ToValue(ctx context.Context) (value.Value, bool, error)

type LoopControl

type LoopControl struct {
	Skip  bool
	Break bool
	Value value.Value
}

func (*LoopControl) Kind

func (l *LoopControl) Kind() value.Kind

type NativeFunc

type NativeFunc func(context.Context, []value.Value) (value.Value, bool, error)

type Op

type Op struct {
	Unary    bool
	Comments Comments
	Operator value.Operator
	Left     Expression
	Right    Expression
	Pos      value.Position
}

func (*Op) ToValue

func (o *Op) ToValue(ctx context.Context) (value.Value, bool, error)

type Parens

type Parens struct {
	Comments Comments
	Expr     Expression
}

func (*Parens) ToValue

func (p *Parens) ToValue(ctx context.Context) (value.Value, bool, error)

type Path

type Path []PathElement

func (Path) String

func (p Path) String() string

type PathElement

type PathElement struct {
	Key   *string
	Index *int
	Call  bool
}

type Schema

type Schema struct {
	Comments       Comments
	Expression     Expression
	AllowNewFields bool
}

func (*Schema) ToValue

func (s *Schema) ToValue(ctx context.Context) (value.Value, bool, error)

type Scope

type Scope interface {
	Depth() int
	IsRoot(ctx context.Context) (bool, error)
	Get(ctx context.Context, key string) (value.Value, bool, error)
	NewScope(ctx context.Context, data ScopeStorage) (Scope, context.Context)
}
var Builtin Scope

func EmptyScope

func EmptyScope(ctx context.Context, data map[string]any) (Scope, context.Context)

func GetScope

func GetScope(ctx context.Context) Scope

type ScopeAsValue

type ScopeAsValue struct {
	Ctx   context.Context
	Scope Scope
}

func (ScopeAsValue) Kind

func (s ScopeAsValue) Kind() value.Kind

func (ScopeAsValue) LookupValue

func (s ScopeAsValue) LookupValue(key value.Value) (value.Value, bool, error)

type ScopeData

type ScopeData map[string]any

func (ScopeData) Lookup

func (m ScopeData) Lookup(ctx context.Context, key string, parent Scope) (value.Value, bool, error)

type ScopeFunc

type ScopeFunc func(ctx context.Context, key string, parent Scope) (value.Value, bool, error)

func (ScopeFunc) Lookup

func (s ScopeFunc) Lookup(ctx context.Context, key string, parent Scope) (value.Value, bool, error)

type ScopeStorage

type ScopeStorage interface {
	Lookup(ctx context.Context, key string, parent Scope) (value.Value, bool, error)
}

type Selector

type Selector struct {
	Comments Comments
	Pos      value.Position
	Base     Expression
	Key      Expression
}

func (*Selector) ToValue

func (s *Selector) ToValue(ctx context.Context) (_ value.Value, _ bool, retErr error)

type Slice

type Slice struct {
	Comments Comments
	Pos      value.Position
	Base     Expression
	Start    Expression
	End      Expression
}

func (*Slice) ToValue

func (s *Slice) ToValue(ctx context.Context) (value.Value, bool, error)

type Struct

type Struct struct {
	Position value.Position
	Comments Comments
	Fields   []Field
}

func (*Struct) ToValue

func (s *Struct) ToValue(ctx context.Context) (value.Value, bool, error)

type Value

type Value struct {
	Value value.Value
}

func (Value) ToValue

func (v Value) ToValue(_ context.Context) (value.Value, bool, error)

type ValueScopeLookup

type ValueScopeLookup struct {
	Value value.Value
}

func (ValueScopeLookup) Lookup

func (v ValueScopeLookup) Lookup(ctx context.Context, key string, parent Scope) (value.Value, bool, error)

Jump to

Keyboard shortcuts

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