summaryrefslogtreecommitdiff
path: root/hclwrite/parser.go
AgeCommit message (Collapse)Author
2023-02-28[COMPLIANCE] Add Copyright and License Headers (#586)hashicorp-copywrite[bot]
* [COMPLIANCE] Add Copyright and License Headers * add copywrite file and revert headers in testdata --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2020-08-21hclwrite: Make block labels a node in their own rightMartin Atkins
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-21hclwrite: Fix a bug that Block.open/close positions were not recorded in parserMasayuki Morita
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-05-27Merge pull request #317 from minamijoyo/fix-typos-in-hclwrite-parserRadek Simko
Fix typos in hclwrite/parser.go
2020-04-28hclwrite: handle legacy dot access of numeric indexesBen Drucker
2019-10-31Fix typos in hclwrite/parser.goMasayuki Morita
2019-09-09Unfold the "hcl" directory up into the rootMartin Atkins
The main HCL package is more visible this way, and so it's easier than having to pick it out from dozens of other package directories.
2019-09-09Change module path to github.com/hashicorp/hcl/v2Martin Atkins
This is in preparation for the first v2 release from the main HCL repository.
2019-09-09hclwrite: Unquoted label should be parsed as *identifierMasayuki Morita
2018-11-04hclwrite: Expression.RenameVariablePrefixMartin Atkins
This function serves the use-case of surgically renaming references to variables in an existing file without disturbing other tokens.
2018-08-25hclwrite: Adjust token spacing automatically when writingMartin Atkins
Although our underlying parse tree retains all of the token content, it doesn't necessarily retain all of the spacing information under editing, and so formatting on save ensures that we'll produce a canonical result even if some edits have been applied that have changed the expected alignment of objects, etc.
2018-08-09hclwrite: Body.SetAttributeValueMartin Atkins
For now, this is the only way to set an attribute, and so attributes can only be set to literal values. Later this will be generalized so that this is just a helper wrapper around a "SetAttribute" method that just uses a given expression, which then helps by constructing the expression from the value first.
2018-08-01hclwrite: Simplify internal data structuresMartin Atkins
The original prototype of hclwrite tried to track both the tokens and the AST as two parallel data structures. This quickly exploded in complexity, leading to lots of messy code to manage keeping those two structures in sync. This new approach melds the two structures together, creating first a physical token tree (made of "node" objects, and hidden from the caller) and then attaching the AST nodes to that token tree as additional sidecar data. The result is much easier to work with, leading to less code in the parser and considerably less complex data structures in the parser's tests. This commit is enough to reach feature parity with the previous prototype, but it remains a prototype. With a more usable foundation, we'll evolve this into a more complete implementation in subsequent commits.
2018-07-14hclwrite: Parsing of absolute traversals in expressionsMartin Atkins
This will allow for use-cases such as renaming a variable (changing the content of the first token) and replacing variable references with constant values that they evaluate to for debug purposes.
2018-01-23update zclsyntax to hclsyntax in various comments and stringsFatih Arslan
These are remnants of the project HCL was forked from.
2017-09-11Move the zcl package and its two parsing subpackages to "hcl" namesMartin Atkins
This is a super-invasive update since the "zcl" package in particular is referenced all over. There are probably still a few zcl references hanging around in comments, etc but this takes care of most of it.
2017-09-11Rename the ancillary packages from "zcl" to "hcl".Martin Atkins
The main "zcl" package requires a bit more care because of how many callers it has and because of its two subpackages, so we'll take care of that one separately.