hclexpr

package
v1.8.0 Latest Latest
Warning

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

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

Documentation

Overview

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinaryOpSymbol added in v0.0.5

func BinaryOpSymbol(op *hclsyntax.Operation) string

BinaryOpSymbol returns the HCL operator symbol for a binary operation (e.g. "+", "==").

func Dispatch

func Dispatch[T any](expr hclsyntax.Expression, v Visitor[T]) (T, error)

Dispatch unwraps expr then dispatches to the appropriate Visitor method. Add new expression types here (or in dispatchComposite) and to the Visitor interface so all sites stay in sync. The dispatch is split across two functions purely to keep each below the cyclomatic complexity limit.

func UnaryOpSymbol added in v0.0.5

func UnaryOpSymbol(op *hclsyntax.Operation) string

UnaryOpSymbol returns the HCL operator symbol for a unary operation (e.g. "-", "!").

func Unwrap

Unwrap returns the inner expression for wrapper types (TemplateWrapExpr, ParenthesesExpr, ObjectConsKeyExpr). For other expression types, returns expr unchanged. Callers can use this before their own type switch so wrapper handling is centralized.

Types

type Visitor

type Visitor[T any] interface {
	VisitLiteralValue(e *hclsyntax.LiteralValueExpr) (T, error)
	VisitTemplateExpr(e *hclsyntax.TemplateExpr) (T, error)
	VisitScopeTraversal(e *hclsyntax.ScopeTraversalExpr) (T, error)
	VisitIndexExpr(e *hclsyntax.IndexExpr) (T, error)
	VisitRelativeTraversal(e *hclsyntax.RelativeTraversalExpr) (T, error)
	VisitFunctionCall(e *hclsyntax.FunctionCallExpr) (T, error)
	VisitConditional(e *hclsyntax.ConditionalExpr) (T, error)
	VisitTupleCons(e *hclsyntax.TupleConsExpr) (T, error)
	VisitObjectCons(e *hclsyntax.ObjectConsExpr) (T, error)
	VisitTemplateJoin(e *hclsyntax.TemplateJoinExpr) (T, error)
	VisitBinaryOp(e *hclsyntax.BinaryOpExpr) (T, error)
	VisitUnaryOp(e *hclsyntax.UnaryOpExpr) (T, error)
	VisitForExpr(e *hclsyntax.ForExpr) (T, error)
	VisitSplatExpr(e *hclsyntax.SplatExpr) (T, error)
	// VisitAnonSymbol handles the synthetic placeholder for the current item
	// inside a splat's Each expression (e.g. the item in var.list[*].id).
	VisitAnonSymbol(e *hclsyntax.AnonSymbolExpr) (T, error)
	// VisitExprSyntaxError handles the placeholder produced for invalid or
	// incomplete expressions that could not be parsed.
	VisitExprSyntaxError(e *hclsyntax.ExprSyntaxError) (T, error)
	VisitDefault(e hclsyntax.Expression) (T, error)
}

Visitor is the interface for handling each HCL expression type in one place. Implement this interface for each dispatch site (engine, inspector, modules, converter). Adding a new expression type: add a method here and a case in Dispatch below.

Jump to

Keyboard shortcuts

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