vm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 16 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 interface{}) (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 or any of the parent scopes, Evaluate will return an error.

type Scope

type Scope struct {
	// Parent optionally points to a parent Scope containing more variable.
	// Variables defined in children scopes take precedence over variables of the
	// same name found in parent scopes.
	Parent *Scope

	// 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]interface{}
}

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

func (*Scope) Lookup

func (s *Scope) Lookup(name string) (interface{}, bool)

Lookup looks up a named identifier from the scope, all of the scope's parents, and the stdlib.

Jump to

Keyboard shortcuts

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