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:
Martin Atkins 2018-01-27 09:15:53 -08:00
parent 34e27c038a
commit 678f7e6781
3 changed files with 2 additions and 63 deletions

View File

@ -88,28 +88,3 @@ func ParseFile(filename string) (*hcl.File, hcl.Diagnostics) {
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
}

View File

@ -95,30 +95,3 @@ func TestParseTemplateUnwrap(t *testing.T) {
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"))
}
}

View File

@ -17,12 +17,6 @@ type body struct {
// be treated as non-existing. This is used when Body.PartialContent is
// called, to produce the "remaining content" Body.
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
@ -133,7 +127,6 @@ func (b *body) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Bod
unusedBody := &body{
obj: b.obj,
hiddenAttrs: usedNames,
useHIL: b.useHIL,
}
return content, unusedBody, diags
@ -220,7 +213,6 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *hcl.Range, labels
Labels: labels,
Body: &body{
obj: tv,
useHIL: b.useHIL,
},
DefRange: tv.OpenRange,
@ -246,7 +238,6 @@ func (b *body) unpackBlock(v node, typeName string, typeRange *hcl.Range, labels
Labels: labels,
Body: &body{
obj: ov,
useHIL: b.useHIL,
},
DefRange: tv.OpenRange,