Skip to content

hclwrite: parse object-construct expressions#810

Open
bbasata wants to merge 7 commits into
hashicorp:mainfrom
bbasata:bbasata/parse-object-construct-expressions
Open

hclwrite: parse object-construct expressions#810
bbasata wants to merge 7 commits into
hashicorp:mainfrom
bbasata:bbasata/parse-object-construct-expressions

Conversation

@bbasata

@bbasata bbasata commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Description

Builds an AST for object-construct expressions such as:

a = {
    hat = "derby", (cat) = "calico" }

Given an hclwrite.Expression, an application can read an object value as:

object := expr.AsObjectConsExpr()
value := object.ValueFor("hat")

tokens := value.Expr().BuildTokens(nil)

Retrieval is based on matching a Go string to an HCL identifier. As an implementation choice, there is no way to retrieve the value for the variable expression (cat) at the time of this pull request.

#811 is a speculative pull request that builds on this one and introduces the capability to rewrite objects.

Related Issue

#695 and design notes from Martin in #695 (comment).

How Has This Been Tested?

hclwrite/parser_test.go

@bbasata bbasata requested a review from a team as a code owner June 17, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant