aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcldec/schema.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcldec/schema.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hcldec/schema.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcldec/schema.go b/vendor/github.com/hashicorp/hcl2/hcldec/schema.go
new file mode 100644
index 0000000..b57bd96
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/hcldec/schema.go
@@ -0,0 +1,36 @@
1package hcldec
2
3import (
4 "github.com/hashicorp/hcl2/hcl"
5)
6
7// ImpliedSchema returns the *hcl.BodySchema implied by the given specification.
8// This is the schema that the Decode function will use internally to
9// access the content of a given body.
10func ImpliedSchema(spec Spec) *hcl.BodySchema {
11 var attrs []hcl.AttributeSchema
12 var blocks []hcl.BlockHeaderSchema
13
14 // visitSameBodyChildren walks through the spec structure, calling
15 // the given callback for each descendent spec encountered. We are
16 // interested in the specs that reference attributes and blocks.
17 var visit visitFunc
18 visit = func(s Spec) {
19 if as, ok := s.(attrSpec); ok {
20 attrs = append(attrs, as.attrSchemata()...)
21 }
22
23 if bs, ok := s.(blockSpec); ok {
24 blocks = append(blocks, bs.blockHeaderSchemata()...)
25 }
26
27 s.visitSameBodyChildren(visit)
28 }
29
30 visit(spec)
31
32 return &hcl.BodySchema{
33 Attributes: attrs,
34 Blocks: blocks,
35 }
36}