Commit Graph

1158 Commits

Author SHA1 Message Date
Martin Atkins
3c57e14932
Update CHANGELOG.md 2020-08-21 11:37:10 -07:00
Martin Atkins
7d8f0ff870 hclwrite: Make block labels a node in their own right
All of the other subdivisions of a block were already nodes, but we'd
represented the labels as an undifferentiated set of nodes belonging
directly to the block's child node list.

Now that we support replacing the labels in the public API, that's a good
excuse to refactor this slightly to make the labels their own node. As
well as being consistent with everything else in Block, this also makes
it easier to implement the Block.SetLabels operation because we can
just  change the children of the labels node, rather than having to
carefully identify and extract the individual child nodes of the block
that happen to represent labels.

Internally this models the labels in a similar sort of way as the content
of a body, although we've kept the public API directly on the Block type
here because that's a more straightforward model for the use-cases we
currently know and matches better with the API of hcl.Block. This is just
an internal change for consistency.

I also added a few tests for having comments interspersed with labels
while I was here, because that helped to better exercise the new
parseBlockLabels function.
2020-08-21 11:30:32 -07:00
Masayuki Morita
143a545916 hclwrite: Fix a bug that Block.open/close positions were not recorded in parser
While implementing Block.SetLabels(), I found a new hclwrite parser bug.

The NewBlock() method records positions of TokenOBrace / TokenCBrace.
Nevertheless when generating blocks via hclwrite.ParseConfig(),
they were not recorded.

The position of TokenOBrace is needed for Block.SetLabels(),
so I also fixed this existing bug.
2020-08-21 11:30:32 -07:00
Masayuki Morita
c3cbe9a9e2 hclwrite: Allow updating block type and labels
Fixes #338

Add methods to update block type and labels to enable us to refactor HCL
configurations such as renaming Terraform resources.

- `*Block.SetType(typeName string)`
- `*Block.SetLabels(labels []string)`

Some additional notes about SetLabels:

Since we cannot assume that old and new labels are equal in length,
remove old labels and insert new ones before TokenOBrace.

To implement this, I also added the following methods.

- `*nodes.Insert(pos *node, c nodeContent) *node`
- `*nodes.InsertNode(pos *node, n *node) *node`

They are similar to the existing Append / AppendNode,
but insert a node before a given position.
2020-08-21 11:30:32 -07:00
Alisdair McDiarmid
ea60f7f2a6
Merge pull request #380 from minamijoyo/fix-bitwise-or-error
Fix a wrong error message for bitwise OR
2020-06-25 15:07:25 -04:00
Chris Marchesi
350d663f3c
v2.6.0 release 2020-06-04 14:36:42 -07:00
Chris Marchesi
7ebdbcbe97
Formatting change on CHANGELOG.md 2020-06-04 14:35:53 -07:00
Chris Marchesi
b6a2b60e17
Update CHANGELOG.md 2020-06-04 14:34:21 -07:00
Chris Marchesi
919ba77aeb
Merge pull request #387 from hashicorp/hcldec-add-validatefuncspec
hcldec: add ValidateSpec
2020-06-04 14:27:47 -07:00
Chris Marchesi
9c4784b144
hcldec: add ValidateSpec
This adds ValidateSpec, a new decoder Spec that allows one to add
custom validations to work with values at decode-time.

The validation is run on the value after the wrapped spec is applied to
the expression in question. Diagnostics are expected to be returned,
with the author having flexibility over whether or not they want to
specify a range; if one is not supplied, the range of the wrapped
expression is used.
2020-06-04 14:25:45 -07:00
Kristin Laemmert
92a27b785a
Update CHANGELOG.md 2020-06-03 12:31:34 -04:00
Kristin Laemmert
47e2447d3f
Merge pull request #386 from hashicorp/mildwonkey/b-null-seq-panic
hclsyntax: address multiple issues with sequences (...)
2020-06-03 11:16:17 -04:00
Kristin Laemmert
3733856456 pr feedback: check for null first argument 2020-06-03 09:50:50 -04:00
Kristin Laemmert
1f97062183 hclsyntax: return cty.DynamicVal when encountering (...) and unknown
vals
2020-06-03 09:33:38 -04:00
Kristin Laemmert
d9969e8731 hclsyntax: do not panic when encountering a null + sequence (...)
Previously functions such as concat() would result in a panic if there
was a null element and a sequence, as in the included test. This PR adds
a check if the error index is outside of the range of arguments and
crafts an error that references the entire function instead of the null
argument.
2020-06-03 09:13:36 -04:00
Radek Simko
a20a69ce16 Merge pull request #317 from minamijoyo/fix-typos-in-hclwrite-parser
Fix typos in hclwrite/parser.go
2020-05-27 10:35:22 +01:00
Radek Simko
92aa0d1272 Merge pull request #345 from pratikmallya/fix-typo
FIX: a couple of minor typos
2020-05-27 10:34:17 +01:00
Masayuki Morita
04e412a99b Fix a wrong error message for bitwise OR
Fixes #376
2020-05-21 10:12:28 +09:00
Alisdair McDiarmid
50eda8bd0c
Merge pull request #377 from hashicorp/alisdair/hclwrite-fuzz
hclwrite: Add fuzz testing
2020-05-15 08:48:44 -04:00
Alisdair McDiarmid
e899db5b9f Update other fuzz docs for consistency 2020-05-14 15:03:29 -04:00
Alisdair McDiarmid
b5f1f971b4 hclwrite: Add fuzz testing 2020-05-14 15:03:29 -04:00
Alisdair McDiarmid
148b442e04
v2.5.1 release 2020-05-14 09:33:42 -04:00
Alisdair McDiarmid
80755673bc
v2.5.1 release 2020-05-14 09:33:09 -04:00
Alisdair McDiarmid
20b8095b08
Merge pull request #374 from hashicorp/alisdair/hclwrite-splat
hclwrite: Fix panic for dotted full splat (foo.*)
2020-05-14 09:23:05 -04:00
Alisdair McDiarmid
d58c873a08 hclwrite: Fix panic for dotted full splat (foo.*)
The following expression caused a panic in hclwrite:

  a = foo.*

This was due to the unusual dotted form of a full splat (where the splat
operator is at the end of the expression) being generated with an
invalid source range. In the full splat case, the end of the range was
uninitialized, which caused the token slice to be empty, and thus the
panic.

This commit fixes the bug, adds test coverage, and includes some bonus
tests for other splat expression cases.
2020-05-13 16:23:21 -04:00
Alisdair McDiarmid
fff0a094cc
Merge pull request #369 from bendrucker/hclwriter-numeric-dot
hclwrite: handle legacy dot access of numeric indexes
2020-05-13 16:05:28 -04:00
Alisdair McDiarmid
332f42681b
Prepare CHANGELOG for forthcoming v2.6.0 release 2020-05-06 13:33:34 -04:00
Alisdair McDiarmid
b35ebdc330
v2.5.0 release 2020-05-06 13:31:39 -04:00
Alisdair McDiarmid
60bf88b2b7
Merge pull request #372 from hashicorp/format-objects-maps-on-multiple-lines
hclwrite: Generate multi-line objects and maps
2020-05-06 13:29:44 -04:00
Alisdair McDiarmid
926e53e338 hclwrite: Generate multi-line objects and maps
The previous syntax for object and map values was a single line of
key-value pairs. For example:

  object = { bar = 5, baz = true, foo = "foo" }

This is very compact, but in practice for many HCL values, less readable
and less common than a multi-line object format. This commit changes the
generated output from hclwrite to one line per attribute.

Examples of the new format:

  // Empty object/map is a single line
  a = {}

  // Single-value object/map has the attribute on a separate line
  b = {
    bar = 5
  }

  // Multi-value object/map has one line per attribute
  c = {
    bar = 5
    baz = true
  }
2020-05-06 09:45:13 -04:00
Ben Drucker
8e720e092f add for 'foo[bar.baz]' 2020-04-28 21:08:43 -07:00
Ben Drucker
8e04c38ebf hclwrite: handle legacy dot access of numeric indexes 2020-04-28 20:38:45 -07:00
Alisdair McDiarmid
7098edec61 Fix CircleCI config 2020-04-15 15:16:44 -04:00
Alisdair McDiarmid
10b94c0a94 Revert "Remove AppVeyor"
This reverts commit cc3d78637c.
2020-04-15 14:55:33 -04:00
Alisdair McDiarmid
4e0b10461f Run CircleCI builds for hcl2 branch 2020-04-15 14:53:48 -04:00
Alisdair McDiarmid
cc3d78637c Remove AppVeyor 2020-04-15 14:52:35 -04:00
Alisdair McDiarmid
f27fc87d8f
Prepare CHANGELOG for forthcoming v2.5.0 release 2020-04-13 10:39:45 -04:00
Alisdair McDiarmid
70cdf594dd
v2.4.0 release 2020-04-13 10:37:38 -04:00
Pam Selle
be7ce64449
Update changelog typo 2020-04-09 14:30:10 -04:00
Alisdair McDiarmid
bcf199a15f
Update CHANGELOG.md 2020-03-26 09:00:05 -04:00
Alisdair McDiarmid
08f5f12a13
Merge pull request #358 from hashicorp/alisdair/fix-malformed-json-panic
json: Fix panic when parsing malformed JSON
2020-03-26 08:58:29 -04:00
Alisdair McDiarmid
b265bbd046 json: Fix panic when parsing malformed JSON
When scanning JSON, upon encountering an invalid token, we immediately
return. Previously this return happened without inserting an EOF token.
Since other functions assume that a token sequence always ends in EOF,
this could cause a panic.

This commit adds a synthetic EOF token after the invalid token before
returning. While this does not match the real end-of-file of the source
JSON, it is marking the end of the scanned bytes, so it seems reasonable.

Fixes #339
2020-03-25 16:40:36 -04:00
Martin Atkins
cda5e9cf34
Update CHANGELOG.md 2020-03-09 09:18:44 -07:00
Martin Atkins
fee90926da Use Unicode 12.0.0 grapheme cluster segmentation rules
HCL uses grapheme cluster segmentation to produce accurate "column"
indications in diagnostic messages and other human-oriented source
location information. Each new major version of Unicode introduces new
codepoints, some of which are defined to combine with other codepoints to
produce a single visible character (grapheme cluster).

We were previously using the rules from Unicode 9.0.0. This change
switches to using the segmentation rules from Unicode 12.0.0, which is
the latest version at the time of this commit and is also the version of
Unicode used for other purposes by the Go 1.14 runtime.

HCL does not use text segmentation results for any purpose that would
affect the meaning of decoded data extracted from HCL files, so this
change will only affect the human-oriented source positions generated for
files containing characters that were newly-introduced in Unicode 10, 11,
or 12. (Machine-oriented uses of source location information are based on
byte offsets and not affected by text segmentation.)
2020-03-09 09:16:33 -07:00
Martin Atkins
2cf95f2b60
hclsyntax: Correct spec to allow colons as object element delimiter
To allow easir adaptation of data already serialized as JSON, HCL native
syntax allows both equals signs _and_ colons for object constructors.

This was already implemented, but not reflected in the pseudo-BNF in
the specification.
2020-03-05 09:51:26 -08:00
Chris Marchesi
5200d8dd67
Merge pull request #344 from hashicorp/gohcl-document-optional
gohcl: document optional attribute
2020-02-18 09:29:48 -08:00
Pratik Mallya
3c24a1211a FIX: a couple of typos 2020-02-17 23:25:41 -08:00
Chris Marchesi
939ae58199
gohcl: document optional attribute
This documents the "optional" attribute, which allows you to specify an
attribute that is optional when parsing.
2020-02-13 18:51:40 -08:00
Masayuki Morita
cec773f974 Fix various stale links to spec.md
These resulted from repository reorganization in preparation for the 2.0.0 release.
2020-01-09 11:02:20 -08:00
Martin Atkins
7990d6e9a2 Prepare CHANGELOG for forthcoming v2.4.0 release 2020-01-03 11:13:30 -08:00