A single json object with nested objects is flattened by the json parser
to a list of objects sharing the parent key. If we're decoding into
struct this was likely a mistake, and we need to re-expand the ast.
It was unclear how nested object example in hcl would map to json.
README now updated to include an example of the son equivalent
to a hcl nested object.
At some point we ignored the " in interpolations. We do this for HCL and
it is correct but this is invalid JSON syntax and for JSON we've always
had the stance that we have to escape them.
The way the scanner works '/ foo' was actually valid comment syntax.
This obviously is not what we want. This modifies the scanner to verify
that '//' comments in fact have the second '/'.
When decoding an object into a struct where the object structure doesn't
match the Go struct structure, the case tested here would panic. This
introduces additional checks to guard against the edge case being hit to
avoid the panic.
The specific checks being added are: if an item being decoded into a
struct is a literal type, the item to be decoded must be non-nil in
order to use it. This isn't super clear and to be honest I also don't
fully understand it but this fixes the problem without introducing any
more test failures and without significant code complexity.
This allows multiline strings to be parsed in order to make HIL
interpolations nicer in Terraform:
```
my_complex_thing = "${merge(var.list1,
var.list2,
var.list3)}"
```
a.k.a lists of maps
Implementation was pretty straightforward - I had to tweak the `needsComma`
handling since it was stuck inside literal parsing. It happens out front
now. I also promoted the `assign_deep.hcl` parser test to a decoder
test that passes, since it was testing for an error to occur but now it
works! :)
Additionally we make ObjectLists support being comma-delimited, which
enables maps to defined inline like `{one = 1, two = 2}`.
Refs https://github.com/hashicorp/terraform/issues/7142
When we switched to the current edition of the HCL parser, we
inadvertently broke some undocumented behavior where users could
successfully used escaped double quotes in a nested interpolation like
this:
foo = "${somefunc(\"somearg\")}"
The proper syntax here is:
foo = "${somefunc("somearg")}"
Because once you are inside the interpolation braces, the "quoting
context" is different.
At the time, while we didn't like the fact that the non-standard syntax
was in the wild, we didn't want to break BC, so we treated it as a bug
and fixed it in #62.
Now that we are at the moment of a major Terraform release, we can yank
the BC compatible behavior, which fixes a currently broken use case -
there is no way to express strings with double quotes in them from
inside interpolation braces.
foo = "${somefunc("\"inquotes\"")}"
After merge and a dep upgrade, this will take care of
https://github.com/hashicorp/terraform/issues/5550
Fixes https://github.com/hashicorp/terraform/issues/6359 and several
related issues by unescaping a double backslash within braces to a
single backslash.
This bumps into the bit of HIL that still hangs out in HCL - for values
that aren't interpolated, like Terraform's variable defaults - users
were unable to get a backslash to show up within `${}`.
That's because `${}` is handled specially to allow for, e.g., double
quotes inside of braces.
Here, we add `\\` as a special cased escape (along with `\"`) so users
can get backslashes in these scenarios by doubling them up.
The fmtcmd tests weren't running before due to the same build tag
problem as #112, so didn't catch the fact that there was an extra
newline being added here, which is now doubled thanks to #112.
Fixing up the build tag reveals failing tests - removing the extra
newline fixes the tests.
Noticed that the `hclfmt` tool (which uses hcl/printer) was chomping
the trailing newline from config files.
Here we switch to the more conventional newline-at-EOF output.
In the process of changing this, I realized that:
* The printer_test.go build tag was wrong, so it wasn't running
* The format() test helper was not exercising Format
So both of those fixes are included here