eval

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 ElementsKey added in v0.7.0

func ElementsKey(elems []string) string

ElementsKey encodes a list so that different elements never give the same text, which the space-joined value cannot promise. Run-once and the cache fingerprint share it so the two identities cannot drift apart.

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 Args added in v0.7.0

type Args struct {
	Values map[string]string
	Lists  map[string][]string
}

Args is one task invocation's bound parameters (spec 030 R1).

Values holds every parameter; a variadic's value is its elements joined by single spaces, the text every reader saw before spec 030. Lists holds the variadic's elements as given, which only quote_each, dependency forwarding, and invocation identity read.

Invariants:

  • For every key `k` in `Lists`, `Values[k] == strings.Join(Lists[k], " ")`, except on the dependency path, where `Values[k]` keeps the written arguments' joined text so an empty forwarded list next to other arguments leaves the extra space it always did.
  • `Lists` has at most one key.
  • `Lists[k]` may be empty only for a `*` parameter, or for a `+` parameter that a dependency call forwarded an empty list into.

func (Args) Key added in v0.7.0

func (a Args) Key() string

Key is a canonical encoding of both maps: equal keys mean the same values and the same elements. Every string is strconv-quoted so no value can forge a separator.

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
	// Lists holds the current invocation's variadic elements; only
	// quote_each reads it (spec 030).
	Lists     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) Fork added in v0.10.0

func (s *Scope) Fork() *Scope

Fork returns a scope with the same bindings and host hooks and its own assignment cache, which starts as a copy of s's. A variable first read through the fork is not cached in s, so a check made before a run cannot fix the value the run would read later (spec 050).

func (*Scope) WithArgs added in v0.7.0

func (s *Scope) WithArgs(a Args) *Scope

WithArgs returns a shallow copy of the scope with an invocation's bound arguments, elements included. 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