Help us shape the future of Go! Take the 2026 Go Developer Survey

expression

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExpressionPattern = regexp.MustCompile(`\$\{\{\s*(.*?)\s*\}\}`)

ExpressionPattern matches ${{ ... }} expressions

Functions

func ContainsExpression

func ContainsExpression(input string) bool

ContainsExpression checks if a string contains any expressions

func ExtractExpressions

func ExtractExpressions(input string) []string

ExtractExpressions returns all expression strings from input

func ReplaceExpressions

func ReplaceExpressions(input string, replacer func(expr string) (string, error)) (string, error)

ReplaceExpressions replaces all expressions in a string using a replacement function

Types

type Context

type Context struct {
	Event            map[string]interface{}
	Env              map[string]string
	Steps            map[string]StepContext
	Functions        map[string]Function
	ContextFunctions map[string]ContextFunction
}

Context holds the evaluation context for expressions

func NewContext

func NewContext() *Context

NewContext creates a new evaluation context

func (*Context) Evaluate

func (ctx *Context) Evaluate(expr string) (interface{}, error)

Evaluate evaluates an expression string against the context

func (*Context) EvaluateBool

func (ctx *Context) EvaluateBool(expr string) (bool, error)

EvaluateBool evaluates an expression and returns a boolean result

func (*Context) EvaluateString

func (ctx *Context) EvaluateString(input string) (string, error)

EvaluateString evaluates an expression and returns a string result

type ContextFunction

type ContextFunction func(ctx *Context, args ...interface{}) (interface{}, error)

ContextFunction represents a built-in function that needs context access

type Expression

type Expression struct {
	Raw    string  // Original expression string
	Tokens []Token // Parsed tokens
}

Expression represents a parsed expression

func Parse

func Parse(input string) ([]Expression, error)

Parse extracts and parses expressions from a string Returns the original string with expression placeholders and a map of expressions

type Function

type Function func(args ...interface{}) (interface{}, error)

Function represents a built-in function

type StepContext

type StepContext struct {
	Outputs map[string]string
	Outcome string // success, failure, cancelled, skipped
}

StepContext holds the output of a previous step

type Token

type Token struct {
	Type  TokenType
	Value string
}

Token represents a parsed token in an expression

type TokenType

type TokenType int

TokenType identifies the type of token

const (
	TokenLiteral TokenType = iota
	TokenIdentifier
	TokenNumber
	TokenString
	TokenOperator
	TokenLeftParen
	TokenRightParen
	TokenLeftBracket
	TokenRightBracket
	TokenDot
	TokenComma
	TokenEOF
)

Jump to

Keyboard shortcuts

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