Full architecture overhaul: bidirectional HCL2 ↔ JSON pipeline with typed rule classes#203
Merged
kkozik-amplify merged 42 commits intorelease/8.xfrom Mar 9, 2026
Merged
Conversation
feb6628 to
c9a38fe
Compare
04ed570 to
f72ab4d
Compare
f72ab4d to
5a10fec
Compare
batch of other changes
require heredoc openers to be on their on separate line in lark grammar; whitespace trimming based on current implementation in dict_transformer.py;
ebda402 to
e173dcf
Compare
…her fixes and changes: * preserve order of serialized attributes and blocks * make RuleTransformer.__default_token__ differentiate between StringToken and StaticStringToken * add separate ProviderFunctionCallRule class for more accurate reconstruction
e173dcf to
107fcb2
Compare
* FunctionCallRule.serialize - properly serialize into dollar string * remove unused import
e90ec16 to
ca19232
Compare
…remove unused import
…one singleton"); fix whitespaces in `test/round_trip/hcl2_reconstructed/smoke.tf`
5b0fff0 to
b235ec9
Compare
e33b728 to
cf33fb3
Compare
- hcl2/rules/base.py - hcl2/rules/for_expressions.py - hcl2/rules/functions.py add some related bugs
… serialization, and block label spacing in reconstruction
unit tests for deserializer and formatter
rddimon
approved these changes
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the old
DictTransformer(Lark parse tree → Python dict) with a two-stage pipeline that routes through a typed intermediate representation:This enables full round-trip fidelity: parse HCL2 to JSON and reconstruct it back to semantically equivalent HCL2.
What changed
hcl2/rules/) — one typed class per grammar rule with property accessors,serialize(), and_children_layoutannotationshcl2/transformer.py) — maps Lark parse tree nodes to LarkElement treehcl2/deserializer.py) — Python dict → LarkElement tree (reverse of serialize)hcl2/reconstructor.py) — LarkElement tree → Lark tree → HCL2 text with correct spacinghcl2/formatter.py) — vertical alignment and whitespace normalization on LarkElement treeshcl2/api.py) —load/loads,dump/dumpsfollowing thejsonmodule convention, plus intermediate-stage functionscli/) —hcl2tojsonandjsontohcl2entry points with flags mapping to option dataclassestest/unit/(direct rule instantiation) andtest/integration/(golden-file round-trip suites)Highlights
__is_block__markersforce_parensmode)with_commentsserialization optionBreaking changes
hcl2.load()/hcl2.loads()now accept keyword-only option parameters instead of positional booleansDictTransformerremoved — usehcl2.transform()for the LarkElement tree orhcl2.load()for dictshcl2tojsonCLI flags changed to--flagstyle (e.g.--with-meta,--wrap-objects)