fix: allow keywords as block type names and labels - #355
Open
aoskotsky-amplify wants to merge 1 commit into
Open
fix: allow keywords as block type names and labels#355aoskotsky-amplify wants to merge 1 commit into
aoskotsky-amplify wants to merge 1 commit into
Conversation
`in { ... }`, `for { ... }`, and `resource in { ... }` failed to parse
while the matching attribute form `in = 1` already worked. Keywords are
reserved only inside expressions; in a body they are ordinary names.
Reuse the existing `_attribute_name` rule for the block type and label
positions, and normalize KeywordRule/LiteralValueRule to IdentifierRule
in the block transformer so labels stay a single type.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
aoskotsky-amplify
force-pushed
the
fix/keyword-block-names
branch
from
September 4, 2026 17:14
e24e552 to
eb9995d
Compare
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.
Problem
Keywords parse as attribute names but not as block names:
Keywords (
in,for,if,for_each,else,endif,endfor) and literal keywords (true,false,null) are reserved only inside expressions. In a body they are ordinary names, valid as a block type or label just as they already are as attribute names.The grammar already encodes this for attributes and simply never carried it to blocks:
This continues the line of #164 (attributes named
in) and #168 (if/for_eachas identifiers), which fixed the attribute side only.Fix
One line of grammar — reuse the existing
_attribute_namerule in the block type and label positions:No new rule, so nothing to keep in sync. Because the rule is inlined,
block()now receivesKeywordRule/LiteralValueRulefor bare names, so the transformer normalizes them toIdentifierRule— exactly whatattribute()already does — keepingBlockRule.labelsa single type for downstream consumers.Testing
resource_keyword_blockintegration suite (the block-side sibling of the existingresource_keyword_attribute), covering keyword block types, a keyword label (resource in), nesting, and a string label. All four pipeline files included.for_each =, and template%{ for }/%{ if }directives all parse and reconstruct as before.pre-commitclean (ruff, ruff format, mypy).Note for reviewers
Sharing
_attribute_namealso permitstrue { }/null { }as block names. That matches HCL, where a block type is an Identifier and these are contextual keywords, and it matches how they are already accepted as attribute names. Easy to restrict toidentifier | keywordat the block position if you would rather not accept it.🤖 Generated with Claude Code