2017-09-11 23:00:31 +00:00
|
|
|
package hcldec
|
2017-06-04 00:34:32 +00:00
|
|
|
|
|
|
|
import (
|
2019-09-09 23:08:19 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2017-06-04 00:34:32 +00:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
2017-10-03 22:59:20 +00:00
|
|
|
func decode(body hcl.Body, blockLabels []blockLabel, ctx *hcl.EvalContext, spec Spec, partial bool) (cty.Value, hcl.Body, hcl.Diagnostics) {
|
2017-06-04 00:34:32 +00:00
|
|
|
schema := ImpliedSchema(spec)
|
|
|
|
|
2017-09-11 23:40:37 +00:00
|
|
|
var content *hcl.BodyContent
|
|
|
|
var diags hcl.Diagnostics
|
|
|
|
var leftovers hcl.Body
|
2017-06-04 00:34:32 +00:00
|
|
|
|
|
|
|
if partial {
|
|
|
|
content, leftovers, diags = body.PartialContent(schema)
|
|
|
|
} else {
|
|
|
|
content, diags = body.Content(schema)
|
|
|
|
}
|
|
|
|
|
2017-10-03 22:59:20 +00:00
|
|
|
val, valDiags := spec.decode(content, blockLabels, ctx)
|
2017-06-04 00:34:32 +00:00
|
|
|
diags = append(diags, valDiags...)
|
|
|
|
|
|
|
|
return val, leftovers, diags
|
|
|
|
}
|
2017-06-04 15:13:36 +00:00
|
|
|
|
2017-10-03 23:27:34 +00:00
|
|
|
func impliedType(spec Spec) cty.Type {
|
|
|
|
return spec.impliedType()
|
|
|
|
}
|
|
|
|
|
2017-10-03 22:59:20 +00:00
|
|
|
func sourceRange(body hcl.Body, blockLabels []blockLabel, spec Spec) hcl.Range {
|
2017-06-04 15:13:36 +00:00
|
|
|
schema := ImpliedSchema(spec)
|
|
|
|
content, _, _ := body.PartialContent(schema)
|
|
|
|
|
2017-10-03 22:59:20 +00:00
|
|
|
return spec.sourceRange(content, blockLabels)
|
2017-06-04 15:13:36 +00:00
|
|
|
}
|