Please explain alternate (repeating blocks) array syntax
- Dominant language
- Go
- Stars
- 5.8k
- Forks
- 657
- Avg merge
- 20h 36m
- Merged PRs (30d)
- 6
Description
Hello. Thanks for great config language, I loved it from Terraform and surely wanted to use HCL everywhere for nice syntax and available autoformat tool.
Please explain middle string token in alternate array syntax.
### HCL Template
```hcl
// Wrong, combination explosion
item { code = 1 text = "first" }
item { code = 2 text = "second" }
// Correct using "nominal" syntax
item = [
{ code = 1 text = "first" },
{ code = 2 text = "second" },
]
// Correct using alternate syntax with string token which I don't understand
item "what is this?" { code = 1 text = "first" }
item "where does it go?" { code = 2 text = "second" }
```
### Expected behavior
This is expected and produced by `item = []` and also by `item "string" {}`
```
- &MenuItem{Code:1, Text:"first"}
- &MenuItem{Code:2, Text:"second"}
```
### Actual behavior
Produced by `item {...} item {...}`
```
- &MenuItem{Code:1, Text:""}
- &MenuItem{Code:0, Text:"first"}
- &MenuItem{Code:2, Text:""}
- &MenuItem{Code:0, Text:"second"}
```
### Code
```go
package main
import (
"github.com/hashicorp/hcl"
"log"
)
type Config struct {
Items []MenuItem `hcl:"item"`
}
type MenuItem struct {
Code int `hcl:"code"`
Text string `hcl:"text"`
}
const testContent = `
// Wrong, combination explosion
item { code = 1 text = "first" }
item { code = 2 text = "second" }
`
func main() {
c := new(Config)
if err := hcl.Unmarshal([]byte(testContent), c); err != nil {
log.Fatal(err)
}
for _, item := range c.Menu.Items {
log.Printf("- %#v", item)
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Read the HCL syntax documentation and run the Go reproducer included in the issue, comparing the repeated-block and array forms. Done means the documentation clearly explains the purpose and destination of the string token in alternate syntax and distinguishes it from repeated blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100