Skip to content

Commit

Permalink
hclwrite: Fix a bug that Block.open/close positions were not recorded…
Browse files Browse the repository at this point in the history
… in parser

While implementing Block.SetLabels(), I found a new hclwrite parser bug.

The NewBlock() method records positions of TokenOBrace / TokenCBrace.
Nevertheless when generating blocks via hclwrite.ParseConfig(),
they were not recorded.

The position of TokenOBrace is needed for Block.SetLabels(),
so I also fixed this existing bug.
  • Loading branch information
minamijoyo authored and apparentlymart committed Aug 21, 2020
1 parent c3cbe9a commit 143a545
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hclwrite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func parseBlock(nativeBlock *hclsyntax.Block, from, leadComments, lineComments,

before, oBrace, from := from.Partition(nativeBlock.OpenBraceRange)
children.AppendUnstructuredTokens(before.Tokens())
children.AppendUnstructuredTokens(oBrace.Tokens())
block.open = children.AppendUnstructuredTokens(oBrace.Tokens())

// We go a bit out of order here: we go hunting for the closing brace
// so that we have a delimited body, but then we'll deal with the body
Expand All @@ -342,7 +342,7 @@ func parseBlock(nativeBlock *hclsyntax.Block, from, leadComments, lineComments,
children.AppendNode(body)
children.AppendUnstructuredTokens(after.Tokens())

children.AppendUnstructuredTokens(cBrace.Tokens())
block.close = children.AppendUnstructuredTokens(cBrace.Tokens())

// stragglers
children.AppendUnstructuredTokens(from.Tokens())
Expand Down

0 comments on commit 143a545

Please sign in to comment.