json: remove non-functional HIL parsing functions
An earlier iteration of this package was able to optionally use HIL as its expression engine in place of the hclsyntax expression parser, but this has since been removed and so this flag no longer has any effect. Consequently, the public functions ParseWithHIL and ParseFileWithHIL were, in fact, just using the zclsyntax parser and thus behaving identically to the Parse and ParseFile functions.
This commit is contained in:
parent
34e27c038a
commit
678f7e6781
@ -88,28 +88,3 @@ func ParseFile(filename string) (*hcl.File, hcl.Diagnostics) {
|
|||||||
|
|
||||||
return Parse(src, filename)
|
return Parse(src, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseWithHIL is like Parse except the returned file will use the HIL
|
|
||||||
// template syntax for expressions in strings, rather than the native zcl
|
|
||||||
// template syntax.
|
|
||||||
//
|
|
||||||
// This is intended for providing backward compatibility for applications that
|
|
||||||
// used to use HCL/HIL and thus had a JSON-based format with HIL
|
|
||||||
// interpolations.
|
|
||||||
func ParseWithHIL(src []byte, filename string) (*hcl.File, hcl.Diagnostics) {
|
|
||||||
file, diags := Parse(src, filename)
|
|
||||||
if file != nil && file.Body != nil {
|
|
||||||
file.Body.(*body).useHIL = true
|
|
||||||
}
|
|
||||||
return file, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseFileWithHIL is like ParseWithHIL but it reads data from a file before
|
|
||||||
// parsing it.
|
|
||||||
func ParseFileWithHIL(filename string) (*hcl.File, hcl.Diagnostics) {
|
|
||||||
file, diags := ParseFile(filename)
|
|
||||||
if file != nil && file.Body != nil {
|
|
||||||
file.Body.(*body).useHIL = true
|
|
||||||
}
|
|
||||||
return file, diags
|
|
||||||
}
|
|
||||||
|
@ -95,30 +95,3 @@ func TestParseTemplateUnwrap(t *testing.T) {
|
|||||||
t.Errorf("wrong result %#v; want %#v", val, cty.True)
|
t.Errorf("wrong result %#v; want %#v", val, cty.True)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseTemplateWithHIL(t *testing.T) {
|
|
||||||
src := `{"greeting": "hello ${\"world\"}"}`
|
|
||||||
file, diags := ParseWithHIL([]byte(src), "")
|
|
||||||
if len(diags) != 0 {
|
|
||||||
t.Errorf("got %d diagnostics on parse; want 0", len(diags))
|
|
||||||
}
|
|
||||||
if file == nil {
|
|
||||||
t.Errorf("got nil File; want actual file")
|
|
||||||
}
|
|
||||||
if file.Body == nil {
|
|
||||||
t.Fatalf("got nil Body; want actual body")
|
|
||||||
}
|
|
||||||
attrs, diags := file.Body.JustAttributes()
|
|
||||||
if len(diags) != 0 {
|
|
||||||
t.Errorf("got %d diagnostics on decode; want 0", len(diags))
|
|
||||||
}
|
|
||||||
|
|
||||||
val, diags := attrs["greeting"].Expr.Value(&hcl.EvalContext{})
|
|
||||||
if len(diags) != 0 {
|
|
||||||
t.Errorf("got %d diagnostics on eval; want 0", len(diags))
|
|
||||||
}
|
|
||||||
|
|
||||||
if !val.RawEquals(cty.StringVal("hello world")) {
|
|
||||||
t.Errorf("wrong result %#v; want %#v", val, cty.StringVal("hello world"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,12 +17,6 @@ type body struct {
|
|||||||
// be treated as non-existing. This is used when Body.PartialContent is
|
// be treated as non-existing. This is used when Body.PartialContent is
|
||||||
// called, to produce the "remaining content" Body.
|
// called, to produce the "remaining content" Body.
|
||||||
hiddenAttrs map[string]struct{}
|
hiddenAttrs map[string]struct{}
|
||||||
|
|
||||||
// If set, string values are turned into expressions using HIL's template
|
|
||||||
// language, rather than the native zcl language. This is intended to
|
|
||||||
// allow applications moving from HCL to zcl to continue to parse the
|
|
||||||
// JSON variant of their config that HCL handled previously.
|
|
||||||
useHIL bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// expression is the implementation of "Expression" used for files processed
|
// expression is the implementation of "Expression" used for files processed
|
||||||
@ -133,7 +127,6 @@ func (b *body) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Bod
|
|||||||
unusedBody := &body{
|
unusedBody := &body{
|
||||||
obj: b.obj,
|
obj: b.obj,
|
||||||
hiddenAttrs: usedNames,
|
hiddenAttrs: usedNames,
|
||||||
useHIL: b.useHIL,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return content, unusedBody, diags
|
return content, unusedBody, diags
|
||||||
@ -219,8 +212,7 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *hcl.Range, labels
|
|||||||
Type: typeName,
|
Type: typeName,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Body: &body{
|
Body: &body{
|
||||||
obj: tv,
|
obj: tv,
|
||||||
useHIL: b.useHIL,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
DefRange: tv.OpenRange,
|
DefRange: tv.OpenRange,
|
||||||
@ -245,8 +237,7 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *hcl.Range, labels
|
|||||||
Type: typeName,
|
Type: typeName,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Body: &body{
|
Body: &body{
|
||||||
obj: ov,
|
obj: ov,
|
||||||
useHIL: b.useHIL,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
DefRange: tv.OpenRange,
|
DefRange: tv.OpenRange,
|
||||||
|
Loading…
Reference in New Issue
Block a user