expression

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ExpressionDefs []ExpressionDef
	FunctionDefs   []*FunctionDefinition
)
View Source
var VariablePattern = regexp.MustCompile(`(\$)?\$\{\{\s*(.*?)\s*\}\}`)

VariablePattern is a regular expression that matches variable references in a template.

Functions

func ToBool

func ToBool(v Value) bool

func ToNumber

func ToNumber(v Value) float64

func ToString

func ToString(v Value) string

func ValueToString

func ValueToString(value interface{}) string

ValueToString converts a value to its string representation

Types

type Argument

type Argument struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Required bool   `json:"required"`
}

type BinaryOpExpr

type BinaryOpExpr struct {
	Left  Expression
	Op    BinaryOpType
	Right Expression
}

BinaryOpExpr represents a binary operation

func (*BinaryOpExpr) Definition

func (e *BinaryOpExpr) Definition() ExpressionDef

func (*BinaryOpExpr) Eval

func (e *BinaryOpExpr) Eval(ctx *EvalContext) (Value, error)

type BinaryOpType

type BinaryOpType string
const (
	BinaryOpTypeAdd BinaryOpType = "+"
	BinaryOpTypeSub BinaryOpType = "-"
	BinaryOpTypeMul BinaryOpType = "*"
	BinaryOpTypeDiv BinaryOpType = "/"
	BinaryOpTypeMod BinaryOpType = "%"

	BinaryOpTypeEq  BinaryOpType = "=="
	BinaryOpTypeNeq BinaryOpType = "!="
	BinaryOpTypeLt  BinaryOpType = "<"
	BinaryOpTypeGt  BinaryOpType = ">"
	BinaryOpTypeLte BinaryOpType = "<="
	BinaryOpTypeGte BinaryOpType = ">="
	BinaryOpTypeAnd BinaryOpType = "&&"
	BinaryOpTypeOr  BinaryOpType = "||"
)

type BoolValue

type BoolValue struct {
	Val bool
}

func (BoolValue) Equals

func (v BoolValue) Equals(other Value) bool

func (BoolValue) GoValue

func (v BoolValue) GoValue() interface{}

func (BoolValue) String

func (v BoolValue) String() string

func (BoolValue) Type

func (v BoolValue) Type() ValueType

type CallExpr

type CallExpr struct {
	Name string
	Args []Expression
}

CallExpr represents a function call

func (*CallExpr) Definition

func (e *CallExpr) Definition() ExpressionDef

func (*CallExpr) Eval

func (e *CallExpr) Eval(ctx *EvalContext) (Value, error)

type ConditionalExpr

type ConditionalExpr struct {
	Condition Expression
	TrueExpr  Expression
	FalseExpr Expression
}

ConditionalExpr represents a ternary conditional expression

func (*ConditionalExpr) Definition

func (e *ConditionalExpr) Definition() ExpressionDef

func (*ConditionalExpr) Eval

func (e *ConditionalExpr) Eval(ctx *EvalContext) (Value, error)

type DotExpr

type DotExpr struct {
	Object Expression
	Field  string
}

DotExpr represents object property access

func (*DotExpr) Definition

func (e *DotExpr) Definition() ExpressionDef

func (*DotExpr) Eval

func (e *DotExpr) Eval(ctx *EvalContext) (Value, error)

type EvalContext

type EvalContext struct {
	Variables *VariableScope
	Functions *FunctionRegistry
	ExecCtx   *execcontext.ExecutionContext
}

EvalContext contains the context for expression evaluation

type Expression

type Expression interface {
	Eval(*EvalContext) (Value, error)
	Definition() ExpressionDef
}

func Parse

func Parse(input string) (Expression, error)

type ExpressionDef

type ExpressionDef struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Examples    []string `json:"examples"`
}

type ExpressionEvaluator

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

ExpressionEvaluator handles expression evaluation

func NewExpressionEvaluator

func NewExpressionEvaluator() *ExpressionEvaluator

NewExpressionEvaluator creates a new expression evaluator

func (*ExpressionEvaluator) Evaluate

func (ee *ExpressionEvaluator) Evaluate(expression string, execCtx *execcontext.ExecutionContext) (interface{}, error)

Evaluate evaluates an expression

type Function

type Function func(args []interface{}, execCtx *execcontext.ExecutionContext) (interface{}, error)

Function represents a built-in function

type FunctionDefinition

type FunctionDefinition struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Args        []Argument `json:"args"`
	Returns     string     `json:"returns"`
	Example     string     `json:"example"`
	Impl        Function   `json:"-"`
}

type FunctionRegistry

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

FunctionRegistry manages built-in functions for expressions

func NewFunctionRegistry

func NewFunctionRegistry() *FunctionRegistry

NewFunctionRegistry creates a new function registry with all GitHub Actions functions

func (*FunctionRegistry) Call

func (fr *FunctionRegistry) Call(name string, args []interface{}, execCtx *execcontext.ExecutionContext) (interface{}, error)

Call invokes a function with the given arguments

func (*FunctionRegistry) GetCompactPromptDescription

func (fr *FunctionRegistry) GetCompactPromptDescription() string

GetCompactPromptDescription returns a condensed version suitable for shorter prompts

func (*FunctionRegistry) GetFunctionDefinition

func (fr *FunctionRegistry) GetFunctionDefinition(name string) (*FunctionDefinition, bool)

GetFunctionDefinition returns the function definition for a given name

func (*FunctionRegistry) ListFunctions

func (fr *FunctionRegistry) ListFunctions() []*FunctionDefinition

ListFunctions returns all available function definitions sorted by name

type IndexExpr

type IndexExpr struct {
	Object Expression
	Index  Expression
}

IndexExpr represents array/map indexing

func (*IndexExpr) Definition

func (e *IndexExpr) Definition() ExpressionDef

func (*IndexExpr) Eval

func (e *IndexExpr) Eval(ctx *EvalContext) (Value, error)

type ListValue

type ListValue struct {
	Vals []Value
}

func (ListValue) Equals

func (v ListValue) Equals(other Value) bool

func (ListValue) GoValue

func (v ListValue) GoValue() interface{}

func (ListValue) String

func (v ListValue) String() string

func (ListValue) Type

func (v ListValue) Type() ValueType

type LiteralExpr

type LiteralExpr struct {
	Value Value
}

LiteralExpr represents a literal value

func (*LiteralExpr) Definition

func (e *LiteralExpr) Definition() ExpressionDef

func (*LiteralExpr) Description

func (e *LiteralExpr) Description() string

func (*LiteralExpr) Eval

func (e *LiteralExpr) Eval(ctx *EvalContext) (Value, error)

type MapValue

type MapValue struct {
	Vals map[string]Value
}

func (MapValue) Equals

func (v MapValue) Equals(other Value) bool

func (MapValue) GoValue

func (v MapValue) GoValue() interface{}

func (MapValue) String

func (v MapValue) String() string

func (MapValue) Type

func (v MapValue) Type() ValueType

type NilValue

type NilValue struct{}

func (NilValue) Equals

func (v NilValue) Equals(other Value) bool

func (NilValue) GoValue

func (v NilValue) GoValue() interface{}

func (NilValue) String

func (v NilValue) String() string

func (NilValue) Type

func (v NilValue) Type() ValueType

type NumberValue

type NumberValue struct {
	Val float64
}

func (NumberValue) Equals

func (v NumberValue) Equals(other Value) bool

func (NumberValue) GoValue

func (v NumberValue) GoValue() interface{}

func (NumberValue) String

func (v NumberValue) String() string

func (NumberValue) Type

func (v NumberValue) Type() ValueType

type Parser

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

type StringValue

type StringValue struct {
	Val string
}

func (StringValue) Equals

func (v StringValue) Equals(other Value) bool

func (StringValue) GoValue

func (v StringValue) GoValue() interface{}

func (StringValue) String

func (v StringValue) String() string

func (StringValue) Type

func (v StringValue) Type() ValueType

type TemplateEngine

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

TemplateEngine handles variable interpolation and template rendering

func NewTemplateEngine

func NewTemplateEngine() *TemplateEngine

NewTemplateEngine creates a new template engine

func (*TemplateEngine) Render

func (te *TemplateEngine) Render(template string, execCtx *execcontext.ExecutionContext) (interface{}, error)

Render renders a template string with variables from the execution context

type Token

type Token struct {
	Type  TokenType
	Value string
}

func Tokenize

func Tokenize(input string) ([]Token, error)

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenNumber
	TokenString

	TokenEq       // ==
	TokenNe       // !=
	TokenLt       // <
	TokenGt       // >
	TokenLe       // <=
	TokenGe       // >=
	TokenAnd      // &&
	TokenOr       // ||
	TokenNot      // !
	TokenPlus     // +
	TokenMinus    // -
	TokenMul      // *
	TokenDiv      // /
	TokenMod      // %
	TokenQuestion // ?
	TokenColon    // :

	TokenLParen   // (
	TokenRParen   // )
	TokenLBracket // [
	TokenRBracket // ]
	TokenDot      // .
	TokenComma    // ,
)

type UnaryOpExpr

type UnaryOpExpr struct {
	Op   UnaryOpType
	Expr Expression
}

UnaryOpExpr represents a unary operation

func (*UnaryOpExpr) Definition

func (e *UnaryOpExpr) Definition() ExpressionDef

func (*UnaryOpExpr) Eval

func (e *UnaryOpExpr) Eval(ctx *EvalContext) (Value, error)

type UnaryOpType

type UnaryOpType string
const (
	UnaryOpTypeNot UnaryOpType = "!"
	UnaryOpTypeNeg UnaryOpType = "-"
)

type Value

type Value interface {
	Type() ValueType
	GoValue() interface{}
	String() string
	Equals(Value) bool
}

Value represents any value in the expression system

func GoToValue

func GoToValue(v interface{}) Value

GoToValue converts a Go value to an expression Value

type ValueType

type ValueType string

ValueType represents the type of a value

const (
	TypeNil     ValueType = "nil"
	TypeBool    ValueType = "bool"
	TypeNumber  ValueType = "number"
	TypeString  ValueType = "string"
	TypeList    ValueType = "list"
	TypeMap     ValueType = "map"
	TypeUnknown ValueType = "unknown"
)

type VariableExpr

type VariableExpr struct {
	Name string
}

VariableExpr represents a variable reference

func (*VariableExpr) Definition

func (e *VariableExpr) Definition() ExpressionDef

func (*VariableExpr) Eval

func (e *VariableExpr) Eval(ctx *EvalContext) (Value, error)

type VariableResolver

type VariableResolver struct{}

VariableResolver handles variable resolution from the execution context

func NewVariableResolver

func NewVariableResolver() *VariableResolver

NewVariableResolver creates a new variable resolver

func (*VariableResolver) ResolveVariable

func (vr *VariableResolver) ResolveVariable(varPath string, execCtx *execcontext.ExecutionContext) (interface{}, error)

ResolveVariable resolves a variable path from the execution context

type VariableScope

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

VariableScope manages variable resolution

func NewVariableScope

func NewVariableScope(execCtx *execcontext.ExecutionContext) *VariableScope

NewVariableScope creates a new variable scope

func (*VariableScope) Get

func (vs *VariableScope) Get(name string) (Value, error)

Get retrieves a variable value

Jump to

Keyboard shortcuts

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