Commit Graph

1232 Commits

Author SHA1 Message Date
Alisdair McDiarmid 9dabf7d816
Prepare changelog for next release 2020-11-18 11:54:22 -05:00
Alisdair McDiarmid eadfd40eca
Update CHANGELOG.md 2020-11-18 11:53:03 -05:00
Alisdair McDiarmid 253a71d65c
Merge pull request #422 from hashicorp/alisdair/hclwrite-empty-labels
hclwrite: Allow blank quoted string block labels
2020-11-18 11:50:06 -05:00
Alisdair McDiarmid 1818f36094 hclwrite: Allow blank quoted string block labels
The hclsyntax package permits block labels to be blank quoted strings,
and defers to the application to determine if this is valid or not. This
commit updates hclwrite to allow the same behaviour.

This is in response to an upstream bug report on Terraform, which uses
hclwrite to implement its fmt subcommand. Given a block with a blank
quoted string label, it currently deletes the label when formatting.
This is inconsistent with Terraform's behaviour when parsing HCL, which
treats empty labels differently from missing labels.
2020-11-18 09:21:23 -05:00
Mitchell Hashimoto 3de61ecba2
Merge pull request #412 from hashicorp/mitchellh/body
"body" struct tag to capture entire body for a block decode
2020-10-22 17:07:45 -07:00
Mitchell Hashimoto 38280c6c69
gohcl: add "body" struct tag to capture entire block body
Structs can specify the "body" struct tag to capture the entire block
body. This does NOT act as "remain" where leftover fields are
non-erroneous. If you want leftover fields to be allowed, a "remain"
field must ALSO be present.

This is used to capture the full block body that was decoded for the
block. This is useful if you want to ever redecode something differently
(maybe with a different EvalContext) or partially decode something but
redecode the entire value.
2020-10-22 16:56:33 -07:00
Alisdair McDiarmid d56ed51dbc
Update CHANGELOG.md 2020-10-14 10:12:29 -04:00
Alisdair McDiarmid 84d75d846a Update CHANGELOG.md 2020-10-14 09:36:31 -04:00
Alisdair McDiarmid fec69aa0e2
Merge pull request #407 from hashicorp/alisdair/for-expressions-over-marked-values
hclsyntax: Fix for expressions over marked values
2020-10-09 10:48:19 -04:00
Alisdair McDiarmid 39015a09a3 hclsyntax: Fix for expressions over marked values
A for expression over a marked collection should result in a new
collection with the same marks. Previously this would fail with a type
error.
2020-10-08 16:07:45 -04:00
Alisdair McDiarmid a0de289809
Merge pull request #406 from hashicorp/alisdair/fix-panic-traversing-marked-map
Fix panic traversing marked map
2020-09-25 11:19:48 -04:00
Alisdair McDiarmid 8eccdca8f9 hclsyntax: Test for interpolating from marked map 2020-09-24 12:46:39 -04:00
Alisdair McDiarmid 35ad93007d Fix panic when traversing marked map value 2020-09-24 12:40:41 -04:00
Alisdair McDiarmid 4997e114f6
Merge pull request #404 from hashicorp/alisdair/pass-marks-through-expression-templates
hclsyntax: Pass marks through template expressions
2020-09-24 12:34:35 -04:00
Alisdair McDiarmid 876b4237a0 hclsyntax: Pass marks through template expressions
If a template expression interpolates values which have marks, we should
apply all of those marks to the output value. This allows template
expressions to function like native cty functions with respect to marks.
2020-09-22 15:19:46 -04:00
Alisdair McDiarmid bf0a7fe4fe
Update CHANGELOG.md 2020-09-15 15:56:56 -04:00
Martin Atkins 5c3a3da3cc
Update CHANGELOG.md 2020-09-04 14:13:39 -07:00
wata_mac 636e660fac json: Add ParseExpression function 2020-09-04 14:12:01 -07:00
Martin Atkins 90676d47a0 hclsyntax: Tailored error for "curly quotes"
It seems to be somewhat common for someone to share HCL code via a forum
or a document and have the well-meaning word processor or CMS replace the
straight quotes with curly quotes, which then lead to confusing errors
when someone copies the result and tries to use it as valid HCL
configuration.

Here we add a special hint for that, giving a tailored error message
instead of the generic "This character is not used within the language"
error message.

HCL has always had some of these special hints implemented here, and they
were originally implemented with special token types to allow the parser
handle them. However, we later refactored to do the check all at once
inside the Lex* family of functions, prior to parsing, so it's now
relatively straightforward to handle it as a special case of TokenInvalid
rather than an entirely new token type. Perhaps later we'll rework the
existing ones to also just use TokenInvalid, but that's a decision for
another day.
2020-08-24 11:35:03 -07:00
Martin Atkins a484440c53
Update CHANGELOG.md 2020-08-24 10:55:42 -07:00
Kazuma Watanabe e72341df8a
json: Add json.ParseWithStartPos function
This is like json.Parse but allows specifying a non-default start position,
in case the caller is parsing a fragment from a larger JSON document.
2020-08-24 10:53:10 -07:00
Mark Foster b41530cb36 hcl: Fix the simple example in the README 2020-08-21 15:11:58 -07:00
Patrick Hagan 9603bea74b
ext/userfunc: Fix the package documentation link in the README 2020-08-21 15:03:22 -07:00
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