expression

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractExpressions

func ExtractExpressions(value string) ([]Span, []Error)

ExtractExpressions finds all ${{ ... }} expression spans in the given value. It returns the spans and any extraction-level errors (e.g. unterminated expressions).

func Parse

func Parse(input string) (Node, []Error)

Parse parses a GitHub Actions expression (the content between ${{ and }}). It returns the AST and any syntax errors found. On error, node is nil.

func Walk added in v0.5.0

func Walk(node Node, fn func(Node) bool)

Walk traverses the AST in pre-order. fn is called for each node. If fn returns false, the children of that node are not visited.

Types

type BinaryNode added in v0.5.0

type BinaryNode struct {
	Op     TokenKind
	Left   Node
	Right  Node
	Offset int
}

BinaryNode represents a binary operation (==, !=, &&, ||, <, <=, >, >=).

func (*BinaryNode) NodeOffset added in v0.5.0

func (n *BinaryNode) NodeOffset() int

type Error

type Error struct {
	Offset  int
	Message string
}

Error represents a syntax error at a specific offset within an expression.

type FilterNode added in v0.5.0

type FilterNode struct {
	Object Node
	Offset int
}

FilterNode represents a wildcard filter (e.g., steps.*.outcome).

func (*FilterNode) NodeOffset added in v0.5.0

func (n *FilterNode) NodeOffset() int

type FunctionCallNode added in v0.5.0

type FunctionCallNode struct {
	Name   string
	Args   []Node
	Offset int
}

FunctionCallNode represents a function call (e.g., contains(a, b)).

func (*FunctionCallNode) NodeOffset added in v0.5.0

func (n *FunctionCallNode) NodeOffset() int

type IdentNode added in v0.5.0

type IdentNode struct {
	Name   string
	Offset int
}

IdentNode represents a bare identifier (e.g., "github", "matrix").

func (*IdentNode) NodeOffset added in v0.5.0

func (n *IdentNode) NodeOffset() int

type IndexAccessNode added in v0.5.0

type IndexAccessNode struct {
	Object Node
	Index  Node
	Offset int
}

IndexAccessNode represents bracket access (e.g., matrix['os']).

func (*IndexAccessNode) NodeOffset added in v0.5.0

func (n *IndexAccessNode) NodeOffset() int

type LiteralNode added in v0.5.0

type LiteralNode struct {
	Kind   TokenKind
	Value  string
	Offset int
}

LiteralNode represents a literal value (string, int, float, true, false, null).

func (*LiteralNode) NodeOffset added in v0.5.0

func (n *LiteralNode) NodeOffset() int

type Node added in v0.5.0

type Node interface {
	NodeOffset() int
	// contains filtered or unexported methods
}

Node is the interface for all expression AST nodes. Every node carries an offset (byte position within the expression string).

type ParenNode added in v0.5.0

type ParenNode struct {
	Inner  Node
	Offset int
}

ParenNode represents a parenthesized expression.

func (*ParenNode) NodeOffset added in v0.5.0

func (n *ParenNode) NodeOffset() int

type PropertyAccessNode added in v0.5.0

type PropertyAccessNode struct {
	Object   Node
	Property string
	Offset   int
}

PropertyAccessNode represents dot access (e.g., github.actor).

func (*PropertyAccessNode) NodeOffset added in v0.5.0

func (n *PropertyAccessNode) NodeOffset() int

type Span

type Span struct {
	Start int
	End   int
	Inner string
}

Span represents a single ${{ ... }} expression found in a string value.

type Token

type Token struct {
	Kind   TokenKind
	Value  string
	Offset int
}

type TokenKind

type TokenKind int
const (
	TokenEOF TokenKind = iota
	TokenIdent
	TokenInt
	TokenFloat
	TokenString
	TokenTrue
	TokenFalse
	TokenNull
	TokenLParen
	TokenRParen
	TokenLBracket
	TokenRBracket
	TokenDot
	TokenStar
	TokenNot
	TokenLT
	TokenLE
	TokenGT
	TokenGE
	TokenEQ
	TokenNE
	TokenAnd
	TokenOr
	TokenComma
)

func (TokenKind) String

func (k TokenKind) String() string

type UnaryNode added in v0.5.0

type UnaryNode struct {
	Op      TokenKind
	Operand Node
	Offset  int
}

UnaryNode represents the unary ! operator.

func (*UnaryNode) NodeOffset added in v0.5.0

func (n *UnaryNode) NodeOffset() int

Jump to

Keyboard shortcuts

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