Commit Graph

1103 Commits

Author SHA1 Message Date
Martin Atkins
afbe52484f go get github.com/zclconf/go-cty@v1.2.0
This includes a new feature to allow extension properties associated with
capsule types, which HCL can in turn use to allow certain capsule types
to opt in to special handing at the HCL layer.

(There are no such hooks in use as of this commit, however.)
2019-12-17 07:51:07 -08:00
Martin Atkins
9348ee05cd Prepare CHANGELOG for forthcoming v2.3.0 release 2019-12-11 07:36:54 -08:00
Martin Atkins
c4a8fbfd31 v2.2.0 release 2019-12-11 07:35:40 -08:00
Martin Atkins
a21a3f1908 Fix import ordering from the move from hcl2 repository
When we did the automatic rewriting from the hashicorp/hcl2 import paths
to hashicorp/hcl/v2 import paths, our automatic rewrite script did not
run "go fmt" afterwards and so left some imports misordered as a result
of the slightly-differently-shaped directory structure in the new
repository.
2019-12-11 07:34:30 -08:00
Martin Atkins
051d00ef91
Update CHANGELOG.md 2019-12-11 07:27:38 -08:00
Martin Atkins
c22ad7a9a6 hcldec: Improved context for expression diagnostics
The two cases where we decode attribute values should include the
expression and EvalContext in any diagnostics they generate so that the
calling application can give hints about the types and values of variables
that are used within the expression.

This also includes some adjustments to the returned source ranges so that
both cases are consistent with one another and so that both indicate
the entire expression as the Subject and include the attribute name in
the Context. Including the whole expression in the range ensures that
when there's a problem inside a tuple or object constructor, for example,
we'll show the line containing the problem and not just the opening [
or { symbol.
2019-12-11 07:25:33 -08:00
Martin Atkins
fc57429f63
Update CHANGELOG.md 2019-12-06 09:12:15 -08:00
Martin Atkins
63e2897c12 hclsyntax: Source range of IndexExpr must cover whole expression
Some HCL callers make the (reasonable) assumption that the overall source
range of an expression will be a superset of all of the ranges of its
child expressions, for purposes such as extraction of source code
snippets, parse tree annotation in hclwrite, text editor analysis
functions like "go to reference", etc.

The IndexExpr type was not previously honoring that assumption, since its
source range was placed around only the bracket portion. That is a good
region to use when reporting errors relating to the index operation, but
it is not a faithful representation of the full extent of the expression.

In order to meet both of these requirements at once, IndexExpr now has
both SrcRange covering the entire expression and BracketRange covering
the index part delimited by brackets. We can then use BracketRange in
our error messages but return SrcRange as the result of the general
Range method that is common to all expression types.
2019-12-06 09:09:18 -08:00
Martin Atkins
af72151950 dependencies: go get github.com/zclconf/go-cty@v1.1.1
This patch release includes a couple small bug fixes that don't affect HCL
directly, and a slight improvement to error messages for failed
conversions from boolean to string.

The primary goal of this upgrade is to ratchet dependents on HCL up to the
newer version of cty in order to get those improved error messages, but
during upgrading they may also benefit from the other bug fixes.
2019-12-06 09:08:25 -08:00
Martin Atkins
7f9aa845c1 Prepare for later v2.2.0 release 2019-11-19 17:21:19 -08:00
Martin Atkins
2c9d84a2cb v2.1.0 release 2019-11-19 17:20:21 -08:00
Martin Atkins
30ef7871f7
Update CHANGELOG.md 2019-11-19 17:18:56 -08:00
Martin Atkins
06985781df hclwrite: Allow constructing expressions from raw tokens
We currently have functions for constructing new expressions from either
constant values or from traversals, but some surgical updates require
producing a more complex expression.

In the long run perhaps we'll have some mechanism for constructing valid
expressions via a high-level AST-like API, similar to what we already have
for structural constructs, but as a simpler first step here we add a
mechanism to just write raw tokens directly into an expression, with the
caller being responsible for making sure those tokens represent valid
HCL expression syntax.

Since this new API treats the given tokens as unstructured, the resulting
expression can't fully support the whole of the expression API, but it's
good enough for writing in complex expressions without disturbing existing
content elsewhere in the input file.
2019-11-19 15:35:01 -08:00
Martin Atkins
56bc00a23c
Update README.md 2019-11-14 08:52:37 -08:00
Martin Atkins
63cdbee39c
Update CHANGELOG.md 2019-11-11 15:18:42 -08:00
Colin Hoglund
b954e171a6 hclwrite: fix TokensForTraversal handling of index steps 2019-11-11 15:17:19 -08:00
Martin Atkins
3c7194d967
Update CHANGELOG.md 2019-10-17 11:26:46 -07:00
Masayuki Morita
c21e319577 hclwrite: Fix unstable list returned by Body.Blocks()
Fixes #310

The type of `Body.items` is a `nodeSet` (That is, `map[*node]struct{}`),
so the order of the list returned by Body.Blocks () was unstable.
2019-10-17 11:24:26 -07:00
Martin Atkins
b15db4a513
Update CHANGELOG.md 2019-10-10 09:17:29 -07:00
Mateusz Gozdek
42351b1d15 gohcl: retain nested blocks while decoding
Currently, if nonzero struct is passed to the DecodeBody function,
decoding process will keep already initialized top-level fields values or
overwrite them, if they are specified in HCL. This behaviour is useful,
as it allows to have some default values for top-level fields.

However, if the field is a type block or slice (multiple blocks), then the
entire block is overwritten, which erases the existing values. Because of
that, setting default values in nested structs is not possible.

With this commit, decode functions will check if the value is
nil and only then set them to empty struct, which allows for appending
to existing structs.

In case of a slice, either new empty element will be added, or existing
element will be used for setting new value (so values will be merged).

Also, to keep the same behavior as json.Unmarshal, if retained list
have more elements than new list, additional elements will be removed
and existing elements will be merged. This allows to have default values
also for positional elements.

Behavior added by this patch is the same as in json.Unmarshal and
yaml.Unmarshal, which both retain nested structs during unmarshaling
process, so I believe this is an expected behavior from user
perspective.
2019-10-10 09:15:24 -07:00
Martin Atkins
6ca13f360e build: A basic appveyor.yml
In the long run we intend to transition to using CircleCI for all of the
testing steps here, but we need to keep appveyor enabled here until we
have both the HCL 1 and HCL 2 branches ready to use CircleCI, so this is
just a minimal appveyor configuration for running our tests in a Windows
environment in order to avoid errant test failures on PRs until we have
completed the move fully to CircleCI.
2019-10-03 09:47:09 -07:00
John Flores
87e23659ab README: Fix specification file links 2019-10-03 09:23:15 -07:00
Martin Atkins
a545295bc8
README: Fix incorrect link to Version Selection guide 2019-10-02 08:03:34 -07:00
Martin Atkins
181452c162 CHANGELOG: prepare for next release 2019-10-02 08:00:16 -07:00
Martin Atkins
4e12e081a1 Release v2.0.0 2019-10-02 07:58:32 -07:00
Martin Atkins
763cf0ee1e README: Link to the version selection guide 2019-10-02 07:54:25 -07:00
Martin Atkins
9e36050dd7 CHANGELOG: Some small tweaks prior to v2.0.0 release 2019-10-02 07:47:30 -07:00
Martin Atkins
46f91bd139 README: include a short Go example using the hclsimple API 2019-10-01 16:20:52 -07:00
Martin Atkins
34955ebf80 hclsimple: Simple one-shot parse/decode/evaluate API
For programs that don't need fine control over the process of decoding a
configuration, this allow a one-shot decode into a value of a Go struct
type.
2019-10-01 16:18:16 -07:00
Martin Atkins
b0134908b0 hclwrite: Allow removing attributes and blocks from bodies
Previously we allowed adding both attributes and blocks, and we allowed
updating attributes, but we had no mechanism to surgically remove
attributes and blocks altogether.
2019-10-01 15:59:10 -07:00
Masayuki Morita
9d1235a5b4 hclwrite: Allow selecting blocks for updating 2019-10-01 15:59:10 -07:00
Martin Atkins
ed70541558 hclsyntax: Include legacy index syntax in the specification 2019-10-01 15:59:10 -07:00
Martin Atkins
2c66cf702c hclsyntax: Additional tests for template sequence escapes
In previous versions we had some bugs around template sequence escapes.
These tests show that they no longer seem to be present, and should
hopefully avoid them regressing in future.
2019-10-01 15:59:10 -07:00
Martin Atkins
22ba006718 hclsyntax: Allow parens to force mapping key to be expression
Our error message for the ambiguous situation recommends doing this, but
the parser didn't actually previously allow it. Now we'll accept the form
that the error message recommends.

As before, we also accept a template with an interpolation sequence as
a disambiguation, but the error message doesn't mention that because it's
no longer idiomatic to use an inline string template containing just a
single interpolation sequence.
2019-10-01 15:59:10 -07:00
Martin Atkins
ee38c67330 specsuite: Tests for the expression language operators 2019-10-01 15:59:10 -07:00
Martin Atkins
48fbad7bf4 specsuite: tests for primitive type literals 2019-10-01 15:59:10 -07:00
Martin Atkins
791068cd07 cmd/hclspecsuite: run hcldec with --keep-nulls
This gives us a more precise picture of the result, which is helpful to
ensure our tests are not "cheating".
2019-10-01 15:59:10 -07:00
Martin Atkins
c366498686 cmd/hcldec: Allow overriding the removal of nulls
We remove properties whose values are null by default in order to produce
output that is more convenient to consume in the common case.

However, sometimes those nulls are significant, so we'll allow the user
to opt in to retaining them, at the expense of producing a result that is
more noisy if the spec contains lots of optional attributes that are not
set.
2019-10-01 15:59:10 -07:00
Martin Atkins
af5f398dc0 go get github.com/zclconf/go-cty@v1.1.0 2019-10-01 15:59:10 -07:00
Martin Atkins
75cf5ded6e hclsyntax: Correct specification of the interpretation of tabs
This changed during development as we iterated on the prototype, but the
spec is lagging behind.
2019-10-01 15:59:10 -07:00
Martin Atkins
938b3d3319 build: Simplify Circle-CI run; use Go Module proxy 2019-10-01 15:59:10 -07:00
Martin Atkins
18eab5520f build: Use home directory for Circle-CI test run 2019-10-01 15:59:10 -07:00
Martin Atkins
d2dae93c75 build: Disable codecov reporting in Circle-CI for now
This isn't currently enabled for our organization.
2019-10-01 15:59:10 -07:00
Martin Atkins
4755f8bf41 json: Clarify that this package is not interesting to import 2019-10-01 15:59:10 -07:00
Martin Atkins
76cda0e2aa build: Switch from Travis-CI to Circle-CI 2019-10-01 15:59:10 -07:00
Martin Atkins
c29bdc1243 hclparse: Go package documentation 2019-10-01 15:59:10 -07:00
Martin Atkins
dca4accff0 ext/dynblock: Go package documentation 2019-10-01 15:59:10 -07:00
Martin Atkins
b26a9bb7be Add a CHANGELOG 2019-10-01 15:59:10 -07:00
Martin Atkins
6c43130979 specsuite: Move the Go testing stub into the specsuite directory
The separate "spectests" directory was an artifact of our former nesting
of the main package under a "hcl" directory. However, it was confusing
to have both specsuite and spectests directories at the top level, so
instead we'll just conflate these two by putting the automatic Go testing
helper into the specsuite directory.
2019-10-01 15:59:10 -07:00
Martin Atkins
8617b7c8c4 extras/grammar: Remove
These grammar files are not yet feature-complete and so we'll remove them
for now until such time that we're ready to support them.

The main blocker here is in lacking a good testing procedure for updates
to these. While in principle they can be loaded into a number of different
text editors, that is a very manual process that often requires a high
degree of familiarity with the extension API. In order to support these
properly we'd instead need some sort of automatic test suite which can
run various inputs through these rulesets and check that the resulting
tokenization.
2019-10-01 15:59:10 -07:00