procedure

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequiredType = cty.CapsuleWithOps("required", reflect.TypeOf(requiredMarker{}), &cty.CapsuleOps{})

RequiredType is the cty capsule type for the "required" sentinel.

View Source
var RequiredVal = cty.CapsuleVal(RequiredType, &requiredMarker{})

RequiredVal is the sentinel value that marks a procedure parameter as required.

Functions

func BuildFunction

func BuildFunction(spec *ProcSpec, stmts []Statement, evalCtxFn func() *hcl.EvalContext) function.Function

BuildFunction builds a cty/function.Function from the compiled procedure.

The cty function framework does not support optional parameters directly. We place only the required parameters in Spec.Params and use VarParam to capture any additional positional arguments (optional params + user-level variadic). The Impl closure then maps these back to parameter names, applying defaults for any that were not provided.

func ParamsEvalContext

func ParamsEvalContext() *hcl.EvalContext

ParamsEvalContext returns an EvalContext with the "required" sentinel bound, for use when evaluating parameter default expressions.

Types

type Assignment

type Assignment struct {
	Name     string
	Expr     hcl.Expression
	SrcRange hcl.Range
}

Assignment represents a variable assignment: name = expr

type Break

type Break struct {
	Condition hcl.Expression
	SrcRange  hcl.Range
}

Break represents a break statement: break = bool_expr

type Case

type Case struct {
	Value    hcl.Expression
	Body     []Statement
	SrcRange hcl.Range
}

Case is a single case within a switch, with a value expression and body.

type CondBranch

type CondBranch struct {
	Condition hcl.Expression
	Body      []Statement
	SrcRange  hcl.Range
}

CondBranch is a single branch (if or elif) with a condition and body.

type Continue

type Continue struct {
	Condition hcl.Expression
	SrcRange  hcl.Range
}

Continue represents a continue statement: continue = bool_expr

type IfChain

type IfChain struct {
	Branches []CondBranch // if + elif(s)
	Else     []Statement  // else body, nil if no else clause
	SrcRange hcl.Range
}

IfChain represents an if/elif/else conditional chain.

type ProcSpec

type ProcSpec struct {
	ParamNames    []string    // parameter names in source order
	ParamDefaults []cty.Value // parallel to ParamNames; cty.NilVal means required
	VariadicParam string      // empty if no variadic parameter
}

ProcSpec holds the parsed spec block information for a procedure.

func ParseSpec

func ParseSpec(body *hclsyntax.Body) (*ProcSpec, *hclsyntax.Body, hcl.Diagnostics)

ParseSpec extracts and parses the spec block from a procedure body. It returns the ProcSpec and the remaining body (with spec removed). If no spec block is present, returns an empty ProcSpec.

type Range

type Range struct {
	ItemName   string         // iteration variable name
	Collection hcl.Expression // parsed from label
	Body       []Statement
	SrcRange   hcl.Range
}

Range represents a range loop: range "item" "collection_expr" { ... }

type Return

type Return struct {
	Expr     hcl.Expression
	SrcRange hcl.Range
}

Return represents a return statement: return = expr

type Scope

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

Scope implements a chained variable scope for procedure execution. Variable lookup walks outward through the parent chain. Assignment to an existing name in any ancestor updates that ancestor; assignment to a new name creates it in the innermost scope.

func NewScope

func NewScope(parent *Scope) *Scope

NewScope creates a new scope with the given parent (may be nil for root).

func (*Scope) Get

func (s *Scope) Get(name string) (cty.Value, bool)

Get looks up a variable by walking the scope chain outward.

func (*Scope) Set

func (s *Scope) Set(name string, val cty.Value)

Set assigns a value to a variable. If the name already exists in any ancestor scope, that ancestor is updated. Otherwise the variable is created in this (innermost) scope. Discard names (starting with "_") are ignored.

func (*Scope) ToMap

func (s *Scope) ToMap() map[string]cty.Value

ToMap flattens the scope chain into a single map, with inner scopes taking precedence over outer ones.

type Signal

type Signal struct {
	Kind  SignalKind
	Value cty.Value // meaningful only for SignalReturn
}

Signal carries a control-flow signal up the call stack.

func Execute

func Execute(stmts []Statement, scope *Scope, parentCtx *hcl.EvalContext) (cty.Value, *Signal, hcl.Diagnostics)

Execute runs a compiled list of statements in the given scope. It returns the procedure result value and any signal that should propagate. If no return is encountered, the result is cty.NullVal(cty.DynamicPseudoType).

type SignalKind

type SignalKind int

SignalKind identifies the type of control-flow signal.

const (
	SignalNone     SignalKind = iota
	SignalReturn              // procedure exit with a value
	SignalBreak               // exit innermost loop
	SignalContinue            // skip to next loop iteration
)

type Statement

type Statement interface {
	// contains filtered or unexported methods
}

Statement is the interface implemented by all IR nodes.

func Compile

func Compile(body hcl.Body, filename string) ([]Statement, hcl.Diagnostics)

Compile compiles an HCL body (the procedure body after spec extraction) into an ordered list of IR statements.

type Switch

type Switch struct {
	Subject  hcl.Expression
	Cases    []Case
	Default  []Statement // nil if no default clause
	SrcRange hcl.Range
}

Switch represents a switch/case/default block.

type While

type While struct {
	Condition hcl.Expression
	Body      []Statement
	SrcRange  hcl.Range
}

While represents a while loop: while "condition" { ... }

Jump to

Keyboard shortcuts

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