Documentation
¶
Index ¶
- Variables
- func BuildFunction(spec *ProcSpec, stmts []Statement, evalCtxFn func() *hcl.EvalContext) function.Function
- func ParamsEvalContext() *hcl.EvalContext
- type Assignment
- type Break
- type Case
- type CondBranch
- type Continue
- type IfChain
- type ProcSpec
- type Range
- type Return
- type Scope
- type Signal
- type SignalKind
- type Statement
- type Switch
- type While
Constants ¶
This section is empty.
Variables ¶
var RequiredType = cty.CapsuleWithOps("required", reflect.TypeOf(requiredMarker{}), &cty.CapsuleOps{})
RequiredType is the cty capsule type for the "required" sentinel.
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.
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.
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.