Add literal_value grammar rule for true, false, and null#294
Merged
kkozik-amplify merged 1 commit intomainfrom Apr 10, 2026
Merged
Add literal_value grammar rule for true, false, and null#294kkozik-amplify merged 1 commit intomainfrom
kkozik-amplify merged 1 commit intomainfrom
Conversation
9e5961c to
d7507d7
Compare
Introduces a dedicated `literal_value` grammar rule and `LiteralValueRule` class
so that `true`, `false`, and `null` serialize to native Python/JSON types
(True, False, None) instead of strings. Updates grammar, transformer,
deserializer, reconstructor, and all affected golden files.
Also fixes InterpolationRule to set inside_dollar_string context so that
literal values inside interpolations serialize as strings (${null} not ${None}).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d7507d7 to
92b0886
Compare
rddimon
approved these changes
Apr 10, 2026
mluhovyi
approved these changes
Apr 10, 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.
Caused by #293
Summary
HCL2 keywords
true,false, andnullwere parsed as generic identifiers, causing them to serialize as strings ("true","false","null") in JSON output instead of native JSON types (true,false,null). This adds a dedicatedliteral_valuegrammar rule so these keywords produce the correct Python/JSON types.Changes
TRUE,FALSE,NULLlexer tokens andliteral_valuegrammar rule to the Lark grammarLiteralValueRuleclass that serializes to nativeTrue/False/None(falls back to string form inside interpolation contexts)literal_valuein expressions, attribute names, object keys, and get_attr accessLiteralValueRuleforboolandNonevalues instead ofIdentifierRuleliteral_valueandidentifier/stringtokensnulls.json,smoke.json,builder_basic_*.json,comments.json)Manual testing checklist
echo 'x = true' | hcl2tojson→ produces{"x": true}(not"true")echo 'x = null' | hcl2tojson→ produces{"x": null}(not"null")echo '{"x": true}' | jsontohcl2→ producesx = trueecho '{"x": null}' | jsontohcl2→ producesx = nullecho 'x = "${true}"' | hcl2tojson→ interpolated form stays as stringhcl2tojson file.tf | jsontohcl2preservestrue/false/nullcorrectlytrue/false/nullstill parse (e.g.null = 1)🤖 Co-Authored-By: Claude Opus 4.6 (1M context) Claude Code