vm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package vm provides an Alloy syntax expression evaluator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

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

Evaluator evaluates Alloy syntax AST nodes into Go values. Each Evaluator is bound to a single AST node. To evaluate the node, call Evaluate.

func New

func New(node ast.Node) *Evaluator

New creates a new Evaluator for the given AST node. The given node must be either an *ast.File, *ast.BlockStmt, ast.Body, or assignable to an ast.Expr.

func (*Evaluator) Evaluate

func (vm *Evaluator) Evaluate(scope *Scope, v any) (err error)

Evaluate evaluates the Evaluator's node into a Alloy syntax value and decodes that value into the Go value v.

Each call to Evaluate may provide a different scope with new values for available variables. If a variable used by the Evaluator's node isn't defined in scope, Evaluate will return an error.

type Scope

type Scope struct {
	// Variables holds the list of available variable names that can be used when
	// evaluating a node.
	//
	// Values in the Variables map should be considered immutable after passed to
	// Evaluate; maps and slices will be copied by reference for performance
	// optimizations.
	Variables map[string]any
}

A Scope exposes a set of variables available to use during evaluation.

func NewScope added in v0.1.1

func NewScope(variables map[string]any) *Scope

func (*Scope) IsStdlibDeprecated added in v0.1.1

func (s *Scope) IsStdlibDeprecated(name string) bool

IsStdlibDeprecated returns true if the identifier exists and is deprecated.

func (*Scope) IsStdlibExperimental added in v0.1.1

func (s *Scope) IsStdlibExperimental(fullName string) bool

IsStdlibExperimental returns true if the scoped identifier is experimental.

func (*Scope) IsStdlibIdentifiers added in v0.1.1

func (s *Scope) IsStdlibIdentifiers(name string) bool

IsStdlibIdentifiers returns true if the identifier exists.

func (*Scope) Lookup

func (s *Scope) Lookup(name string) (any, bool)

Lookup looks up a named identifier from the scope and the stdlib.

Jump to

Keyboard shortcuts

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