Skip to content

Terminate keywords at HCL identifier boundaries - #108

Merged
FichteFoll merged 2 commits into
masterfrom
bugfix/keyword-break-termination
Nov 10, 2026
Merged

FichteFoll merged 2 commits into
masterfrom
bugfix/keyword-break-termination

Conversation

@FichteFoll

Copy link
Copy Markdown
Member

Keywords were not properly terminated by - before. Additionally, since we currently adhere to token termination etiquette, we can drop leading \b anchors for all our keyword and identifier matches.

Note that this relies on the removal of the JSON object-body context via #107, which matches \S as invalid and would otherwise allow keywords to begin mid-word.

FichteFoll and others added 2 commits November 10, 2026 14:33
HCL identifiers may contain `-`, but most keyword and constant rules
ended with `\b`, which treats `-` as a boundary. So `true-ish`,
`var-x`, `count-x = 1` or `[for-x]` highlighted a keyword followed by
a minus operator instead of a single identifier.

Replace the trailing `\b` with `{{break}}` in the rules for named
values, type keywords, language constants, template directives,
`terraform import`, the `count`/`for_each` attribute keys and the
tuple `for` and for-expression `in`/`if` keywords.
Numeric literals keep `\b` because `-` ends a number.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every context with a keyword rule also has a rule that consumes whole
identifiers from their first character. Since the leftmost match wins,
a keyword rule can no longer match in the middle of an identifier such
as `xtrue` or `a-in`, which makes the leading `\b` redundant.

Patterns now starting with `{{` are quoted to remain valid YAML.
`\b` stays in the numeric literals, in `arn:aws:` inside strings and in
the plan syntax, whose contexts have no such identifier rule.

Add regression tests for identifiers ending with a keyword, notably
`{ waitfor: 1 }`, which relies on the native object key parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from feature/native-hcl-objects to master November 10, 2026 17:38
@FichteFoll
FichteFoll force-pushed the bugfix/keyword-break-termination branch 2 times, most recently from 337af00 to c684c91 Compare November 10, 2026 17:43
@FichteFoll
FichteFoll merged commit 6848e65 into master Nov 10, 2026
2 checks passed
@FichteFoll
FichteFoll deleted the bugfix/keyword-break-termination branch November 10, 2026 17:43
@FichteFoll FichteFoll added this to the 2.1.0 milestone Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants