2017-09-11 23:00:31 +00:00
|
|
|
package hcldec
|
2017-06-04 00:34:32 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-11 23:40:37 +00:00
|
|
|
"github.com/hashicorp/hcl2/hcl"
|
2017-06-04 00:34:32 +00:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
2017-09-11 23:40:37 +00:00
|
|
|
func decode(body hcl.Body, block *hcl.Block, 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
val, valDiags := spec.decode(content, block, ctx)
|
|
|
|
diags = append(diags, valDiags...)
|
|
|
|
|
|
|
|
return val, leftovers, diags
|
|
|
|
}
|
2017-06-04 15:13:36 +00:00
|
|
|
|
2017-09-11 23:40:37 +00:00
|
|
|
func sourceRange(body hcl.Body, block *hcl.Block, spec Spec) hcl.Range {
|
2017-06-04 15:13:36 +00:00
|
|
|
schema := ImpliedSchema(spec)
|
|
|
|
content, _, _ := body.PartialContent(schema)
|
|
|
|
|
|
|
|
return spec.sourceRange(content, block)
|
|
|
|
}
|