eval

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package eval is the total tree-walking evaluator for the Runefile expression sublanguage: it turns an ast.Expr into a string Value. It has no loops or recursion in the language itself (Principle III) — the only branching is the if/else conditional. Variable resolution consults task params first, then run-time overrides, then module assignments (FR-006).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinNames added in v0.3.0

func BuiltinNames() []string

BuiltinNames returns the sorted names of every built-in function. It is the authoritative set the language registry (internal/language) verifies itself against so completion/hover/validation never drift from evaluation (FR-027).

func IsBuiltin

func IsBuiltin(name string) bool

IsBuiltin reports whether name is a known built-in function. The analyzer uses this to flag unknown function calls statically.

Types

type Error

type Error struct {
	Span token.Span
	Msg  string
}

Error is an evaluation failure carrying a source span for diagnostics.

func (*Error) Error

func (e *Error) Error() string

type Evaluator

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

Evaluator walks expressions against a Scope.

func New

func New(scope *Scope) *Evaluator

New builds an Evaluator. The scope's host hooks default to the real host.

func (*Evaluator) Eval

func (e *Evaluator) Eval(expr ast.Expr) (string, *Error)

Eval evaluates an expression to its string value.

func (*Evaluator) Interpolate

func (e *Evaluator) Interpolate(raw string, baseSpan token.Span) (string, *Error)

Interpolate expands {{ expr }} placeholders in a body line's raw text using the evaluator. A literal "{{" is written as "{{{{" (and "}}" as "}}}}"). baseSpan locates the line for diagnostics; expression spans are approximate (anchored to the line) since body text is not pre-tokenized.

type Scope

type Scope struct {
	Params    map[string]string
	Overrides map[string]string
	Assigns   map[string]*ast.Assignment

	GOOS string
	Arch string

	Env func(string) (string, bool)
	Now func() string
	// contains filtered or unexported fields
}

Scope holds the bindings visible to an expression: task parameters, run-time overrides, and module-level assignments (evaluated lazily, with a cycle guard). Host hooks (env/os/arch/now) are injectable for deterministic tests.

func NewScope

func NewScope(assigns map[string]*ast.Assignment, overrides map[string]string) *Scope

NewScope builds a scope from module assignments and run-time overrides.

func (*Scope) WithParams

func (s *Scope) WithParams(params map[string]string) *Scope

WithParams returns a shallow copy of the scope with task params bound. The assignment cache is shared (assignments do not see params).

Jump to

Keyboard shortcuts

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