0d6247f4cf
A BlockLabelSpec can be placed in the nested spec structure of one of the block specs to require and obtain labels on that block. This is a more generic methodology than BlockMapSpec since it allows the result to be a list or set with the labels inside the values, rather than forcing all the label tuples to be unique and losing the ordering by collapsing into a map structure.
22 lines
353 B
Go
22 lines
353 B
Go
package hcldec
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl2/hcl"
|
|
)
|
|
|
|
type blockLabel struct {
|
|
Value string
|
|
Range hcl.Range
|
|
}
|
|
|
|
func labelsForBlock(block *hcl.Block) []blockLabel {
|
|
ret := make([]blockLabel, len(block.Labels))
|
|
for i := range block.Labels {
|
|
ret[i] = blockLabel{
|
|
Value: block.Labels[i],
|
|
Range: block.LabelRanges[i],
|
|
}
|
|
}
|
|
return ret
|
|
}
|