a9f913f830
This allows callers to determine the source location where a particular value (identified by a spec) came from, for use in application-level diagnostic messages.
33 lines
782 B
Go
33 lines
782 B
Go
package zcldec
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-zcl/zcl"
|
|
)
|
|
|
|
func decode(body zcl.Body, block *zcl.Block, ctx *zcl.EvalContext, spec Spec, partial bool) (cty.Value, zcl.Body, zcl.Diagnostics) {
|
|
schema := ImpliedSchema(spec)
|
|
|
|
var content *zcl.BodyContent
|
|
var diags zcl.Diagnostics
|
|
var leftovers zcl.Body
|
|
|
|
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
|
|
}
|
|
|
|
func sourceRange(body zcl.Body, block *zcl.Block, spec Spec) zcl.Range {
|
|
schema := ImpliedSchema(spec)
|
|
content, _, _ := body.PartialContent(schema)
|
|
|
|
return spec.sourceRange(content, block)
|
|
}
|